<?php
session_start();
include "includes/database.php";
include "includes/security.php";
$email=$_SESSION["pengguna"];
$dataPengguna=mysqli_query($newcon,"SELECT * from tbl_user where email='$email'");
$showData=mysqli_num_rows($dataPengguna);

?>

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>MyUniversity MarketPlace</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/heroic-features.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

    <!-- Navigation -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">MyUniversity MarketPlace</a>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li class="nav-item active">
              <a class="nav-link" href="index2.php">HOME
                <span class="sr-only">(current)</span>
              </a>
            </li>
                    <li>
                        <a href="about2.php">ABOUT</a>
                    </li>
                    <li>
                        <a href="shop2.php">SHOP</a>
                    </li>
                    <li class="nav-item">
              <a class="nav-link" href="viewcart.php">CART</a>
            </li>

            <li class="nav-item">
              <a class="nav-link active" href="logout.php">LOGOUT</a>
            </li>

            
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>
            


          </ul>
        </div>
      </div>
    </nav>
<br>
<br>
  <div class="container">

      <div class="row">

        <div class="col-lg-3">

          <h1 class="my-4"></h1>
          <div class="list-group">
            
          </div>

        </div>
        </div>          

<?php

if (isset($_GET["pid"]))
{
$pid=$_GET["pid"];
							
							//check duplicate
							
$data=mysqli_query($newcon, "SELECT * FROM tbl_purchase_detail_temp where product_id='$pid' and user_id='$email'");
$bil_rekod=mysqli_num_rows($data);
							$show=mysqli_fetch_array($data);
							
if ($bil_rekod!=0)
{
$jum=$show['quantity']+1;						
mysqli_query($newcon,"UPDATE tbl_purchase_detail_temp set quantity ='$jum' where id='$show[id]'")or die (mysqli_error($newcon));							
?>
                            
<div class="a"><br><br><br>
                              <h1><b><center>Shopping card updated</center></h1></b><a href="viewcart.php" class="alert-link"><br><center>Click here to view cart</center></a>.
                            </div>
                            
                         <?php
							}
							else
							{
$dateregister=date("Y-m-d");								
//insert data into database		
mysqli_query($newcon,"INSERT INTO tbl_purchase_detail_temp (product_id,user_id, quantity) values ('$pid', '$email','1')")or die (mysqli_error($newcon));								
								
								
								
								?>
								
								<div class="alert alert-success">
                               Item added into shopping card <a href="viewcart.php" class="alert-link">Click here to view cart</a>.
                            </div>
						<?php
							}}
							?>
                                
                                
</body>
</html>