  <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                   Manage Ads SubCategories
                </h1>
              <ol class="breadcrumb">
                    <li><a href="<?php echo base_url();?>admin"><i class="fa fa-home"></i>Home</a></li>
                    <li class="active">Manage Ads SubCategories</li>
                </ol>
            </section>
            <!-- Main content -->
            <div class="content">
           
                <div class="container-fluid">
                 
                    <!-- Tabs -->
                    <!-- third row  -->
                    <div class="row"> 
                       <div class="col-md-12 col-sm-12">
                       <?php if($this->session->flashdata("msg")!==""){?>
                          <!--<div class="alert alert-info">
                                            <strong><?php echo $this->session->flashdata("msg");?>!</strong> 
                                        </div>--><?php }?>
                            <div class="panel panel-primary">
							
      <div class="panel-heading">Add New Subcategory</div>
      <div class="panel-body">
      
      <form  action="<?php echo base_url();?>admin/add_subcategory" method="post" enctype="multipart/form-data">
          <div class="row">
          		<div class="col-md-4">
             	  <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">
                    <input type="text" placeholder="SubCategory Title" required class="form-control" name="subcat">
                  </div>
                  <div class="form-group">
                    <input type="text" placeholder="Monthly Price" required class="form-control" name="mon">
                  </div>
                  <div class="form-group">
                    <input type="text" placeholder="Quarterly Price" required class="form-control" name="quar">
                  </div>
                  <div class="form-group">
                    <input type="text" placeholder="Half Yearly Price" required class="form-control" name="half">
                  </div>
                  <div class="form-group">
                    <input type="text" placeholder="Yearly Price" required class="form-control" name="year">
                  </div>
                  
                </div>
                <div class="col-md-6">
                	<div class="form-group label-floating">
                        <label class="control-label">Description</label>
                        <textarea class="form-control" name="desc" rows="8"></textarea>
                    </div>
                    <div class="form-group label-floating">
                        <label class="control-label">Features (PIPE (|) Seperated)</label>
                        <textarea class="form-control" name="feature" rows="6"></textarea>
                    </div>
                </div>
                  
            
          </div>  
          <button type="submit" class="btn btn-success" name="submit">Add Subcategory</button>
        </form>
        
        <br/>
        <table class="table table-condensed table-bordered table-striped">
        	<thead><tr><th>S.No.</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><?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>
     <!--<button id="<?php echo $subcat->sid;?>" type="button" class="btn btn-primary btn-xs addfields" data-toggle="modal" data-target="#myModal1">Post Attr</button>-->
     <button id="<?php echo $subcat->sid;?>" type="button" class="btn btn-warning btn-xs editform" data-toggle="modal" data-target="#myModal">Edit</button>
      <a href="<?php echo $subcat->sid;?>" id="<?php echo $subcat->subcat_image;?>" class="btn btn-xs btn-danger subcatdelete">Delete</a></td>
                <?php $i++;}?>
            </tbody>
        </table>
      </div>
      <div class="modal fade" id="myModal" role="dialog">
            <div class="modal-dialog">
              <!-- Modal content-->
              <div class="modal-content">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal">&times;</button>
                  <h4 class="modal-title">Update Subcategory</h4>
                </div>
                <div class="modal-body">
                  <form action="" method="post" enctype="multipart/form-data" id="updateform">
                  <div class="row">
                  <div class="col-md-5">
                  <div class="form-group">
                    <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">
                    <input type="text" placeholder="SubCategory Title" value="" id="subcat" required class="form-control" name="subcat">
                  </div>
                  <div class="form-group">
                    <input type="text" placeholder="Monthly Price" required class="form-control" id="mon" name="mon">
                  </div>
                  <div class="form-group">
                    <input type="text" placeholder="Quarterly Price" required class="form-control" id="quar" name="quar">
                  </div>
                  <div class="form-group">
                    <input type="text" placeholder="Half Yearly Price" required class="form-control"  id="half" name="half">
                  </div>
                  <div class="form-group">
                    <input type="text" placeholder="Yearly Price" required class="form-control" id="year" name="year">
                  </div>
                  
                </div>
                <div class="col-md-7">
                	<div class="form-group label-floating">
                        <label class="control-label">Description</label>
                        <textarea class="form-control" name="desc" rows="8" id="desc"></textarea>
                    </div>
                    <div class="form-group label-floating">
                        <label class="control-label">Features (PIPE (|) Seperated)</label>
                        <textarea class="form-control" name="feature" rows="6" id="feature"></textarea>
                    </div>
                </div>
                  
                  </div>
                    <input type="hidden" name="oldimg" value="" id="oldimg" />
                    <input type="hidden" name="sid" value=""  id="sid"/>
                  <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>
                    
                    
                </div>
            </div>
            <!-- /.content -->
        </div>
  <footer class="main-footer">
            <!-- To the right -->
           <!-- <div class="pull-right hidden-xs">
                Developed by <i class="fa fa-heart"></i> Floatin
            </div>-->
            <!-- Default to the left -->
            <strong>Copyright &copy; 2017 <a href="#">CRM</a>.</strong> All rights reserved.
        </footer>
    </div>
   <script>
	$(document).ready(function(){
		$("#field").change(function(){
			var f=$(this).val();
			if(f=="checkbox" || f=="radio" || f=="select")
			{ $("#commas").show();
			}else{$("#commas").hide();
			}
		});
		$(".addfields").click(function(){
			var id=$(this).attr("id");
			$("#sidd").val(id);
			//alert(id);
			$.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>admin/showallf',
				 data: {id:id},
				 success: function(response){
				 //alert(response);
				 $("#showallf").html(response);
				 }
				 });
		});
		
		$("form#fieldform").submit(function(e){e.preventDefault();
			var formdata=$(this).serialize();
			$("#label").val("");$("#values").val("");$('#field').prop('selectedIndex',0);
			var id=$(this).attr("id");
			$.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>admin/add_fields',
				 data: {formdata:formdata,id:id},
				 success: function(response){
					//alert(response);
				 $("#showallf").html(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();
			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);
							 	$("#oldimg").val(response.subcat_image);
								
								$("#mon").val(response.monthly);
								$("#quar").val(response.quarterly);
								$("#half").val(response.half);
								$("#year").val(response.yearly);
								$("#desc").val(response.service);
								$("#feature").val(response.feature);
								
								$("#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
								{
								$("#tr"+sid+":first-child").text(data.subcat_name);
								//$("#respond").html(data);
								$("#cancelmodal").trigger("click");
								}
								});
		});
	});
</script>
   <!-- <script>
	$(document).ready(function(){
   function readURL(input,id) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            
            reader.onload = function (e) {alert("asfda");
                $('#i'+id).attr('src', e.target.result);
            }
            
            reader.readAsDataURL(input.files[0]);
        }
    }
	$("#imgInp").change(function(){
        readURL(this,"front");
    });
	});
</script>-->
    <script src="<?php echo base_url();?>newadminassets/plugins/js/countUp.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/raphael.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/morris.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/jquery-jvectormap-2.0.2.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/jquery-jvectormap-world-mill-en.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/material.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/ripples.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/rendro-easy-pie-chart/dist/jquery.easypiechart.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/Chart.bundle.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/jquery.slimscroll.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/js/dashboard.js"></script>
    <script src="<?php echo base_url();?>newadminassets/js/widgets.js"></script>
    <script src="<?php echo base_url();?>newadminassets/js/app.js"></script>

    <!-- Color Switcher -->
    
    <!-- END Skin switcher -->


</body>

