<?php 
include "koneksi.php";
if (!isset($_SESSION["UserID"]))
{
	header("location:login.php?p=3");
}
?>
<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="style.css">
<html>
  <head>
	<title> Modifikasi Motor </title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<?php
		include "part/jss.php";
	?>
	
  </head>
  <body>
	
	<div class="container">
	
		<div class="span12">
			<div class="alert alert-info">
					<b><center><h1>MODIFIKASI MOTOR </h1></center></b>
			</div>
					
					<?php
						include "part/menu.php";
					?>
			
			
		<div class="alert alert-info" align='center'>
		<h3>UPLOAD REFERENSI SPAREPART</h3>
		<?php
		if (isset($_GET["p"]))
				{
					$p=mysqli_real_escape_string($conn,$_GET["p"]);
					if ($p=="3")
					{
						?>
							<div class="alert alert-primary" role="alert">
							  Referensi berhasil ditambah!
							</div>
						<?php
					}
					else if ($p=="1")
					{
						?>
							<div class="alert alert-primary" role="alert">
							  Referensi berhasil dihapus!
							</div>
						<?php
					}
				}
		?>
		
		<table class="table table-bordered">
			    <thead>
				  <tr>
				    <th>
					   Sparepart 
					</th>
					<th>
					   Kategori 
					</th>
					<th>
					   Jenis Motor 
					</th>
					<th>
					   Nama Motor 
					</th>
					<th>
					   Merk Sparepart
					</th>
					<th>
						Pilihan :
					</th>
				  </tr>
				</thead>
				<tbody>
				    <?php
						$user=$_SESSION["UserID"];
						$q="SELECT s.*,k.nama as ktg,j.nama as jns,m.nama as mrk,z.nama as mtr ".
						   "FROM sparepart s ".
						   "INNER JOIN kategori k ON (s.id_kategori=k.id) ".
						   "INNER JOIN jenis_motor j ON (j.id=s.id_jenisMotor) ".
						   "INNER JOIN merk_sparepart m ON (m.id=s.id_merkSparepart)".
						   "INNER JOIN kendaraan z ON (z.id=s.id_merkMotor)".
						   "ORDER BY k.nama ASC";
						$res=mysqli_query($conn,$q);
						while ($row=mysqli_fetch_assoc($res))
						{
							?>
							  <tr>
							    <td>
								  <?php
									echo $row["nama"];
								  ?>
								</td>
								<td>
								  <?php
									echo $row["ktg"];
								  ?>
								</td>
								<td>
								  <?php
									echo $row["jns"];
								  ?>
								</td>
								<td>
								  <?php
									echo $row["mtr"];
								  ?>
								</td>
								<td>
								  <?php
									echo $row["mrk"];
								  ?>
								</td>
								<td>
								  
								  |
								  <a href="referensisparepart1.php?id=<?php echo $row["id"];?>">LIHAT REFERENSI</a>
								  |
								  <?php
									$q="SELECT * FROM referensi_sparepart WHERE id_user='".$user."' AND id_sparepart='". $row["id"] ."'";
									//echo $q;
									$res2=mysqli_query($conn,$q);
									if ($row2=mysqli_fetch_assoc($res2))
									{
									}
									else {
										?>	
											|
										   <a href="tambahreferensi.php?id=<?php echo $row["id"];?>">TAMBAH</a>
										   |
										<?php
									}
								  ?>
								  
								 
								</td>
							  </tr>
							<?php
						}
					?>
				</tbody>
			 </table>
			
		</div>		
	</div>
	
  
  </body>
</html>




