<?php  $this->load->view('master/common/header.php',$data);
$base_name = $data['base_name'];
$shop = $data['shop'];
$mlm = $data['mlm'];
if($shop == 0){ $dpcol = 'd-none'; } else { $dpcol = ''; }
if($mlm == 0){ $pvcol = 'd-none'; } else { $pvcol = ''; }

?>

    <div class="content">
        
        <!-- Start Content-->
        <div class="container-fluid">
            
            <!-- start page title -->
            <div class="row">
                <div class="col-12">
                    <div class="page-title-box">
                        <div class="page-title-right">
                            <ol class="breadcrumb m-0">
                                <li class="breadcrumb-item"><a href="javascript: void(0);"><?= $base_name;?></a></li>
                                <li class="breadcrumb-item active text-capitalize"><?= $page;?></li>
                            </ol>
                        </div>
                        <h4 class="page-title text-uppercase"><?= $page;?></h4>
                    </div>
                </div>
            </div>     
            <!-- end page title --> 

            <div class="row">
                <div class="col-md-12 col-xl-12">
                    <div class="card-box">
                        <div class="row">
                            <div class="col-sm-12">
							    <table id="datatable" class="table table-bordered table-responsive">
                                    <thead>
                                        <tr>
                                            <th>S.no.</th>
            								<th>Photo</th>
            								<th>Product Name</th>
            								<th>Product Details  (Size,Old Price, Current Price,Quantity)</th>
            								<th>Is Featured?</th>
            								<th>Is Today's  Best Deal?</th>
            								<th>Is Active?</th>
            								<th>Category</th>
            								<th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        
								<?php if (!empty($product)) {
								    $i=0;
								    foreach ($product as $row) {
									    $i++;
									    $p_id = $row['p_id'];
									?>
								        <tr>
                                            <td><?= $i;?></td>
        									<td>
                                                <?php
                                                    if(!empty($row['p_featured_photo']) && file_exists('./uploads/shop/product/'.$row['p_featured_photo'])){
                                                ?>
                                                    <img src="<?=base_url('uploads/shop/product/'.$row['p_featured_photo']);?>" class="img-fluid" width="60" />
                                                <?php 
                                                    } else{
                                                ?>
                                                    <img src="<?=base_url('uploads/no-image.png');?>" class="img-fluid" width="60" />
                                                <?php
                                                    }
                                                ?>
                                                </td>
                                                <td><?= $row['p_name'];?></td>
                                                <td>
                                                    <?php
                                                    if(!empty($product_size)){
                                                        $y=0;
                                                        foreach($product_size as $row2){
                                                            if($row2['p_id'] == $p_id){
                                                                $y++;
                                                                    echo $y.'. ';
                                                                    echo 'Size: ';
                                                                    echo $row2['size_name'];
                                                                    echo '; Color: ';
                                                                    echo $row2['color_id'];
                                                                    echo '; Old Price: &#8377;';
                                                                    echo $row2['p_old_price'];
                                                                    echo '; Current Price: &#8377;';
                                                                    echo $row2['p_current_price'];
                                                                    echo '; DP Price: &#8377;';
                                                                    echo $row2['p_dp_price'];
                                                                    echo '; PV: &#8377;';
                                                                    echo $row2['p_pv'];
                                                                    echo '; QTY: ';
                                                                    echo $row2['p_qty'];
                                                                    echo ' &nbsp;&nbsp; | &nbsp;&nbsp;<hr>';
                                                            }
                                                        }
                                                    }
                                                    ?>
                                                </td>
        									<td>
        										<?php if ($row['p_is_featured'] == 1) { ?>
            										<form class="form-horizontal" action="<?= base_url('master/product/update2');?>" method="post" enctype="multipart/form-data">
                                                        <input type="hidden" name="p_is_featured" value="0" />
                                                        <input type="hidden" name="todays_best_deal" value="1" />
                                                        <input type="hidden" name="pid" value="<?=$row['p_id'];?>" />
                                                        <button type="submit" class="btn btn-success btn-sm" title="Yes">Yes</button>
            										</form>
        										<?php } else if ($row['p_is_featured'] == 0) { ?>
            										<form class="form-horizontal" action="<?= base_url('master/product/update2');?>" method="post" enctype="multipart/form-data">
                                                        <input type="hidden" name="p_is_featured" value="1" />
                                                        <input type="hidden" name="todays_best_deal" value="0" />
                                                        <input type="hidden" name="pid" value="<?=$row['p_id'];?>" />
                                                        <button type="submit" class="btn btn-danger btn-sm" title="No">No</button>
            										</form>
        										<?php }?>
        									</td>
        									<td>
        										<?php if ($row['todays_best_deal'] == 1) { ?>
            										<form class="form-horizontal" action="<?= base_url('master/product/update2');?>" method="post" enctype="multipart/form-data">
                                                        <input type="hidden" name="p_is_featured" value="1" />
                                                        <input type="hidden" name="todays_best_deal" value="0" />
                                                        <input type="hidden" name="pid" value="<?=$row['p_id'];?>" />
                                                        <button type="submit" class="btn btn-success btn-sm" title="Yes">Yes</button>
            										</form>
        										<?php } else if ($row['todays_best_deal'] == 0) { ?>
            										<form class="form-horizontal" action="<?= base_url('master/product/update2');?>" method="post" enctype="multipart/form-data">
                                                        <input type="hidden" name="p_is_featured" value="0" />
                                                        <input type="hidden" name="todays_best_deal" value="1" />
                                                        <input type="hidden" name="pid" value="<?=$row['p_id'];?>" />
                                                        <button type="submit" class="btn btn-danger btn-sm" title="No">No</button>
            										</form>
        										<?php }?>
        									</td>
        									<td>
        									         
                                                        
                                                        
        										<?php if ($row['p_is_active'] == 1) { ?>
            									<button class="btn btn-success btn-sm" id="change_<?= $p_id ?>" onclick="changests(<?= $p_id ?>)" >Yes</button>
        										<?php } else if ($row['p_is_active'] == 0) { ?>
                                                <button class="btn btn-danger btn-sm"  id="change_<?= $p_id ?>" onclick="changests(<?= $p_id ?>)">No</button>
        										<?php }?>
        									</td>
        									<td><?='('.$row['tcat_name'].')<br>'.'('.$row['mcat_name'].')<br>'.'('.$row['ecat_name'].')'; ?></td>
        									<td>
        									    <a href="<?php echo base_url().'master/product/edit/'.$row['p_id'];?>" class="btn btn-primary btn-sm" title="Edit">
        									        <i class="far fa-edit"></i> Edit
        									    </a>
									            <form class="form-horizontal" onsubmit="return deleteProduct();" action="<?= base_url('master/product/delete');?>" method="post" enctype="multipart/form-data">
                                                    <input type="hidden" name="pid" value="<?=$row['p_id'];?>" />
                                                    <button type="submit" class="btn btn-danger btn-sm" title="Delete">Delete</button>
        										</form>
        									</td>
        								</tr>
								<?php }?>
								<?php } else {?>
								<tr>
									<td colspan="5" class="text-center">Records Not Found</td>
								</tr>
								<?php }?>
							</tbody>
							</table>
							</div>
					    </div>
					</div>
				</div>
				<!-- /.col-md-6 -->
			</div>
			<!-- /.row -->
		</div>
		<!-- /.container-fluid -->
	</div>
	<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<?php $this->load->view('master/common/footer.php'); ?>
<script>
    $(document).ready(function() {
    $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            {
                extend: 'copyHtml5',
                exportOptions: {
                    columns: [ 0, ':visible' ]
                }
            },
            {
                extend: 'excelHtml5',
                exportOptions: {
                    columns: ':visible'
                }
            },
            {
                extend: 'pdfHtml5',
                exportOptions: {
                    columns: ':visible'
                }
            },
            {
                extend: 'csvHtml5',
                exportOptions: {
                    columns: ':visible'
                }
            },
            'colvis'
        ]
    } );
} );
</script>
<style>
    button.dt-button {
    background: linear-gradient(
45deg
, #000000ba, #723d01);
    color: #fff;
    border-radius: 30px;
    padding: 5px 15px;
}
div.dt-button-collection button.dt-button:active:not(.disabled), div.dt-button-collection button.dt-button.active:not(.disabled), div.dt-button-collection div.dt-button:active:not(.disabled), div.dt-button-collection div.dt-button.active:not(.disabled), div.dt-button-collection a.dt-button:active:not(.disabled), div.dt-button-collection a.dt-button.active:not(.disabled){
    background: linear-gradient(to bottom, var(--green) 0%, #006b56 100%);
}

button.dt-button:hover:not(.disabled), div.dt-button:hover:not(.disabled), a.dt-button:hover:not(.disabled), input.dt-button:hover:not(.disabled){
    background: linear-gradient(to bottom, var(--yellow) 0%, var(--orange) 100%);
}
</style>
<script type="text/javascript">
	function deleteProduct() {
		if (confirm("Are You Sure You Want TO Delete Product ?")) {
            return true;
		}
		return false;
	}
</script>

<script>
   function changests(id){
        $.post("<?= base_url('master/product/update3');?>",
          {
              id: id
          },
          function(data){
            if(data == 1){
                    $('#change_'+id).html('Yes');
                    $('#change_'+id).toggleClass('btn-danger');
                    $('#change_'+id).toggleClass('btn-success');
            }
            if(data == 0){
                    $('#change_'+id).html('No');
                    $('#change_'+id).toggleClass('btn-success');
                    $('#change_'+id).toggleClass('btn-danger');
            }
          });
    }
</script>