Mercurial > hg > extraction-interface
comparison interface/edit_section_db.php @ 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 |
comparison
equal
deleted
inserted
replaced
2:da5309d54083 | 3:f196939ccc03 |
---|---|
73 }else{ | 73 }else{ |
74 $table="sections"; | 74 $table="sections"; |
75 $condition=""; | 75 $condition=""; |
76 } | 76 } |
77 | 77 |
78 echo "select from ".$table."\n"; | 78 // echo "select from ".$table."\n"; |
79 | 79 |
80 | 80 |
81 $query="SELECT * | 81 $query="SELECT * |
82 FROM ".$table." | 82 FROM ".$table." |
83 WHERE books_id=".$bookId." ".$condition." | 83 WHERE books_id=".$bookId." ".$condition." |
98 $query="SELECT id AS revisions_id, name,books_id,section_after,start_page,end_page,level,split_from,sections_id AS id, deleted FROM sections_revisions WHERE versions_id=".$versionInfo['id']." ORDER BY revisions_id ASC"; | 98 $query="SELECT id AS revisions_id, name,books_id,section_after,start_page,end_page,level,split_from,sections_id AS id, deleted FROM sections_revisions WHERE versions_id=".$versionInfo['id']." ORDER BY revisions_id ASC"; |
99 }else{ | 99 }else{ |
100 $query="SELECT * FROM sections WHERE books_id=".$bookId." ORDER BY id ASC"; | 100 $query="SELECT * FROM sections WHERE books_id=".$bookId." ORDER BY id ASC"; |
101 } | 101 } |
102 $result=mysql_query($query); | 102 $result=mysql_query($query); |
103 | |
103 $i=0; | 104 $i=0; |
104 $sectionArray=array(); | 105 $sectionArray=array(); |
105 while($row=mysql_fetch_assoc($result)){ | 106 while($row=mysql_fetch_assoc($result)){ |
106 $flag=""; | 107 $flag=""; |
107 if($i!=sizeof($pageArray) && $pageArray[$i]['start_page']==$row['start_page'] && $pageArray[$i]['end_page']==$row['end_page']){ | 108 if($i!=sizeof($pageArray) && $pageArray[$i]['start_page']==$row['start_page'] && $pageArray[$i]['end_page']==$row['end_page']){ |
127 } | 128 } |
128 function updateSectionArray($bookId,$sectionArray,$version,$editor){ | 129 function updateSectionArray($bookId,$sectionArray,$version,$editor){ |
129 $query="INSERT INTO sections_versions (version,editor,date,books_id) VALUES (".($version+1).",'".$editor."',NOW(),'".$bookId."')"; | 130 $query="INSERT INTO sections_versions (version,editor,date,books_id) VALUES (".($version+1).",'".$editor."',NOW(),'".$bookId."')"; |
130 $result=mysql_query($query); | 131 $result=mysql_query($query); |
131 if(!$result){ | 132 if(!$result){ |
132 echo json_encode("Failed during inserting version records."); | 133 echo json_encode("Failed during inserting sections_version records."); // .mysql_error(); |
133 return; | 134 return; |
134 } | 135 } |
135 $versionId=mysql_insert_id(); | 136 $versionId=mysql_insert_id(); |
136 $query="INSERT INTO sections_revisions (name,books_id,section_after,start_page,end_page,level,split_from,sections_id,versions_id,deleted) VALUES "; | 137 $query="INSERT INTO sections_revisions (name,books_id,section_after,start_page,end_page,level,split_from,sections_id,versions_id,deleted) VALUES "; |
137 foreach($sectionArray as $idx=>$row){ | 138 foreach($sectionArray as $idx=>$row){ |
152 } | 153 } |
153 $query.=$str; | 154 $query.=$str; |
154 } | 155 } |
155 $result=mysql_query($query); | 156 $result=mysql_query($query); |
156 if(!$result){ | 157 if(!$result){ |
157 echo json_encode("Failed during inserting section records."); | 158 echo json_encode("Failed during inserting sections_revisions records."); // .mysql_error(); |
159 | |
160 // Delete the sections_versions for this user | |
161 // delete $versionId in table sections_versions | |
162 $query="DELETE FROM sections_versions WHERE id=".$versionId; | |
163 $result_deleting=mysql_query($query); | |
164 if(!$result_deleting){ | |
165 echo json_encode("Failed during deleting wrongly inserted sections_version record."); | |
166 } | |
158 return; | 167 return; |
159 }else{ | 168 }else{ |
160 echo json_encode("Succeeded."); | 169 echo json_encode("Succeeded."); |
161 } | 170 } |
162 } | 171 } |
186 //$query="SELECT id FROM books WHERE id NOT IN (SELECT DISTINCT (books_id) FROM sections)"; | 195 //$query="SELECT id FROM books WHERE id NOT IN (SELECT DISTINCT (books_id) FROM sections)"; |
187 $query="SELECT books.id, books.name FROM books LEFT JOIN sections ON books.id=sections.books_id WHERE sections.books_id IS NULL"; | 196 $query="SELECT books.id, books.name FROM books LEFT JOIN sections ON books.id=sections.books_id WHERE sections.books_id IS NULL"; |
188 | 197 |
189 $result=mysql_query($query); | 198 $result=mysql_query($query); |
190 if(!$result){ | 199 if(!$result){ |
191 echo json_encode("Failed during inserting section records."); | 200 echo json_encode("Failed during querying records."); |
192 return; | 201 return; |
193 } | 202 } |
194 | 203 |
195 while($row=mysql_fetch_assoc($result)){ | |
196 //echo $row['books_id'], ", "; | |
197 //echo $row.", "; | |
198 } | |
199 echo "missing books num: ".mysql_num_rows($result); | 204 echo "missing books num: ".mysql_num_rows($result); |
200 echo '\n'; | 205 echo '\n'; |
201 | 206 |
202 | 207 |
203 | 208 |
263 | 268 |
264 | 269 |
265 if(isset($_POST['command']) && $_POST['command']!=''){ | 270 if(isset($_POST['command']) && $_POST['command']!=''){ |
266 $command=$_POST['command']; | 271 $command=$_POST['command']; |
267 if($command=="write"){ | 272 if($command=="write"){ |
268 $bookId=$_POST['bookId']; | 273 |
269 $sectionArray=$_POST['sectionArray']; | |
270 $version=$_POST['version']; | |
271 $editor=$_POST['editor']; | |
272 | |
273 foreach ($sectionArray as $key => $value) { | |
274 //echo $key.','; | |
275 foreach ($value as $key => $inner_val) { | |
276 //echo $key.",".$inner_val."\n"; | |
277 } | |
278 } | |
279 | |
280 //echo "bookId:".$bookId.", "."editor:".$editor; | |
281 if(isset($bookId)&&isset($sectionArray)&&isset($version)&&isset($editor)&&\ | |
282 is_numeric($bookId) && sizeof($sectionArray)!=0 && is_numeric($version) && $editor!=""){ | |
283 | |
284 updateSectionArray($bookId,$sectionArray,$version,$editor); | |
285 } | |
286 /* | |
287 if(isset($_POST['bookId'])&&isset($_POST['sectionArray'])&&isset($_POST['version'])&&isset($_POST['editor'])&&\ | 274 if(isset($_POST['bookId'])&&isset($_POST['sectionArray'])&&isset($_POST['version'])&&isset($_POST['editor'])&&\ |
288 is_numeric($_POST['bookId']) && sizeof($_POST['sectionArray'])!=0 && is_numeric($_POST['version']) && $_POST['editor']!=""){ | 275 is_numeric($_POST['bookId']) && sizeof($_POST['sectionArray'])!=0 && is_numeric($_POST['version']) && $_POST['editor']!=""){ |
289 $bookId=$_POST['bookId']; | 276 $bookId=$_POST['bookId']; |
290 $sectionArray=$_POST['sectionArray']; | 277 $sectionArray=$_POST['sectionArray']; |
291 $version=$_POST['version']; | 278 $version=$_POST['version']; |
292 $editor=$_POST['editor']; | 279 $editor=$_POST['editor']; |
293 | 280 |
294 echo "updating db..."; | 281 updateSectionArray($bookId,$sectionArray,$version,$editor); |
295 // updateSectionArray($bookId,$sectionArray,$version,$editor); | 282 } |
296 } | 283 else{ |
297 */ | 284 echo json_encode("Editing info not correct."); |
285 | |
286 } | |
287 } | |
288 else{ | |
289 echo json_encode("Wrong command."); | |
290 return; | |
298 } | 291 } |
299 } | 292 } |
300 | 293 |
301 ?> | 294 ?> |