<!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">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker.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 Details</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">Add Job </button>
			</div>
			
			<div class="table-responsive">
				<table  class="table table-striped datatble">
					<thead>
					  <tr>
                                              <th>Sr.No</th>
						<th>Job Category</th>
						<th>Job ID</th>
						<th>Job Title</th>
                        <th>Hourly Rate</th>
						<th>Start Date/Time</th>
						<th>End Date/Time</th>
						<th>Action</th>
					  </tr>
					</thead>
                                         <?php 
					$i=1;
                                        $ans=0;
					?>
					<tbody>
						<?php 
					
					$query = $this->db->query("SELECT * FROM  jobdetails_tbl jd join jobcategories_tbl jc on(jd.job_id = jc.job_category_id)");
					foreach($query->result_array('jobdetails_tbl') as $row){
                                             $ans = $ans+$i;
					?>
					  <tr>
                                               <td><?php echo $ans;?></td>
						<td><?php echo $row['category_name'];?></td>
						<td><?php echo $row['job_id'];?></td>
                        <td><?php echo $row['job_title'];?></td>
						<td><?php echo $row['hoursly_rate'];?></td>
						<td><?php echo $row['start_date'];?></td>
						<td><?php echo $row['end_date'];?></td>
						<td>
							<button class="btn btn-info edit_jobInfo" data-toggle="modal" data-target="#edit-job" job_information_id="<?php echo $row['job_information_id'];?>">Edit</button>
							<button class="btn btn-danger delete" del="<?php echo $row['job_information_id'];?>">Delete</button>
						</td>
					  </tr>
					 
					 <?php } $ans=$i+1;?> 
					</tbody>
				  </table>
			</div>

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

    <!-- Modal content-->
    <div class="modal-content">
      <form  method="post" id="add_jobsInfo">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Add Job </h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
		  <label for="usr">Category Name:</label>
		
            <select class="form-control"  name="cat_name" id="cat_name">
			<option value="">Select JobCategory</option>
           <?php 
					
					$query1 = $this->db->query("SELECT * FROM  jobcategories_tbl");
					foreach($query1->result_array('jobcategories_tbl') as $row1){
					?>
		  <option value="<?php echo $row1['job_category_id'];?>"><?php echo $row1['category_name'];?></option>
		  <?php } ?>
          </select>
		</div>
		<div class="form-group">
		  <label for="usr">Job Title:</label>
		  <input type="text" class="form-control" id="job_title" name="job_title" required>
		</div>
		<div class="form-group">
		  <label for="usr">Job Type:</label>
		  <select class="form-control" id="job_type" name="job_type"><option>-</option></select>
		</div>
		<div class="form-group">
		  <label for="usr">Hourly Rate:</label>
		  <input type="text" class="form-control" id="hourly_rate" name="hourly_rate" required>
		</div>
		<div class="form-group">
		  <label for="usr">Description:</label>
		  <input type="text" class="form-control" id="description" name="description" required>
		</div>
		<div class="form-group">
		  <label for="usr">Start Date:</label>
		  <input type="text" class="form-control date" id="start_date" name="start_date" required>
		</div>
		<div class="form-group">
		  <label for="usr">End Date:</label>
		  <input type="text" class="form-control date" id="end_date" name="end_date" 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" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <div class="modal-content">
      <form  method="post" id="edit_jobsInfo">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Edit Job </h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
		  <label for="usr">Category Name:</label>
		   <select class="form-control"  name="cat_name1" id="cat_name1">
			<option value="">Select JobCategory</option>
           <?php 
					
					$query1 = $this->db->query("SELECT * FROM  jobcategories_tbl");
					foreach($query1->result_array('jobcategories_tbl') as $row1){
					?>
		  <option value="<?php echo $row1['job_category_id'];?>"><?php echo $row1['category_name'];?></option>
		  <?php } ?>
          </select>
		</div>
		<div class="form-group">
		  <label for="usr">Job Title:</label>
		  <input type="text" class="form-control" id="job_title1" name="job_title1" required>
           <input type="hidden" class="form-control" id="job_information_id" name="job_information_id" required>
          
		</div>
		<div class="form-group">
		  <label for="usr">Job Type:</label>
		  <select class="form-control"><option>-</option></select>
		</div>
		<div class="form-group">
		  <label for="usr">Hourly Rate:</label>
		  <input type="text" class="form-control" id="hourly_rate1" name="hourly_rate1" required>
		</div>
		<div class="form-group">
		  <label for="usr">Description:</label>
		  <input type="text" class="form-control" id="description1" name="description1" required>
		</div>
		<div class="form-group">
		  <label for="usr">Start Date:</label>
		  <input type="text" class="form-control date" id="start_date1" name="start_date1" required>
		</div>
		<div class="form-group">
		  <label for="usr">End Date:</label>
		  <input type="text" class="form-control date" id="end_date1" name="end_date1" 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 update" value="UPDATE">
      </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_jobsInfo"]').validate({
 rules: {

	cat_name:{
		required:true,
		},
	job_title:{
		required:true,
		},
	
	hourly_rate:{
		required:true,
		},
	description:{
		required:true,
		},
	start_date:{
		required:true,
		},
	
	end_date:{
		required:true,
		},
		
	},
	
 submitHandler: function(form) {
  var data = $("#add_jobsInfo").serialize();
 $.ajax({                                      
			  url: '<?php echo base_url() ?>index.php/admin/add_jobsInfo',                 //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_jobInfo').click(function(){
     var job_information_id = $(this).attr('job_information_id');
   
         $.ajax({
                type: "POST",
                url: '<?php echo base_url() ?>index.php/admin/edit_jobInfo',
                data: {job_information_id:job_information_id},
				dataType:"json",
                success:function(data)
                {
			      $("#job_information_id").val(data.job_information_id);
				  $("#cat_name").val(data.category_name);  
				  $("#job_title").val(data.job_title);
				  $("#hourly_rate1").val(data.hoursly_rate);
				 $("#description1").val(data.description);
				  $("#start_date1").val(data.start_date);
				   $("#end_date1").val(data.end_date);
				 },
                error:function()
                {
                    alert('fail');
                }
            });
   
   
   });
 
 $(".update").click(function () {
$('form[id="edit_jobsInfo"]').validate({
  rules: {
    cat_name: {
      required: true,
    },
	job_title: {
      required: true,
    },
	hourly_rate1: {
	
      required: true,
    },
	
	description1: {
      required: true,
    },
	start_date1 : {
	required: true,	
		},
		end_date1 : {
	required: true,	
		},
	
	},

  submitHandler: function(form) {
	var job_information_id   = $('#job_information_id').val();
	var data = $("#edit_jobsInfo").serialize();
	$.ajax({                                      
				  url: '<?php echo base_url() ?>index.php/admin/update_jobInfo_details',      //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_information_id= $(this).attr('del');
if (confirm("Do you really want to delete?")){
	   $.ajax({
                type: "POST",
                url: '<?php echo base_url() ?>index.php/admin/delete_job_information',
                data: {job_information_id:job_information_id},
                success:function(data)
                {
				    
                    alert('Data deleted successfully!!');
					location.reload();
					
                },
                error:function()
                {
                    alert('fail');
                }
            });
}
	
	
	});
</script>	
</body>
</html>
