<?php session_start();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<?php
		include_once("../../functions/init.php"); 

		$tmp = $thisUrl."adm1n/functions/access.php";
		include ($tmp);

		$tmp = $thisUrl."adm1n/functions/koneksi.php";
		include_once ($tmp);

		$tmp = $thisUrl."adm1n/functions/head_section.php";
		include ($tmp);
		?>
    </head>	
	<body>
    	<div class="se-pre-con"></div>
		<center>
			<table width="1024">
				<tr valign="top">
					<td width="207" class="bg">
						<?php 
						$tmp = $thisUrl."adm1n/functions/kiri.php";
						include ($tmp);
						?>
					</td>
					<td width="10"></td>
					<td width="807">
						<?php 
						$tmp = $thisUrl."adm1n/functions/logo.php";
						include ($tmp);
						
						$tmp = $thisUrl."adm1n/functions/getUrl.php";
						include ($tmp);
						
						$tmp = $thisUrl."adm1n/functions/php_functions.php";
						include ($tmp);

						echo '<div>'.$txt_legend.'</div>';

						$action = (isset($_REQUEST["action"]) ? $_REQUEST["action"] : null);
						
						//echo "action : ".$action ;
						if ($action == "addRecord"){
							include ("add_record.php");
						} else if ($action == "Manage Company Info"){
							include ("edit_record.php");
						} else if ($action == "addProduct" || $action == "editProduct"){
							include ("add_product.php");	
						} else if ($action == "delete"){
						} else {
							$addRecord = "location='?action=addRecord'";
							echo '						
							<div style="display:block;">
								<div style="margin-top:15px"></div>
								<div style="float:left">
									<form name="form" id="form" class="form" action="?action=search" onsubmit="return validate(this)" method="post">
										<strong>Company Name</strong>: <br>
										<input type="text" name="s_text" value="'.$s_text.'" size="50">
										<input type="submit" name="s_submit" class="button1" value="Search">
									</form>
								</div>
								<div style="float:right">
									<div id="tab1" class="button" onClick="'.$addRecord.'">Add Record</div>
								</div>
							</div>
							<div style="clear:both; margin-top:15px">&nbsp;</div>
							<table width="100%" cellpadding="10" cellspacing="1" border="0" bgcolor="#222222">
								<tr bgcolor="#DDDDDD">
									<td width="10%" align="center"><strong>NO</strong></td>
									<td width="75%"><strong>COMPANY NAME</strong></td>
									<td width="15%" align="center"><strong>ACTION</strong></td>
								</tr>';
								$exhibitorID = (isset($_POST["exhibitorID"]) ? $_POST["exhibitorID"] : null);
								//echo "exhibitorID: ".$exhibitorID;
								$sql = 
								" select * from exhibitor_list ";
								if ($action=="search") {
									$sql .= 
									" where UPPER(companyName) ".
									" like '%".strtoupper($_POST["s_text"])."%' ";
								} else if ($exhibitorID) {
									$sql .= 
									" where exhibitorID = ".$exhibitorID;
								}
								$sql .= 
								" order by exhibitorID desc";
								
								$max = mysqli_num_rows(mysqli_query($conn, $sql));
								$perhalaman = 15;
								$page = (isset($_SESSION['page']) ? $_SESSION['page'] : (isset($_REQUEST["page"]) ? $_REQUEST["page"] : null));
								//$page = $_SESSION['page'];
								//if (!$page) $page = $_REQUEST["page"];
								if ($page){
									$start=($page - 1) * $perhalaman;
								} else {
									$start=0;
								}
								
								$sql  .= " LIMIT $start, $perhalaman";
								//echo "<br>sql: ".$sql;
								if ($hasil = mysqli_query($conn, $sql)) {
									$counter = $start;
									while ($data = mysqli_fetch_array($hasil)) {
										$counter++;
										$addProduct  = 'onclick="';
										$addProduct .= "location='?action=Manage Company Info&exhibitorID=".$data["exhibitorID"]."'";
										$addProduct .= '"';
										echo '
										<tr bgcolor="#FFFFFF">
											<td align="center">'.$counter.'</td>
											<td>'.strtoupper($data["companyName"]).'</td>
											<td align="center">
												<div style="cursor:pointer;" '.$addProduct.'>Edit</div>
											</td>
										</tr>';
									}
								}
								echo '
							</table> 
							<div align="center" style="margin:30px 0px">';
								$tmp = $thisUrl."functions/fungsi_paging.php";
								include($tmp);
								halaman($max, $perhalaman, 3, "?");
								echo '
							</div>';
						}
						?>
					</td>
				</tr>
			</table>
		</center>
	</body>
</html>	