<?php require('header.php');?>
<?php

if(isset($arr_cart_p_id2)){$arr_cart_p_id2=$arr_cart_p_id2;}else{$arr_cart_p_id2=0;}
if(isset($arr_cart_size_id2)){$arr_cart_size_id2=$arr_cart_size_id2;}else{$arr_cart_size_id2=0;}

$f=0;


   $statement = $pdo->prepare("SELECT * FROM tbl_settings WHERE id=1");
   $statement->execute();
   $result = $statement->fetchAll(PDO::FETCH_ASSOC);
   foreach ($result as $row)
   {
       $cta_title = $row['cta_title'];
       $cta_content = $row['cta_content'];
       $cta_read_more_text = $row['cta_read_more_text'];
       $cta_read_more_url = $row['cta_read_more_url'];
       $cta_photo = $row['cta_photo'];
       $featured_product_title = $row['featured_product_title'];
       $featured_product_subtitle = $row['featured_product_subtitle'];
       $latest_product_title = $row['latest_product_title'];
       $latest_product_subtitle = $row['latest_product_subtitle'];
       $popular_product_title = $row['popular_product_title'];
       $popular_product_subtitle = $row['popular_product_subtitle'];
       $testimonial_title = $row['testimonial_title'];
       $testimonial_subtitle = $row['testimonial_subtitle'];
       $testimonial_photo = $row['testimonial_photo'];
       $blog_title = $row['blog_title'];
       $blog_subtitle = $row['blog_subtitle'];
       $total_featured_product_home = $row['total_featured_product_home'];
       $total_latest_product_home = $row['total_latest_product_home'];
       $total_popular_product_home = $row['total_popular_product_home'];
       $home_service_on_off = $row['home_service_on_off'];
       $home_welcome_on_off = $row['home_welcome_on_off'];
       $home_featured_product_on_off = $row['home_featured_product_on_off'];
       $home_latest_product_on_off = $row['home_latest_product_on_off'];
       $home_popular_product_on_off = $row['home_popular_product_on_off'];
       $home_testimonial_on_off = $row['home_testimonial_on_off'];
       $home_blog_on_off = $row['home_blog_on_off'];
       $ads_above_welcome_on_off           = $row['ads_above_welcome_on_off'];
       $ads_above_featured_product_on_off  = $row['ads_above_featured_product_on_off'];
       $ads_above_latest_product_on_off    = $row['ads_above_latest_product_on_off'];
       $ads_above_popular_product_on_off   = $row['ads_above_popular_product_on_off'];
       $ads_above_testimonial_on_off       = $row['ads_above_testimonial_on_off'];
       $ads_category_sidebar_on_off        = $row['ads_category_sidebar_on_off'];
       $special        = $row['special'];
       $spt                              = $row['spt'];
       $sps                              = $row['sps'];
   }
   $statement = $pdo->prepare("SELECT * FROM tbl_advertisement");
   $statement->execute();
   $result = $statement->fetchAll(PDO::FETCH_ASSOC);
   foreach ($result as $row) {
       $adv_type[] = $row['adv_type'];
       $adv_photo[] = $row['adv_photo'];
       $adv_url[] = $row['adv_url'];
       $adv_adsense_code[] = $row['adv_adsense_code'];
   }
   ?>
      
      

      <?php if($home_latest_product_on_off == 1): ?>
      <section class="product-items-slider section-padding">
         <div class="container">
            <div class="section-header">
               <h5 class="heading-design-h5 text-center">Latest Product <!--<span class="badge badge-success">20% OFF</span>-->
                  <a class="float-right text-secondary" href="latest.php">View All</a>
               </h5>
            </div>
            <div class="owl-carousel owl-carousel-featured">
                <?php  
                    $statement = $pdo->prepare("SELECT * FROM tbl_product WHERE p_is_active=?   ORDER BY p_id DESC");
                    $statement->execute(array(1));
                    $result = $statement->fetchAll(PDO::FETCH_ASSOC);                            
                    foreach ($result as $row) {
                        $statement2 = $pdo->prepare("SELECT * FROM tbl_product_size WHERE p_id=?");
                        $statement2->execute(array($row['p_id']));
                        $result2 = $statement2->fetchAll(PDO::FETCH_ASSOC);                            
                        foreach ($result2 as $row2) {
                                $statement3 = $pdo->prepare("SELECT * FROM tbl_size WHERE size_id=?");
                                $statement3->execute(array($row2['size_id']));
                                $result3 = $statement3->fetchAll(PDO::FETCH_ASSOC);         
                                foreach ($result3 as $row3) {
                                     $row3['size_name'];
                                }
                        }
                            ?>
                <div class="item" id="item_id_<?php echo $row['p_id']; ?>">
                  <div class="product product_id_<?php echo $row['p_id']; ?>">
                      <a href="product_view.php?id=<?php echo $row['p_id']; ?>">
                        <div class="product-header">
                            <?php if( $row['p_old_price']!='' &&  $row['p_old_price']!=$row['p_current_price']) { $c= $row['p_old_price']-$row['p_current_price']; $d=$c/$row['p_old_price']; }?>
                                <span class="badge badge-success" <?php echo 'id="offer_'.$row['p_id'].'"'; ?> >1 % OFF</span>
                            
                           <img class="img-fluid" src="assets/uploads/<?php echo  $row['p_featured_photo']; ?>" alt="<?php echo $row['p_name']; ?>">
                           <span class="veg text-success mdi mdi-circle"></span>
                           <!--<span class="non-veg text-danger mdi mdi-circle"></span>-->
                        </div>
                        <div class="product-body">
                           <h5 class="text-inline"><?php echo $row['p_name']; ?></h5>
                           <h6><strong><span class="mdi mdi-approval"></span> Available in</strong> - </h6>
                        </div>
                        </a>
                        <div class="product-footer">
                            <p>
                                <select id="size_<?php echo $row['p_id']; ?>" onchange="Myvalueput(<?php echo $row['p_id']; ?>)" class="form-control form_value" id2="<?php echo $row['p_id']; ?>">
                                              
                                <?php
                                                $statement2 = $pdo->prepare("SELECT * FROM tbl_product_size WHERE p_id=?");
                                                $statement2->execute(array($row['p_id']));
                                                $result2 = $statement2->fetchAll(PDO::FETCH_ASSOC);  
                                                $i=1;
                                                
                                                foreach ($result2 as $row2) {
                                                        $statement3 = $pdo->prepare("SELECT * FROM tbl_size WHERE size_id=?");
                                                        $statement3->execute(array($row2['size_id']));
                                                        $result3 = $statement3->fetchAll(PDO::FETCH_ASSOC);         
                                                        foreach ($result3 as $row3) {
                                                            if($i==1){
                                                                $p_old_price = $row2['p_old_price'];
                                                                $p_current_price = $row2['p_current_price'];
                                                                $p_qty = $row2['p_qty'];
                                                                $size_id = $row3['size_id'];
                                                                $size_name = $row3['size_name'];
                                                            }
                                                            $i++;
                                                            ?>
                                                             <option 
                                                             value='<?php echo $row2['size_id']?>,<?php echo $row2['p_old_price']?>,<?php echo $row2['p_current_price']?>,<?php echo $row2['p_qty']?>,<?php echo $row3['size_name'];?>'
                                                             
                                                             <?php 
                                                             for($i3=1;$i3<=count($arr_cart_size_id2);$i3++){
                                                             if($arr_cart_size_id2[$i3]==$row3['size_id']){ echo 'selected';}
                                                             }
                                                             
                                                             ?>
                                                             
                                                             >
                                                                 <?php echo $row3['size_name'];?>
                                                            </option>
                                                       <?php
                                                        }
                                                }
                                                    
                                                ?>
                                                </select>
                            </p>
                           <p class="offer-price mb-0">
                               &#8377;<b id="price_c_<?php echo $row['p_id']; ?>"><?php  echo $p_current_price; ?></b>
                               <i class="mdi mdi-tag-outline"></i> 
                               <?php if($p_old_price!='' && $p_old_price!=$p_current_price){?><span class="regular-price">&#8377;<b id="price_o_<?php echo $row['p_id']; ?>"><?php echo $p_old_price; ?></b></span><?php } ?>
                           
                           </p>
                                       
                             
                                 
                                       <!--advanced feature start-->
                                       <?php 
                                       if($p_qty >= 1){
                                       ?>
                                        <input type="hidden" name="p_current_price" id="p_current_price_<?php echo $row['p_id']; ?>" value="<?php echo $p_current_price; ?>">
                                          <input type="hidden" name="p_name" id="p_name_<?php echo $row['p_id']; ?>" value="<?php echo $row['p_name']; ?>">
                                          <input type="hidden" name="size_id" id="size_id_<?php echo $row['p_id']; ?>" value="<?php echo $size_id; ?>">
                                          <input type="hidden" name="size_name" id="size_name_<?php echo $row['p_id']; ?>" value="<?php echo $size_name; ?>">
                                          <input type="hidden" name="p_featured_photo" id="p_featured_photo_<?php echo $row['p_id']; ?>" value="<?php echo  $row['p_featured_photo']; ?>">
                                          
                                   
                                          
                                       <?php  
                                          for($i3=1;$i3<=count($arr_cart_p_id2);$i3++){
                                              if($arr_cart_p_id2[$i3]==$row['p_id']){
                                                 ?>
                                                
                                         <div class="col-xs-12 col-sm-12 input-group" id="hide_A<?php echo $row['p_id']; ?>">
                                          <button class="btn btn-md input-group-btn btn-danger" onclick="minus(<?php echo $row['p_id']; ?>)">-</button>
                                          <input type="text" name="quantity" class="form-control input-type text-center" qty_id="<?php echo $i3;?>" id="qty_<?php echo $row['p_id']; ?>"
                                             qty="<?php echo $row['p_qty']; ?>" readonly value="<?php echo $arr_cart_p_qty2[$i3];?>" >
                                          <button class="btn btn-md input-group-btn btn-danger" onclick="plus(<?php echo $row['p_id']; ?>)">+</button>
                                       </div>
                                       
                                       <input id="qty2_<?php echo $row['p_id']; ?>"  qty="<?php echo $row['p_qty']; ?>" type="hidden" value="1"/>
                                       <button type="button" id="hide_B<?php echo $row['p_id']; ?>" style="display:none" class="btn  btn-secondary btn-sm" onclick="add(<?php echo $row['p_id']; ?>)"><i class="mdi mdi-cart-outline"></i> Add To Cart</button>
                                       <?php
                                          } else{ if(empty($f)){ $f=0; } $f=$f+1;} } 
                                          if($f < count($arr_cart_p_id2)){ $f=0; }
                                          if(count($arr_cart_p_id2) == $f){ $f=0;
                                           ?>
                                            <div class="col-xs-12 col-sm-12 input-group" id="hide_A<?php echo $row['p_id']; ?>" style="display:none">
                                                <button class="btn btn-md input-group-btn btn-danger" onclick="minus(<?php echo $row['p_id']; ?>)">-</button>
                                                <input type="text" readonly name="quantity" class="form-control input-type text-center " qty_id="" id="qty_<?php echo $row['p_id']; ?>"
                                                 qty="<?php echo $row['p_qty']; ?>"  value="1" >
                                                <button class="btn btn-md input-group-btn btn-danger " onclick="plus(<?php echo $row['p_id']; ?>)">+</button>
                                            </div>
                                       <input id="qty2_<?php echo $row['p_id']; ?>"  qty="<?php echo $row['p_qty']; ?>" type="hidden" value="1" />
                                       <button type="button" id="hide_B<?php echo $row['p_id']; ?>" class="btn btn-secondary btn-sm" onclick="add(<?php echo $row['p_id']; ?>);"><i class="mdi mdi-cart-outline"></i> Add To Cart</button>
                                    <?php  }  }
                                    elseif($p_qty <= 0){ ?>
                                    <button type="button" class="btn btn-secondary btn-sm"><i class="mdi mdi-cart-outline"></i> Out Of Stock</button>
                                    <?php } ?>
                        </div>
                  </div>
               </div>
                <?php } ?>
            </div>
         </div>
      </section>
      <?php endif; ?>
      
      
      
                        
      <section class="offer-product">
         <div class="container">
            <div class="row no-gutters">
                <?php
                    $statement = $pdo->prepare("SELECT * FROM tbl_ad_slider ORDER BY RAND() limit 2");
                    $statement->execute(array(1));
                    $result = $statement->fetchAll(PDO::FETCH_ASSOC);
                    foreach ($result as $row) {
                    ?>
               <div class="col-md-6">
                  <a href="<?php echo $row['link']; ?>"><img class="img-fluid" src="assets/uploads/<?php echo $row['img']; ?>" alt="<?php echo $row['link']; ?>"></a>
               </div>
               <?php  } ?>
            </div>
         </div>
      </section>
  


  <?php
  if(isset($_SESSION['customer']['cust_email'])){
        if($_SESSION['customer']['cust_email']!='')
            {
            ?>                
                 <script>
                    window.localStorage.setItem('kush','<?php echo $_SESSION['customer']['cust_email']; ?>');
                      
                 </script>              
                 <?php
            }
  }
            
            if(isset($_SESSION['customer']['cust_email'])){
            if($_SESSION['customer']['cust_email']=='')
            {
                if($_SESSION['kkks']!=1)
                {
                    ?>
                         <script>
                         if(window.localStorage.getItem('kush')){
                            document.write("<form method='post' action='kush.php' id='LOCAL_USER'><input name='kush' type='hidden' value='"+window.localStorage.getItem('kush')+"'></form>");
                            document.getElementById("LOCAL_USER").submit();    
                         }
                         </script>
                 <?php 
             }
         }
            }
         ?>
         
      
<?php require('footer.php');?>