# HG changeset patch # User Zoe Hong # Date 1426773994 -3600 # Node ID 723a162b6627ac478ee763211b72d5d51d18ca10 first commit diff -r 000000000000 -r 723a162b6627 check_sections.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_sections.php Thu Mar 19 15:06:34 2015 +0100 @@ -0,0 +1,271 @@ +=".$count." + ORDER BY COUNT( * ) DESC ";*/ + $query="(SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections.name, start_page, end_page, COUNT( * ) AS count + FROM sections + JOIN books ON sections.books_id = books.id + WHERE NOT EXISTS + (SELECT 1 FROM sections_versions WHERE books_id=sections.books_id) + GROUP BY books_id, start_page, end_page + HAVING COUNT( * ) >=".$count.") + UNION + (SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections_revisions.name, start_page, end_page, COUNT( * ) AS count + FROM sections_revisions + JOIN books ON sections_revisions.books_id = books.id + JOIN ( + SELECT sections_versions.id + FROM sections_versions WHERE sections_versions.version=(SELECT MAX(version) FROM sections_versions) + GROUP BY books_id + ) AS t ON t.id=sections_revisions.versions_id + WHERE deleted=0 + GROUP BY books_id, versions_id,start_page, end_page + HAVING COUNT( * ) >=".$count.") + ORDER BY count DESC "; + $result = mysql_query($query); + echo mysql_num_rows($result)." result(s)

"; + echo ""; + echo ""; + echo ""; + $str.="
book namelevel1level2periodsection namepagecount"; + while ($row = mysql_fetch_assoc($result)) { + $str="
".$row['book_name']; + $str.="".$row['level1']; + $str.="".$row['level2']; + $str.="".$row['period']; + $str.="".$row['name'].""; + $str.="p".$row['start_page']."-".$row['end_page']; + $str.="".$row['count'].""; + echo $str; + } + echo "
"; +} + + +// sorting by the $sort_by parameter +function checkSections_sort_by($sort_by){ + switch ($sort_by) { + case 'time': + $query="(SELECT name AS book_name,level1,level2,period,dynasty,start_year,id,toc_correction,comments FROM books ORDER BY start_year)"; + $result = mysql_query($query); + echo mysql_num_rows($result)." result(s)

"; + + echo "
"; + echo ""; + echo ""; + echo ""; + $str.="
book namelevel1level2 + perioddynastystart_year + last_editoredit_time + Some notes for the book (optional)"; + while ($row = mysql_fetch_assoc($result)) { + $str="
".$row['book_name']; + $str.="".$row['level1']; + $str.="".$row['level2']; + $str.="".$row['period']; + $str.="".$row['dynasty']; + $str.="".$row['start_year']; + + $id = $row['id']; + + // query last_editor and last_edit_time + $query_editor = "(SELECT editor, date from sections_versions WHERE books_id='".$row['id']."' ORDER BY version DESC)"; + $row_sections_versions = mysql_fetch_assoc(mysql_query($query_editor)); // the first one + $last_editor = $row_sections_versions['editor']; + $last_edit_time = $row_sections_versions['date']; + $str.="".$last_editor; + $str.="".$last_edit_time; + + $str.=""."Edit".""; + + switch ($row['toc_correction']) { + + case '0': + $str.=" Finished"; + break; + + case '1': + $str.=" Finished"; + break; + default: + break; + } + // comments for book + $comments = $row['comments']; + if ($comments != "") { + $str.=" "; + } else { + $str.=" "; + } + echo $str; + + } + echo "
"; + echo "
"; + break; + + default: + # code... + echo "no sorting parameter set"; + break; + } +} + +?> + + + + + + + + + + + + +
+ find sections overlapping more than other sections + +
+
+
+ +
+ + + + + + + + + + diff -r 000000000000 -r 723a162b6627 check_sections_details.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_sections_details.php Thu Mar 19 15:06:34 2015 +0100 @@ -0,0 +1,206 @@ +"; + $str.="book id + book name + level1 + level2 + period + pages + version + editor + date"; + $str.=""; + $str.="".$bookInfo['id']; + $str.="".$bookInfo['name']; + $str.="".$bookInfo['level1']; + $str.="".$bookInfo['level2']; + $str.="".$bookInfo['period']; + $str.="".$bookInfo['line']; + $str.="".$bookInfo['version']; + $str.="".$bookInfo['editor']; + $str.="".$bookInfo['date']; + $str.=""; + echo $str; +} +function printSectionArray($sectionArray,$missingPageArray){ + $str="
"; + echo $str; + $i=0; + foreach($sectionArray as $idx=>$row){ + /* + $flag=""; + if($i!=sizeof($pageArray) && $pageArray[$i]['start_page']==$row['start_page'] && $pageArray[$i]['end_page']==$row['end_page']){ + $flag="overlapper"; + $i++; + } + if($i!=0 && $pageArray[$i-1]['start_page']==$row['start_page'] && $pageArray[$i-1]['end_page']==$row['end_page']){ + $flag="overlapper"; + }*/ + if(!($idx!=0 && $sectionArray[$idx-1]['start_page']==$row['start_page'] && $sectionArray[$idx-1]['end_page']==$row['end_page']) + && $i
"; + //$str.="
"; + $i++; + echo $str; + } + + $str="
"; + $str.="
"; + $str.="
".$row['id']."
"; + $str.="
".sprintf("%05d",$row['books_id'])."
"; + $str.="
".$row['split_from']."
"; + $str.="
".$row['section_after']."
"; + $str.="
";//end of hiddenInfo + $str.="
".($idx+1)."
"; + $str.="
".$row['name']."
"; + $str.="
"; + $str.="
".$row['start_page']."
"; + $str.=" - "; + $str.="
".$row['end_page']."
"; + $str.="
";//end of page + $str.="
"; //end of class entry + echo $str; + + } + if($i"; + echo $str; + } + $str=""; + echo $str; +} + +?> + + + + + + + + + + + + + +
...
+
+ $version,"editor"=>$editor,"date"=>$date]); + printBookInfo($bookInfo); + //echo "version: ".$version."
last editor: ".$editor; + $missingPageArray=checkMissingPage($bookInfo,$info); + ?> + + + Show editing records: + + + + + + + + + + + + + +
+ + + +
+ +
+
+
+ + + + + + + + + diff -r 000000000000 -r 723a162b6627 config.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config.php Thu Mar 19 15:06:34 2015 +0100 @@ -0,0 +1,26 @@ + diff -r 000000000000 -r 723a162b6627 css/check_sections.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/css/check_sections.css Thu Mar 19 15:06:34 2015 +0100 @@ -0,0 +1,269 @@ +body{ + font-family:Helvetica,"Adobe 宋體"; + font-size:18px; + padding:0; + margin:0; +} +#loading{ + position:fixed; + z-index:2000; + background:rgba(0,0,0,0.5); + color:#fff; + width:100vw; + height:100vh; + padding:300px 0; + text-align:center; + vertical-align:middle; + font-size:20px; + line-height:20px; +} +#container{ + padding:10px; +} +#searchResults{ + margin:30px 0; +} +#bookContainer{ + display:table; + border-collapse: collapse; + border-spacing:10px; +} +.missingPageContainer{ + font-style:italic; + display:table-row; +} +.missingPage{ + border:1px dashed #000; + width:400px; + text-align:center; + padding:10px; + margin:20px 0; +} +#bookContainer td{ + padding:10px; +} +table{ + margin-bottom:20px; +} +td.level1, td.level2,td.level3, td.period{ + width:70px; +} +div.entry{ + display:table-row; + vertical-align:middle; + cursor:move; +} +div.entry .cell{ + display:table-cell; +} +div.level1 .cell{ + vertical-align:middle; + padding:15px 0px 5px 0px; +} +div.level2 .cell{ + padding:5px 0px; +} +div.level3 .cell{ + padding:10px 0px; +} +div.entry .sequence{ + display:inline-block; + width:36px; + text-align:right; + padding-left:10px; + padding-right:10px; + font-size:14px; + margin-right:30px; + border-right:1px #888 solid; + color:#888; +} +div.entry .name{ + display:inline-block; + width:350px; + margin-left:20px; + min-height:20px; +} +div.entry .page{ + display:inline-block; + padding:0px; +} +div.startPage{ + display:inline-block; + text-align:center; + width:50px; + min-height:20px; +} +div.endPage{ + display:inline-block; + text-align:center; + width:50px; + min-height:20px; +} +div.level1{ + border-bottom:1px solid #000; +} +div.level2{ +} +div.level2 .name{ + text-indent:40px; +} +div.level3{ +} +div.level3 .name{ + text-indent:80px; +} +div.overlapper{ + background:#F5A9A9; +} +div.entry .editLevel{ + display:inline-block; + margin:0 5px; +} +div.entry .deleteEntry{ + display:inline-block; + padding-right:5px; + position:relative; +} +div.deleteEntry input{ + width:60px; + text-align:center; +} +#deleteRange{ + position:absolute; + z-index:102; + background:#000; + color:#fff; + -webkit-border-radius: 10px; + -moz-border-radius: 10px; + border-radius: 10px; + padding:10px; + width:260px; + font-size:16px; + line-height:24px; + top:-15px; + left:65px +} +#deleteRange .deleteFrom,#deleteRange .deleteTo,#deleteRange .deleteRangeButton{ + display:inline-block; +} +#deleteRange .deleteButton{ + margin-left:10px; +} +div.deleted{ + opacity:0.2; +} +div.page input[type="text"]{ + width:45px; + height:17px; + text-align:center; +} +input{ + margin:0; + padding:0; +} +input[type="text"]{ + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + border-radius: 4px; + border:1px #888 solid; + font-size:16px; + font-family:inherit; +} +input[type="button"]{ + font-size:20px; + font-family:inherit; +} +#panel{ + position:fixed; + top:30px; + right:0px; + font-size:16px; + line-height:24px; +} +#saveBook,#configure{ + background:#000; + color:#fff; + padding:15px; + -webkit-border-top-left-radius: 10px; + -webkit-border-bottom-left-radius: 10px; + -moz-border-radius-topleft: 10px; + -moz-border-radius-bottomleft: 10px; + border-top-left-radius: 10px; + border-bottom-left-radius: 10px; + vertical-align:middle; +} +#configure{ + +} +#configure input[type="checkbox"]{ + margin-right:5px; + -ms-transform: scale(1.2); /* IE */ + -moz-transform: scale(1.2); /* FF */ + -webkit-transform: scale(1.2); /* Safari and Chrome */ + -o-transform: scale(1.2); /* Opera */ + position:relative; + top:-2px; + *overflow:hidden; +} +#saveBook{ + margin-top:10px; + text-align:right; +} +#saveBook .label{ + display:block; + text-align:left; + margin-bottom:10px; +} +#saveBook .editor{ + display:block; + margin:4px 0; +} +#saveBook .save{ +} +.hovered{ + background:#ddd !important; +} +div.entry .insert{ + display:inline-block; + color:#fff; + text-align:center; + vertical-align:center; + position:relative; +} +.insertIcon{ + display:inline-block; + margin: auto 5px; + background:#444; + padding:5px 7px; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + border-radius: 5px; + cursor:pointer; + font-size:16px; + line-height:16px; +} +.insertOption{ + position:absolute; + left:33px; + width:190px; + top:-15px; + text-align:left; + background:#000; + color:#fff; + -webkit-border-radius: 10px; + -moz-border-radius: 10px; + border-radius: 10px; + padding:10px; + font-size:16px; + line-height:24px; +} +.insertBefore{ + text-align:center; + display:inline-block; + cursor:pointer; +} +.insertAfter{ + text-align:center; + display:inline-block; + margin-left:5px; +} diff -r 000000000000 -r 723a162b6627 edit_section_db.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/edit_section_db.php Thu Mar 19 15:06:34 2015 +0100 @@ -0,0 +1,294 @@ +$lastPage){ + $pageArray[$i]['start_page']=$lastPage; + $pageArray[$i]['end_page']=$row['start_page']; + //echo $pageArray[$i]['start_page']." ".$pageArray[$i]['end_page']."
"; + $i++; + } + $lastPage=$row['end_page']; + } + if($bookPage>$lastPage){ + $pageArray[$i]['start_page']=$lastPage; + $pageArray[$i]['end_page']=$bookPage; + } + return $pageArray; +} +function getSectionArray($bookId,$count,$versionInfo){ + + $str=""; + if($versionInfo['version']!=0){ + $table="sections_revisions"; + $condition="AND deleted=0 "; + $condition=" AND versions_id=".$versionInfo['id']." AND deleted=0 "; + }else{ + $table="sections"; + $condition=""; + } + + // echo "select from ".$table."\n"; + + + $query="SELECT * + FROM ".$table." + WHERE books_id=".$bookId." ".$condition." + GROUP BY books_id, start_page, end_page + HAVING COUNT( * ) >=".$count." + ORDER BY id ASC"; + /*ORDER BY start_page ASC, level ASC, id ASC,end_page DESC";*/ + $result=mysql_query($query); + + $i=0; + $pageArray=array(); + while($row=mysql_fetch_assoc($result)){ + $pageArray[$i]['start_page']=$row['start_page']; + $pageArray[$i]['end_page']=$row['end_page']; + $i++; + } + if($versionInfo['version']!=0){ + $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"; + }else{ + $query="SELECT * FROM sections WHERE books_id=".$bookId." ORDER BY id ASC"; + } + $result=mysql_query($query); + + $i=0; + $sectionArray=array(); + while($row=mysql_fetch_assoc($result)){ + $flag=""; + if($i!=sizeof($pageArray) && $pageArray[$i]['start_page']==$row['start_page'] && $pageArray[$i]['end_page']==$row['end_page']){ + $flag="overlapper"; + $i++; + } + if($i!=0 && $pageArray[$i-1]['start_page']==$row['start_page'] && $pageArray[$i-1]['end_page']==$row['end_page']){ + $flag="overlapper"; + } + $row['flag']=$flag; + if(!isset($row['deleted'])){ + $row['deleted']=""; + }else{ + if($row['deleted']==0){ + $row['deleted']=""; + }else{ + $row['deleted']="deleted"; + } + } + $sectionArray[]=$row; + } + return $sectionArray; +} +function updateSectionArray($bookId,$sectionArray,$version,$editor){ + $query="INSERT INTO sections_versions (version,editor,date,books_id) VALUES (".($version+1).",'".$editor."',NOW(),'".$bookId."')"; + $result=mysql_query($query); + if(!$result){ + echo json_encode("Failed during inserting sections_version records."); // .mysql_error(); + return; + } + $versionId=mysql_insert_id(); + $query="INSERT INTO sections_revisions (name,books_id,section_after,start_page,end_page,level,split_from,sections_id,versions_id,deleted) VALUES "; + foreach($sectionArray as $idx=>$row){ + $str="("; + $str.="'".$row['name']."',"; + $str.="'".sprintf("%05d",$row['booksId'])."',"; + $str.="'".$row['sectionAfter']."',"; + $str.=$row['startPage'].","; + $str.=$row['endPage'].","; + $str.=$row['level'].","; + $str.=$row['splitFrom'].","; + $str.=$row['id'].","; + $str.=$versionId.","; + $str.=$row['deleted']; + $str.=")"; + if($idx!=sizeof($sectionArray)-1){ + $str.=", "; + } + $query.=$str; + } + $result=mysql_query($query); + if(!$result){ + echo json_encode("Failed during inserting sections_revisions records."); // .mysql_error(); + + // Delete the sections_versions for this user + // delete $versionId in table sections_versions + $query="DELETE FROM sections_versions WHERE id=".$versionId; + $result_deleting=mysql_query($query); + if(!$result_deleting){ + echo json_encode("Failed during deleting wrongly inserted sections_version record."); + } + return; + }else{ + echo json_encode("Succeeded."); + } +} + + +function _select_distinct(){ + /* + $query="SELECT DISTINCT (books_id) FROM sections"; + + $result=mysql_query($query); + if(!$result){ + echo json_encode("Failed during inserting section records."); + return; + }else{ + echo json_encode("Succeeded."); + } + + while($row=mysql_fetch_assoc($result)){ + // echo $row['books_id'], ", "; + } + + echo "section num: ".mysql_num_rows($result); + echo '\n'; + */ + + + //$query="SELECT id FROM books WHERE id NOT IN (SELECT DISTINCT (books_id) FROM sections)"; + $query="SELECT books.id, books.name FROM books LEFT JOIN sections ON books.id=sections.books_id WHERE sections.books_id IS NULL"; + + $result=mysql_query($query); + if(!$result){ + echo json_encode("Failed during querying records."); + return; + } + + echo "missing books num: ".mysql_num_rows($result); + echo '\n'; + + + + +} + + + +function add_missing_books_to_sections(){ + // find missing books + // Run the following line/mysql to find out what books are missing in sections table + // _select_distinct(); + // Or load missing_books_id.csv + if (($missing_books = fopen("intermediate_results/missing_books.csv", "r")) !== FALSE) { + while (($data = fgetcsv($missing_books, ",")) !== FALSE) { + + $bookId = $data[0]; + $name = $data[1]; + + _add_book_to_sections($name, $bookId); + + } + fclose($missing_books); + } + +} + + +function _add_book_to_sections($name, $bookId){ + + /* + // get Auto_increment + $query = mysql_query("SHOW TABLE STATUS WHERE name='sections'"); + if (mysql_num_rows($query)) { + $result = mysql_fetch_assoc($query); + echo $result['Auto_increment']; + } else {//error + //error control here + echo "error in getting Auto_increment"; + } + */ + + // id should be autoincremated + $query="INSERT INTO sections (name,books_id,section_after) VALUES "; + + $str="("; + $str.="'".$name."','"; + $str.=$bookId."',"; + $str.="''"; + $str.=")"; + $query.=$str; + + // echo $name.", ".$bookId."\n"; + + $result=mysql_query($query); + if(!$result){ + echo json_encode("Failed during inserting section records."); + return; + } + // echo mysql_insert_id(); + +} + + +if(isset($_POST['command']) && $_POST['command']!=''){ + $command=$_POST['command']; + if($command=="write"){ + + if(isset($_POST['bookId'])&&isset($_POST['sectionArray'])&&isset($_POST['version'])&&isset($_POST['editor'])&&\ + is_numeric($_POST['bookId']) && sizeof($_POST['sectionArray'])!=0 && is_numeric($_POST['version']) && $_POST['editor']!=""){ + $bookId=$_POST['bookId']; + $sectionArray=$_POST['sectionArray']; + $version=$_POST['version']; + $editor=$_POST['editor']; + + updateSectionArray($bookId,$sectionArray,$version,$editor); + } + else{ + echo json_encode("Editing info not correct."); + + } + } + else{ + echo json_encode("Wrong command."); + return; + } +} + +?> diff -r 000000000000 -r 723a162b6627 js/check_sections_details.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/js/check_sections_details.js Thu Mar 19 15:06:34 2015 +0100 @@ -0,0 +1,371 @@ +var saving=0; +$(document).ready(function(){ + initEntry(); + initName(); + initPage(); + initLevel(); + initDelete(); + initInsert(); + initConfigure(); + initSave(version); + $("#loading").hide(); +}); +window.onbeforeunload = function() { + if(saving==0){ + return 'Remember to save your revision.'; + }else{ + } +}; +function initEntry(){ + //create an empty entry by cloning the entry we have, so that when a new entry is to be inserted, we can just clone the empty entry + var clone=$(".entry").first().clone(); + clone.addClass("clone"); + if(clone.hasClass("overlapper")){clone.removeClass('overlapper');} + clone.children(".hiddenInfo").children(".id").html("-1"); + clone.children(".hiddenInfo").children(".splitFrom").html(""); + clone.children(".hiddenInfo").children(".sectionAfter").html(""); + clone.children(".name").html(""); + clone.children(".page").children(".startPage").html(""); + clone.children(".page").children(".endPage").html(""); + clone.children(".editLevel").children("select").val(1); + clone.insertAfter("#searchResults"); + clone.hide(); + $(".entry").hover(function(){ + $(this).addClass("hovered"); + },function(){ + $(this).removeClass("hovered"); + }); + $(".hiddenInfo").hide(); + $(".entry").children().each(function(){ + $(this).addClass("cell");//for layout + }); + + //$("#bookContainer").droppable(); + //drag and drop + $(".entry").draggable(); + $(".entry").droppable({ + drop:function(e,ui){ + $(ui.draggable).insertAfter($(this)); + $(this).mouseleave(); + $(ui.draggable).mouseenter(); + } + }); +} +function dropHandler(e){//for debug + console.log("QQ"); + console.log($(event.target).children("hiddenInfo").html()); +} +function initName(){ + $(".entry .name").click(function(){ + var editMode=false; + var name=$(this).html(); + if($(this).children().length!=0){//if the name element has children, i.e. the input text + editMode=true; + } + if(!editMode){ + $(this).html(""); + $(this).children("input").focus(); + } + }); +} +function initInsert(){ + var insert=$("
").addClass("insert"); + var insertIcon=$("
").addClass("insertIcon").html("+"); + var insertBefore=$("").addClass("insertBefore").val("insert before"); + var insertAfter=$("").addClass("insertAfter").val("insert after"); + var insertOption=$("
").addClass("insertOption").append("insert a new section
").append(insertBefore).append(insertAfter); + insert.append(insertIcon); + //insert.append(insertBefore); + //insert.append(insertAfter); + $(".entry").append(insert); + insertOption.insertAfter("#searchResults"); + //$(".insertAfter").hide(); + //$(".insertBefore").hide(); + insertOption.hide(); + $(".insert").hover(function(){ + $(this).append($(".insertOption")); + $(".insertOption").show(); + //$(this).children(".insertAfter").show(); + //$(this).children(".insertBefore").show(); + },function(){ + $(".insertOption").hide(); + //$(this).children(".insertAfter").hide(); + //$(this).children(".insertBefore").hide(); + }); + $(".insertAfter").click(function(){ + addEntry($(this).parent().parent().parent(),1); + $(this).parent().hide(); + }); + $(".insertBefore").click(function(){ + addEntry($(this).parent().parent().parent(),0); + $(this).parent().hide(); + }); +} +function addEntry(obj,pos){//obj: the obj next to which we would like to add a new entry, pos: before the obj or after the obj + var clone=$(".clone").clone(true); + clone.removeClass("clone"); + clone.show(); + if(pos==0){ + clone.insertBefore(obj); + //$("
").insertAfter(clone); + }else{ + clone.insertAfter(obj); + //$("
").insertBefore(clone); + } + $("#searchResults .sequence").each(function(idx){ + $(this).html(idx+1); + }); +} +function initPage(){// init the column start page & end page, so that they turn into input boxes when clicked + //page + $("div.page").click(function(e){ + var startPage=$(this).children(".startPage").html(); + var endPage=$(this).children(".endPage").html(); + var editMode=false; + if($(this).children(".startPage").children().length!=0){ + editMode=true; + } + if(!editMode){ + $(this).children(".startPage").html(""); + //$(this).children(".startPage").children("input").focus(); + $(this).children(".endPage").html(""); + //$(this).children(".endPage").children("input").focus(); + $(e.target).children("input").focus(); + }else{ + //console.log($(this).parent().children(".editLevel").children().first().val()); + } + }); + +} +function initLevel(){//init the column level, turn it into select element + //level + var levelObj=$("
").addClass("editLevel").append(""); + $(".entry").append(deleteObj); + $(".deleted .deleteEntry input").val("recover"); + var deleteRangeObj=$("
").attr("id","deleteRange").append("delete entry
from "); + var deleteFromObj=$("").addClass("deleteFrom"); + var deleteToObj=$("").addClass("deleteTo"); + var deleteButtonObj=$("").addClass("deleteButton").val("delete"); + deleteRangeObj.append(deleteFromObj).append(" to ").append(deleteToObj).append(deleteButtonObj); + deleteRangeObj.insertAfter($("#searchResults")); + deleteRangeObj.hide(); + $(".deleteEntry .deleteButton").click(function(){ + var entryObj=$(this).parent().parent(); + var buttonVal=$(this).val(); + if(buttonVal=="delete"){ + entryObj.addClass("deleted"); + $(this).val("recover"); + }else{ + entryObj.removeClass("deleted"); + $(this).val("delete"); + } + if($("#deleteRange").is(":visible")){ + deleteRangeObj.insertAfter($("#searchResults")); + $("#deleteRange").hide(); + } + }); + $(".deleteEntry").hover(function(){ + var entryObj=$(this).parent(); + var deleteRangeObj=$("#deleteRange"); + var buttonVal=$(this).children(".deleteButton").val(); + if(buttonVal=="delete"){ + $(this).append(deleteRangeObj); + deleteRangeObj.show(); + deleteRangeObj.children(".deleteFrom").val(entryObj.children(".sequence").html()); + } + },function(){ + var buttonVal=$(this).children(".deleteButton").val(); + var deleteRangeObj=$("#deleteRange"); + if(buttonVal=="delete"){ + deleteRangeObj.children("input:text").val(""); + deleteRangeObj.insertAfter($("#searchResults")); + deleteRangeObj.hide(); + } + + }); + $("#deleteRange .deleteButton").click(function(){ + var from=$("#deleteRange .deleteFrom").val().trim(); + var to=$("#deleteRange .deleteTo").val().trim(); + from=Number(from); + to=Number(to); + if(isNaN(from) || isNaN(to) || to $(".entry").size()){console.log($(".entry").size());break;} + var entryObj=$(".entry:eq("+(i-1)+")"); + var buttonObj=entryObj.children(".deleteEntry").children(".deleteButton"); + var buttonVal=buttonObj.val(); + if(buttonVal=="delete"){ + buttonObj.click(); + } + $("#deleteRange").children("input:text").val(""); + } + }); +}/* +function isNumeric(str){ + if(str.search(/\D/)>=0){ + console.log("not a number"); + return false; + }else{ + return true; + } +}*/ +function initConfigure(){ + var configureObj=$("
").attr("id","configure"); + var hideDeletedObj=$("
").addClass("hideDeleted").append(""); + hideDeletedObj.append("hide deleted sections"); + configureObj.append(hideDeletedObj); + $("#panel").append(configureObj); + $(".hideDeleted input:checkbox").change(function(){ + if($(this).is(":checked")){ + $(".deleted").hide(); + //$(".deleted").next().hide(); + }else{ + $(".deleted").show(); + //$(".deleted").next().show(); + } + }); + var href=window.location.href; + var reg=/hideDeletedChecked=[a-zA-Z]+/g; + var hidden=reg.exec(href); + if(hidden!=null){ + hidden=hidden[0].replace("hideDeletedChecked=",""); + if(hidden=="true"){ + //if(hidden.search("true")!=-1){ + $(".hideDeleted input:checkbox").attr("checked","true"); + $(".deleted").hide(); + } + } +} +function initSave(version){ + //save + var saveObj=$("
").attr("id","saveBook"); + var labelObj=$("
").addClass("label").html("Name of the editor:"); + saveObj.append(labelObj); + labelObj.append(""); + saveObj.append(""); + $("#panel").append(saveObj); + $("#saveBook .save").click(function(){ + if($("#saveBook .editor").val()!=""){ + saveBook(version); + }else{ + alert("Please fill in the name of the editor."); + } + }); + var href=window.location.href; + var reg=/editor=[^\?^\&]+/g; + var editor=reg.exec(href); + if(editor!=null){ + editor=editor[0].replace("editor=",""); + editor=editor.replace("%20"," "); + $("#saveBook .editor").val(editor); + } +} +function saveBook(version){ + var sectionArray=collectSectionArray(); + var bookId=$(".entry").first().children(".hiddenInfo").children(".booksId").html(); + var editor=$("#saveBook .editor").val(); + console.log("editor:"+editor); + + var version=version; + $("#loading").show(); + $.post("edit_section_db.php", // use ajax to post to a php then wait for return + {//post data + command:"write", + version:version, + editor:editor, + bookId:bookId, + sectionArray:sectionArray + }, + function(data){//things to do after edit_section_db is done + if(data=="Succeeded."){ + saving=1; + var hideDeletedChecked=$(".hideDeleted input:checkbox").is(":checked");//get the previous setting for checked + var href=window.location.href; + var reg=/count=[0-9^\?]+/g; + var count=reg.exec(href); + reg = /[^\?]+/g; + href = reg.exec(href); + href=href+"?book_id="+bookId+"&"+count+"&hideDeletedChecked="+hideDeletedChecked+"&editor="+editor; + location.href=href; //refresh the page to load the sections saved in db + + }else{ + console.log("db failed. log: ", data); + alert("Saving failed. You've NOT saved your editing."); + alert("Please check your editing again. If the issue remains, please contact us."); + $("#loading").hide(); + + } + }, + "json" + ); +} +function collectSectionArray(){ + var sectionArray=new Array(); + var idx=0; + $("#searchResults .entry").each(function(){//go through all the entries wrapped in the element searchResults + var startPage,endPage,name,deleted="FALSE"; + if($(this).children(".page").children(".startPage").children().length!=0){ //if the value is a input box + startPage=$(this).children(".page").children(".startPage").children().first().val(); + endPage=$(this).children(".page").children(".endPage").children().first().val(); + }else{ // if the value is not an input box (has not been edited) + startPage=$(this).children(".page").children(".startPage").html(); + endPage=$(this).children(".page").children(".endPage").html(); + } + if($(this).children(".name").children().length!=0){ + name=$(this).children(".name").children().first().val(); + }else{ + name=$(this).children(".name").html(); + } + startPage=$.trim(startPage); + endPage=$.trim(endPage); + name=$.trim(name); + if(name=="" || startPage=="" ||endPage==""){ // if any of the fields is blank, dont insert to db (since none of them should be blank) + console.log("empty row: "+name+" -- "+startPage+" -- "+endPage); + return; // "continue" in jquery + } + if($(this).hasClass("deleted")){ deleted="TRUE";} + var id=$(this).children(".hiddenInfo").children(".id").html(); + var booksId=$(this).children(".hiddenInfo").children(".booksId").html(); + var sectionAfter=$(this).children(".hiddenInfo").children(".sectionAfter").html() + var level=$(this).children(".editLevel").children("select").val(); + var splitFrom=$(this).children(".hiddenInfo").children(".splitFrom").html(); + if(splitFrom==""){splitFrom="NULL";} + sectionArray[idx]={name:name,booksId:booksId,sectionAfter:sectionAfter, + startPage:startPage,endPage:endPage, + level:level,splitFrom:splitFrom, + id:id,deleted:deleted}; + idx++; + }); + return sectionArray; +}