<?php require_once("header.php");?>

<?php
$fetch_product = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `og_products` WHERE `product_id` = '".$_REQUEST['product_id']."'"));
$pname = stripslashes($fetch_product['product_name_english']);

$num_review_whole = mysqli_num_rows(mysqli_query($connection,"SELECT * FROM `og_reviews` WHERE `product_id` = '".$_GET['product_id']."'"));

$arr_pack_rate = mysqli_fetch_array(mysqli_query($connection,"SELECT AVG(`rate`) AS `avg_rate` FROM `og_reviews` WHERE `product_id` = '".$_GET['product_id']."'"));
?>

			<!-- page template area start -->
			<section id="about">
				<div class="container mt-10 pb-10 pt-0">
				    <div class="section-content">
    				    <div class="row">
    				        <div class="mt-10 mb-30 text-center"><a href="index.php" style="color:#333;">Home</a> / Product / <?php echo $pname;?></div>
    						<div class="col-lg-6">
    						    <div>
    							<a href="uploads/product/<?php echo $fetch_product['product_photo'];?>" data-title="" data-lightbox="example-set"><div class="thumb" style="border:2px solid #ccc;">
    								<img class="img-fullwidth" alt="" src="uploads/product/<?php echo $fetch_product['product_photo'];?>">
    							</div></a></div>
    							<div>&nbsp;</div>
    						</div>
    						<form action="add_to_cart.php" method="GET">
    						    <input type="hidden" name="hid_product_id" id="hid_product_id" value="<?php echo $_GET['product_id'];?>">
    						<div class="col-lg-6">
    						    <h3 class="title mt-0 mb-10" style="text-align:left; "><?php echo $pname;?></h3>
    						    <div style="margin-bottom:20px; color:#777;"><span style="background:#34A853; border-radius:5px; padding:5px 7px; color:#fff;"><?php echo number_format($arr_pack_rate['avg_rate'],1);?> *</span><?php if($num_review_whole == 0) { ?>&nbsp;&nbsp;<?php echo $num_review_whole;?> Review(s)&nbsp;&nbsp;<?php if(isset($_SESSION['USER_ID'])) { ?><a href="post-review.php?product_id=<?php echo $fetch_product['product_id'];?>" style="color:#d75500; font-size:14px; text-align:left;">(Be the first to review this product)</a><?php } else { ?><a href="javascript:void();" data-toggle="modal" data-target="#myModalLogin" style="color:#d75500; font-size:14px; text-align:left;">(Be the first to review this product)</a><?php } ?><?php } else { ?>&nbsp;&nbsp;<?php echo $num_review_whole;?> Review(s)&nbsp;&nbsp;<?php if(isset($_SESSION['USER_ID'])) { ?><a href="post-review.php?product_id=<?php echo $fetch_product['product_id'];?>" style="color:#d75500; font-size:14px;">Write a Review</a><?php } else { ?><a href="javascript:void();" data-toggle="modal" data-target="#myModalLogin" style="color:#d75500; font-size:14px;">Write a Review</a><?php } ?><?php } ?></div>
    							<!--<p style="margin-bottom:0;"><span style="text-align:left; font-size:19px;">&#8377;<b><?php echo $fetch_product['price'];?></b></span><?php if($fetch_product['discount']!=0) { ?>&nbsp;&nbsp;<span style="text-align:right; color:#ff0000;"><del>&#8377;<?php echo $fetch_product['mrp'];?></del></span><span>&nbsp;&nbsp;<font color="#26A541"><b style="font-size:18px;"><?php echo $fetch_product['discount'];?>% Off</b></font></span><?php } ?></p>-->
    							<h3 style="margin-bottom:0;"><b>&pound;<?php echo $fetch_product['price'];?></b></h3>
    							<p>Free Express Delivery on All Orders.</p>
    							<h3 class="title mt-0 mb-10" style="text-align:left; color:#333;">Description</h3>
    							<p style="margin-bottom:10px;"><?php echo stripslashes($fetch_product['description']);?></p>
    							<?php if($fetch_product['features']!="") { ?>
    							<h3 class="title mt-0 mb-10" style="text-align:left; color:#333;">Features</h3>
    							<p style="margin-bottom:0;"><?php echo stripslashes($fetch_product['features']);?></p>
    							<?php } ?>
    							<?php if($fetch_product['how_to_use']!="") { ?>
    							<h3 class="title mt-0 mb-10" style="text-align:left; color:#333;">How To Use</h3>
    							<p style="margin-bottom:0;"><?php echo stripslashes($fetch_product['how_to_use']);?></p>
    							<?php } ?>
    							<?php if($fetch_product['note']!="") { ?>
    							<h3 class="title mt-0 mb-10" style="text-align:left; color:#333;">Note</h3>
    							<p style="margin-bottom:0;"><?php echo stripslashes($fetch_product['note']);?></p>
    							<?php } ?>
    							<?php if($fetch_product['package_included']!="") { ?>
    							<h3 class="title mt-0 mb-10" style="text-align:left; color:#333;">Package Included</h3>
    							<p style="margin-bottom:0;"><?php echo stripslashes($fetch_product['package_included']);?></p>
                                <?php } ?>
    							<?php if($fetch_product['total_stock']>0) { ?>
    						        <div style="margin-top:18px; margin-bottom:17px;"><select name="quantity" id="quantity" style="height: 37px; background: #f5efe3; display: inline-block; border: 1px solid #dbd0be">
    						            <?php
    							        for($i=1;$i<=$fetch_product['total_stock'];$i++)
                            			{
                            			    ?>
    						            <option value="<?php echo $i;?>"><?php echo $i;?></option>
    						            <?php
                            			}
                            			?></select>&nbsp;<button type="submit" class="btn btn-flat btn-theme-colored border-left-theme-color-2-4px" style="width:45%;" name="action" value="cart">Add To Cart</button>&nbsp;<button type="submit" class="btn btn-flat btn-theme-colored2 border-left-theme-color-2-4px" style="width:39%;" name="action" value="buy">Buy Now</button></div>
                            			<?php } else { ?>
                            			<div><h2 style="color:#ff0000; text-align:left;">OUT OF STOCK</h2></div>
                            			<?php } ?>
                            			<!--<div style="clear:both; height:17px;">&nbsp;</div>-->
                            			
            							<div>
        							</div>
    						        
    					</div>
    					</form>
    				</div>
				</div>
			</section>
			
			<section id="about">
				<div class="container mt-10 pb-10 pt-0">
					<div class="section-content">
						<div class="row">
							<div class="col-sm-12 col-md-12">
							    <h1 class="title mt-5 mb-15" style="text-align:center;">Happy Customers</h1>
							    <h3 class="title mt-5 mb-15" style="text-align:center; color:#d75500;"><?php echo $num_review_whole;?> Review(s)</h3>
							    <div class="text-center mb-20">
							        <?php if(isset($_SESSION['USER_ID'])) { ?>
							        <a class="btn btn-colored btn-theme-colored btn-lg mt-0" href="post-review.php?product_id=<?php echo $_GET['product_id'];?>">Write a Review</a><?php } else { ?><a href="javascript:void();" data-toggle="modal" data-target="#myModalLogin" class="btn btn-colored btn-theme-colored btn-lg mt-0">Write a Review</a><?php } ?></div>
							    <?php
    							$sql_review = "SELECT * FROM `og_reviews` WHERE `product_id` = '".$_GET['product_id']."'  ORDER BY `review_id` DESC";
    							$exe_review = mysqli_query($connection,$sql_review);
    							while($arr_review = mysqli_fetch_array($exe_review))
    							{
    								$getUser = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `og_users` WHERE `user_id` = '".$arr_review['user_id']."'"));
    								?>
							    <div class="col-sm-12 col-md-12" style="border:1px solid #ddd; background-color:#f1f1f1; border-radius:5px; padding:10px;">
							        <h3 style="margin:5px 0; color:#333333;"><?php echo stripslashes($getUser['fname']);?>&nbsp;<?php echo stripslashes($getUser['lname']);?></h3>
							        <div class="mb-10">
							            <?php if($arr_review['rate'] == '1') { ?>
							            <img src="images/rate.png" alt="">&nbsp;<img src="images/rate1.png" alt="">&nbsp;<img src="images/rate1.png" alt="">&nbsp;<img src="images/rate1.png" alt="">&nbsp;<img src="images/rate1.png" alt="">
							            <?php } ?>
							            <?php if($arr_review['rate'] == '2') { ?>
							            <img src="images/rate.png" alt="">&nbsp;<img src="images/rate.png" alt="">&nbsp;<img src="images/rate1.png" alt="">&nbsp;<img src="images/rate1.png" alt="">&nbsp;<img src="images/rate1.png" alt="">
							            <?php } ?>
							            <?php if($arr_review['rate'] == '3') { ?>
							            <img src="images/rate.png" alt="">&nbsp;<img src="images/rate.png" alt="">&nbsp;<img src="images/rate.png" alt="">&nbsp;<img src="images/rate1.png" alt="">&nbsp;<img src="images/rate1.png" alt="">
							            <?php } ?>
							            <?php if($arr_review['rate'] == '4') { ?>
							            <img src="images/rate.png" alt="">&nbsp;<img src="images/rate.png" alt="">&nbsp;<img src="images/rate.png" alt="">&nbsp;<img src="images/rate.png" alt="">&nbsp;<img src="images/rate1.png" alt="">
							            <?php } ?>
							            <?php if($arr_review['rate'] == '5') { ?>
							            <img src="images/rate.png" alt="">&nbsp;<img src="images/rate.png" alt="">&nbsp;<img src="images/rate.png" alt="">&nbsp;<img src="images/rate.png" alt="">&nbsp;<img src="images/rate.png" alt="">
							            <?php } ?>
							        </div>
									<div><?php echo nl2br(stripslashes($arr_review['comment']));?></div>
								</div>
								<div style="clear:both;">&nbsp;</div>
								<?php
    							}
    							?>
							</div>
						</div>
					</div>
				</div>
			</section>
			<!-- page template area end -->
  
<?php require_once("footer.php");?>