<!doctype html>
<html>
<head>
<meta content="text/css;charset=utf-8" /> 

<style type="text/css">
td, th {border-left: 1px solid #DBDBDB; vertical-align: top;}
#heads {background: green; color: aliceblue;}
/*div#menu { margin:5px auto; }*/
	
.third-level-menu{position: absolute;
							top: 0;
							right: -150px;
							width: 150px;
							list-style: none;
							padding: 0;
							margin: 0;
							display: none;}
.third-level-menu > li{height: 30px;background: #999999;}
.third-level-menu > li:hover { background: #CCCCCC; }
.second-level-menu{position: absolute;
							 top: 30px;
							 left: 0;
							 width: 150px;
							 list-style: none;
							 padding: 0;
							 margin: 0;
							 display: none;}
.second-level-menu > li{position: relative;height: 30px; background: #999999;}
.second-level-menu > li:hover { background: #CCCCCC; }
.top-level-menu{list-style: none;padding: 0;margin: 0;}
.top-level-menu > li{position: relative;
							  float: left;
							  height: 30px;
							  width: 150px;
							  background: #999999;}
.top-level-menu > li:hover { background: #CCCCCC; }
.top-level-menu li:hover > ul{display: inline;}/* On hover, display the next level's menu */
    
/* Menu Link Styles */
/* Apply to all links inside the multi-level menu */	
.top-level-menu a{font: bold 14px Arial, Helvetica, sans-serif;
						  color: #FFFFFF;
						  text-decoration: none;
						  padding: 0 0 0 10px;
						  /* Make the link cover the entire list item-container */
						  display: block;
						  line-height: 30px;
						  text-align: center;}
.top-level-menu a:hover { color: #000000; }
#search {position: absolute; left: 550px;}	
	
#bg{
	margin: auto;
	width: 830px;
	height: 100px;
	font-size: 20px;
	color: crimson;
	background: #ddf;
	border: 2px solid rgba(186,186,186,1.00);
	position: absolute;
	top: 100px;
	left: 135px;
}
#bg a{
	border-collapse: collapse;
	font-family:  Gill Sans, Gill Sans MT, Myriad Pro, DejaVu Sans Condensed, Helvetica, Arial," sans-serif";
}
.wd{
			table-layout: fixed;
			width: 100%;
		}	
</style>
</head>

<body>
	<?php
		ini_set('display_errors', 1);
		error_reporting(~0);
		$strKeyword = null;
		if(isset($_POST["txtKeyword"]))
			{
				$strKeyword = $_POST["txtKeyword"];
			}
		include "functions/dblink.php";
		$sql = "SELECT * FROM member WHERE Username LIKE '%".$strKeyword."%' ";
		$query = mysqli_query($con,$sql);
	
 		error_reporting(~0);
 		include "pagination.php";   
		include "functions/dblink.php";	   

		ini_set('display_errors', 1);
		error_reporting(~0);
		$strKeyword = null;
		if(isset($_POST["txtKeyword"]))
		{
			$strKeyword = $_POST["txtKeyword"];
		}
	
		$find = "ทั้งหมด";
		$condition = 1;				   
		
		//กรณี chkbox แล้วโพสกลับขึ้นมา	
		if(isset($_POST['UserID']))	
		{
			$id=implode(", ", $_POST['UserID']);
			$sql="DELETE FROM member WHERE UserID IN($id)";
			mysqli_query($con,$sql);
		}	
	
		if(@$_SESSION["Status"] =="ADMIN"){
	?>
			<ul class="top-level-menu">
				<li><a href="actionController.php?action=seller/addMemberAction&
							 actionIs=insert">Add Member</a>
				</li>
			</ul>
	<?php	
			$sql="SELECT * FROM member";
			$result=mysqli_query($con,$sql);

			$rs = page_query($con, $sql, 24);	

			$first = page_start_row();
			$last = page_stop_row();
			$total = page_total_rows();
			if($total == 0) {$first = 0;}	

			echo '<form method="post">';
			echo "<table class='wd'><caption>" ;     //อ่านข้อมูล result set มาแสดงในรูปแบบตาราง

			echo "<tr><h1>รายชื่อสมาชิก (Member)</h1></tr>";					
			echo "<tr><span id=\"result\">รายการที่ : $first - $last จากทั้งหมด $total</span></caption></tr>";					

			echo "<tr id='heads'>";      //ส่วนหัวตาราง(ชื่อฟิลด์)
			//echo "<th style='width:5%;'>select</th>";
			echo "<th>action</th>";
			echo "<th>UserID</th>";
			echo "<th>Username</th>";
			echo "<th>Password</th>";
			echo "<th>Name</th>";
			echo "<th>Status</th>";
			echo "</tr>";		
			echo "<br>";
			while($data=mysqli_fetch_array($rs,MYSQLI_ASSOC))
			{
				echo "<tr>";
				//echo '<td><input type="checkbox" name="C_NO[]" value=" ' .$data['C_NO'].' "></td>';
				echo "<td><a href=\"actionController.php?
									action=seller/editMemberAction&UserID={$data['UserID']}&
									actionIs=update\">[แก้ไข]</a>
						  <a href=\"actionController.php?
									action=seller/deleteMemberAction&UserID={$data['UserID']}&
									actionIs=delete\">[ลบ]</a></td>";
				echo "<td>$data[UserID]</td>";
				echo "<td>$data[Username]</td>";
				echo "<td>$data[Password]</td>";	
				echo "<td>$data[Name]</td>";
				echo "<td>$data[Status]</td>";									
				echo "<tr>";
			}
			echo "</table>";
			echo "</form>";

			//ต่อไปให้แสดงหมายเลขเพจเฉพาะเมื่อมีมากกว่า 1 เพจ 
			if(page_total() > 1)
			{ 	
				echo '<p id="pagenum">';
				page_echo_pagenums();
				echo '</p>';
			}
	}else{ ?>
			<div id="bg" align="center">	
					<!-- <p>Username and Password Incorrect !</p> -->
					<br>
					<p>กรุณาตรวจสิทธิของท่าน ! ใช้ได้เฉพาะสิทธิ ADMIN เท่านั้น</p>
					<a href="login.php" style="text-decoration: none">Login</a>
			</div>
	<?php			
		}	
		mysqli_close($con);
	?>
</body>
</html>