<!doctype html>
<html>
<head>
	<meta content="text/css;charset=utf-8" />
	<title>Seller List</title>
	<style type="text/css">
		/*td, th{border-right: solid 1px white;}*/
		#heads {
			background: green;
			color: aliceblue;
		}

		/*div#menu { margin:5px auto; }*/
		td,th {
			border-left: 1px solid #DBDBDB;
			vertical-align: top;
		}
		tr,p{
			margin-left: 101px;
		}

		/*#table1 {border-collapse: collapse;} */

		.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: 558px;
		}
		.wd{
			table-layout: fixed;
			width: 100%;
		}
	</style>
</head>

<body>

	<ul class="top-level-menu">
		<li><a href="actionController.php?
					                    action=seller/addSeller1Action&
										actionIs=insert">Add Seller</a>
		</li>
		<li>
			<a href="#">Saler Report</a>
			<ul class="second-level-menu">
				<li><a href="report-content/saleReport.php">All Saler</a></li>
			</ul>
		</li>
	</ul>

	<?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 sale001 WHERE SMFNAME LIKE '%" . $strKeyword . "%' ";
	$query = mysqli_query($con, $sql);
	?>

	<div id="search">
		<form name="frmSearch" method="post" action="<?php echo 'actionController.php?
								          	 action=seller/retrieveSeller1Action&$strKeyword'; ?>">
			<div>
				<tr>
					<p>พนักงานขาย
						<input name="txtKeyword" type="text" id="txtKeyword" size="21" placeholder="Search"
						       value="<?php echo $strKeyword; ?>">
						<input type="submit" value="ค้นหา">
					</p>
				</tr>
			</div>
		</form>
	</div>

	<?php

	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['SMNO'])) {
		$id = implode(", ", $_POST['SMNO']);
		$sql = "DELETE FROM sale001 WHERE SMNO IN($id)";
		mysqli_query($con, $sql);
	}

	//$sql = "SELECT * FROM sale001";
	$sql = "SELECT * FROM sale001 WHERE SMFNAME LIKE '%".$strKeyword."%' ORDER BY SMNO DESC";
	$result = mysqli_query($con, $sql);
	$num=mysqli_num_rows($result);

	if($strKeyword==''){
		$rs = page_query($con, $sql, 35);
	}else{
		$rs = page_query($con, $sql, $num);
	}

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

	echo "<div style='color: blue; margin-top: 30px; text-align: center;'>";
		echo "<h4>รายชื่อพนักงานขาย (Salesman)</h4>";
		echo "<span id=\"result\">รายการที่ : $first - $last จากทั้งหมด $total</span>";	
	echo "</div>";

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

	echo "<tr id='heads' style='text-align: center;'>";      //ส่วนหัวตาราง(ชื่อฟิลด์)
	//echo "<th style='width:5%;'>select</th>";
	echo "<th width='13%'>action</th>";
	echo "<th width='5%'>No.</th>";
	echo "<th width='5%'>Name</th>";
	echo "<th width='20%'></th>";
	echo "<th width='24%'></th>";
	echo "<th width='13%'>ประเภท</th>";
	echo "<th width='20%'>Note</th>";
	echo "</tr>";

	while ($data = mysqli_fetch_array($rs, MYSQLI_ASSOC)) {
		echo "<tr>";
		//echo '<td><input type="checkbox" name="SMNO[]" value=" ' .$data['SMNO'].' "></td>';
		echo "<td><a href=\"actionController.php?
			                                        action=seller/editSeller1Action&SMNO={$data['SMNO']}&
													actionIs=update\">[แก้ไข]</a>
							 <a href=\"actionController.php?
								                    action=seller/deleteSeller1Action&SMNO={$data['SMNO']}&
													actionIs=delete\">[ลบ]</a>
							  <a href=\"report-content/saleIndReport.php?
							                        no={$data['SMNO']}\">[พิมพ์]</a></td>"; //เวลานำไปใช้ $no=$_GET['no'];
		//echo "<td><a href=\"form.php?action=update&id={$data['id']}\">แก้ไข</a>|		
		//<a href='actionController.php?action=product/editProductAction'>เพิ่มข้อมูล</a>	
		echo "<td>$data[SMNO]</td>";
		echo "<td>$data[SMSUR]</td>";
		echo "<td>$data[SMFNAME]</td>";
		echo "<td>$data[SMLNAME]</td>";
		echo "<td>$data[SMKIND]</td>";
		echo "<td>$data[SMNOTE]</td>";
		/*echo "<td>$data[NOTE]</td>";*/
		echo "<tr>";
	}
	echo "</table>";
	echo "</form>";

	//ต่อไปให้แสดงหมายเลขเพจเฉพาะเมื่อมีมากกว่า 1 เพจ 
	if (page_total() > 1) {
		echo '<p id="pagenum">';
		page_echo_pagenums();
		echo '</p>';
	}
	mysqli_close($con);
	?>
</body>

</html>