<?php
 if(session_status() == PHP_SESSION_NONE)
 {
   session_start();
 }
	include("mysqli_con.php");

	$prodID = $_GET['prodid'];
	if(!empty($prodID)){
		$sqlSelectSpecProd = mysqli_query($conn,"select * from items where items_id = '$prodID'") or die(mysql_error());
		$getProdInfo = mysqli_fetch_array($sqlSelectSpecProd);
		$prodname= $getProdInfo["items_name"];
		$prodCode = $getProdInfo["itemCode"];
		$prodprice = $getProdInfo["price"];
		$prodinfo = $getProdInfo["items_info"];
		$prodsize = $getProdInfo["size_items"];
    $prodimage = $getProdInfo["image"];
		$buyerid = $getProdInfo["buyer_id"];
				}
				?>

<?php
if (!isset($_SESSION)) {session_start();}
if (isset($_SESSION['seller'])){}
else { $_SESSION["seller"] = array();}

require_once("dbcontroller.php");
$db_handle = new DBController();



if(!empty($_GET["action"])) {
	switch($_GET["action"]) {
		case "add":
			if(isset($_SESSION['byrID']))
			{
				if(!empty($_POST["quantity"])) {
					$productByCode = $db_handle->runQuery("SELECT * FROM items WHERE itemCode='" . $_GET["itemCode"] . "';");
					$itemArray = array($productByCode[0]["itemCode"]=>array('items_name'=>$productByCode[0]["items_name"], 'size_items'=>$productByCode[0]["size_items"], 'items_info'=>$productByCode[0]["items_info"], 'itemCode'=>$productByCode[0]["itemCode"], 'image'=>$productByCode[0]["image"], 'buyer_id'=>$productByCode[0]["buyer_id"], 'quantity'=>$_POST["quantity"], 'price'=>$productByCode[0]["price"]));
					
					if(!in_array($productByCode[0]["buyer_id"],$_SESSION["seller"])){array_push($_SESSION["seller"],$productByCode[0]["buyer_id"]);}
					
					if(!empty($_SESSION["cart_item"])) {
						if(in_array($productByCode[0]["itemCode"],array_keys($_SESSION["cart_item"]))) {
							foreach($_SESSION["cart_item"] as $k => $v) {
									if($productByCode[0]["itemCode"] == $k) {
										if(empty($_SESSION["cart_item"][$k]["quantity"])) {
											$_SESSION["cart_item"][$k]["quantity"] = 0;
										}
										$_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"];
									}
							}
						} else {
							$_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray);
							echo "test";
						}
					} else {
						$_SESSION["cart_item"] = $itemArray;
					}
				}
			}
			else
			{
				echo '<script>alert("Please login before making any purchase thank you.");</script>';
			}
		break;
		case "remove":
			if(!empty($_SESSION["cart_item"])) {
				foreach($_SESSION["cart_item"] as $k => $v) {
						if($_GET["itemCode"] == $k)
							unset($_SESSION["cart_item"][$k]);				
						if(empty($_SESSION["cart_item"]))
							unset($_SESSION["cart_item"]);
				}
			}
		break;
		case "empty":
			unset($_SESSION["cart_item"]);
		break;	
	}
	}

?>


<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Buy And Sell</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
<!--Less styles -->
   <!-- Other Less css file //different less files has different color scheam
	<link rel="stylesheet/less" type="text/css" href="themes/less/simplex.less">
	<link rel="stylesheet/less" type="text/css" href="themes/less/classified.less">
	<link rel="stylesheet/less" type="text/css" href="themes/less/amelia.less">  MOVE DOWN TO activate
	-->
	<!--<link rel="stylesheet/less" type="text/css" href="themes/less/bootshop.less">
	<script src="themes/js/less.js" type="text/javascript"></script> -->

<!-- Bootstrap style -->
    <link id="callCss" rel="stylesheet" href="themes/bootshop/bootstrap.min.css" media="screen"/>
    <link href="themes/css/base.css" rel="stylesheet" media="screen"/>
<!-- Bootstrap style responsive -->
	<link href="themes/css/bootstrap-responsive.min.css" rel="stylesheet"/>
	<link href="themes/css/font-awesome.css" rel="stylesheet" type="text/css">
<!-- Google-code-prettify -->
	<link href="themes/js/google-code-prettify/prettify.css" rel="stylesheet"/>
<!-- fav and touch icons -->
    <link rel="shortcut icon" href="themes/images/ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="themes/images/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="themes/images/ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="themes/images/ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="themes/images/ico/apple-touch-icon-57-precomposed.png">
	<style type="text/css" id="enject"></style>
  </head>
<body>
<div id="header">

<div class="container">
<!-- Navbar ================================================== -->
<div id="logoArea" class="navbar">
<a id="smallScreen" data-target="#topMenu" data-toggle="collapse" class="btn btn-navbar">

	<span class="icon-bar"></span>
	<span class="icon-bar"></span>
	<span class="icon-bar"></span>
</a>
  <div class="navbar-inner">

    <a class="brand" href="home.php"><img style="width:100px;height:50px;" src="themes/images/buyandsell.png" alt="BuyAndSell"/></a>
		<form class="form-inline navbar-search" method="post" action="products.php" >
		<input id="srchFld" class="srchTxt" type="text" />
		  <select class="srchTxt">
        <option>Category</option>
        <option>Cameras </option>
        <option>Computers</option>
        <option>Women's Clothing</option>
        <option>Women's Shoes</option>
        <option>Men's Clothings</option>
        <option>Men's Shoes</option>
        <option>Stationery</option>
        <option>Books</option>
		</select>
		  <button type="submit" id="submitButton" class="btn btn-primary">Go</button>
    </form>
		<ul id="topMenu" class="nav pull-right">
			<li class=""><a href="sellitems.php">SELL ITEMS</a></li>
			<li class=""><a href="product.php">BROWSE</a></li>
			<li class=""><a href="userP.php">PROFILE</a></li>
			<li class="">
			<?php
				if(isset($_SESSION['byrID']))
				{
					echo '<a href="logoutPro.php"><span class="btn btn-large btn-success">LOGOUT</span></a>';
				}
				else
				{
					echo '<a href="login.php"><span class="btn btn-large btn-success">LOGIN</span></a>';
				}
			?>
			</li>
		</ul>
  </div>
</div>
</div>
</div>
<!-- Header End====================================================================== -->
<div id="mainBody">
	<div class="container">
	<div class="row">
<!-- Sidebar ================================================== -->
	<div id="sidebar" class="span3">
		<div class="well well-small"><a id="myCart" href="shopCart.php?action=checkout"><img src="themes/images/ico-cart.png" alt="cart"> Unique items in your cart : <?php if(isset($_SESSION["cart_item"])){echo count($_SESSION["cart_item"]);}else{echo '0';}  ?> <br> <?php //total_price(); ?></br>  </span></a></div>

		<ul id="sideManu" class="nav nav-tabs nav-stacked">
			<li class="subMenu open"><a> ELECTRONICS </a>
				<ul>
				<li><a class="active" href="products.html"><i class="icon-chevron-right"></i>Cameras  </a></li>
				<li><a href="products.html"><i class="icon-chevron-right"></i>Computers, Tablets & laptop </a></li>
				<li><a href="products.html"><i class="icon-chevron-right"></i>Mobile Phone </a></li>
				</ul>
			</li>
			<li class="subMenu"><a> CLOTHES  </a>
			<ul style="display:none">
				<li><a href="products.html"><i class="icon-chevron-right"></i>Women's Clothing </a></li>
				<li><a href="products.html"><i class="icon-chevron-right"></i>Women's Shoes </a></li>
				<li><a href="products.html"><i class="icon-chevron-right"></i>Women's Hand Bags </a></li>
				<li><a href="products.html"><i class="icon-chevron-right"></i>Men's Clothings  </a></li>
				<li><a href="products.html"><i class="icon-chevron-right"></i>Men's Shoes </a></li>
			</ul>
			</li>
      <li class="subMenu"><a>BOOKS AND STATIONERY </a>
				<ul style="display:none">
				<li><a href="products.html"><i class="icon-chevron-right"></i>Stationery</a></li>
				<li><a href="products.html"><i class="icon-chevron-right"></i>Books</a></li>
			</ul>
			</li>
		</ul>
		<br/>
		  <div class="thumbnail">
			<img src="themes/images/products/panasonic.jpg" alt="Bootshop panasonoc New camera"/>
			<div class="caption">
			  <h5>Panasonic</h5>
				<h4 style="text-align:center"><a class="btn" href="product_details.html"> <i class="icon-zoom-in"></i></a> <a class="btn" href="#">Add to <i class="icon-shopping-cart"></i></a> <a class="btn btn-primary" href="#">RM999.00</a></h4>
			</div>
		  </div><br/>
			<div class="thumbnail">
				<img src="themes/images/products/kindle.png" title="Bootshop New Kindel" alt="Bootshop Kindel">
				<div class="caption">
				  <h5>Kindle</h5>
				    <h4 style="text-align:center"><a class="btn" href="product_details.html"> <i class="icon-zoom-in"></i></a> <a class="btn" href="#">Add to <i class="icon-shopping-cart"></i></a> <a class="btn btn-primary" href="#">RM799.00</a></h4>
				</div>
			  </div><br/>
	</div>
<!-- Sidebar end=============================================== -->
	<div class="span9">

    <ul class="breadcrumb">
    <li><a href="home.php">Home</a> <span class="divider">/</span></li>
    <li><a href="product.php">Products</a> <span class="divider">/</span></li>
    <li class="active">Product Details</li>
    </ul>

    <!--------- gambar ---->
	<div class="row"><center>
			<div id="gallery" class="span3">
            <a href="" title="<?php echo $prodname; ?> ">
							<center><?php
				echo '<img src="data:image/jpeg;base64,'.base64_encode($prodimage).'" style="style="width:400px;height:400px;" alt=""/>'
				?>
            </a>
					n
			<div id="differentview" class="moreOptopm carousel slide">
                <div class="carousel-inner">
                  <div class="item active">
                   <a> <?php echo '<img style="width:29%" src="data:image/jpeg;base64,'.base64_encode($prodimage).'" style="style="width:400px;height:400px;" alt=""/></a>'?>
                   <a> <?php echo '<img style="width:29%" src="data:image/jpeg;base64,'.base64_encode($prodimage).'" style="style="width:400px;height:400px;" alt=""/></a>'?>
                   <a> <?php echo '<img style="width:29%" src="data:image/jpeg;base64,'.base64_encode($prodimage).'" style="style="width:400px;height:400px;" alt=""/></a>'?>
                  </div>
                  <div class="item">
                   <a href="themes/images/products/large/f3.jpg" > <img style="width:29%" src="themes/images/products/large/f3.jpg" alt=""/></a>
                   <a href="themes/images/products/large/f1.jpg"> <img style="width:29%" src="themes/images/products/large/f1.jpg" alt=""/></a>
                   <a href="themes/images/products/large/f2.jpg"> <img style="width:29%" src="themes/images/products/large/f2.jpg" alt=""/></a>
                  </div>
                </div>

              <!--
			  <a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>
              <a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>
			  -->
              </div></center>

			</div>
			<div class="span6">

				<h3><?php echo $prodname; ?></h3>

				<hr class="soft"/>
				<!--<form class="form-horizontal qtyFrm" method="post" action="../fyp_draft/process/product_details.php">-->
				  <div class="control-group">
					<label class="control-label"><span><h4>Price :  RM<?php echo $prodprice?> </h4></span></label>
					<h4>Description :</h4><h5><?php echo $prodinfo ?></h5>

					</div>
				  </div>
				<!--</form>-->
				<hr class="soft"/>
				<hr class="soft clr"/>
				<form method="post" action="product_details.php?prodid=<?php echo $prodID; ?>&action=add&itemCode=<?php echo $prodCode; ?>">
					<div style="text-align:right">Quantity : <input type="text" name="quantity" value="1" size="2" /><div>
					<div><button type="submit" class="btn btn-large btn-primary pull-right"> Add to cart <i class=" icon-shopping-cart"></i></button></div>
				</form>
				<br class="clr"/>
			<a href="#" name="detail"></a>
			<hr class="soft"/>
			</div>

			<div class="span9">

            <ul id="productDetail" class="nav nav-tabs">
              <li class="active"><a href="#home" data-toggle="tab">Seller Details</a></li>
            </ul>
            <div id="myTabContent" class="tab-content">
						<form class="form-horizontal" method="post" action="updateProcess.php" enctype="multipart/form-data">
            <div class="tab-pane fade active in" id="home">
			  <h4>Product Information</h4>
                <table class="table table-bordered">
				<tbody>
          <?php
					$prodID = $_GET['prodid'];
					if(!empty($buyerid)){
						$sqlSelectSeller = mysqli_query($conn,"select * from buyer where buyer_id = '$buyerid'") or die(mysql_error());
						$getProdInfo = mysqli_fetch_array($sqlSelectSeller, MYSQLI_ASSOC);
						$first_name= $getProdInfo["first_name"];
						$last_name = $getProdInfo["last_name"];
						$phone = $getProdInfo["phone"];
						$add = $getProdInfo["address"];
						$buyerid = $getProdInfo["buyer_id"];
							}
						?>
					<center>
				<tr class="techSpecRow"><th colspan="2">Seller Details</th></tr>
				<tr class="techSpecRow"><td class="techSpecTD1">Name: </td><td class="techSpecTD2"><?php echo $first_name?> <?php echo $last_name?></td></tr>
				<tr class="techSpecRow"><td class="techSpecTD1">Phone Number:</td><td class="techSpecTD2"><?php echo $phone?></td></tr>
				<tr class="techSpecRow"><td class="techSpecTD1">Meet Up Location:</td><td class="techSpecTD2"><?php echo $add?></td></tr>
				<!--- <tr class="techSpecRow"><td class="techSpecTD1">Profile Seller:</td><td class="techSpecTD2"><a href="userP2.php" data-toggle="tab">Seller Profile</a></td></tr> --->
				</center>
			</table>
				<?php
				$sellerid = $getProdInfo["buyer_id"];
					echo '<a href="userP2.php?sellerid='.$sellerid.'" class="btn">View Details Seller</a>'
			 ?>
              </div>
		<div class="tab-pane fade" id="profile">
		<div id="myTab" class="pull-right">
		 <a href="#listView" data-toggle="tab"><span class="btn btn-large"><i class="icon-list"></i></span></a>
		 <a href="#blockView" data-toggle="tab"><span class="btn btn-large btn-primary"><i class="icon-th-large"></i></span></a>
		</div>
		</div>
				<br class="clr">
					 </div>
		</div>
          </div>

	</div>
</div>
</div> </div>
</div>
<!-- MainBody End ============================= -->
<!-- Footer ================================================================== -->
	<div  id="footerSection">
	<div class="container">
		<div class="row">
			<div class="span3">
				<h5>ACCOUNT</h5>
        <a href="register.html">REGISTRATION</a>
				<a href="login.html">LOG IN</a>
			 </div>
			<div class="span3">
				<h5>INFORMATION</h5>
        <a href="contact.html">CONTACT</a>
				<a href="legal_notice.html">LEGAL NOTICE</a>
				<a href="tac.html">TERMS AND CONDITIONS</a>
			 </div>
       <div id="socialMedia" class="span3 pull-right">
 				<h5>Copyright : UniKL MIIT</h5>
        <a class="brand" href="index.html"><img width="6000" height="6000"src="themes/images/products/logoUnikl.png" alt="Bootsshop"/></a>
 			 </div>
		 </div>
		<p class="pull-right">&copy; Buy And Sell</p>
	</div><!-- Container End -->
	</div>
<!-- Placed at the end of the document so the pages load faster ============================================= -->
	<script src="themes/js/jquery.js" type="text/javascript"></script>
	<script src="themes/js/bootstrap.min.js" type="text/javascript"></script>
	<script src="themes/js/google-code-prettify/prettify.js"></script>

	<script src="themes/js/bootshop.js"></script>
    <script src="themes/js/jquery.lightbox-0.5.js"></script>
<span id="themesBtn"></span>
</body>
</html>
