Mercurial > hg > LGSearch
comparison search.php @ 6:4b9ae7d500f9
add example page, modify password popup
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Wed, 14 Oct 2015 11:01:26 +0200 |
| parents | 1cf7bb8db5dd |
| children | 23dcd1b5e9c4 |
comparison
equal
deleted
inserted
replaced
| 5:1cf7bb8db5dd | 6:4b9ae7d500f9 |
|---|---|
| 18 | 18 |
| 19 <script src="js/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> | 19 <script src="js/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> |
| 20 <script src="js/jquery/jquery-ui.js" type="text/javascript"></script> | 20 <script src="js/jquery/jquery-ui.js" type="text/javascript"></script> |
| 21 | 21 |
| 22 <script src="search.js" charset="utf-8"></script> | 22 <script src="search.js" charset="utf-8"></script> |
| 23 <script type="text/javascript"> | |
| 24 // TODO: hide and show are not working here... | |
| 25 // after searching, the returning page still shows the popup | |
| 26 | |
| 27 // prompt to ask there password when open page | |
| 28 $(document).ready(function(){ | |
| 29 initSection(); | |
| 30 | |
| 31 var checkPasswd = <?php echo $checkPasswd?>; | |
| 32 | |
| 33 | |
| 34 if (checkPasswd == 1) { | |
| 35 $("#search").hide(); | |
| 36 showPopup(); | |
| 37 console.log("showPopup"); | |
| 38 } else { | |
| 39 $("#search").show(); | |
| 40 closePopup(); | |
| 41 console.log("closePopup"); | |
| 42 } | |
| 43 }); | |
| 44 | |
| 45 </script> | |
| 23 </head> | 46 </head> |
| 24 <body> | 47 <body> |
| 25 <script type="text/javascript"> | 48 |
| 26 // prompt to ask the password when open page | |
| 27 var checkPasswd = <?php echo $checkPasswd?>; | |
| 28 if (checkPasswd == 1) { | |
| 29 showPopup(); | |
| 30 } | |
| 31 function done() { | |
| 32 var password = document.getElementById("pass").value; | |
| 33 $.ajax({ | |
| 34 url : 'search_function.php', | |
| 35 async : false, | |
| 36 type : 'POST', | |
| 37 data : 'func=checkPassword'+'&password='+password, | |
| 38 success: function (e) { | |
| 39 }, | |
| 40 error: function (e) { | |
| 41 alert("Internal error when checking password."); | |
| 42 } | |
| 43 }).done(function(result) { | |
| 44 console.log("password checking result: "+result); | |
| 45 if (result == 1) { | |
| 46 document.getElementById("popup").style.display = "none"; | |
| 47 } else { | |
| 48 // still showing popup | |
| 49 alert("Wrong password!"); | |
| 50 showPopup(); | |
| 51 } | |
| 52 }); | |
| 53 }; | |
| 54 | |
| 55 function showPopup() { | |
| 56 // clear previous input | |
| 57 if (document.getElementById("pass")) { | |
| 58 document.getElementById("pass").value = ""; | |
| 59 document.getElementById("popup").style.display = "block"; | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 | |
| 64 | 49 |
| 65 </script> | 50 |
| 66 | 51 |
| 67 <div id="popup"> | 52 <div id="popup"> |
| 68 <div>Enter Password:</div> | 53 <div>Enter Password:</div> |
| 69 <input id="pass" type="password"/> | 54 <input id="pass" type="password" onKeyPress="return submitenter(event)"/> |
| 70 <button onclick="done()">OK</button> | 55 <button onclick="checkPassword()">OK</button> |
| 71 </div> | 56 </div> |
| 72 | 57 |
| 73 <form action='search.php' method='POST'> | 58 |
| 74 關鍵字: <input type="text" name="keyword" size="100"> (若要搜尋多筆關鍵字請用半型逗號,隔開)<br> | 59 <div id="search"> |
| 75 將結果輸出至: <input type="text" name="filename" size="40">.html (請用英文非空白字元命名)<br> | 60 <form action='search.php' method='POST'> |
| 76 <input type="submit" name="search" value="搜尋"> | 61 關鍵字: <input type="text" name="keyword" size="100"> (若要搜尋多筆關鍵字請用半型逗號,隔開)<br> |
| 77 <input type="hidden" name="passwd"> | 62 將結果輸出至: <input type="text" name="filename" size="40">.html (請用英文非空白字元命名)<br> |
| 63 <input type="submit" name="search" value="搜尋"> | |
| 64 <input type="hidden" name="passwd"> | |
| 78 | 65 |
| 79 </form> | 66 </form> |
| 80 <br> | 67 <br> |
| 81 <div id="search_result"> | 68 |
| 82 <?php | 69 <div id="search_result"> |
| 83 if(isset($_POST['search']) && $_POST['keyword']!='' && $_POST['filename']!=''){ | 70 <?php |
| 84 $keywordArray=trimKeyword($_POST['keyword']); | 71 if( isset($_POST['passwd']) && isset($_POST['search']) && $_POST['keyword']!='' && $_POST['filename']!=''){ |
| 85 $array=search($keywordArray); | 72 |
| 86 writeCsvFile($array,$_POST['filename']); | 73 $keywordArray=trimKeyword($_POST['keyword']); |
| 87 // write html to search_results folder | 74 $array=search($keywordArray); |
| 88 printTable($array,$keywordArray,$_POST['filename'],$NO_TAG); | 75 writeCsvFile($array,$_POST['filename']); |
| 89 } | 76 // write html to search_results folder |
| 90 ?> | 77 printTable($array,$keywordArray,$_POST['filename'],$NO_TAG); |
| 78 | |
| 79 } | |
| 80 ?> | |
| 81 </div> | |
| 91 </div> | 82 </div> |
| 83 | |
| 84 | |
| 92 </body> | 85 </body> |
| 93 </html> | 86 </html> |
| 94 | 87 |
