<!doctype html>
<html class="no-js" lang="zxx">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Sudila Printers</title>
<meta name="description" content="Sudila Printers">
<meta name="keywords" content="Sudila Printers">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Favicons -->
<!-- <link rel="shortcut icon" href="images/favicon.ico"> -->

<!-- Google font (font-family: 'Roboto', sans-serif; Poppins ; Satisfy) -->
<link type="text/css" href="css/font_opensans.css" rel="stylesheet">
<link type="text/css" href="css/font_poppins.css" rel="stylesheet">
<link type="text/css" href="css/font_roboto.css" rel="stylesheet">
<!-- Stylesheets -->
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="css/plugins.css">
<link type="text/css" rel="stylesheet" href="css/style.css">
<!-- Cusom css -->
<link type="text/css" rel="stylesheet" href="css/custom.css">
<!-- Modernizer js -->
<script type="text/javascript" src="js/vendor/modernizr-3.5.0.min.js"></script>
<link href="css/jquery.toast.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
.product .product__content .action {
	bottom: 38px;
}
.rating-widget-block {
    -webkit-transform: rotateY(180deg);
    transform: rotateY(180deg);
    border: 2px solid #ececec;
    padding: 12px 20px;
}.rating-widget-block input {
    display: none;
}
.rating-widget-block label {
    margin-right: 8px;
    
    cursor: pointer;
    position: relative;
    margin-bottom: 0;
    display: inline-block;
}
.rating-widget-block label:before {
    content: "\f006";
    font-family: "FontAwesome";
    position: relative;
    display: block;
    font-size: 18px;
    color: #e3e3e3;
    font-weight: 500;
}.rating-widget-block label:after {
    content: "\f006";
    font-family: "FontAwesome";
    position: absolute;
    display: block;
    font-size: 18px;
    color: #fec701;
    font-weight: 500;
    top: 0;
    left: 0;
    opacity: 0;
    -webkit-transition: 0.4s;
    -o-transition: 0.4s;
    transition: 0.4s;
}
.product__info__detailed .review-fieldset .review_form_field .input__box span::after {
	content: none
}
.product__info__detailed .review-fieldset .review_form_field .input__box {
margin-bottom: 10px;
}
.product__info__detailed .review-fieldset .review_form_field .input__box span{

}
.help-block {
    color: #F44336 !important;
    font-size: 12px;
	margin-bottom: 10px;
}
.rating-widget-block label:hover ~ label:after, .rating-widget-block label:hover:after, .rating-widget-block input:checked ~ label:after {
    opacity: 1;
}
.blog-details .comments_area .comment__list li .wn__comment .content::before {
	content: none
}.blog-details .comments_area .comment__list .rating li {
    margin-bottom: 0;
}.blog-details .comments_area .comment__list li .wn__comment .content { margin-left: 0px}

.container-fluid1{
	max-width: 1550px;
}
  .productcategory__slide--2 .owl-item{max-width: 257px !important; max-height: auto !important;}
  .product__indicator--4 .owl-item{max-width: 257px !important; max-height: auto !important; border-radius: 3px;}
 /* .single__product{max-width: 274px !important; max-height: auto; }*/

 .product .product__thumb {
   margin: 10px;
}
</style>
</head>
<body>
<!-- Main wrapper -->
<div class="wrapper" id="wrapper"> 
  <!-- Header -->
	<?php 
	include 'common/header.php';	
	
	if(isset($_GET['bid'])) {
		$sid = htmlspecialchars(strip_tags(trim($_GET['bid'])), ENT_QUOTES, 'UTF-8');
		
		if(empty($sid)) {
			$redirectUrl = "index";
			echo "<script type=\"text/javascript\">";
			echo "window.location.href = '$redirectUrl'";
			echo "</script>";
			
		} else {
			$sqlbk = mysqli_query($conn, "SELECT * FROM bookdetails where search_id = '$sid'");
			if(mysqli_num_rows($sqlbk) == 0) {
				$redirectUrl = "index";
				echo "<script type=\"text/javascript\">";
				echo "window.location.href = '$redirectUrl'";
				echo "</script>";
			
			} else {
				$sqlb = mysqli_fetch_assoc($sqlbk);
				$bid = $sqlb['id'];
				$name = $sqlb['name'];
				$isbn = $sqlb['isbn'];
				$details = $sqlb['description'];
				$pub = $sqlb['publisher'];
				$width = $sqlb['width'];
				$height = $sqlb['height'];
				$weight = $sqlb['weight'];
				$stk = $sqlb['stock_out'];
				$search_id = $sqlb['search_id'];
				$reviews = $sqlb['reviews'];
				
				$old_price = $sqlb['price'];
				if($sqlb['discount'] == 0) {
					$new_price = $sqlb['price'];
					$clz = 'hidden';
					
				} else {
					$new_price = ($sqlb['price'] - ($sqlb['price'] * $sqlb['discount']/100));
					$clz = '';
				}
				
				$f_img = $sqlb['front_image'];
				$b_img = $sqlb['back_image'];
				
				if(empty($f_img)) { $front_img = 'noimg.jpg'; } else { $front_img = $f_img; }
				if(empty($b_img)) { $back_img = $front_img; } else { $back_img = $b_img; }
				
				$cat_arr = array();
				$cat_name = array();
				
				$sql_cat = mysqli_query($conn, "SELECT
category.category,
category.search_id,
category_map.Cat_ID
FROM
category
Inner Join category_map ON category_map.Cat_ID = category.id
WHERE
category_map.Book_ID = $bid");
				while($row_cat = mysqli_fetch_array($sql_cat)) {
					array_push($cat_arr, $row_cat['Cat_ID']);
					array_push($cat_name, array('category' => $row_cat['category'], 'search_id' => $row_cat['search_id']));
				}
				
				$cat_list = implode(", ", array_values($cat_arr));
				
				$pub_name = '';
				if(!empty($pub)) {
					$sql_pub = mysqli_fetch_assoc(mysqli_query($conn, "SELECT name, search_id FROM publisher WHERE id=$pub"));
					$pub_name = '<a href="publishers-sudila-printers-sri-lanka?p='.$sql_pub['search_id'].'">'.$sql_pub['name'].'</a>';
				}
			}
		}

	} else {
		$redirectUrl = "index";
		echo "<script type=\"text/javascript\">";
		echo "window.location.href = '$redirectUrl'";
		echo "</script>";
	}
	?>
  <!-- //Header --> 
  <!-- Start Bradcaump area -->
  <div class="ht__bradcaump__area bg-image--4">
    <div class="container">
      <div class="row">
        <div class="col-lg-12">
          <div class="bradcaump__inner text-center">
            <h2 class="bradcaump-title"><?php echo $name; ?></h2>
            <nav class="bradcaump-content"> <a class="breadcrumb_item" href="index">HOME</a> <span class="brd-separetor">/</span> <a href="bookstore-sudila-printers-sri-lanka"><span class="breadcrumb_item active">Book Store</span></a> </nav>
          </div>
        </div>
      </div>
    </div>
  </div>
  <!-- End Bradcaump area -->
  <!-- Start main Content -->
  <div class="maincontent bg--white pt--70 pb--55">
    <div class="container-fluid container-fluid1">
      <div class="row">
        <div class="col-lg-12 col-12">
          <div class="wn__single__product">
            <div class="row">
              <div class="col-md-4 col-12">
				<div class="wn__fotorama__wrapper">
					<div class="fotorama wn__fotorama__action" data-nav="thumbs">
						  <a href="#"><img src="image/books/<?php echo $front_img; ?>" alt=""></a>
						  <?php if(!empty($b_img)) { ?>
						  <a href="#"><img src="image/books/<?php echo $back_img; ?>" alt=""></a>
						  <?php } ?>
					</div>
				</div>
              </div>
              <div class="col-md-8 col-12">
                <div class="product__info__main">
				<?php if(!empty($cat_name)) {
				echo '<p>';
				$ct_x = 0;
				foreach ($cat_name as $cat) { $ct_x++; ?>
				<a href="bookstore-sudila-printers-sri-lanka?c=<?php echo $cat['search_id']; ?>"><?php echo $cat['category']; ?></a> <?php if($ct_x != count($cat_name)) { echo ' | '; } } echo '</p>'; } ?>
                  <h1><?php echo $name; ?></h1>
                  <div class="product-info-stock-sku">
                    <p>Availability:<span> <?php if($stk == 0 && $weight > 0) { echo 'In Stock'; } else { echo 'Out of Stock'; } ?></span></p>
                    <p>ISBN:<span> <?php echo $isbn; ?></span></p>
                  </div>
                  <div class="product-reviews-summary d-flex">
                    <ul class="rating-summary d-flex">
						<?php
						for($rx = 0; $rx < $reviews; $rx++) {
							echo '<li><i class="zmdi zmdi-star-outline"></i></li>';
						}
						
						for($rx = 0; $rx < (5-$reviews); $rx++) {
							echo '<li class="off"><i class="zmdi zmdi-star-outline"></i></li>';
						}
						?>
                    </ul>
                    <div class="reviews-actions d-flex"> <?php echo $reviews; ?> Customer Review(s) </div>
                  </div>
                  <br>
                  <p>Author(s):<span>
				  <?php
					$sql_au = mysqli_query($conn, "SELECT
					author.name,
					author.search_id
					FROM
					author_map
					Inner Join author ON author_map.Auth_ID = author.id
					WHERE
					author_map.Book_ID = $bid");
					$au_x = 0;
					while($row_au = mysqli_fetch_array($sql_au)) { $au_x++;
						echo '<a href="authors-sudila-printers-sri-lanka?a='.$row_au['search_id'].'">'.$row_au['name'].'</a>';
						if($au_x != mysqli_num_rows($sql_au)) {
							echo ' | ';
						}
					}
					?></span></p>
                  <p>Publisher:<span> <?php echo $pub_name; ?></span></p>
                  <div class="price-box"> 
					<span>LKR <?php echo number_format($new_price, 2); ?></span>
					<del class="old_prize <?php echo $clz; ?>">LKR <?php echo number_format($old_price, 2); ?></del>
				  </div>
				  <hr><br>
                  <div class="product-info-stock-sku">
                    <p>Width:<span> <?php echo $width; ?> mm</span></p>
                    <p>Height:<span> <?php echo $height; ?> mm</span></p>
                    <p>Weight:<span> <?php echo $weight; ?> g</span></p>
                  </div>
				  <?php if($stk == 0 && $weight > 0) { ?>
                  <div class="box-tocart"> <span>Qty:</span>
                    <input id="qty" class="input-text qty" name="qty" min="1" value="1" title="Quantity" autocomplete='off' type="number">
                    <div class="addtocart__actions">
                      <button class="tocart btn_cart btn_itm_<?php echo $bid; ?>" data-product-id="<?php echo $bid; ?>" title="Add to Cart">Add to Cart</button>
                      <!--&nbsp;<button class="tocart buynow" title="Buy Now">Buy Now</button>-->
                    </div>
                  </div>
               <!--    <div class="product-add-to-cart chkt">
    <input name="rev_submit" type="button" class="btn btn-black" value="Submit Review" id="submitReviewButton"/>
</div> -->

				  <?php } ?>
                  <div class="product-addto-links clearfix"> <a data-product-id="<?php echo $bid; ?>" class="wishlist btn_wish btn_wh_<?php echo $bid; ?>" href="javascript:void(0);" title="Add to Wishlist"></a>  </div>
                </div>
              </div>
            </div>
          </div>
		  <?php $sql_rev = mysqli_query($conn, "SELECT *, DATE_FORMAT( DATE,  '%M %d, %Y' )  AS dt FROM cus_review WHERE item_id='$bid' AND accept=1 ORDER BY review DESC");
		  $rev_count = mysqli_num_rows($sql_rev); ?>
          <div class="product__info__detailed">
            <div class="pro_details_nav nav justify-content-start" role="tablist"> <a class="nav-item nav-link active" data-toggle="tab" href="#nav-details" role="tab">Description</a> <a class="nav-item nav-link" data-toggle="tab" href="#nav-review" role="tab">Customer Reviews (<?php echo $rev_count; ?>)</a> </div>
            <div class="tab__container"> 
              <!-- Start Single Tab Content -->
              <div class="pro__tab_label tab-pane fade show active" id="nav-details" role="tabpanel">
                <div class="description__attribute">
                  <p><?php echo $details; ?></p>
                </div>
              </div>
              <!-- End Single Tab Content --> 
              <!-- Start Single Tab Content -->
              <div class="pro__tab_label tab-pane fade" id="nav-review" role="tabpanel">
				<div class="row">
				<div class="col-lg-6 blog-details ">
					<div class="comments_area">
						<ul class="comment__list">
							<?php while($row_rev = mysqli_fetch_array($sql_rev)) { ?>
							<li>
								<div class="wn__comment">
									<div class="content">
										<div class="comnt__author d-block d-sm-flex">
											<h6><?php echo $row_rev['name']; ?></h6>
											<span> - <?php echo $row_rev['dt']; ?></span>
										</div>
										<p><?php echo $row_rev['comment']; ?></p>
										
									  <ul class="rating d-flex">
										<?php
										for($rx = 0; $rx < $row_rev['review']; $rx++) {
											echo '<li class="on"><i class="fa fa-star-o"></i></li>';
										}
										
										for($rx = 0; $rx < (5-$row_rev['review']); $rx++) {
											echo '<li><i class="fa fa-star-o"></i></li>';
										}
										?>
									  </ul>
									</div>
								</div>
							</li>
							<?php } ?>
						</ul>
					</div>
				</div>
				<div class="col-lg-6">
				  <h5>ADD A REVIEW</h5>
				<div class="review-fieldset">
                  <form action="javascript:void(0);" method="post" id="commentform">
				  <div class="review_form_field">
					<div class="input__box">
					<span class="rating-widget-block">
						<input type="radio" name="rev_star" id="star1" required value="5">
						<label for="star1"></label>
						<input type="radio" name="rev_star" id="star2" required value="4">
						<label for="star2"></label>
						<input type="radio" name="rev_star" id="star3" required value="3">
						<label for="star3"></label>
						<input type="radio" name="rev_star" id="star4" required value="2">
						<label for="star4"></label>
						<input type="radio" name="rev_star" id="star5" required value="1">
						<label for="star5"></label>
					</span>
						<span class="help-block"></span>
					</div>
					<div class="input__box"> <span>Name</span>
                      <input type="text" id="rev_name" autocomplete="off" name="rev_name" class="clr" required>
					  <span class="help-block"></span>
                    </div>
					<div class="input__box">
						<span>Email</span>
						<input type="text" id="rev_email" autocomplete="off" name="rev_email" class="clr">
						<span class="help-block"></span>
					</div>
                    <div class="input__box"> <span>Comment</span>
					<textarea name="rev_message" autocomplete="off" required id="rev_message" cols="30" rows="10" class="clr"></textarea>
					<span class="help-block"></span>
                    </div>
					<input type="hidden" required value="<?php echo $bid; ?>" name="book_id">
				  <div id="errorDiv"></div>
                    <div class="product-add-to-cart chkt">
					<input name="rev_submit" type="submit" class="btn btn-black" value="Submit Review" />
                    </div>
                  </div>
				  </form>
                </div>
				</div>
              </div>
              <!-- End Single Tab Content --> 
            </div>
          </div>
          <div class="wn__related__product pt--80 container-fluid1">
            <div class="section__title">
              <h2 class="title__be--2">Related Books</h2>
              <hr>
            </div>
            <div class="row mt--50">
              <div class="productcategory__slide--2 arrows_style owl-carousel owl-theme">
				<?php
				if(empty($cat_list)) {
					$cat_list = '';
					$sql_pr = mysqli_query($conn, "SELECT id, name, price, front_image, back_image, weight, stock_out, discount, search_id, new_arrivals, reviews FROM bookdetails WHERE id IN (SELECT Book_ID FROM category_map WHERE Cat_ID IN ('')) AND id!=$bid ORDER by id DESC LIMIT 20");
				
				} else {
					$sql_pr = mysqli_query($conn, "SELECT id, name, price, front_image, back_image, weight, stock_out, discount, search_id, new_arrivals, reviews FROM bookdetails WHERE id IN (SELECT Book_ID FROM category_map WHERE Cat_ID IN ($cat_list)) AND id!=$bid ORDER by id DESC LIMIT 20");
				}
				while($row_rp = mysqli_fetch_array($sql_pr)) {
					$f_img = $row_rp['front_image'];
					$b_img = $row_rp['back_image'];
					
					if(empty($f_img)) { $front_img = 'noimg.jpg'; } else { $front_img = $f_img; }
					if(empty($b_img)) { $back_img = $front_img; } else { $back_img = $b_img; }
					
					$old_price = $row_rp['price'];
					if($row_rp['discount'] == 0) {
						$new_price = $row_rp['price'];
						$clz = 'hidden';
						
					} else {
						$new_price = ($row_rp['price'] - ($row_rp['price'] * $row_rp['discount']/100));
						$clz = '';
					}
				?>
                <div class="col-lg-4 col-md-4 col-sm-6 col-12">
                  <div class="product">
                    <div class="product__thumb"> <a class="first__img" href="book-details-sudila-printers-sri-lanka?bid=<?php echo $row_rp['search_id']; ?>"><img src="image/books/thumb/<?php echo $front_img; ?>" alt="<?php echo $row_rp['name']; ?>" title="<?php echo $row_rp['name']; ?>"></a> <a class="second__img animation1" href="book-details-sudila-printers-sri-lanka?bid=<?php echo $row_rp['search_id']; ?>"><img src="image/books/thumb/<?php echo $back_img; ?>" alt="<?php echo $row_rp['name']; ?>" title="<?php echo $row_rp['name']; ?>"></a>
                      <?php if($row_rp['new_arrivals'] == 1) { ?>
                      <div class="new__box"> <span class="new-label">New</span> </div>
                      <?php } ?>
                      <ul class="prize position__right__bottom">
						<li>LKR <?php echo number_format($new_price, 2); ?></li>
						<li class="old_prize <?php echo $clz; ?>">LKR <?php echo number_format($old_price, 2); ?></li>
                      </ul>
                    </div>
                    <div class="product__content">
                      <h4><a href="book-details-sudila-printers-sri-lanka?bid=<?php echo $row_rp['search_id']; ?>"><?php echo $row_rp['name']; ?></a></h4>
                      <div class="action">
                        <div class="actions_inner">
                          <ul class="add_to_links">
						  <?php if($row_rp['stock_out'] == 0 && $row_rp['weight'] > 0) { ?>
							<li><a title="Add to Cart" data-product-id="<?php echo $row_rp['id']; ?>" class="btn_cart btn_itm_<?php echo $row_rp['id']; ?>" href="javascript:void(0);"><i class="bi bi-shopping-cart-emply"></i></a></li>
						  <?php } else { echo '<small class="text-danger">Out of Stock</small>'; } ?>
							<li><a title="Add to Wishlist" data-product-id="<?php echo $row_rp['id']; ?>" class="btn_wish btn_wh_<?php echo $row_rp['id']; ?>" href="javascript:void(0);"><i class="bi bi-love"></i></a></li>
							<li><a data-toggle="modal" title="Quick View" data-product-id="<?php echo $row_rp['id']; ?>" class="quickview modal-view detail-link btn_view" href="#productmodal"><i class="bi bi-search"></i></a></li>
                          </ul>
                        </div>
                      </div>
                      <ul class="rating d-flex">
						<?php
						$reviews = $row_rp['reviews'];
						for($rx = 0; $rx < $reviews; $rx++) {
							echo '<li class="on"><i class="fa fa-star-o"></i></li>';
						}
						
						for($rx = 0; $rx < (5-$reviews); $rx++) {
							echo '<li><i class="fa fa-star-o"></i></li>';
						}
						?>
                      </ul>
                    </div>
                  </div>
                </div>
                <?php } ?>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  </div>
  <!-- End main Content --> 
  <!-- Footer Area -->
  <?php include 'common/footer.php'; ?>
  <!-- //Footer Area --> 
</div>
<!-- //Main wrapper -->
<!-- JS Files --> 
<script type="text/javascript" src="js/vendor/jquery-3.2.1.min.js"></script> 
<script type="text/javascript" src="js/popper.min.js"></script> 
<script type="text/javascript" src="js/bootstrap.min.js"></script> 
<script type="text/javascript" src="js/plugins.js"></script> 
<script type="text/javascript" src="js/active.js"></script>
<script type="text/javascript" src="js/add-to-cart.js"></script>
<script type="text/javascript" src="js/jquery.toast.js"></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
	// valid email pattern
	var eregex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	$.validator.addMethod("validemail", function (value, element) {
		return this.optional(element) || eregex.test(value);
	});
	
	// JavaScript Validation For Checkout Form 
	$("#commentform").validate({
		ignore: [],
		rules: {
			rev_email: {
				validemail: true
			},
		},
		messages: {
			rev_email: {
				validemail: "Please Enter Valid Email Address"
			},
		},
		errorPlacement: function (error, element) {
			$(element).closest('.input__box').find('.help-block').html(error.html()).show();
		},
		highlight: function (element) {
			$(element).closest('.input__box').removeClass('has-success').addClass('has-error');
		},
		unhighlight: function (element, errorClass, validClass) {
			$(element).closest('.input__box').removeClass('has-error');
			$(element).closest('.input__box').find('.help-block').html('').hide();
		},
		submitHandler: submitForm
	});

	function submitForm() {
		$.ajax({
			type: 'POST',
			async: false,
			url: 'connection/cust_feedback',
			data: $('#commentform').serialize(),
			dataType: 'json',
			success: function (data) {
				$('input[name=rev_submit]').prop('disabled', true);
				$('input[type=text],input[type=select],input[type=email]').prop('disabled', true);
				setTimeout(function () {
					if (data.status === '1') {
						$("#commentform").trigger('reset');
						
						$('#errorDiv').slideDown(200, function () {
							$('#errorDiv').html('<div class="alert alert-success">' + data.message + '</div>');
							$('#errorDiv').delay(5000).slideUp(100);
							$('input[type=text],input[type=select],input[type=email]').prop('disabled', false);
							$('input[name=rev_submit]').prop('disabled', false);
						});
					
					} else {
						$('#errorDiv').slideDown(200, function () {
							$('#errorDiv').html('<div class="alert alert-danger">' + data.message + '</div>');
							$('#errorDiv').delay(5000).slideUp(100);
							$('input[type=text],input[type=select],input[type=email]').prop('disabled', false);
							$('input[name=rev_submit]').prop('disabled', false);
						});
					}
				}, 1000);
			},
			error: function () {
				$('#errorDiv').slideDown(200, function () {
					$('#errorDiv').html('<div class="alert alert-danger">An unknown error occoured, Please try again Later...!</div>');
					$('#errorDiv').delay(5000).slideUp(100);
					$('input[type=text],input[type=select],input[type=email]').prop('disabled', false);
					$('input[name=rev_submit]').prop('disabled', false);
				});
			}
		});
		return false;
	}
});

// $(document).ready(function () {
//     // Handle the form submission
//     $("#submitReviewButton").click(function () {
//         // Collect form data
//         var formData = {
//             rev_star: $('input[name="rev_star"]:checked').val(),
//             rev_name: $("#rev_name").val(),
//             rev_email: $("#rev_email").val(),
//             rev_message: $("#rev_message").val(),
//             book_id: $('input[name="book_id"]').val()
//         };

//         // Send the form data via AJAX to the server-side script
//         $.ajax({
//             type: "POST",
//             url: "send_email.php", // Server-side script to send email
//             data: formData,
//             success: function (response) {
//                 // Handle the response from the server
//                 alert("Review submitted and email sent successfully!");
//             },
//             error: function () {
//                 alert("An error occurred. Please try again.");
//             }
//         });
//     });
// });

</script>

</body>
</html>