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

if(isset($_SESSION['cart_p_id'])){
    $i1=0;
    foreach($_SESSION['cart_p_id'] as $key => $value) 
    {
        $i1++;
        $arr_cart_p_id1[$i1] = $value;
    }
    
    $i2=0;
    foreach($_SESSION['cart_p_id'] as $key2 => $value2) 
    {
        $i2++;
        $arr_cart_p_id2[$i2] = $value2;
    }
    
    $i2=0;
    foreach($_SESSION['cart_size_id'] as $key2 => $value2) 
    {
        $i2++;
        $arr_cart_size_id2[$i2] = $value2;
    }
}

if(isset($_SESSION['cart_p_qty'])){
    $i2=0;
    foreach($_SESSION['cart_p_qty'] as $key => $value) 
    {
        $i2++;
        $arr_cart_p_qty1[$i2] = $value;
    }
    
    $i2=0;
    foreach($_SESSION['cart_p_qty'] as $key2 => $value2) 
    {
        $i2++;
        $arr_cart_p_qty2[$i2] = $value2;
    }


}


?>
<style>
input:read-only {
    cursor: pointer;
}
    .scroll {
    overflow: scroll;
    width: 100%;
    display: flex;
}
.btn-radius {
    margin: 5px;
}
::-webkit-scrollbar {
    -webkit-appearance: none;
}

.bg-light ::-webkit-scrollbar:vertical {
    width: 0px;
}

::-webkit-scrollbar:horizontal {
    height: 0px;
}

::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, .2);
    border: 0px solid #ffffff;
}

::-webkit-scrollbar-track {
    background-color: #ffffff; 
}
</style>
<?php
$statement = $pdo->prepare("SELECT * FROM tbl_settings WHERE id=1");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);                            
foreach ($result as $row) {
    $banner_product_category = $row['banner_product_category'];
}
?>

<?php
if( !isset($_REQUEST['id']) || !isset($_REQUEST['type']) ) {
    header('location: index.php');
    exit;
} else {

    if( ($_REQUEST['type'] != 'top-category') && ($_REQUEST['type'] != 'mid-category') && ($_REQUEST['type'] != 'end-category') ) {
        header('location: index.php');
        exit;
    } else {

        $statement = $pdo->prepare("SELECT * FROM tbl_top_category");
        $statement->execute();
        $result = $statement->fetchAll(PDO::FETCH_ASSOC);                            
        foreach ($result as $row) {
            $top[] = $row['tcat_id'];
            $top1[] = $row['tcat_name'];
        }

        $statement = $pdo->prepare("SELECT * FROM tbl_mid_category");
        $statement->execute();
        $result = $statement->fetchAll(PDO::FETCH_ASSOC);                            
        foreach ($result as $row) {
            $mid[] = $row['mcat_id'];
            $mid1[] = $row['mcat_name'];
            $mid2[] = $row['tcat_id'];
        }

        $statement = $pdo->prepare("SELECT * FROM tbl_end_category");
        $statement->execute();
        $result = $statement->fetchAll(PDO::FETCH_ASSOC);                            
        foreach ($result as $row) {
            $end[] = $row['ecat_id'];
            $end1[] = $row['ecat_name'];
            $end2[] = $row['mcat_id'];
        }

        if($_REQUEST['type'] == 'top-category') {
            if(!in_array($_REQUEST['id'],$top)) {
                header('location: index.php');
                exit;
            } else {

                // Getting Title
                for ($i=0; $i < count($top); $i++) { 
                    if($top[$i] == $_REQUEST['id']) {
                        $title = $top1[$i];
                        break;
                    }
                }
                $arr1 = array();
                $arr2 = array();
                // Find out all ecat ids under this
                for ($i=0; $i < count($mid); $i++) { 
                    if($mid2[$i] == $_REQUEST['id']) {
                        $arr1[] = $mid[$i];
                    }
                }
                for ($j=0; $j < count($arr1); $j++) {
                    for ($i=0; $i < count($end); $i++) { 
                        if($end2[$i] == $arr1[$j]) {
                            $arr2[] = $end[$i];
                        }
                    }   
                }
                $final_ecat_ids = $arr2;
            }   
        }

        if($_REQUEST['type'] == 'mid-category') {
            if(!in_array($_REQUEST['id'],$mid)) {
                header('location: index.php');
                exit;
            } else {
                // Getting Title
                for ($i=0; $i < count($mid); $i++) { 
                    if($mid[$i] == $_REQUEST['id']) {
                        $title = $mid1[$i];
                        break;
                    }
                }
                $arr2 = array();        
                // Find out all ecat ids under this
                for ($i=0; $i < count($end); $i++) { 
                    if($end2[$i] == $_REQUEST['id']) {
                        $arr2[] = $end[$i];
                    }
                }
                $final_ecat_ids = $arr2;
            }
        }

        if($_REQUEST['type'] == 'end-category') {
            if(!in_array($_REQUEST['id'],$end)) {
                header('location: index.php');
                exit;
            } else {
                // Getting Title
                for ($i=0; $i < count($end); $i++) { 
                    if($end[$i] == $_REQUEST['id']) {
                        $title = $end1[$i];
                        break;
                    }
                }
                $final_ecat_ids = array($_REQUEST['id']);
            }
        }
        
    }   
}
?>






<section class="pt-3 pb-3 page-info section-padding border-bottom bg-white">
			<div class="container">
				<div class="row">
					<div class="col-md-12">
						<a href="<?php echo BASE_URL;?>"><strong><span class="mdi mdi-home"></span> Home</strong></a>
						<span class="mdi mdi-chevron-right"></span> <a href="#"><?php echo LANG_VALUE_51; ?> <?php echo $title; ?></a>
					</div>
				</div>
			</div>
		</section>

<section class="bg-light pb-1 pt-1">
			<div class="container">
			<div class="row">
        <div class="scroll hidden-md hidden-lg ">
             <?php
             
             if(isset($_GET['type']) && $_GET['type']=='mid-category'){
                 $statement2 = $pdo->prepare("SELECT * FROM tbl_end_category WHERE mcat_id=?");
                 $statement2->execute(array($_GET['mid']));
                 $result2 = $statement2->fetchAll(PDO::FETCH_ASSOC);
                 $q=0;
                 foreach ($result2 as $row2) {
                 $q++;
                 ?>
                <?php if($row2['mcat_id'] == $_GET['mid'] && 1==$q){ ?>
                <a href="product_special.php?id=<?php echo $_GET['mid']; ?>&type=mid-category<?php if(isset($_GET['order'])){ echo '&order='.$_GET['order'];}?>&mid=<?php echo $_GET['mid'];?>" class=" btn-radius col-auto <?php if($row2['mcat_id'] == $_GET['mid']){ ?>bg-theme-color text-white<?php }else{ ?>bg-white text-theme-color<?php } ?>">All</a>
              
           
                  <?php
                  }
                  }
                   foreach ($result2 as $row2) {
                                                    ?>
                                                    <?php if($row2['ecat_id'] != $_GET['id']){ ?>
                <a href="product_special.php?id=<?php echo $row2['ecat_id']; ?>&type=end-category<?php if(isset($_GET['order'])){ echo '&order='.$_GET['order'];}?>&mid=<?php echo $_GET['mid'];?>" class="col-auto btn-radius <?php if($row2['ecat_id']===$_GET['id']){ ?>bg-theme-color text-white<?php }else{ ?>bg-white text-theme-color<?php } ?>"><?php echo $row2['ecat_name']; ?></a>
              
           
                  <?php
                  }
                  }
                  } 
             if(isset($_GET['mid'])){
                 $statement2 = $pdo->prepare("SELECT * FROM tbl_end_category WHERE mcat_id=?");
                                                            $statement2->execute(array($_GET['mid']));
                                                            $result2 = $statement2->fetchAll(PDO::FETCH_ASSOC);
                                                            foreach ($result2 as $row2) {
                                                    ?>
                                                    <?php if($row2['ecat_id']===$_GET['id']){ ?>
                <a href="product_special.php?id=<?php echo $_GET['mid']; ?>&type=mid-category<?php if(isset($_GET['order'])){ echo '&order='.$_GET['order'];}?>&mid=<?php echo $_GET['mid'];?>" class=" btn-radius col-auto <?php if($row2['mcat_id'] == $_GET['mid']){ ?>bg-white text-theme-color<?php }else{ ?>bg-white text-theme-color<?php } ?>">All</a>
              
              
                <a href="product_special.php?id=<?php echo $row2['ecat_id']; ?>&type=end-category<?php if(isset($_GET['order'])){ echo '&order='.$_GET['order'];}?>&mid=<?php echo $_GET['mid'];?>" class=" btn-radius col-auto <?php if($row2['ecat_id']===$_GET['id']){ ?>bg-theme-color text-white<?php }else{ ?>bg-white text-theme-color<?php } ?>"><?php echo $row2['ecat_name']; ?></a>
              
           
                  <?php
                  }
                  }
                   foreach ($result2 as $row2) {
                                                    ?>
                                                    <?php if($row2['ecat_id'] != $_GET['id']){ ?>
                <a href="product_special.php?id=<?php echo $row2['ecat_id']; ?>&type=end-category<?php if(isset($_GET['order'])){ echo '&order='.$_GET['order'];}?>&mid=<?php echo $_GET['mid'];?>" class="col-auto btn-radius <?php if($row2['ecat_id']===$_GET['id']){ ?>bg-theme-color text-white<?php }else{ ?>bg-white text-theme-color<?php } ?>"><?php echo $row2['ecat_name']; ?></a>
              
           
                  <?php
                  }
                  }
                  }
                  ?>
                  
            
        </div>
    </div>
    </div>
		</section>


<section class="shop-list section-padding">
    <div class="container">
        <div class="row">
      <div class="col-sm-12">
        <div class="shop-head">
    							<div class="btn-group float-right mt-2">
    								<div class="col-4 col-sm-4 col-md-4 text-right">
                <label class="control-label" for="input-sort">Sort By:</label>
              </div>
              <div class="col-8 col-sm-8 col-md-8">
                  <form method="GET" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
                      <input type="hidden" name="id" value="<?php echo $_GET['id'];?>">
                      <input type="hidden" name="type" value="<?php echo $_GET['type'];?>">
                <select onchange="this.form.submit();" name="order">
                  <option value="default" <?php if(isset($_GET['order'])){if($_GET['order']=='default'){ echo 'selected';}}?>>Default</option>
                  <option value="ASC_a_to_z" <?php if(isset($_GET['order'])){if($_GET['order']=='ASC_a_to_z'){ echo 'selected';}}?>>Name (A - Z)</option>
                  <option value="ASC_z_to_a" <?php if(isset($_GET['order'])){if($_GET['order']=='ASC_z_to_a'){ echo 'selected';}}?>>Name (Z - A)</option>
                  <option value="ASC_price_low" <?php if(isset($_GET['order'])){if($_GET['order']=='ASC_price_low'){ echo 'selected';}}?>>Price (Low &gt; High)</option>
                  <option value="ASC_price_high" <?php if(isset($_GET['order'])){if($_GET['order']=='ASC_price_high'){ echo 'selected';}}?>>Price (High &gt; Low)</option>
                </select>
                </form>
              </div>
    					
                
    							</div>
    						</div>
    						</div>	
      <div class="col-sm-12">
    						
        <div class="row product-layoutrow section-product">
            
    
     <?php
                            // Checking if any product is available or not
                            $prod_count = 0;
                            $statement = $pdo->prepare("SELECT * FROM tbl_product");
                            $statement->execute();
                            $result = $statement->fetchAll(PDO::FETCH_ASSOC);
                            foreach ($result as $row) {
                                $prod_table_ecat_ids[] = $row['ecat_id'];
                            }
    
                            for($ii=0;$ii<count($final_ecat_ids);$ii++):
                                if(in_array($final_ecat_ids[$ii],$prod_table_ecat_ids)) {
                                    $prod_count++;
                                }
                            endfor;
    
                            if($prod_count==0) {
                                echo '<div class="pl_15">'.LANG_VALUE_153.'</div>';
                            } else {
                                for($ii=0;$ii<count($final_ecat_ids);$ii++) {
                                    if(isset($_GET['order'])){
                                    if($_GET['order']=='default'){
                                        $statement = $pdo->prepare("SELECT * FROM tbl_product WHERE ecat_id=? AND p_is_active=? ");
                                    }
                                    if($_GET['order']=='ASC_a_to_z'){
                                        $statement = $pdo->prepare("SELECT * FROM tbl_product WHERE ecat_id=? AND p_is_active=? order by p_name asc ");
                                    }
                                    if($_GET['order']=='ASC_z_to_a'){
                                        $statement = $pdo->prepare("SELECT * FROM tbl_product WHERE ecat_id=? AND p_is_active=? order by p_name desc ");
                                    }
                                    if($_GET['order']=='ASC_price_low'){
                                        $statement = $pdo->prepare("SELECT * FROM tbl_product WHERE ecat_id=? AND p_is_active=? order by p_current_price asc ");
                                    }
                                    if($_GET['order']=='ASC_price_high'){
                                        $statement = $pdo->prepare("SELECT * FROM tbl_product WHERE ecat_id=? AND p_is_active=? order by p_current_price desc");
                                    }
                                    }
                                    if(!isset($_GET['order'])){
                                        $statement = $pdo->prepare("SELECT * FROM tbl_product WHERE ecat_id=? AND p_is_active=? ");
                                    }
                                    
                                    
                                    
                                    $statement->execute(array($final_ecat_ids[$ii],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="col-6 col-sm-6 col-md-4 col-lg-3 col-xl-2 mt-5  mb-10 item">
                      <div class="product">
                          <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>-->
                                <?php }?>
                                <span class="badge badge-success" <?php echo 'id="offer_'.$row['p_id'].'"'; ?> >1 % OFF</span>
                               
                               <img class="img-fluid" id="pic_<?php echo $row['p_id']; ?>" src="assets/uploads/<?php echo  $row['p_featured_photo']; ?>" alt="<?php echo $row['p_name']; ?>">
                               <input type="hidden" id="pic2_<?php echo $row['p_id']; ?>" value="<?php echo  $row['p_featured_photo']; ?>" />
                               <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><?php
                                                $statement2 = $pdo->prepare("SELECT * FROM tbl_product_size WHERE p_id=?");
                                                $statement2->execute(array($row['p_id']));
                                                $product_size=$statement2->rowCount();
                                                $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'];
                                                            
                                                            ?>
                                                            <div class="input-group">
                                                              <input id="size2_<?php echo $row['p_id']; ?>"  id2="<?php echo $row['p_id']; ?>" onclick="check_size(<?php echo $row['p_id']; ?>);" class="form-control input-sm" value='<?php echo $row3['size_name'];?>' readonly>
                                                              <div class="input-group-addon" style="background: #ddd;padding: 5px;">
                                                                <i class="mdi mdi-view-module"></i>
                                                              </div>
                                                            </div>
                                                            
                                                            
                                                            <input type="hidden" 
                                                            id="size_<?php echo $row['p_id']; ?>"
                                                            class="form_value" 
                                                            value="<?php echo $size_id; ?>,<?php echo $p_old_price;?>,<?php echo $p_current_price;?>,<?php echo $p_qty;?>,<?php echo $size_name;?>,<?php echo $row['p_id']; ?>"
                                                            id2="<?php echo $row['p_id']; ?>" />
                                                       <?php
                                                        }
                                                        $i++;
                                                        }
                                                }
                                                    
                                                ?>
                                </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_old_price" id="p_old_price_<?php echo $row['p_id']; ?>" value="<?php echo $p_old_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  
                                        $count=0;     
                                        $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) {
                                            $pid_search=0;
                                            $size_id_search=0;
                                            $primary_id=0;
                                            $ok=0;
                                            $count++;
                                            
                                            for($l=1;$l<=count($arr_cart_p_id2);$l++){
                                                $size_id_search = array_search($row2['size_id'],$arr_cart_size_id2);
                                                if($row['p_id'] == $arr_cart_p_id2[$l] && $row2['size_id'] == $arr_cart_size_id2[$l]){
                                                    $size_id_search=$l;
                                                    $ok=1;
                                                    break;
                                                }
                                            }
                                            
                                            $primary_id = $row['p_id'].$row2['size_id'];
                                            
                                           if($ok){
                                      ?>
                                                
                                       
                                             <div class="col-xs-12 col-sm-12 input-group" id2="yes" id3="<?php echo $count;?>" id="hide_A<?php echo $primary_id; ?>">
                                              <button class="btn btn-md input-group-btn btn-danger" onclick="minus(<?php echo $row['p_id'].','.$primary_id; ?>)">-</button>
                                              <input type="text" name="quantity" class="form-control input-type text-center" qty_id="<?php echo $l;?>" id="qty_<?php echo $primary_id; ?>"
                                                 qty="<?php echo $row2['p_qty']; ?>" readonly value="<?php echo $arr_cart_p_qty2[$l];?>" >
                                              <button class="btn btn-md input-group-btn btn-danger" onclick="plus(<?php echo $row['p_id'].','.$primary_id; ?>)">+</button>
                                           </div>
                                           
                                           <input id="qty2_<?php echo $primary_id; ?>"  qty="<?php echo $row2['p_qty']; ?>" type="hidden" value="1"/>
                                           <button type="button" id2="no" id3="<?php echo $count;?>" id="hide_B<?php echo $primary_id; ?>" style="display:none" class="btn  btn-secondary btn-sm" onclick="add(<?php echo $row['p_id'].','.$primary_id; ?>)"><i class="mdi mdi-cart-outline"></i> Add To Cart</button>
                                       <?php
                                           }
                                           else{
                                           ?>
                                       
                                                <div class="col-xs-12 col-sm-12 input-group" id2="yes1" id3="<?php echo $count;?>" id="hide_A<?php echo $primary_id; ?>" style="display:none">
                                                    <button class="btn btn-md input-group-btn btn-danger" onclick="minus(<?php echo $row['p_id'].','.$primary_id; ?>)">-</button>
                                                    <input type="text" readonly name="quantity" class="form-control input-type text-center " qty_id="<?php echo $i3;?>" id="qty_<?php echo $primary_id; ?>"
                                                     qty="<?php echo $row2['p_qty']; ?>"  value="1" >
                                                    <button class="btn btn-md input-group-btn btn-danger " onclick="plus(<?php echo $row['p_id'].','.$primary_id; ?>)">+</button>
                                                </div>
                                       
                                           <input id="qty2_<?php echo $primary_id; ?>"  qty="<?php echo $row2['p_qty']; ?>" type="hidden" value="1" />
                                               <button type="button" id2="no1" id3="<?php echo $count;?>" id="hide_B<?php echo $primary_id; ?>" class="btn btn-secondary btn-sm" onclick="add(<?php echo $row['p_id'].','.$primary_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>
    </div>
    </div>
</section>


      <section class="section-padding bg-white border-top">
         <div class="container">
            <div class="row">
               <div class="col-lg-4 col-sm-6 col-12 ">
                  <div class="feature-box">
                     <i class="mdi mdi-truck-fast"></i>
                     <h6>Same Day Delivery & Easy Return</h6>
                     <p>Same Day Delivery & Easy To Return</p>
                  </div>
               </div>
               <div class="col-lg-4 col-sm-6 col-12">
                  <div class="feature-box">
                     <i class="mdi mdi-basket"></i>
                     <h6>100% Satisfaction Guarantee </h6>
                     <p>Full safety procedures packing and delivery</p>
                  </div>
               </div>
               <div class="col-lg-4 col-sm-6 col-12">
                  <div class="feature-box">
                     <i class="mdi mdi-tag-heart"></i>
                     <h6>Great Daily Deals Discount</h6>
                     <p>Great Daily Deals Discount</p>
                  </div>
               </div>
            </div>
         </div>
      </section>
      <!-- Footer -->
      <section class="section-padding no-padding2 footer bg-white border-top">
         <div class="container">
            <div class="row">
               <div class="col-lg-3 col-md-3">
                  <h6 class="mb-4 d-md-block d-sm-none d-xs-none d-lg-block d-xl-block">CONTACTS </h6>
                  <h6 class="collapsed d-md-none  d-lg-none d-xl-none  d-sm-block d-xs-block" data-target="#Touch" data-toggle="collapse">CONTACTS<i class=" float-right mdi mdi-arrow-down-bold-circle mr-0 pr-3"></i></h6>
                  <ul  class="list-unstyled collapse d-md-block  d-lg-block d-xl-block" id="Touch">
                      <li class="mb-2 mt-0"><a class="logo" href="<?php echo BASE_URL;?>"><img src="assets/uploads/<?php echo $footer_logo;?>" class="bg-danger" alt="<?php echo $meta_title_home;?>"></a></li>
                      <li><a class="text-dark" href="#"><i class="mdi mdi-map-marker"></i> <?php echo $contact_address;?></a></li>
                      <li><a class="text-dark" target="blank" href="tel:<?php echo $contact_fax;?>"><i class="mdi mdi-phone"></i><?php echo $contact_fax;?></a></li>
                      <li><a class="text-dark" target="blank" href="tel:<?php echo $contact_phone;?>"><i class="mdi mdi-cellphone-iphone"></i> <?php echo $contact_phone;?></a></li>
                      <li><a class="text-success" target="blank" href="mailto:<?php echo $contact_email;?>"><i class="mdi mdi-email"></i> <?php echo $contact_email;?></a></li>
                      <!--<li><a class="text-primary" href="#"><i class="mdi mdi-web"></i> www.freshmartaj.com</a></li>-->
                  </ul>
               </div>
               <div class="col-lg-2 col-md-2">
                  <h6 class="mb-4 d-md-block d-sm-none d-xs-none d-lg-block d-xl-block">TOP CITIES </h6>
                  <h6 class="collapsed d-md-none  d-lg-none d-xl-none  d-sm-block d-xs-block" data-target="#CITIES" data-toggle="collapse">TOP CITIES <i class=" float-right mdi mdi-arrow-down-bold-circle mr-0 pr-3"></i></h6>
                  <ul  class="list-unstyled collapse d-md-block  d-lg-block d-xl-block" id="CITIES">
                        <?php
                            $statement = $pdo->prepare("SELECT * FROM tbl_top_cities WHERE status=? ORDER BY id ASC");
                            $statement->execute(array(0));
                            $result = $statement->fetchAll(PDO::FETCH_ASSOC);							
                            foreach ($result as $row) {
                        ?>
                                <li><a href="#"><?php echo $row['name']; ?></a></li>
                        <?php } ?>
	                    
                  <ul>
               </div>
               
               <div class="col-lg-2 col-md-2">
                  <h6 class="mb-4 d-md-block d-sm-none d-xs-none d-lg-block d-xl-block">CATEGORIES </h6>
                  <h6 class="collapsed d-md-none  d-lg-none d-xl-none  d-sm-block d-xs-block" data-target="#CATEGORIES" data-toggle="collapse">CATEGORIES <i class=" float-right mdi mdi-arrow-down-bold-circle mr-0 pr-3"></i></h6>
                  <ul  class="list-unstyled d-md-block collapse d-lg-block d-xl-block" id="CATEGORIES">
                  <?php
					$statement = $pdo->prepare("SELECT * FROM tbl_mid_category order by rand() limit 5");
					$statement->execute();
					$result = $statement->fetchAll(PDO::FETCH_ASSOC);
					foreach ($result as $row1) {
						?>
						<li><a href="product_special.php?id=<?php echo $row1['mcat_id'];?>&type=mid-category"><?php echo $row1['mcat_name'];?></a></li>
					<?php } ?>
                               
                               
                  <ul>
               </div>
               <div class="col-lg-2 col-md-2">
                  <h6 class="mb-4 d-md-block d-sm-none d-xs-none d-lg-block d-xl-block">ABOUT US </h6>
                  <h6 class="collapsed d-md-none  d-lg-none d-xl-none  d-sm-block d-xs-block" data-target="#ABOUT" data-toggle="collapse">ABOUT US <i class=" float-right mdi mdi-arrow-down-bold-circle mr-0 pr-3"></i></h6>
                  <ul  class="list-unstyled d-md-block collapse  d-lg-block d-xl-block" id="ABOUT">
                  <li><a href="about.php">Company Information</a></li>
                  <li><a href="faq.php">FAQ</a></li>
                  <li><a href="career.php">Career</a></li>
                  <li><a href="terms_and_condition.php">Terms &amp; Condition</a></li>
                  <li><a href="contact.php">Contact Us</a></li>
                  <ul>
               </div>
               <div class="col-lg-3 col-md-3">
                  <h6 class="mb-4 d-md-block d-sm-none d-xs-none d-lg-block d-xl-block">DOWNLOAD APP </h6>
                  <h6 class="collapsed d-md-none  d-lg-none d-xl-none  d-sm-block d-xs-block" data-target="#App" data-toggle="collapse">DOWNLOAD APP <i class=" float-right mdi mdi-arrow-down-bold-circle mr-0 pr-3"></i></h6>
                  <ul  class="list-unstyled d-md-block collapse hover-white  d-lg-block d-xl-block" id="App">
                  <li>
                  <div class="app">
                     <a href="<?php echo $app_url; ?>" target="blank"><img src="img/google.png" alt=""></a>
                     <!--<a href="#"><img src="img/apple.png" alt=""></a>-->
                  </div>
                  </li>
                  </ul>
                  <div class="w-100-h-1"></div>
                  <h6 class="mb-4 d-md-block d-sm-none d-xs-none d-lg-block d-xl-block">GET IN TOUCH </h6>
                  <h6 class="collapsed d-md-none  d-lg-none d-xl-none  d-sm-block d-xs-block" data-target="#GET" data-toggle="collapse">GET IN TOUCH <i class=" float-right mdi mdi-arrow-down-bold-circle mr-0 pr-3"></i></h6>
                  <ul  class="list-unstyled d-md-block collapse  d-lg-block d-xl-block" id="GET">
                  <li>
                  <div class="footer-social">
                      <?php 
                  $null='';
                    $statement2 = $pdo->prepare("SELECT * FROM tbl_social WHERE social_url!=?");
                    $statement2->execute(array($null));
                    $result2 = $statement2->fetchAll(PDO::FETCH_ASSOC);
                        foreach ($result2 as $row2) {
                            ?>
                            <a class="btn-<?php echo $row2['social_name'];?> text-white" href="<?php echo $row2['social_url'];?>"  target="blank"  class="btn btn-sm bg-theme-color text-white"><i class="<?php echo $row2['social_icon'];?>"></i> </a>
                            <?php
                        }
                    
                    ?>
                    
                  </div>
                  </li>
                  </ul>
                  <br>
               </div>
            </div>
         </div>
      </section>
      <!-- End Footer -->
      <!-- Copyright -->
      <section class="pt-4 pb-4 footer-bottom">
         <div class="container">
            <div class="row no-gutters">
               <div class="col-lg-6 col-sm-6 col-12 sm-text-center">
                  <p class="mt-1 mb-0"><?php echo $footer_copyright;?>
              
              </p>
               </div>
               <div class="col-lg-6 col-sm-6 col-12 sm-text-center text-right">
                  <p  class="mt-1 mb-0">Made with <i class="mdi mdi-heart text-danger"></i> by <a href="https://decentdesign.in/" target="_blank" class="text-primary">Decent Web Services</a>
                  </p>
               </div>
            </div>
         </div>
      </section>
      <!-- End Copyright -->

      
      
      <!--MY CUSTOM JAVASCRIPT-->

      
              <!-- <div class="footer-fix-nav shadow">
         <div class="row mx-0">
            <div class="col">
               <a href="#"><i class="mdi mdi-home"></i></a>
            </div>
            <div class="col border-0">
               <a href="#" data-toggle="offcanvas" ><i class="mdi mdi-cart"></i></a>
            </div>
            <div class="col active">
               <a class="toggle hc-nav-trigger" href="#" role="button" ><i class="mdi mdi-menu"></i></a>
            </div>
            <div class="col">
               <a href="#"><i class="mdi mdi-tag"></i></a>
            </div>
            <div class="col">
               <a href="#"><i class="mdi mdi-account-circle"></i></a>
            </div>
         </div>
      </div>-->
       <nav id="main-nav">
         <ul class="first-nav bg-me2">
           <li class="search" data-nav-custom-content>
             <div class="form-container">
                   <?php
            if(isset($_SESSION['customer'])) {
                if(empty($_SESSION['customer']['cust_image'])){
                    $img='user.PNG';
                }
                else{
                    $img  = $_SESSION['customer']['cust_image'];
                }
                ?>
                    <a href="#" class="text-white">
                        <div class="pro ">
                            <img src="assets/uploads/<?php  echo $img;?>" class="rounded-circle img_60-60" alt="<?php  echo $_SESSION['customer']['cust_name'];?>">
                            &nbsp; <b><?php  echo $_SESSION['customer']['cust_name'];?></b>
                        </div><?php  echo $_SESSION['customer']['cust_email'];?>
                    </a>
        <?php
            } 
        ?>
             </div>
           </li>
         </ul>
          
   
         <ul class="second-nav">
             <li class="home"><a href="index.php">Home</a></li>
           <li>
             <span>Category</span>
             <ul>
                 <?php
						$statement1 = $pdo->prepare("SELECT * FROM tbl_mid_category LIMIT 6");
						$statement1->execute();
						$result1 = $statement1->fetchAll(PDO::FETCH_ASSOC);
						foreach ($result1 as $row1) {
							?>
							
               <li class="mobile">
                 <a href="#"><?php echo $row1['mcat_name']; ?></a>
                 <ul>
                  
                 
                      	<?php
								$statement2 = $pdo->prepare("SELECT * FROM tbl_end_category WHERE mcat_id=?");
								$statement2->execute(array($row1['mcat_id']));
								$result2 = $statement2->fetchAll(PDO::FETCH_ASSOC);
								foreach ($result2 as $row2) {
									?>
									 <li class="mobile"><a href="product_special.php?id=<?php echo $row2['ecat_id']; ?>&type=end-category&mid=<?php echo $row1['mcat_id']; ?>"><?php echo $row2['ecat_name']; ?></a></li>
                        	<?php } ?> 
                        	</ul>
                  </li>
                 	<?php } ?> 
                 	
                 	
             </ul>
           </li>
           
           
            <?php
            if(isset($_SESSION['customer'])) {
            ?>
            <li class="face"><a href="my-profile.php">My Profile </a></li>
            <li><a href="orderlist.php">My Orders </a></li>
            <?php } ?>
            <li><a href="about.php">About Us </a></li>
            <li><a href="contact.php">Customer Care </a></li>
            <?php
            if(isset($_SESSION['customer'])) {
            ?>
            <li><a href="customer-password-update.php">Password </a></li>
            <?php } ?>
            <li><a href="terms_and_condition.php">Terms & Condition </a></li>
            <!--<a href="#">Share </a>-->
            <!--<a href="#">Rate Us </a>-->
            <?php
                if(isset($_SESSION['customer'])) {
            ?>
              <li class=""><a href="logout.php">Logout</a></li>
            <?php } ?>
         </ul>
   
         <!--<ul class="bottom-nav">-->
         <!--  <li class="github">-->
         <!--    <a href="#" target="_blank">-->
         <!--      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg>-->
         <!--    </a>-->
         <!--  </li>-->
         <!--  <li class="email">-->
         <!--    <a href="#" target="_blank">-->
         <!--      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"/><path d="M0 0h24v24H0z" fill="none"/></svg>-->
         <!--    </a>-->
         <!--  </li>-->
         <!--  <li class="ko-fi">-->
         <!--    <a href="#" target="_blank">-->
         <!--      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M23.881 8.948c-.773-4.085-4.859-4.593-4.859-4.593H.723c-.604 0-.679.798-.679.798s-.082 7.324-.022 11.822c.164 2.424 2.586 2.672 2.586 2.672s8.267-.023 11.966-.049c2.438-.426 2.683-2.566 2.658-3.734 4.352.24 7.422-2.831 6.649-6.916zm-11.062 3.511c-1.246 1.453-4.011 3.976-4.011 3.976s-.121.119-.31.023c-.076-.057-.108-.09-.108-.09-.443-.441-3.368-3.049-4.034-3.954-.709-.965-1.041-2.7-.091-3.71.951-1.01 3.005-1.086 4.363.407 0 0 1.565-1.782 3.468-.963 1.904.82 1.832 3.011.723 4.311zm6.173.478c-.928.116-1.682.028-1.682.028V7.284h1.77s1.971.551 1.971 2.638c0 1.913-.985 2.667-2.059 3.015z"/></svg>-->
         <!--    </a>-->
         <!--  </li>-->
         <!--</ul>-->
   
       </nav>
      
      
      
      <link href='https://fonts.googleapis.com/css?family=Kalam' rel='stylesheet'>
      <script>
          $(document).ready(function(){
              $('.nav-close').hide();
          });
      </script>
      <script>
          
      (function($) {
        var $main_nav = $('#main-nav');
        var $toggle = $('.toggle');

        var defaultOptions = {
          disableAt: false,
          customToggle: $toggle,
          levelSpacing: 40,
          navTitle: 'Fresh Mart AJ',
          levelTitles: true,
          levelTitleAsBack: true,
          pushContent: '#container',
          insertClose: 2
        };

        // call our plugin
        var Nav = $main_nav.hcOffcanvasNav(defaultOptions);

        // add new items to original nav
        $main_nav.find('li.add').children('a').on('click', function() {
          var $this = $(this);
          var $li = $this.parent();
          var items = eval('(' + $this.attr('data-add') + ')');

          $li.before('<li class="new"><a href="#">'+items[0]+'</a></li>');

          items.shift();

          if (!items.length) {
            $li.remove();
          }
          else {
            $this.attr('data-add', JSON.stringify(items));
          }

          Nav.update(true);
        });

        // demo settings update

        const update = (settings) => {
          if (Nav.isOpen()) {
            Nav.on('close.once', function() {
              Nav.update(settings);
              Nav.open();
            });

            Nav.close();
          }
          else {
            Nav.update(settings);
          }
        };

        $('.actions').find('a').on('click', function(e) {
          e.preventDefault();

          var $this = $(this).addClass('active');
          var $siblings = $this.parent().siblings().children('a').removeClass('active');
          var settings = eval('(' + $this.data('demo') + ')');

          update(settings);
        });

        $('.actions').find('input').on('change', function() {
          var $this = $(this);
          var settings = eval('(' + $this.data('demo') + ')');

          if ($this.is(':checked')) {
            update(settings);
          }
          else {
            var removeData = {};
            $.each(settings, function(index, value) {
              removeData[index] = false;
            });

            update(removeData);
          }
        });
      })(jQuery);
    
      </script>
      
<script type="text/javascript">

// pin code verify
$('#pin_code').keypress(function(event){
  if(event.keyCode == 13){
    pin_verify();
  }
});

function pin_verify(){
        var pin_code = $("#pin_code").val();
        $.ajax({
            type: "POST",
            url: "district.php",
            data: {
                pin_code: pin_code
            },
            success: function(data) {
                var obj = JSON.parse(data);
                // alert(data);
                if(obj.pin_count == 0){
                    alert('Sorry We Can not Provide Delivery services this area.');
                }
                if(obj.pin_count == 1){
                    $("#pin_verified").html(obj.pin_code);
                    $("#pin_verified2").html(obj.pin_code);
                    alert('Congrats We  Provide Delivery services this area.');
                    window.location=window.location.href;
                    $('#pin_modal').modal('toggle');
                }
            }
        });
    
}

$('#username').keypress(function(event){
  if(event.keyCode == 13){
    login_verify();
  }
});

$('#password').keypress(function(event){
  if(event.keyCode == 13){
    login_verify();
  }
});

// verify data for login user
function login_verify(){
        var username = $("#username").val();
        var password = $("#password").val();
        $.ajax({
            type: "POST",
            url: "verify.php",
            data: {
                cust_email: username,
                cust_password: password
            },
            success: function(data) {
                var obj = JSON.parse(data);
                if(obj.log == 0){
                    $("#error").toggle();
                    $("#error").html(obj.error);
                    $("#error").hide(3500);
                }
                if(obj.log == 1){
                    $("#success").toggle();
                    $("#success").html(obj.succ);
                    $("#success").hide(3500);
                    
                }
            }
        });
    
}


// register user
function user_register(){
        // $(".mobile_number").find("label").html('a');
        var mobile_number = $("#mobile_number").val();
        var otp = $("#otp").val();
        var cust_name = $("#cust_name").val();
        var cust_email = $("#cust_email").val();
        var reg_password = $("#reg_password").val();
        var reg_confirm_password = $("#reg_confirm_password").val();
        var form2 = $("#form_open").val();
        
        if(mobile_number !='' && otp=='' && cust_name=='' && cust_email=='' && reg_password=='' && reg_confirm_password==''  && form2=='1'){
            var form = 1;
        $.ajax({
            type: "POST",
            url: "user_register.php",
            data: {
                mobile_number: mobile_number,
                form: form
            },
            success: function(data) {
                var obj = JSON.parse(data);
                if(obj.log == 0){
                    $("#error").toggle();
                    $("#error").html(obj.error);
                    $("#error").hide(3500);
                }
                if(obj.log == 1){
                    $("#success").toggle();
                    // alert(obj.succ);
                    $("#success").html('OTP is Sent On Your Mobile Number.');
                    $("#form_open").val(obj.form);
                    $(".mobile_number").hide();
                    $("#register_head").html("Verify OTP!!");
                    $("#button_reg").html("Verify OTP!!");
                    $(".resend_otp").show();
                    $(".otp").show();
                    $("#success").hide(3500);
                    
                }
            }
        });
        }
         
        if(mobile_number !='' && otp!='' && cust_name=='' && cust_email=='' && reg_password=='' && reg_confirm_password==''  && '2'==form2){
            var form = 2;
        $.ajax({
            type: "POST",
            url: "user_register.php",
            data: {
                mobile_number: mobile_number,
                otp: otp,
                form: form
            },
            success: function(data) {
                var obj = JSON.parse(data);
                if(obj.log == 0){
                    $("#error").toggle();
                    $("#error").html(obj.error);
                    $("#error").hide(3500);
                }
                if(obj.log == 1){
                    $("#success").toggle();
                    $("#success").html(obj.succ);
                    $(".mobile_number").hide();
                    $(".otp").hide();
                    $("#register_head").html('Enter Your Name Email && Password!!');
                    $("#button_reg").html("Create Account!!");
                    $("#form_open").val(obj.form);
                    $(".cust_name").show();
                    $(".cust_email").show();
                    $(".reg_password").show();
                    $(".reg_confirm_password").show();
                    $(".resend_otp").hide();
                    $("#success").hide(3500);
                    
                    
                }
            }
        });
        }
        
        
        if(mobile_number !='' && otp!='' && cust_name!='' && cust_email!='' && reg_password!='' && reg_confirm_password!='' && '3'==form2){
            var form = 3;
        $.ajax({
            type: "POST",
            url: "user_register.php",
            data: {
                mobile_number: mobile_number,
                otp: otp,
                cust_name: cust_name,
                cust_email: cust_email,
                reg_password: reg_password,
                reg_confirm_password: reg_confirm_password,
                form: form
            },
            success: function(data) {
                var obj = JSON.parse(data);
                if(obj.log == 0){
                    $("#error").toggle();
                    $("#error").html(obj.error);
                    $("#error").hide(3500);
                }
                if(obj.log == 1){
                    $("#success").toggle();
                    $("#form_open").val(obj.form);
                    $("#success").html(obj.succ);
                    $(".otp").hide();
                    $("#success").hide(3500);
                    
                }
            }
        });
        }

        
    
}
        
        
    function resend_otp(){
        
        var mobile_number = $("#mobile_number").val();
        var form = $("#form_open").val();
                    $.ajax({
            type: "POST",
            url: "user_register.php",
            data: {
                mobile_number: mobile_number,
                form: form
            },
            success: function(data) {
                var obj = JSON.parse(data);
                if(obj.log == 0){
                    $("#error").toggle();
                    $("#error").html(obj.error);
                    $("#error").hide(3500);
                }
                if(obj.log == 1){
                    $("#success").toggle();
                    // alert(obj.succ);
                    $("#success").html('OTP is Resend Successfully.');
                    $("#form_open").val('2');
                    $("#register_head").html("Verify OTP!!");
                    $("#button_reg").html("Verify OTP!!");
                    $("#success").hide(3500);
                    
                }
            }
        });

    } 


$(document).ready(function(){
    // $(".mobile_number").hide();
    $(".otp").hide();
    $(".cust_name").hide();
    $(".cust_email").hide();
    $(".reg_password").hide();
    $(".reg_confirm_password").hide();
    $(".resend_otp").hide();
    
    
    $("#mobile_number").keyup(function(){
        var mobile_number = $("#mobile_number").val();
        if(mobile_number.length>10){
            $("#mobile_number").val('');
        }
        
        if(mobile_number.length<10){
            $("#mobile_number").css('border','1px solid red');
        }
        if(mobile_number.length==10){
            $("#mobile_number").css('border','1px solid #ccc');
        }
    });
    
    $("#otp").keyup(function(){
        var otp = $("#otp").val();
        if(otp.length>6){
            $("#otp").val('');
        }
        if(otp.length<6){
            $("#otp").css('border','1px solid red');
        }
        if(otp.length==6){
            $("#otp").css('border','1px solid #ccc');
        }
    });
    
    
});


// add product in cart
    function add(id,sid) {
                        
                         var p_current_price = $('#p_current_price_'+id).val();
                         var p_old_price = $('#p_old_price_'+id).val();
                         var p_name=$('#p_name_'+id).val();
                         var size_id = $('#size_id_'+id).val();
                         var size_name = $('#size_name_'+id).val();
                         var p_featured_photo=$('#p_featured_photo_'+id).val();
                         var p_qty = $('#qty2_'+sid).val();
                         $('#qty_'+sid).val(p_qty);
                         var p_qty_stock = parseInt($('#qty2_'+sid).attr('qty'));
                         $('#spname').html(p_name);
                         
                         
                   
                      
                      
                $('#closes').css('display','block'); 
                $("#hide_A"+sid).css('display','flex'); 
                $("#hide_B"+sid).hide();
                
                         
                         $.ajax({
            type: "POST",
            url: "cart-item-add.php",
            data:{id: id, p_current_price: p_current_price, p_old_price: p_old_price,p_name: p_name,p_featured_photo:p_featured_photo,p_qty:p_qty,p_qty_stock:p_qty_stock,size_id:size_id,size_name:size_name},
            success: function(data){
                // alert(data);
                $("#cart_quantity").html(parseInt($("#cart_quantity").html())+1);
                $("#cart_quantity2").html(parseInt($("#cart_quantity2").html())+1);
                $("#cart_quantity3").html(parseInt($("#cart_quantity3").html())+1);
                // $('#item_id_'+ id).load(window.location.href + ' .product_id_' + id);
                var qty_id = parseInt(data);
                $('#qty_' + sid).attr('qty_id', qty_id);
                $("#carts").load(location.href + " .cart-sidebar");
            }
            });
            
            
                    }

function plus(ida,sida) {
// quantity update
    var x = parseInt($('#qty_' + sida).attr('qty'));
    var qty_id = parseInt($('#qty_' + sida).attr('qty_id'));
    var a = parseInt($('#qty_' + sida).val());
    var b = parseInt(1);
    var c = parseInt(a + b);
    if (a == x) {
        alert('Out Of Stock.');
    } else {
// send data for quantity update
        $.ajax({
            type: 'post',
            url: 'quantity_update.php',
            data: {
                qty: c,
                qty_id: qty_id
            },
            success: function(data) {
                if(data==1){
                $('#qty_' + sida).val(parseInt(c));
                $("#carts").load(location.href + " .cart-sidebar");
                }
            }
        });
    }
}


// quantity minus for product
function minus(idb,sidb) {
                        
                         var qty_id = parseInt($('#qty_'+sidb).attr('qty_id'));
                         var a = $('#qty_'+sidb).val();
                         var b = a-1;
                         
                         
                       
  
  
  
             if(a==1){
                 
                var pid=$("#as1_"+idb).val();
                var size=$("#as2_"+idb).val();
                var color=$("#as3_"+idb).val();
                
                $("#hidem_"+idb).css("display","none");
                $("#hide_A"+sidb).css("display","none");
                $("#hide_B"+sidb).css("display","inline-block");
                $("#cartdel_"+idb).hide();
            
                $.ajax({
                    url:"cart-item-delete.php",
                    type:"POST",
                    data:{id:pid,size:size,color:color},
                    // dataType: 'json',
                    success:function(data)
                    {
                        if(parseInt($("#cart_quantity").html()) == 0){}else
                        {
                            $("#cart_quantity").html(parseInt($("#cart_quantity").html())-1);
                            $("#cart_quantity2").html(parseInt($("#cart_quantity2").html())-1);
                            $("#cart_quantity3").html(parseInt($("#cart_quantity3").html())-1);
                            
                        }
                        $("#carts").load(location.href + " .cart-sidebar");
                    }
                    
                })

             }
                         else{
                            $.ajax({
                    type: 'post',
                    url: 'quantity_update.php',
                    data: {qty: b, qty_id: qty_id},
                    success: function (data) {
                      $('#qty_'+sidb).val(parseInt(b));
                $("#carts").load(location.href + " .cart-sidebar");
                    }
                  });
                         
                         
                         
                  
                         }
                    }


function del(id) {
// delete this item from cart
    var pid = $("#s1_" + id).val();
    var size = $("#s2_" + id).val();
    var color = $("#s3_" + id).val();

    $("#hidem_" + id).css("display", "none");
    $("#hide_A" + pid).css("display", "none");
    $("#hide_B" + pid).css("display", "inline-block");
    $("#cartdel_" + id).hide();
    $.ajax({
        url: "cart-item-delete.php",
        type: "POST",
        data: {
            id: pid,
            size: size,
            color: color
        },
        // dataType: 'json',
        success: function() {
            if (parseInt($("#cart_quantity").html()) == 0) {} else {
                
                            $("#cart_quantity").html(parseInt($("#cart_quantity").html())-1);
                            $("#cart_quantity2").html(parseInt($("#cart_quantity2").html())-1);
                            $("#cart_quantity3").html(parseInt($("#cart_quantity3").html())-1);
            }
            $("#carts").load(location.href + " .cart-sidebar");
        }

    })
}


// hidden works

function Myvalueput(idall){
    
    
    var size =  idall;
    var size_array = size.split(",");
    var size_id = size_array[0];
    var size_name = size_array[4];
    var p_old_price = size_array[1];
    var p_current_price = size_array[2];
    var p_qty = size_array[3];
    var id =  size_array[5];
    var sid = id+size_id;
    $('#price_c_'+id).html(p_current_price);
    $('#p_current_price_'+id).val(p_current_price);
    $('#size_id_'+id).val(size_id);
    $('#size_name_'+id).val(size_name);
    
    var pic = size_array[6];
    var pic2 =  $('#pic2_'+id).val();
    
    if(pic==''){
        $('#pic_'+id).attr('src', 'assets/uploads/'+pic2);
        $('#p_featured_photo_'+id).val(pic2);
    }
    else
    {
        $('#pic_'+id).attr('src', 'assets/uploads/'+pic);
        $('#p_featured_photo_'+id).val(pic);
    }
    
    $('#qty_'+id).attr('qty', parseInt(p_qty));
    $('#qty2_'+id).attr('qty', parseInt(p_qty));
    $('#price_o_'+id).html(p_old_price);
    $('#p_old_price_'+id).val(p_old_price);
    var a = ((p_old_price-p_current_price)/p_old_price)*100;
    var off = a.toFixed();
    $('#offer_'+id).html(off+' % off');
    // alert(size_id);
    var primaryid = id + size_id;
        
    $('[id^=hide_A'+id+']').css('display','none');
    $('[id^=hide_B'+id+']').css('display','none');
     // alert($('#qty_'+id).attr('qty_id'));
    if($('#hide_A'+primaryid).attr('id2')=='yes'){
        $('#hide_A'+primaryid).css('display','');
    }
    else
    if($('#qty_'+primaryid).attr('qty_id')!=''){
        $('#hide_A'+primaryid).css('display','');
    }
    else
    {
        $('#hide_B'+primaryid).css('display','');
    }
    
}

$(document).ready(function(){
    $('[id^=hide_A]').css('display','none');
    $('[id^=hide_B]').css('display','none');
var numItems = $('.form_value').length;
for(i=0;i<numItems;i++){
    var id = parseInt($('.form_value').eq(i).attr('id2'));
    var size =  $('#size_'+id).val();
    if(size){
    var size_array = size.split(",");
    var size_id = size_array[0];
    var size_name = size_array[4];
    var p_old_price = size_array[1];
    var p_current_price = size_array[2];
    var p_qty = size_array[3];
    $('#price_c_'+id).html(p_current_price);
    $('#p_current_price_'+id).val(p_current_price);
    $('#size_id_'+id).val(size_id);
    $('#size_name_'+id).val(size_name);
    
    $('#qty_'+id).attr('qty', parseInt(p_qty));
    $('#qty2_'+id).attr('qty', parseInt(p_qty));
    $('#price_o_'+id).html(p_old_price);
    $('#p_old_price_'+id).val(p_old_price);
    var a = ((p_old_price-p_current_price)/p_old_price)*100;
    var off = a.toFixed();
    $('#offer_'+id).html(off+' % off');
    var primaryid = id+size_id;
     if($('#hide_A'+primaryid).attr('id2')=='yes'){
            $('#hide_A'+primaryid).css('display','');
        }
        else
        {
            $('#hide_B'+primaryid).css('display','');
        }
    }
}
});







function block() {
    $('#closes').css('display', 'none');
}

var timeout = setTimeout(reloadChat, 10000);
function reloadChat() {
    $('#closes').css('display', 'none');
    timeout = setTimeout(reloadChat, 10000);
}
</script>
      
      
      
      <!-- Bootstrap core JavaScript -->
      <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
      <!-- select2 Js -->
      <script src="vendor/select2/js/select2.min.js"></script>
      <!-- Owl Carousel -->
      <script src="vendor/owl-carousel/owl.carousel.js"></script>
      <!-- Custom -->
      <script src="js/custom.js"></script>
      
      <!-- Data Tables -->
      <link href="vendor/datatables/datatables.min.css" rel="stylesheet" />
      <script src="vendor/datatables/datatables.min.js"></script>
      <script>
         $(document).ready(function() {
             $('.datatabel').DataTable();
         } );
      </script>
      
        <script>
        
        function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();
                
                reader.onload = function (e) {
                    $('#blah').attr('src', e.target.result);
                };
                
                reader.readAsDataURL(input.files[0]);
                
                input.form.submit();
            
            }
        }
        
        </script>
      
      
      
      
      
      
      
      <!--cart items-->
      
      <div id="carts">
        <div class="cart-sidebar ">
         <div class="cart-sidebar-header">
            <h5>
               My Cart <span class="text-success">(<small class="cart-value2" id="cart_quantity2"><?php if(isset($_SESSION['cart_p_id'])) {echo count($_SESSION['cart_p_id']);} else {echo '0';}?></small> item)</span>
               <a  class="float-right" href="#"><i class="mdi mdi-close" onclick="$('body').toggleClass('toggled')"></i></a>
            </h5>
         </div>
         <input id='sonu' type="hidden" value="<?php 
         
            if(isset($_SESSION['cart_p_id'])) {
                 $table_total_price = 0; $i=0;
                    foreach($_SESSION['cart_p_qty'] as $key => $value) 
                    {
                        $i++;
                        $arr_cart_p_qty[$i] = $value;
                    }
                    echo $i;
            } else {
                echo '0';
                }
            ?>">  
					
         
         <?php if(!isset($_SESSION['cart_p_id'])){ ?>
                   <center> <b><?php echo 'Cart is empty'; ?></b></center>
		  <?php } 
		  else { ?>
         <div class="cart-sidebar-body">
             
             <?php
                                        $table_total_price = 0;
                                        $i=0;
                                        foreach($_SESSION['cart_p_id'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_p_id[$i] = $value;
                                        }
                                        $i=0;
                                        foreach($_SESSION['cart_size_id'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_size_id[$i] = $value;
                                        }
                                        $i=0;
                                        foreach($_SESSION['cart_size_name'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_size_name[$i] = $value;
                                        }
                                        $i=0;
                                        foreach($_SESSION['cart_color_id'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_color_id[$i] = $value;
                                        }
                                        $i=0;
                                        foreach($_SESSION['cart_color_name'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_color_name[$i] = $value;
                                        }
                                        $i=0;
                                        foreach($_SESSION['cart_p_qty'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_p_qty[$i] = $value;
                                        }
                                        
                                        $i=0;
                                        foreach($_SESSION['cart_p_current_price'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_p_current_price[$i] = $value;
                                        }
                                        
                                        $i=0;
                                        foreach($_SESSION['cart_p_old_price'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_p_old_price[$i] = $value;
                                        }
                                        
                                        $i=0;
                                        foreach($_SESSION['cart_p_name'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_p_name[$i] = $value;
                                        }
                                        $i=0;
                                        foreach($_SESSION['cart_p_featured_photo'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_p_featured_photo[$i] = $value;
                                        }
                                        ?>
                                        <?php for($i=1;$i<=count($arr_cart_p_id);$i++){ ?>



                                        
                                            <input type="hidden" id="s1_<?php echo $i;?>" value="<?php echo $arr_cart_p_id[$i]; ?>">
                                            <input type="hidden" id="s2_<?php echo $i;?>" value="<?php echo $arr_cart_size_id[$i]; ?>">
                                            <input type="hidden" id="s3_<?php echo $i;?>" value="<?php echo $arr_cart_color_id[$i]; ?>">
                                            <input type="hidden" id="as1_<?php echo $arr_cart_p_id[$i];?>" value="<?php echo $arr_cart_p_id[$i]; ?>">
                                            <input type="hidden" id="as2_<?php echo $arr_cart_p_id[$i];?>" value="<?php echo $arr_cart_size_id[$i]; ?>">
                                            <input type="hidden" id="as3_<?php echo $arr_cart_p_id[$i];?>" value="<?php echo $arr_cart_color_id[$i]; ?>">
                                            <input type="hidden" id="pid_<?php echo $i;?>" name="product_id[]" value="<?php echo $arr_cart_p_id[$i]; ?>">
                                            <input type="hidden" id="pname_<?php echo $i;?>" name="product_name[]" value="<?php echo $arr_cart_p_name[$i]; ?>">
                                            
                                            
                                            
            <div class="cart-list-product" id="hidem_<?php echo $i;?>">
               <div class="row">
                   <div class="col-4"><img class="img-fluid" src="assets/uploads/<?php echo $arr_cart_p_featured_photo[$i]; ?>" alt="<?php echo $arr_cart_p_name[$i]; ?>"></div>
                   <div class="col-8">
                       
                   
               <!--<span class="badge badge-success">50% OFF</span>-->
               <a class="float-right remove-cart" href="#" onclick="del(<?php echo $i;?>)"><i class="mdi mdi-close"></i></a>
               <h5><a href="#"><?php echo $arr_cart_p_name[$i]; ?></a></h5>
               <h6><strong><span class="mdi mdi-approval"></span> Available in</strong> - <?php echo $arr_cart_size_name[$i]; ?></h6>
               <p class="offer-price mb-0">
                    <span><?php echo '&#8377;'.number_format($arr_cart_p_current_price[$i]*$arr_cart_p_qty[$i],2); ?></span>
                    <del class="text-black-50 font-weight-normal"><?php echo '&#8377;'.number_format($arr_cart_p_old_price[$i]*$arr_cart_p_qty[$i],2); ?></del>
                    <br>
                    <span class="text-success font-italic">You save <?php
                    
                    $m =  $arr_cart_p_old_price[$i]*$arr_cart_p_qty[$i];
                    $n = $arr_cart_p_current_price[$i]*$arr_cart_p_qty[$i];
                    $o =  $m-$n;
                    echo '&#8377;';
                    echo number_format($o,2);
                    
                    // calculate total amount
                    $row_total_price = $m;
                    
                    if($table_total_price){
                        $table_total_price = $table_total_price + $row_total_price;
                        $table_total_price_new = $table_total_price_new + $n;
                    }
                    else{
                        $table_total_price=$row_total_price;
                        $table_total_price_new = $n;
                    }
                            
                            
                    ?></span>
                    <br>
                    <span class="text-black-50 font-weight-normal">
                        QTY : <?php echo $arr_cart_p_qty[$i];?>
                    </span>                             
               </p>
               </div>
               </div>
            </div>
            <?php } ?>
            
         </div> <!--cart sidebar body end-->
         
         <?php 
         
         $statement4 = $pdo->prepare("SELECT * FROM tbl_shipping_cost_all WHERE status=? AND  min_amt <= ? AND max_amt >= ?");
                            $statement4->execute(array(1,$table_total_price,$table_total_price));
                            if($statement4->rowCount()){
                            $result4 = $statement4->fetchAll(PDO::FETCH_ASSOC);
                            foreach ($result4 as $row4) {
                                $shipping_cost = $row4['amount'];
                            }
                        
                         
                         
                                $final_total = $table_total_price_new+$shipping_cost;
                            }
                            else{
                                $final_total=$table_total_price_new;
                                $shipping_cost=0;
                            }
                                
                        ?>
         
         
         <div class="cart-sidebar-footer cart-sidebar-footer2">
            <div class="cart-store-details">
                
             <div class="form-group d-none">
                         <label>Have a Coupon Code</label>
                         <div id="message_c2"></div>
                         <div class="input-group">
                             <input class="form-control" type="text" placeholder="Enter Coupon Code" id="enter_coupon_code2">
                             <input type="hidden" id="final_total_c2" value="<?php echo $table_total_price;?>">
                             <span class="input-group-btn">
                                 <button class="btn btn-success btn-lg1" id="apply_coupon_code2" onclick="apply_coupon_code()">Apply</button>
                             </span>
                             
                         </div>
                 </div>
                
             <p>MRP Total - <strong class="float-right"><?php echo LANG_VALUE_1; ?> <?php echo number_format($table_total_price,2); ?></strong></p>
             <p >Discount - <strong class="float-right"><?php echo LANG_VALUE_1; ?> <?php echo $save = number_format($table_total_price-$table_total_price_new,2); ?></strong></p>
            
              <p>Shipping cost - <strong class="float-right"><?php if($shipping_cost==0){ echo 'FREE';}else{ echo LANG_VALUE_1.number_format($shipping_cost,2);} ?></strong></p>
              <p class="d-none">Coupon Discount - 
              <strong class="float-right"  id="discount_c2">
                  <?php 
                  if($_SESSION['discount_percentage']){
                      echo LANG_VALUE_1;
                      echo $ff = ($table_total_price/100)*$_SESSION['discount_percentage'];
                      $gg =  $final_total-$ff-$save;
                      $save = $save+$ff;
                      
                  }
                  else
                  {
                        $gg=$final_total;
                        echo LANG_VALUE_1.'0.00';
                        
                  } 
                  
                  ?></strong>
                </p>
              <p>Total Amount - <strong class="float-right" id="to_pay2"><?php echo LANG_VALUE_1.number_format($gg,2); ?></strong></p>
              <p> <strong class="float-right text-success" id="you_save2">You Save <?php echo LANG_VALUE_1.$save; ?></strong></p>
            </div>
            <a  <?php if(!isset($_SESSION['customer'])){?>href="javascript:void(0);" onclick="alert('Please Login To Continue.')"  data-target="#bd-example-modal"  data-toggle="modal" <?php }else{?> href="checkout.php" <?php }?>>
                <button class="btn btn-secondary btn-lg btn-block text-left" type="button">
                    <span class="float-left">
                        <i class="mdi mdi-cart-outline"></i> Proceed to Checkout 
                    </span>
                    <span class="float-right">
                        <strong><?php echo LANG_VALUE_1; ?>  <?php echo number_format($gg,2); ?></strong>
                        <span class="mdi mdi-chevron-right"></span>
                    </span>
                </button>
            </a>
         </div>
         
         <?php } ?>
      </div>
      
      </div>
      <!--cart-->
      
      
   </body>
</html>

  
  <!-- Modal for sizes -->
       <div class="modal fade login-modal-main" id="sizeModal">
         <div class="modal-dialog modal-md modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                                        <h6 class="modal-title">Available Quantities for <b id="av_pname"></b></h6>
                    <button type="button" class="close close-top-right" data-dismiss="modal" aria-label="Close">
                       <span aria-hidden="true"><i class="mdi mdi-close"></i></span>
                       <span class="sr-only">Close</span>
                    </button>
                </div>
               <div class="modal-body">
                                        <div id="loop" class="text-center"></div>
                                       
               </div>
            </div>
         </div>
      </div>
      
      

<script>
    function check_size(pid){
        $('#sizeModal').modal('show');
        var av_p_name = $('#p_name_'+pid).val();
        $('#av_pname').html(av_p_name);
        
             $.ajax({
                type: "POST",
                url: "size.php",
                data:{id: pid},
                success: function(data){
                    $('#loop').html(data);
                }
             });
        
    }
</script>
<!--sizes end-->
  
  
  
  