changeset 3:5d0bfd909857

modify updating to sections_index table when deletion/recovery
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Fri, 20 Mar 2015 15:32:58 +0100
parents bd46d26a7b18
children 373c8ecad8b4
files edit_section_db.php js/check_sections_details.js
diffstat 2 files changed, 36 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/edit_section_db.php	Fri Mar 20 11:32:06 2015 +0100
+++ b/edit_section_db.php	Fri Mar 20 15:32:58 2015 +0100
@@ -176,6 +176,36 @@
 			$section_id = mysql_insert_id();	
 		}
 
+		
+		if ($deleted == 1) {
+			// deleted section from sections_index where id = $section_id
+			$qry = "DELETE FROM sections_index WHERE id=".$section_id;
+			$rst = mysql_query($qry);
+			if (!$rst) {
+				break;	// handle to ROLLBACK
+			}
+
+		} else {
+			$qry = "SELECT * FROM sections_index WHERE id=".$section_id;
+			$rst = mysql_query($qry);
+			if (!$rst) {
+				break;	// handle to ROLLBACK
+			}
+			if (mysql_num_rows($rst) == 0) {
+				$qry = "INSERT INTO sections_index (id,name,books_id,section_after,start_page,end_page,level,split_from) VALUES 
+				(".$section_id.",'".$name."','".$books_id."','".$section_after."',".$start_page.
+				",".$end_page.",".$level.",".$split_from.")";
+				// recover section in sections_index table where id = $section_id
+				$rst = mysql_query($qry);
+				if (!$rst) {
+					break;	// handle to ROLLBACK
+				}	
+			}
+
+		}
+		
+		// query for sections_revisions table
+
 		$str="(";
 		$str.="'".$name."',";
 		$str.="'".$books_id."',";
--- a/js/check_sections_details.js	Fri Mar 20 11:32:06 2015 +0100
+++ b/js/check_sections_details.js	Fri Mar 20 15:32:58 2015 +0100
@@ -362,7 +362,12 @@
 			console.log("empty row: "+name+" -- "+startPage+" -- "+endPage);
 			return; // "continue" in jquery
 		}
-		if($(this).hasClass("deleted")){	deleted="TRUE";}
+		// bug fix: the type of deleted should be 'int' in database, 0 or 1, rather than TRUE
+		if($(this).hasClass("deleted")){	// deleted="TRUE";
+			deleted = 1;
+		} else {
+			deleted = 0;
+		}
 		var id=$(this).children(".hiddenInfo").children(".id").html();
 		var booksId=$(this).children(".hiddenInfo").children(".booksId").html();
 		var sectionAfter=$(this).children(".hiddenInfo").children(".sectionAfter").html()