diff 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
line wrap: on
line diff
--- a/search.php	Mon Oct 12 15:36:13 2015 +0200
+++ b/search.php	Wed Oct 14 11:01:26 2015 +0200
@@ -20,75 +20,68 @@
         <script src="js/jquery/jquery-ui.js" type="text/javascript"></script>
         
 		<script src="search.js" charset="utf-8"></script>
+		<script type="text/javascript">
+			// TODO: hide and show are not working here...
+			// after searching, the returning page still shows the popup
+
+			// prompt to ask there password when open page
+			$(document).ready(function(){
+				initSection();
+
+				var checkPasswd = <?php echo $checkPasswd?>;
+				
+
+				if (checkPasswd == 1) {
+					$("#search").hide();
+					showPopup();			
+					console.log("showPopup");
+				} else {
+					$("#search").show();
+					closePopup();
+					console.log("closePopup");
+				}	
+			});
+
+    	</script>
 	</head>
 	<body>
-		<script type="text/javascript">
-			// prompt to ask the password when open page
-			var checkPasswd = <?php echo $checkPasswd?>;
-			if (checkPasswd == 1) {
-				showPopup();
-			}
-			function done() { 
-		    	var password = document.getElementById("pass").value;
-		    	$.ajax({
-			        url : 'search_function.php',
-			        async : false,
-			        type : 'POST',
-			        data : 'func=checkPassword'+'&password='+password,
-			        success: function (e) {
-			        },
-			        error: function (e) {
-			            alert("Internal error when checking password.");
-			        }
-			    }).done(function(result) {
-			    	console.log("password checking result: "+result);
-			    	if (result == 1) {
-			    		document.getElementById("popup").style.display = "none";
-			    	} else {
-			    		// still showing popup
-			    		alert("Wrong password!");
-			    		showPopup();
-			    	}
-			    });
-			};
-			
-			function showPopup() {
-				// clear previous input
-				if (document.getElementById("pass")) {
-					document.getElementById("pass").value = "";	
-					document.getElementById("popup").style.display = "block";
-				}
-			}
-			
-		    
+		
+
+    		
 
-    	</script>
-
-		<div id="popup">
+    	<div id="popup">
 		    <div>Enter Password:</div>
-		    <input id="pass" type="password"/>
-		    <button onclick="done()">OK</button>    
+		    <input id="pass" type="password" onKeyPress="return submitenter(event)"/>
+		    <button onclick="checkPassword()">OK</button>    
 		</div>
 
-		<form action='search.php' method='POST'>
-			關鍵字: <input type="text" name="keyword" size="100"> (若要搜尋多筆關鍵字請用半型逗號,隔開)<br>
-			將結果輸出至: <input type="text" name="filename" size="40">.html (請用英文非空白字元命名)<br>
-			<input type="submit" name="search" value="搜尋">
-			<input type="hidden" name="passwd">
+		
+		<div id="search">
+			<form action='search.php' method='POST'>
+				關鍵字: <input type="text" name="keyword" size="100"> (若要搜尋多筆關鍵字請用半型逗號,隔開)<br>
+				將結果輸出至: <input type="text" name="filename" size="40">.html (請用英文非空白字元命名)<br>
+				<input type="submit" name="search" value="搜尋">
+				<input type="hidden" name="passwd">
 
-		</form>
-		<br>
-		<div id="search_result">
-		<?php
-			if(isset($_POST['search']) && $_POST['keyword']!='' && $_POST['filename']!=''){
-				$keywordArray=trimKeyword($_POST['keyword']);
-				$array=search($keywordArray);
-				writeCsvFile($array,$_POST['filename']);
-				// write html to search_results folder
-				printTable($array,$keywordArray,$_POST['filename'],$NO_TAG);
-			}			
-		?>
+			</form>
+			<br>
+		
+			<div id="search_result">
+			<?php
+				if( isset($_POST['passwd']) && isset($_POST['search']) && $_POST['keyword']!='' && $_POST['filename']!=''){
+					
+					$keywordArray=trimKeyword($_POST['keyword']);
+					$array=search($keywordArray);
+					writeCsvFile($array,$_POST['filename']);
+					// write html to search_results folder
+					printTable($array,$keywordArray,$_POST['filename'],$NO_TAG);
+					
+				}			
+			?>
+			</div>
 		</div>
+	
+		
 	</body>
 </html>