<?php  $i=1;foreach($customers as $user){?>
<tr>
<td><?php echo $i;?></td>

                                                <td><?php echo date("d M Y",strtotime($user->created));?></td>


                                                <td><i class="fa fa-user"></i> <?php echo $user->first_name.' '.$user->last_name;?></td>

                                                <td><i class="fa fa-envelope"></i> <?php echo $user->email;?><br/>
                                                	<i class="fa fa-phone"></i> <?php echo $user->mobile;?></td>
<td><?php echo $this->db->get_where("orders",array("userid"=>$user->id))->num_rows();?></td>
<td><?php $this->db->select_sum('ototal');  
								  //$this->db->where("ostatus","Completed"); 
								  $this->db->where("userid",$user->id); 
       							  $total_orders=$this->db->get('orders')->row();echo $total_orders->ototal;?></td>
                                                <td><a target="_new" href="<?php echo base_url();?>admin/orders/<?php echo $user->id;?>" class="btn btn-sm btn-success">(<?php echo $this->db->get_where("orders",array("userid"=>$user->id))->num_rows();?>) View Orders</a> <a class="btn btn-sm btn-danger userdel" href="<?php echo $user->id;?>"><i class="fa fa-trash-o"></i></a></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);
							 }
							 });
						});
		$(".userdel").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/userdel',
							 data: {id:id},
							 success: function(response){
								 //alert(response);
							 }
							 });
		});
	});
</script>