<?php
	require_once("koneksi.php");
    include 'header.php';
?>

	<!-- breadcrumbs -->
		<div class="breadcrumbs">
			<div class="container">
				<ol class="breadcrumb breadcrumb1">
				<?php
	                if (isset($_SESSION['pengunjung'])) {
					    echo '
						<li><span><i class="fa fa-sign-in" aria-hidden="true"></i><a href="login.php"> Masuk</a></span></li>
						<li class="active">Keranjang Belanja</li> ';
					}
					else {
						echo '
						<li><a href="index.php"><span class="glyphicon glyphicon-home" aria-hidden="true"></span>Beranda</a></li>
						<li class="active">Keranjang Belanja</li> ';
					}
				?>
				</ol>
			</div>
		</div>
	<!-- //breadcrumbs -->
	<!-- checkout -->
			<div class="container">
				<h2><br>Detail keranjang belanja :</h2><br>
				<div class="checkout-right">
					<table class="timetable_sub table table-bordered table-hover">
						<thead>
							<tr>
								<th>No. Pesanan</th>	
								<th>ISBN</th>
								<th>Judul Buku</th>
								<th>Harga</th>
								<th>Jumlah</th>
								<th>Sub-Total</th>
								<th>Opsi</th>
							</tr>
							<?php    
			    				$total = 0;
							    if (isset($_SESSION['items'])) {
							        foreach ($_SESSION['items'] as $key => $val) {
							            $query = mysqli_query($koneksi, "SELECT * FROM t_buku WHERE isbn = '$key'");
							            $data = mysqli_fetch_array($query);

							            $jumlah_harga = $data['harga'] * $val;
							            $total += $jumlah_harga;
							            $no = 1;
				            ?>
						</thead>
						<tr class="rem1">
							<td class="invert"><?php echo $no++; ?></td>
							<td class="invert"><?php echo $data['isbn']; ?></td>
							<td class="invert"><?php echo $data['judul']; ?></td>
							<td class="invert"><?php echo $data['harga']; ?></td>
							<td class="invert"><?php echo number_format($val); ?></td>
							<td class="invert">Rp.<?php echo number_format($jumlah_harga); ?>,00</td>
							<td class="invert">
								<div class="rem">
									<div>
						                <a href="function.php?act=min&amp;barang_id=<?php echo $key; ?>&amp;ref=singlebook.php">
						                	<img src="images/minus.png" />
						                </a>
						                <a href="function.php?act=plus&amp;barang_id=<?php echo $key; ?>&amp;ref=singlebook.php">
											<img src="images/plus.png" />
										</a>
						                <a onclick="if(confirm('Apakah Anda yakin ingin menghapus data ini ?')){ location.href='function.php?act=del&amp;barang_id=<?php echo $key; ?>&amp;ref=singlebook.php' }">
						                	<img src="images/close_1.png" />
						                </a>
									</div>
								</div>
							</td>
						</tr>
						<?php
								}
							}
						?>
						<?php
							if($total != 0 && isset($_SESSION['pengunjung'])){
								echo '
									<tr style="background-color:#dbase_delete_record(dbase_identifier, record_number);"><td colspan="5" align="right"><b>Total :</b></td><td align="right"><b>Rp. '.number_format($total,2,",",".").'</b></tr></table>
									<p><div align="right">
										<div class="checkout-right-basket">
											<a href="allbook.php"><span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span>Lanjut Berbelanja</a>
											<a href="savebook.php">Lakukan pembayaran &nbsp&nbsp;<span class="glyphicon glyphicon-menu-right" aria-hidden="true"></span></a>
											<br><br><br><br><br><br>
										</div>
									</div></p>
									';
								}
							elseif($total != 0) {
								echo '
									<tr style="background-color:#dbase_delete_record(dbase_identifier, record_number);"><td colspan="5" align="right"><b>Total :</b></td><td align="right"><b>Rp. '.number_format($total,2,",",".").'</b></td></td></td></tr></table>
									<p><div align="right">
										<div class="checkout-right-basket">
											<a href="allbook.php"><span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span>Lanjut Berbelanja</a>
											<a href="login.php"><span aria-hidden="true"></span>Masuk Lebih Dulu</a>
											<br><br><br><br><br>
											</div>
									</div></p>
									';
								}
							else {
								echo '
									<tr><td colspan="7" align="center" style="background-color:#ffffff">
										Ups, Keranjang belanja kosong ! </td></tr></table>
									<div class="checkout-right-basket">
											<a href="allbook.php"><span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span>Lanjut Berbelanja</a>
											<br><br><br><br><br>
									</div>
								';
								}
						?>
					</table>
				</div>
			</div>
	<!-- //checkout -->
	
<?php
	include 'footer.php';
?>