<!DOCTYPE html>
<?php
include("mysqli_con.php");
include("functions.php");
?>
<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="">

<!-- 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="index.html"><img style="width:100px;height:50px;" src="themes/images/buyandsell.png" alt="BuyAndSell"/></a>
		<form class="form-inline navbar-search" method="post" action="" >
		<input id="srchFld" class="srchTxt" name ="searchButt" 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" name = "buttonSearch" class="btn btn-primary">Go</button>
    </form>
    <ul id="topMenu" class="nav pull-right">
      <li class=""><a href="updateProfile.php">Edit Profile</a></li>
      <li class=""><a href="sellitems.php">Sell Items</a></li>
      <li class=""><a href="product.php">Product</a></li>
      <li class=""><a href="userP.php">Profile</a></li>
      <li class="">
        <a href="" role="button" data-toggle="modal" style="padding-right:0"><span class="btn btn-large btn-success">Logout</span></a>
          </div>
        </div>
      </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="product_summary.html"><img src="themes/images/ico-cart.png" alt="cart"> Items in your cart </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>Men's Clothings  </a></li>
				<li><a href="products.html"><i class="icon-chevron-right"></i>Men's Shoes </a></li>
			</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="index1.html">Home</a> <span class="divider">/</span></li>
		<li class="active"> SHOPPING CART</li>
    </ul>
	<h3>  SHOPPING CART <a href="product.php" class="btn btn-large pull-right"><i class="icon-arrow-left"></i> Continue Shopping </a></h3>
  <hr class="soft"/>

  <form action="" enctype="multipart/form-data" method="post">

  <table align="center" width="700" bgcolor="skyblue" border="0">

   <tr align="right">
    <td colspan="4"><b>Sub total:</b></td>
   </tr>

   <tr>
     <th>REMOVE</th>
     <th>PRODUCT(S)</th>
     <th>QUANTITY</th>
     <th>TOTAL PRICE</th>
   </tr>

   <?php

     $total = 0;

     global $conn;

     $ip = getIp();

     $sel_price = "select * from cart where ip_add = '$ip'";

     $run_price = mysqli_query($conn, $sel_price);

     while ($p_price = mysqli_fetch_array($run_price)){
       $pro_id = $p_price['p_id'];

      $pro_price = "select * from items where items_id = '$pro_id'";

      $run_pro_price = mysqli_query($conn, $pro_price);

      while ($pp_price = mysqli_fetch_array($run_pro_price)){

        $product_price = array ($pp_price ['price']);

        $product_title = $p_price['items_name'];

        $product_image = $pp_price['image'];

        $single_price = $pp_price['price'];

        $values = array_sum($product_price);

        $total += values;

   ?>

    <tr align="center">
       <td><input type = "checkbox"name="remove[]" value="<?php echo $pro_id; ?>"</td>
       <td><? echo $product_title ?> <br>
       <img src="<?php echo $product_image; ?>" width="60" height="60"/>
       </td>
       <td><input type="text" size="4" name="qty" /> </td>
       <td><?php echo "RM" . $single_price; ?></td>
    </tr>

    <tr align="right">
      <td colspan="5">Sub Total :</td>
      <td><?php echo "RM" . $single_price; ?></td>
    </tr>

<?php }} ?>

  <tr align="right">
    <td colspan="4">Sub Total :</td>
    <td><?php echo "RM" . $total; ?></td>
  </tr>
  <tr align="center">
    <td colspan="2"><input type ="submit" name="update_cart" value="Update Cart"/></td>
    <td><input type ="submit" name="continue" value="Continue Shopping"/></td>
    <td><a href="product.php"><button>Checkout</a></button></td>
  </tr>

  </table>
  </form>


  <?php

  $ip = getIp();

  if(isset($_POST['update_cart'])){

  foreach ($_POST['remove'] as $remove_id){

  $delete_product = "delete from cart where p_id='$remove_id' AND ip_add='$ip'";

  $run_delete = mysqli_query($conn, $delete, $delete_product);

  if ($run_delete){
    echo "<script>window.open('addtoCart.php','_self')</script>";
  }
  }
  }
  if(isset($_POST['continue'])){
    echo "<script>window.open('poduct.php','_self')</script>";
  }
?>


  </div>
     <!-- end of center content -->
 <div class="right_content">
       <div class="shopping_cart">
         <div class="cart_details"><font color="blue"></font>&nbsp;items <br />
           <span class="border_cart"></span> Total:<span class="price"> </span> </div>
         <div class="cart_icon"><a href="cart.php" title="header=[Checkout] body=[&nbsp;] fade=[on]"><img src="images/shoppingcart.png" alt="" width="48" height="48" border="0" /></a></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>
