<style>
/*button.btn.btn-approve {
    background-color: turquoise;
}
button.btn.btn-approved {
    background-color: green;
}*/

button.btn.btn-approve {
    background-color: #fdb66d;
	width: 100%;
	color: white;
	margin-bottom: 5px;
}
button.btn.btn-approved {
    background-color:#0d3b94;
	width: 100%;
	color: white;
	margin-bottom: 5px;
}
button.btn.btn-denied {
    background-color: red;
	width: 100%;
	color: white;
	   margin-bottom: 5px;
}
button.btn.btn-denie {
    background-color: #dd4b39;
	color: white;
	   
}

.btn-info {
    width: 100%;
}
.btn-danger {
    width: 100%;
    margin-top: 5px;
}
.main-sidebar{ min-height: 1000px !important;}

</style>

<!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">
  
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>

<script src="js/adminlte.min.js"></script>
<script>
$(document).ready(function() {
$('.datatble').DataTable();


} );
</script>
<script>
$(".upoadldbtn").click(function () {
    $(this).next().click();
});
</script>	

  </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>Contractors</h1>
    </section>
  
 
		<section class="content">
			
		<div class="backf pt30">
		
		
			
			<div class="mb20">
				<button class="btn btn-warning mb20" data-toggle="modal" data-target="#add-contractor">Add Contractor</button>
			</div>
			
			<div class="table-responsive">
				<table  class="table table-striped datatble">
					<thead>
					  <tr>
						<th width="42">Sr.No</th>
						<th>First Name</th>
						<th>Last Name</th>
						<th>Email</th>
						<!--<th>Password</th>-->
						<th>Company Name</th>
						<th>Phone</th>
						<!-- <th>Address</th> -->
                        <th>Address</th>
						<th>Action</th>
					  </tr>
					</thead>
                    <?php 
					$i=1;
                                        $ans=0;
					?>
					<tbody>
					<?php 
					
					$query = $this->db->query("SELECT * FROM  contractors_tbl");
					foreach($query->result_array('contractors_tbl') as $row){
                                            $ans = $ans+$i;
					?>
					  <tr>
                       <td><?php echo $ans;?></td>
                      	<td><?php echo $row['first_name'];?></td>
						<td><?php echo $row['last_name'];?></td>
						<td><?php echo $row['email'];?></td>
						<?php /*?><td><?php echo $row['password'];?></td><?php */?>
						<td><?php echo $row['company_name'];?></td>
						<td><?php echo $row['phone'];?></td>
						
						
						<td><?php echo $row['location'];?></td>
                        <td>
                            <?php if($row['approve']=='0' && $row['denied']=='0'){?>
                            <button class="btn btn-approve approve_denied" approve_denied_id="<?php echo $row['contractor_id'];?>" data-toggle="modal" data-target="#approve-contractor">Pending</button>
                            <?php } else if($row['approve']=='1') {?>
                        	<button class="btn btn-approved denied_status" denied_id ="<?php echo $row['contractor_id'];?>" data-toggle="modal" data-target="#approved-contractor">Approved</button>
                            <?php } else if($row['denied']=='1' && $row['approve']=='0' ){ ?>
                            <button class="btn btn-denied approved_status" approved_id="<?php echo $row['contractor_id'];?>" data-toggle="modal" data-target="#denied-contractor">Denied</button>
                            <?php } ?>
			<button class="btn btn-info edit_contractor" data-toggle="modal" data-target="#edit-contractor" contractor_id="<?php echo $row['contractor_id'];?>">Edit</button>
			<button class="btn btn-danger delete" del="<?php echo $row['contractor_id'];?>">Delete</button>
						</td>
					  </tr>
				 <?php } $ans=$i+1;?> 
					</tbody>
				  </table>
			</div>

      </div>
		</section>
		
  </div>
  
  
  <div id="denied-contractor" class="modal fade" 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">View Contractor's License number and Picture</h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
             
              <input type="hidden" name="denied_to_approve_status_id" id="denied_to_approve_status_id" value="">
               <input type="hidden" name="approved_id" id="approved_id" value="">
              
             
        	 <lable><strong>Name: </strong></lable> <span class="fname_lname"></span>
		</div>
		 <div class="form-group">
		  <lable><strong>Attorney ID: </strong></lable> <span class="license"></span>
		</div>
		 <div class="form-group">
		  <lable><strong>License Picture: </strong></lable><span class="error_disp"></span> <a href=""><span class="image_url"><img src="" class="image_path" width="200" ></span></a>
		</div>
	 </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-success denied_to_approve" >Approve</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>
  
  <div id="approve-contractor" class="modal fade" 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">View Contractor's License number and Picture</h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
            <input type="hidden" name="approve_denied_status_id" id="approve_denied_status_id" value="">
              <input type="hidden" name="approve_denied_id" id="approve_denied_id" value="">
        	 <lable><strong>Name: </strong></lable> <span class="fname_lname"></span>
		</div>
		 <div class="form-group">
		  <lable><strong>Attorney ID: </strong></lable> <span class="license"></span>
		</div>
		 <div class="form-group">
                     <lable><strong>License Picture: </strong></lable><span class="error_disp"></span> <a href=""><span class="image_url"><img src="" class="image_path" width="200" ></span></a>
                   
		</div>
	 </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-success to_approve" >Approve</button>
         <button type="button" class="btn btn-denie pendind_to_denied">Deny</button>
      </div>
    </div>

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

    <!-- Modal content-->
    <div class="modal-content">
     <form  method="post" id="add_contractor">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Add Contractor</h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
		  <label for="usr">First Name:</label>
		  <input type="text" class="form-control" id="first_name" name="first_name" required>
		</div>
		 <div class="form-group">
		  <label for="usr">Last Name:</label>
		  <input type="text" class="form-control" id="last_name" name="last_name" required>
		</div>
		 <div class="form-group">
		  <label for="usr">Email:</label>
		  <input type="text" class="form-control" id="email" name="email" required>
		</div>
		 <div class="form-group">
		  <label for="usr">Password:</label>
		  <input type="text" class="form-control" id="password" name="password" required>
		</div>
		<div class="form-group">
		  <label for="usr">Company Name:</label>
		  <input type="text" class="form-control" id="company_name" name="company_name" required>
		</div>
		 <div class="form-group">
		  <label for="usr">Phone:</label>
		  <input type="text" class="form-control" id="phone" name="phone" required>
		</div>
		 <!-- <div class="form-group">
		  <label for="usr">Address:</label>
		  <input type="text" class="form-control" id="usr">
		</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-contractor" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
     <form  method="post" id="edit_contractor">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Edit Contractor</h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
		  <label for="usr">First Name:</label>
		  <input type="text" class="form-control" id="first_name1" name="first_name1" required>
           <input type="hidden" id="contractor_id" name="contractor_id">
		</div>
		 <div class="form-group">
		  <label for="usr">Last Name:</label>
		  <input type="text" class="form-control" id="last_name1" name="last_name1" required>
		</div>
		 <div class="form-group">
		  <label for="usr">Email:</label>
		  <input type="text" class="form-control" id="email1" name="email1" required>
		</div>
		 <div class="form-group">
		  <label for="usr">Password:</label>
		  <input type="text" class="form-control" id="password1" name="password1">
		</div>
		<div class="form-group">
		  <label for="usr">Company Name:</label>
		  <input type="text" class="form-control" id="company_name1" name="company_name1" required>
		</div>
		 <div class="form-group">
		  <label for="usr">Phone:</label>
		  <input type="text" class="form-control" id="phone1" name="phone1" required>
		</div>
		<!--  <div class="form-group">
		  <label for="usr">Address:</label>
		  <input type="text" class="form-control" id="usr">
		</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>

  
    <!-- Modal -->
<div id="approved-contractor" class="modal fade" 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">View Contractor's License number and Picture</h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
            <input type="hidden" name="denied_status_id" id="denied_status_id" value="">
               <input type="hidden" name="denied_id" id="denied_id" value="">
            
        	 <lable><strong>Name: </strong></lable> <span class="fname_lname"></span>
		</div>
		 <div class="form-group">
                   
		  <lable><strong>Attorney ID: </strong></lable> <span class="license"></span>
		</div>
		 <div class="form-group">
		    <lable><strong>License Picture: </strong></lable><span class="error_disp"></span> <a href=""><span class="image_url"><img src="" class="image_path" width="200" ></span></a>
		</div>
	 </div>
      <div class="modal-footer">
          <button type="submit" class="btn btn-denie changing_denied" >Deny</button>
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

      </div>
    </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_contractor"]').validate({
 rules: {

	first_name:{
		required:true,
		},
	last_name:{
		required:true,
		},
	email:{
		email: true,
		required:true,
		},
	phone:{
		required:true,
		},
	password:{
		required:true,
		},
	company_name:{
		required:true,
		},
	
		
	},
	
 submitHandler: function(form) {
  var data = $("#add_contractor").serialize();
 $.ajax({                                      
			  url: '<?php echo base_url() ?>index.php/admin/add_contractor',                 //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();
				}  
                                else if(data == 3){
                                  alert('Email is already exist, Please use other one');   
                                }
				 } 
			  });
 }	
});
 
  $('.edit_contractor').click(function(){
     var contractor_id = $(this).attr('contractor_id');
   
         $.ajax({
                type: "POST",
                url: '<?php echo base_url() ?>index.php/admin/edit_contractor',
                data: {contractor_id:contractor_id},
				dataType:"json",
                success:function(data)
                {
			      $("#contractor_id").val(data.contractor_id);
				  $("#first_name1").val(data.first_name);  
				  $("#last_name1").val(data.last_name);
				  $("#email1").val(data.email);
				 // $("#password1").val(data.password);
				  $("#phone1").val(data.phone);
				   $("#company_name1").val(data.company_name);
				 },
                error:function()
                {
                    alert('fail');
                }
            });
   
   
   });
  
   
$(".update").click(function () {
$('form[id="edit_contractor"]').validate({
  rules: {
    first_name1: {
      required: true,
    },
	last_name1: {
      required: true,
    },
	email1: {
	 email : true,
      required: true,
    },
	
	phone1: {
      required: true,
    },
	company_name1 : {
	required: true,	
		},
	
	},

  submitHandler: function(form) {
	var contractor_id   = $('#contractor_id').val();
	var data = $("#edit_contractor").serialize();
	$.ajax({                                      
				  url: '<?php echo base_url() ?>index.php/admin/update_contractor_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();
						}
                                                else if(data == 3){
                                                     alert('Email is already exist, Please use other one');
                                                }
						
					  } 
				  });
  }
});
});


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

 </script>
 <script>
     $(".image_path").hide(); 
     $(".approve_denied").click(function(){
        
     var approve_denied_id= $(this).attr('approve_denied_id');
    
       var approve_denied_status_id =$('#approve_denied_status_id').val(approve_denied_id);
       $.ajax({
                type: "POST",
                url: '<?php echo base_url() ?>index.php/admin/get_approve_denied',
                data: {approve_denied_id:approve_denied_id},
		dataType:"json",
                success:function(data)
                {
                 
		 //var zbc = data.first_name;
              $(".fname_lname").empty();
              $(".fname_lname").append(data.first_name);
              
               
              
              if(data.attorney_id=='0'){
                  $(".license").empty();
               $(".license").append("N/A");    
              }
              else {
                  $(".license").empty();
              $(".license").append(data.attorney_id);
              }
              
             if(data.image==""){
                 $(".image_path").hide();
                 $(".error_disp").empty();
               $(".error_disp").append('Image is not available');  
             }
             else
             {
                 $(".error_disp").hide();  
               $(".image_path").show();  
              var detailUrl = data.image;
               $(".image_path").empty();
             $(".image_path").attr('src', detailUrl);
         }
             
            },
                error:function()
                {
                    alert('fail');
                }
            });
 });
 </script>
 <script>
     $(".to_approve").click(function(){
	
	var approve_denied_id= $('#approve_denied_status_id').val();
if (confirm("Do you want to change the status?")){
	   $.ajax({
                type: "POST",
                url: '<?php echo base_url() ?>index.php/admin/status_to_approve',
                data: {approve_denied_id:approve_denied_id},
                success:function(data)
                {
		   if(data=='1'){		    
                    alert('status updated successfully!!');
					location.reload();
                                    }
                                    else if(data=='2'){
                                     alert('something is went wrong!!');
					location.reload();    
                                    }
					
                },
               
            });
}
	
	
	});
 
 </script>
 <script>
      $(".image_path").hide(); 
     $(".denied_status").click(function(){
        
     var denied_id= $(this).attr('denied_id');
     var denied_status_id =$('#denied_status_id').val(denied_id);
       $.ajax({
                type: "POST",
                url: '<?php echo base_url() ?>index.php/admin/get_approve_denied2',
                data: {denied_id:denied_id},
		dataType:"json",
                success:function(data)
                {
                 
		 //var zbc = data.first_name;
                 $(".fname_lname").empty();
              $(".fname_lname").append(data.first_name);
              
               if(data.attorney_id=='0'){
                  $(".license").empty();
               $(".license").append("N/A");    
              }
              else{
               $(".license").empty();
              $(".license").append(data.attorney_id);
          }
                 
		if(data.image==""){
                 $(".image_path").hide();
                 $(".error_disp").empty();
               $(".error_disp").append('Image is not available');  
             }
             else
             {
                 $(".error_disp").hide();  
               $(".image_path").show();  
              var detailUrl = data.image;
               $(".image_path").empty();
             $(".image_path").attr('src', detailUrl);
         }	  
		},
                error:function()
                {
                    alert('fail');
                }
            });
 });
 </script>
 <script>
 
 
     $(".changing_denied").click(function(){
	
	var denied_status_id= $('#denied_status_id').val();
if (confirm("Do you want to change the status?")){
	   $.ajax({
                type: "POST",
                url: '<?php echo base_url() ?>index.php/admin/status_to_denied',
                data: {denied_status_id:denied_status_id},
                success:function(data)
                {
		   if(data=='1'){		    
                    alert('status updated successfully!!');
					location.reload();
                                    }
                                    else if(data=='2'){
                                     alert('something is went wrong!!');
					location.reload();    
                                    }
					
                },
               
            });
}
	
	
	});
 
 
 </script>
 <script>
      $(".image_path").hide();   
  $(".approved_status").click(function(){
     var approved_id= $(this).attr('approved_id');
   
     var denied_to_approve_status_id =$('#denied_to_approve_status_id').val(approved_id);
     $.ajax({
                type: "POST",
                url: '<?php echo base_url() ?>index.php/admin/get_approve_denied4',
                data: {approved_id:approved_id},
		dataType:"json",
                success:function(data)
                {
                 
		 //var zbc = data.first_name;
              $(".fname_lname").empty();
              $(".fname_lname").append(data.first_name);
              
               if(data.attorney_id=='0'){
                  $(".license").empty();
               $(".license").append("N/A");    
              }
              else{
               $(".license").empty();
              $(".license").append(data.attorney_id);
          }
                 
           if(data.image==""){
                 $(".image_path").hide();
                 $(".error_disp").empty();
               $(".error_disp").append('Image is not available');  
             }
             else
             {
                 $(".error_disp").hide();  
               $(".image_path").show();  
              var detailUrl = data.image;
               $(".image_path").empty();
             $(".image_path").attr('src', detailUrl);
         }	
				  
		},
                error:function()
                {
                    alert('fail');
                }
            });
 });
 </script>
 <script>
  $(".denied_to_approve").click(function(){
	
	var denied_to_approve_status_id= $('#denied_to_approve_status_id').val();
if (confirm("Do you want to change the status?")){
	   $.ajax({
                type: "POST",
                url: '<?php echo base_url() ?>index.php/admin/denied_to_approve',
                data: {denied_to_approve_status_id:denied_to_approve_status_id},
                dataType:"json",
                success:function(data)
                {
                   
		    
		   if(data=='1'){		    
                    alert('status updated successfully!!');
					location.reload();
                                    }
                                    else if(data=='2'){
                                     alert('something is went wrong!!');
					location.reload();    
                                    }
					
                },
               
            });
}
	
	
	});
 </script>
 <script>
     $(".pendind_to_denied").click(function(){
	
	var approve_denied_status_id= $('#approve_denied_status_id').val();
if (confirm("Do you want to change the status?")){
	   $.ajax({
                type: "POST",
                url: '<?php echo base_url() ?>index.php/admin/pendind_to_denied',
                data: {approve_denied_status_id:approve_denied_status_id},
                success:function(data)
                {
		   if(data=='1'){		    
                    alert('status updated successfully!!');
					location.reload();
                                    }
                                    else if(data=='2'){
                                     alert('something is went wrong!!');
					location.reload();    
                                    }
					
                },
               
            });
}
	
	
	});
 </script>
</body>
</html>
