<?php
session_start();
if(!isset ($_SESSION['user_id'])){
	header("Location:../login.php?msg=Log in first");
    exit();
}else{
	
	include('../Server/connection.php');
	include('includes/session.php');
	echo "<div class='div-request div-hide'>editOrd</div>";
    	
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

	
	 <?php
  include 'title.php';
         ?>
	
	
	<link type = "image/png" rel="icon" href="images/brvision.png" />

    <!-- Bootstrap must-->
    <link href="../vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
	
    <!-- Font Awesome must-->
    <link href="../vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
	
	<!-- custom css -->
    <link rel="stylesheet" href="custom/css/custom.css">
	
    <!-- NProgress must-->
    <link href="../vendors/nprogress/nprogress.css" rel="stylesheet">
	
    <!-- Custom Theme Style must-->
    <link href="../build/css/custom.min.css" rel="stylesheet">
	
	
	
	<!-- must-->
	<script src="assests/jquery/jquery.min.js"></script>
	
	<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"></script>
    <script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/additional-methods.min.js"></script>
	
  <!-- jquery ui -->  
  <link rel="stylesheet" href="assests/jquery-ui/jquery-ui.min.css">
  <script src="assests/jquery-ui/jquery-ui.min.js"></script>
	
  <!-- Must Bootstrap -->
    <script src="../vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	
	<style>
  .error {
    color: #F00;
}  

</style>
	
	<script type="text/javascript">
$(document).ready(function(){
    $('#relId').on('change',function(){
        var regID = $(this).val();
        if(regID){
            $.ajax({
                type:'POST',
                url:'rajaxData.php',
                data:'relId='+regID,
                success:function(html){
                    $('#denId').html(html);
                }
            }); 
        }else{
            $('#denId').html('<option value="">Select Religion First</option>');
        }
    });

});
</script>

<script type="text/javascript">
$(document).ready(function(){
    $('#deptId').on('change',function(){
        var regID = $(this).val();
        if(regID){
            $.ajax({
                type:'POST',
                url:'ajaxData.php',
                data:'deptId='+regID,
                success:function(html){
                    $('#desId').html(html);
                }
            }); 
        }else{
            $('#desId').html('<option value="">Select Department First</option>');
        }
    });

});
</script>
	
  </head>

  <body class="nav-md">
  
    <div class="container body">
	
      <div class="main_container">
        <div class="col-md-3 left_col">
          <div class="left_col scroll-view">
		  
             <?php  
		include 'includes/role.php';
               ?>

            <div class="clearfix"></div>
            
			
			<?php
            include 'includes/profile.php';
			print '</br></br>';
			include 'includes/menu.php';
			?>


           

        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
		  
			
			
            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
				  
                    <a href="staffContracts.php">  <h2><span class="glyphicon glyphicon-step-backward"></span> Back</h2></a>
					
					<?php
				$cont_id = $_GET['i'];
				$sql81 = "SELECT * FROM staff_contracts WHERE contract_id = {$cont_id}";
				$result81 = $conn->query($sql81);
				while($data81 = mysqli_fetch_array($result81))
							{
							$contract_start = $data81['contract_start'];
							$cont_dur_id = $data81['cont_dur_id'];
							$staff_id = $data81['staff_id'];
							$cont_status = $data81['cont_status'];
				            }	
							
				$sql816 = "SELECT * FROM staff_termination WHERE staff_id = {$staff_id}";
				$result816 = $conn->query($sql816);
                           $count88 = mysqli_num_rows($result816);
						   if($count88>0){
							   
				$sql818 = "SELECT * FROM staff_termination WHERE staff_id = {$staff_id}";
				$result818 = $conn->query($sql818);	
                 while($data818 = mysqli_fetch_array($result818))
							{
						$remarks = $data818['remarks'];
                            }								
							   
						   }else{
							   
						$remarks = '';	   
						   }
										 
				      ?>
					
					
					
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                      
                     
                    </ul>
                    <div class="clearfix"></div>
                  </div>
				  
				
				<div class="x_content" style="overflow: auto;">
				
				<?php if (isset($_SESSION['success_message']) && !empty($_SESSION['success_message'])) { ?>
                        <div class="success-message" style="margin-bottom: 20px;font-size: 20px;color: green;"><?php echo $_SESSION['success_message']; ?></div>
                        <?php
                        unset($_SESSION['success_message']);
                    }
                    ?>	
				 
				  <div class="success-messages"></div> <!--/success-messages-->

               <form class="form-horizontal" method="POST" action="php_action/editCont.php" enctype="multipart/form-data">
			   
			    <input type="hidden" name="staff_id" value="<?php echo $staff_id; ?>">
				 <input type="hidden" name="cont_id" value="<?php echo $cont_id; ?>">
				
				  <div class="controls">
			  <div class="row">
			  
			  <div class="col-sm-4">
			  <div class="form-group">
                 <label for="form_name"> Contract Status</label>
				 </br>
		 <?php	
                 $sql4217 = "SELECT * FROM staff_contracts where contract_id='$cont_id'";	
        $result4217 = $conn->query($sql4217); 
		while ($row4217 = mysqli_fetch_array($result4217))
		{
			
			$contStatus227 = $row4217['cont_status'];
	
		?>			
				 
				 <label class="radio-inline">
          <input type="radio" name="cont_status" value="Renew Contract" id="cont_status" <?php if($contStatus227=='Renew Contract'){ echo "checked";}?> /> Renew Contract
         </label>&nbsp&nbsp&nbsp&nbsp
         <label class="radio-inline">
          <input type="radio" name="cont_status" value="Terminate Contract" id="cont_status" <?php if($contStatus227=='Terminate Contract'){ echo "checked";}?> /> Terminate Contract
         </label>&nbsp&nbsp&nbsp&nbsp
				 
		<?php
		                }
						?>		
				    
              </div>
			  </div>
			  
			   <?php
			if($cont_status=='Renew Contract'){  
			  ?>
			  
			  <div id="textboxes1">	
			  
			  <div class="col-sm-4">
			  <div class="form-group">
                 <label for="form_name"> Contract Start Date </label>
                 <input  type="text" class="form-control" id="contractStartDate" name="contractStartDate"  value="<?php echo $contract_start; ?>" placeholder="Contract Start Date" autocomplete="off" />
                    <br/>
                         <label for="contractStartDate" class="error" generated="true"></label>  
                    </div>
			  </div>
			  
			  <div class="col-sm-4">
			  <div class="form-group">
                 <label for="form_name"> Contract Duration </label>
				  <select class="form-control" name="cont_dur_id" id="cont_dur_id" autocomplete="off" />
				
			  						<?php
			  							$productSql = "SELECT * from cont_duration where cont_dur_id='$cont_dur_id'";
			  							$productData = $conn->query($productSql);

			  							while($row = $productData->fetch_array()){									 		
			  								echo "<option value='".$row['cont_dur_id']."'>".$row['cont_dur_name']."</option>";
										 	} // /while 
											
									   $productSql1 = "SELECT * from cont_duration where  cont_dur_id!='$cont_dur_id'";
			  							$productData1 = $conn->query($productSql1);

			  							while($row1 = $productData1->fetch_array()){									 		
			  								echo "<option value='".$row1['cont_dur_id']."'>".$row1['cont_dur_name']."</option>";
										 	} // /while

			  						?>
		  						</select>
                      <br/>
                         <label for="cont_dur_id" class="error" generated="true"></label>  
                    </div>
			  </div> 
			  
			  
             </div>
			 
			 <?php
			}else{
			 ?>
			 
			  <div id="textboxes1"  style="display: none">	
			 
			  <div class="col-sm-4">
			  <div class="form-group">
                 <label for="form_name"> Contract Start Date </label>
                 <input  type="text" class="form-control" id="contractStartDate" name="contractStartDate"  value="<?php echo $contract_start; ?>" placeholder="Contract Start Date" autocomplete="off" />
                    <br/>
                         <label for="contractStartDate" class="error" generated="true"></label>  
                    </div>
			  </div>
			  
			  <div class="col-sm-4">
			  <div class="form-group">
                 <label for="form_name"> Contract Start Date </label>
				  <select class="form-control" name="cont_dur_id" id="cont_dur_id" autocomplete="off" />
				
			  						<?php
			  							$productSql = "SELECT * from cont_dduration where cont_dur_id='$cont_dur_id'";
			  							$productData = $conn->query($productSql);

			  							while($row = $productData->fetch_array()){									 		
			  								echo "<option value='".$row['cont_dur_id']."'>".$row['cont_dur_name']."</option>";
										 	} // /while 
											
									   $productSql1 = "SELECT * from cont_dduration where  cont_dur_id!='$cont_dur_id'";
			  							$productData1 = $conn->query($productSql1);

			  							while($row1 = $productData1->fetch_array()){									 		
			  								echo "<option value='".$row1['cont_dur_id']."'>".$row1['cont_dur_name']."</option>";
										 	} // /while

			  						?>
		  						</select>
                      <br/>
                         <label for="cont_dur_id" class="error" generated="true"></label>  
                    </div>
			  </div>
			  
             </div>
			 
			 <?php
                }
			 ?>
			 
			 
			 
			    <?php
			if($contStatus227=='Renew Contract'){  
			  ?>
			  
			  <div id="textboxes2" style="display: none">	
			  <div class="col-sm-4">
			  <div class="form-group">
                 <label for="form_name"> Remarks </label>
				 
				 <textarea rows="3" cols="50" name="remarks" id="remarks"  class="form-control" style="margin-left:0%;" autocomplete="off" /> <?php echo htmlspecialchars($remarks); ?> </textarea>
				 
                    <br/>
                         <label for="remarks" class="error" generated="true"></label>  
                    </div>
			  </div>
			  
             </div>
			 
			 <?php
			}else{
			 ?>
			 
			  <div id="textboxes2">	
			 
			  <div class="col-sm-4">
			  <div class="form-group">
                 <label for="form_name"> Remarks </label>
				 
				 <textarea rows="3" cols="50" name="remarks" id="remarks"  class="form-control" style="margin-left:0%;" autocomplete="off" /> <?php echo htmlspecialchars($remarks); ?> </textarea>
				 
                    <br/>
                         <label for="remarks" class="error" generated="true"></label>  
                    </div>
			  </div>
			  
             </div>
			 
			 <?php
                }
			 ?>
			  
			  
			  	</div>	  
                </div>
				
				
				
			 
			
			  <div class="form-group submitButtonFooter">
			    <div class="col-sm-12">
			      <button type="submit" id="createOrderBtn" data-loading-text="Loading..." class="btn btn-success"><i class="glyphicon glyphicon-ok-sign"></i> Save Changes</button>
                  </br></br>
			      <!--<button type="reset" class="btn btn-default" onclick="resetOrderForm()"><i class="glyphicon glyphicon-erase"></i> Reset</button>-->
			    </div>
			  </div>
			  
			  
			</form>                  
				
            </div>
			
			
			
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->
		
		
		<?php
		include 'includes/footer.php';
		?>
		
        
      </div>
      </div>


	
	<script>
	// order date picker
		$("#contractStartDate").datepicker();
		
		
	
	</script>
	
	<script>
//$(function(){
	
$(document).ready(function(){
    $('input[name="cont_status"]').on('click', function(){
        if ($(this).val() == 'Renew Contract'){
			 $('#textboxes1').show();
			 $('#textboxes2').hide();
        }else {
			$('#textboxes2').show();
			 $('#textboxes1').hide();
		}
	
		
    });
});



 $("#id_frm").validate({
        rules: {
			
			"fname": {
                required: true
            },
			
			"mname": {
                required: true
            },
			
			"lname": {
                required: true
            },
			
			"gender_id": {
                required: true
            },
			
			"email": {
                required: true
            },
			
			"phone": {
                required: true
            },
			
			
			"bdate": {
                required: true
            },
			
			
			"empdate": {
                required: true
            },
			
			"marital_id": {
                required: true
            },
			
			"relId": {
                required: true
            },
			
			"denId": {
                required: true
            },
			
			"cont_dur_id": {
                required: true
            },
			
			
            "contractStartDate": {
                required: true,
                //minlength: 10,
                // minlength: 10 // same rule twice
            },
			
			"edu_level_id": {
                required: true
            },
			
			"region_id": {
                required: true
            },
			
			"district_id": {
                required: true
            },
			
			"ward_id": {
                required: true
            },
			
			"heslb_status": {
                required: true
            },
			
			"basicSalary": {
                required: true
            },
			
			"bankName": {
                required: true
            },
			
			"bankAccountNo": {
                required: true
            },
			
			"company_address": {
                required: true
            }
			
            
        },
        messages: {
			
			"fname": {
                required: "Please Enter Staff First Name."
            },
			
			"mname": {
                required: "Please Enter Staff Middle Name"
            },
			
			"lname": {
                required: "Please Enter Staff Last Name"
            },
			
			"gender_id": {
                required: "Please Select Gender"
            },
			
            "email": {
                required: "Please Enter Staff Email Address"
            },
			
			"phone": {
                required: "Please Enter Staff Phone Number"
            },
			
			"bdate": {
                required: "Please Enter Staff Birth Date"
            },
			
			"empdate": {
                required: "Please Enter Staff Employment Date"
            },
			
			"marital_id": {
                required: "Please Select Marital Status."
            },
			
			
			"relId": {
                required: "Please Select Religion"
            },
			
			"denId": {
                required: "Please Select Denomination."
            },
			
			
			"cont_dur_id": {
                required: "Please Select Contract Duration"
            },
			
			"contractStartDate": {
                required: "Please Enter Contract Start Date"
            },
			
			"edu_level_id": {
                required: "Please Select Education Level"
            },
			
			"region_id": {
                required: "Please Select Region"
            },
			
			"district_id": {
                required: "Please Select District"
            },
			
			"ward_id": {
                required: "Please Select Ward"
            },
			
			"heslb_status": {
                required: "Please Select Heslb Status"
            },
			
			"basicSalary": {
                required: "Please Select Staff Basic Salary"
            },
			
			"bankName": {
                required: "Please Select Staff Bank Name"
            },
			
			"bankAccountNo": {
                required: "Please Select Staff Bank Account No"
            },
			
			"company_address": {
                required: "Please Enter Company Address"
            }
			
			
        },
        // for demo
        //submitHandler: function(form) {
            //alert('valid form');
            //return false;
        //}
 });


</script>
	
	

   <!-- Must -->
    <script src="custom/js/editStaff.js"></script>
	
    <!-- Must Custom Theme Scripts -->
    <script src="../build/js/custom.min.js"></script>
	
	<!-- file input -->
	<script src="assests/plugins/fileinput/js/plugins/canvas-to-blob.min.js'); ?>" type="text/javascript"></script>	
	<script src="assests/plugins/fileinput/js/plugins/sortable.min.js" type="text/javascript"></script>	
	<script src="assests/plugins/fileinput/js/plugins/purify.min.js" type="text/javascript"></script>
	<script src="assests/plugins/fileinput/js/fileinput.min.js"></script>	


	<!-- DataTables -->
	<script src="assests/plugins/datatables/jquery.dataTables.min.js"></script>

  </body>
</html>



<?php
}
?>