<?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>

<label class="badge badge-warning"><?php echo $myad->brand;?></label><br/>

<input type="checkbox" name="in_trend" <?php if($myad->feat!=""){echo "checked";}?> value="<?php echo $myad->pid;?>" class="in_feat" /> <?php if($myad->feat!=""){?><span class="label label-warning">Featured</span><?php }else{echo "Featured";}?></span>

</td>

<td><?php 

//$mcat=$this->db->get_where("mcategory",array("mid"=>$myad->mid))->row();



echo '<b class="text-success">'.$myad->mcat_name.'</b><br/>';
?></td>

<td><?php $pvs=$this->db->get_where("prod_variants",array("pid"=>$myad->pid))->result();

foreach($pvs as $pv){?>

<label class="badge badge-success"><?php echo $pv->ppieces.' units of '.$pv->pptype.' @ '.$pv->pmrp;?>/-</label><br/><?php }

 if($myad->prod_type=="Variant"){?>

<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 }?></td>

<td data-title="Action">

<div class="tg-btnsactions">

<?php if($myad->pstatus==""){$st="Disable";}else{$st="Enable";}?>

<a href="<?php echo $myad->pid;?>" class="btn btn-sm btn-default enable"><?php echo $st;?></a>

<a class="btn btn-sm btn-warning" href="<?php echo base_url().'admin/add_product/'.$myad->pid;?>"><i class="fa fa-edit"></i></a>

<a class="btn btn-sm btn-danger pro_delete" href="<?php echo $myad->pid;?>"><i class="fa fa-trash-o"></i></a>



</div>

</td>

    </tr>

<?php $i++;}?>

<script>

	$(document).ready(function(){

		//$(".deal_pro").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();?>admin/deal_pro',

//							 data: {pid:pid},

//							 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();?>admin/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();?>admin/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();?>admin/in_feat',

							 data: {v:v,id:id},

							 success: function(response){

								// alert(response);

							 }

							 });

						});

						$(".buy_now").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();?>admin/buy_now',

							 data: {v:v,id:id},

							 success: function(response){

								// alert(response);

							 }

							 });

						});

						$(".autoclone").click(function(){

							var totc=$('input.autoclone:checked').length;

							if(totc>4){alert("Maximum 4 Auctions can be set in Autoclone");return false;}

							//alert(totc);

							var id=$(this).val();

							var v="";

							if ($(this).is(':checked')) {

								var v='yes';

							}

							//alert(v);

							$.ajax({

							 type: "POST",

							 url: '<?php echo base_url();?>admin/autoclone',

							 data: {v:v,id:id},

							 success: function(response){

							//	alert(response);

							 }

							 });

						});

		$(".pro_delete").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();?>admin/pro_delete',

							 data: {id:id},

							 success: function(response){

								 //alert(response);

							 }

							 });

		});

	});

</script>