comparison edit_section_db.php @ 16:0bbf7b85d005

bug fixed: update section tables
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Wed, 15 Jul 2015 12:03:22 +0200
parents 3abf39f0eb46
children
comparison
equal deleted inserted replaced
15:e4c5f9cf66cb 16:0bbf7b85d005
128 function updateSectionArray($bookId,$sectionArray,$version,$editor){ 128 function updateSectionArray($bookId,$sectionArray,$version,$editor){
129 129
130 // -- Start Transaction -- 130 // -- Start Transaction --
131 mysql_query("BEGIN"); 131 mysql_query("BEGIN");
132 132
133 $query="INSERT INTO sections_versions (version,editor,date,books_id) VALUES (".($version+1).",'".$editor."',NOW(),'".$bookId."')"; 133 $ver = $version+1;
134
135 $query="INSERT INTO sections_versions (version,editor,date,books_id) VALUES (".$ver.",'".$editor."',NOW(),'".$bookId."')";
134 $result_versions=mysql_query($query); 136 $result_versions=mysql_query($query);
135 if(!$result_versions){ 137 if(!$result_versions){
136 echo json_encode("Failed during inserting sections_version records."); // .mysql_error(); 138 echo json_encode("Failed during inserting sections_version records."); // .mysql_error();
139
137 } 140 }
138 $versionId=mysql_insert_id(); 141 $versionId=mysql_insert_id();
139 142
140 $query="INSERT INTO sections_revisions (name,books_id,section_after,start_page,end_page,level,split_from,sections_id,versions_id,deleted) VALUES "; 143 $query="INSERT INTO sections_revisions (name,books_id,section_after,start_page,end_page,level,split_from,sections_id,versions_id,deleted) VALUES ";
141 foreach($sectionArray as $idx=>$row){ 144 foreach($sectionArray as $idx=>$row){
150 $split_from = $row['splitFrom']; 153 $split_from = $row['splitFrom'];
151 $deleted = $row['deleted']; 154 $deleted = $row['deleted'];
152 155
153 // --- update to section_index table, which is the up-to-date section table --- 156 // --- update to section_index table, which is the up-to-date section table ---
154 $qry = ""; 157 $qry = "";
155 if ($section_id == 0) { // section_id = 0 means it is a new record created by user 158 if ($section_id == 0 ) { // section_id = 0 means it is a new record created by user
156 // insert new row to section_index table 159 // insert new row to section_index table
157 $qry = "INSERT INTO sections_index (name,books_id,section_after,start_page,end_page,level,split_from) VALUES 160 $qry = "INSERT INTO sections_index (name,books_id,section_after,start_page,end_page,level,split_from) VALUES
158 ('".$name."','".$books_id."','".$section_after."',".$start_page. 161 ('".$name."','".$books_id."','".$section_after."',".$start_page.
159 ",".$end_page.",".$level.",".$split_from.")"; 162 ",".$end_page.",".$level.",".$split_from.")";
160 163
237 if (!$result) { 240 if (!$result) {
238 error_log("error in inserting all records to sections_index table.".mysql_error(),0); 241 error_log("error in inserting all records to sections_index table.".mysql_error(),0);
239 } 242 }
240 243
241 // --- End Transaction --- 244 // --- End Transaction ---
242 if ($result and $rst) { 245 if ($result and $rst and $result_versions) {
243 mysql_query("COMMIT"); 246 mysql_query("COMMIT");
244 echo json_encode("Succeeded."); // important returning info to js 247 echo json_encode("Succeeded."); // important returning info to js
245 248
246 } else { 249 } else {
247 mysql_query("ROLLBACK"); 250 mysql_query("ROLLBACK");