<?php
session_start();
include('config/koneksi2.php');

if(isset($_POST['add'])){
$qty = $_POST['qty'];
/*$size = $_POST['size'];
$color = $_POST['color'];
$config = $_POST['config'];

$sql=mysql_query("select id from bs_stok where kode_ax='$kode' and size_ax='$size' and config_ax='$config', and colour_ax='$color'");
$data =mysql_fetch_array($sql);*/

	$id = mysql_real_escape_string((int)$_POST['add']);
	$qt = mysql_query("SELECT id, stok FROM bs_stok WHERE id='$id'");
	while($qt_row = mysql_fetch_assoc($qt)){
		//if($qt_row['stok'] != $_SESSION['cart_'.$_GET['add']] && $qt_row['stok'] > 0){
		if($qt_row['stok'] != $_SESSION['cart_'.$_POST['add']]){
			$_SESSION['cart_'.$_POST['add']]+=1;
		} else {
			echo 'stok habis';
		}
	}
}
	foreach($_SESSION as $name => $value){
		if($value > 0){
			if(substr($name, 0, 5) == 'cart_'){
				$id1 = substr($name, 5, (strlen($name)-5));
				$get = mysql_query("SELECT * FROM bs_stok WHERE id='$id1'");
				while($get_row = mysql_fetch_assoc($get)){
					//$sub = $get_row['retail'] * $value;
					$sub = $get_row['dealer'] * $value;
					//echo '<div style="font-size:11px; margin-bottom:-10px">&raquo; '.$get_row['nama'].' @ Rp. '.$get_row['dealer'].' X '.$value.' = Rp. '.$sub.'</div><br>';
					echo '<div style="font-size:11px; margin-bottom:-10px">&raquo; '.$get_row['nama'].' '.$get_row['config_ax'].' '.$get_row['size_ax'].' '.$get_row['colour_ax'].' '.$value.' </div><br>';
				}
			}
			$total += $sub;
			$total_value += $value;
			$total_all = $total_value - $_SESSION['port'];
		}
	} 
	
	//$id = $_POST['add'];
	echo "<div>".$qty."</div>";
	if($total == 0){
		echo '<div style="text-align:right; font-size:14px; font-family: Raleway, sans-serif;">Keranjang Belanja Kosong!</div>';
	} else {
		echo "<div style=\"text-align:right; font-size:14px; font-family: Raleway, sans-serif;\">Ada ".$total_all." item dalam Keranjang anda</div>" ;
		
		echo '<div style="text-align:right; font-size:14px; font-family: Raleway, sans-serif;"><a href="#" class="btn btn-primary" role="button" onclick="detail()">Detail</a></div>';
		echo '<div style="text-align:right; font-size:14px; font-family: Raleway, sans-serif;"><a href="#" class="btn btn-primary" role="button" onclick="hapus()">Kosongkan Keranjang</a></div>';
	} 
?>