<?php session_start();
	include_once("../../functions/init.php"); 

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

	$tmp = $thisUrl."adm1n/functions/koneksi.php";
	include_once ($tmp);
	
	$page = $_REQUEST["page"];
	$_SESSION["page"] = $page;
	//echo dirname(__FILE__);
	//echo "<br>".$thisUrl;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<?php
		$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/php_functions.php";
						include ($tmp);
						
						echo '<div>'.$txt_legend.'</div>';
						
						$regID = $_REQUEST["regID"];
						$buyerReport = $_POST["buyerReport"];
						if ($buyerReport == "Export to Excell") {
							include ("php-to-excell.php");
						} else if ($regID) {
							$sql = "SELECT * FROM buyer_register WHERE buyerRegID = '$regID' ";
							if ($hasil = mysql_query($sql)) {
								while ($data = mysql_fetch_array($hasil)) {
									echo '
									<div style="clear:both; margin-bottom:10px"></div>
									<table width="100%" cellpadding="6" cellspacing="1" border="0" bgcolor="#999">
										<tr valign="top" bgcolor="#ffffff">
											<td width="28%">Date Register</td>
											<td width="70%">'.date("l, F m, Y", strtotime($data["date_register"])).'</td>
										</tr>					
										<tr valign="top" bgcolor="#ffffff">
											<td>Buyer ID</td>
											<td>'.$data["buyerRegID"].'</td>
										</tr>					
										<tr valign="top" bgcolor="#ffffff">
											<td>Full Name</td>
											<td>'.$data["fullName"].'</td>
										</tr>
										<tr valign="top" bgcolor="#ffffff">
											<td>Gender</td>
											<td>'.FindData($data["gender"], "form_element_value", $dataTitle, $dataRecord).'</td>
										</tr>					
										<tr valign="top" bgcolor="#ffffff">
											<td>Negara</td>
											<td>'.FindData($data["country"], "form_element_value", $dataTitle, $dataRecord).'</td>
										</tr>
										<tr valign="top" bgcolor="#ffffff">
											<td>Kota / Propinsi</td>
											<td>';
												if ($data["kota_propinsi"] == '279') {
													echo $data["kota_propinsi_lain"];
												} else {
													echo FindData($data["kota_propinsi"], "form_element_value", $dataTitle, $dataRecord);
												}
											echo '
											</td>
										</tr>
										<tr valign="top" bgcolor="#ffffff">
											<td>Nama Perusahaan</td>
											<td>'.$data["company_name"].'</td>
										</tr>					
										<tr valign="top" bgcolor="#ffffff">
											<td>Nomor Telpon Perusahaan</td>
											<td>'.$data["telpon"].'</td>
										</tr>					
										<tr valign="top" bgcolor="#ffffff">
											<td>Alamat Perusahaan</td>
											<td>'.$data["alamat_perusahaan"].'</td>
										</tr>					
										<tr valign="top" bgcolor="#ffffff">
											<td>Kode Pos</td>
											<td>'.$data["kdpos"].'</td>
										</tr>					
										<tr valign="top" bgcolor="#ffffff">
											<td>Nomor Hand Phone</td>
											<td>'.$data["hp"].'</td>
										</tr>					
										<tr valign="top" bgcolor="#ffffff">
											<td>Alamat Email</td>
											<td>'.$data["email"].'</td>
										</tr>			
										<tr valign="top" bgcolor="#ffffff">
											<td>Menghadiri TEI tahun lalu</td>
											<td>'.FindData($data["attend_last_year"], "form_element_value", $dataTitle, $dataRecord).'</td>
										</tr>					
										<tr valign="top" bgcolor="#ffffff">
											<td>Mengetahui TEI dari</td>
											<td>
												<ul style="margin:0; padding:0px 0px 0px 18px">';
													$sql2 = "SELECT * FROM buyer_register_knowfrom WHERE link_to_buyer = '".$data["buyerID"]."' ";
													//echo $sql2;
													if ($hasil2 = mysql_query($sql2)) {
														while ($data2 = mysql_fetch_array($hasil2)) {
															//echo "<br> value: ". $data2["link_to_table_value"];
															echo '
															<li style="padding:0px 0px 3px 0px">
																'.FindData($data2["link_to_table_value"], "form_element_value", $dataTitle, $dataRecord);
																if ($data2["link_to_table_value"] == '590') {
																	echo '
																	('.FindData($data["know_from_office_rep"], "form_element_value", $dataTitle, $dataRecord).')';
																}
															echo '	
															</li>
															'; 
														}
													}
												echo '	
												</ul>
											</td>
										</tr>
										<tr valign="top" bgcolor="#ffffff">
											<td>Produk yang diminati</td>
											<td>';
												$cek = "";
												$sql2 = "SELECT * FROM buyer_register_product WHERE link_to_buyer = '".$data["buyerID"]."' ";
												//echo $sql2;
												if ($hasil2 = mysql_query($sql2)) {
													while ($data2 = mysql_fetch_array($hasil2)) {
														$val = FindData($data2["link_to_product_value"], "form_element_value", $dataTitle, $dataRecord);
														if ($data2["link_to_product_table"] != $cek) {
															if ($cek != "") {
																$sql3 = "SELECT * FROM buyer_register_product_lain WHERE link_to_product_table = '$cek' AND link_to_buyer = '".$data["buyerID"]."' ";
																if ($hasil3 = mysql_query($sql3)) {
																	while ($data3 = mysql_fetch_array($hasil3)) {
																		echo '
																		<li style="padding:0px 0px 3px 0px">
																			'.$data3["byProdLainName"].'
																		</li>';
																	}
																}
																echo '
																</ul> <br>
																';
															}
															$cek = $data2["link_to_product_table"];
															echo '
															<strong>'.$dataTitle.'</strong>
															<ul style="margin:0; padding:0px 0px 0px 18px">
															';
															
														}
														echo '
														<li style="padding:0px 0px 3px 0px">
															'.$val.'
														</li>';
													}
													if ($cek) {
														echo '
														</ul>';
													}
												}
											echo '
											</td>
										</tr>			
									</table> 
									<div align="center" style="clear:both; margin:10px 0px 20px 0px">
										<a href="'.$thisPage.'adm1n/'.$curPage1.'"  class="menu-box" style="width:160px; color:#ffffff; margin-right:5px;">
											Back to list
										</a>
									</div>
									';
								}
							}
						} else {
							echo '
							<div id="container">
								<a id="tab1" class="menu-box" style="width:160px; margin-right:5px; float:left">Buyer List</a>
								<a id="tab2" class="menu-box" style="width:160px; margin-right:5px; float:left">Statistik</a>
								<a id="tab3" class="menu-box" style="width:160px; margin-right:5px; float:left">Country List</a>
							</div>
							<div style="clear:both; margin-bottom:10px"></div>';
							echo '
							<div id="tab-content">
							</div>';
						}
						?>
					</td>
				</tr>
			</table>
		</center>
	</body>
</html>	