<!doctype html>
<html>

<head>
	<meta charset="UTF-8">
	<title>Seller List</title>
	<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: 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="#">Services</a></li>-->
		<li>
			<a href="#">Saler Report</a>
			<ul class="second-level-menu">
				<li><a href="report-content/saleReport.php">All Sales</a></li>
			</ul>
		</li>
		<li></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">
		<!-- echo $_SERVER['SCRIPT_NAME']; -->
		<form name="frmSearch" method="post" action="
											      <?php echo 'actionController.php?
								          					action=seller/retrieveSeller1Action&$strKeyword'; ?>">
			<table>
				<tr>
					<th>พนักงานขาย
						<input name="txtKeyword" type="text" id="txtKeyword" size="21" placeholder="Search"
						       value="<?php echo $strKeyword; ?>">
						<input type="submit" value="ค้นหา">
					</th>
				</tr>
			</table>
		</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 '<form method="post">';
	echo "<table class='wd'><caption>";     //อ่านข้อมูล result set มาแสดงในรูปแบบตาราง
	echo "<h1>รายชื่อพนักงานขาย (Salesman)</h1>";

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

	//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>