<!doctype html>
<html>

<head>
	<meta charset="UTF-8">
	<title>Product 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: 30;
			/*right: -150px;*/
			left: 0;
			width: 150px;
			list-style: none;
			padding: 0;
			margin: 0;
			display: none;
		}

		.third-level-menu>li {
			position: relative;
			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: 567px;
		}
		.wd{
			table-layout: fixed;
			width: 100%;
		}
	</style>
</head>

<body>

	<ul class="top-level-menu">
		<li><a href="actionController.php?
					                    action=seller/addProductAction&
										actionIs=insert">Add Product</a></li>
		<!--<li><a href="#">Services</a></li>-->
		<li>
			<a href="#">Product Report</a>
			<ul class="second-level-menu">
				<li><a href="report-content/inputProdCond.php">สินค้า,ราคา,วันบันทึก</a></li>	
			</ul>
		</li>
		<li>
			<a href="#">Product Report(All)</a>
			<ul class="third-level-menu">
			<li><a href="report-content/productReportByKind.php">ประเภท(Z->A)</a></li>
				<li><a href="report-content/productReportByCode.php">รหัส(A->Z)</a></li>
				<li><a href="report-content/productReportByName.php">ชื่อสินค้า</a></li>
				<li><a href="report-content/productReportByDate.php">วันบันทึกสินค้า</a></li>
				<li><a href="report-content/productReportByCost.php">ราคา(มาก->น้อย)</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 prod001 WHERE PDNO 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/retrieveProductAction&$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

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

	//$sql="SELECT * FROM prod001";
	$sql = "SELECT * FROM prod001 WHERE PDNO LIKE '%".$strKeyword."%' ORDER BY PDNO ASC,PDDATE DESC";
	$result = mysqli_query($con, $sql);
	$num=mysqli_num_rows($result);

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

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

	//<a href='form.php?action=insert'>เพิ่มข้อมูล</a>
	echo '<form method="post">';
	echo "<table class='wd'><caption>";     //อ่านข้อมูล result set มาแสดงในรูปแบบตาราง
	echo "<h1>รายการสินค้า(Product)</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%'>ลำดับ</th>";
	echo "<th width='12%'>ประเภท</th>";    //PDKIND
	echo "<th width='10%'>รหัส(1)</th>";    //PDNO
	echo "<th width='22%'>ชื่อสินค้า</th>";    //PDNAME
	echo "<th width='8%'>UpDte</th>";    //PDDATE
	//echo "<th width='10%'>cost</th>";      PDCSTPRC
	echo "<th width='10%'>ขาย</th>";       //PDSLEPRC
	echo "<th width='10%'>from</th>";      //PDFROM
	echo "<th width='5%'>ส่วนลด</th>";      //PDDISC
	echo "<th width='10%'>Note</th>";      //PDNOTE
	echo "</tr>";

	while ($data = mysqli_fetch_array($rs, MYSQLI_ASSOC)) {
		echo "<tr>";
		//echo '<td><input type="checkbox" name="PDNO[]" value=" ' .$data['PDNO'].'  "></td>';
		echo "<td><a href=\"actionController.php?
			                action=seller/editProductAction&PDNO={$data['PDNO']}&
							actionIs=update\">[แก้ไข]</a>
				  <a href=\"actionController.php?
							action=seller/deleteProductAction&PDNO={$data['PDNO']}&
							actionIs=delete\">[ลบ]</a>  									
				  <a href=\"report-content/productIndReport.php?
							no={$data['PDNO']}\">[พิมพ์]</a></td>"; //เวลานำไปใช้ $no=$_GET['no'];

		//echo "<td>$data[NO]</td>";					
		echo "<td>$data[PDKIND]</td>";
		echo "<td>$data[PDNO]</td>";
		echo "<td>$data[PDNAME]</td>";
		echo "<td>".date('d-m-Y',strtotime($data['PDDATE']))."</td>";
		echo "<td class=rt>".number_format($data['PDSLEPRC'],2)."</td>";
		echo "<td>$data[PDFROM]</td>";
		echo "<td class=rt>$data[PDDISC]</td>";
		echo "<td>$data[PDNOTE]</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>