<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Contractor App </title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

  <!-- Theme style -->
  <link rel="stylesheet" href="<?php echo base_url();?>assets/css/AdminLTE.min.css">
  <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
  <link rel="stylesheet" href="<?php echo base_url();?>assets/css/custom.css" type="text/css" media="screen"/>


  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

  <!-- Google Font -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

<?php  include"includes/header.php";  ?>
  <!-- Left side column. contains the logo and sidebar -->
  <aside class="main-sidebar">
    <!-- sidebar: style can be found in sidebar.less -->
    <?php  include"includes/sidebar.php";  ?>
    <!-- /.sidebar -->
  </aside>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper ">
	<section class="content-header">
      <h1>Job Categories</h1>
    </section>
  
 
		<section class="content">
			
		<div class="backf pt30">
		
			<!-- <div class="row mb20">
				<div class="col-sm-10 col-sm-offset-1 col-md-8 ">
					<div class="form-group">
					  <label for="usr">Email Name:</label>
					  <input type="text" class="form-control" id="usr">
					</div>
					 <div class="form-group">
					  <label for="usr">Grade:</label>
					 <select class="form-control"><option>A</option></select>
					</div>
					
					<div class="mb20">
						<button class="btn btn-success" >SAVE</button>
					</div>
					<div class="mb20">
						<button class="btn btn-info upoadldbtn" >Upload Button</button>
						<input type="file" id="my_file" style="display: none;" multiple /> 
					</div>
					
				</div>
			</div> -->
		
			
			<div class="mb20">
				<button class="btn btn-warning mb20" data-toggle="modal" data-target="#add-job-categories">Add Job Categories</button>
			</div>
			
			<div class="table-responsive">
				<table  class="table table-striped datatble">
					<thead>
					  <tr>
                                              <th>Sr.No</th>
						<th>Category Name</th>
						<th>Action</th>
					  </tr>
					</thead>
                                         <?php 
					$i=1;
                                        $ans=0;
					?>
					<tbody>
					<?php 
					
					$query = $this->db->query("SELECT * FROM  jobcategories_tbl");
					foreach($query->result_array('jobcategories_tbl') as $row){
                                             $ans = $ans+$i;
					?>
					  <tr>
                                               <td><?php echo $ans;?></td>
						<td><?php echo $row['category_name'];?></td>
						<td>
							<button class="btn btn-info edit_job" data-toggle="modal" data-target="#edit-job-categories" job_category_id="<?php echo $row['job_category_id'];?>">Edit</button>
							<button class="btn btn-danger delete" del="<?php echo $row['job_category_id'];?>">Delete</button>
						</td>
					  </tr>
                    <?php } $ans=$i+1;?> 
					</tbody>
				  </table>
			</div>

      </div>
		
		</section>
		
		
		
  </div>
  
  
  
  
  <!-- Modal -->
<div id="add-job-categories" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <form  method="post" id="add_jobCategory">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Add Job Categories</h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
		  <label for="usr">Category Name:</label>
		  <input type="text" class="form-control" id="cat_name" name="cat_name" required>
		</div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
       <input type="submit" class="btn btn-success" name="sub" value="Save">
      </div>
      </form>
    </div>

  </div>
</div>
  
  
  <!-- Modal -->
<div id="edit-job-categories" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
    <form  method="post" id="edit_jobCategory">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Edit Job Categories</h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
		  <label for="usr">Category Name:</label>
		  <input type="text" class="form-control" id="cat_name1" name="cat_name1" required>
          <input type="hidden" class="form-control" id="job_category_id" name="job_category_id" value="">
          
		</div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <input type="submit" class="btn btn-success update" value="SAVE">
      </div>
      </form>
    </div>

  </div>
</div>
  
<?php  include"includes/footer.php";  ?>
 <script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
 <script>
 $('form[id="add_jobCategory"]').validate({
 rules: {

	cat_name:{
		required:true,
		},

	},
	
 submitHandler: function(form) {
  var data = $("#add_jobCategory").serialize();
 $.ajax({                                      
			  url: '<?php echo base_url() ?>index.php/admin/add_jobCategory',                 //the script to call to get data  
			  type:'post',
			  data: data,//you can insert url argumnets here to pass to api.php
				  success: function(data)          //on recieve of reply
				  {

					if(data == 1){
					alert('Data inserted Successfully');
					location.reload();
						
						}  
				 } 
			  });
 }	
});
 
 $('.edit_job').click(function(){
     var job_category_id = $(this).attr('job_category_id');
   
         $.ajax({
                type: "POST",
                url: '<?php echo base_url() ?>index.php/admin/edit_job',
                data: {job_category_id:job_category_id},
				dataType:"json",
                success:function(data)
                {
			      $("#job_category_id").val(data.job_category_id);
				  $("#cat_name1").val(data.category_name);  
				
				 },
                error:function()
                {
                    alert('fail');
                }
            });
   
   
   });
 
    
$(".update").click(function () {
$('form[id="edit_jobCategory"]').validate({
  rules: {
    cat_name1: {
      required: true,
    },
	
	},

  submitHandler: function(form) {
	var job_category_id   = $('#job_category_id').val();
	var data = $("#edit_jobCategory").serialize();
	$.ajax({                                      
				  url: '<?php echo base_url() ?>index.php/admin/update_jobCategoryDetails',      //the script to call to get data  
				  type:'post',
				 // dataType: 'json',
				  data: data,//you can insert url argumnets here to pass to api.php
					  success: function(data)          //on recieve of reply
					  {
						if(data == 1){
					 alert("Data Updated Successfully");
						location.reload();
						}
						
					  } 
				  });
  }
});
});


$(".delete").click(function(){
	
	var job_category_id= $(this).attr('del');
if (confirm("Do you really want to delete?")){
	   $.ajax({
                type: "POST",
                url: '<?php echo base_url() ?>index.php/admin/delete_jobCategory',
                data: {job_category_id:job_category_id},
                success:function(data)
                {
				    
                    alert('Data deleted successfully!!');
					location.reload();
					
                },
                error:function()
                {
                    alert('fail');
                }
            });
}
	
	
	});

 </script>
</body>
</html>
