<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap.min.css" />
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<section role="main" class="content-body">
					<header class="page-header">
						<h2>Manage Products</h2>
					
						<div class="right-wrapper pull-right">
							<ol class="breadcrumbs">
								<li>
									<a href="<?php echo base_url();?>admin">
										<i class="fa fa-home"></i>
									</a>
								</li>
								<li><span>Manage Products</span></li>
							</ol>
					
						</div>
					</header>
					<div class="row">
                    <div class="col-md-12">
                     <div class="panel panel-featured">
							
      <div class="panel-heading">Listing All Products</div>
      <div class="panel-body">
            <table class="table table-bordered table-striped mb-none" id="datatable-default">
        	<thead>
												<tr>
													<th>S.No.</th>
													<th>Photo</th>
													<th>Title</th>
													<th>Category</th>
													<th>Total Purchase</th>
													<th>Action</th>
												</tr>
											</thead>
			<tbody>
                                            <?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">
                                <h4><?php echo $myad->title;?></h4>
                                <span>ImgID: IMG<?php echo $myad->pid;?><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">Trending</span><?php }else{echo "Trending";}?></span>
                            </td>
                            <td data-title="Category"><span class="tg-adcategories"><?php 
$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($cat)){
echo $cat->cat_name.'-'.$scat->subcat_name;}else{echo "Free Vector";}?></span></td>
                        <td>
                          <a href="#" class="btn btn-xs btn-success"><i class="fa fa-shopping-cart"> <?php echo $this->db->get_where("order_items",array("pid"=>$myad->pid))->num_rows();?> Purchase</i></a>
                        </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-xs btn-default enable"><?php echo $st;?></a>
    <a class="btn btn-xs btn-warning" href="<?php echo base_url();?>admin/add_product/<?php echo $myad->pid;?>"><i class="fa fa-edit"></i></a>
    <a class="btn btn-xs btn-danger pro_delete" href="<?php echo $myad->pid;?>"><i class="fa fa-trash-o"></i></a>
  
</div>
                        </td>
												</tr>
                                            <?php $i++;}?>
                                            </tbody>
        </table>
        </div></div>
                    </div>
                </div>
				</section>
			</div>

			
		</section>

		<!-- Vendor -->
        <script>
	$(document).ready(function(){
	    $('#example').DataTable();
		$(".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);
							 }
							 });
						});
		$(".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>
		<script src="<?php echo base_url();?>admin_assets/vendor/jquery-browser-mobile/jquery.browser.mobile.js"></script>
		<script src="<?php echo base_url();?>admin_assets/vendor/bootstrap/js/bootstrap.js"></script>
		<script src="<?php echo base_url();?>admin_assets/vendor/nanoscroller/nanoscroller.js"></script>
		<script src="<?php echo base_url();?>admin_assets/vendor/jquery-placeholder/jquery.placeholder.js"></script>
		
		<!-- Theme Base, Components and Settings -->
		<script src="<?php echo base_url();?>admin_assets/javascripts/theme.js"></script>
		
		<!-- Theme Custom -->
		<script src="<?php echo base_url();?>admin_assets/javascripts/theme.custom.js"></script>
		
		<!-- Theme Initialization Files -->
		<script src="<?php echo base_url();?>admin_assets/javascripts/theme.init.js"></script>

	</body>
</html>