Mercurial > hg > LGToc
annotate check_sections.php @ 12:7e04cbe8b2a0
add required libraries to server
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 24 Jun 2015 11:11:31 +0200 |
parents | 373c8ecad8b4 |
children |
rev | line source |
---|---|
0 | 1 <?php |
4
373c8ecad8b4
deploy to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
2 include_once('config/Lib_mb_utf8.php'); |
373c8ecad8b4
deploy to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
3 include_once('config/config.php'); |
0 | 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){ | |
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
59 /* |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
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 |
0 | 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 | |
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
66 HAVING COUNT( * ) >=".$count.") |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
67 UNION |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
68 (SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections_revisions.name, start_page, end_page, COUNT( * ) AS count |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
69 FROM sections_revisions |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
70 JOIN books ON sections_revisions.books_id = books.id |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
71 JOIN ( |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
72 SELECT sections_versions.id |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
73 FROM sections_versions WHERE sections_versions.version=(SELECT MAX(version) FROM sections_versions) |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
74 GROUP BY books_id |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
75 ) AS t ON t.id=sections_revisions.versions_id |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
76 WHERE deleted=0 |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
77 GROUP BY books_id, versions_id,start_page, end_page |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
78 HAVING COUNT( * ) >=".$count.") |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
79 ORDER BY count DESC "; |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
80 */ |
4
373c8ecad8b4
deploy to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
81 $query="(SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections_index.name, start_page, end_page, COUNT( * ) AS count |
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
82 FROM sections_index |
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
83 JOIN books ON sections_index.books_id = books.id |
0 | 84 WHERE NOT EXISTS |
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
85 (SELECT 1 FROM sections_versions WHERE books_id=sections_index.books_id) |
0 | 86 GROUP BY books_id, start_page, end_page |
87 HAVING COUNT( * ) >=".$count.") | |
88 UNION | |
89 (SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections_revisions.name, start_page, end_page, COUNT( * ) AS count | |
90 FROM sections_revisions | |
91 JOIN books ON sections_revisions.books_id = books.id | |
92 JOIN ( | |
93 SELECT sections_versions.id | |
94 FROM sections_versions WHERE sections_versions.version=(SELECT MAX(version) FROM sections_versions) | |
95 GROUP BY books_id | |
96 ) AS t ON t.id=sections_revisions.versions_id | |
97 WHERE deleted=0 | |
98 GROUP BY books_id, versions_id,start_page, end_page | |
99 HAVING COUNT( * ) >=".$count.") | |
100 ORDER BY count DESC "; | |
101 $result = mysql_query($query); | |
4
373c8ecad8b4
deploy to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
102 if (!$result) { |
373c8ecad8b4
deploy to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
103 echo mysql_error(); |
373c8ecad8b4
deploy to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
104 return; |
373c8ecad8b4
deploy to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
105 } |
0 | 106 echo mysql_num_rows($result)." result(s)<br><br>"; |
107 echo "<table>"; | |
108 echo "<tr>"; | |
109 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"; | |
110 while ($row = mysql_fetch_assoc($result)) { | |
111 $str="<tr>"; | |
112 $str.="<td>".$row['book_name']; | |
113 $str.="<td>".$row['level1']; | |
114 $str.="<td>".$row['level2']; | |
115 $str.="<td>".$row['period']; | |
116 $str.="<td><a href='tagging_text.php?id=".$row['id']."' target='_blank'>".$row['name']."</a>"; | |
117 $str.="<td>p".$row['start_page']."-".$row['end_page']; | |
118 $str.="<td><a href='check_sections_details.php?book_id=".$row['id']."&count=".$count."' target='_blank'>".$row['count']."</a>"; | |
119 echo $str; | |
120 } | |
121 echo "</table>"; | |
122 } | |
123 | |
124 | |
125 // sorting by the $sort_by parameter | |
126 function checkSections_sort_by($sort_by){ | |
127 switch ($sort_by) { | |
128 case 'time': | |
129 $query="(SELECT name AS book_name,level1,level2,period,dynasty,start_year,id,toc_correction,comments FROM books ORDER BY start_year)"; | |
130 $result = mysql_query($query); | |
131 echo mysql_num_rows($result)." result(s)<br><br>"; | |
132 | |
133 echo "<form autocomplete='off'>"; | |
134 echo "<table>"; | |
135 echo "<tr>"; | |
136 echo "<td class='bookName'>book name<td class='level1'>level1<td class='level2'>level2 | |
137 <td class='period'>period<td class='dynasty'>dynasty<td class='start_year'>start_year | |
138 <td class='last_editor'>last_editor<td class='level1'>edit_time | |
139 <td> <td> <td> Some notes for the book (optional)"; | |
140 while ($row = mysql_fetch_assoc($result)) { | |
141 $str="<tr>"; | |
142 $str.="<td>".$row['book_name']; | |
143 $str.="<td>".$row['level1']; | |
144 $str.="<td>".$row['level2']; | |
145 $str.="<td>".$row['period']; | |
146 $str.="<td>".$row['dynasty']; | |
147 $str.="<td>".$row['start_year']; | |
148 | |
149 $id = $row['id']; | |
150 | |
151 // query last_editor and last_edit_time | |
152 $query_editor = "(SELECT editor, date from sections_versions WHERE books_id='".$row['id']."' ORDER BY version DESC)"; | |
153 $row_sections_versions = mysql_fetch_assoc(mysql_query($query_editor)); // the first one | |
154 $last_editor = $row_sections_versions['editor']; | |
155 $last_edit_time = $row_sections_versions['date']; | |
156 $str.="<td>".$last_editor; | |
157 $str.="<td>".$last_edit_time; | |
158 | |
159 $str.="<td><a href='check_sections_details.php?book_id=".$row['id']."&count=100"."' target='_blank'>"."Edit"."</a>"; | |
160 | |
161 switch ($row['toc_correction']) { | |
162 | |
163 case '0': | |
164 $str.="<td> <input type='checkbox' name='".$id."' onchange='toc_status(this)' /> Finished"; | |
165 break; | |
166 | |
167 case '1': | |
168 $str.="<td> <input type='checkbox' name='".$id."' onchange='toc_status(this)' checked='true' /> Finished"; | |
169 break; | |
170 default: | |
171 break; | |
172 } | |
173 // comments for book | |
174 $comments = $row['comments']; | |
175 if ($comments != "") { | |
176 $str.="<td> <textarea rows='1' cols='30' name='".$id."' maxlength='100' onchange='toc_comments(this)'>".$comments."</textarea>"; | |
177 } else { | |
178 $str.="<td> <textarea rows='1' cols='30' name='".$id."' maxlength='100' onchange='toc_comments(this)'></textarea>"; | |
179 } | |
180 echo $str; | |
181 | |
182 } | |
183 echo "</table>"; | |
184 echo "</form>"; | |
185 break; | |
186 | |
187 default: | |
188 # code... | |
189 echo "no sorting parameter set"; | |
190 break; | |
191 } | |
192 } | |
193 | |
194 ?> | |
195 | |
196 | |
197 | |
198 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
199 <html> | |
200 <head> | |
201 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
4
373c8ecad8b4
deploy to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
202 <!-- <link href="css/search.css" type="text/css" rel="stylesheet"/> --> |
12
7e04cbe8b2a0
add required libraries to server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
4
diff
changeset
|
203 <script src="js/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> |
7e04cbe8b2a0
add required libraries to server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
4
diff
changeset
|
204 <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> --> |
0 | 205 <!--<script src="js/check_sections.js" charset="utf-8"></script>!--> |
206 </head> | |
207 <body> | |
208 <form action='check_sections.php' method='GET'> | |
209 find sections overlapping more than <input type="text" name="count"> other sections | |
210 <input type="submit" name="find" value="find"> | |
211 </form> | |
212 <br> | |
213 <div id="search_result"> | |
214 <?php | |
215 if(isset($_GET['find']) && $_GET['count']!='' && is_numeric($_GET['count'])){ | |
216 checkSections($_GET['count']); | |
217 } | |
218 else if(isset($_GET['sort_by'])){ | |
219 checkSections_sort_by($_GET['sort_by']); | |
220 } | |
221 ?> | |
222 </div> | |
223 </body> | |
224 | |
225 | |
226 <script type="text/javascript"> | |
227 | |
228 function toc_status(t) { | |
229 var id = t.name; | |
230 var val; | |
231 | |
232 if (t.checked) { | |
233 val = '1'; | |
234 } else { | |
235 val = '0'; | |
236 } | |
237 | |
238 $.ajax({ | |
239 url : './check_sections.php', | |
240 async : false, | |
241 type : 'POST', | |
242 data : 'func=UpdateTOCstatus'+'&id='+id+'&status='+val, | |
243 complete: function(){ | |
244 switch (val){ | |
245 case '0': | |
246 alert('You update the status of book to "Not Finished"!'); | |
247 break; | |
248 case '1': | |
249 alert('You update the status of book to "Finished"!'); | |
250 break; | |
251 } | |
252 | |
253 }, | |
254 error:function() { | |
255 console.log("error to update toc status"); | |
256 alert('You have NOT updated the status of book. If this issue remains, please contact us. Thanks.'); | |
257 } | |
258 }); | |
259 | |
260 } | |
261 | |
262 function toc_comments(t) { | |
263 console.log(t.value); | |
264 var text = t.value; | |
265 var id = t.name; | |
266 | |
267 $.ajax({ | |
268 url: './check_sections.php', | |
269 async : false, | |
270 type: 'POST', | |
271 data: 'func=UpdateTOCcomments'+'&id='+id+'¬es='+text, | |
272 complete: function(){ | |
273 console.log('You update the comments of book!'); | |
274 }, | |
275 error:function() { | |
276 console.log("error to update toc comments"); | |
277 alert('You have NOT updated the status of book. If this issue remains, please contact us. Thanks.'); | |
278 } | |
279 }); | |
280 | |
281 } | |
282 </script> | |
283 | |
284 | |
285 | |
286 </html> | |
287 | |
288 <?php | |
289 ?> |