<?php session_start();
   require_once("./config/config.php");
   $search = ($_REQUEST['bar']);
   $search2 = ($_REQUEST['merchantdata']);
   echo $search2;
   $search = str_replace("-"," ","$search");
   $search = ucwords($search);
   $sql_tag = "SELECT * FROM meta_tag_setting WHERE pages = 'search'";
   $mydara_sql = $conn->query($sql_tag);
   $fetch_tag = $mydara_sql->fetchAll();
   $rows_tag =$mydara_sql->rowCount();
   
   if($rows_tag !=0 ){
      foreach( $fetch_tag  as $rowcon ) {
         $title = $rowcon['title'];
         $description  = $rowcon['description'];
         $keyword = $rowcon['keyword'];
      }
   }
   
   $limit =16;  
       if (isset($_GET["page"])) { 
         $pn  = $_GET["page"]; 
       } 
       else { 
         $pn=1; 
       };  
     
   $start_from = ($pn-1) * $limit;  
   if( $search2!=""){
      $sqlcou="SELECT * FROM product_master WHERE created_by=$search2 LIMIT $start_from, $limit";
      $myquerycou=$conn->query($sqlcou);
      //var_dump($myquerycou);
      $mydaracou= $myquerycou->fetchAll()  ;
      $rows_foundcou = $myquerycou->rowCount();
       if($rows_foundcou=='0'){
              $status='active';
              }

  
   
         }else{
            $sqlcou="SELECT * FROM product_master WHERE title LIKE '%$search%' OR discription LIKE '%$search%' OR category LIKE '%$search%' LIMIT $start_from, $limit";
            $myquerycou=$conn->query($sqlcou);
            //var_dump($myquerycou);
            $mydaracou= $myquerycou->fetchAll()  ;
            $rows_foundcou = $myquerycou->rowCount();
             if($rows_foundcou=='0'){
                    $status='active';
                    }
         }

// This is a code for php minifiers Begin

ob_start("minifier");
function minifier($code) {
    $search = array(
         
        // Remove whitespaces after tags
        '/\>[^\S ]+/s',
         
        // Remove whitespaces before tags
        '/[^\S ]+\</s',
         
        // Remove multiple whitespace sequences
        '/(\s)+/s',
         
        // Removes comments
        '/<!--(.|\s)*?-->/'
    );
    $replace = array('>', '<', '\\1');
    $code = preg_replace($search, $replace, $code);
    return $code;
}

// This is a code for php minifiers End
      
      ?>
<!DOCTYPE html>
<html lang="en">
   <head>
      <!-- Character set configuration -->
      <base href="<?=$base_link?>" target="_self">
      <meta charset="UTF-8" />
      <title><?=$title?></title>
      <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <link id="favicon" rel="icon" type="image/x-icon" href="images/web-images/home/favicon.png"/>
      <meta name="robots" content="index, follow" />
      <link rel="canonical" href="search.php"/>
      <meta name="description" content="<?=$description?>">
      <meta name="keywords" content="<?=$keyword?>">
      <!-- Viewport configuration, scaling options -->
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>

      <!-- CSS Stylesheet -->
      <link href="css/icouponworld.css" rel="stylesheet" />
      <!-- Font Awesome icon -->
      <link href="fontawesome/css/fontawesome.css" rel="stylesheet" />
      <!-- Google Analytics Code Begin-->
      <?=$google_ana ?>
      <!-- Google Analytics Code End-->
      <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
      <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
      <![endif]-->
   </head>
   <body>
         <!-- Preloader Begin-->
         <div class="preloader">
         <div class="loading">
           <img src="images/web-images/home/loader.gif" alt="loader" title="loader" class="mx-auto d-flex"> 
            <h2 class="text-center fw-light">loading...</h2>
         </div>
      </div>
      <!-- Preloader End-->
      <!--Header Begin-->
      <?php include("./includefiles/header.php"); ?>
      <!--Header End-->
      <!--Overlay Begin-->
      <div id="overlay"></div>
      <!--Overlay End-->
      <!--Deal of the Day Begin-->
      <section class="bg-primary-gradient gap-top">
         <div class="container">
            <ul class="nav nav-pills product-coupons-tab mt-5 justify-content-center align-items-center" id="pills-tab" role="tablist">
               <li class="nav-item" role="presentation">
                  <button class="nav-link <?php  if (isset($_GET["page"])) { echo 'active'; }else{ if (empty($_GET["page_coupon"])){ echo 'active'; } } ?>" id="pills-product-dealoftheday-tab" data-bs-toggle="pill" data-bs-target="#pills-product-dealoftheday" type="button" role="tab" aria-controls="pills-product-dealoftheday" aria-selected="true"><i class="fas fa-store pe-2"></i> Product</button>
               </li>
               <li class="nav-item" role="presentation">
                  <button class="nav-link <?php  if (isset($_GET["page_coupon"])) { echo 'active'; } ?>" id="pills-coupons-dealoftheday-tab" data-bs-toggle="pill" data-bs-target="#pills-coupons-dealoftheday" type="button" role="tab" aria-controls="pills-coupons-dealoftheday" aria-selected="false"><i class="fas fa-tags pe-2"></i> Coupons</button>
               </li>
            </ul>
            <div class="tab-content" id="pills-tabContent">
               <!--pills product dealoftheday Begin-->
               <div class="tab-pane fade <?php  if (isset($_GET["page"])) { echo 'show active'; }else{ if(empty($_GET["page_coupon"])){ echo 'show active'; } } ?>" id="pills-product-dealoftheday" role="tabpanel" aria-labelledby="pills-product-dealoftheday-tab" tabindex="0">
                  <div class="row pt-3">
                     <!--Product Deal of the Day-->
                     <?php  
                        foreach( $mydaracou as $rowcou ){
                        $rowId    = $rowcou["rowId"];
                        $short_title   = $rowcou["title"];
                        $discription   = $rowcou["discription"];
                        $link = $rowcou["product_url"];
                        $product_image   = $rowcou["product_image"];
                        $type = $rowcou["exp_date"];
                        $coupon_code   = $rowcou["country_name"];
                        $company_name   = $rowcou["company_name"];
                        $amount   = $rowcou["amount"]; 
                        $currency    = $rowcou["currency"]; 
                        $total_likes   = $rowcou["total_likes"];
                        
                        
                        if($_SESSION[ADD_TAG.'_UserId_vendor']!=''){
                        
                        $user_id=$_SESSION[ADD_TAG.'_UserId_vendor'];
                        /*for like master vendor*/
                        $sqlli = "SELECT * FROM like_master_product 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_product('.$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_product('.$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_product 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_product('.$rowId.',1);" title="My Favourite"><i class="fas fa-heart"  ></i></a></li>';
                        }else{
                        $fav='  <li class="fav'.$rowId.'"><a onclick="return fav_product('.$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_product 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_product('.$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_product('.$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 user*/  
                         /*for fav master user*/
                        $sqlfav = "SELECT * FROM fav_master_product 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_product('.$rowId.',1);" title="My Favourite"><i class="fas fa-heart" ></i></a></li>';
                        }else{
                        $fav='  <li class="fav'.$rowId.'"><a onclick="return fav_product('.$rowId.',0);" title="My Favourite"><i class="fas fa-heart"></i></a></li>';
                        }
                        /*for fav master user */
                        
                        }else{
                        
                        $like='  <li data-bs-toggle="modal" data-bs-target="#like-coupon"><i title="I Like This" class="fas fa-thumbs-up">&nbsp;'.$total_likes.'</i></li> ';
                         $fav=' <li data-bs-toggle="modal" data-bs-target="#favorite-coupon"><i title="My Favourite" class="fas fa-heart"> </i></li>';
                        }
                        
                        
                        
                        
                        
                        
                        ?> 
                     <div class="col-lg-3 col-6">
                        <div class="deals">
                           <div class="card border-0">
                              <div class="card-body">
                                 <img alt="<?=$short_title?>" title=" <?=$short_title?>" src="<?=$product_image?>" alt="deal" title="deal" class="img-fluid mx-auto d-block">
                                 <div class="d-grid">
                                    <small title="<?=$short_title?>" class="context-menu text-muted text-truncate"><?=$short_title?></small>
                                    <p class="d-para">
                                       <a class="context-menu" title="<?=$discription?>"><?=$discription?></a> 
                                    </p>
                                 </div>
                                 <div class="row align-items-center">
                                    <div class="col-md-7">
                                       <h3 class="mb-2 fw-bold text-truncate">
                                       <?=$currency?>   <?=$amount?>
                                       </h3>
                                    </div>
                                    <div class="col-md-5 text-end">
                                       <h6 class="shop-now"><a target="_blank" href="<?=$link?>">Shop Now</a></h6>
                                    </div>
                                 </div>
                              </div>
                              <div class="card-footer social-icons bg-white">
                                 <ul class="list-unstyled mb-0">
                                    <?=$fav ?>
                                    <?=$like?>
                                    <li  data-bs-toggle="modal" data-bs-target="#share-product<?=$rowId?>"><i title="Share" class="fas fa-share pe-1"></i>Share</li>
                                 </ul>
                              </div>
                           </div>
                        </div>
                     </div>
                     <!--Product Deal of the Day-->
                     <div class="modal fade" id="share-product<?=$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">
                                             <img alt="<?=$short_title?>" title=" <?=$short_title?>" src="<?=$product_image?>" alt="deal" title="deal" class="img-fluid mx-auto d-block">
                                          </div>
                                       </div>
                                       <div class="col-md-7">
                                          <div class="dm-price">
                                             <h3 title="<?=$short_title?>" class="fw-bold text-truncate"><?=$short_title?></h3>
                                             <a href="product-details./<?=($rowId)?>" class="btn btn-view-deal w-100 d-block mt-2 mb-4">View Product Deal</a>
                                             <!--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="copyproduct(<?=$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>
                     <?php } ?>
                     <div class="col-lg-12">
                        <!-- Paginations-->
                        <nav aria-label="Page navigation example">
                           <ul class="pagination justify-content-center pt-4 pb-4">
                              <?php   
                                 $sqlpa= "SELECT COUNT(*) FROM product_master"; 
                                 
                                 
                                 
                                 
                                 $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 > 16){
                                 $total_pages = ceil($total_records / $limit);
                                 
                                 $k = (($pn+1>$total_pages)?$total_pages-1:(($pn-1<1)?2:$pn));   
                                 
                                 $pagLink = "";
                                 if($pn>=2){
                                 echo "<li class='page-item'><a class='page-link' href='search-page/1".$sr."'> << </a></li>";
                                 echo "<li class='page-item'><a class='page-link' href='search-page/".($pn-1).$sr." '> < </a></li>";
                                 }
                                 for ($i=-1; $i<=1; $i++) {
                                 if($total_pages>=$k+$i && $k+$i!='0' ){
                                 if($k+$i==$pn){
                                 $pagLink .= "<li class='page-item active'><a class='page-link' href='search-page/".($k+$i).$sr." ' >".($k+$i)."</a></li>";
                                 }
                                 else{
                                 $pagLink .= "<li class='page-item'><a class='page-link' href='search-page/".($k+$i).$sr." '>".($k+$i)."</a></li>";  
                                 } }
                                 };  
                                 echo $pagLink;
                                 if($pn<$total_pages){
                                 echo "<li class='page-item'><a class='page-link' href='search-page/".($pn+1).$sr." '> > </a></li>";
                                 echo "<li class='page-item'><a class='page-link' href='search-page/".$total_pages.$sr." '> >> </a></li>";
                                 }  }  ?> 
                           </ul>
                        </nav>
                     </div>
                  </div>
               </div>
               <!--pills product dealoftheday End-->
               <!--pills coupons dealoftheday Begin-->
               <div class="tab-pane fade <?php  if (isset($_GET["page_coupon"])) { echo 'show active'; } ?>" id="pills-coupons-dealoftheday" role="tabpanel" aria-labelledby="pills-coupons-dealoftheday-tab" tabindex="0">
                  <div class="row pt-3">
                     <?php  
                        $limit =16;  
                        if (isset($_GET["page_coupon"])) { 
                        $pn_c  = $_GET["page_coupon"]; 
                        } 
                        else { 
                        $pn_c=1; 
                        };  
                        
                        $start_from = ($pn_c-1) * $limit; 
                        if($search2!=""){
                           $sqlcou_coupon="SELECT * FROM coupon WHERE created_by = $search2 LIMIT $start_from, $limit";
                           $myquerycou_coupon=$conn->query($sqlcou_coupon);
                           $mydaracou_coupon= $myquerycou_coupon->fetchAll()  ;
                           
                           $rows_foundcou_coupon = $myquerycou_coupon->rowCount();

                        
                        }else{
                           $sqlcou_coupon="SELECT * FROM coupon WHERE coupon_code !='' AND short_title LIKE '%$search%' OR full_title LIKE '%$search%' OR category LIKE '%$search%' 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   = $rowcou["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>';
                        }
                        
                        
                        
                        ?>
                     <!--Coupons Deal of the Day-->
                     <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 ?>" src="<?=$image?>" class="img-fluid rounded-3" alt="<?=$company_name ?>"></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">
                              <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>
                     <!-- coupon share modal -->
                     <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="<?=$company_name?>"  >
                                                <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 title="<?=$short_title?>" 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="coupon(<?=$rowId?>)"><i class="far fa-copy"></i></span>
                                                   </div>
                                                   <div id="copiedtextproductdealsday" class="copieddealoftheday">
                                                      <span>Copied!</span>
                                                   </div>
                                                   <!--copy to copyclipboardproductdealoftheday End-->
                                                </div>
                                             </div>
                                             <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 -->
                     <!--Coupons Deal of the Day-->
                     <?php } ?>
                     <div class="col-lg-12">
                        <!-- Paginations-->
                        <nav aria-label="Page navigation example">
                           <ul class="pagination justify-content-center pt-4 pb-4">
                              <?php   
                                 $sqlpa= "SELECT COUNT(*) FROM coupon"; 
                                 
                                 
                                 
                                 
                                 $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 > 16){
                                 $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='search-cou-page/1".$sr."'> << </a></li>";
                                 echo "<li class='page-item'><a class='page-link' href='search-cou-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='search-cou-page/".($k+$i).$sr." ' >".($k+$i)."</a></li>";
                                 }
                                 else{
                                 $pagLink .= "<li class='page-item'><a class='page-link' href='search-cou-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='search-cou-page/=".($pn_c+1).$sr." '> > </a></li>";
                                 echo "<li class='page-item'><a class='page-link' href='search-cou-page/".$total_pages.$sr." '> >> </a></li>";
                                 }  }  ?> 
                           </ul>
                        </nav>
                     </div>
                  </div>
               </div>
               <!--pills coupons dealoftheday End-->
            </div>
         </div>
      </section>
     
      <!--like Product Modal -->
      <div class="modal fade" id="like-product" tabindex="-1" aria-labelledby="likeproductLabel" aria-hidden="true">
         <div class="modal-dialog modal-dialog-centered">
            <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">
                  <div class="mx-auto d-block text-center">
                     <h6 class="likethead">Please <a href="#">Sign in </a><strong> for like</strong></h6>
                     <img src="images/web-images/home/like.png" alt="like" title="like" width="50" class="img-fluid">
                  </div>
               </div>
               <div class="modal-footer bg-transparent">
                  <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
               </div>
            </div>
         </div>
      </div>
      <!--favourate  Product Modal -->
      <div class="modal fade" id="favorite-product" tabindex="-1" aria-labelledby="favoriteproductLabel" aria-hidden="true">
         <div class="modal-dialog modal-dialog-centered">
            <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">
                  <div class="mx-auto d-block text-center">
                     <h6 class="likethead">Please <a href="#">Sign in </a><strong> for favorite</strong></h6>
                     <img src="images/web-images/home/favorite.png" alt="favorite" title="favorite" width="50" class="img-fluid">
                  </div>
               </div>
               <div class="modal-footer bg-transparent">
                  <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
               </div>
            </div>
         </div>
      </div>
      <!--share-coupon Modal -->
      <!--like coupon Modal -->
      <div class="modal fade" id="like-coupon" tabindex="-1" aria-labelledby="likecouponLabel" aria-hidden="true">
         <div class="modal-dialog modal-dialog-centered">
            <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">
                  <div class="mx-auto d-block text-center">
                     <h6 class="likethead">Please <a href="#">Sign in </a><strong> for like</strong></h6>
                     <img src="images/web-images/home/like.png" alt="like" title="like" width="50" class="img-fluid">
                  </div>
               </div>
               <div class="modal-footer bg-transparent">
                  <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
               </div>
            </div>
         </div>
      </div>
      <!--favourate coupon Modal -->
      <div class="modal fade" id="favorite-coupon" tabindex="-1" aria-labelledby="favoritecouponLabel" aria-hidden="true">
         <div class="modal-dialog modal-dialog-centered">
            <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">
                  <div class="mx-auto d-block text-center">
                     <h6 class="likethead">Please <a href="#">Sign in </a><strong> for favorite</strong></h6>
                     <img src="images/web-images/home/favorite.png" alt="favorite" title="favorite" width="50" class="img-fluid">
                  </div>
               </div>
               <div class="modal-footer bg-transparent">
                  <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
               </div>
            </div>
         </div>
      </div>
      <!--Deal of the Day End-->
      <!--Text Section Begin-->
      <section class="py-5">
         <div class="container">
            <div class="row">
               <div class="mb-4">
                  <h6 class="mb-3 fw-bold">Today’s Deals That Will Make You Smile</h6>
                  <p>Shopping on your mind? So why not get the best deals on time? Be it any day or any time of the week, the best deals on the internet will leave you gaga over it. Shopping online is simple and fun, and here we are, to spread smiles with nothing but the best deals online. You name it, we have it - from fashion to foot wear, electronics to home and kitchen appliances, and more and more. What are the best deals today? We’ve got a list of all the top and exclusive deals for you to pick from a wide range of products like electronics, laptops, mobile phones, smart gadgets, TVs, sarees, stylish tops for men, women, kids, etc, etc, etc… And our list goes on and on. Get the best deals at unbelievable prices from the best shopping sites like Amazon, Myntra, Flipkart, Tata Cliq and many more. We’ve got some amazing discounts of up to 80% to help you Save On Everything. What are you waiting for? Fill in your shopping list now.</p>
               </div>
               <div class="col-md-12">
                  <?php    if(!empty($google_adar )){
                     echo $google_adar ;
                     }else{
                     echo ' <img src="admin/forms/'.$adimg4.'" alt="Horizontal Banner" title="Horizontal Banner" class="img-fluid w-100 rounded-3 mt-4 mb-4">';
                     } ?>
               </div>
            </div>
         </div>
      </section>
      <!--Text Section End-->
      <!--For more saving  subscribe now Begin-->
      <section class="bg-primary-gradient py-5">
         <div class="container">
            <div class="row justify-content-center align-items-center g-5">
               <div class="col-md-6">
                  <div class="row">
                     <div class="col-lg-8">
                        <script charset="utf-8" type="text/javascript" src="https://js.hsforms.net/forms/embed/v2.js"></script>
                        <script>
                           hbspt.forms.create({
                              region: "na1",
                              portalId: "22164858",
                              formId: "37091fc7-7595-4ab4-99c2-33d1791e3ba9"
                           });
                        </script>
                     </div>
                     <div class="col-lg-4">
                        <img src="images/web-images/home/subscribe-img.png" alt="subscribe" titlt="subscribe" class="img-fluid">
                     </div>
                  </div>
               </div>
               <div class="col-md-5 ms-auto">
                  <div class="subscriber-now">
                     <div class="d-flex align-items-center mb-4">
                        <div class="flex-shrink-0">
                           <div class="imgwrap">
                              <svg width="30px" height="30px" viewBox="0 0 30 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
                                 <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                                    <g id="Gift-Card-Home-Page-Copy" transform="translate(-216.000000, -4906.000000)" fill="#FFFFFF" fill-rule="nonzero">
                                       <g id="Group-7" transform="translate(196.000000, 4887.000000)">
                                          <path d="M37.4012,21.0050571 L32.5991,21.0050571 L35,19 L37.4012,21.0050571 Z M32.1182,40.9952463 L24.8543,35.1202589 L24.8543,22.0145646 L45.1454,22.0145646 L45.1454,35.1202589 L37.8815,40.9952463 L35,39.1467584 L32.1182,40.9952463 Z M28.2554,27.1855972 L42.1982,27.1855972 L42.1982,26.1248104 L28.2554,26.1248104 L28.2554,27.1855972 Z M28.2554,30.3081825 L42.1982,30.3081825 L42.1982,29.2473956 L28.2554,29.2473956 L28.2554,30.3081825 Z M28.2554,33.4310711 L42.1982,33.4310711 L42.1982,32.3702842 L28.2554,32.3702842 L28.2554,33.4310711 Z M23.8562,28.0758572 L20,31.1944978 L23.8562,34.3131385 L23.8562,28.0758572 Z M20.0273,32.5092546 L20.0273,48.7499747 L31.2269,41.566906 L20.0273,32.5092546 Z M21.5018,49 L48.4982,49 L35,40.3422676 L21.5018,49 Z M49.9727,48.7499747 L49.9727,32.5092546 L38.7731,41.566906 L49.9727,48.7499747 Z M46.1438,28.0758572 L46.1438,34.3131385 L50,31.1944978 L46.1438,28.0758572 Z" id="Shape"></path>
                                       </g>
                                    </g>
                                 </g>
                              </svg>
                           </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                           <p class="fst-italic">For More Savings </p>
                           <h1 class="h5 fw-bold fst-italic pb-2">Subscribe Now</h1>
                           <p class="fs-12 ">We Take Care of Your Savings Subscribe now and save on everything with the latest Coupons & Discount offers. </p>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </section>
      <!--For more saving subscribe now End-->
      <!--footer Section Begin-->
      <?php include("./includefiles/footer.php"); ?>
      <!--footer Section End-->
      <!--scroll to top Begin-->
      <button onclick="topFunction()" id="gobackToTop" title="Go To Top"><i class="fas fa-angle-up"></i></button>
      <!--scroll to top end-->
      <!-- jquery-3.4.1.min js Begin -->
      <script src="js/jquery-3.4.1.min.js"></script>
      <!-- jquery-3.4.1.min js End -->
      <!-- bootstrap.bundle.min js Begin-->
      <script src="js/bootstrap.bundle.min.js"></script>
      <!-- bootstrap.bundle.min js End-->
      <!-- icouponworld js Begin-->
      <script src="js/icouponworld.js"></script>
      <!-- icouponworld js End-->
      <!-- sweetalert.min.js Begin-->
      <script src="js/sweetalert.min.js"></script>
      <!-- sweetalert.min.js End--> 
      <!--script for googleTranslateElementInit Begin-->
      <!-- <script>
         function googleTranslateElementInit() {
  new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
      </script> -->
      <!--script for googleTranslateElementInit End-->
      <!--script for googleTranslate Begin-->
      <!-- <script src="js/googletranslate.js"></script> -->
      <!--script for googleTranslate End-->
      <!-- like_dislike_product Script Begin-->
      <script type="text/javascript">  
         function cwRating_product(id,type,target){
         $.ajax({
           type:'POST',
           url:'forms/like_dislike_product.php',
           data:'id='+id+'&type='+type,
           success:function(msg){
               if(msg == 'err'){
                   alert('Some problem occured, please try again.');
               }else{
                   $('.like'+target).html(msg);
                   swal({
         title: "Hurray!",
         text: "Your liking was just saved.",
         imageUrl: 'thumbs-up.jpg'
         });
               }
           }
         });
         }
      </script>
      <!-- like_dislike_product Script End-->
      <!-- fav_master_product Script Begin-->
      <script type="text/javascript">  
         function fav_product(id,type){
         $.ajax({
           type:'POST',
           url:'forms/fav_master_product.php',
           data:'id='+id+'&type='+type,
           success:function(msg){
               if(msg == 'err'){
                   alert('Some problem occured, please try again.');
               }else{
                   $('.fav'+id).html(msg);
                   swal({
         title: "Yay!",
         text: "We just saved your favourite.",
         imageUrl: 'thumbs-up.jpg'
         });
               }
           }
         });
         }
      </script> 
      <!-- fav_master_product Script End-->
      <!-- like_dislike Script Begin-->
      <script type="text/javascript">  
         function cwRating(id,type,target){
         $.ajax({
           type:'POST',
           url:'forms/like_dislike.php',
           data:'id='+id+'&type='+type,
           success:function(msg){
               if(msg == 'err'){
                   alert('Some problem occured, please try again.');
               }else{
                   $('.like'+target).html(msg);
                   swal({
         title: "Hurray!",
         text: "Your liking was just saved.",
         imageUrl: 'thumbs-up.jpg'
         });
               }
           }
         });
         }
      </script>
      <!-- like_dislike Script End-->
      <!-- fav_master Script Begin-->
      <script type="text/javascript">  
         function fav(id,type){
         $.ajax({
           type:'POST',
           url:'forms/fav_master.php',
           data:'id='+id+'&type='+type,
           success:function(msg){
               if(msg == 'err'){
                   alert('Some problem occured, please try again.');
               }else{
                   $('.fav'+id).html(msg);
                   swal({
         title: "Yay!",
         text: "We just saved your favourite.",
         imageUrl: 'thumbs-up.jpg'
         });
               }
           }
         });
         }
      </script>
      <!-- fav_master Script End-->
       <!-- Script for copy coupon Begin -->
      <script>
    function coupon(inputId) {
        /* Get the text field */

        // Changed to get the Element by the parameter containing the ElementID
        var couponText = document.getElementById(inputId);

        /* Select the text field */
        couponText.select();
        couponText.setSelectionRange(0, 99999); /* For mobile devices */

        /* Copy the text inside the text field */
        navigator.clipboard.writeText(couponText.value);

        /* Alert the copied text */
        alert("Copied the text: " + couponText.value);
    }
</script>
 <!-- Script for copy coupon End -->
 <!-- Script for copy copyproduct Begin -->
<script>
    function copyproduct(inputId) {
        /* Get the text field */

        // Changed to get the Element by the parameter containing the ElementID
        var copyproductText = document.getElementById(inputId);

        /* Select the text field */
        copyproductText.select();
        copyproductText.setSelectionRange(0, 99999); /* For mobile devices */

        /* Copy the text inside the text field */
        navigator.clipboard.writeText(copyproductText.value);

        /* Alert the copied text */
        alert("Copied the text: " + copyproductText.value);
    }
</script>
<!-- Script for copy copyproduct End -->
   </body>
</html>
<?php
ob_end_flush();  // This is a code for php minifiers
?>