<!-- header top start -->
<?php include('header_top.php');?>

<?php if($_REQUEST['store_name']!=''){
		$store_name_slug=$_REQUEST['store_name'];
	//   print_r($subcate);
	//   exit();
		}else{
		echo "<script>window.location.href='https://couponclap.com/';</script>";
        exit;
		}

		$query = mysqli_query($con, "
			SELECT * FROM stores 
			WHERE LOWER(REPLACE(store_name,' ','-')) = '$store_name_slug'
		");
		$store = mysqli_fetch_assoc($query);
		if(empty($store)){
		    echo "<script>window.location.href='https://couponclap.com/';</script>";
            exit;
		}else{
		
		 ?>
<!-- header top end -->
<?php 
$st_id = $store['id'];
$query_meta = "SELECT * FROM meta_data WHERE meta_name='stor_$st_id'";
$res = mysqli_query($con, $query_meta);
while($row = mysqli_fetch_array($res)) {
?>
    <?php echo $row['content']; ?>
<?php 
}
?>

<link href='https://couponclap.com/static/css/store1-min8d36.css?v=2024111902' rel="stylesheet" />
<link href='https://couponclap.com/static/css/store1-minaa58.css?v=2024111902' rel="stylesheet" />
<link href='https://couponclap.com/static/css/favourite-icon-rating-min8d36.css?v=20240422' rel="stylesheet" />
<link href='https://couponclap.com/static/css/favourite-icon-rating-min839a.css?v=20240422' rel="stylesheet" />
<!-- header bottom start -->
<?php include('header_buttom.php');?>
<!-- header bottom end -->
<style>
    /* Default: Hide */
.offer-percentage.redeemOffer.redeemCoupon.mobileviewlist {
    display: none;
}

/* Show only on mobile screens */
@media (max-width: 767px) {
    .offer-percentage.redeemOffer.redeemCoupon.mobileviewlist {
        display: block;
    }
    .grab-deal-mob {
        display: block;
        margin-top: -23px;
        text-align: center;
        padding: 5px 0 !important;
        cursor: pointer;
        width: 61% !important;
        margin-left: 19.5%;
    }
    .offer-title-div.redeemCoupon {
    text-align: center;
}
}
</style>
<body style="background-color: #e2e2e1">
	<!-- header menu start -->
	<?php include('header.php');?>
	<!-- header menu end -->
	<div class="container-fluid store-main-container col-xs-12 col-md-12 col-lg-12 col-sm-12">
		<section class="col-xs-12 col-md-12 col-lg-12 col-sm-12 main-cont-row store-info1">
			<div class="store-top-header link-section col-xs-12 col-sm-12 col-lg-12 col-md-12">
				<span class="home-link">
					<a href="https://couponclap.com/">Home</a></span> > <span class="stores-link">
					<a href="https://couponclap.com/all-stores">Stores</a></span>
				>
				<span class="store-name">
					<?php echo $store['store_name'];?>
				</span>
			</div>
			<div class="store-details-info col-md-12 col-xs-12 col-lg-12 col-sm-12">
				<div class="col-xs-3 col-sm-3 col-md-4 col-lg-4 cc-desc-elm"></div>
				<div class="store-desc1 col-xs-6 col-sm-3 col-md-2 col-lg-2">
					<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 store-desc-holder">
						<div id="favourite_user" class="unfavourited fa-heart-sym"></div>
						<div class="store-image-div">
							<a class='goToStoresFromOfferPage' href="<?php echo $store['store_url']; ?>">
								<img alt="<?php echo $store['store_name'];?>" src="https://couponclap.com/images/uploads/stores/<?php echo $store['store_image']; ?>" class="store-image">
							</a>
						</div>
					</div>
				</div>
				<div class="col-xs-3 col-sm-3 col-md-4 col-lg-4 cc-desc-elm"></div>
				<div class="store-details1 col-xs-12 col-sm-8 col-md-9 col-lg-9">
					<div class="store-h1 col-xs-12 col-sm-12 col-md-12 col-lg-12">
						<h1 class="desktop-h1"><?php echo $store['store_name'];?> Coupons & Sale Offers Upto</h1>
					</div>
					<div class="store-h2 col-md-12 col-lg-12 col-xs-12 col-sm-12">
						<div class="store-cb-heading"><?php echo $store['coupon_offer'];?></div>
					</div>
					<div class="store-mini-desc store-mini-desc-desk col-md-12 col-lg-12 col-xs-12 col-sm-12 "> <?php echo $store['description'];?> </div>
				</div>
			</div>
		</section>
		<section class="coupons-main-section col-md-9 col-lg-9 col-xs-12 col-sm-9">
			<?php 
				$storeids = $store['id'];
				$category_filter = [];
				$where = " WHERE p.status = 'published' AND p.unpaused='0' AND p.stores_id='$storeids' ";
				/* CATEGORY FILTER USING POST */
				if(isset($_POST['category']) && !empty($_POST['category'])){
					$category_filter = array_map('intval', $_POST['category']);
					$cat_ids = implode(',', $category_filter);
					$where .= " AND p.category_id IN ($cat_ids)";
				}
				
			    $limit = 8;
                $page = 1;
                $start = ($page - 1) * $limit;
				
				$query = "
					SELECT p.*, c.name as category_name
					FROM posts p
					LEFT JOIN categories c ON c.id = p.category_id
					$where
					ORDER BY p.id DESC LIMIT $start,$limit
				";
				$result = mysqli_query($con,$query);
				/* COUNT */
				$count_query = "
					SELECT COUNT(*) as total 
					FROM posts p
					$where
				";
				$count_all = mysqli_fetch_assoc(mysqli_query($con, $count_query));
			?>
			<section class="coupons-category col-md-12 col-lg-12 col-xs-12 col-sm-12">
				<article class="coupons-heading col-md-12 col-lg-12 col-xs-12 col-sm-12">
					<ul class="nav nav-tabs">
						<li class="filter active-tab all navigation-tab col-sm-4 col-xs-4 col-md-2 col-lg-2"
							data-rel="ALL">
							<a>All <span class="all-offers-count">(<?php echo $count_all['total']; ?>)</span></a>
						</li>
					</ul>
				</article>
			</section>

			<ul class="coupons-main-section-ul col-md-12 col-lg-12 col-xs-12 col-sm-12">
				<!-- loop -->
				
				<?php if(mysqli_num_rows($result)>0){ ?>
                <?php while($post = mysqli_fetch_assoc($result)){ 
                      $stores_id = $post['stores_id'];
                      $slug = strtolower(str_replace(' ','-',$post['slug']));
                    // store details
                    $sql_stores_s = "SELECT * FROM stores WHERE id = '$stores_id'";
                    $res_stores_s = mysqli_query($con, $sql_stores_s);
                    $result_stores_d=mysqli_fetch_assoc($res_stores_s);
                    ?>
                    
                <li class="offer1 col-md-12 col-lg-12 col-xs-12 col-sm-12">
                    <article class="store-coupons col-md-12 col-lg-12 col-xs-12 col-sm-12">
                        <div class="offer-percent-section coupon-section col-md-3 col-lg-3 col-sm-4 col-xs-12">
                            <div class="share-symbol share-social">
                                <img src="https://couponclap.com/images/icons/icon-share.png">
                            </div>

                            <div class="store-vertical-line">
                                <a class='goToStoresFromOfferPage' href="https://couponclap.com/deals/<?php echo $slug; ?>">
                                    <div class="offer-percentage redeemOffer redeemCoupon"
                                        data-coupon="<?php echo $post['code']; ?>"
                                        data-type="<?php echo $post['type']; ?>">
                                        <img src="https://couponclap.com/images/blogs/coupon/<?php echo $post['image_big']; ?>" style="width:100%">
                                    </div>
                                </a>
                            </div>
                        </div>
                        <div class="coupon-section offer-desc-section col-md-9 col-lg-9 col-xs-12 col-sm-12">
                            <div class="row coupon-head-row">
                                <div class="cc-how-it-works cc-how-it-works-mobile" id="hw-offer-<?php echo $post['id']; ?>">HOW IT WORKS</div>
                                <div class="editors_choice">
                                    <span class="cc-choice">
                                        <span class="editors-choice-text"><img src="https://couponclap.com/images/favicon.ico"> Recommended</span>
                                    </span>
                                </div>
                                <div class="user-share-count">
                                    <div class="storeLogo" style="text-align: right; margin-right: 10px;">
                                        <img style="max-width: 100px;" class="delayed-image" src="https://couponclap.com/images/brand/2logo.jpg"
                                            data-src="https://couponclap.com/images/uploads/stores/<?php echo $result_stores_d['store_image']; ?>"
                                            alt="storeLogo" width="50%" />
                                    </div>
                                    <div class="user-count">
                                        <span><img class="count-logo" src="https://couponclap.com/images/icons/people.png"></span>
                                        <span class="count"><?php echo $post['usedno']; ?> people used till this date </span>
                                    </div>
                                </div>
                                <div class="share-symbol share-mob"><img src="https://couponclap.com/images/icons/icon-share.png"></div>
                            </div>
                            
                            <a class='goToStoresFromOfferPage' href="https://couponclap.com/deals/<?php echo $slug; ?>"
                                data-logo='https://couponclap.com/images/uploads/stores/<?php echo $result_stores_d['store_image']; ?>'
                                data-store='<?php echo $result_stores_d['store_name']; ?>' data-coupon='<?php echo $post['code']; ?>'
                                data-type='<?php echo $post['type']; ?>' data-title='<?php echo $post['title']; ?>'>
                                <div class="offer-title-div redeemCoupon" data-coupon="<?php echo $post['code']; ?>" data-type="<?php echo $post['type']; ?>">
                                    <div class="offer-percentage redeemOffer redeemCoupon mobileviewlist text-center"
                                        data-coupon="<?php echo $post['code']; ?>"
                                        data-type="<?php echo $post['type']; ?>">
                                        <img src="https://couponclap.com/images/blogs/coupon/<?php echo $post['image_big']; ?>" style="width:50%;height:89px">
                                       
                                    </div>
                                    <div class="offer-title"><?php echo $post['title']; ?></div>
                                    <div class="offer-cashback-title"><?php echo $post['coupon_code']; ?></div>
                                </div>
                            </a>
                            <!--<div class="offer-desc"><p></?php echo $post['description']; ?></p></div>-->
                            <br>
                            <?php if(!empty($post['code'])){?>
                                 <a class="goToStoresFromOfferPage copy-btn-grap" href="https://couponclap.com/deals/<?php echo $slug; ?>"
                                    data-logo='https://couponclap.com/images/uploads/stores/<?php echo $result_stores_d['store_image']; ?>'
                                    data-store='<?php echo $result_stores_d['store_name']; ?>' data-coupon='<?php echo $post['code']; ?>'
                                    data-title='<?php echo $post['title']; ?>' data-type='<?php echo $post['type']; ?>'
                                    data-src="https://couponclap.com/images/blogs/coupon/<?php echo $post['image_big']; ?>"
                                    data-slug="<?php echo $post['slug']; ?>" data-click-type="coupon">
                                    <div class="grab-deal-div grab-deal-mob btn-orange grab-deal-btn col-xs-12 col-lg-4 col-sm-4 col-md-4">Get Coupon</div>
                                </a>
                                <?php }else{ ?>
                                <a class="goToStoresFromOfferPageset copy-btn-grap" href="javascript:void(0);" data-slug="<?php echo $slug; ?>"
                                    data-store-url="<?php echo $result_stores_d['store_url']; ?>"
                                    data-logo="https://couponclap.com/images/uploads/stores/<?php echo $result_stores_d['store_image']; ?>"
                                    data-store="<?php echo $result_stores_d['store_name']; ?>" data-title="<?php echo $post['title']; ?>"
                                    data-type="<?php echo $post['type']; ?>" data-click-type="grab"
                                    data-image="https://couponclap.com/images/blogs/coupon/<?php echo $post['image_big']; ?>">
                                    <div class="grab-deal-div grab-deal-mob btn-orange grab-deal-btn col-xs-12 col-lg-4 col-sm-4 col-md-4">Grab Deal</div>
                                </a>
                            <?php } ?>
                            
                            <div class="couponfoot col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                <span class="expiry col-lg-6 col-md-6 col-sm-6 col-xs-6">
                                    <img src="images/icons/icon-calendar.png" alt="calendar" class="calendar-image">
                                    <?php echo "Expires on " . date("M j, Y", strtotime($post['end_date']));?>
                                </span>
                                <span class="expiry expiry-mob col-lg-6 col-md-6 col-sm-6 col-xs-4">
                                    <img src="images/icons/icon-calendar.png" alt="calendar" class="calendar-image">
                                    <?php echo date("M j, Y", strtotime($post['end_date']));?>
                                </span>
                                <span class="verification col-lg-6 col-md-6 col-sm-6 col-xs-4 redeemCoupon"
                                    data-coupon="<?php echo $post['code']; ?>" data-type="<?php echo $post['type']; ?>">
                                    <img src="images/icons/icon-verified.png" alt="verified" class="verified-image">
                                    <a class='goToStoresFromOfferPage'> Verified
                                    </a>
                                </span>
                            </div>
                        </div>
                    </article>
                </li>
                <?php } ?>
                <?php } else { ?>
                <li class="offer1 col-md-12 col-lg-12 col-xs-12 col-sm-12">
                    <article class="store-coupons col-md-12 col-lg-12 col-xs-12 col-sm-12">
                        <div class="offer-percent-section coupon-section col-md-3 col-lg-3 col-sm-4 col-xs-12">
                            No offers found.
                        </div>
                    </article>
                </li>
                <?php } ?>

			</ul>
		        <div style="text-align:center;margin-top:20px;">
                    <button id="loadMore" class="btn btn-dark btn-md"><img src="https://couponclap.com/images/icon-image/loading.gif" style="width:10%"> Load More</button>
                </div>
		</section>
		<section class="offers-deals-section col-md-3 col-lg-3 col-xs-12 col-sm-3">
			<div class="mobile-container category-fix" id="mobile-container-id">
				<form method="POST" id="filterForm">
				<div>
					<article class="categories-container left-widget">
						<h3>Categories</h3>
						<div class="item-list-div">
    						<ul class="item-list search-list" id="cat-filters">
                                <?php
                                $storeids = intval($store['id']); // selected store
                                $cat_query = "
                                SELECT 
                                    c.id, 
                                    c.name,
                                    COUNT(p.id) AS total_posts
                                FROM categories c
                                LEFT JOIN posts p 
                                    ON p.category_id = c.id 
                                    AND p.stores_id = $storeids
                                    AND p.status = 'published' AND p.unpaused = '0'
                                WHERE FIND_IN_SET($storeids, c.stores_id)
                                GROUP BY c.id, c.name
                                ORDER BY c.name ASC
                                ";
                                
                                $result_cat = mysqli_query($con, $cat_query);
                                while($row = mysqli_fetch_assoc($result_cat)) {
                                    $checked = (!empty($category_filter) && in_array($row['id'], $category_filter)) 
                                                ? 'checked' 
                                                : '';
                                ?>
                                    <li class="category-item">
                                        <input type="checkbox" 
                                               class="list-check category-check"
                                               name="category[]"
                                               value="<?php echo $row['id']; ?>" 
                                               <?php echo $checked; ?>>
                                        <?php echo htmlspecialchars($row['name']); ?>
                                        <span>(<?php echo $row['total_posts']; ?>)</span>
                                    </li>
                                <?php } ?>
                            </ul>
						</div>
					</article>
					<article class="popular-store-cont left-widget">
				<h2>Popular Stores</h2>
				<ul class="row popular-stores">
					<!-- loop -->
					<?php
						$sql_s = "SELECT * FROM stores WHERE store_types = 'trending_stores' ORDER BY id DESC LIMIT 6";
						$res_s = mysqli_query($con, $sql_s);
						$i=1;
						while($row_s=mysqli_fetch_assoc($res_s)){
							$store_slug = strtolower(trim($row_s['store_name']));
							$store_slug = preg_replace('/[^a-z0-9]+/', '-', $store_slug);
							$store_slug = trim($store_slug, '-');
					?>
					<li class="pop-store-dtls col-xs-6 col-sm-6 col-md-6 col-lg-6">
						<a href="<?php echo $store_slug; ?>" target="_blank">
							<div class="pop-store-logo">
								<img src="https://couponclap.com/images/uploads/stores/<?php echo $row_s['store_image']; ?>"
									class="store-img" alt="<?php echo $row_s['store_name']; ?>">
							</div>
							<div class="pop-store-cb"><?php echo $row_s['store_name']; ?></div>
						</a>
					</li>
					<?php } ?>
				</ul>
			</article>
				</div> 
				<span class="mobile-filter-apply" id="go_apply_filter" data-type="cat">Apply </span>
				</form>
			</div>

			
			<article class="popular-store-cont left-widget">
				<h2>Similar Stores</h2>
				<ul class="row popular-stores">
					<!-- loop -->
					 <?php
						$sql_s = "SELECT * FROM stores WHERE store_types = 'top_stores' ORDER BY id DESC LIMIT 6";
						$res_s = mysqli_query($con, $sql_s);
						$i=1;
						while($row_s=mysqli_fetch_assoc($res_s)){
							$store_slug = strtolower(trim($row_s['store_name']));
							$store_slug = preg_replace('/[^a-z0-9]+/', '-', $store_slug);
							$store_slug = trim($store_slug, '-');
					?>
					<li class="pop-store-dtls col-xs-6 col-sm-6 col-md-6 col-lg-6">
						<a href="<?php echo $store_slug; ?>" target="_blank">
							<div class="pop-store-logo">
								<img src="https://couponclap.com/images/uploads/stores/<?php echo $row_s['store_image']; ?>"
									class="store-img" alt="<?php echo $row_s['store_name']; ?>">
							</div>
							<div class="pop-store-cb"><?php echo $row_s['store_name']; ?></div>
						</a>
					</li>
					<?php } ?>
				</ul>
			</article>
			<article class="store-about-container left-widget cont-mob-hide">
				<h2>About Reliance Digital</h2>
				<div class="store-about-div">Couponclap offers you the best prices on various products featured on
					Reliance Digital, Reliance Digital is an online shop which offers a wide range of electronics from
					Appliances to Mobiles and more.</div>
			</article>
		</section>
		<article class="filt-mob col-xs-12">
			<img class="filter-mob" src="https://couponclap.com/images/icon-image/filter.png">
		</article>
		<div class="mobile-overlay col-xs-12"></div>
	</div>

	<script>
		function applyFilters() {
			document.getElementById('filterForm').submit();
		}
		/* DESKTOP → Auto Submit */
		if (window.innerWidth > 768) {
			document.querySelectorAll('.category-check').forEach(function (checkbox) {
				checkbox.addEventListener('change', function () {
					applyFilters();
				});
			});
		}
		/* MOBILE → Apply Button */
		document.getElementById('go_apply_filter').addEventListener('click', function () {
			applyFilters();
		});
    </script>
    
    <script>
        let page = 1;
        $("#loadMore").on("click", function(){
            let btn = $(this);
            btn.text("Loading...");
            page++;
            $.ajax({
                url:"load-more-storedata.php",
                type:"POST",
                data:{
                    page:page,
                    category:"<?php echo implode(',', $category_filter); ?>",
                    storeids:"<?php echo $storeids; ?>"
                },
                success:function(data){
        
                    if($.trim(data) != ''){
                        $(".coupons-main-section-ul").append(data);
                        btn.text("Load More Offers");
                    }else{
                        btn.hide();
                    }
                }
            });
        });
    </script>
	<!-- footer code start -->
	<?php include('footer.php');?>
	<!-- footer code end -->
	<script src="https://couponclap.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
	<script src='https://couponclap.com/static/javascripts/store1-mina8e7.js?v=2024121802'></script>
	<!-- footer url link start code -->
	<?php include('footer_url.php');?>
	<!-- footer url link end code -->
	
	<?php } ?>