<?php
include '../connect/cms-config.php' ;
include '../requires/session.php' ;
include '../requires/function.php' ;

// set value in variable
$type = escapeString($_GET['type']) ;
$page = escapeString($_POST['page']) ;
$status = escapeString($_POST['status']) ;

$result = false ;
$update_query = '' ;

switch($type){
	case 'update-status' :
		
		$mysqli_page = $mysqli->query("SELECT * FROM staff_employment
									   WHERE employment_id = '".$page."' AND employment_trash = '0' LIMIT 1") ;
		
		if ($mysqli_page->num_rows > 0){
			
			$row_page = $mysqli_page->fetch_array(MYSQLI_ASSOC) ;
			$current_employment_status = $row_page['employment_status'] ;
			
			$array_update_status = array() ;
			switch($current_employment_status){
				case 'Pending' :
					$array_update_status = array('Pending', 'Offer', 'Reject') ;
				break ;
				case 'Offer' :
					$array_update_status = array('Offer', 'Confirmation', 'Terminate') ;
				break ;
				case 'Confirmation' :
					$array_update_status = array('Confirmation', 'Terminate') ;
				break ;
			}

			if (in_array($status, $array_update_status)) {
				
				switch($status){
					case 'Confirmation' :
						$update_query = "employment_confirmation_date = '".TODAYDATE."'," ;
					break ;
					case 'Terminate' :
						$update_query = "employment_terminate_date = '".TODAYDATE."'," ;
					break ;	
				}
				
				if ($mysqli->query("UPDATE staff_employment SET
									".$update_query."
									employment_status = '".$status."',
									employment_modified = '".TODAYDATE."'
									WHERE employment_id = '".$page."'")){
				
					$result = true ;
					
				}
			}
			
		}
		
	break ;	
	   
}

$array['result'] = $result ;
echo json_encode($array) ;

?>