	<?php
	include_once ($thisUrl."adm1n/functions/php_functions.php");
	$search_text = (isset($_REQUEST["search_text"]) ? $_REQUEST["search_text"] : null);
	$selected_category = (isset($_REQUEST["selected_category"]) ? $_REQUEST["selected_category"] : null);
	
	$search_panel = '
	<style>
		input[type=text], select, textarea{
			padding: 12px;
			border: 1px solid #ccc;
			border-radius: 4px;
			box-sizing: border-box;
			resize: vertical;
		}	
	</style>
	<form name="form" id="form" method="post" class="form" action="'.$thisPage.$curPage.'" enctype="multipart/form-data">
		<div class="col l-col12 m-col12 s-col12" style="margin-bottom:0">
			<h3 class="h4-teaser" style="margin-bottom:5px">
				<strong>Search by: </strong>
			</h3>
		</div>
		<div class="col l-col12 m-col12 s-col12" style="border:1px solid #333333; padding:10px 0px 0px 10px;">
			<div>
				<h4 class="h4-teaser" style="margin-bottom:3px">
					<strong>Company\'s name or product</strong>
				</h4>
				<input value="'.(isset($search_text) ? $search_text : '').'" type="text" name="search_text" style="height:31px; width:280px" placeholder="type here ..">
			</div>
			<div style="margin-top:15px">
				<h4 class="h4-teaser" style="margin-bottom:3px">
					<strong>In the following category</strong>
				</h4>';
				$sql = 
				" SELECT a.idsubkat, namasubkat ".
				" FROM dt_subkategori as a, dt_produk_registrasi_exhibitor as b ".
				" WHERE a.idsubkat = b.idsubkat ".
				" ORDER BY namasubkat ";
				if ($hasil = mysql_query($sql, $conn2)) {
					$_cek = '';
					if (mysql_num_rows($hasil) > 0) {
						$search_panel .= '
						<select name="selected_category">
							<option value=""> - All - </option>';
							while ($data = mysql_fetch_array($hasil)) {
								if ($_cek != $data["idsubkat"]) {
									$_cek = $data["idsubkat"];
									$selected_ = ($selected_category==$data["idsubkat"] ? 'selected' : '');
									$search_panel .= '
									<option '.$selected_.' value="'.$data["idsubkat"].'"> '.$data["namasubkat"].' </option>';
								}
							}
							$search_panel .= '
						</select>';
					}
				}
				$search_panel .= '
			</div>
			<div style="margin-top:15px">
				<input type="submit" class="button-search" name="action" value="Search Now">
			</div>
		</div>
	</form />
	<div style="clear:both;height:20px"></div>';		

	$id = (isset($_REQUEST["id"]) ? $_REQUEST["id"] : null);
    if ($id) {
		include ("exhibitor_list_detil.php");
	} else {
		$dis_produk = ''; $ctr = 0;
		$sql = 
		" SELECT DISTINCT(idexhibitor) ".
		" FROM dt_exhibitor as a, dt_hall as b, ".
		" dt_produk_registrasi_exhibitor as c, dt_subkategori as d ".
		" WHERE nama_company <> '' ".
		" AND a.id_hall = b.id_hall ".
		" AND a.email = c.email ".
		" AND c.idsubkat = d.idsubkat ";
		//echo "<br>sql: ".$sql; 
		if ($search_text) {
			$sql .= "
			AND (
				UPPER(nama_company)  like '%".strtoupper($search_text)."%' "."  
				OR UPPER(nama_brand) like '%".strtoupper($search_text)."%' "." 
				OR UPPER(namasubkat) like '%".strtoupper($search_text)."%' "."  
				OR UPPER(ket_subkat) like '%".strtoupper($search_text)."%' "."  
			)";	
		}		
		if ($selected_category) {
			$sql .= 
			" AND d.idsubkat = $selected_category ";	
		}
		
		$max = (mysql_num_rows(mysql_query($sql, $conn2))>0 ? mysql_num_rows(mysql_query($sql, $conn2)) : 0);
		$perhalaman = 9;
		$page = (isset($_SESSION['page']) ? $_SESSION['page'] : (isset($_REQUEST["page"]) ? $_REQUEST["page"] : null));
		//if (!$page) $page = $_REQUEST["page"];
		if ($page){
			$start=($page - 1) * $perhalaman;
		} else {
			$start=0;
		}
		
		$sql .= 
		" ORDER BY nama_company ".
		" LIMIT $start, $perhalaman ";
		if ($hasil = mysql_query($sql, $conn2)) {
			if (mysql_num_rows($hasil) > 0) {
				$list_idexhibitor = null;
				while ($data = mysql_fetch_array($hasil)) {
					if ($list_idexhibitor) $list_idexhibitor .= ',';
					$list_idexhibitor .= $data["idexhibitor"];
				}
			}
		}
		
		$sql = 
		" SELECT idexhibitor, nama_company, logo, a.id_hall, b.id_hall, ".
		" nama_stand, nama_hall, a.idexhibitor, namasubkat, nama_brand ".
		" FROM dt_exhibitor as a, dt_hall as b, ".
		" dt_produk_registrasi_exhibitor as c, dt_subkategori as d ".
		" WHERE nama_company <> '' ".
		" AND a.id_hall = b.id_hall ".
		" AND a.email = c.email ".
		" AND c.idsubkat = d.idsubkat ".
		" AND idexhibitor in ($list_idexhibitor) ".
		" ORDER BY nama_company ";
		//echo "<br>sql: ".$sql; 
		
		$ctr = 1;
		//echo "<br>sql: ".$sql;
		if ($hasil = mysql_query($sql, $conn2)) {
			if (mysql_num_rows($hasil)) {
				$cek_company_name = '';
				while ($data = mysql_fetch_array($hasil)) {
					if ($cek_company_name != $data["nama_company"] && $data["namasubkat"]) {
						$cek_company_name = $data["nama_company"];
						if ($data["logo"]) {
							$imageName = 'http://account.tradexpoindonesia.com/uploads/logo/'.$data["logo"];
							$img_style = 'max-height:168px;';
						} else {
							$imageName = $thisPage.'images/logo/logo_desktop.png';
							$img_style = 'display:inline-block; width:195px; padding:35px 0px 0px 0px';
						}
						
						if (!isset(${"Kolom$ctr"})) ${"Kolom$ctr"} = '';
						${"Kolom$ctr"} .= '
						<div class="card card-1">
							<a href="'.$thisPage.'attending/exhibitors-products-profile/?id='.$data["idexhibitor"].'" data-teaserId="M00601">
								<div align="center" style="margin-bottom:20px">
									<img style="$img_style" src="'.$imageName.'" border="0" />
								</div>
								<p align="center" style="margin:0; padding:0" >
									<h3 style="line-height:normal; text-align:center">
										'.strtoupper($data["nama_company"]).'
									</h3>
									<p>
										<table>
											<tr valign="top">
												<td style="color:#000000; font-weight:bold">Hall Number</td>
												<td style="color:#000000; font-weight:bold">'.$data["nama_hall"].'</td>
											</tr>
											<tr valign="top">
												<td style="color:#000000; font-weight:bold">Stand Number</td>
												<td style="color:#000000; font-weight:bold">'.$data["nama_stand"].'</td>
											</tr>
										</table>
									</p>
								</p>
								<div align="center" style="margin:20px;">
									<div id="box-detail">view detail</div>
								</div>
							</a>	
						</div>';
						${"Kolom$ctr"} .= '
						<div class="card card-1" style="width:332px; margin-bottom:25px">
							<a href="'.$thisPage.'attending/exhibitors-products-profile/?id='.$data["idexhibitor"].'&search_text='.$search_text.'&selected_category='.$selected_category.'" data-teaserId="M00601">
								<div class="teaserTextBlock" style="text-align:center; padding-top:16px;">
									<div style="height:368px;">
										<div style="height:208px; padding:0px 10px">
											<img style="max-height:190px" style="$img_style" src="'.$imageName.'" border="0" />
										</div>
										<div style="height:88px; padding:0px 10px">
											<h3 style="line-height:normal; text-align:center">
												'.strtoupper($data["nama_company"]).'
											</h3>
										</div>
										<div style="height:80px; padding:0px 10px">
											<p align="center">
												Hall Number: '.$data["nama_hall"].'<br>
												Stand Number: '.$data["nama_stand"].'
											</p>
										</div>
									</div>
									<div align="center" style="margin:20px;">
										<div id="box-detail">view detail</div>
									</div>
								</div>		
							</a>			
						</div>';			
						if ($ctr == 3) $ctr = 0;
						$ctr++;
					}
				}
			} else {
				$dis_produk = '
				<div class="col l-col12 m-col12 s-col12" style="background-color:#cccccc">
					<div class="teaserTextBlock" style="text-align:center; padding:16px 0px 16px 0px;">
						<p>Data not found.</p>
					</div>
				</div>';
			}
		}
		
		$dis_produk = '
		<div class="teasers">
			<div class="col l-col4 m-col6 s-col12">
				<div class="teasers">
					'.(isset($Kolom1) ? $Kolom1 : '').'
				</div>
			</div>	
			<div class="col l-col4 m-col6 s-col12">
				<div class="teasers">
					'.(isset($Kolom2) ? $Kolom2 : '').'
				</div>
			</div>
			<div class="col l-col4 m-col6 s-col12">
				<div class="teasers">
					'.(isset($Kolom3) ? $Kolom3 : '').'
				</div>
			</div>
		</div>';
		/** 
		echo '
		<form name="form" id="form" method="post" class="form" action="?" enctype="multipart/form-data" onsubmit="return validate(this)">
			<div class="col l-col12 m-col12 s-col12" style="margin:0; padding:7px 0px; background-color:#999999">
				<div class="col l-col5 m-col12 s-col12">
					<div class="styled-select grey" style="float:left;">
						<select id="search_category">
							<option value="">- Select -</option>
							<option value="1">Product Category</option>
							<option value="2">Product Sub Category</option>
							<option value="3">Hall Number</option>
							<option value="4">Company Name</option>
						</select>
					</div>	
				</div>
				<div class="col l-col7 m-col12 s-col12">
					<div id="sub_search_category" class="styled-select grey" style="float:left;">
						<select>
							<option value="">- Select -</option>
						</select>
					</div>
					<span class="icon" style="float:left; padding:6px 22px; background-color:#999999;"><i class="fa fa-search" style="color:#ffffff;"></i></span>
				</div>
			</div>
		</form />
		<div style="clear:both;height:20px"></div>';
		**/
		
		echo $search_panel;
		echo $dis_produk;		
		
		echo '
		<div class="col l-col12 m-col12 s-col12" style="margin:0; width:100%;clear:both; background-color:#fff;">
			<div class="col l-col12 m-col12 s-col12">
				<div class="teasers">
					<div style="margin:15px 0px 30px 0px;">';
						$tmp = $thisUrl."functions/fungsi_paging.php";
						include($tmp);
						halaman($max, $perhalaman, 2, 'search_text='.$search_text.'&selected_category='.$selected_category.'&');
						echo '
					</div>
				</div>
			</div>
		</div>';
	}
    ?>