<!DOCTYPE html><html lang="en">
<head>
	<?php 
		include "includes/operations.php";
		include "includes/headerlinks.php";
		
		$token = 0;
		if(isset($_GET['token'])){
			$token = $_GET['token'];
		}
		$check_token = mysqli_query($con,"select * from orders where download_passcode = '$token'");
		$chk_row = mysqli_fetch_array($check_token);
		$order_id = $chk_row['id'];
		$order_number = $chk_row['order_id'];
		
		$order_result = mysqli_query($con, "SELECT * FROM orders WHERE download_passcode = '$token'");
		if (mysqli_num_rows($order_result)==0) {
			header("Location:404.php");
			exit();
		}
	?>
	
	<style>
		
		.error__content--title {
			font-size:1.7em !important;
		}
	
		@media screen and (max-width: 650px) {
			.checkout__sidebar {
				margin-top: 30px !important;
			}
			.error__content--title {
				font-size:1.4em !important;
			}
		}
	</style>
	
</head>

<body>

    
		
	<?php include "includes/top_header.php";?>
	<?php include "includes/navigation.php";?>
	<?php include "includes/mobile_navigation.php";?>
	<?php include "includes/mobile_sticky_menus.php";?>
	<?php include "includes/cart_window.php";?>
	<?php include "includes/search.php";?>


    <main class="main__content_wrapper">
        <!-- Start slider section -->
        <section class="breadcrumb__section breadcrumb__bg">
            <div class="container-fluid">
                <div class="row row-cols-1">
                    <div class="col">
                        <div class="breadcrumb__content">
                            <h1 class="breadcrumb__content--title text-white mb-10">Success</h1>
                            <ul class="breadcrumb__content--menu d-flex">
                                <li class="breadcrumb__content--menu__items"><a class="text-white" href="index.php">Home</a></li>
                                <li class="breadcrumb__content--menu__items"><span class="text-white">Success</span></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <!-- End slider section -->
		<section class="cart__section section--padding">
            <div class="container-fluid">
                <div class="cart__section--inner">
                    <form action="#"> 
                        <div class="row">
							<div class="col-lg-6 col-md-6">
								<div class="contact__form">
									<center>
										<img class="success-image mb-20" src="images/success-35.png" alt="error-img">
										<h2 class="error__content--title">Thanks for shopping with Candy Cleanse.  </h2>
										<h5 class="error__content--title">
											Order Number: <b><?=$order_number;?></b>
										</h5>
										
										<p class="error__content--desc">You will receive an email with the order details. You can expect delivery in 7 business days!</p>
										<p class="error__content--desc" style="color:red !important">Note: Kindly check your spam folder as well!</p>
									</center>
								</div>
							</div>
							<div class="col-lg-6 col-md-6">
								<aside class="checkout__sidebar sidebar border-radius-10">
									<h2 class="checkout__order--summary__title text-center mb-15">Your Order Summary</h2>
									<?php
										$result = mysqli_query($con, "SELECT * FROM order_details INNER JOIN product ON order_details.product_id = product.product_id WHERE order_id=$order_id");
									?>
									<?php if (mysqli_num_rows($result)>0) { ?>
									<div class="cart__table checkout__product--table">
										<table class="cart__table--inner">
											<tbody class="cart__table--body">
												<?php
													$total_price = 0;
													$count = 0;
													while ($row = mysqli_fetch_array($result)) {
													$total_price = $total_price + ($row['product_price']*$row['product_quantity']);
													$count++;
													$pid = $row['product_id'];
															
												?>
												<tr class="cart__table--body__items">
													<td class="cart__table--body__list">
														<div class="product__image two  d-flex align-items-center">
															<div class="product__thumbnail border-radius-5">
																<a class="display-block" href="#"><img class="display-block border-radius-5" src="images/product_images/<?php echo $row['product_image']?>" alt="cart-product"></a>
																<span class="product__thumbnail--quantity">
																	<?php echo $row['product_quantity'];?>
																</span>
															</div>
															<div class="product__description">
																<h4 class="product__description--name" style="max-width: 220px !important;">
																	<a href="#">
																		<?php echo $row['product_title']?>
																	</a>
																</h4>
															</div>
														</div>
													</td>
													<td class="cart__table--body__list">
														<span class="cart__price">$<?php echo $row['product_price']*$row['product_quantity'] ?>.00</span>
													</td>
												</tr>
												<?php
													}
												?>
											</tbody>
										</table> 
									</div>
									<div class="checkout__total" style="border-top:0px !important;">
										<table class="checkout__total--table">
											<tr class="checkout__total--items">
												<td class="checkout__total--title text-left">Subtotal</td>
												<td class="checkout__total--calculated__text text-right">
													$<?php echo number_format($total_price,2);?>
												</td>
											</tr>
											<tr class="checkout__total--items">
												<td class="checkout__total--title text-left">Estimated Tax (7%)</td>
												<td class="checkout__total--calculated__text text-right">
													$<?php
														$tax = 7/100;
														echo $value_tax = $total_price * $tax;
													?>
												</td>
											</tr>
											<tr class="checkout__total--items">
												<td class="checkout__total--title text-left">Shipping Cost</td>
												<td class="checkout__total--calculated__text text-right">
													$9.95
												</td>
											</tr>
											<tr>
												<td colspan="3"><hr style="border:1px solid #e4e4e4" /></td>
											</tr>
											<?php
												$shipping_cost = floatval(9.95);
												$final_total = $total_price + $shipping_cost + $value_tax;
											?>
											<tfoot class="checkout__total--footer">
												<tr class="checkout__total--footer__items">
													<td class="checkout__total--footer__title checkout__total--footer__list text-left">Total </td>
													<td class="checkout__total--footer__amount checkout__total--footer__list text-right">$<span id="grand_total"><?php echo number_format($final_total,2);?></span></td>
													
												</tr>
											</tfoot>
										</table>
									</div>
									<div class="payment__history mb-30">
									</div>
									<?php } else { ?>
									<div class="checkout-right">
										<h4 class="text-left" style="color:red !important">Your shopping cart don't contain any Product</span></h4>
									</div>
									<?php } ?>
								</aside>
							</div>
                        </div> 
                    </form> 
                </div>
            </div>     
        </section>

    </main>

    <!-- Start footer section -->
    <?php include "includes/footer.php";?>
    <!-- End footer section -->

	<?php include "includes/footerlinks.php";?>
	<?php include "includes/cart_functions.php";?>

</body></html>