<?php session_start();
	include("../../init.php");
	if (!$_SESSION['username']){
		echo "<script language=JavaScript>";
		echo "location.href = '".$thisPage."login.php';";
		echo "</script>";
	}
	
	$tmp = $thisUrl."koneksi.php";
	include ($tmp);
	//echo "<br>Temp : ".$tmp;

	$action=$_REQUEST["action"];
	$menu=$_REQUEST["menu"];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>WEBSITE BACKOFFICE </title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<link href="<?php echo $thisPage.'style.css'; ?>" rel="stylesheet" type="text/css">
		<link href="<?php echo $thisPage.'pagination.css'; ?>" rel="stylesheet" type="text/css">
        
        
        <link rel="stylesheet" type="text/css" href="<?php echo $thisPage; ?>tabs/font-awesome.min.css">
        <link rel="stylesheet" type="text/css" href="<?php echo $thisPage; ?>tabs/responsive-tabs.css">

		<script language="JavaScript" type="text/javascript" src="<?php echo $thisPage.'richtext.js'; ?>"></script>
		<script language="JavaScript" type="text/javascript">
		<!--
		function submitForm() {
			//make sure hidden and iframe value are in sync before submitting form
			//to sync only 1 rte, use updateRTE(rte)
			//to sync all rtes, use updateRTEs
			updateRTE('description');
			//updateRTEs();
			//alert("rte1 = " + document.RTEDemo.content.value);
			
			//change the following line to true to submit form
			return true;
		}
		
		//Usage: initRTE(imagesPath, includesPath, cssFile)
		initRTE("images/", "", "");
		//-->
		</script>				



	</head>	
	<body>
		<center>
			<table width="987">
				<tr valign="top">
					<td width="207" class="bg">
						<?php 
						$tmp = $thisUrl."kiri.php";
						include ($tmp);
						?>
					</td>
					<td width="10"></td>
					<td width="770">
						<?php 
						$tmp = $thisUrl."logo.php";
						include ($tmp);
						$sql  = "select * from buyer_register order by date_register desc";
						
						$sql2 = "select distinct(country) from buyer_register";
						$maxCountry = mysql_num_rows(mysql_query($sql2));
						
						$max = mysql_num_rows(mysql_query($sql));
						if ($max > 0) {
							echo '
							<div id="container">
								<div class="tabs">
									<input type="radio" name="tabs" id="tab1" checked >
									<label for="tab1">
										<i class="fa fa-html5"></i><span>Buyer List</span>
									</label>
									<input type="radio" name="tabs" id="tab2">
									<label for="tab2">
										<i class="fa fa-css3"></i><span>Statistic</span>
									</label>
									<input type="radio" name="tabs" id="tab3">
									<label for="tab3">
										<i class="fa fa-code"></i><span>Country List</span>
									</label>
									
									<!-- #tab-content1 -->
									<div id="tab-content1" class="tab-content">
										<h3>Buyer List</h3>
										<p>';
											echo '
											<table width="100%" cellpadding="5" cellspacing="1" bgcolor="#666666" border="0">
												<tr bgcolor="#e6e6e6">
													<td align="center"><strong>No</strong></td>
													<td><strong>Date Register</strong></td>
													<td align="center"><strong>Buyer ID</strong></td>
													<td><strong>Full Name</strong></td>
													<td><strong>Company Name</strong></td>
													<td align="center"><strong>Action</strong></td>
												</tr>
											';
											$nomor=0;
											if ($hasil = mysql_query($sql)) {
												while ($data = mysql_fetch_array($hasil)) {
													$nomor++;
													echo '
													<tr bgcolor="#ffffff">
														<td align="center">'.$nomor.'</td>
														<td>'.date ("l, d-F-Y", strtotime($data["date_register"])).'</td>
														<td align="center">'.$data["buyerRegID"].'</td>
														<td>'.$data["fullName"].'</td>
														<td>'.$data["company_name"].'</td>
														<td align="center">
															<a href="">
																Detail
															</a>
														</td>
													</tr>
													';
												}
											}
											echo '
											</table>
											';
										
										echo '
										</p>
									</div> 
									<!-- #tab-content1 -->
									
									<!-- #tab-content2 -->
									';
									
									echo '
									<div id="tab-content2" class="tab-content">
										<h3>Buyer Statistic</h3>
										<p>
											Registered Buyer: '.$max.' <br>
											Number of Countries: '.$maxCountry.' <br>
										</p>
									</div> 
									<!-- #tab-content2 -->
									
									<!-- #tab-content3 -->
									<div id="tab-content3" class="tab-content">
										<h3>Country List</h3>
										<p>';
										$sql3 = "select * from buyer_register, form_element_value where valueID=country order by country";
										$cek = 0;
										if ($hasil3 = mysql_query($sql3)) {
											$nomor=0;	
											$negara = array();
											while ($data3 = mysql_fetch_array($hasil3)) {
												if ($cek != $data3["country"]) {
													$sql4 = "select country from buyer_register where country=".$data3["country"];
													$max4 = mysql_num_rows(mysql_query($sql4));
													//$data[] = array('volume' => 67, 'edition' => 2);
													$negara[] = array('nmNegara' => $data3["valueName"], 'jmNegara' => $max4);
													$cek = $data3["country"];
												}
											}
											foreach ($negara as $key => $row) {
												$nmNegara[$key] = $row['nmNegara'];
												$jmNegara[$key] = $row['jmNegara'];
											}											
											array_multisort($jmNegara, SORT_DESC, $nmNegara, SORT_ASC, $negara);
											//echo "max4 : ".$nmNegara;
											
											echo '
											<table width="100%" cellpadding="5" cellspacing="1" bgcolor="#666666" border="0">
												<tr bgcolor="#e6e6e6">
													<td align="center"><strong>No</strong></td>
													<td><strong>Nama Negara</strong></td>
													<td align="center"><strong>Jumlah</strong></td>
												</tr>';
												foreach ($negara as $key => $value) {
													$nomor++;
													echo '
													<tr bgcolor="#ffffff">
														<td align="center">'.$nomor.'</td>
														<td>'.$value["nmNegara"].'</td>
														<td align="center">'.$value["jmNegara"].'</td>
													</tr>';
												}
												echo '
											</table>';
										}
										echo '
										</p>
									</div> 
									<!-- #tab-content3 -->
								</div> <!-- .tabs -->
							</div>
							';
							
						} else {
							?>
							<table cellpadding="0" cellspacing="0" border="0">
								<tr valign="top">
									<td align="center">
										<img src="images/loading.gif" border="0"><br>
									</td>
								</tr>
								<tr>
									<td align="left">
										<div id="spasi1d"></div>
										<strong>Updating on progress, please check back later</strong> 
									</td>
								</tr>
							</table>
							<?php
						}
						?>
					</td>
				</tr>
			</table>
		</center>
	</body>
</html>	