Mercurial > hg > LGToc
comparison check_sections_details2.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 | |
| children |
comparison
equal
deleted
inserted
replaced
| 19:c0eccf597fcc | 20:ae69cfe4f9d2 |
|---|---|
| 1 <?php | |
| 2 include_once('config/Lib_mb_utf8.php'); | |
| 3 include_once('config/config.php'); | |
| 4 include_once('edit_section_db.php'); | |
| 5 set_time_limit(0); | |
| 6 ini_set('memory_limit', '-1'); | |
| 7 | |
| 8 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); | |
| 9 mysql_query("SET NAMES utf8"); | |
| 10 | |
| 11 if (!$link_mysql) { | |
| 12 die('Could not connect: ' . mysql_error()); | |
| 13 } | |
| 14 | |
| 15 $db_selected = mysql_select_db($mysql_database, $link_mysql); | |
| 16 | |
| 17 if (!$db_selected) { | |
| 18 die ('Can\'t use foo : ' . mysql_error()); | |
| 19 } | |
| 20 | |
| 21 function getBookInfo($bookId){ | |
| 22 | |
| 23 $query="SELECT * FROM books WHERE id=".$bookId; | |
| 24 $result=mysql_query($query); | |
| 25 $bookInfo=mysql_fetch_assoc($result); | |
| 26 return $bookInfo; | |
| 27 } | |
| 28 | |
| 29 function printBookInfo($bookInfo){ | |
| 30 | |
| 31 $str="<table class='bookInfo'><tr> | |
| 32 <th class='bookId'>book id</th> | |
| 33 <th class='bookName'>book name</th> | |
| 34 <th class='level1'>level1</th> | |
| 35 <th class='level2'>level2</th> | |
| 36 <th class='period'>period</th> | |
| 37 <th class='bookId'>pages</th> | |
| 38 <th class='bookId'>version</th> | |
| 39 <th class='bookName'>editor</th> | |
| 40 <th class='bookName'>date</th></tr>"; | |
| 41 | |
| 42 $str.="<tr>"; | |
| 43 $str.="<td>".$bookInfo['id']; | |
| 44 $str.="</td><td>".$bookInfo['name']; | |
| 45 $str.="</td><td>".$bookInfo['level1']; | |
| 46 $str.="</td><td>".$bookInfo['level2']; | |
| 47 $str.="</td><td>".$bookInfo['period']; | |
| 48 $str.="</td><td>".$bookInfo['line']; | |
| 49 $str.="</td><td>".$bookInfo['version']; | |
| 50 $str.="</td><td>".$bookInfo['editor']; | |
| 51 $str.="</td><td>".$bookInfo['date']; | |
| 52 $str.="</td></tr></table>"; | |
| 53 | |
| 54 echo $str; | |
| 55 } | |
| 56 | |
| 57 function printSectionArray($sectionArray,$missingPageArray){ | |
| 58 $str="<div id='bookContainer'>"; | |
| 59 echo $str; | |
| 60 $i=0; | |
| 61 foreach($sectionArray as $idx=>$row){ | |
| 62 /* | |
| 63 $flag=""; | |
| 64 if($i!=sizeof($pageArray) && $pageArray[$i]['start_page']==$row['start_page'] && $pageArray[$i]['end_page']==$row['end_page']){ | |
| 65 $flag="overlapper"; | |
| 66 $i++; | |
| 67 } | |
| 68 if($i!=0 && $pageArray[$i-1]['start_page']==$row['start_page'] && $pageArray[$i-1]['end_page']==$row['end_page']){ | |
| 69 $flag="overlapper"; | |
| 70 }*/ | |
| 71 if(!($idx!=0 && $sectionArray[$idx-1]['start_page']==$row['start_page'] && $sectionArray[$idx-1]['end_page']==$row['end_page']) | |
| 72 && $i<sizeof($missingPageArray) && $missingPageArray[$i]['end_page']==$row['start_page']){ | |
| 73 $str="<div class='missingPageContainer'><div class='missingPage'>Missing pages: ".$missingPageArray[$i]['start_page']." - ".$missingPageArray[$i]['end_page']."</div></div>"; | |
| 74 //$str.="<br>"; | |
| 75 $i++; | |
| 76 echo $str; | |
| 77 } | |
| 78 | |
| 79 $str="<div class='entry level".$row['level']." ".$row['flag']." ".$row['deleted']."'>"; | |
| 80 $str.="<div class='hiddenInfo'>"; | |
| 81 $str.="<div class='id'>".$row['id']."</div>"; | |
| 82 $str.="<div class='booksId'>".sprintf("%05d",$row['books_id'])."</div>"; | |
| 83 $str.="<div class='splitFrom'>".$row['split_from']."</div>"; | |
| 84 $str.="<div class='sectionAfter'>".$row['section_after']."</div>"; | |
| 85 $str.="</div>";//end of hiddenInfo | |
| 86 $str.="<div class='sequence'>".($idx+1)."</div>"; | |
| 87 $str.="<div class='name'>".$row['name']."</div>"; | |
| 88 $str.="<div class='page'>"; | |
| 89 $str.="<div class='startPage'>".$row['start_page']."</div>"; | |
| 90 $str.=" - "; | |
| 91 $str.="<div class='endPage'>".$row['end_page']."</div>"; | |
| 92 $str.="</div>";//end of page | |
| 93 $str.="</div>"; //end of class entry | |
| 94 echo $str; | |
| 95 | |
| 96 } | |
| 97 if($i<sizeof($missingPageArray)){ | |
| 98 $str="<div class='missingPage'>Missing pages: ".$missingPageArray[$i]['start_page']." - ".$missingPageArray[$i]['end_page']."</div>"; | |
| 99 echo $str; | |
| 100 } | |
| 101 $str="</div>"; | |
| 102 echo $str; | |
| 103 } | |
| 104 | |
| 105 ?> | |
| 106 | |
| 107 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
| 108 <html> | |
| 109 <head> | |
| 110 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
| 111 | |
| 112 <link href="css/jquery-ui/jquery-ui.css" type="text/css" rel="stylesheet"/> | |
| 113 <script src="js/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> | |
| 114 <script src="js/jquery/jquery-ui.js" type="text/javascript"></script> | |
| 115 | |
| 116 <link href="css/check_sections.css?v=18" type="text/css" rel="stylesheet"/> | |
| 117 <script src="js/check_sections_details.js?v=18" type="text/javascript"></script> | |
| 118 | |
| 119 </head> | |
| 120 <body> | |
| 121 <div id="loading">...</div> | |
| 122 <div id="container"> | |
| 123 <?php | |
| 124 $version=0; | |
| 125 $editor=""; | |
| 126 $date=""; | |
| 127 if(isset($_GET['book_id']) && isset($_GET['count']) && is_numeric($_GET['count'])){ | |
| 128 $bookId=$_GET['book_id']; | |
| 129 $count=$_GET['count']; | |
| 130 $bookInfo=getBookInfo($bookId); | |
| 131 $info=checkSectionInfo($bookId); | |
| 132 $version=$info['version']; | |
| 133 $editor=$info['editor']; | |
| 134 $date=$info['date']; | |
| 135 $bookInfo=array_merge($bookInfo,["version"=>$version,"editor"=>$editor,"date"=>$date]); | |
| 136 printBookInfo($bookInfo); | |
| 137 //echo "version: ".$version."<br>last editor: ".$editor; | |
| 138 $missingPageArray=checkMissingPage($bookInfo,$info); | |
| 139 ?> | |
| 140 | |
| 141 <table id="history_table"> | |
| 142 <thead> | |
| 143 <button id="show_all" style="display:block;">Show history</button> | |
| 144 <button id="close" style="display:none;margin-bottom:10px;">Close</button> | |
| 145 </thead> | |
| 146 <tbody id="history_body"> | |
| 147 | |
| 148 </tbody> | |
| 149 </table> | |
| 150 <div id="searchResults"> | |
| 151 <?php | |
| 152 $sectionArray=getSectionArray($bookId,$count,$info); | |
| 153 printSectionArray($sectionArray,$missingPageArray); | |
| 154 }else{ | |
| 155 echo "Cannot process the data due to incomplete input."; | |
| 156 } | |
| 157 ?> | |
| 158 </div> | |
| 159 </div> | |
| 160 <div id="panel"></div> | |
| 161 <script> | |
| 162 var version=<?php echo $version;?>; | |
| 163 var session_id = "<?php echo $_GET['sessionId'];?>"; | |
| 164 | |
| 165 function setCurrentEditor() { | |
| 166 // current_editor is gotten from LGService | |
| 167 var current_editor = <?php echo json_encode($current_editor) ?>; | |
| 168 if (current_editor != "") { | |
| 169 $("#saveBook .editor").val(current_editor); | |
| 170 } else { | |
| 171 alert("Error!! You have to login from LGService!"); | |
| 172 $("#loading").show(); | |
| 173 } | |
| 174 } | |
| 175 | |
| 176 function showAll() { | |
| 177 | |
| 178 <?php | |
| 179 | |
| 180 $query_editor = "(SELECT editor, date, version from sections_versions WHERE books_id='".$bookId."' ORDER BY version DESC)"; | |
| 181 $result = mysql_query($query_editor); | |
| 182 | |
| 183 while ($row = mysql_fetch_assoc($result)) { | |
| 184 $history[] = $row; | |
| 185 } | |
| 186 | |
| 187 $struct = array("data" => $history); | |
| 188 print "var histories=".json_encode($struct) .";"; | |
| 189 | |
| 190 ?> | |
| 191 | |
| 192 var tableData = '<tr><td>Editor</td><td>Version</td><td>Saved Time</td></tr>'; | |
| 193 | |
| 194 $.each(histories.data, function(idx, data) { | |
| 195 tableData += (`<tr><td>${data.editor}</td><td>${data.version}</td><td>${data.date}</td><</tr>`); | |
| 196 }); | |
| 197 | |
| 198 $('#history_body').html(tableData); | |
| 199 | |
| 200 document.getElementById("show_all").style.display = "none"; | |
| 201 document.getElementById("close").style.display = "block"; | |
| 202 | |
| 203 } | |
| 204 | |
| 205 document.getElementById("show_all").onclick = showAll; | |
| 206 | |
| 207 function closeAll() { | |
| 208 | |
| 209 $('#history_body').html(""); | |
| 210 | |
| 211 document.getElementById("show_all").style.display = "block"; | |
| 212 document.getElementById("close").style.display = "none"; | |
| 213 } | |
| 214 | |
| 215 document.getElementById("close").onclick = closeAll; | |
| 216 | |
| 217 | |
| 218 // --- timeout reminder --- | |
| 219 // var timeoutID; | |
| 220 // delayedAlert(); | |
| 221 // function delayedAlert() { | |
| 222 // timeoutID = window.setTimeout(slowAlert, 600*1000); | |
| 223 // } | |
| 224 // function slowAlert() { | |
| 225 // if (confirm("Reminder: It's been 10 mins. Remember saving your work to prevent data lost. \n\nKeep working? \n(Press Cancel will turn off this reminder.)")) { | |
| 226 // | |
| 227 // var lg_url = "<?php echo $lgserver_url?>" + "rest/utils/getUser?sessionId=" + session_id; | |
| 228 // | |
| 229 // $.post(lg_url, function(data) { | |
| 230 // console.log("renew session."); | |
| 231 // | |
| 232 // }).done(function(data){ | |
| 233 // console.log(data); | |
| 234 // console.log("login as: " + data['userName']); | |
| 235 // | |
| 236 // if (data['userName'] == "") { | |
| 237 // alert("Error!! You have to re-login from LGService!"); | |
| 238 // $("#loading").show(); | |
| 239 // } else { | |
| 240 // timeoutID = window.setTimeout(slowAlert, 600*1000); | |
| 241 // } | |
| 242 // | |
| 243 // }).fail(function(){ | |
| 244 // console.log("fail to renew session."); | |
| 245 // }); | |
| 246 // } | |
| 247 // | |
| 248 // } | |
| 249 | |
| 250 | |
| 251 | |
| 252 </script> | |
| 253 | |
| 254 | |
| 255 </body> | |
| 256 | |
| 257 </html> |
