diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/interface/review_index_xml_js.php	Mon Jan 19 17:13:49 2015 +0100
@@ -0,0 +1,478 @@
+<?php
+header("Content-Type: text/html;charset=utf-8");
+
+if (isset($_GET['books_id'])) {
+	$books_id = $_GET['books_id'];
+}
+
+include_once('./Lib_mb_utf8.php');
+   
+set_time_limit(0);
+ini_set('memory_limit', '-1');
+
+$link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password);
+mysql_query("SET NAMES utf8");
+
+if (!$link_mysql) {
+    die('Could not connect: ' . mysql_error());
+}
+
+$db_selected = mysql_select_db($mysql_database, $link_mysql);
+if (!$db_selected) {
+    die ('Can\'t use foo : ' . mysql_error());
+}
+
+if (!function_exists("GetSQLValueString")) {
+function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
+{
+  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
+
+  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
+
+  switch ($theType) {
+    case "text":
+      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
+      break;    
+    case "long":
+    case "int":
+      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
+      break;
+    case "double":
+      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
+      break;
+    case "date":
+      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
+      break;
+    case "defined":
+      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
+      break;
+  }
+  return $theValue;
+}
+}
+
+$counter=0;
+$counterError=0;
+$counterIndex1=0;
+$counterIndex2=0;
+$counterMultiIndex=0;
+$counterSingleIndex=0;
+$counterNullIndex=0;
+
+$hasWordInIndex=array();
+$hasWordInContent=array();
+
+//echo "<table width=\"100%\" border=\"1\">";
+$query = sprintf("SELECT * FROM books WHERE `id`=%s ORDER BY `id` ASC", $books_id);
+$result = mysql_query($query);
+while ($row = mysql_fetch_assoc($result)) {
+	$startPage = -1;
+	$endPage = -1;
+	$fileID = $row['id'];
+	$indexFilename = "../bookindexxml/".$fileID.".xml";
+}
+?>
+
+<html>
+<head>
+<title></title>
+<script src="./jquery-1.10.2.min.js"></script>
+
+</head>
+
+<body>
+
+<table width="100%" border="1" id="tableMain"> </table>
+<script type="text/javascript">
+if (window.XMLHttpRequest) {	// code for IE7+, Firefox, Chrome, Opera, Safari
+	xmlhttp=new XMLHttpRequest();
+} else {						// code for IE6, IE5
+	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
+}
+xmlhttp.open("GET","<?php echo $indexFilename; ?>",false);
+xmlhttp.send();
+xmlDoc=xmlhttp.responseXML;
+
+//window.alert();
+var xmlcontent = xmlDoc.getElementsByTagName("Item");
+var length = xmlcontent.length;
+var canNewId = xmlcontent.length+1;
+for (var i = 0; i < length; i++) {
+	//document.write(xmlcontent[i].getAttribute('Entry')+"</br>");
+	
+	var tableMain=document.getElementById("tableMain");
+	
+	var row = tableMain.appendChild(document.createElement("tr"));
+	row.id = "tr"+xmlcontent[i].getAttribute('id');
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.setAttribute("width","50");
+	row.appendChild(newcolumn).innerHTML=xmlcontent[i].getAttribute('id');
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.setAttribute("width","50");
+	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>";
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.id = "tdName"+xmlcontent[i].getAttribute('id');
+	newcolumn.setAttribute("idnum",xmlcontent[i].getAttribute('id'));
+	newcolumn.setAttribute("name","tdName");
+	newcolumn.setAttribute("width","300");
+	
+	var textString=xmlcontent[i].getAttribute('Entry');
+	var levelNow = parseInt(xmlcontent[i].getAttribute('Level'));
+	for ( j=1; j<levelNow; j++ ) {
+		textString = "<span name=\"emptyspan" + xmlcontent[i].getAttribute('id') + "\"style=\"padding: 0 40px\">&nbsp;</span>" + textString;
+	}
+	row.appendChild(newcolumn).innerHTML=textString;
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.id = "tdDescription"+xmlcontent[i].getAttribute('id');
+	newcolumn.setAttribute("idnum",xmlcontent[i].getAttribute('id'));
+	newcolumn.setAttribute("name","tdDescription");
+	newcolumn.setAttribute("width","200");
+	row.appendChild(newcolumn).innerHTML="";
+	
+
+	var newcolumn = document.createElement("td");
+	newcolumn.setAttribute("width","160");
+	row.appendChild(newcolumn).innerHTML="<button onclick=\"moveTop("+xmlcontent[i].getAttribute('id')+")\">←</button>"+
+	"<button onclick=\"moveLow("+xmlcontent[i].getAttribute('id')+")\">→</button>  "+
+	"<button onclick=\"addNode("+xmlcontent[i].getAttribute('id')+")\">┼</button>  "+
+	"<button onclick=\"deleteNode("+xmlcontent[i].getAttribute('id')+")\">X</button>";
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.setAttribute("width","50");
+	row.appendChild(newcolumn).innerHTML=xmlcontent[i].getAttribute('StartRange');
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.id = "tdStartPage"+xmlcontent[i].getAttribute('id');
+	newcolumn.setAttribute("idnum",xmlcontent[i].getAttribute('id'));
+	newcolumn.setAttribute("name","tdStartPage");
+	newcolumn.setAttribute("width","80");
+	row.appendChild(newcolumn).innerHTML=xmlcontent[i].getAttribute('StartPage');
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.id = "tdEndPage"+xmlcontent[i].getAttribute('id');
+	newcolumn.setAttribute("idnum",xmlcontent[i].getAttribute('id'));
+	newcolumn.setAttribute("name","tdEndPage");
+	newcolumn.setAttribute("width","80");
+	row.appendChild(newcolumn).innerHTML=xmlcontent[i].getAttribute('EndPage');
+	
+	if ( xmlcontent[i].getAttribute('Type') == "UNKNOWN" ) {
+		row.setAttribute("bgcolor","FFE4E1");
+	} else if ( xmlcontent[i].getAttribute('Type') == "FROMFULLTEXT" ) {
+		row.setAttribute("bgcolor","FFFACD");
+	} else {
+		row.setAttribute("bgcolor","FFFFFF");
+	}
+}
+
+function findIndexofId( id ) {
+	var length = xmlcontent.length;
+	for (var i = 0; i < length; i++) {
+		if ( xmlcontent[i].getAttribute('id') == id ) {
+			return i;
+		}
+	}
+}
+
+function addNode( id ) {
+	var newElem = xmlDoc.createElement("Item");
+	newElem.setAttribute("id", canNewId);
+	newElem.setAttribute("Entry", "Empty");
+	newElem.setAttribute("Level", 1);
+	newElem.setAttribute("StartPage", 0);
+	newElem.setAttribute("EndPage", 0);
+	newElem.setAttribute("StartRange", 0);
+	newElem.setAttribute("Type", "MANUAL");
+	newElem.setAttribute("Manually", 1);
+	
+	xmlDoc.documentElement.insertBefore(newElem, xmlcontent[findIndexofId(id)]);
+	
+	var tableMain=document.getElementById("tableMain");
+	
+	var row = tableMain.insertBefore(document.createElement("tr"), document.getElementById("tr"+id) );
+	row.id = "tr"+canNewId;
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.setAttribute("width","50");
+	row.appendChild(newcolumn).innerHTML=canNewId;
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.setAttribute("width","50");
+	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>";
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.id = "tdName"+canNewId;
+	newcolumn.setAttribute("idnum",canNewId);
+	newcolumn.setAttribute("name","tdName");
+	newcolumn.setAttribute("width","300");
+	row.appendChild(newcolumn).innerHTML=xmlcontent[findIndexofId(canNewId)].getAttribute('Entry');
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.id = "tdDescription"+canNewId;
+	newcolumn.setAttribute("idnum",canNewId);
+	newcolumn.setAttribute("name","tdDescription");
+	newcolumn.setAttribute("width","200");
+	row.appendChild(newcolumn).innerHTML="";
+	
+
+	var newcolumn = document.createElement("td");
+	newcolumn.setAttribute("width","160");
+	row.appendChild(newcolumn).innerHTML="<button onclick=\"moveTop("+canNewId+")\">←</button>"+
+	"<button onclick=\"moveLow("+canNewId+")\">→</button>  "+
+	"<button onclick=\"addNode("+canNewId+")\">┼</button>  "+
+	"<button onclick=\"deleteNode("+canNewId+")\">X</button>";
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.setAttribute("width","50");
+	row.appendChild(newcolumn).innerHTML="0";
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.id = "tdStartPage"+canNewId;
+	newcolumn.setAttribute("idnum",canNewId);
+	newcolumn.setAttribute("name","tdStartPage");
+	newcolumn.setAttribute("width","80");
+	row.appendChild(newcolumn).innerHTML="0";
+	
+	var newcolumn = document.createElement("td");
+	newcolumn.id = "tdEndPage"+canNewId;
+	newcolumn.setAttribute("idnum",canNewId);
+	newcolumn.setAttribute("name","tdEndPage");
+	newcolumn.setAttribute("width","80");
+	row.appendChild(newcolumn).innerHTML="0";
+	
+	canNewId++;
+}
+ 
+ /*
+$('[name=tdName]').click( function () {
+	if ( $("#input"+this.id).length > 0 ) {
+		return;
+	}
+	$('[name=emptyspan'+this.getAttribute('idnum')+']').remove();
+	var startPageValue = this.innerHTML;
+	this.innerHTML="";
+	var newTextBox = document.createElement("input");
+	newTextBox.id = "input"+this.id;
+	newTextBox.setAttribute("name","inputName");
+	newTextBox.setAttribute("size","20");
+	
+	var levelNow = parseInt(xmlcontent[findIndexofId(this.getAttribute('idnum'))].getAttribute('Level'));
+	for ( i=1; i<levelNow; i++ ) {
+		$(this).html("<span name=\"emptyspan" + this.getAttribute('idnum') + "\"style=\"padding: 0 40px\">&nbsp;</span>" + $(this).html());
+	}
+	this.appendChild(newTextBox).value=startPageValue;
+	
+	$("#input"+this.id).focus();
+} );
+*/
+
+$(document).on("click", "[name=tdName]", function () {
+	if ( $("#input"+this.id).length > 0 ) {
+		return;
+	}
+	$('[name=emptyspan'+this.getAttribute('idnum')+']').remove();
+	var startPageValue = this.innerHTML;
+	this.innerHTML="";
+	var newTextBox = document.createElement("input");
+	newTextBox.id = "input"+this.id;
+	newTextBox.setAttribute("name","inputName");
+	newTextBox.setAttribute("onfocus","this.select()");
+	newTextBox.setAttribute("size","20");
+	
+	var levelNow = parseInt(xmlcontent[findIndexofId(this.getAttribute('idnum'))].getAttribute('Level'));
+	for ( i=1; i<levelNow; i++ ) {
+		$(this).html("<span name=\"emptyspan" + this.getAttribute('idnum') + "\"style=\"padding: 0 40px\">&nbsp;</span>" + $(this).html());
+	}
+	this.appendChild(newTextBox).value=startPageValue;
+	
+	$("#input"+this.id).focus();
+} );
+
+
+$(document).on("click", "[name=tdDescription]", function () {
+//$('[name=tdDescription]').click( function () {
+	if ( $("#input"+this.id).length > 0 ) {
+		return;
+	}
+	var startPageValue = this.innerHTML;
+	this.innerHTML="";
+	var newTextBox = document.createElement("input");
+	newTextBox.id = "input"+this.id;
+	newTextBox.setAttribute("name","inputDescription");
+	newTextBox.setAttribute("onfocus","this.select()");
+	newTextBox.setAttribute("size","25");
+	
+	this.appendChild(newTextBox).value=startPageValue;
+	
+	$("#input"+this.id).focus();
+} );
+
+$(document).on("click", "[name=tdStartPage]", function () {
+//$('[name=tdStartPage]').click( function () {
+	if ( $("#input"+this.id).length > 0 ) {
+		return;
+	}
+	var startPageValue = this.innerHTML;
+	this.innerHTML="";
+	var newTextBox = document.createElement("input");
+	newTextBox.id = "input"+this.id;
+	newTextBox.setAttribute("name","inputStartPage");
+	newTextBox.setAttribute("onfocus","this.select()");
+	newTextBox.setAttribute("size","5");
+	
+	this.appendChild(newTextBox).value=startPageValue;
+	
+	$("#input"+this.id).focus();
+} );
+ 
+$(document).on("click", "[name=tdEndPage]", function () {
+//$('[name=tdEndPage]').click( function () {
+	if ( $("#input"+this.id).length > 0 ) {
+		return;
+	}
+	var startPageValue = this.innerHTML;
+	this.innerHTML="";
+	var newTextBox = document.createElement("input");
+	newTextBox.id = "input"+this.id;
+	newTextBox.setAttribute("name","inputEndPage");
+	newTextBox.setAttribute("onfocus","this.select()");
+	newTextBox.setAttribute("size","5");
+	
+	this.appendChild(newTextBox).value=startPageValue;
+	
+	$("#input"+this.id).focus();
+} );
+	
+$(document).on("keypress", "[name=tdName]", function () {
+//$('[name=tdName]').keypress(function(event) {
+	if (event.keyCode == 13) {
+		$(this).focusout();
+	}
+});
+
+$(document).on("keypress", "[name=tdDescription]", function () {
+//$('[name=tdDescription]').keypress(function(event) {
+	if (event.keyCode == 13) {
+		$(this).focusout();
+	}
+});
+
+$(document).on("keypress", "[name=tdStartPage]", function () {
+//$('[name=tdStartPage]').keypress(function(event) {
+	if (event.keyCode == 13) {
+		$(this).focusout();
+	}
+});
+
+$(document).on("keypress", "[name=tdEndPage]", function () {
+//$('[name=tdEndPage]').keypress(function(event) {
+	if (event.keyCode == 13) {
+		$(this).focusout();
+	}
+});
+	
+$(document).on("focusout", "[name=tdName]", function () {
+//$('[name=tdName]').focusout( function () {
+	var value=$("#input"+this.id).val();
+	
+	var levelNow = parseInt(xmlcontent[findIndexofId(this.getAttribute('idnum'))].getAttribute('Level'));
+	$(this).html($(this).html() + value);
+	
+	xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Entry', value);
+	xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Manually', 1);
+	$("#input"+this.id).remove();
+});
+
+$(document).on("focusout", "[name=tdDescription]", function () {
+//$('[name=tdDescription]').focusout( function () {
+	var value=$("#input"+this.id).val();
+	this.innerHTML=value;
+	xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Description', value);
+	xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Manually', 1);
+	$("#input"+this.id).remove();
+});
+
+$(document).on("focusout", "[name=tdStartPage]", function () {
+//$('[name=tdStartPage]').focusout( function () {
+	var value=$("#input"+this.id).val();
+	this.innerHTML=value;
+	xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('StartPage', value);
+	xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Manually', 1);
+	xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Type', "CORRECTED");
+	$("#input"+this.id).remove();
+});
+
+$(document).on("focusout", "[name=tdEndPage]", function () {
+//$('[name=tdEndPage]').focusout( function () {
+	var value=$("#input"+this.id).val();
+	this.innerHTML=value;
+	xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('EndPage', value);
+	xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Manually', 1);
+	xmlcontent[findIndexofId(this.getAttribute('idnum'))].setAttribute('Type', "CORRECTED");
+	$("#input"+this.id).remove();
+});
+
+function deleteNode( id ) {
+	xmlcontent[findIndexofId(id)].parentNode.removeChild(xmlcontent[findIndexofId(id)]);
+	$("#tr"+id).remove();
+}
+
+function moveTop( id ) {
+	var levelNow = parseInt(xmlcontent[findIndexofId(id)].getAttribute('Level'));
+	if ( levelNow == 1 ) {
+		alert("Already the toppest level");
+		return;
+	}
+	$('[name=emptyspan'+id+']').remove();
+	xmlcontent[findIndexofId(id)].setAttribute('Level', levelNow-1);
+	xmlcontent[findIndexofId(id)].setAttribute('Manually', 1);
+	levelNow--;
+	for ( i=1; i<levelNow; i++ ) {
+		$("#tdName"+id).html("<span name=\"emptyspan" + id + "\"style=\"padding: 0 40px\">&nbsp;</span>" + $("#tdName"+id).html());
+	}
+}
+
+function moveLow( id ) {
+	$('[name=emptyspan'+id+']').remove();
+	var levelNow = parseInt(xmlcontent[findIndexofId(id)].getAttribute('Level'));
+	xmlcontent[findIndexofId(id)].setAttribute('Level', levelNow+1);
+	xmlcontent[findIndexofId(id)].setAttribute('Manually', 1);
+	levelNow++;
+	for ( i=1; i<levelNow; i++ ) {
+		$("#tdName"+id).html("<span name=\"emptyspan" + id + "\"style=\"padding: 0 40px\">&nbsp;</span>" + $("#tdName"+id).html());
+	}
+}
+
+function DisplayXMLIsland () {
+	$.ajax({
+		url : 'save_xml.php',
+		async : false,
+		type : 'POST',
+		data : 'require='+encodeURIComponent((new XMLSerializer()).serializeToString(xmlDoc))+'&filename=<?php echo $indexFilename; ?>'
+	}).done(function(result) {
+		alert("XML file updated!");
+	});
+}
+	
+/*
+//This is the code for adding a new row
+var newrow = document.createElement("tr");
+newrow.id = "tr10a";
+newrow.appendChild(document.createElement("td")).innerText="123";
+newrow.appendChild(document.createElement("td")).innerText="123";
+newrow.appendChild(document.createElement("td")).innerText="123";
+newrow.appendChild(document.createElement("td")).innerText="123";
+newrow.appendChild(document.createElement("td")).innerText="123";
+$("#tr10").closest( "tr" ).after(newrow);
+*/
+
+</script>
+
+
+<button onclick="DisplayXMLIsland ()">Save XML file</button>
+	
+</body>
+</html>