<link href="<?php echo base_url();?>adminassets/plugins/dataTables/css/jquery.dataTables.html" rel="stylesheet" type="text/css">
<link href="<?php echo base_url();?>adminassets/plugins/dataTables/css/dataTables.bootstrap.css" rel="stylesheet" type="text/css"> 	
<div class="vd_content-wrapper">
      <div class="vd_container">
        <div class="vd_content clearfix">
          <div class="vd_head-section clearfix">
            <div class="vd_panel-header">
              <ul class="breadcrumb">
                <li><a href="<?php echo base_url();?>admin">Home</a> </li>
                <li class="active">SubCategories</li>
              </ul>
              
 
            </div>
          </div>
          <!-- vd_head-section -->
          
          <div class="vd_title-section clearfix">
            <div class="vd_panel-header">
              <h1>Manage SubCategories</h1>
              <small class="subtitle">Add, Edit Delete SubCategories</small>
              
<!-- vd_panel-menu --> 
            </div>
            <!-- vd_panel-header --> 
          </div>
          <!-- vd_title-section -->
          
          <div class="vd_content-section clearfix">
            
         <div class="row">
                	
                    
                    <!-- User Activity -->
                    <div class="col-md-5">
                        <div class="panel panel-success">
							
      <div class="panel-heading">Add/Edit SubCategories</div>
      <div class="panel-body">
      <form action="<?php echo base_url();?>admin/add_subcategory" method="post" enctype="multipart/form-data">
         <div class="form-group ">
            <label for="email">Choose Category</label>
          	<select class="form-control" name="cat">
            	<option value="">Choose Category</option>
                <?php foreach($cats as $cat){?>
                <option value="<?php echo $cat->cid;?>"><?php echo $cat->cat_name;?></option>
                <?php }?>
            </select>
          </div>
          <div class="form-group "> <label for="email">Subcategory Title</label>
            <input type="text" required class="form-control" name="subcat">
          </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">Subcategory Image</label>
            <input type="file" class="btn btn-primary" name="img">
          </div><br/>
          <button type="submit" class="btn btn-success" name="submit">Add Subcategory</button>
        </form>
      </div>
    </div>
                    </div>
                    
                    <div class="col-md-7">
                     <div class="panel panel-success">
							
      <div class="panel-heading">Listing All Subcategory</div>
      <div class="panel-body">
                    <table class="table table-striped table-responsive table-bordered dataTable" id="data-tables">
        	<thead><tr><th>S.No.</th><th>Image</th><th>Title</th><th>Category</th><th>Action</th></tr></thead>
            <tbody>
            	<?php $i=1;foreach($subcats as $subcat){?>
                <tr id="tr<?php echo $subcat->sid;?>"><td><?php echo $i;?></td>
                <td width="100px"><img src="<?php echo base_url();?>assets/images/category/<?php echo $subcat->subcat_image;?>" class="img img-responsive"></td>
                <td><?php echo $subcat->subcat_name;?><br/>
                <input type="checkbox" name="in_trend" <?php if($subcat->in_trend!=""){echo "checked";}?> value="<?php echo $subcat->sid;?>" class="in_trend" /> In Trend</td>
                <td><?php $sc=$this->db->get_where("category",array("cid"=>$subcat->cid))->row();
				if($sc){echo $sc->cat_name;}?></td>
                <td>
                 <?php if($subcat->subcat_status==""){$st="Disable";}else{$st="Enable";}?>
                <a href="<?php echo $subcat->sid;?>" class="btn btn-xs btn-default enable"><?php echo $st;?></a>
     <button id="<?php echo $subcat->sid;?>" type="button" class="btn btn-warning btn-xs editform" data-toggle="modal" data-target="#myModal"><i class="fa fa-edit"></i></button>
      <a href="<?php echo $subcat->sid;?>" id="<?php echo $subcat->subcat_image;?>" class="btn btn-xs btn-danger subcatdelete"><i class="fa fa-trash-o"></i></a></td>
                <?php $i++;}?>
            </tbody>
        </table>
        <div class="modal fade" id="myModal" role="dialog">
            <div class="modal-dialog">
              <!-- Modal content-->
              <div class="modal-content">
                <div class="modal-header vd_bg-blue vd_white">
                          <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
                          <h4 class="modal-title" id="myModalLabel">Update Subcategory</h4>
                        </div>
                <div class="modal-body">
                  <form action="" method="post" enctype="multipart/form-data" id="updateform">
                  <div class="row"><div class="form-group col-md-6">
                    <label for="email">Choose Category</label>
                    <select class="form-control" name="cat" id="cat">
                        <option value="">Choose Category</option>
                        <?php foreach($cats as $cat){?>
                        <option value="<?php echo $cat->cid;?>"><?php echo $cat->cat_name;?></option>
                        <?php }?>
                    </select>
                  </div>
                  <div class="form-group col-md-6"> <label for="email">SubCategory Title</label>
                    <input type="text" placeholder="SubCategory Title" value="" id="subcat" required class="form-control" name="subcat">
                  </div></div>
                  <div class="form-group">
                    <label for="email">Meta Title</label>
                    <input type="text"  class="form-control" name="metatitle" id="metatitle">
                  </div>
                  <div class="form-group">
                    <label for="email">Meta Keywords</label>
                    <input type="text"  class="form-control" name="metakey" id="metakey">
                  </div>
                  <div class="form-group">
                    <label for="email">Meta Description</label>
                    <input type="text"  class="form-control" name="metadesc" id="metadesc">
                  </div>
                  <div class="row">
                  <div class="col-md-6">
                  	<label for="file"> Upload File</label>
                    <input type="file" class="btn btn-success" value="" name="img">
                    <input type="hidden" name="oldimg" value="" id="oldimg" />
                    <input type="hidden" name="sid" value=""  id="sid"/>
                  </div>
                  <div class="col-md-6">
                  	<img src="" class="img img-responsive"  id="img" width="50%"/>
                  </div>
                  </div>
                  <button type="submit" class="btn btn-primary" name="submit">Update</button>
                  <button type="button" class="btn btn-default" data-dismiss="modal" id="cancelmodal">Cancel</button>
                </form>
                
                </div>
                
              </div>
              
            </div>
  		</div>
        </div></div>
                    </div>
                    
                    
                    <!-- End Chat Room -->
                </div>
          </div>
          <!-- .vd_content-section --> 
          
        </div>
        <!-- .vd_content --> 
      </div>
      <!-- .vd_container --> 
    </div>
    <!-- .vd_content-wrapper --> 
    
    <!-- Middle Content End --> 
    
  </div>
  <!-- .container --> 
</div>
<!-- .content -->

<!-- Footer Start -->
  <footer class="footer-1"  id="footer">      
    <div class="vd_bottom ">
        <div class="container">
            <div class="row">
              <div class=" col-xs-12">
                <div class="copyright">
                  	Copyright &copy;2018 HadesIndia. All Rights Reserved 
                </div>
              </div>
            </div><!-- row -->
        </div><!-- container -->
    </div>
  </footer>
<!-- Footer END -->
  

</div>

<!-- .vd_body END  -->
<a id="back-top" href="#" data-action="backtop" class="vd_back-top visible"> <i class="fa  fa-angle-up"> </i> </a>

<!--
<a class="back-top" href="#" id="back-top"> <i class="icon-chevron-up icon-white"> </i> </a> -->

<!-- Javascript =============================================== --> 
<!-- Placed at the end of the document so the pages load faster --> 
<script>
	$(document).ready(function(){
		$(".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/subcatenable',
							 data: {id:id,st:st},
							 success: function(response){
								 //alert(response);
							 }
							 });
		});
		
		$(".in_trend").click(function(){
							var id=$(this).val();
							//alert(id);
							var v="";
							if ($(this).is(':checked')) {
								var v=$(this).val();
							}
							//alert(v);
							$.ajax({
							 type: "POST",
							 url: '<?php echo base_url();?>admin/in_trend',
							 data: {v:v,id:id},
							 success: function(response){
								// alert(response);
							 }
							 });
						});
		
		$(".subcatdelete").click(function(e){e.preventDefault();
		if (!confirm("Sure you want to delete?")){
				  return false;
				}
			var id=$(this).attr("href");
			var img=$(this).attr("id");
		//alert(img);return false;
			$(this).closest("tr").remove();
			$.ajax({
							 type: "POST",
							 
							 url: '<?php echo base_url();?>admin/subcatdelete',
							 data: {id:id,img:img},
							 success: function(response){
								 //alert(response);
							 }
							 });
		});
		$(".editform").click(function(){
			var id=$(this).attr("id");
			$.ajax({
							 type: "POST",
							 dataType:"json",
							 url: '<?php echo base_url();?>admin/ajax_showsubcat',
							 data: {id:id},
							 success: function(response){
								 //alert(response);
								$("#subcat").val(response.subcat_name);
								$("#metakey").val(response.metakey);
								$("#metatitle").val(response.metatitle);
								$("#metadesc").val(response.metadesc);
							 	$("#oldimg").val(response.subcat_image);
								$("#img").attr("src","<?php echo base_url();?>assets/images/category/"+response.subcat_image);
								$("#sid").val(response.sid);
								$("#cat").val(response.cid).prop("selected",true);
							 }
							 });
		});
		$("form#updateform").submit(function(e){
								var sid=$("#sid").val();
								//alert(sid);
								e.preventDefault();
								$.ajax({
								url: "<?php echo base_url();?>admin/update_subcategory", // Url to which the request is send
								type: "POST",             // Type of request to be send, called as method
								data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
								contentType: false,       // The content type used when sending data to the server.
								cache: false,             // To unable request pages to be cached
								processData:false,        // To send DOMDocument or non processed data file it is set to false
								success: function(data)   // A function to be called if request succeeds
								{
									window.location.href = '<?php echo base_url();?>admin/subcategory';
								//$("#tr"+sid+":first-child").text(data.subcat_name);
								//$("#respond").html(data);
								//$("#myModal").modal('toggle'); 
								//$("#cancelmodal").trigger("click");
								}
								});
		});
	});
</script>
<script type="text/javascript" src='<?php echo base_url();?>adminassets/plugins/jquery-ui/jquery-ui.custom.min.js'></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/jquery-ui-touch-punch/jquery.ui.touch-punch.min.js"></script>

<script type="text/javascript" src="<?php echo base_url();?>adminassets/js/caroufredsel.js"></script> 
<script type="text/javascript" src="<?php echo base_url();?>adminassets/js/plugins.js"></script>

<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/breakpoints/breakpoints.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/dataTables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/prettyPhoto-plugin/js/jquery.prettyPhoto.js"></script> 

<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/mCustomScrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/tagsInput/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/bootstrap-switch/bootstrap-switch.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/blockUI/jquery.blockUI.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/pnotify/js/jquery.pnotify.min.js"></script>

<script type="text/javascript" src="<?php echo base_url();?>adminassets/js/theme.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/custom/custom.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/dataTables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/dataTables/dataTables.bootstrap.js"></script>

<script type="text/javascript">
		$(document).ready(function() {
				
				$('#data-tables').dataTable();
		} );
</script>

</body>
</html>