Mercurial > hg > extraction-interface
comparison interface/review_index_xml_js.php @ 0:b12c99b7c3f0
commit for previous development
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 19 Jan 2015 17:13:49 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b12c99b7c3f0 |
---|---|
1 <?php | |
2 header("Content-Type: text/html;charset=utf-8"); | |
3 | |
4 if (isset($_GET['books_id'])) { | |
5 $books_id = $_GET['books_id']; | |
6 } | |
7 | |
8 include_once('./Lib_mb_utf8.php'); | |
9 | |
10 set_time_limit(0); | |
11 ini_set('memory_limit', '-1'); | |
12 | |
13 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); | |
14 mysql_query("SET NAMES utf8"); | |
15 | |
16 if (!$link_mysql) { | |
17 die('Could not connect: ' . mysql_error()); | |
18 } | |
19 | |
20 $db_selected = mysql_select_db($mysql_database, $link_mysql); | |
21 if (!$db_selected) { | |
22 die ('Can\'t use foo : ' . mysql_error()); | |
23 } | |
24 | |
25 if (!function_exists("GetSQLValueString")) { | |
26 function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") | |
27 { | |
28 $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; | |
29 | |
30 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); | |
31 | |
32 switch ($theType) { | |
33 case "text": | |
34 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; | |
35 break; | |
36 case "long": | |
37 case "int": | |
38 $theValue = ($theValue != "") ? intval($theValue) : "NULL"; | |
39 break; | |
40 case "double": | |
41 $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; | |
42 break; | |
43 case "date": | |
44 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; | |
45 break; | |
46 case "defined": | |
47 $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; | |
48 break; | |
49 } | |
50 return $theValue; | |
51 } | |
52 } | |
53 | |
54 $counter=0; | |
55 $counterError=0; | |
56 $counterIndex1=0; | |
57 $counterIndex2=0; | |
58 $counterMultiIndex=0; | |
59 $counterSingleIndex=0; | |
60 $counterNullIndex=0; | |
61 | |
62 $hasWordInIndex=array(); | |
63 $hasWordInContent=array(); | |
64 | |
65 //echo "<table width=\"100%\" border=\"1\">"; | |
66 $query = sprintf("SELECT * FROM books WHERE `id`=%s ORDER BY `id` ASC", $books_id); | |
67 $result = mysql_query($query); | |
68 while ($row = mysql_fetch_assoc($result)) { | |
69 $startPage = -1; | |
70 $endPage = -1; | |
71 $fileID = $row['id']; | |
72 $indexFilename = "../bookindexxml/".$fileID.".xml"; | |
73 } | |
74 ?> | |
75 | |
76 <html> | |
77 <head> | |
78 <title></title> | |
79 <script src="./jquery-1.10.2.min.js"></script> | |
80 | |
81 </head> | |
82 | |
83 <body> | |
84 | |
85 <table width="100%" border="1" id="tableMain"> </table> | |
86 <script type="text/javascript"> | |
87 if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari | |
88 xmlhttp=new XMLHttpRequest(); | |
89 } else { // code for IE6, IE5 | |
90 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); | |
91 } | |
92 xmlhttp.open("GET","<?php echo $indexFilename; ?>",false); | |
93 xmlhttp.send(); | |
94 xmlDoc=xmlhttp.responseXML; | |
95 | |
96 //window.alert(); | |
97 var xmlcontent = xmlDoc.getElementsByTagName("Item"); | |
98 var length = xmlcontent.length; | |
99 var canNewId = xmlcontent.length+1; | |
100 for (var i = 0; i < length; i++) { | |
101 //document.write(xmlcontent[i].getAttribute('Entry')+"</br>"); | |
102 | |
103 var tableMain=document.getElementById("tableMain"); | |
104 | |
105 var row = tableMain.appendChild(document.createElement("tr")); | |
106 row.id = "tr"+xmlcontent[i].getAttribute('id'); | |
107 | |
108 var newcolumn = document.createElement("td"); | |
109 newcolumn.setAttribute("width","50"); | |
110 row.appendChild(newcolumn).innerHTML=xmlcontent[i].getAttribute('id'); | |
111 | |
112 var newcolumn = document.createElement("td"); | |
113 newcolumn.setAttribute("width","50"); | |
114 row.appendChild(newcolumn).innerHTML="<a href=\"review_index_xml_images.php?books_id=<?php echo $fileID; ?>&pages="+xmlcontent[i].getAttribute('StartPage')+"&entry="+xmlcontent[i].getAttribute('Entry')+"\" target=\"imageWin\">Read</a>"; | |
115 | |
116 var newcolumn = document.createElement("td"); | |
117 newcolumn.id = "tdName"+xmlcontent[i].getAttribute('id'); | |
118 newcolumn.setAttribute("idnum",xmlcontent[i].getAttribute('id')); | |
119 newcolumn.setAttribute("name","tdName"); | |
120 newcolumn.setAttribute("width","300"); | |
121 | |
122 var textString=xmlcontent[i].getAttribute('Entry'); | |
123 var levelNow = parseInt(xmlcontent[i].getAttribute('Level')); | |
124 for ( j=1; j<levelNow; j++ ) { | |
125 textString = "<span name=\"emptyspan" + xmlcontent[i].getAttribute('id') + "\"style=\"padding: 0 40px\"> </span>" + textString; | |
126 } | |
127 row.appendChild(newcolumn).innerHTML=textString; | |
128 | |
129 var newcolumn = document.createElement("td"); | |
130 newcolumn.id = "tdDescription"+xmlcontent[i].getAttribute('id'); | |
131 newcolumn.setAttribute("idnum",xmlcontent[i].getAttribute('id')); | |
132 newcolumn.setAttribute("name","tdDescription"); | |
133 newcolumn.setAttribute("width","200"); | |
134 row.appendChild(newcolumn).innerHTML=""; | |
135 | |
136 | |
137 var newcolumn = document.createElement("td"); | |
138 newcolumn.setAttribute("width","160"); | |
139 row.appendChild(newcolumn).innerHTML="<button onclick=\"moveTop("+xmlcontent[i].getAttribute('id')+")\">←</button>"+ | |
140 "<button onclick=\"moveLow("+xmlcontent[i].getAttribute('id')+")\">→</button> "+ | |
141 "<button onclick=\"addNode("+xmlcontent[i].getAttribute('id')+")\">┼</button> "+ | |
142 "<button onclick=\"deleteNode("+xmlcontent[i].getAttribute('id')+")\">X</button>"; | |
143 | |
144 var newcolumn = document.createElement("td"); | |
145 newcolumn.setAttribute("width","50"); | |
146 row.appendChild(newcolumn).innerHTML=xmlcontent[i].getAttribute('StartRange'); | |
147 | |
148 var newcolumn = document.createElement("td"); | |
149 newcolumn.id = "tdStartPage"+xmlcontent[i].getAttribute('id'); | |
150 newcolumn.setAttribute("idnum",xmlcontent[i].getAttribute('id')); | |
151 newcolumn.setAttribute("name","tdStartPage"); | |
152 newcolumn.setAttribute("width","80"); | |
153 row.appendChild(newcolumn).innerHTML=xmlcontent[i].getAttribute('StartPage'); | |
154 | |
155 var newcolumn = document.createElement("td"); | |
156 newcolumn.id = "tdEndPage"+xmlcontent[i].getAttribute('id'); | |
157 newcolumn.setAttribute("idnum",xmlcontent[i].getAttribute('id')); | |
158 newcolumn.setAttribute("name","tdEndPage"); | |
159 newcolumn.setAttribute("width","80"); | |
160 row.appendChild(newcolumn).innerHTML=xmlcontent[i].getAttribute('EndPage'); | |
161 | |
162 if ( xmlcontent[i].getAttribute('Type') == "UNKNOWN" ) { | |
163 row.setAttribute("bgcolor","FFE4E1"); | |
164 } else if ( xmlcontent[i].getAttribute('Type') == "FROMFULLTEXT" ) { | |
165 row.setAttribute("bgcolor","FFFACD"); | |
166 } else { | |
167 row.setAttribute("bgcolor","FFFFFF"); | |
168 } | |
169 } | |
170 | |
171 function findIndexofId( id ) { | |
172 var length = xmlcontent.length; | |
173 for (var i = 0; i < length; i++) { | |
174 if ( xmlcontent[i].getAttribute('id') == id ) { | |
175 return i; | |
176 } | |
177 } | |
178 } | |
179 | |
180 function addNode( id ) { | |
181 var newElem = xmlDoc.createElement("Item"); | |
182 newElem.setAttribute("id", canNewId); | |
183 newElem.setAttribute("Entry", "Empty"); | |
184 newElem.setAttribute("Level", 1); | |
185 newElem.setAttribute("StartPage", 0); | |
186 newElem.setAttribute("EndPage", 0); | |
187 newElem.setAttribute("StartRange", 0); | |
188 newElem.setAttribute("Type", "MANUAL"); | |
189 newElem.setAttribute("Manually", 1); | |
190 | |
191 xmlDoc.documentElement.insertBefore(newElem, xmlcontent[findIndexofId(id)]); | |
192 | |
193 var tableMain=document.getElementById("tableMain"); | |
194 | |
195 var row = tableMain.insertBefore(document.createElement("tr"), document.getElementById("tr"+id) ); | |
196 row.id = "tr"+canNewId; | |
197 | |
198 var newcolumn = document.createElement("td"); | |
199 newcolumn.setAttribute("width","50"); | |
200 row.appendChild(newcolumn).innerHTML=canNewId; | |
201 | |
202 var newcolumn = document.createElement("td"); | |
203 newcolumn.setAttribute("width","50"); | |
204 row.appendChild(newcolumn).innerHTML="<a href=\"review_index_xml_images.php?books_id=<?php echo $fileID; ?>&pages="+xmlcontent[i].getAttribute('StartPage')+"&entry="+xmlcontent[i].getAttribute('Entry')+"\" target=\"imageWin\">Read</a>"; | |
205 | |
206 var newcolumn = document.createElement("td"); | |
207 newcolumn.id = "tdName"+canNewId; | |
208 newcolumn.setAttribute("idnum",canNewId); | |
209 newcolumn.setAttribute("name","tdName"); | |
210 newcolumn.setAttribute("width","300"); | |
211 row.appendChild(newcolumn).innerHTML=xmlcontent[findIndexofId(canNewId)].getAttribute('Entry'); | |
212 | |
213 var newcolumn = document.createElement("td"); | |
214 newcolumn.id = "tdDescription"+canNewId; | |
215 newcolumn.setAttribute("idnum",canNewId); | |
216 newcolumn.setAttribute("name","tdDescription"); | |
217 newcolumn.setAttribute("width","200"); | |
218 row.appendChild(newcolumn).innerHTML=""; | |
219 | |
220 | |
221 var newcolumn = document.createElement("td"); | |
222 newcolumn.setAttribute("width","160"); | |
223 row.appendChild(newcolumn).innerHTML="<button onclick=\"moveTop("+canNewId+")\">←</button>"+ | |
224 "<button onclick=\"moveLow("+canNewId+")\">→</button> "+ | |
225 "<button onclick=\"addNode("+canNewId+")\">┼</button> "+ | |
226 "<button onclick=\"deleteNode("+canNewId+")\">X</button>"; | |
227 | |
228 var newcolumn = document.createElement("td"); | |
229 newcolumn.setAttribute("width","50"); | |
230 row.appendChild(newcolumn).innerHTML="0"; | |
231 | |
232 var newcolumn = document.createElement("td"); | |
233 newcolumn.id = "tdStartPage"+canNewId; | |
234 newcolumn.setAttribute("idnum",canNewId); | |
235 newcolumn.setAttribute("name","tdStartPage"); | |
236 newcolumn.setAttribute("width","80"); | |
237 row.appendChild(newcolumn).innerHTML="0"; | |
238 | |
239 var newcolumn = document.createElement("td"); | |
240 newcolumn.id = "tdEndPage"+canNewId; | |
241 newcolumn.setAttribute("idnum",canNewId); | |
242 newcolumn.setAttribute("name","tdEndPage"); | |
243 newcolumn.setAttribute("width","80"); | |
244 row.appendChild(newcolumn).innerHTML="0"; | |
245 | |
246 canNewId++; | |
247 } | |
248 | |
249 /* | |
250 $('[name=tdName]').click( function () { | |
251 if ( $("#input"+this.id).length > 0 ) { | |
252 return; | |
253 } | |
254 $('[name=emptyspan'+this.getAttribute('idnum')+']').remove(); | |
255 var startPageValue = this.innerHTML; | |
256 this.innerHTML=""; | |
257 var newTextBox = document.createElement("input"); | |
258 newTextBox.id = "input"+this.id; | |
259 newTextBox.setAttribute("name","inputName"); | |
260 newTextBox.setAttribute("size","20"); | |
261 | |
262 var levelNow = parseInt(xmlcontent[findIndexofId(this.getAttribute('idnum'))].getAttribute('Level')); | |
263 for ( i=1; i<levelNow; i++ ) { | |
264 $(this).html("<span name=\"emptyspan" + this.getAttribute('idnum') + "\"style=\"padding: 0 40px\"> </span>" + $(this).html()); | |
265 } | |
266 this.appendChild(newTextBox).value=startPageValue; | |
267 | |
268 $("#input"+this.id).focus(); | |
269 } ); | |
270 */ | |
271 | |
272 $(document).on("click", "[name=tdName]", function () { | |
273 if ( $("#input"+this.id).length > 0 ) { | |
274 return; | |
275 } | |
276 $('[name=emptyspan'+this.getAttribute('idnum')+']').remove(); | |
277 var startPageValue = this.innerHTML; | |
278 this.innerHTML=""; | |
279 var newTextBox = document.createElement("input"); | |
280 newTextBox.id = "input"+this.id; | |
281 newTextBox.setAttribute("name","inputName"); | |
282 newTextBox.setAttribute("onfocus","this.select()"); | |
283 newTextBox.setAttribute("size","20"); | |
284 | |
285 var levelNow = parseInt(xmlcontent[findIndexofId(this.getAttribute('idnum'))].getAttribute('Level')); | |
286 for ( i=1; i<levelNow; i++ ) { | |
287 $(this).html("<span name=\"emptyspan" + this.getAttribute('idnum') + "\"style=\"padding: 0 40px\"> </span>" + $(this).html()); | |
288 } | |
289 this.appendChild(newTextBox).value=startPageValue; | |
290 | |
291 $("#input"+this.id).focus(); | |
292 } ); | |
293 | |
294 | |
295 $(document).on("click", "[name=tdDescription]", function () { | |
296 //$('[name=tdDescription]').click( function () { | |
297 if ( $("#input"+this.id).length > 0 ) { | |
298 return; | |
299 } | |
300 var startPageValue = this.innerHTML; | |
301 this.innerHTML=""; | |
302 var newTextBox = document.createElement("input"); | |
303 newTextBox.id = "input"+this.id; | |
304 newTextBox.setAttribute("name","inputDescription"); | |
305 newTextBox.setAttribute("onfocus","this.select()"); | |
306 newTextBox.setAttribute("size","25"); | |
307 | |
308 this.appendChild(newTextBox).value=startPageValue; | |
309 | |
310 $("#input"+this.id).focus(); | |
311 } ); | |
312 | |
313 $(document).on("click", "[name=tdStartPage]", function () { | |
314 //$('[name=tdStartPage]').click( function () { | |
315 if ( $("#input"+this.id).length > 0 ) { | |
316 return; | |
317 } | |
318 var startPageValue = this.innerHTML; | |
319 this.innerHTML=""; | |
320 var newTextBox = document.createElement("input"); | |
321 newTextBox.id = "input"+this.id; | |
322 newTextBox.setAttribute("name","inputStartPage"); | |
323 newTextBox.setAttribute("onfocus","this.select()"); | |
324 newTextBox.setAttribute("size","5"); | |
325 | |
326 this.appendChild(newTextBox).value=startPageValue; | |
327 | |
328 $("#input"+this.id).focus(); | |
329 } ); | |
330 | |
331 $(document).on("click", "[name=tdEndPage]", function () { | |
332 //$('[name=tdEndPage]').click( function () { | |
333 if ( $("#input"+this.id).length > 0 ) { | |
334 return; | |
335 } | |
336 var startPageValue = this.innerHTML; | |
337 this.innerHTML=""; | |
338 var newTextBox = document.createElement("input"); | |
339 newTextBox.id = "input"+this.id; | |
340 newTextBox.setAttribute("name","inputEndPage"); | |
341 newTextBox.setAttribute("onfocus","this.select()"); | |
342 newTextBox.setAttribute("size","5"); | |
343 | |
344 this.appendChild(newTextBox).value=startPageValue; | |
345 | |
346 $("#input"+this.id).focus(); | |
347 } ); | |
348 | |
349 $(document).on("keypress", "[name=tdName]", function () { | |
350 //$('[name=tdName]').keypress(function(event) { | |
351 if (event.keyCode == 13) { | |
352 $(this).focusout(); | |
353 } | |
354 }); | |
355 | |
356 $(document).on("keypress", "[name=tdDescription]", function () { | |
357 //$('[name=tdDescription]').keypress(function(event) { | |
358 if (event.keyCode == 13) { | |
359 $(this).focusout(); | |
360 } | |
361 }); | |
362 | |
363 $(document).on("keypress", "[name=tdStartPage]", function () { | |
364 //$('[name=tdStartPage]').keypress(function(event) { | |
365 if (event.keyCode == 13) { | |
366 $(this).focusout(); | |
367 } | |
368 }); | |
369 | |
370 $(document).on("keypress", "[name=tdEndPage]", function () { | |
371 //$('[name=tdEndPage]').keypress(function(event) { | |
372 if (event.keyCode == 13) { | |
373 $(this).focusout(); | |
374 } | |
375 }); | |
376 | |
377 $(document).on("focusout", "[name=tdName]", function () { | |
378 //$('[name=tdName]').focusout( function () { | |
379 var value=$("#input"+this.id).val(); | |
380 | |
381 var levelNow = parseInt(xmlcontent[findIndexofId(this.getAttribute('idnum'))].getAttribute('Level')); | |
382 $(this).html($(this).html() + value); | |
383 | |
384 xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Entry', value); | |
385 xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Manually', 1); | |
386 $("#input"+this.id).remove(); | |
387 }); | |
388 | |
389 $(document).on("focusout", "[name=tdDescription]", function () { | |
390 //$('[name=tdDescription]').focusout( function () { | |
391 var value=$("#input"+this.id).val(); | |
392 this.innerHTML=value; | |
393 xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Description', value); | |
394 xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Manually', 1); | |
395 $("#input"+this.id).remove(); | |
396 }); | |
397 | |
398 $(document).on("focusout", "[name=tdStartPage]", function () { | |
399 //$('[name=tdStartPage]').focusout( function () { | |
400 var value=$("#input"+this.id).val(); | |
401 this.innerHTML=value; | |
402 xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('StartPage', value); | |
403 xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Manually', 1); | |
404 xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Type', "CORRECTED"); | |
405 $("#input"+this.id).remove(); | |
406 }); | |
407 | |
408 $(document).on("focusout", "[name=tdEndPage]", function () { | |
409 //$('[name=tdEndPage]').focusout( function () { | |
410 var value=$("#input"+this.id).val(); | |
411 this.innerHTML=value; | |
412 xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('EndPage', value); | |
413 xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Manually', 1); | |
414 xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Type', "CORRECTED"); | |
415 $("#input"+this.id).remove(); | |
416 }); | |
417 | |
418 function deleteNode( id ) { | |
419 xmlcontent[findIndexofId(id)].parentNode.removeChild(xmlcontent[findIndexofId(id)]); | |
420 $("#tr"+id).remove(); | |
421 } | |
422 | |
423 function moveTop( id ) { | |
424 var levelNow = parseInt(xmlcontent[findIndexofId(id)].getAttribute('Level')); | |
425 if ( levelNow == 1 ) { | |
426 alert("Already the toppest level"); | |
427 return; | |
428 } | |
429 $('[name=emptyspan'+id+']').remove(); | |
430 xmlcontent[findIndexofId(id)].setAttribute('Level', levelNow-1); | |
431 xmlcontent[findIndexofId(id)].setAttribute('Manually', 1); | |
432 levelNow--; | |
433 for ( i=1; i<levelNow; i++ ) { | |
434 $("#tdName"+id).html("<span name=\"emptyspan" + id + "\"style=\"padding: 0 40px\"> </span>" + $("#tdName"+id).html()); | |
435 } | |
436 } | |
437 | |
438 function moveLow( id ) { | |
439 $('[name=emptyspan'+id+']').remove(); | |
440 var levelNow = parseInt(xmlcontent[findIndexofId(id)].getAttribute('Level')); | |
441 xmlcontent[findIndexofId(id)].setAttribute('Level', levelNow+1); | |
442 xmlcontent[findIndexofId(id)].setAttribute('Manually', 1); | |
443 levelNow++; | |
444 for ( i=1; i<levelNow; i++ ) { | |
445 $("#tdName"+id).html("<span name=\"emptyspan" + id + "\"style=\"padding: 0 40px\"> </span>" + $("#tdName"+id).html()); | |
446 } | |
447 } | |
448 | |
449 function DisplayXMLIsland () { | |
450 $.ajax({ | |
451 url : 'save_xml.php', | |
452 async : false, | |
453 type : 'POST', | |
454 data : 'require='+encodeURIComponent((new XMLSerializer()).serializeToString(xmlDoc))+'&filename=<?php echo $indexFilename; ?>' | |
455 }).done(function(result) { | |
456 alert("XML file updated!"); | |
457 }); | |
458 } | |
459 | |
460 /* | |
461 //This is the code for adding a new row | |
462 var newrow = document.createElement("tr"); | |
463 newrow.id = "tr10a"; | |
464 newrow.appendChild(document.createElement("td")).innerText="123"; | |
465 newrow.appendChild(document.createElement("td")).innerText="123"; | |
466 newrow.appendChild(document.createElement("td")).innerText="123"; | |
467 newrow.appendChild(document.createElement("td")).innerText="123"; | |
468 newrow.appendChild(document.createElement("td")).innerText="123"; | |
469 $("#tr10").closest( "tr" ).after(newrow); | |
470 */ | |
471 | |
472 </script> | |
473 | |
474 | |
475 <button onclick="DisplayXMLIsland ()">Save XML file</button> | |
476 | |
477 </body> | |
478 </html> |