Mercurial > hg > LGToc
annotate edit_section_db.php @ 1:1f9d2bfe1d13
handle new section created by user, update sections_index table
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Thu, 19 Mar 2015 18:36:21 +0100 |
| parents | 723a162b6627 |
| children | bd46d26a7b18 |
| rev | line source |
|---|---|
| 0 | 1 <?php |
| 2 include_once('Lib_mb_utf8.php'); | |
| 3 include_once('config.php'); | |
| 4 set_time_limit(0); | |
| 5 ini_set('memory_limit', '-1'); | |
| 6 | |
| 7 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); | |
| 8 mysql_query("SET NAMES utf8"); | |
| 9 | |
| 10 if (!$link_mysql) { | |
| 11 die('Could not connect: ' . mysql_error()); | |
| 12 } | |
| 13 | |
| 14 $db_selected = mysql_select_db($mysql_database, $link_mysql); | |
| 15 if (!$db_selected) { | |
| 16 die ('Can\'t use foo : ' . mysql_error()); | |
| 17 } | |
| 18 function checkSectionInfo($bookId){ | |
| 19 $query="SELECT * FROM sections_versions WHERE books_id=".$bookId." ORDER BY version DESC"; | |
| 20 $result=mysql_query($query); | |
| 21 if(mysql_num_rows($result)==0){ | |
| 22 $row['version']=0; | |
| 23 $row['editor']=""; | |
| 24 $row['date']=""; | |
| 25 return $row; | |
| 26 }else{ | |
| 27 $row=mysql_fetch_assoc($result); | |
| 28 return $row; | |
| 29 } | |
| 30 } | |
| 31 function checkMissingPage($bookInfo,$versionInfo){ | |
| 32 $bookId=$bookInfo['id']; | |
| 33 $bookPage=$bookInfo['line']; | |
| 34 if($versionInfo['version']!=0){ | |
| 35 $table="sections_revisions"; | |
| 36 $condition=" AND versions_id=".$versionInfo['id']." AND deleted=0 "; | |
| 37 $versionId=$versionInfo['id']; | |
| 38 }else{ | |
|
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
39 // $table="sections"; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
40 $table="sections_index"; |
| 0 | 41 $condition=""; |
| 42 } | |
| 43 $query="SELECT * | |
| 44 FROM ".$table." | |
| 45 WHERE books_id=".$bookId." ".$condition." | |
| 46 GROUP BY books_id,start_page,end_page | |
| 47 ORDER BY books_id,start_page,level,end_page"; | |
| 48 $result=mysql_query($query); | |
| 49 $lastPage=1; | |
| 50 $i=0; | |
| 51 $pageArray=array(); | |
| 52 while($row=mysql_fetch_assoc($result)){ | |
| 53 if($row['start_page']-1>$lastPage){ | |
| 54 $pageArray[$i]['start_page']=$lastPage; | |
| 55 $pageArray[$i]['end_page']=$row['start_page']; | |
| 56 //echo $pageArray[$i]['start_page']." ".$pageArray[$i]['end_page']."<br>"; | |
| 57 $i++; | |
| 58 } | |
| 59 $lastPage=$row['end_page']; | |
| 60 } | |
| 61 if($bookPage>$lastPage){ | |
| 62 $pageArray[$i]['start_page']=$lastPage; | |
| 63 $pageArray[$i]['end_page']=$bookPage; | |
| 64 } | |
| 65 return $pageArray; | |
| 66 } | |
| 67 function getSectionArray($bookId,$count,$versionInfo){ | |
| 68 | |
| 69 $str=""; | |
| 70 if($versionInfo['version']!=0){ | |
| 71 $table="sections_revisions"; | |
| 72 $condition="AND deleted=0 "; | |
| 73 $condition=" AND versions_id=".$versionInfo['id']." AND deleted=0 "; | |
| 74 }else{ | |
|
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
75 // $table="sections"; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
76 $table="sections_index"; |
| 0 | 77 $condition=""; |
| 78 } | |
| 79 | |
| 80 // echo "select from ".$table."\n"; | |
| 81 | |
| 82 | |
| 83 $query="SELECT * | |
| 84 FROM ".$table." | |
| 85 WHERE books_id=".$bookId." ".$condition." | |
| 86 GROUP BY books_id, start_page, end_page | |
| 87 HAVING COUNT( * ) >=".$count." | |
| 88 ORDER BY id ASC"; | |
| 89 /*ORDER BY start_page ASC, level ASC, id ASC,end_page DESC";*/ | |
| 90 $result=mysql_query($query); | |
| 91 | |
| 92 $i=0; | |
| 93 $pageArray=array(); | |
| 94 while($row=mysql_fetch_assoc($result)){ | |
| 95 $pageArray[$i]['start_page']=$row['start_page']; | |
| 96 $pageArray[$i]['end_page']=$row['end_page']; | |
| 97 $i++; | |
| 98 } | |
| 99 if($versionInfo['version']!=0){ | |
| 100 $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"; | |
| 101 }else{ | |
|
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
102 //$query="SELECT * FROM sections WHERE books_id=".$bookId." ORDER BY id ASC"; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
103 $query="SELECT * FROM sections_index WHERE books_id=".$bookId." ORDER BY id ASC"; |
| 0 | 104 } |
| 105 $result=mysql_query($query); | |
| 106 | |
| 107 $i=0; | |
| 108 $sectionArray=array(); | |
| 109 while($row=mysql_fetch_assoc($result)){ | |
| 110 $flag=""; | |
| 111 if($i!=sizeof($pageArray) && $pageArray[$i]['start_page']==$row['start_page'] && $pageArray[$i]['end_page']==$row['end_page']){ | |
| 112 $flag="overlapper"; | |
| 113 $i++; | |
| 114 } | |
| 115 if($i!=0 && $pageArray[$i-1]['start_page']==$row['start_page'] && $pageArray[$i-1]['end_page']==$row['end_page']){ | |
| 116 $flag="overlapper"; | |
| 117 } | |
| 118 $row['flag']=$flag; | |
| 119 if(!isset($row['deleted'])){ | |
| 120 $row['deleted']=""; | |
| 121 }else{ | |
| 122 if($row['deleted']==0){ | |
| 123 $row['deleted']=""; | |
| 124 }else{ | |
| 125 $row['deleted']="deleted"; | |
| 126 } | |
| 127 } | |
| 128 $sectionArray[]=$row; | |
| 129 } | |
| 130 return $sectionArray; | |
| 131 } | |
| 132 function updateSectionArray($bookId,$sectionArray,$version,$editor){ | |
|
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
133 |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
134 // TODO: ---transaction --- |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
135 |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
136 |
| 0 | 137 $query="INSERT INTO sections_versions (version,editor,date,books_id) VALUES (".($version+1).",'".$editor."',NOW(),'".$bookId."')"; |
| 138 $result=mysql_query($query); | |
| 139 if(!$result){ | |
| 140 echo json_encode("Failed during inserting sections_version records."); // .mysql_error(); | |
|
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
141 //return; |
| 0 | 142 } |
| 143 $versionId=mysql_insert_id(); | |
| 144 $query="INSERT INTO sections_revisions (name,books_id,section_after,start_page,end_page,level,split_from,sections_id,versions_id,deleted) VALUES "; | |
| 145 foreach($sectionArray as $idx=>$row){ | |
|
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
146 // get the section_id |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
147 $section_id = $row['id']; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
148 $name = $row['name']; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
149 $books_id = sprintf("%05d",$row['booksId']); |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
150 $section_after = $row['sectionAfter']; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
151 $start_page = $row['startPage']; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
152 $end_page = $row['endPage']; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
153 $level = $row['level']; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
154 $split_from = $row['splitFrom']; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
155 $deleted = $row['deleted']; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
156 |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
157 // update to section_index table, which is the up-to-date section table |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
158 if ($section_id == 0) { // section_id = 0 means it is a new record created by user |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
159 // insert new row to section_index table |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
160 $qry = "INSERT INTO sections_index (name,books_id,section_after,start_page,end_page,level,split_from) VALUES |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
161 ('".$name."','".$books_id."','".$section_after."',".$start_page. |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
162 ",".$end_page.",".$level.",".$split_from.")"; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
163 $rst = mysql_query($qry); |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
164 if (!$rst) { |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
165 echo json_encode(mysql_error()); |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
166 } |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
167 $section_id = mysql_insert_id(); |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
168 |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
169 } else { |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
170 // update |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
171 $qry = "UPDATE sections_index SET name='".$name."',books_id='".$books_id."',section_after='".$section_after. |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
172 "',start_page=".$start_page.",end_page=".$end_page.",level=".$level.",split_from=".$split_from." WHERE id=".$section_id; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
173 $rst = mysql_query($qry); |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
174 if (!$rst){ |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
175 echo json_encode(mysql_error()); |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
176 } |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
177 } |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
178 |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
179 $str="("; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
180 $str.="'".$name."',"; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
181 $str.="'".$books_id."',"; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
182 $str.="'".$section_after."',"; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
183 $str.=$start_page.","; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
184 $str.=$end_page.","; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
185 $str.=$level.","; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
186 $str.=$split_from.","; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
187 $str.=$section_id.","; // sections_id should get from section_index table |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
188 $str.=$versionId.","; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
189 $str.=$deleted; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
190 $str.=")"; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
191 if($idx!=sizeof($sectionArray)-1){ |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
192 $str.=", "; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
193 } |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
194 |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
195 |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
196 /* |
| 0 | 197 $str="("; |
| 198 $str.="'".$row['name']."',"; | |
| 199 $str.="'".sprintf("%05d",$row['booksId'])."',"; | |
| 200 $str.="'".$row['sectionAfter']."',"; | |
| 201 $str.=$row['startPage'].","; | |
| 202 $str.=$row['endPage'].","; | |
| 203 $str.=$row['level'].","; | |
| 204 $str.=$row['splitFrom'].","; | |
|
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
205 $str.=$section_id.","; // sections_id should get from section_index table |
| 0 | 206 $str.=$versionId.","; |
| 207 $str.=$row['deleted']; | |
| 208 $str.=")"; | |
| 209 if($idx!=sizeof($sectionArray)-1){ | |
| 210 $str.=", "; | |
| 211 } | |
|
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
212 */ |
| 0 | 213 $query.=$str; |
| 214 } | |
| 215 $result=mysql_query($query); | |
| 216 if(!$result){ | |
| 217 echo json_encode("Failed during inserting sections_revisions records."); // .mysql_error(); | |
| 218 | |
| 219 // Delete the sections_versions for this user | |
| 220 // delete $versionId in table sections_versions | |
| 221 $query="DELETE FROM sections_versions WHERE id=".$versionId; | |
| 222 $result_deleting=mysql_query($query); | |
| 223 if(!$result_deleting){ | |
| 224 echo json_encode("Failed during deleting wrongly inserted sections_version record."); | |
| 225 } | |
| 226 return; | |
| 227 }else{ | |
| 228 echo json_encode("Succeeded."); | |
| 229 } | |
|
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
230 |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
231 |
| 0 | 232 } |
| 233 | |
| 234 | |
| 235 function _select_distinct(){ | |
| 236 /* | |
| 237 $query="SELECT DISTINCT (books_id) FROM sections"; | |
| 238 | |
| 239 $result=mysql_query($query); | |
| 240 if(!$result){ | |
| 241 echo json_encode("Failed during inserting section records."); | |
| 242 return; | |
| 243 }else{ | |
| 244 echo json_encode("Succeeded."); | |
| 245 } | |
| 246 | |
| 247 while($row=mysql_fetch_assoc($result)){ | |
| 248 // echo $row['books_id'], ", "; | |
| 249 } | |
| 250 | |
| 251 echo "section num: ".mysql_num_rows($result); | |
| 252 echo '\n'; | |
| 253 */ | |
| 254 | |
| 255 | |
| 256 //$query="SELECT id FROM books WHERE id NOT IN (SELECT DISTINCT (books_id) FROM sections)"; | |
|
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
257 // $query="SELECT books.id, books.name FROM books LEFT JOIN sections ON books.id=sections.books_id WHERE sections.books_id IS NULL"; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
258 $query="SELECT books.id, books.name FROM books LEFT JOIN sections_index ON books.id=sections_index.books_id WHERE sections_index.books_id IS NULL"; |
| 0 | 259 |
| 260 $result=mysql_query($query); | |
| 261 if(!$result){ | |
| 262 echo json_encode("Failed during querying records."); | |
| 263 return; | |
| 264 } | |
| 265 | |
| 266 echo "missing books num: ".mysql_num_rows($result); | |
| 267 echo '\n'; | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 } | |
| 273 | |
| 274 | |
| 275 | |
| 276 function add_missing_books_to_sections(){ | |
| 277 // find missing books | |
| 278 // Run the following line/mysql to find out what books are missing in sections table | |
| 279 // _select_distinct(); | |
| 280 // Or load missing_books_id.csv | |
| 281 if (($missing_books = fopen("intermediate_results/missing_books.csv", "r")) !== FALSE) { | |
| 282 while (($data = fgetcsv($missing_books, ",")) !== FALSE) { | |
| 283 | |
| 284 $bookId = $data[0]; | |
| 285 $name = $data[1]; | |
| 286 | |
| 287 _add_book_to_sections($name, $bookId); | |
| 288 | |
| 289 } | |
| 290 fclose($missing_books); | |
| 291 } | |
| 292 | |
| 293 } | |
| 294 | |
| 295 | |
| 296 function _add_book_to_sections($name, $bookId){ | |
| 297 | |
| 298 /* | |
| 299 // get Auto_increment | |
| 300 $query = mysql_query("SHOW TABLE STATUS WHERE name='sections'"); | |
| 301 if (mysql_num_rows($query)) { | |
| 302 $result = mysql_fetch_assoc($query); | |
| 303 echo $result['Auto_increment']; | |
| 304 } else {//error | |
| 305 //error control here | |
| 306 echo "error in getting Auto_increment"; | |
| 307 } | |
| 308 */ | |
| 309 | |
| 310 // id should be autoincremated | |
|
1
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
311 // $query="INSERT INTO sections (name,books_id,section_after) VALUES "; |
|
1f9d2bfe1d13
handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
312 $query="INSERT INTO sections_index (name,books_id,section_after) VALUES "; |
| 0 | 313 |
| 314 $str="("; | |
| 315 $str.="'".$name."','"; | |
| 316 $str.=$bookId."',"; | |
| 317 $str.="''"; | |
| 318 $str.=")"; | |
| 319 $query.=$str; | |
| 320 | |
| 321 // echo $name.", ".$bookId."\n"; | |
| 322 | |
| 323 $result=mysql_query($query); | |
| 324 if(!$result){ | |
| 325 echo json_encode("Failed during inserting section records."); | |
| 326 return; | |
| 327 } | |
| 328 // echo mysql_insert_id(); | |
| 329 | |
| 330 } | |
| 331 | |
| 332 | |
| 333 if(isset($_POST['command']) && $_POST['command']!=''){ | |
| 334 $command=$_POST['command']; | |
| 335 if($command=="write"){ | |
| 336 | |
| 337 if(isset($_POST['bookId'])&&isset($_POST['sectionArray'])&&isset($_POST['version'])&&isset($_POST['editor'])&&\ | |
| 338 is_numeric($_POST['bookId']) && sizeof($_POST['sectionArray'])!=0 && is_numeric($_POST['version']) && $_POST['editor']!=""){ | |
| 339 $bookId=$_POST['bookId']; | |
| 340 $sectionArray=$_POST['sectionArray']; | |
| 341 $version=$_POST['version']; | |
| 342 $editor=$_POST['editor']; | |
| 343 | |
| 344 updateSectionArray($bookId,$sectionArray,$version,$editor); | |
| 345 } | |
| 346 else{ | |
| 347 echo json_encode("Editing info not correct."); | |
| 348 | |
| 349 } | |
| 350 } | |
| 351 else{ | |
| 352 echo json_encode("Wrong command."); | |
| 353 return; | |
| 354 } | |
| 355 } | |
| 356 | |
| 357 ?> |
