0
|
1 <?php
|
|
2 include_once('Lib_mb_utf8.php');
|
|
3 include_once('config.php');
|
|
4 include_once('edit_section_db.php');
|
|
5 set_time_limit(0);
|
|
6 ini_set('memory_limit', '-1');
|
|
7
|
|
8 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password);
|
|
9 mysql_query("SET NAMES utf8");
|
|
10
|
|
11 if (!$link_mysql) {
|
|
12 die('Could not connect: ' . mysql_error());
|
|
13 }
|
|
14
|
|
15 $db_selected = mysql_select_db($mysql_database, $link_mysql);
|
|
16 if (!$db_selected) {
|
|
17 die ('Can\'t use foo : ' . mysql_error());
|
|
18 }
|
|
19
|
|
20 if (isset($_POST['func'])){
|
|
21 switch ($_POST['func']) {
|
|
22 case 'UpdateTOCstatus':
|
|
23 UpdateTOCstatus($_POST['id'],$_POST['status']);
|
|
24 break;
|
|
25
|
|
26 case 'UpdateTOCcomments':
|
|
27 UpdateTOCcomments($_POST['id'],$_POST['notes']);
|
|
28 break;
|
|
29 default:
|
|
30 # code...
|
|
31 break;
|
|
32 }
|
|
33 }
|
|
34
|
|
35
|
|
36 function UpdateTOCcomments($id, $notes) {
|
|
37 $query = "UPDATE books SET comments='".$notes."' WHERE id='".$id."'";
|
|
38
|
|
39 $result = mysql_query($query);
|
|
40 if (!$result){
|
|
41 echo mysql_error();
|
|
42 echo ("Failed during updating books table.");
|
|
43 }
|
|
44
|
|
45 }
|
|
46
|
|
47 function UpdateTOCstatus($id, $status) {
|
|
48
|
|
49 $query = "UPDATE books SET toc_correction='".$status."' WHERE id='".$id."'";
|
|
50
|
|
51 $result = mysql_query($query);
|
|
52 if (!$result){
|
|
53 echo mysql_error();
|
|
54 echo ("Failed during updating books table.");
|
|
55 }
|
|
56 }
|
|
57
|
|
58 function checkSections($count){
|
|
59
|
|
60 /* $query="SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections.name, start_page, end_page, COUNT( * ) AS count
|
|
61 FROM sections
|
|
62 JOIN books ON sections.books_id = books.id
|
|
63 WHERE NOT EXISTS
|
|
64 (SELECT 1 FROM sections_versions WHERE books_id=sections.books_id)
|
|
65 GROUP BY books_id, start_page, end_page
|
|
66 HAVING COUNT( * ) >=".$count."
|
|
67 ORDER BY COUNT( * ) DESC ";*/
|
|
68 $query="(SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections.name, start_page, end_page, COUNT( * ) AS count
|
|
69 FROM sections
|
|
70 JOIN books ON sections.books_id = books.id
|
|
71 WHERE NOT EXISTS
|
|
72 (SELECT 1 FROM sections_versions WHERE books_id=sections.books_id)
|
|
73 GROUP BY books_id, start_page, end_page
|
|
74 HAVING COUNT( * ) >=".$count.")
|
|
75 UNION
|
|
76 (SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections_revisions.name, start_page, end_page, COUNT( * ) AS count
|
|
77 FROM sections_revisions
|
|
78 JOIN books ON sections_revisions.books_id = books.id
|
|
79 JOIN (
|
|
80 SELECT sections_versions.id
|
|
81 FROM sections_versions WHERE sections_versions.version=(SELECT MAX(version) FROM sections_versions)
|
|
82 GROUP BY books_id
|
|
83 ) AS t ON t.id=sections_revisions.versions_id
|
|
84 WHERE deleted=0
|
|
85 GROUP BY books_id, versions_id,start_page, end_page
|
|
86 HAVING COUNT( * ) >=".$count.")
|
|
87 ORDER BY count DESC ";
|
|
88 $result = mysql_query($query);
|
|
89 echo mysql_num_rows($result)." result(s)<br><br>";
|
|
90 echo "<table>";
|
|
91 echo "<tr>";
|
|
92 echo "<td class='bookName'>book name<td class='level1'>level1<td class='level2'>level2<td class='period'>period<td class='sectionName'>section name<td class='sectionName'>page<td class='page'>count";
|
|
93 while ($row = mysql_fetch_assoc($result)) {
|
|
94 $str="<tr>";
|
|
95 $str.="<td>".$row['book_name'];
|
|
96 $str.="<td>".$row['level1'];
|
|
97 $str.="<td>".$row['level2'];
|
|
98 $str.="<td>".$row['period'];
|
|
99 $str.="<td><a href='tagging_text.php?id=".$row['id']."' target='_blank'>".$row['name']."</a>";
|
|
100 $str.="<td>p".$row['start_page']."-".$row['end_page'];
|
|
101 $str.="<td><a href='check_sections_details.php?book_id=".$row['id']."&count=".$count."' target='_blank'>".$row['count']."</a>";
|
|
102 echo $str;
|
|
103 }
|
|
104 echo "</table>";
|
|
105 }
|
|
106
|
|
107
|
|
108 // sorting by the $sort_by parameter
|
|
109 function checkSections_sort_by($sort_by){
|
|
110 switch ($sort_by) {
|
|
111 case 'time':
|
|
112 $query="(SELECT name AS book_name,level1,level2,period,dynasty,start_year,id,toc_correction,comments FROM books ORDER BY start_year)";
|
|
113 $result = mysql_query($query);
|
|
114 echo mysql_num_rows($result)." result(s)<br><br>";
|
|
115
|
|
116 echo "<form autocomplete='off'>";
|
|
117 echo "<table>";
|
|
118 echo "<tr>";
|
|
119 echo "<td class='bookName'>book name<td class='level1'>level1<td class='level2'>level2
|
|
120 <td class='period'>period<td class='dynasty'>dynasty<td class='start_year'>start_year
|
|
121 <td class='last_editor'>last_editor<td class='level1'>edit_time
|
|
122 <td> <td> <td> Some notes for the book (optional)";
|
|
123 while ($row = mysql_fetch_assoc($result)) {
|
|
124 $str="<tr>";
|
|
125 $str.="<td>".$row['book_name'];
|
|
126 $str.="<td>".$row['level1'];
|
|
127 $str.="<td>".$row['level2'];
|
|
128 $str.="<td>".$row['period'];
|
|
129 $str.="<td>".$row['dynasty'];
|
|
130 $str.="<td>".$row['start_year'];
|
|
131
|
|
132 $id = $row['id'];
|
|
133
|
|
134 // query last_editor and last_edit_time
|
|
135 $query_editor = "(SELECT editor, date from sections_versions WHERE books_id='".$row['id']."' ORDER BY version DESC)";
|
|
136 $row_sections_versions = mysql_fetch_assoc(mysql_query($query_editor)); // the first one
|
|
137 $last_editor = $row_sections_versions['editor'];
|
|
138 $last_edit_time = $row_sections_versions['date'];
|
|
139 $str.="<td>".$last_editor;
|
|
140 $str.="<td>".$last_edit_time;
|
|
141
|
|
142 $str.="<td><a href='check_sections_details.php?book_id=".$row['id']."&count=100"."' target='_blank'>"."Edit"."</a>";
|
|
143
|
|
144 switch ($row['toc_correction']) {
|
|
145
|
|
146 case '0':
|
|
147 $str.="<td> <input type='checkbox' name='".$id."' onchange='toc_status(this)' /> Finished";
|
|
148 break;
|
|
149
|
|
150 case '1':
|
|
151 $str.="<td> <input type='checkbox' name='".$id."' onchange='toc_status(this)' checked='true' /> Finished";
|
|
152 break;
|
|
153 default:
|
|
154 break;
|
|
155 }
|
|
156 // comments for book
|
|
157 $comments = $row['comments'];
|
|
158 if ($comments != "") {
|
|
159 $str.="<td> <textarea rows='1' cols='30' name='".$id."' maxlength='100' onchange='toc_comments(this)'>".$comments."</textarea>";
|
|
160 } else {
|
|
161 $str.="<td> <textarea rows='1' cols='30' name='".$id."' maxlength='100' onchange='toc_comments(this)'></textarea>";
|
|
162 }
|
|
163 echo $str;
|
|
164
|
|
165 }
|
|
166 echo "</table>";
|
|
167 echo "</form>";
|
|
168 break;
|
|
169
|
|
170 default:
|
|
171 # code...
|
|
172 echo "no sorting parameter set";
|
|
173 break;
|
|
174 }
|
|
175 }
|
|
176
|
|
177 ?>
|
|
178
|
|
179
|
|
180
|
|
181 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
182 <html>
|
|
183 <head>
|
|
184 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
|
185 <link href="css/search.css" type="text/css" rel="stylesheet"/>
|
|
186 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
|
|
187 <!--<script src="js/check_sections.js" charset="utf-8"></script>!-->
|
|
188 </head>
|
|
189 <body>
|
|
190 <form action='check_sections.php' method='GET'>
|
|
191 find sections overlapping more than <input type="text" name="count"> other sections
|
|
192 <input type="submit" name="find" value="find">
|
|
193 </form>
|
|
194 <br>
|
|
195 <div id="search_result">
|
|
196 <?php
|
|
197 if(isset($_GET['find']) && $_GET['count']!='' && is_numeric($_GET['count'])){
|
|
198 checkSections($_GET['count']);
|
|
199 }
|
|
200 else if(isset($_GET['sort_by'])){
|
|
201 checkSections_sort_by($_GET['sort_by']);
|
|
202 }
|
|
203 ?>
|
|
204 </div>
|
|
205 </body>
|
|
206
|
|
207
|
|
208 <script type="text/javascript">
|
|
209
|
|
210 function toc_status(t) {
|
|
211 var id = t.name;
|
|
212 var val;
|
|
213
|
|
214 if (t.checked) {
|
|
215 val = '1';
|
|
216 } else {
|
|
217 val = '0';
|
|
218 }
|
|
219
|
|
220 $.ajax({
|
|
221 url : './check_sections.php',
|
|
222 async : false,
|
|
223 type : 'POST',
|
|
224 data : 'func=UpdateTOCstatus'+'&id='+id+'&status='+val,
|
|
225 complete: function(){
|
|
226 switch (val){
|
|
227 case '0':
|
|
228 alert('You update the status of book to "Not Finished"!');
|
|
229 break;
|
|
230 case '1':
|
|
231 alert('You update the status of book to "Finished"!');
|
|
232 break;
|
|
233 }
|
|
234
|
|
235 },
|
|
236 error:function() {
|
|
237 console.log("error to update toc status");
|
|
238 alert('You have NOT updated the status of book. If this issue remains, please contact us. Thanks.');
|
|
239 }
|
|
240 });
|
|
241
|
|
242 }
|
|
243
|
|
244 function toc_comments(t) {
|
|
245 console.log(t.value);
|
|
246 var text = t.value;
|
|
247 var id = t.name;
|
|
248
|
|
249 $.ajax({
|
|
250 url: './check_sections.php',
|
|
251 async : false,
|
|
252 type: 'POST',
|
|
253 data: 'func=UpdateTOCcomments'+'&id='+id+'¬es='+text,
|
|
254 complete: function(){
|
|
255 console.log('You update the comments of book!');
|
|
256 },
|
|
257 error:function() {
|
|
258 console.log("error to update toc comments");
|
|
259 alert('You have NOT updated the status of book. If this issue remains, please contact us. Thanks.');
|
|
260 }
|
|
261 });
|
|
262
|
|
263 }
|
|
264 </script>
|
|
265
|
|
266
|
|
267
|
|
268 </html>
|
|
269
|
|
270 <?php
|
|
271 ?>
|