<?php 
include('header.php');

if(isset($arr_cart_p_id2)){$arr_cart_p_id2=$arr_cart_p_id2;}else{$arr_cart_p_id2=array();}
if(isset($arr_cart_size_id2)){$arr_cart_size_id2=$arr_cart_size_id2;}else{$arr_cart_size_id2=array();}
$f=0;
?>
  <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="<?=base_url();?>"><strong><span class="mdi mdi-home"></span> Home</strong></a>
						<span class="mdi mdi-chevron-right"></span> <a href="#"><?=LANG_VALUE_51; ?> <?=(isset($page)) ?  strtoupper($page) :''; ?></a>
					</div>
				</div>
			</div>
		</section>
		
        
<section class="product-items-slider section-padding">
         <div class="container">
            <div class="section-header">
               <h5 class="heading-design-h5 text-center"> <?=(isset($page)) ?  strtoupper($page) :''; ?> <span class="badge badge-warning">Trending</span>
               </h5>
            </div>
            <div class="row">
                    <?php
                        $query11 = $this->db->query('select * from tbl_product where p_is_active=1 and p_is_featured=1 order by p_id limit 50');
                        if(count($query11->result_array())){
                            foreach ($query11->result_array() as $row) {
                    ?>
                        <div class="col-6 col-sm-6 col-md-4 col-lg-3 col-xl-2 mt-5  mb-10 item" loading="lazy" id="pid_2_<?=$row['p_id']; ?>">
                          <div class="product">
                              <a href="<?=base_url('product_view');?>?id=<?=$row['p_id']; ?>">
                                <div class="product-header">
                                    <span class="badge badge-success" <?='id="offer_'.$row['p_id'].'"'; ?> >0 % OFF</span>
                                   
                                   <img class="img-fluid" id="pic_<?=$row['p_id']; ?>" src="<?=base_url('uploads/shop/product/'.$row['p_featured_photo']); ?>" alt="<?=$row['p_name']; ?>">
                                   <input type="hidden" id="pic2_<?=$row['p_id']; ?>" value="<?= $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"><?=$row['p_name']; ?></h5>
                                   <h6><strong><span class="mdi mdi-approval"></span> Available in</strong> - </h6>
                                </div>
                                </a>
                                <div class="product-footer">
                                    <p>
                                    <?php
                                        $i=1;
                                        $pid=$row['p_id'];
                                        $query_product_size = $this->db->query("select * from tbl_product_size where p_id = $pid");
                                        foreach ($query_product_size->result_array() as $row2) {
                                            $size_id = $row2['size_id'];
                                            $query3 = $this->db->query("select * from tbl_size where size_id = $size_id ");
                                            if($query3->num_rows() > 0){
                                            foreach ($query3->result_array() 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_<?=$row['p_id']; ?>"  id2="<?=$row['p_id']; ?>" onclick="check_size(<?=$row['p_id']; ?>);" class="form-control input-sm" value='<?=$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_<?=$row['p_id']; ?>"
                                                    class="form_value" 
                                                    value="<?=$size_id; ?>,<?=$p_old_price;?>,<?=$p_current_price;?>,<?=$p_qty;?>,<?=$size_name;?>,<?=$row['p_id']; ?>"
                                                    id2="<?=$row['p_id']; ?>" />
                                           <?php
                                                }
                                                
                                                $i++;
                                            }
                                            }
                                            else{
                                                ?>
                                                <script>
                                                    $('#pid_2_<?=$row['p_id']; ?>').remove();
                                                </script>
                                                <?php
                                            }
                                        }
                                    ?>
                                    </p>
                                   <p class="offer-price mb-0">
                                       &#8377;<b id="price_c_<?=$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_<?=$row['p_id']; ?>"><?=$p_old_price; ?></b></span><?php } ?>
                                   
                                   </p>
                                        <!--Product Size start-->
                                    <?php 
                                        if($p_qty >= 1){
                                    ?>
                                        <input type="hidden" name="p_current_price" id="p_current_price_<?=$row['p_id']; ?>" value="<?=$p_current_price; ?>">
                                        <input type="hidden" name="p_old_price" id="p_old_price_<?=$row['p_id']; ?>" value="<?=$p_old_price; ?>">
                                        <input type="hidden" name="p_name" id="p_name_<?=$row['p_id']; ?>" value="<?=$row['p_name']; ?>">
                                        <input type="hidden" name="size_id" id="size_id_<?=$row['p_id']; ?>" value="<?=$size_id; ?>">
                                        <input type="hidden" name="size_name" id="size_name_<?=$row['p_id']; ?>" value="<?=$size_name; ?>">
                                        <input type="hidden" name="p_featured_photo" id="p_featured_photo_<?=$row['p_id']; ?>" value="<?= $row['p_featured_photo']; ?>">
                                        
                                        <?php  
                                            $count=0; 
                                            $query21 = $this->db->query("select * from tbl_product_size where p_id = $pid");
                                            foreach ($query21->result_array() 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="<?=$count;?>" id="hide_A<?=$primary_id; ?>">
                                                    <button class="btn btn-md input-group-btn bg-theme-color" onclick="minus(<?=$row['p_id'].','.$primary_id; ?>)">-</button>
                                                    <input type="text" name="quantity" class="form-control input-type text-center" qty_id="<?=$l;?>" id="qty_<?=$primary_id; ?>"
                                                    qty="<?=$row2['p_qty']; ?>" readonly value="<?=$arr_cart_p_qty2[$l];?>" >
                                                    <button class="btn btn-md input-group-btn bg-theme-color" onclick="plus(<?=$row['p_id'].','.$primary_id; ?>)">+</button>
                                                </div>
                                                
                                                <input id="qty2_<?=$primary_id; ?>"  qty="<?=$row2['p_qty']; ?>" type="hidden" value="1"/>
                                                <button type="button" id2="no" id3="<?=$count;?>" id="hide_B<?=$primary_id; ?>" style="display:none" class="btn  btn-secondary btn-sm" onclick="add(<?=$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="<?=$count;?>" id="hide_A<?=$primary_id; ?>" style="display:none">
                                                <button class="btn btn-md input-group-btn bg-theme-color" onclick="minus(<?=$row['p_id'].','.$primary_id; ?>)">-</button>
                                                <input type="text" readonly name="quantity" class="form-control input-type text-center " qty_id="<?=$l;?>" id="qty_<?=$primary_id; ?>"
                                                qty="<?=$row2['p_qty']; ?>"  value="1" >
                                                <button class="btn btn-md input-group-btn bg-theme-color " onclick="plus(<?=$row['p_id'].','.$primary_id; ?>)">+</button>
                                                </div>
                                                <input id="qty2_<?=$primary_id; ?>"  qty="<?=$row2['p_qty']; ?>" type="hidden" value="1" />
                                                <button type="button" id2="no1" id3="<?=$count;?>" id="hide_B<?=$primary_id; ?>" class="btn btn-secondary btn-sm" onclick="add(<?=$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 } ?>
                                        <!--Product Size end-->
                                </div>
                          </div>
                       </div>
                        <?php }
                        } else {
                            ?>
                            <div class="col-md-12 text-center">
                                <img src="<?=base_url('uploads/no_product_found.png');?>" class="img-fluid" />
                            </div>
                            <?php
                        }
                        ?>
            </div>
         </div>
      </section>


<?php include('footer.php');?>