<?php
ob_start();

if (!session_start()) {
    session_start();
}
?>



<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>Monsoon Vibes - Book Market Place</title>
<!-- Google monseratt Font-->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200;300;400;500;600;700&display=swap" rel="stylesheet">
<!-- Favicon-->
<link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
<!-- Bootstrap icons-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="css/layout.css" rel="stylesheet" />
<link href="css/styles.css" rel="stylesheet" />
</head>
<body>
<header>
  <div class="container">
    <div class="row">
      <div class="col-md-12">
        <nav class="navbar navbar-expand-lg navbar-light navigation"> <a class="navbar-brand" href="index.php"> <img src="assets/image/monsoon_vibes.png" alt="Monsoon Vibes" class="img-fluid"> </a>
          <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
          <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav m-auto main-nav ">
              <li class="nav-item"><a class="nav-link active" aria-current="page" href="index.php">Home</a></li>
               <li class="nav-item"><a class="nav-link" href="publishing_policy.php">Publishing Policy</a></li>
              <li class="nav-item"><a class="nav-link" href="about_us.php">About Us</a></li>
              <li class="nav-item"><a class="nav-link" href="contact_us.php">Contact Us</a></li>
            </ul>
            <ul class="navbar-nav me-end">
             <?php
                                if ($_SESSION['CustId'] > 0) {
                                    ?>
							     <a class="nav-link login-btn" href="login/logout.php">Logout</a> 
							     <?php
                                } else {
                                    ?>
							     <a class="nav-link login-btn" href="login/login.php">Login</a> 
							     <?php
                                }
?>
            </ul>
          </div>
        </nav>
      </div>
    </div>
    
  </div>
</header>
<!-- Global Header Ends --> 
<!-- Global Header Ends --> 

<!-- Inside Body Starts-->
<?php
if (isset($_SESSION['CustId']) == false && $_SESSION['bookid'] == 0) {?><div class="text-center" style="color:red;     height: 193px !important;">
   <h1 ><a href="login/login.php" style="color:red;     height: 193px !important;"><?php echo 'Please Login'; ?></a></h1></div><?php
} else {
    unset($_SESSION['cartCount']);


    try {
        $db = new PDO('mysql:host=localhost;dbname=gdhhsxmy_monsoonvibespublica;charset=utf8', 'gdhhsxmy_monsoonvibespublica', 'monsoonvibespublica');
    } catch (Exception $e) {
        echo 'Error has Occured';
    }
    $cid       = $_SESSION['CustId'];
    $subTotal  = 0;
    $quan      = 0;
    $tax       = 0;
    $ipaddress = $_SESSION['ipaddress'];

    if ($_SESSION['bookid'] > 0 && $_SESSION['CustId'] == 0) {
        $bookid = $_SESSION['bookid'];
        $stmt   = $db->query("select product.*,author.title authname,category.title catname,
	product.image AS image, product.price*1 AS totalAmount,1 AS Quantity
	FROM product
		inner join author on author.id=product.authorid
		inner join category on category.id=product.catid
		WHERE product.id=$bookid ");
    } else {
        $stmt = $db->query("select product.*,author.title authname,category.title catname,cart.id cartid,
	product.image AS image, product.price*cart.Quantity AS totalAmount ,cart.Quantity AS Quantity
	FROM cart LEFT JOIN product ON cart.Pid=product.id
	inner join author on author.id=product.authorid
	inner join category on category.id=product.catid
	WHERE cart.Cid=$cid ");
    }


    ?>
 

<section class="pt-5"> 
  
  <!-- Buy Book section -->
  <div class="container my-5">
    <div class="row">
      <div class="col-12 title-band">
        <div class="d-flex justify-content-between mb-3 px-0">
          <div class="cmn-title">
            <h3 class="section-title">My shopping cart</h3>
          </div>
        </div>
      </div>
    </div>
    <div class="card gx-4 gx-lg-5 px-4"> 
    <?php
      $disable = 1;
    while ($row = $stmt->fetch()) {
        $disable = 0;
        $subTotal += 1 * $row['totalAmount'];
        $quan = $row['Quantity'];

        if ($row['paid_delivery'] == 'no') {
            $delivery = 'Free Delivery';
        } else {
            $delivery = 'Paid Delivery';
        }

        ?>
      <!-- Cart Single item query starts -->
      <div class="row py-4 cart-item align-items-center">
        <div class="col-md-2"><img class="card-img-top mx-auto d-block img-fluid book-cover" src="../pic/book/<?php echo $row['image']?>" alt="..."></div>
        <div class="col-md-6 py-4">
          <h1 class="fw-bolder cart-book-title"><?php	echo $row['title']?></h1>
          <div class="mb-2 fs-5"> By <span class="text-uppercase text-theme auth-name"><?php	echo $row['authname']?></span> </div>
          <div class="row">
            <div class="col-md-6">
              <div class="det-col"> Category: <span class="fw-semibold category"><?php	echo $row['catname']?></span> </div>
              <div class="det-col"> Language: <span class="fw-semibold b-language"><?php	echo $row['language']?></span> </div>
            </div>
            <div class="col-md-12 mt-4">
              <div class="d-flex">
               <!-- <div class="d-flex align-items-center cart-num">
                  <input type="number" name="cartcount" class="product-count" value="1" step="1" min="0" max="10" >
                </div> -->
                <div class="fw-semibold delevery-row ps-3">
                  <div class="delevery-type"><?php	echo $delivery?></div>
                 <!-- <div class="delevery-date">Wednesday, 6 September</div> -->
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="row">
            <div class="col-md-12 d-flex justify-content-center cart-phold">
              <div class="price-col text-center">
                <div class="book-price">
                  <div class="d-flex align-items-center">
                    <div class="offer-price"><span class="inr">₹</span><?php	echo $row['price']?></div>
                    <div class="text-muted text-decoration-line-through orginal-price"> <span class="inr">₹</span><?php	echo $row['old_price']?></div>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-md-12">
              <div class="d-flex justify-content-center btn-phold">
               <!-- <button class="btn btn-outline-dark rounded-pill px-4 btn-removecart" type="button"> <i class="bi-cart-fill me-1"></i> Remove </button>--> 
                <form name="removecart" action="removeCartQuery.php" method="post">
 <input type="hidden" name="remove_cid" value="<?php echo $_SESSION['CustId']; ?>" style="color:black"/>
	<input type="hidden" name="remove_id" value="<?php echo $row['cartid']; ?>" style="color:black"/>
	<input type="hidden" name="subTotal" value="<?php echo $subTotal; ?>" style="color:black"/>
	<button type="submit1" value="submit1" class="btn btn-outline-dark rounded-pill px-4 btn-removecart" name="remove_btn"><i class="bi-cart-fill me-1"></i> Remove</button></form>
              </div>
            </div>
          </div>
        </div>
      </div>
      
     <?php
    }
    ?>
      <!-- Cart Single item query Ends --> 
    </div>
  </div>
  <!-- Buy Book Ends--> 
</section>
<!-- Form Section-->
<?php
if ($disable == 0) {
    ?>
 
<section class="shipping-details">
  <div class="container">
    
      <div class="row">
      <div class="col-12 title-band">
        <div class="d-flex justify-content-between mb-3 px-0">
          <div class="cmn-title">
            <h3 class="section-title">Total Amount:  <?php echo $subTotal; ?></h3>
             
          </div>
        </div>
      </div>
    </div>
    
    
    <div class="row">
      <div class="col-12 title-band">
        <div class="d-flex justify-content-between mb-3 px-0">
          <div class="cmn-title">
            <h3 class="section-title">Enter Shipping Address</h3>
          </div>
        </div>
      </div>
    </div>

    <?php
     if ($_SESSION['CustId'] > 0) {
         try {
             $db = new PDO('mysql:host=localhost;dbname=gdhhsxmy_monsoonvibespublica;charset=utf8', 'gdhhsxmy_monsoonvibespublica', 'monsoonvibespublica');
         } catch (Exception $e) {
             echo 'Error has Occured';
         }
         $cid  = $_SESSION['CustId'];
         $cust = $db->query("select * from customer where Cid=$cid");

         while ($rowcust = $cust->fetch()) {
             $k1 = $rowcust['email'];

             $k3 = $rowcust['name'];

             $k4      = $rowcust['house'];
             $k5      = $rowcust['location'];
             $k6      = $rowcust['city'];
             $k7      = $rowcust['state'];
             $k8      = $rowcust['country'];
             $k9      = $rowcust['zipcode'];
             $k10     = $rowcust['mobile'];
             $butname = 'Proceed';
         }
     } else {
         $k1 = '';

         $k3 = '';

         $k4      = '';
         $k5      = '';
         $k6      = '';
         $k7      = '';
         $k8      = '';
         $k9      = '';
         $k10     = '';
         $butname = 'Save Details';
     }
    $orderid = 'ORDS' . rand(10000, 99999999);
    ?>
     
    <div class="row">
      <div class="col-lg-8">
        <div class="card gx-4 gx-lg-5 p-4">
           
          <form class="row g-3" action="payment/index.php" method="post">
                
            <div class="col-md-6">
              <label for="inputName" class="form-label">Name</label>
             <input type="text" class="form-control" name="fname" pattern="([A-z][\s\.]|[A-z])+" title="Only letters & dot allowed" placeholder="Name" value="<?php echo $k3; ?>" required />
            </div>
            <div class="col-md-6">
              <label for="inputPhone" class="form-label">Flat No/House Name</label>
              <input type="text" class="form-control" name="add1" placeholder="Flat No/House Name"  value="<?php echo $k4; ?>"required />
            </div>
            <div class="col-md-6">
              <label for="inputPin" class="form-label">Street/Road/Location</label>
              <input type="Text" class="form-control" name="add2" placeholder="Street/Road/Location" value="<?php echo $k5; ?>" required />
            </div>
            <div class="col-md-6">
              <label for="inputCity" class="form-label">City</label>
              <input type="Text" class="form-control" name="city" placeholder="City"  value="<?php echo $k6; ?>"required />
            </div>
            <div class="col-md-12">
              <label for="inputAddress" class="form-label">State</label>
               <input type="Text" class="form-control" name="state" placeholder="Street/Road/Location" value="<?php echo $k7; ?>" required />
            </div>
            <div class="col-md-6">
              <label for="inputstate" class="form-label">Zip Code</label>
              <input type="number" class="form-control" name="Zipcode" placeholder="Zip Code" pattern="[0-9]{6}" min="100000" max="999999" title="Only numbers allowed" value="<?php echo $k9; ?>" required />
 
            </div>
            <div class="col-md-6">
              <label for="inputCountry" class="form-label">Country</label>
              <input type="Text" class="form-control" name="country" placeholder="Country"  value="<?php echo $k8; ?>" required  />
            </div>
             <div class="col-md-6">
              <label for="inputCountry" class="form-label">Mobile</label>
               <input type="tel" class="form-control" name="contactno" placeholder="Mobile No" pattern="[0-9]{10}" title="Only numbers allowed" value="<?php echo $k10; ?>" required />
            </div>
             <div class="col-md-6">
              <label for="inputCountry" class="form-label">Email</label>
              <input type="email" class="form-control" name="Email" placeholder="Email" value="<?php echo $k1; ?>" required/>
            </div>
            <!--  button -->
           
            <div class="col-md-12 d-grid gap-2 d-md-flex justify-content-center mt-5">
             <input title="TXN_AMOUNT"  tabindex="10" type="hidden" name="TXN_AMOUNT" value="<?php echo $subTotal + ($tax * $quan) ?>"/>
<input id="ORDER_ID"  tabindex="1" maxlength="20" size="20" name="ORDER_ID" autocomplete="off" type="hidden"
value="<?php echo $orderid ?>"/>   
  <button  class="btn btn-primary rounded-pill me-md-2 px-5" type="submit" value="submit" >Save and Deliver</button>
               
               
              <button class="btn btn-outline-dark rounded-pill px-5" type="button"><span class="px-5">Cancel</span></button> 
            </div>
           
          </form>
                     
 
        </div>
      </div>
    </div>
 
  </div>
  
     
  
</section>
 
<!--cta ends--> 
<?php } else {
    ?>  <div class="text-center" >
   <h1 ><a href="" style="color:red; "><?php echo 'Cart Empty'; ?></a></h1></div>
<?php

}
}?>

<!-- Global Footer Section-->

  <footer class="footer-new mt-5">
    <div class="container">
      <div class="row">
        <div class="footer-new-col">
          
          <img src="assets/image/monsoon_vibes.png" class="img-fluid set-200" alt="logo">
       
          <p class="alt-color mt-2">MONSOONVIBES PUBLICA PRIVATE LIMITED, 33/6466-C, Shanthi Villa, Vappoli Thazham,
            Puliyankode Road,Marikunnu P.O, 673012 - Pin, Kozhikkode .</p>
        </div>
        <div class="footer-new-col res-new-ps-md" >
          <h4>Policies</h4>
          <ul>
            <li><a href="Privacy_Policy.php">Privacy policy</a></li>
              <li><a href="Refundpolicy.php">Refund policy</a></li>
              <li><a href="TermsAndConditions.php">Terms & conditions</a></li>
          </ul>
        </div>
        <div class="footer-new-col">
          <h4>Quick Links</h4>
          <ul>
            <li><a href="about_us.php">About us</a></li>
            <li><a href="contact_us.php">Contact us</a></li>
            <!--<li><a href="#">FAQ</a></li>-->
            <li><a href="#">Profile</a></li>
          </ul>
        </div>
        
        <div class="footer-new-col">
          <h4>follow us</h4>
          <div class="social-links">
            <a href="https://www.facebook.com/monsoonvibes/?paipv=0&eav=AfZpBwqPtSXZtMH65SXYth8zMXVn66ngzKdU58PQvx1ZMABzbpEHV9J5qSZ3WcOGdWE&_rdr"><i class="fab fa-facebook-f"></i></a>
            <a href="#"><i class="fab fa-twitter"></i></a>
            <a href="#"><i class="fab fa-instagram"></i></a>
            <a href="#"><i class="fab fa-linkedin-in"></i></a>
            <a href="#"><i class="fab fa-youtube"></i></a>

          </div>
        </div>
      </div>
    </div>
 </footer>

<footer class="py-1 footer">
    <div class="container">
      <p class="m-0 text-center " style="color: gray;">Copyright @ 2024. Workmate infotech Pvt Ltd All rights reserved</p>
    </div>
  </footer>


<!-- Bootstrap core JS--> 
 <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" charset="utf-8"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script> 
<script
  src="https://code.jquery.com/jquery-3.7.1.min.js"
  integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
  crossorigin="anonymous"></script> 
<!-- Core theme JS--> 
<script src="js/scripts.js"></script> 
<script type="text/javascript">

    $('.cart-num input').each(function () {
        

        $(this).number();
        
       

    });
    
    
    

</script>
</body>
</html>
<!-- Global Footer Section Ends-->