<?php 
include "koneksi.php";
if (!isset($_SESSION["UserID"]))
{
	header("location:login.php?p=3");
}

$id="";
if (isset($_GET["id"]))
{
	$id=mysqli_real_escape_string($conn,$_GET["id"]);
}

?>
<!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";
						
						$q="SELECT * FROM sparepart WHERE id='$id'";
						
						$res=mysqli_query($conn,$q);
						$dataMerkMotor=mysqli_fetch_assoc($res);
						
						$z="SELECT * FROM referensi_sparepart WHERE id_sparepart='$id'";
						$ress=mysqli_query($conn,$z);
						$referensimotor=mysqli_fetch_assoc($ress);
						
						//echo $referensimotor['id'];
						//echo $dataMerkMotor['id'];
					?>
			
			
		<div class="alert alert-info" align='center'>
			 <h3>REFERENSI <?php echo $dataMerkMotor["nama"];?></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 dihapus!
							</div>
						<?php
					}
					else if ($p=="1")
					{
						?>
							<div class="alert alert-primary" role="alert">
							  Nama motor berhasil ditambah
							</div>
						<?php
					}
					else if ($p=="2")
					{
						?>
							<div class="alert alert-primary" role="alert">
							  Nama motor berhasil diupdate
							</div>
						<?php
					}
				}
			 ?>
			 <table class="table table-bordered">
			    <thead>
				  <tr>
				    <th>
					   Detail :
					</th>
					<th>
					  Gambar :
					</th>
					<th>
					  Harga:
					</th>
					<th>
					  Alamat :
					</th>
				  </tr>
				</thead>
				<tbody>
				    <?php
					 if (isset($_SESSION["UserID"]))
					 {
						$q="SELECT * FROM referensi_sparepart WHERE id_sparepart='". $_GET["id"] ."' AND id_user='". $_SESSION["UserID"] ."' ";
						
						$res=mysqli_query($conn,$q);
						while ($row=mysqli_fetch_assoc($res))
						{
							?>
							  <tr>
							    <td>
								  <?php
									echo $row["detail"];
								  ?>
								</td>
								<td>
								  <?php	  
								  ?>
								  <img style="max-height:80px" src="img/<?php echo $row["gambar"];?>"/>
								  <?php
								  ?>
								</td>
								<td>
								  <?php
									$hasil=number_format($row["harga"],0,',','.');
											echo "Rp.".$hasil;
								  ?>
								</td>
								<td>
								  <?php
									$b="SELECT * FROM user WHERE id='". $_SESSION["UserID"] ."'";
									$ress=mysqli_query($conn,$b);
									$dataUser=mysqli_fetch_assoc($ress);
									echo $dataUser["alamat"];
								  ?>
								</td>
								</th>
								<td>
								  
								  
								  <a href="deletereferensisparepart.php?id=<?php echo $row["id"];?>">|Hapus|</a>
								  
								</td>
							  </tr>
							<?php
						}
					 }
					?>
				</tbody>
			 </table>
			 |
			 <a href="referensisparepart.php?id=<?php echo $id;?>">KEMBALI</a>
			 |
			 <a href="updatereferensisparepart.php?id=<?php echo $referensimotor['id']?>">UPDATE</a>
			 |
		</div>		
	</div>
	
  
  </body>
</html>




