changeset 3:f196939ccc03

error handle and alert feedback to user. If error occurs, user'll not be halted by the loading page and sections_revisions will recovery to previous version.
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 26 Jan 2015 12:19:39 +0100
parents da5309d54083
children 883ad980a43b
files interface/edit_section_db.php interface/js/check_sections_details.js
diffstat 2 files changed, 28 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/interface/edit_section_db.php	Fri Jan 23 19:00:57 2015 +0100
+++ b/interface/edit_section_db.php	Mon Jan 26 12:19:39 2015 +0100
@@ -75,7 +75,7 @@
 			$condition="";
 		}
 
-		echo "select from ".$table."\n";
+		// echo "select from ".$table."\n";
 
 
         $query="SELECT * 
@@ -100,6 +100,7 @@
                 $query="SELECT * FROM sections WHERE books_id=".$bookId." ORDER BY id ASC";
         }
         $result=mysql_query($query);
+
         $i=0;
 	$sectionArray=array();
         while($row=mysql_fetch_assoc($result)){
@@ -129,7 +130,7 @@
 	$query="INSERT INTO sections_versions (version,editor,date,books_id) VALUES (".($version+1).",'".$editor."',NOW(),'".$bookId."')";	
 	$result=mysql_query($query);
 	if(!$result){
-		echo json_encode("Failed during inserting version records.");
+		echo json_encode("Failed during inserting sections_version records."); // .mysql_error();
 		return;
 	}
 	$versionId=mysql_insert_id();
@@ -154,7 +155,15 @@
 	}
 	$result=mysql_query($query);
 	if(!$result){
-		echo json_encode("Failed during inserting section records.");
+		echo json_encode("Failed during inserting sections_revisions records."); // .mysql_error();
+		
+		// Delete the sections_versions for this user
+		// delete $versionId in table sections_versions
+		$query="DELETE FROM sections_versions WHERE id=".$versionId;
+		$result_deleting=mysql_query($query);
+		if(!$result_deleting){
+			echo json_encode("Failed during deleting wrongly inserted sections_version record.");
+		}
 		return;
 	}else{
 		echo json_encode("Succeeded.");
@@ -188,14 +197,10 @@
 	
 	$result=mysql_query($query);
 	if(!$result){
-		echo json_encode("Failed during inserting section records.");
+		echo json_encode("Failed during querying records.");
 		return;
 	}
 
-	while($row=mysql_fetch_assoc($result)){
-		//echo $row['books_id'], ", ";
-		//echo $row.", ";		
-	}
 	echo "missing books num: ".mysql_num_rows($result);
 	echo '\n';
 
@@ -265,25 +270,7 @@
 if(isset($_POST['command']) && $_POST['command']!=''){
 	$command=$_POST['command'];
 	if($command=="write"){		
-		$bookId=$_POST['bookId'];
-		$sectionArray=$_POST['sectionArray'];
-		$version=$_POST['version'];
-		$editor=$_POST['editor'];
-
-		foreach ($sectionArray as $key => $value) {
-			//echo $key.',';
-			foreach ($value as $key => $inner_val) {
-				//echo $key.",".$inner_val."\n";
-			}
-		}
-		
-		//echo "bookId:".$bookId.", "."editor:".$editor;
-		if(isset($bookId)&&isset($sectionArray)&&isset($version)&&isset($editor)&&\
-			is_numeric($bookId) && sizeof($sectionArray)!=0 && is_numeric($version) && $editor!=""){
-			
-			updateSectionArray($bookId,$sectionArray,$version,$editor);
-		}
-		/*
+	
 		if(isset($_POST['bookId'])&&isset($_POST['sectionArray'])&&isset($_POST['version'])&&isset($_POST['editor'])&&\
 			is_numeric($_POST['bookId']) && sizeof($_POST['sectionArray'])!=0 && is_numeric($_POST['version']) && $_POST['editor']!=""){
 			$bookId=$_POST['bookId'];
@@ -291,10 +278,16 @@
 			$version=$_POST['version'];
 			$editor=$_POST['editor'];
 			
-			echo "updating db...";
-			// updateSectionArray($bookId,$sectionArray,$version,$editor);
+			updateSectionArray($bookId,$sectionArray,$version,$editor);
 		}
-		*/
+		else{
+			echo json_encode("Editing info not correct.");
+
+		}
+	}
+	else{
+		echo json_encode("Wrong command.");
+		return;
 	}
 }
 
--- a/interface/js/check_sections_details.js	Fri Jan 23 19:00:57 2015 +0100
+++ b/interface/js/check_sections_details.js	Mon Jan 26 12:19:39 2015 +0100
@@ -318,8 +318,12 @@
     				href = reg.exec(href);		
 				href=href+"?book_id="+bookId+"&"+count+"&hideDeletedChecked="+hideDeletedChecked+"&editor="+editor;
 				location.href=href; //refresh the page to load the sections saved in db
+				
 			}else{
-				console.log("db not succeeded.");
+				console.log("db failed. log: ", data);
+				alert("Saving failed. You've NOT saved your editing.");
+				alert("Please check your editing again. If the issue remains, please contact us.");
+				$("#loading").hide();
 				
 			}
 		},