annotate edit_section_db.php @ 20:ae69cfe4f9d2 default tip

new version, remove session mechanism, after all server side save data without session in previous version, check_sections_detail.php
author Calvin Yeh <cyeh@mpiwg-berlin.mpg.de>
date Mon, 25 Sep 2017 14:32:47 +0200
parents 0bbf7b85d005
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1 <?php
4
373c8ecad8b4 deploy to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 3
diff changeset
2 include_once('config/Lib_mb_utf8.php');
373c8ecad8b4 deploy to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 3
diff changeset
3 include_once('config/config.php');
0
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
4 set_time_limit(0);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
5 ini_set('memory_limit', '-1');
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
6
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
7 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
8 mysql_query("SET NAMES utf8");
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
9
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
10 if (!$link_mysql) {
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
11 die('Could not connect: ' . mysql_error());
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
12 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
13
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
14 $db_selected = mysql_select_db($mysql_database, $link_mysql);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
15 if (!$db_selected) {
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
16 die ('Can\'t use foo : ' . mysql_error());
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
17 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
18 function checkSectionInfo($bookId){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
19 $query="SELECT * FROM sections_versions WHERE books_id=".$bookId." ORDER BY version DESC";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
20 $result=mysql_query($query);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
21 if(mysql_num_rows($result)==0){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
22 $row['version']=0;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
23 $row['editor']="";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
24 $row['date']="";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
25 return $row;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
26 }else{
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
27 $row=mysql_fetch_assoc($result);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
28 return $row;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
29 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
30 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
31 function checkMissingPage($bookInfo,$versionInfo){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
32 $bookId=$bookInfo['id'];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
33 $bookPage=$bookInfo['line'];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
34 if($versionInfo['version']!=0){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
35 $table="sections_revisions";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
36 $condition=" AND versions_id=".$versionInfo['id']." AND deleted=0 ";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
37 $versionId=$versionInfo['id'];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
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
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
41 $condition="";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
42 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
43 $query="SELECT *
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
44 FROM ".$table."
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
45 WHERE books_id=".$bookId." ".$condition."
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
46 GROUP BY books_id,start_page,end_page
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
47 ORDER BY books_id,start_page,level,end_page";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
48 $result=mysql_query($query);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
49 $lastPage=1;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
50 $i=0;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
51 $pageArray=array();
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
52 while($row=mysql_fetch_assoc($result)){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
53 if($row['start_page']-1>$lastPage){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
54 $pageArray[$i]['start_page']=$lastPage;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
55 $pageArray[$i]['end_page']=$row['start_page'];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
56 //echo $pageArray[$i]['start_page']." ".$pageArray[$i]['end_page']."<br>";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
57 $i++;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
58 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
59 $lastPage=$row['end_page'];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
60 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
61 if($bookPage>$lastPage){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
62 $pageArray[$i]['start_page']=$lastPage;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
63 $pageArray[$i]['end_page']=$bookPage;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
64 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
65 return $pageArray;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
66 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
67 function getSectionArray($bookId,$count,$versionInfo){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
68
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
69 $str="";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
70 if($versionInfo['version']!=0){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
71 $table="sections_revisions";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
72 $condition="AND deleted=0 ";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
73 $condition=" AND versions_id=".$versionInfo['id']." AND deleted=0 ";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
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
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
77 $condition="";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
78 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
79
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
80 $query="SELECT *
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
81 FROM ".$table."
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
82 WHERE books_id=".$bookId." ".$condition."
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
83 GROUP BY books_id, start_page, end_page
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
84 HAVING COUNT( * ) >=".$count."
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
85 ORDER BY id ASC";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
86 /*ORDER BY start_page ASC, level ASC, id ASC,end_page DESC";*/
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
87 $result=mysql_query($query);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
88
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
89 $i=0;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
90 $pageArray=array();
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
91 while($row=mysql_fetch_assoc($result)){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
92 $pageArray[$i]['start_page']=$row['start_page'];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
93 $pageArray[$i]['end_page']=$row['end_page'];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
94 $i++;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
95 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
96 if($versionInfo['version']!=0){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
97 $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";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
98 }else{
1
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
99 $query="SELECT * FROM sections_index WHERE books_id=".$bookId." ORDER BY id ASC";
0
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
100 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
101 $result=mysql_query($query);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
102
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
103 $i=0;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
104 $sectionArray=array();
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
105 while($row=mysql_fetch_assoc($result)){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
106 $flag="";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
107 if($i!=sizeof($pageArray) && $pageArray[$i]['start_page']==$row['start_page'] && $pageArray[$i]['end_page']==$row['end_page']){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
108 $flag="overlapper";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
109 $i++;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
110 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
111 if($i!=0 && $pageArray[$i-1]['start_page']==$row['start_page'] && $pageArray[$i-1]['end_page']==$row['end_page']){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
112 $flag="overlapper";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
113 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
114 $row['flag']=$flag;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
115 if(!isset($row['deleted'])){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
116 $row['deleted']="";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
117 }else{
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
118 if($row['deleted']==0){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
119 $row['deleted']="";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
120 }else{
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
121 $row['deleted']="deleted";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
122 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
123 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
124 $sectionArray[]=$row;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
125 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
126 return $sectionArray;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
127 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
128 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
129
2
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
130 // -- Start Transaction --
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
131 mysql_query("BEGIN");
1
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
132
16
0bbf7b85d005 bug fixed: update section tables
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 7
diff changeset
133 $ver = $version+1;
0bbf7b85d005 bug fixed: update section tables
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 7
diff changeset
134
0bbf7b85d005 bug fixed: update section tables
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 7
diff changeset
135 $query="INSERT INTO sections_versions (version,editor,date,books_id) VALUES (".$ver.",'".$editor."',NOW(),'".$bookId."')";
2
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
136 $result_versions=mysql_query($query);
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
137 if(!$result_versions){
0
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
138 echo json_encode("Failed during inserting sections_version records."); // .mysql_error();
16
0bbf7b85d005 bug fixed: update section tables
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 7
diff changeset
139
0
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
140 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
141 $versionId=mysql_insert_id();
2
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
142
0
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
143 $query="INSERT INTO sections_revisions (name,books_id,section_after,start_page,end_page,level,split_from,sections_id,versions_id,deleted) VALUES ";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
144 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
145 // 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
146 $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
147 $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
148 $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
149 $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
150 $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
151 $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
152 $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
153 $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
154 $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
155
2
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
156 // --- update to section_index table, which is the up-to-date section table ---
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
157 $qry = "";
16
0bbf7b85d005 bug fixed: update section tables
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 7
diff changeset
158 if ($section_id == 0 ) { // section_id = 0 means it is a new record created by user
1
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
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
164 } else {
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
165 // update
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
166 $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
167 "',start_page=".$start_page.",end_page=".$end_page.",level=".$level.",split_from=".$split_from." WHERE id=".$section_id;
2
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
168 }
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
169
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
170 $rst = mysql_query($qry);
7
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
171
2
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
172 if (!$rst) {
7
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
173 error_log("error in querying sections_index table.",0);
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
174
2
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
175 break; // handle to ROLLBACK
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
176 }
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
177
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
178 if ($section_id == 0) {
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
179 // set section_id from section_index if this is a new section
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
180 $section_id = mysql_insert_id();
1
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
181 }
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
182
3
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
183
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
184 if ($deleted == 1) {
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
185 // deleted section from sections_index where id = $section_id
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
186 $qry = "DELETE FROM sections_index WHERE id=".$section_id;
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
187 $rst = mysql_query($qry);
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
188 if (!$rst) {
7
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
189 error_log("error in deleting sections_index table.",0);
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
190
3
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
191 break; // handle to ROLLBACK
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
192 }
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
193
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
194 } else {
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
195 $qry = "SELECT * FROM sections_index WHERE id=".$section_id;
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
196 $rst = mysql_query($qry);
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
197 if (!$rst) {
7
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
198 error_log("error in selecting sections_index table.",0);
3
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
199 break; // handle to ROLLBACK
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
200 }
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
201 if (mysql_num_rows($rst) == 0) {
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
202 $qry = "INSERT INTO sections_index (id,name,books_id,section_after,start_page,end_page,level,split_from) VALUES
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
203 (".$section_id.",'".$name."','".$books_id."','".$section_after."',".$start_page.
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
204 ",".$end_page.",".$level.",".$split_from.")";
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
205 // recover section in sections_index table where id = $section_id
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
206 $rst = mysql_query($qry);
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
207 if (!$rst) {
7
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
208 error_log("error in inserting to sections_index table.".mysql_error(),0);
3
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
209 break; // handle to ROLLBACK
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
210 }
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
211 }
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
212
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
213 }
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
214
5d0bfd909857 modify updating to sections_index table when deletion/recovery
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
215 // query for sections_revisions table
7
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
216
1
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
217 $str="(";
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
218 $str.="'".$name."',";
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
219 $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
220 $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
221 $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
222 $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
223 $str.=$level.",";
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
224 $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
225 $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
226 $str.=$versionId.",";
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
227 $str.=$deleted;
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
228 $str.=")";
7
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
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 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
231 $str.=", ";
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
232 }
7
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
233
2
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
234 $query.=$str;
1
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
235
7
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
236
0
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
237 }
7
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
238
0
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
239 $result=mysql_query($query);
7
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
240 if (!$result) {
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
241 error_log("error in inserting all records to sections_index table.".mysql_error(),0);
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
242 }
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
243
2
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
244 // --- End Transaction ---
16
0bbf7b85d005 bug fixed: update section tables
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 7
diff changeset
245 if ($result and $rst and $result_versions) {
2
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
246 mysql_query("COMMIT");
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
247 echo json_encode("Succeeded."); // important returning info to js
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
248
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
249 } else {
7
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
250 mysql_query("ROLLBACK");
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
251 $err_msg = "Failed during updating sections.";
3abf39f0eb46 bug fixed: sessionId from LGServices
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 4
diff changeset
252 echo json_encode($err_msg);
2
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
253 return;
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
254 }
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
255
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
256 /*
0
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
257 if(!$result){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
258 echo json_encode("Failed during inserting sections_revisions records."); // .mysql_error();
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
259
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
260 // Delete the sections_versions for this user
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
261 // delete $versionId in table sections_versions
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
262 $query="DELETE FROM sections_versions WHERE id=".$versionId;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
263 $result_deleting=mysql_query($query);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
264 if(!$result_deleting){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
265 echo json_encode("Failed during deleting wrongly inserted sections_version record.");
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
266 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
267 return;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
268 }else{
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
269 echo json_encode("Succeeded.");
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
270 }
2
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
271 */
bd46d26a7b18 adding transaction when updating sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 1
diff changeset
272
1
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
273
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
274
0
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
275 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
276
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
277
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
278 function _select_distinct(){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
279 /*
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
280 $query="SELECT DISTINCT (books_id) FROM sections";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
281
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
282 $result=mysql_query($query);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
283 if(!$result){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
284 echo json_encode("Failed during inserting section records.");
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
285 return;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
286 }else{
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
287 echo json_encode("Succeeded.");
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
288 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
289
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
290 while($row=mysql_fetch_assoc($result)){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
291 // echo $row['books_id'], ", ";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
292 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
293
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
294 echo "section num: ".mysql_num_rows($result);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
295 echo '\n';
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
296 */
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
297
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
298
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
299 //$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
300 $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
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
301
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
302 $result=mysql_query($query);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
303 if(!$result){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
304 echo json_encode("Failed during querying records.");
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
305 return;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
306 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
307
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
308 echo "missing books num: ".mysql_num_rows($result);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
309 echo '\n';
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
310
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
311
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
312
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
313
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
314 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
315
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
316
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
317
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
318 function add_missing_books_to_sections(){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
319 // find missing books
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
320 // Run the following line/mysql to find out what books are missing in sections table
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
321 // _select_distinct();
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
322 // Or load missing_books_id.csv
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
323 if (($missing_books = fopen("intermediate_results/missing_books.csv", "r")) !== FALSE) {
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
324 while (($data = fgetcsv($missing_books, ",")) !== FALSE) {
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
325
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
326 $bookId = $data[0];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
327 $name = $data[1];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
328
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
329 _add_book_to_sections($name, $bookId);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
330
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
331 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
332 fclose($missing_books);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
333 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
334
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
335 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
336
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
337
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
338 function _add_book_to_sections($name, $bookId){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
339
1
1f9d2bfe1d13 handle new section created by user, update sections_index table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
340 $query="INSERT INTO sections_index (name,books_id,section_after) VALUES ";
0
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
341
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
342 $str="(";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
343 $str.="'".$name."','";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
344 $str.=$bookId."',";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
345 $str.="''";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
346 $str.=")";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
347 $query.=$str;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
348
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
349 // echo $name.", ".$bookId."\n";
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
350
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
351 $result=mysql_query($query);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
352 if(!$result){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
353 echo json_encode("Failed during inserting section records.");
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
354 return;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
355 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
356 // echo mysql_insert_id();
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
357
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
358 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
359
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
360
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
361 if(isset($_POST['command']) && $_POST['command']!=''){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
362 $command=$_POST['command'];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
363 if($command=="write"){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
364
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
365 if(isset($_POST['bookId'])&&isset($_POST['sectionArray'])&&isset($_POST['version'])&&isset($_POST['editor'])&&\
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
366 is_numeric($_POST['bookId']) && sizeof($_POST['sectionArray'])!=0 && is_numeric($_POST['version']) && $_POST['editor']!=""){
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
367 $bookId=$_POST['bookId'];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
368 $sectionArray=$_POST['sectionArray'];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
369 $version=$_POST['version'];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
370 $editor=$_POST['editor'];
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
371
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
372 updateSectionArray($bookId,$sectionArray,$version,$editor);
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
373 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
374 else{
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
375 echo json_encode("Editing info not correct.");
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
376
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
377 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
378 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
379 else{
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
380 echo json_encode("Wrong command.");
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
381 return;
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
382 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
383 }
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
384
723a162b6627 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
385 ?>