<section class="bg-primary-gradient py-4">
   <div class="container">
      <div class="row">
         <!--bottom-line Coupons Begin-->
         <div class="bottom-line">
            <h6 class="h5 mb-4">Coupons</h6>
         </div>
         <!--bottom-line Coupons End-->
      </div>
      <div class="row">
         <!--Coupons Deal of the Day-->
         <?php  
            $limit =20;  
            if (isset($_GET["page_coupon"])) { 
            $pn_c  = $_GET["page_coupon"]; 
            } 
            else { 
            $pn_c=1; 
            };  
            
            $start_from = ($pn_c-1) * $limit; 
            
            $sqlcou_coupon="SELECT * FROM coupon WHERE coupon_code !='' ORDER BY rand() LIMIT $start_from, $limit";
            $myquerycou_coupon=$conn->query($sqlcou_coupon);
            $mydaracou_coupon= $myquerycou_coupon->fetchAll()  ;
            
            $rows_foundcou_coupon = $myquerycou_coupon->rowCount();
            
              foreach( $mydaracou_coupon as $rowcoupon ){
               $rowId    = $rowcoupon["rowId"];
            $short_title   = $rowcoupon["short_title"];
            $full_title   = $rowcoupon["full_title"];
            $link = $rowcoupon["link"];
            $image   = $rowcoupon["image"];
            $exp_date = $rowcoupon["exp_date"];
            $coupon_code   = $rowcoupon["coupon_code"];
            $category   = $rowcoupon["category"];
            $company_name   = $rowcoupon["company_name"]; 
            $total_likes   = $rowcoupon["total_likes"]; 
            
            if($_SESSION[ADD_TAG.'_UserId_vendor']!=''){
            
            $user_id=$_SESSION[ADD_TAG.'_UserId_vendor'];
            /*for like master vendor*/
            $sqlli = "SELECT * FROM like_master WHERE coupan_id='$rowId ' AND user_id='$user_id' AND user_type='vendor' ";
            $myqueryli=$conn->query($sqlli); 
            $mydarali= $myqueryli->fetchAll()  ;
            
            $rows_foundli = $myqueryli->rowCount();
            
            if($rows_foundli=='0'){
            $like='<li class="like'.$rowId .'" ><a onclick="return cwRating('.$rowId .', 1,'.$rowId .');" title="I Like This"><i title="I Like This" class="fas fa-thumbs-up"></i>&nbsp;'.$total_likes.'</a></li>';
            
            }else{
            $like=' <li  class="like'.$rowId .'"><a onclick="return cwRating('.$rowId .', 0,'.$rowId .');" title="I Like This"><i class="fa fa-thumbs-up" title="I Like This"></i>
            &nbsp;'.$total_likes.'</a></li>';
            }
            /*for like master vendor */
            /*for fav master vendor*/
            $sqlfav = "SELECT * FROM fav_master WHERE coupan_id='$rowId ' AND user_id='$user_id' AND user_type='vendor' ";
            $myqueryfav=$conn->query($sqlfav); 
            $mydarafav= $myqueryfav->fetchAll()  ;
            
            $rows_foundfav = $myqueryfav->rowCount();
            
            if($rows_foundfav=='0'){
            $fav='<li class="fav'.$rowId .'"><a onclick="return fav('.$rowId .',1);" title="My Favourite"><i class="fas fa-heart"  ></i></a></li>';
            }else{
            $fav='  <li class="fav'.$rowId .'"><a onclick="return fav('.$rowId .',0);" title="My Favourite"><i class="fas fa-heart" ></i></a></li>';
            }
            /*for fav master vendor */
            
            }
            elseif($_SESSION[ADD_TAG.'_UserId_user']!=''){
            $user_id=$_SESSION[ADD_TAG.'_UserId_user'];
            /*for like master user*/
            $sqlli = "SELECT * FROM like_master WHERE coupan_id='$rowId ' AND user_id='$user_id' AND user_type='user'  ";
            $myqueryli=$conn->query($sqlli); 
            $mydarali= $myqueryli->fetchAll()  ;
            
            $rows_foundli = $myqueryli->rowCount();
            
            if($rows_foundli=='0'){
            $like='<li class="like'.$rowId .'"><a onclick="return cwRating('.$rowId .', 1,'.$rowId .');" title="I Like This"><i title="I Like This" class="fas fa-thumbs-up"></i>&nbsp;'.$total_likes.'</a></li>';
            // $like=' <li class="mr-0"  id="asd'.$rowId .'"><a onclick="return cwRating('.$rowId .', 1,'.$rowId .');" title="I Like This"><i class="fa fa-thumbs-o-up fa-1x text-success" aria-hidden="true" ></i>&nbsp;'.$total_likes.'</a></li>';
            }else{
            
            $like=' <li  class="like'.$rowId .'"><a onclick="return cwRating('.$rowId .', 0,'.$rowId .');" title="I Like This"><i class="fa fa-thumbs-up text-success" aria-hidden="true"></i>
            &nbsp;'.$total_likes.'</a></li>';
            }
            /*for like master user*/  
            /*for fav master user*/
            $sqlfav = "SELECT * FROM fav_master WHERE coupan_id='$rowId ' AND user_id='$user_id' AND user_type='user' ";
            $myqueryfav=$conn->query($sqlfav); 
            $mydarafav= $myqueryfav->fetchAll()  ;
            
            $rows_foundfav = $myqueryfav->rowCount();
            
            if($rows_foundfav=='0'){
            $fav='<li class="fav'.$rowId .'"><a onclick="return fav('.$rowId .',1);" title="My Favourite"><i class="fas fa-heart" ></i></a></li>';
            }else{
            $fav='  <li class="fav'.$rowId .'"><a onclick="return fav('.$rowId .',0);" title="My Favourite"><i class="fa fa-heart fa-1x text-danger"></i></a></li>';
            }
            /*for fav master user */
            
            }else{
            
            $like='  <li data-bs-toggle="modal" data-bs-target="#like-product"><i title="I Like This" class="fas fa-thumbs-up"></i>'.$total_likes.'</li>';
            $fav=' <li data-bs-toggle="modal" data-bs-target="#favorite-product"><i title="My Favourite" class="fas fa-heart"></i></li>';
            }
            
            
            
            
            ?>
            <!--deals-coupons Begin-->
         <div class="col-lg-3 col-6">
            <div class="deals-coupons">
               <div class="card border-0">
                  <a  href="./redeem-id/<?=($rowId)?>">
                     <div class="card-body deal-of-day">
                        <?php     if (!filter_var($image, FILTER_VALIDATE_URL) === false) { ?>
                  <a class="text-decoration-none" href="redeem-id/<?=($rowId)?>">
                  <img title="<?=$company_name?>"  alt="<?=$company_name?>" src="<?=$image?>" class="img-fluid rounded-3" alt="..."></a>
                  <?php  } else { ?>
                  <a class="text-decoration-none" href="redeem-id/<?=($rowId)?>">
                  <!-- <img src="images/merchant/myntra-logo.jpg" alt="Avatar" class="w-100 img-fluid store-overlay"> -->
                  <span title="<?=$company_name ?>" class="p-store text-truncate"><?=$company_name ?></span>
                  </a>
                  <?php } ?>
                  <div class="d-grid">
                  <p title=" <?=$short_title ?>" class="text-truncate p-dcoupons">
                  <?=$short_title ?> 
                  </p>
                  <small class="text-muted text-truncate"><i class="far fa-clock"></i> Expires on <?=$exp_date ?></small>
                  </div>
                  <div class="row align-items-center ">
                  <div class="col-md-6 py-3">
                  <h6 class="fw-bold text-truncate text-uppercase get-code-border">
                  Get Code
                  </h6>
                  </div>
                  <div class="col-md-6 py-3">
                  <h6 class="active-offer">  <a class="text-decoration-none" href="redeem-id/<?=($rowId)?>">Active Offer</a></h6>
                  </div>
                  <div class="col-md-12">
                  <h6 class="fs-11 fw-light text-muted text-truncate"><i class="fas fa-users"></i> <?php echo(rand(10,100));?> People Used Today</h6>
                  </div>
                  </div>
                  </div>
                  </a>
                  <div class="card-footer social-icons bg-white">
                     <ul class="list-unstyled mb-0">
                        <li data-bs-toggle="modal" data-bs-target="#like-coupon">
                           <?=$fav?>
                        </li>
                        <li data-bs-toggle="modal" data-bs-target="#like-coupon">
                           <?=$like?>
                        </li>
                        <li  data-bs-toggle="modal" data-bs-target="#share-coupon<?=urlencode($rowId)?>"><i title="Share" class="fas fa-share pe-1"></i>Share</li>
                     </ul>
                  </div>
               </div>
            </div>
         </div>
          <!--deals-coupons End-->
         <!-- coupon share modal Begin-->
         <div class="modal fade" id="share-coupon<?=urlencode($rowId)?>" tabindex="-1"  aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered modal-lg">
               <div class="modal-content">
                  <div class="modal-header border-0">
                     <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                  </div>
                  <div class="modal-body p-5">
                     <div id="removemodalproductdealoftheday">
                        <div class="row justify-content-center align-items-center">
                           <div class="col-md-5">
                              <div class="d-modal-left">
                                 <?php 
                                    if (filter_var($image, FILTER_VALIDATE_URL)) {
                                    echo('<img src="'.$image.'"  alt="'.$company_name.'" title="'.$company_name.'" class="img-fluid mx-auto d-block">');
                                    } else { ?>
                                 <div   title="<?=$image?>"  >
                                    <div class="text-center bg-secondary p-4" >
                                       <h5 class="text-white text-truncate"><?=$image?></h5>
                                    </div>
                                 </div>
                                 <?php  }
                                    ?>
                              </div>
                           </div>
                           <div class="col-md-7">
                              <div class="dm-price">
                                 <h3 class="fw-bold text-truncate mb-3"><?=$short_title?></h3>
                                 <!--Copy url Begin-->
                                 <div class="mb-3 row">
                                    <label class="col-sm-4 col-form-label">Copy url</label>
                                    <div class="col-sm-8">
                                       <!--copy to copyclipboardproductdealoftheday Begin-->
                                       <div class="input-group clipboarddealoftheday">
                                       <input  class="form-control form-control-sm" value="<?php echo $link; ?>" id="<?=$rowId?>">
                                          <span class="input-group-text bg-secondary text-white" onclick="copy(<?=$rowId?>)"><i class="far fa-copy"></i></span>
                                       </div>
                                       <div id="copiedtextproductdealsday" class="copieddealoftheday">
                                          <span>Copied!</span>
                                       </div>
                                       <!--copy to copyclipboardproductdealoftheday End-->
                                    </div>
                                 </div>
                                 <!--Share Via Begin-->
                                 <div class="mb-3 row">
                                    <label class="col-sm-4 col-form-label">Share via</label>
                                    <div class="col-sm-8">
                                       <!--share Via Begin-->
                                       <div class="d-flex justify-content-start align-items-center">
                                          <a title="share via linkedin" href="https://www.linkedin.com/sharing/share-offsite/?url=<?=$link?>" class="share-linkedin ms-2"><i class="fab fa-linkedin-in"></i></a>
                                          <a title="share via facebook" href="https://www.facebook.com/sharer.php?u=<?=$link?>" class="share-facebook ms-2"><i class="fab fa-facebook-f"></i></a>
                                          <a title="share via twitter" href="https://twitter.com/intent/tweet?url=<?=$link?>" class="share-twitter ms-2"><i class="fab fa-twitter"></i></a>
                                          <a title="share via pinterest" href="https://www.pinterest.com/pin/create/button/?url=<?=$link?>" class="share-pinterest ms-2"><i class="fab fa-pinterest-p"></i></a>
                                          <a title="share via whatsapp" href="https://web.whatsapp.com/send?text=<?=$link?>" class="share-whatsapp ms-2"><i class="fab fa-whatsapp"></i></a>
                                          <a title="share via telegram" href="https://t.me/share/url?url=<?=$link?>&text=telegram" class="share-telegram ms-2"><i class="fab fa-telegram"></i></a>
                                          <a title="share via reddit" href="http://www.reddit.com/submit?url=<?=$link?>" class="share-reddit ms-2"><i class="fab fa-reddit"></i></a>
                                          <a title="share via tumblr" href="http://www.tumblr.com/share?v=3&u=<?=$link?>&t=tumblr" class="share-tumblr ms-2"><i class="fab fa-tumblr"></i></a>
                                       </div>
                                       <!--share Via End-->
                                    </div>
                                 </div>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
         </div>
        <!-- coupon share modal End-->
         <?php } ?>
         <div class="col-lg-12">
            <!--Nav Paginations Begin-->
            <nav aria-label="Page navigation example">
               <ul class="pagination justify-content-center pt-4 pb-4">
                  <?php   
                     $sqlpa= "SELECT COUNT(*) FROM coupon WHERE coupon_code !=''"; 
                     
                     
                     
                     
                     $myquerypa=$conn->query($sqlpa);
                     $row = $myquerypa->fetch(PDO::FETCH_BOTH);
                     // do loop stuff
                     
                     
                     $rows_foundpa = $myquerypa->rowCount();   
                     $total_records = $row[0];  
                     
                     //echo $rows_foundpa;
                     if($total_records > 20){
                     $total_pages = ceil($total_records / $limit);
                     
                     $k = (($pn_c+1>$total_pages)?$total_pages-1:(($pn_c-1<1)?2:$pn_c));   
                     
                     $pagLink = "";
                     if($pn_c>=2){
                     echo "<li class='page-item'><a class='page-link' href='coupon-page/1".$sr."'> << </a></li>";
                     echo "<li class='page-item'><a class='page-link' href='coupon-page/".($pn_c-1).$sr." '> < </a></li>";
                     }
                     for ($i=-1; $i<=1; $i++) {
                     if($total_pages>=$k+$i && $k+$i!='0' ){
                     if($k+$i==$pn_c){
                     $pagLink .= "<li class='page-item active'><a class='page-link' href='coupon-page/".($k+$i).$sr." ' >".($k+$i)."</a></li>";
                     }
                     else{
                     $pagLink .= "<li class='page-item'><a class='page-link' href='coupon-page/".($k+$i).$sr." '>".($k+$i)."</a></li>";  
                     } }
                     };  
                     echo $pagLink;
                     if($pn_c<$total_pages){
                     echo "<li class='page-item'><a class='page-link' href='coupon-page/".($pn_c+1).$sr." '> > </a></li>";
                     echo "<li class='page-item'><a class='page-link' href='coupon-page/".$total_pages.$sr." '> >> </a></li>";
                     }  }  ?> 
               </ul>
            </nav>
            <!--Nav Paginations End-->
         </div>
      </div>
   </div>
</section>