<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 Category</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 Category</span></li>
							</ol>
					
						</div>
					</header>

					<div class="row">
						<div class="col-md-5">
                        <?php if($this->session->flashdata("msg")){echo $this->session->flashdata("msg"); }?>
							<section class="panel panel-featured">
								<div class="panel-heading">Add New Category</div>
								<div class="panel-body">
      
      <?php if($this->uri->segment(3)){?>
    <form  action="<?php echo base_url();?>admin/add_category/<?php echo $this->uri->segment(3);?>" method="post" enctype="multipart/form-data">
       	  <div class="form-group ">
            <label for="email">Choose Main Category</label>
          	<select class="form-control" name="mcat">
            	<option value="">Choose Main Category</option>
                <?php $mcat=$this->db->get("mcategory")->result();
					foreach($mcat as $cat){?>
                <option value="<?php echo $cat->mid;?>" <?php if($editcat->mid==$cat->mid){echo "selected";}?>><?php echo $cat->mcat_name;?></option>
                <?php }?>
            </select>
          </div>
          <div class="form-group ">
            <label for="email">Category Title</label>
            <input type="text" required class="form-control" name="cat" value="<?php echo $editcat->cat_name;?>">
          </div>
          <div class="form-group ">
            <label for="email">Meta Title</label>
            <input type="text"  class="form-control" name="metatitle" value="<?php echo $editcat->metatitle;?>">
          </div>
          <div class="form-group ">
            <label for="email">Meta Keywords</label>
            <input type="text"  class="form-control" name="metakey" value="<?php echo $editcat->metakey;?>">
          </div>
          <div class="form-group ">
            <label for="email">Meta Description</label>
            <textarea class="form-control" rows="3" name="metadesc"><?php echo $editcat->metadesc;?></textarea>
          </div><div class="form-group ">
            <label for="email">Category Image</label>
          	<input type="hidden" value="<?php echo $editcat->cat_image;?>" name="oldimg">
            <input type="file"  class="btn btn-primary" name="img"/>
            <img width="30%" src="<?php echo base_url();?>assets/images/category/<?php echo $editcat->cat_image;?>" class="img img-responsive">
          </div><br/>
          <button type="submit" class="btn btn-success" name="submit">Update</button>
        </form>
      <?php }else{?>
      	<form  action="<?php echo base_url();?>admin/add_category" method="post" enctype="multipart/form-data">
          <div class="form-group ">
            <label for="email">Choose Main Category</label>
          	<select class="form-control" name="mcat">
            	<option value="">Choose Main Category</option>
                <?php $mcat=$this->db->get("mcategory")->result();
					foreach($mcat as $cat){?>
                <option value="<?php echo $cat->mid;?>"><?php echo $cat->mcat_name;?></option>
                <?php }?>
            </select>
          </div>
          <div class="form-group ">
            <label for="email">Category Title</label>
            <input type="text" required class="form-control" name="cat">
          </div>
         
          <div class="form-group ">
            <label for="email">Meta Title</label>
            <input type="text"  class="form-control" name="metatitle">
          </div>
          <div class="form-group ">
            <label for="email">Meta Keywords</label>
            <input type="text"  class="form-control" name="metakey">
          </div>
          <div class="form-group ">
            <label for="email">Meta Description</label>
            <textarea class="form-control" rows="3" name="metadesc"></textarea>
          </div><div class="form-group ">
            <label for="email">Cateogory Image</label>
          <input type="file" name="img" class="btn btn-default"/></div><br/>
          <button type="submit" class="btn btn-success" name="submit">Add Category</button>
        </form>
        <?php }?>
      </div>
							</section>
						</div>
                        <div class="col-md-7">
							<section class="panel panel-featured">
								<div class="panel-heading">Listing All Category</div>
								
     							 <div class="panel-body">
      <form action="<?php echo base_url();?>admin/csort" method="post">
                     <table class="table table-striped table-responsive table-bordered dataTable" id="example">
        	<thead><tr><th>Sort.</th><th>Image</th><th>Title/M-category</th><th>Action</th></tr></thead>
            <tbody>
            	<?php $i=1;foreach($cats as $cat){?>
                <tr><td width="80px"><input type="number" class="form-control" value="<?php echo $cat->csort;?>" name="<?php echo $cat->cid;?>" /></td>
                <td width="100px"><img src="<?php echo base_url();?>assets/images/category/<?php echo $cat->cat_image;?>" class="img img-responsive"></td>
                <td><?php echo $cat->cat_name;?><br/>
                <?php $sc=$this->db->get_where("mcategory",array("mid"=>$cat->mid))->row();
				if($sc){echo '<label class="label label-success">'.$sc->mcat_name.'</label>';}?><br/>
                <input type="checkbox" name="in_trend" <?php if($cat->in_trend!=""){echo "checked";}?> value="<?php echo $cat->cid;?>" class="in_trend" /> In Trend</td>
                <td>
                <?php if($cat->cat_status==""){$st="Disable";}else{$st="Enable";}?>
                <a href="<?php echo $cat->cid;?>" class="btn btn-xs btn-default enable"><?php echo $st;?></a>
                <a href="<?php echo base_url();?>admin/category/<?php echo $cat->cid;?>" class="btn btn-xs btn-warning"><i class="fa fa-edit"></i></a>
                	<a href="<?php echo $cat->cid;?>" id="<?php echo $cat->cat_image;?>" class="btn btn-xs btn-danger catdelete"><i class="fa fa-trash-o"></i></a></td>
                <?php $i++;}?></tr>
                <tr><td><button type="submit" class="btn btn-default">Sort</button></td><td></td><td></td><td></td></tr>
            </tbody>
        </table></form>
        </div>
        						</div>
							</section>
						</div>
						
                    </div>
				</section>
			</div>

			
		</section>

		<!-- Vendor -->
        <script>
	$(document).ready(function(){ $('#example').DataTable({ "lengthChange": false,"dom": '<"pull-left"f><"pull-right"l>tip'});
	$(".in_trend").click(function(){
		var id=$(this).val();
		var v="";
		if ($(this).is(':checked')) {
			var v=$(this).val();
		}
		//alert(v);
		$.ajax({
		 type: "POST",
		 url: '<?php echo base_url();?>admin/in_trendcat',
		 data: {v:v,id:id},
		 success: function(response){
			// alert(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/catenable',
							 data: {id:id,st:st},
							 success: function(response){
								 //alert(response);
							 }
							 });
		});
		$(".catdelete").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/catdelete',
							 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>