<?php  $i=1;foreach($products as $myad){?>
<tr data-category="active">
        <td data-title=""><?php echo $i;?></td>
<td data-title="Photo"><img style="width:100px;" src="<?php echo base_url();?>assets/images/products/<?php echo $myad->img;?>" alt=""></td>
<td data-title="Title">
<h5><?php echo substr($myad->title,0,20);?></h5>
<input type="checkbox" name="in_trend" <?php if($myad->pin_feat!=""){echo "checked";}?> value="<?php echo $myad->prod_id;?>" class="in_feat" /> <?php if($myad->pin_feat!=""){?><span class="label label-warning">Featured</span><?php }else{echo "Featured";}?></span><br/>

<?php 
$mcat=$this->db->get_where("mcategory",array("mid"=>$myad->mid))->row();
$cat=$this->db->get_where("category",array("cid"=>$myad->cid))->row();//print_r($cat);
$scat=$this->db->get_where("subcategory",array("sid"=>$myad->sid))->row();
if(!empty($mcat)){
echo '<b class="text-success">'.$mcat->mcat_name.'</b><br/>';}
if(!empty($cat)){
echo '<b class="text-info">'.$cat->cat_name.'</b><br/>';}
if(!empty($scat)){echo $scat->subcat_name;;}?></span></td>
<td><?php echo $myad->pptype;?></td>
<td><?php echo $myad->pmrp;?></td>
<td><?php echo $myad->selling_price;?></td>
<td width="100px"><input type="number" class="form-control update_qty" id="<?php echo $myad->stock_id;?>" value="<?php echo $myad->stock_qty;?>" /></td>
<td>
<a href="#" title="<?php echo $myad->title;?>" id="<?php echo $myad->pid;?>" class="btn btn-sm btn-info variants" data-toggle="modal" data-target="#myModal"><i class="fa fa-plus"></i> ADD</a>
<?php if($myad->prod_status==""){$st="Disable";}else{$st="Enable";}?>
<a href="<?php echo $myad->stock_id;?>" class="btn btn-sm btn-default enable"><?php echo $st;?></a>
<a class="btn btn-sm btn-danger pro_remove" href="<?php echo $myad->stock_id;?>"><i class="fa fa-trash-o"></i></a>
</td>
    </tr>
<?php $i++;}?>
<script>
	$(document).ready(function(){
		$(".pro_remove").click(function(e){e.preventDefault();
		if (!confirm("Sure you want to delete?")){
				  return false;
				}
			var id=$(this).attr("href");$(this).closest("tr").remove();
			$.ajax({
							 type: "POST",
							 url: '<?php echo base_url();?>store/pro_remove_store',
							 data: {id:id},
							 success: function(response){
								 //alert(response);
							 }
							 });
		});
		$(".update_qty").keyup(function(){
			var qty=$(this).val();
			var id=$(this).attr('id');
			$.ajax({
					 type: "POST",
					 url: '<?php echo base_url();?>store/ajax_update_qty',
					 data: {qty:qty,id:id},
					 success: function(response){
						 //alert(response);
						 //$(".modal-body").html(response);
					 }
			});
		});
		$(".variants").click(function(e){e.preventDefault();
			$(".modal-body").html("<h2>Loading...</h2>");
			var pid=$(this).attr("id");
			var title=$(this).attr("title");
			$(".modal-title").text(title);
			$.ajax({
							 type: "POST",
							 url: '<?php echo base_url();?>store/ajax_pvariants',
							 data: {pid:pid},
							 success: function(response){
								 //alert(response);
								 $(".modal-body").html(response);
							 }
							 });
		});
		$(".enable").click(function(e){e.preventDefault();
			var st=$(this).text();
			var id=$(this).attr("href");
			if(st=="Enable"){
			$(this).text("Disable");
			}else{
			$(this).text("Enable");	
			}
			$.ajax({
							 type: "POST",
							 url: '<?php echo base_url();?>store/proenable',
							 data: {id:id,st:st},
							 success: function(response){
								 //alert(response);
							 }
							 });
		});
		$(".in_feat").click(function(){
							var id=$(this).val();
							var v="";
							if ($(this).is(':checked')) {
								var v='yes';
							}
							//alert(v);
							$.ajax({
							 type: "POST",
							 url: '<?php echo base_url();?>store/in_feat',
							 data: {v:v,id:id},
							 success: function(response){
								// alert(response);
							 }
							 });
						});
	});
</script>