<!doctype html>
<html>

<head>
	<meta charset="UTF-8">
	<title>Project List</title>
	<style type="text/css">
		td,
		th {
			border-left: 1px solid #DBDBDB;
			vertical-align: top;
		}

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

<body>
	<ul class="top-level-menu">
		<li><a href="actionController.php?
					                    action=seller/addProjectAction&
										actionIs=insert">Add Project</a></li>
		<!--<li><a href="#">Services</a></li>-->
		<li>
			<a href="#">Project Report</a>
			<ul class="second-level-menu">
				<li><a href="report-content/projectReport.php">โครงการทั้งหมด</a></li>
				<!--<li><a href="actionController.php?
					                    action=seller/reportSellerAction&
										actionIs=reportAll">Customer</a></li>-->
				<li><a href="report-content/projectReportByName.php">ตามชื่อโครงการ</a></li>
				<li><a href="report-content/projectReportByKind.php">ตามประเภท</a></li>
				<li><a href="report-content/projectReportByContract.php">ตามผู้ติดต่อ</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 proj001 WHERE PJNAME 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/retrieveProjectAction&$strKeyword'; ?>">
			<table>
				<tr>
					<th>ชื่อโครงการ
						<input name="txtKeyword" type="text" id="txtKeyword" 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['PJNO'])) {
		$id = implode(", ", $_POST['PJNO']);
		$sql = "DELETE FROM proj001 WHERE PJNO IN($id)";
		mysqli_query($con, $sql);
	}

	/*$sql="SELECT * FROM proj001";*/
	$sql = "SELECT * FROM proj001 WHERE PJNAME LIKE '%" . $strKeyword . "%' ORDER BY PJNO ASC";
	$result = mysqli_query($con, $sql);
	$num=mysqli_num_rows($result);

	if($strKeyword==''){
		$rs = page_query($con, $sql, 25);
	}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>รายชื่อโครงการ</h1>";

	/*echo "<img src='arrow-down.gif'><button>ลบแถวที่เลือก</button>					 
					 <a href=\"actionController.php?action=seller/addProjectAction&
										actionIs=insert\">เพิ่มข้อมูล</a>*/

	echo "<span id=\"result\">รายการที่ : $first - $last จากทั้งหมด $total</span>
					 </caption>";

	echo "<tr id='headpj'>";      //ส่วนหัวตาราง(ชื่อฟิลด์)

	//echo "<th style='width:5%;'>select</th>";
	echo "<th width='13%'>action</th>";
	echo "<th width='22%'>ชื่อโครงการ</th>";
	echo "<th width='12%'>ประเภท</th>";
	echo "<th width='20%'>ที่อยู่</th>";
	echo "<th width='10%'>เบอร์โทร.</th>";
	echo "<th width='11%''>ผู้ติดต่อ</th>";
	echo "<th width='12%'>ผู้รับผิดชอบ</th>";
	echo "</tr>";

	while ($data = mysqli_fetch_array($rs, MYSQLI_ASSOC)) {
		echo "<tr>";
		//echo '<td><input type="checkbox" name="PJNO[]" value=" ' .$data['PJNO'].' "></td>';
		echo "<td><a href=\"actionController.php?
			                                        action=seller/editProjectAction&PJNO={$data['PJNO']}&
													actionIs=update\">[แก้ไข]</a>
							 <a href=\"actionController.php?
								                    action=seller/deleteProjectAction&PJNO={$data['PJNO']}&
													actionIs=delete\">[ลบ]</a>
			                 <a href=\"report-content/projectIndReport.php?
							                        no={$data['PJNO']}\">[พิมพ์]</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[PJNAME]</td>";
		echo "<td>$data[PJKIND]</td>";
		echo "<td>$data[PJADRS]</td>";
		echo "<td>$data[PJTELC1] $data[PJTEL1] $data[PJTELC2] $data[PJTEL2]</td>";
		echo "<td>$data[PJCONTRCT]</td>";
		echo "<td>$data[PJADVISER]</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>