<?php
include("../include/session.php");

		
	$d = date("d");
	$m = date("m");
	$y = date("Y");
	
	$user_id = $_SESSION['username'];
	
	date_default_timezone_set('Africa/Gaborone');
	$entry_date = date("Y-m-d H:i:s", time()); 
	 
	$table_name = $_SESSION['db_prefix']."_employee";
	$employee_query = "INSERT INTO $table_name (
											  emp_no,
											  emp_group,	
											  emp_first_name, 
											  emp_last_name, 
											  gender, 
											  birth_date, 
											  id_number, 
											  marital_status, 
											  bag_box, 
											  box_no, 
											  postal_place, 
											  phys_address, 
											  phys_place, 
											  country, 
											  phone, 
											  cell, 
											  email, 
											  emergency_name,  
											  emergency_phone,
											  expatriate,
											  nationality, 
											  employ_date,
											  end_employ_date,
											  premature_end_date,
											  permit_number,
											  permit_date, 
											  position, 
											  department, 
											  pay_period,
											  rate,
											  salary_scale,
											  leave_days,
											  time_keeping,
											  time_zone,
											  pay_unit,
											  clothing_size, 
											  shoe_size, 
											  bank, 
											  bank_branch, 
											  bank_account,
											  cv,
											  file_reference,
											  notes ) 
	                    VALUES (
						        '".trim($_SESSION['emp_no'])."' ,
								'".trim($_SESSION['group'])."' ,
								'".trim($_SESSION['first_name'])."' ,
     							'".trim($_SESSION['last_name'])."' ,
	 							'".trim($_SESSION['gender'])."' ,
	 							'".trim($_SESSION['birth_date'])."' ,
	 							'".trim($_SESSION['id_number'])."' ,
	 							'".trim($_SESSION['marital_status'])."' ,
	 							'".trim($_SESSION['bag_box'])."' ,
	 							'".trim($_SESSION['box_no'])."' ,
	 							'".trim($_SESSION['post_place'])."' ,
	 							'".trim($_SESSION['phys_address'])."' ,
	 							'".trim($_SESSION['phys_place'])."' ,
	 							'".trim($_SESSION['country'])."' ,
	 							'".trim($_SESSION['phone'])."' ,
	 							'".trim($_SESSION['cell'])."' ,
	 							'".trim($_SESSION['email'])."' ,
	 							'".trim($_SESSION['emergency_name'])."' ,
	 							'".trim($_SESSION['emergency_phone'])."' ,
								'".trim($_SESSION['exp'])."' ,
								'".trim($_SESSION['nationality'])."' ,
	 							'".trim($_SESSION['employ_date'])."' ,
								'".trim($_SESSION['expiry_date'])."' ,
								'2030-01-01' ,
								'".trim($_SESSION['permit'])."' ,
								'".trim($_SESSION['permit_date'])."' ,
	 							'".trim($_SESSION['position'])."' ,
	 							'".trim($_SESSION['department'])."' ,
	 							'".trim($_SESSION['pay_period'])."' ,
	 							'".trim($_SESSION['rate'])."' ,
								'".trim($_SESSION['scale'])."' ,
								'".trim($_SESSION['leave_days'])."' ,
								'".trim($_SESSION['time_keeping'])."' ,
								'".trim($_SESSION['time_zone'])."' ,
								'".trim($_SESSION['pay_unit'])."' ,
	 							'".trim($_SESSION['clothing_size'])."' ,
	 							'".trim($_SESSION['shoe_size'])."' ,
	 							'".trim($_SESSION['bank'])."' ,
	 							'".trim($_SESSION['branch'])."' ,
	 							'".trim($_SESSION['bank_account'])."' ,
								'".trim($_SESSION['cv'])."' ,
								'".trim($_SESSION['file_reference'])."' ,
	 							'".trim($_SESSION['notes'])."')";
								
	$employee_result = $con->query($employee_query);
	
	
	$table_name = $_SESSION['db_prefix']."_employee";
	$emp_id_query = "SELECT emp_id  FROM $table_name ORDER BY emp_id DESC LIMIT 1 ";
	$emp_id_result = $con->query($emp_id_query);
	$row = mysqli_fetch_assoc($emp_id_result);
	$emp_id = $row['emp_id'];

	
	if (isset($_POST['new_button']) )
	   {
		 $action='employeeWiz0.php';
	   }
		 
	if (isset($_POST['finish_button']) )
	  {
		$action='employee_details.php?emp_id='.$emp_id ;
	  }
	
	$table_name = $_SESSION['db_prefix']."_tracking_hr";
   $tracking_query = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '20', '".$emp_id."' ,'','','' )";
   $tracking_result = $con->query($tracking_query);
	
	 $_SESSION['emp_no'] ="";
	 $_SESSION['first_name'] ="";
     $_SESSION['last_name'] = "";
	 $_SESSION['gender'] = "";
	 $_SESSION['birth_date'] = date('Y-m-d');
	 $_SESSION['id_number'] = "";
	 $_SESSION['marital_status'] = "";
	 $_SESSION['bag_box'] = "";
	 $_SESSION['box_no'] = "";
	 $_SESSION['post_place'] = "";
	 $_SESSION['phys_address'] = "";
	 $_SESSION['phys_place'] = "";
	 $_SESSION['country'] = "";
	 $_SESSION['phone'] = "";
	 $_SESSION['cell'] = "";
	 $_SESSION['email'] = "";
	 $_SESSION['emergency_name'] = "";
	 $_SESSION['emergency_phone'] = "";
	 $_SESSION['employ_date'] = date('Y-m-d');
	 $_SESSION['position'] = "";
	 $_SESSION['department'] = "";
	 $_SESSION['company'] = "";
	 $_SESSION['rate'] = "";
	 $_SESSION['time_keeping'] = "";
	 $_SESSION['pay_unit'] = "";
	 $_SESSION['pay_period'] = "";
	 $_SESSION['clothing_size'] = "";
	 $_SESSION['shoe_size'] = "";
	 $_SESSION['bank'] = "";
	 $_SESSION['branch'] = "";
	 $_SESSION['bank_account'] = "";
	 $_SESSION['notes'] = "";
    
	 
?>

<script language="javascript" type="text/javascript">
        
		  window.location="<?php echo $action ?> ";
        
       </script>



