<!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 - Kurunegala Sri Lanka</title>
<meta name="description" content="Sudila Printers">
<meta name="keywords" content="">
<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">
<link href="css/jquery.toast.min.css" rel="stylesheet" type="text/css">
<!-- Modernizer js -->
<script type="text/javascript" src="js/vendor/modernizr-3.5.0.min.js"></script>
<style type="text/css">
.product .product__content .action {
	bottom: 38px;
}
.tt-menu {
	text-align: left;
	position: absolute;
	left: 0!important;
	right: 0!important;
	width: 100%;
	margin-top: 2px;
	padding: 6px 0;
	background-color: #FFF;
	border: 1px solid #D0D0D0;
	border: 1px solid rgba(0,0,0,.15);
	border-radius: 5px;
	/*box-shadow: 0 2px 4px rgba(0,0,0,.2)*/
}
.btn-group>.btn.moveall:first-child, .btn-group>.btn.moveall:first-child+.btn.move, .btn-group>.btn.remove:first-child, .btn-group>.btn.remove:first-child+.btn.removeall, .tt-suggestion p {
	margin: 0
}
.tt-suggestion {
	padding: 3px 12px 4px;
	font-size: 15px;
	line-height: 24px
}
.tt-suggestion.tt-cursor, .tt-suggestion.tt-selectable:hover {
	color: #FFF;
	background-color: #db6c00;
	cursor: pointer
}
input.typeahead.scrollable~.tt-menu {
	max-height: 200px;
	overflow-y: auto
}
</style>
</head>
<body>
<!-- Main wrapper -->
<div class="wrapper" id="wrapper"> 
  <!-- Header -->
	<?php include 'common/header.php'; ?>
  <!-- //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">Publishers</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 -->
  <div class="page-shop-sidebar left--sidebar bg--white section-padding--xlg">
    <div class="container">
      <div class="row">
		  <div class="col-lg-3"></div>
		  <div class="col-lg-6 order-lg-2">
			<div class="wn__sidebar">
				<aside class="widget search_widget">
					<div class="form-input">
						<input type="text" placeholder="Search Publisher..." name="a" id="publisher" autocomplete=off autofocus>
						<button><i class="fa fa-search"></i></button>
					</div>
				</aside>
			</div>
			</div>
	  </div>
	  
      <div class="row">
        <div class="col-lg-12 col-12 order-1 order-lg-2">
		<?php require 'common/pagination.php';
		
		$pagination = new Pagination();
		$records_per_page = 36;
		$pub_id = '';
		$pub_name = '';
		$ktxt = '';
	  
		if(isset($_GET['p'])) { // Publisher Filter
			$pub = htmlspecialchars(strip_tags(trim($_GET['p'])), ENT_QUOTES, 'UTF-8');
			if(empty($pub)) {
				$sql_p = "";
				
			} else {
				$sqlbk = mysqli_query($conn, "SELECT id, name FROM publisher WHERE search_id='$pub'");
				if(mysqli_num_rows($sqlbk) == 0) {
					$sql_p = "";
				
				} else {
					$sqlb = mysqli_fetch_assoc($sqlbk);
					$pub_name = $sqlb['name'];
					$pub_id = $sqlb['id'];
					
					$sql_p = "SELECT
	SQL_CALC_FOUND_ROWS
	id, name, price, front_image, back_image, weight, stock_out, discount, search_id, description, publisher, new_arrivals, reviews
	FROM
	bookdetails
	WHERE publisher=$pub_id";
					$ktxt = "<h5 class='pb--30'><b>".$pub_name."</b></h5>";
				
				}
			}
		
		} else if(isset($_GET['s']))  { // Keyword Search
			$key = htmlspecialchars(strip_tags(trim($_GET['s'])), ENT_QUOTES, 'UTF-8');

			if(empty($key)) {
				$ktxt = "";
				$sql_p = "";
			
			} else {
				$sql_p = "SELECT
		SQL_CALC_FOUND_ROWS
	bookdetails.id,
	bookdetails.name,
	bookdetails.price,
	bookdetails.front_image,
	bookdetails.back_image,
	bookdetails.weight,
	bookdetails.stock_out,
	bookdetails.discount,
	bookdetails.search_id,
	bookdetails.description,
	bookdetails.new_arrivals,
	bookdetails.reviews,
	bookdetails.publisher
	FROM
	bookdetails
	Inner Join publisher ON publisher.id = bookdetails.publisher
	WHERE
	publisher.name LIKE '%$key%'";
				$ktxt = "<h5 class='pb--30'>Search results for: <b>'".$key."'</b></h5>";
			}
			
		} else {
			$sql_p = "";
		}
		
		if(!empty($sql_p)) {
		$sql_pro = $sql_p." ORDER BY id DESC LIMIT " . (($pagination->get_page() - 1) * $records_per_page) . ', ' . $records_per_page . '';
		$tot = mysqli_num_rows(mysqli_query($conn, $sql_p));
		
		//echo $sql_pro;

		if (!($result_pro = @mysqli_query($conn, $sql_pro))) {
			die(mysqli_error($conn));
		}
		if (!($result_pro2 = @mysqli_query($conn, $sql_pro))) {
			die(mysqli_error($conn));
		}
		
		$rows = mysqli_fetch_assoc(mysqli_query($conn, 'SELECT FOUND_ROWS() AS row_ct'));
		$pagination->records($rows['row_ct']);
		$pagination->records_per_page($records_per_page);
		
		?>
		  <div class="row">
            <div class="col-lg-12">
			<?php echo $ktxt; ?>
              <div class="shop__list__wrapper d-flex flex-wrap flex-md-nowrap justify-content-between">
                <?Php if($tot == 0) { ?>
                <p>No Results Found.</p>
                <?php } else { ?>
				<div class="shop__list nav justify-content-center" role="tablist"> <a class="nav-item nav-link active" data-toggle="tab" href="#nav-grid" role="tab"><i class="fa fa-th"></i></a> <a class="nav-item nav-link" data-toggle="tab" href="#nav-list" role="tab"><i class="fa fa-list"></i></a> </div>
                <p>Showing <span><?php echo (($pagination->get_page() - 1) * $records_per_page)+1 ?>-<?php echo (($pagination->get_page() - 1) * $records_per_page)+mysqli_num_rows($result_pro); ?></span> of <span><?php echo $tot; ?></span> Results</p>
                <?php } ?>
              </div>
            </div>
          </div>
          <div class="tab__container">
            <div class="shop-grid tab-pane fade show active" id="nav-grid" role="tabpanel">
              <div class="row">
                <?php while ($row_pr = mysqli_fetch_array($result_pro)) {
					$f_img = $row_pr['front_image'];
					$b_img = $row_pr['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_pr['price'];
					if($row_pr['discount'] == 0) {
						$new_price = $row_pr['price'];
						$clz = 'hidden';
						
					} else {
						$new_price = ($row_pr['price'] - ($row_pr['price'] * $row_pr['discount']/100));
						$clz = '';
					}
				?>
                <div class="col-lg-2 col-md-3 col-sm-3 col-12">
                  <div class="product">
                    <div class="product__thumb"> <a class="first__img" href="book-details-sudila-printers-sri-lanka?bid=<?php echo $row_pr['search_id']; ?>"><img src="image/books/thumb/<?php echo $front_img; ?>" alt="<?php echo $row_pr['name']; ?>" title="<?php echo $row_pr['name']; ?>"></a> <a class="second__img animation1" href="book-details-sudila-printers-sri-lanka?bid=<?php echo $row_pr['search_id']; ?>"><img src="image/books/thumb/<?php echo $back_img; ?>" alt="<?php echo $row_pr['name']; ?>" title="<?php echo $row_pr['name']; ?>"></a>
                      <?php if($row_pr['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_pr['search_id']; ?>"><?php echo $row_pr['name']; ?></a></h4>
                      <div class="action">
                        <div class="actions_inner">
                          <ul class="add_to_links">
						  <?php if($row_pr['stock_out'] == 0 && $row_pr['weight'] > 0) { ?>
							<li><a title="Add to Cart" data-product-id="<?php echo $row_pr['id']; ?>" class="btn_cart btn_itm_<?php echo $row_pr['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_pr['id']; ?>" class="btn_wish btn_wh_<?php echo $row_pr['id']; ?>" href="javascript:void(0);"><i class="bi bi-love"></i></a></li>
							<li><a data-toggle="modal" title="Quick View" class="quickview modal-view detail-link btn_view" data-product-id="<?php echo $row_pr['id']; ?>" href="#productmodal"><i class="bi bi-search"></i></a></li>
                          </ul>
                        </div>
                      </div>
                      <ul class="rating d-flex">
						<?php
						$reviews = $row_pr['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 class="row">
                <div class="col-md-12">
                  <ul class="wn__pagination">
                    <?php $pagination->render(); ?>
                  </ul>
                </div>
              </div>
            </div>
            <div class="shop-grid tab-pane fade" id="nav-list" role="tabpanel">
              <div class="list__view__wrapper">
                <?php while ($row_pr = mysqli_fetch_array($result_pro2)) {
					$f_img = $row_pr['front_image'];
					$b_img = $row_pr['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_pr['price'];
					if($row_pr['discount'] == 0) {
						$new_price = $row_pr['price'];
						$clz = 'hidden';
						
					} else {
						$new_price = ($row_pr['price'] - ($row_pr['price'] * $row_pr['discount']/100));
						$clz = '';
					}
				?>
                <div class="list__view">
                  <div class="thumb"> <a class="first__img" href="book-details-sudila-printers-sri-lanka?bid=<?php echo $row_pr['search_id']; ?>"><img src="image/books/thumb/<?php echo $front_img; ?>" alt="<?php echo $row_pr['name']; ?>" title="<?php echo $row_pr['name']; ?>"></a> <a class="second__img animation1" href="book-details-sudila-printers-sri-lanka?bid=<?php echo $row_pr['search_id']; ?>"><img src="image/books/thumb/<?php echo $back_img; ?>" alt="<?php echo $row_pr['name']; ?>" title="<?php echo $row_pr['name']; ?>"></a> </div>
                  <div class="content">
                    <h2><a href="book-details-sudila-printers-sri-lanka?bid=<?php echo $row_pr['search_id']; ?>"><?php echo $row_pr['name']; ?></a></h2>
                    <ul class="rating d-flex">
						<?php
						$reviews = $row_pr['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>
                    <ul class="prize__box">
					<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>
                    <p>Author(s):                         <?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 = ".$row_pr['id']);
						$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 ' | ';
							}
						}
						?><br>
                      Publisher: <?php
						$sql_pub = mysqli_fetch_assoc(mysqli_query($conn, "SELECT name, search_id FROM publisher WHERE id=".$row_pr['publisher']));
						echo '<a href="publishers-sudila-printers-sri-lanka?p='.$sql_pub['search_id'].'">'.$sql_pub['name'].'</a>';
						?></p>
                    <ul class="cart__action d-flex">
						<li class="cart"><a title="Add to Wishlist" data-product-id="<?php echo $row_pr['id']; ?>" class="btn_wish btn_wish2 btn_wh_<?php echo $row_pr['id']; ?>" href="javascript:void(0);">Add to Wishlist</a></li>
					  <?php if($row_pr['stock_out'] == 0 && $row_pr['weight'] > 0) { ?>
						<li class="cart ct"><a title="Add to Cart" data-product-id="<?php echo $row_pr['id']; ?>" class="btn_cart  btn-outlined btn_itm_<?php echo $row_pr['id']; ?>" href="javascript:void(0);">Add to cart</a></li>
					  <?php } else { echo '<li><small class="text-danger">*Out of Stock</small></li>'; } ?>
                    </ul>
					
                  </div>
                </div>
                <?php } ?>
              </div>
              <br>
              <div class="row">
                <div class="col-md-12">
                  <ul class="wn__pagination">
                    <?php $pagination->render(); ?>
                  </ul>
                </div>
              </div>
            </div>
          </div>
		  <?php } ?>
        </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="backend/assets/js/jquery-typeahead.js"></script>
<script type="text/javascript">
	//typeahead.js
	//example taken from plugin's page at: https://twitter.github.io/typeahead.js/examples/
	var substringMatcher = function(strs) {
		return function findMatches(q, cb) {
			var matches, substringRegex;
		 
			// an array that will be populated with substring matches
			matches = [];
		 
			// regex used to determine if a string contains the substring `q`
			substrRegex = new RegExp(q, 'i');
		 
			// iterate through the pool of strings and for any string that
			// contains the substring `q`, add it to the `matches` array
			$.each(strs, function(i, str) {
				if (substrRegex.test(str)) {
					// the typeahead jQuery plugin expects suggestions to a
					// JavaScript object, refer to typeahead docs for more info
					matches.push({ value: str });
				}
			});

			cb(matches);
		}
	 }
	
	var PUB_LIST=[];
	
	<?php $sql_pb = mysqli_query($conn, "SELECT * FROM publisher ORDER BY name");
	while($row_pb = mysqli_fetch_array($sql_pb)) {
	?>
		PUB_LIST.push('<?php echo $row_pb['name']; ?>');
	<?php } ?>
	
	 $('#publisher').typeahead({
		hint: true,
		highlight: true,
		minLength: 1
	 }, {
		name: 'a',
		displayKey: 'value',
		source: substringMatcher(PUB_LIST),
		limit: 10
	 });

    $( "#publisher" ).keydown(function( event ) {
      if ( event.which == 13 ) {
        var auth = $(this).val();
		if(auth != '') {
		window.location.href = "publishers-sudila-printers-sri-lanka?s="+auth;
		}		
      }
    });	
</script>
</body>
</html>