<!doctype html>
<html>

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

	<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: 290px;
		}

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

<body>

	<ul class="top-level-menu">
		<li><a href="actionController.php?
					                    action=seller/addSellerAction&
										actionIs=insert">Add Customer</a></li>
		<!--<li><a href="#">Services</a></li>-->
		<li>
			<a href="#">Customer Report</a>
			<ul class="second-level-menu">
				<li><a href="report-content/customerReport.php">All Customer</a></li>
				<li><a href="report-content/customerReportByName.php">By Name</a></li>
				<li><a href="report-content/customerReportByContract.php">By Contract</a></li>
				<li><a href="report-content/inputSaleName.php">By 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 cust001 WHERE C_NAME 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/retrieveSellerAction&$strKeyword'; ?>">
			<div>
				<tr>
					<p>ชื่อลูกค้า(name)
						<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
	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['C_NO'])) {
		$id = implode(", ", $_POST['C_NO']);
		$sql = "DELETE FROM cust001 WHERE C_NO IN($id)";
		mysqli_query($con, $sql);
	}

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

	if($strKeyword==''){
		$rs = page_query($con, $sql, 24);
	}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>รายชื่อลูกค้า (Customer)</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='25%'>name</th>";
	echo "<th width='7%'>ประเภท</th>";
	echo "<th width='23%'>ที่อยู่</th>";
	echo "<th width='10%'>เบอร์โทร.</th>";
	echo "<th width='10%'>ผู้ติดต่อ</th>";
	echo "<th width='7%'>ผู้ขาย</th>";
	echo "<th width='5%'>ส่วนลด</th>";
	/*echo "<th id='NOTE' style='width:5%;'>Note</th>";*/
	echo "</tr>";

	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 width='118'><a href=\"actionController.php?
			                action=seller/editSellerAction&C_NO={$data['C_NO']}&
							actionIs=update\">[แก้ไข]</a>
				<a href=\"actionController.php?
					  		action=seller/deleteSellerAction&C_NO={$data['C_NO']}&
							actionIs=delete\">[ลบ]</a>
				<a href=\"report-content/customerIndReport.php?
							no={$data['C_NO']}\">[พิมพ์]</a></td>"; //เวลานำไปใช้ $no=$_GET['no'];
		echo "<td>$data[C_NAME]</td>";
		echo "<td>$data[C_KIND]</td>";
		echo "<td>$data[C_ADRS]</td>";
		echo "<td>$data[C_TELC1] $data[C_TEL1] $data[C_TELC2] $data[C_TEL2]</td>";
		echo "<td>$data[C_CONTRCT]</td>";
		echo "<td>$data[C_SMFNAME]</td>";
		echo "<td class=rt>$data[C_DISC]</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>