<style>
	ul.listed {
		margin-left:0px; 
		padding:5px 5px 10px 15px;
	}
	.listed li {
		list-style: square;
		list-style-position: outside;
		margin:0; padding:0;
		padding-left:5px;
	}
	
	.hvr-sweep-to-right{
		padding:6px; 
		width:100px;
		text-align:center;
	}
	.custom td {
		border:0;
		margin-bottom: 15px;
		background-color:#FFFFFF;
	}
	.custom td img{
		width:66px;
	}
	.panel_right {
		/**
		margin-left:0px; 
		padding-left:0px; 
		border-left-width:2px;
		border-left-color:#CCCCCC;
		border-left-style:double;
		padding-left:15px;
		**/
	}
	.custom tr {
		border-bottom: 2px solid #CCCCCC;
		margin-bottom: 20px;
	}

	.search {
		width: 100%;
		position: relative;
		display: flex;
	}
	
	.searchTerm {
		width: 100%;
		border: 3px solid #00B4CC;
		padding: 5px;
		height: 20px;
		border-radius: 5px 0 0 5px;
		outline: none;
		color: #9DBFAF;
	}
	
	select.searchTerm {
		height:38px;
		color:#003;
	}
		select.searchTerm option{
			color:#039;
		}
	
	.searchTerm:focus{
		color: #00B4CC;
	}
	
	.searchButton {
		width: 100px;
		height: 36px;
		border: 1px solid #00B4CC;
		background: #00B4CC;
		text-align: center;
		color: #fff;
		border-radius: 0 5px 5px 0;
		cursor: pointer;
		font-size: 20px;
	}
	<?php
	echo '
	.panel_left {
		margin-left:0px; 
		margin-right:0px; 
		padding-left:0px; 
		border-right-width:2px;
		border-right-color:#CCCCCC;
		border-right-style:double;
		background-image: url('.$thisPage.'images/content/background/background_exhlist.jpg);
		background-position: center center;
		background-repeat: no-repeat;
		max-width:100%;
		background-size:100% auto;
		background-color:#08ab4e;
	}
	
	';
	?>
</style>

<?php
include ($thisUrl."adm1n/functions/php_functions.php");
$dis_produk = ''; $ctr = 0; $list_data = '';

$detail = (isset($_REQUEST["detail"]) ? $_REQUEST["detail"] : null);

$sql = 
" SELECT *, a.id as exhibitor_id, a.description as companyProfile, ".
" c.product_name as product_name, b.product_name as nmProduk ".
" FROM exhibitors as a ".
" LEFT JOIN exhibitor_images as b ON a.id = b.exhibitor_id ". 
" LEFT JOIN exhibitor_sub_products as c ON a.id = c.exhibitor_id ".
" WHERE a.exhibitor_name <> '' ".
//" AND a.regency_id IS NOT NULL ".
" AND a.id > 22 ";

if ($detail) $sql .= " AND a.id = '".$detail."' ";

$listingProduct = (isset($_REQUEST["listingProduct"]) ? $_REQUEST["listingProduct"] : null);
if ($listingProduct) $sql .= " AND product_sub_interest_id = ".$listingProduct;

$hall = (isset($_REQUEST["hall"]) ? $_REQUEST["hall"] : null);
if ($hall) $sql .= " AND hall = '".$hall."'";

$search_text = (isset($_REQUEST["search_text"]) ? $_REQUEST["search_text"] : '');
if ($search_text) {
	$sql .= "
	AND (
		UPPER(exhibitor_name)  like '%".strtoupper($search_text)."%' "."  
		OR UPPER(a.description) like '%".strtoupper($search_text)."%' "." 
		OR UPPER(c.product_name) like '%".strtoupper($search_text)."%' "." 
		OR UPPER(b.product_name) like '%".strtoupper($search_text)."%' "." 
		OR UPPER(type_product) like '%".strtoupper($search_text)."%' "."  
		OR UPPER(name_merk) like '%".strtoupper($search_text)."%' "."  
	)";	
}

$sql .= 
" ORDER BY exhibitor_name, product_sub_interest_id, ".
" path, b.product_name ".
" LIMIT 0, 500 ";

$sql2 = $sql; 

//echo $sql;

echo '
<p>
	Following are the Exhibitor\'s List of Trade Expo Indonesia Virtual Exhibition (TEI-VE) 2020. 
	Exhibitor\'s List of the 2021 Trade Expo Indonesia Digital Edition (TEI-DE) 2021 will be updated shortly.
</p>
<div class="col l-col12 m-col12 s-col12" style="margin:0;padding:0;">
	<div class="col l-col4 m-col6 s-col12 panel_left">
		<div style="padding:28px">
			<form name="form" id="form" method="post" class="form" action="'.$thisPage.$curPage.'" enctype="multipart/form-data">
				<p>
					<h5 class="h5-teaser" style="color:#ffffff; margin-top:18px; margin-bottom:1px">
						Enter Keyword <br>
					</h5>
					<div class="search">
						<input type="text" name="search_text" class="searchTerm" '.($search_text!='' ? ' value="'.$search_text.'" ' : '').' placeholder="What are you looking for?">
					</div>
				</p>
				<p>
					<h5 class="h5-teaser" style="color:#ffffff; margin-top:18px; margin-bottom:1px">
						Product\'s Listing
					</h5>
					<select name="listingProduct" class="searchTerm">
						<option value=""> - All - </option>';
						$sql3 =
						" SELECT * FROM exhibitor_sub_products ".
						" ORDER BY sub_product_name ";
						if ($result = mysql_query($sql3, $conn2)) {
							$subprod = array();
							while ($row = mysql_fetch_array($result)) {
								$subprod[] = array(
									"product_sub_interest_id" => $row["product_sub_interest_id"],
									"sub_product_name" 		  => $row["sub_product_name"]
								);						
							}
							//var_dump($subprod);
							foreach ($subprod as $key => $row) {
								$s_id[$key] = $row["product_sub_interest_id"];
								$s_nm[$key]  = $row["sub_product_name"];
							}
							array_multisort($s_id,SORT_ASC, $s_nm,SORT_ASC,  $subprod);
							$nama_product = $selected = '';
							foreach($subprod as $value) {
								if ($nama_product != $value) {
									if ($listingProduct == $value["product_sub_interest_id"])
										$selected = ' selected ';
									else 
										$selected = '';	
									echo '
									<option '.$selected.' value="'.$value["product_sub_interest_id"].'">
										'.$value["sub_product_name"].'
									</option>';
									$nama_product = $value;
								}
							}
						}						
						echo '
					</select>
				</p>
				<p>
					<h5 class="h5-teaser" style="color:#ffffff; margin-top:18px; margin-bottom:1px">
						Exhibition Hall
					</h5>
					<select name="hall" class="searchTerm">
						<option value=""> - All - </option>';
						$hallArr = array(
							"Hall 5", "Hall 6", "Hall 7",
							"Hall 8", "Hall 9", "Hall 10"
						);
						foreach ($hallArr as $value) {
							if ($hall == $value)
								$selected = ' selected ';
							else 
								$selected = '';	
							echo '
							<option '.$selected.' value="'.$value.'">
								'.$value.'
							</option>';
							
						}
						echo '
					</select>
				</p>
				<p style="margin-top:38px; margin-bottom:0; text-align:center">
					<button type="submit" class="searchButton">
						Search
					</button>
				</p>
			</form>
		</div>
	</div>
	<div class="col l-col8 m-col6 s-col12 panel_right">
		<div style="overflow-y: scroll; height:350px; max-height: 100vh;">
			<p>';
				$rows = $exhibitor_name = ''; $counter = 0;
				$products = $images = array();
				if ($result = mysql_query($sql, $conn2)) {
					$total_record = mysql_num_rows($result);
					while ($row = mysql_fetch_array($result)) {
						$products[] = array(
							"product_name"     => (isset($row["product_name"]) ? $row["product_name"] : null),
							"sub_product_name" => (isset($row["sub_product_name"]) ? $row["sub_product_name"]: null)
						);						
						$images[] = array(
							"path"     	   => (isset($row["path"]) ? $row["path"] : null),
							"product_name" => (isset($row["nmProduk"]) ? $row["nmProduk"] : null)
						);						
						
						$row_details = '
						<tr>
							<td width="25%" align="center" style="text-align:center">
								<img class="img-fluid" src="'.$row["logo"].'" border="0" />
							</td>
							
							<td width="65%">
								<h3 style="margin-bottom:8px" class="h5-teaser">
									'.$row["exhibitor_name"].'<br>
									<span style="font-weight:normal">
										'.$row["hall"].'
									</span>
								</h3>
								<p>';
									if ($row["type_product"])
										$row_details .= '
										Product Type: '.$row["type_product"].' <br>';
									if ($row["name_merk"])
										$row_details .= '
										Brand Name: '.$row["name_merk"];
									$row_details .= '
								</p>
							</td>';
							
							if (!$detail)
							$row_details .= '
							<td width="10%" valign="right">
								<a href="?detail='.$row["exhibitor_id"].'" class="hvr-sweep-to-right">
									Details >>
								</a>
							</td>';
							$row_details .= '
						</tr>';
						
						if ($detail) {
							$row_details .= '
							<tr>
								<td colspan="2">
									'.($row["companyProfile"] ? '<p style="padding-top:10px">'.$row["companyProfile"].'</p>' : '').'
								</td>
							</tr>';
						}
						
						if ($exhibitor_name != $row["exhibitor_name"]) {
							$exhibitor_name = $row["exhibitor_name"];
							$rows .= $row_details;
						} 
						
						if ($counter == $total_record) {
							$rows .= $row_details;
						}
						
						$counter++;
					}
				}
				if ($detail) {
					if ($products) {
						foreach ($products as $key => $row) {
							$s_product_name[$key]     = $row["product_name"];
							$s_sub_product_name[$key] = $row["sub_product_name"];
						}
						array_multisort($s_product_name,SORT_ASC, $s_sub_product_name,SORT_ASC, $products);
						
						$rows .= '
						<tr style="border:0">
							<td colspan="2">
								<p style="margin-top:18px">
									Our Products listed on the following categories: 
									<table>';
									$product_name = $sub_product_name = '';
									foreach ($products as $value){
										if ($product_name != $value["product_name"]) {
											if ($product_name) {
												$rows .= '
												</ul>
												<strong>'.$value["product_name"].'</strong><br>
												<ul class="listed">';	
											} else {
												$rows .= '
												<strong>'.$value["product_name"].'</strong><br>
												<ul class="listed">';	
											}
											$product_name = $value["product_name"];
										}
										if ($sub_product_name != $value["sub_product_name"]) {
											$rows .= '
											<li>'.$value["sub_product_name"].'</li>';
											$sub_product_name = $value["sub_product_name"];
										}
									}
									$rows .= '
									</table>
								</p>
							</td>
						</tr>';
					}
					
					if ($images) {
						foreach ($images as $key => $row) {
							$s_path[$key]         = $row["path"];
							$s_product_name[$key] = $row["product_name"];
						}
						array_multisort($s_path,SORT_ASC, $s_product_name,SORT_ASC, $images);
						
						if ($images) {
							$path = $product_name = '';
							foreach ($images as $value){
								if ($value["path"]) {
								if (!$path) {
								$rows .= '
								<tr style="border:0">
									<td colspan="2">
										<p><strong>Product(s) Images</strong>:</p>
										<div class="col l-col12 m-col12 s-col12">';}
										if ($path != $value["path"]) {
											$rows .= '
											<div class="col l-col4 m-col6 s-col12">
												<a href="'.$value["path"].'" target="_blank">
													<img class="img-fluid" src="'.$value["path"].'" border="0" />
												</a>
												<p>'.$value["product_name"].'</p>
											</div>';
											$path = $value["path"];
										}

								}
							}
							if ($path) {
										
										$rows .= '
									</div>
								</td>
							</tr>';}
						}
					}

					$rows .= '
					<tr style="border:0">
						<td colspan="2">
							<p style="margin-top:18px">
								<a href="?" class="hvr-sweep-to-right">
									<< Back
								</a>
							</p>
						</td>
					</tr>';
				}
				echo '
				<table class="custom">
					'.$rows.'
				</table>
			</p>
		</div>
	</div>
</div>';
?>