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

// include the class
include 'requires/class_resize.php' ;

// keep parameter in value
$page 			  = escapeString($_GET['page']) ;
$page_mode 		  = escapeString($_GET['page_mode']) ;
$type 			  = escapeString($_GET['type']) ;
$search 		  = escapeString($_GET['search']) ;
$today_year       = date('Y', time()) ;
$today_minus_1    = date('Y-m-d', strtotime('-1 days')) ;

// active menu bar
$active_main_menu = 'hr' ;
$active_sub_menu  = 'hr-staff' ;

// global use

//get all epf, socso, eis, zakat rate
$epf_rate = $socso_rate = $eis_rate = $zakat_rate = [];
$get_salary_tax = $mysqli->query("SELECT * FROM setting_salary_tax WHERE deleted_at IS NULL");
while($row_tax = mysqli_fetch_assoc($get_salary_tax)){
	if($row_tax['tax_type'] == 'EPF'){
		$epf_rate[$row_tax['tax_id']] = [
							'title' => $row_tax['tax_title'],
							'employee_rate' => $row_tax['employee_rate'],
							'employer_rate' => $row_tax['employer_rate'],
		];
	}else if($row_tax['tax_type'] == 'SOCSO'){
		$socso_rate[$row_tax['tax_id']] = [
							'title' => $row_tax['tax_title'],
							'employee_rate' => $row_tax['employee_rate'],
							'employer_rate' => $row_tax['employer_rate'],
		];
	}else if($row_tax['tax_type'] == 'EIS'){
		$eis_rate[$row_tax['tax_id']] = [
							'title' => $row_tax['tax_title'],
							'employee_rate' => $row_tax['employee_rate'],
							'employer_rate' => $row_tax['employer_rate'],
		];
	}else if($row_tax['tax_type'] == 'ZAKAT'){
		$zakat_rate[$row_tax['tax_id']] = [
							'title' => $row_tax['tax_title'],
							'employee_rate' => $row_tax['employee_rate'],
							'employer_rate' => $row_tax['employer_rate'],
		];
	}
}

// get all gender
$gender     = [] ;
$get_gender = $mysqli->query("SELECT * FROM master_gender
							  WHERE deleted_at IS NULL") ;
if ( $get_gender->num_rows > 0 ){
	while ( $row_gender = $get_gender->fetch_assoc() ){
		$gender[$row_gender['gender_id']] = $row_gender['gender_desc'] ;
	}
}

// get all position
$position 	  = [] ;
$get_position = $mysqli->query("SELECT a.job_position_id, a.job_position_code, b.job_position_desc FROM setting_job_position a
		 						LEFT JOIN setting_job_position_translation b ON ( a.job_position_id = b.job_position_id )
					    		WHERE a.deleted_at IS NULL AND b.lang = 'en'") ;
if ( $get_position->num_rows > 0 ){
	while ( $row_position = $get_position->fetch_assoc() ){
		$position[$row_position['job_position_id']] = $row_position['job_position_code'] . ' ( ' . $row_position['job_position_desc'] . ' )' ;
	}
}

// get all section
$section 	  = [] ;
$get_section = $mysqli->query("SELECT a.job_section_id, a.job_section_code, b.job_section_desc FROM setting_job_section a
                               LEFT JOIN setting_job_section_translation b ON ( a.job_section_id = b.job_section_id )
							   WHERE a.deleted_at IS NULL AND b.lang = 'en'") ;
if ( $get_section->num_rows > 0 ){
	while ( $row_section = $get_section->fetch_assoc() ){
		$section[$row_section['job_section_id']] = $row_section['job_section_code'] . ' ( ' . $row_section['job_section_desc'] . ' )' ;
	}
}

// get all job status
$job_status 	= [] ;
$get_job_status = $mysqli->query("SELECT * FROM master_job_status
							      WHERE deleted_at IS NULL") ;
if ( $get_job_status->num_rows > 0 ){
	while ( $row_job_status = $get_job_status->fetch_assoc() ){
		$job_status[$row_job_status['job_status_id']] = $row_job_status['job_status_desc'] ;
	}
}

// get all country
$country     = [] ;
$get_country = $mysqli->query("SELECT * FROM master_country
							  WHERE deleted_at IS NULL") ;
if ( $get_country->num_rows > 0 ){
	while ( $row_country = $get_country->fetch_assoc() ){
		$country[$row_country['country_id']] = $row_country['country_desc'] ;
	}
}

// get all working group
$working_group     = [] ;
$get_working_group = $mysqli->query("SELECT * FROM setting_working_group
						    		 WHERE deleted_at IS NULL") ;
if ( $get_working_group->num_rows > 0 ){
	while ( $row_working_group = $get_working_group->fetch_assoc() ){
		$working_group[$row_working_group['group_id']] = $row_working_group['group_name'] ;
	}
}

// get all branch
$branch     = [] ;
$get_branch = $mysqli->query("SELECT * FROM branch
							  WHERE deleted_at IS NULL".$user_branch_permission_sql) ;
if ( $get_branch->num_rows > 0 ){
	while ( $row_branch = $get_branch->fetch_assoc() ){
		$branch[$row_branch['branch_id']] = $row_branch['branch_name'] ;
	}
}

// get all requires 
$get_user_tier = userTierQuery( $row_user ) ;

$tier_list     = [] ;
$tier_list_id  = [] ;
$mysqli_tier   = $mysqli->query("SELECT a.tier_id, b.title FROM profile_tier a
                         	     LEFT JOIN profile_tier_translation b ON ( a.tier_id = b.tier_id )
				 			     WHERE a.deleted_at IS NULL AND b.lang = 'en' ORDER BY a.sortable DESC") ;
if ( $mysqli_tier->num_rows > 0 ){
	while ( $row_tier = $mysqli_tier->fetch_assoc() ){
		$tier_list[]  = $row_tier ;
		$tier_list_id[$row_tier['tier_id']] = $row_tier['title'] ;
	}
}

// get all requires 
$department_list   = [] ;
$mysqli_department = $mysqli->query("SELECT a.department_id, b.department_desc FROM setting_department a
						   			 LEFT JOIN setting_department_translation b ON ( a.department_id = b.department_id )
									 WHERE a.deleted_at IS NULL AND b.lang = 'en' ORDER BY b.department_desc ASC") ;
if ( $mysqli_department->num_rows > 0 ){
	while ( $row_department = $mysqli_department->fetch_assoc() ){
		$department_list[]  = $row_department ;
	}
}

// mode type | all list | new | edit
switch($page_mode){

	case 'staff-point-history'  :
		include 'hr-staff-point-history.php';
	break;

	// edit staff
	case 'new'  :
	case 'edit' :
		$active_menu 	  = 'hr-staff-list' ;

		// add permission
		$search_query     = '' ;
		// if ( $_SESSION['system_permission'] != 'admin' ){
  //           if ( permissionCheck($row_user, 'staff-list-view') && permissionCheck($row_user, 'foreign-only') ){
  //               // do nothing
  //           }elseif ( permissionCheck($row_user, 'staff-list-view') ){
  //               $search_query .= " AND country_id  = '1'" ;
  //           }else{
  //               $search_query .= " AND country_id != '1'" ;
  //           }
  //       }

		// check query exsits
		$submit_type = 'new' ;
		$mysqli_page = $mysqli->query("SELECT * FROM staff
									   WHERE staff_id = '".$page."' ".$search_query." LIMIT 1");

		if ($mysqli_page->num_rows > 0){
			// keep query value in array
			$row_page    = $mysqli_page->fetch_array(MYSQLI_ASSOC) ;
			$submit_type = 'edit' ;
		}else{
			$page = '' ;
		}

		// trash passport / permit
		if ( $_GET['staff_image'] == 'yes' && $_GET['staff_image_id'] != '' ){

			$error_message   = '<div class="error_message">'.$lang['Sorry image not found'].'</div>' ;

			$staff_image_id  = escapeString($_GET['staff_image_id']) ;
			$get_staff_image = $mysqli->query("SELECT * FROM staff_image
											   WHERE image_id = '".$staff_image_id."' LIMIT 1") ;
			if ( $get_staff_image->num_rows > 0 ){
				$mysqli->query("UPDATE staff_image SET
								deleted_at = '".TODAYDATE."'
								WHERE image_id = '".$staff_image_id."'") ;
				$error_message   = '<div class="result_success">'.$lang['Thank you image was removed'].'</div>' ;
			}

			// refresh page
			header("Location:hr-staff.php?page_mode=edit&page=".$page) ;
			$_SESSION['system_result'] = $error_message ;
			exit ;
		}

		// update database
		if ( isset($type) && ( $type == 'new' || $type == 'edit' ) && $_POST['hide'] == 1 ){
			$error_message 					= '<div class="result_error">'.$lang['Please enter all required fill'].'</div>' ;
			$message 						= '';

			$staff_idno 					= escapeString($_POST['staff_idno']) ;
			$staff_name 					= escapeString($_POST['staff_name']) ;
			$staff_shortname 				= escapeString($_POST['staff_shortname']) ;
			$staff_mobileno 				= escapeString($_POST['staff_mobileno']) ;
			$staff_birthdate   				= escapeString($_POST['staff_birthdate']) ;
			$staff_date_joined 				= escapeString($_POST['staff_date_joined']) ;
			$staff_tier 					= escapeString($_POST['staff_tier']) ;
			$staff_probation_end 			= escapeString($_POST['staff_probation_end']) ;
			$staff_effective_date 			= escapeString($_POST['staff_effective_date']) ;
			$staff_salary_nextreview_date 	= escapeString($_POST['staff_salary_nextreview_date']) ;
			$staff_salary_effective_date 	= escapeString($_POST['staff_salary_effective_date']) ;
			$staff_username 				= escapeString($_POST['staff_username']) ;
			$staff_email 					= escapeString($_POST['staff_email']) ;
			$password 						= escapeString($_POST['password']) ;
			$passwordnotmatch 				= escapeString($_POST['passwordnotmatch']) ;
			$staff_covid 					= escapeString($_POST['staff_covid']) ;
			$staff_covid_test 				= escapeString($_POST['staff_covid_test']) ;
			$staff_fonema 					= escapeString($_POST['staff_fonema']) ;
			$staff_typhoid 					= escapeString($_POST['staff_typhoid']) ;
			$staff_fenoma_period 			= escapeString($_POST['staff_fenoma_period']) ;
	        $country_id  					= $_POST['country_id'] ;
	        $staff_icno  					= escapeString($_POST['staff_icno']) ;
	        $staff_passportno  				= escapeString($_POST['staff_passportno']) ;
	        $staff_passportexpired  		= escapeString($_POST['staff_passportexpired']) ;


			$old_staff_group[0]				= false;



			// if ( $staff_idno != '' && $staff_name != '' && $staff_shortname != '' && $staff_username != '' && $staff_mobileno != '' && $staff_birthdate != '' && $staff_tier != '' && $staff_date_joined != '' ){

				//if( ($country_id == '1' && $staff_icno != '') || ( $country_id != '' && $staff_passportno != '' && $staff_passportexpired != '') ){

					// check if email not exists
					if ( $staff_email != '' ){
						$check_email = $mysqli->query("SELECT * FROM staff
													   WHERE deleted_at IS NULL AND staff_id != '".$page."' AND staff_email = '".$staff_email."' LIMIT 1") ;
						if ( $check_email->num_rows > 0 ){
							$error_message .= '<div class="result_error">'.$lang['Sorry email already exists'].'</div>' ;
						}
					}

					// check if username not exists
					if ( $staff_username != '' ){
						$check_username = $mysqli->query("SELECT * FROM staff
													   	  WHERE deleted_at IS NULL AND staff_id != '".$page."' AND staff_username = '".$staff_username."' LIMIT 1") ;
						if ( $check_username->num_rows > 0 ){
							$error_message .= '<div class="result_error">'.$lang['Sorry username already exists'].'</div>' ;
						}
					}

					// check if staff idno not exists
					if ( $staff_idno != '' ){
						$check_idno = $mysqli->query("SELECT * FROM staff
													  WHERE deleted_at IS NULL AND staff_id != '".$page."' AND staff_idno = '".$staff_idno."' LIMIT 1") ;
						if ( $check_idno->num_rows > 0 ){
							$error_message .= '<div class="result_error">'.$lang['Sorry idno already exists'].'</div>' ;
						}
					}

					$check_group = $mysqli->query("SELECT * FROM staff
												  WHERE deleted_at IS NULL AND staff_id = '".$page."' LIMIT 1") ;
					if ( $check_group->num_rows > 0 ){
						$row = $check_group->fetch_array(MYSQLI_ASSOC);
						if ( $row['group_id'] != $_POST['group_id'] ){
							$old_staff_group[0] = true;
							$old_staff_group[1] = [
								"old" => $row['group_id'],
								"new" => $_POST['group_id'],
							];
						}
						
					}
					
					

					// if ( $password != '' && $password != $passwordnotmatch ){
					// 	$error_message .= '<div class="result_error">'.$lang['Sorry password doesnt exists'].'</div>' ;
					// }

					// save staff data
					if ( $error_message != '' ){

						$error         = 0 ;
	            		$mysqli->autocommit( false ) ;
	            		
	            		$update_query  = '' ;

	            		try {


	            			// new staff
	            			if ( $page == '' ){
	            				$mysqli->query("INSERT INTO staff (created_at) VALUES ('".TODAYDATE."')") ;
								$page = $mysqli->insert_id ;	
	            			}

	            			// password
	            			if ( $password != '' ){
	            				$staff_password  = passwordEncrypt($password) ;
	            				$update_query   .= "staff_password = '".$staff_password."'," ;
	            			}

	            			// staff settings
					        $staff_settings = [
					            'ismanager'        		  => ( $_POST['staff_setting_ismanager'] == 'yes' ? 'yes' : 'no' ),
					            'ishrmanager'        	  => ( $_POST['staff_setting_ishrmanager'] == 'yes' ? 'yes' : 'no' ),
					            'warning'  				  => ( $_POST['staff_setting_warning'] == 'yes' ? 'yes' : 'no' ),
					            'switchbranch'  	      => ( $_POST['staff_setting_switchbranch_card'] == 'yes' ? 'yes' : 'no' ),
					            'reporttaskbranch'        => ( $_POST['staff_setting_reporttaskbranch_card'] == 'yes' ? 'yes' : 'no' ),
					            'reportadjustmentbranch'  => ( $_POST['staff_setting_reportadjustmentbranch_card'] == 'yes' ? 'yes' : 'no' ),
					            'punch'  			      => ( $_POST['staff_setting_punch_card'] == 'yes' ? 'yes' : 'no' ),
					            'without_geometry'        => ( $_POST['staff_setting_without_geometry'] == 'yes' ? 'yes' : 'no' ),
					            'checkrecruitment'        => ( $_POST['staff_setting_checkrecruitment'] == 'yes' ? 'yes' : 'no' ),
					            'checkassociation'        => ( $_POST['staff_setting_checkassociation'] == 'yes' ? 'yes' : 'no' ),
					            'checktraining'           => ( $_POST['staff_setting_checktraining'] == 'yes' ? 'yes' : 'no' ),
					            'approvevisitation'       => ( $_POST['staff_setting_approvevisitation'] == 'yes' ? 'yes' : 'no' ),
					            'checkvisitation'         => ( $_POST['staff_setting_checkvisitation'] == 'yes' ? 'yes' : 'no' ),
					            'vcard_mode'              => ( $_POST['staff_setting_vcard_mode'] == '1' ? '1' : ( $_POST['staff_setting_vcard_mode'] == '2' ? '2' : '3' ) ),
					            'marital_status'          => escapeString($_POST['marital_status']),
					            'mailing_address'         => escapeString($_POST['mailing_address']),
					            'income_tax_no'    	      => escapeString($_POST['income_tax_no']),
					            'spouse_name'    	      => escapeString($_POST['spouse_name']),
					            'spouse_ic'    		      => escapeString($_POST['spouse_ic']),
					            'spouse_working'          => escapeString($_POST['spouse_working']),
					            'spouse_income_tax'       => escapeString($_POST['spouse_income_tax']),
					            'no_children'    	      => escapeString($_POST['no_children']),
					        ] ;
					        $staff_settings = json_encode($staff_settings) ;

					        // resize image
					        // set image in variable
							$image 		  = $_FILES["staff_image"]["name"] ;
							$image_query  = '' ;
							$remove_photo = $_POST['remove_photo'] ;
							if ($remove_photo == 1){
								$image = '' ;	
								$image_query = "staff_image = ''," ;
							}
							$create_image = reCreateImage('Staff', $page, $page, '', $image, $_FILES["staff_image"]["type"], $_FILES['staff_image']['tmp_name']) ;
							
							// Image uploads when exists
							if ($create_image['result'] && is_array($create_image['crop']) && count($create_image['result']) > 0){
								$resizeObj = new resize($create_image['original']) ; // Initialise load image
								foreach($create_image['crop'] as $value){
									// Resize image (options: exact, portrait, landscape, auto, crop)
									$resizeObj -> resizeImage($value['width'], $value['height'], $value['type']) ;
									$resizeObj -> saveImage($value['source'], 70) ; // Save image	
								}
								$image_query = "staff_image = '".$create_image['image']."'," ;
							}

							//Array ( [name] => Array ( [0] => addon-apk.pdf ) [type] => Array ( [0] => application/pdf ) [tmp_name] => Array ( [0] => /tmp/phpy5FLEr ) [error] => Array ( [0] => 0 ) [size] => Array ( [0] => 314338 ) )

							// passport image
							$passportimages = $_FILES['passportimages'] ;
							if ( arrayCheck($passportimages['name']) ){
								foreach ( $passportimages['name'] as $k => $v ){

									$image = $v ;
									if ( $_FILES['passportimages']['type'][$k] == 'application/pdf' ){
										$new_image = 'ppd-'.$k.'-'.rand(000000, 999999).'-'.time().'.pdf' ;
										copy( $_FILES['passportimages']['tmp_name'][$k], 'uploads/StaffImage/'.$new_image ) ;
										$mysqli->query("INSERT INTO staff_image
														(staff_id, type, file_name, created_at, updated_at) VALUES
														('".$page."', 'passport', '".$new_image."', '".TODAYDATE."', '".TODAYDATE."')") ;
									}else{
										$create_image = reCreateImage('StaffImage', $page, 'ppi-'.$k.'-'.rand(000000, 999999).'-'.time(), '', $image, $_FILES['passportimages']["type"][$k], $_FILES['passportimages']['tmp_name'][$k]) ;

										// Image uploads when exists
										if ($create_image['result'] && is_array($create_image['crop']) && count($create_image['result']) > 0){
											$resizeObj = new resize($create_image['original']) ; // Initialise load image
											foreach($create_image['crop'] as $value){
												// Resize image (options: exact, portrait, landscape, auto, crop)
												$resizeObj -> resizeImage($value['width'], $value['height'], $value['type']) ;
												$resizeObj -> saveImage($value['source'], 70) ; // Save image	
											}
											$mysqli->query("INSERT INTO staff_image
															(staff_id, type, file_name, created_at, updated_at) VALUES
															('".$page."', 'passport', '".$create_image['image']."', '".TODAYDATE."', '".TODAYDATE."')") ;
										}
									}
								}
							}

							// permit image
							$permitimages = $_FILES['permitimages'] ;
							if ( arrayCheck($permitimages['name']) ){
								foreach ( $permitimages['name'] as $k => $v ){
									$image = $v ;
									if ( $_FILES['permitimages']['type'][$k] == 'application/pdf' ){
										$permit_pdf = 'pd-'.$k.'-'.rand(000000, 999999).'-'.time().'.pdf' ;
										copy( $_FILES['permitimages']['tmp_name'][$k], 'uploads/StaffImage/'.$permit_pdf ) ;
										$mysqli->query("INSERT INTO staff_image
														(staff_id, type, file_name, created_at, updated_at) VALUES
														('".$page."', 'permit', '".$permit_pdf."', '".TODAYDATE."', '".TODAYDATE."')") ;
									}
									else{
										$create_image = reCreateImage('StaffImage', $page, 'pi-'.$k.'-'.rand(000000, 999999).'-'.time(), '', $image, $_FILES['permitimages']["type"][$k], $_FILES['permitimages']['tmp_name'][$k]) ;
										// Image uploads when exists
										if ($create_image['result'] && is_array($create_image['crop']) && count($create_image['result']) > 0){
											$resizeObj = new resize($create_image['original']) ; // Initialise load image
											foreach($create_image['crop'] as $value){
												// Resize image (options: exact, portrait, landscape, auto, crop)
												$resizeObj -> resizeImage($value['width'], $value['height'], $value['type']) ;
												$resizeObj -> saveImage($value['source'], 70) ; // Save image	
											}
											$mysqli->query("INSERT INTO staff_image
															(staff_id, type, file_name, created_at, updated_at) VALUES
															('".$page."', 'permit', '".$create_image['image']."', '".TODAYDATE."', '".TODAYDATE."')") ;
										}
									}
								}
							}
	            			// update database
							$mysqli->query("UPDATE staff SET
											".$update_query."
											".$image_query."
											staff_idno  					= '".$staff_idno."',
									        staff_name  					= '".$staff_name."',
									        staff_shortname  				= '".$staff_shortname."',
									        staff_email  					= '".$staff_email."',
									        staff_username  				= '".$staff_username."',
									        staff_mobileno  				= '".$staff_mobileno."',
									        gender_id  						= '".escapeString($_POST['gender_id'])."',
									        staff_birthdate  				= '".escapeString($_POST['staff_birthdate'])."',
									        country_id  					= '".escapeString($_POST['country_id'])."',
									        staff_icno  					= '".escapeString($_POST['staff_icno'])."',
									        staff_passportno  				= '".escapeString($_POST['staff_passportno'])."',
									        staff_passportexpired  			= '".escapeString($_POST['staff_passportexpired'])."',
									        religion_id  					= '".escapeString($_POST['religion_id'])."',
									        ethnic_id  						= '".escapeString($_POST['ethnic_id'])."',
									        staff_date_joined  				= '".escapeString($_POST['staff_date_joined'])."',
									        staff_tier 			     	    = '".escapeString($_POST['staff_tier'])."',
									        staff_date_confirmed  			= '".escapeString($_POST['staff_date_confirmed'])."',
									        staff_date_resigned  			= '".escapeString($_POST['staff_date_resigned'])."',
									        staff_run_away	 	  			= '".escapeString($_POST['staff_run_away'])."',
									        staff_resign_reason  			= '".escapeString($_POST['staff_resign_reason'])."',
									        staff_probation_end  			= '".escapeString($_POST['staff_probation_end'])."',
									        job_position_id  				= '".escapeString($_POST['job_position_id'])."',
									        job_section_id  				= '".escapeString($_POST['job_section_id'])."',
									        staff_effective_date 			= '".escapeString($_POST['staff_effective_date'])."',
									        branch_id  						= '".escapeString($_POST['branch_id'])."',
									        leave_id  						= '".escapeString($_POST['leave_id'])."',
									        sick_id  						= '".escapeString($_POST['sick_id'])."',
									        group_id  						= '".escapeString($_POST['group_id'])."',
									        salary_id  						= '".escapeString($_POST['salary_id'])."',
									        job_type_id  					= '".escapeString($_POST['job_type_id'])."',
									        job_status_id 					= '".escapeString($_POST['job_status_id'])."',
									        work_type_id 					= '".escapeString($_POST['work_type_id'])."',
									        staff_permitno 					= '".escapeString($_POST['staff_permitno'])."',
									        staff_permit_start 				= '".escapeString($_POST['staff_permit_start'])."',
									        staff_permit_end 				= '".escapeString($_POST['staff_permit_end'])."',
									        staff_permit_effective_date 	= '".escapeString($_POST['staff_permit_effective_date'])."',
									        staff_salary 					= '".escapeString($_POST['staff_salary'])."',
									        staff_contract_salary 			= '".escapeString($_POST['staff_contract_salary'])."',
									        staff_allowance_topup 			= '".escapeString($_POST['staff_allowance_topup'])."',
									        staff_allowance_work			= '".escapeString($_POST['staff_allowance_work'])."',
									        staff_allowance_food			= '".escapeString($_POST['staff_allowance_food'])."',
									        staff_salary_nextreview_date 	= '".escapeString($_POST['staff_salary_nextreview_date'])."',
									        staff_salary_effective_date 	= '".escapeString($_POST['staff_salary_effective_date'])."',
									        bank_id  						= '".escapeString($_POST['bank_id'])."',
									        payment_type_id  				= '".escapeString($_POST['payment_type_id'])."',
									        payment_transfer_id 			= '".escapeString($_POST['payment_transfer_id'])."',
									        staff_accountno  				= '".escapeString($_POST['staff_accountno'])."',
									        staff_epf_rate  				= '".escapeString($_POST['staff_epf_rate'])."',
									        staff_epf_rate_id  				= '".escapeString($_POST['staff_epf_rate_id'])."',
									        staff_socso_rate_id  			= '".escapeString($_POST['staff_socso_rate_id'])."',
									        staff_eis_rate_id  				= '".escapeString($_POST['staff_eis_rate_id'])."',
									        staff_zakat_rate_id  			= '".escapeString($_POST['staff_zakat_rate_id'])."',
									        staff_epfno  					= '".escapeString($_POST['staff_epfno'])."',
									        staff_taxno  					= '".escapeString($_POST['staff_taxno'])."',
									        staff_child_relief  			= '".escapeString($_POST['staff_child_relief'])."',
									        staff_eis_status  				= '".escapeString($_POST['staff_eis_status'])."',
									        socso_category_id  				= '".escapeString($_POST['socso_category_id'])."',
									        tax_status_id  					= '".escapeString($_POST['tax_status_id'])."',
									        staff_muslim_zakat  			= '".escapeString($_POST['staff_muslim_zakat'])."',
									        staff_eis_status  				= '".escapeString($_POST['staff_eis_status'])."',
									        staff_settings  				= '".$staff_settings."',
									        staff_covid  					= '".$staff_covid."',
									        staff_covid_test  				= '".$staff_covid_test."',
									        staff_fonema  					= '".$staff_fonema."',
									        staff_fenoma_period				= '".$staff_fenoma_period."',
									        staff_typhoid  					= '".$staff_typhoid."',
											updated_at 						= '".TODAYDATE."'
											WHERE staff_id 					= '".$page."'") ;
						
							// knowledge check list
							$knowledgelist = $_POST['knowledge'] ;
							$mysqli->query("DELETE FROM staff_knowledge 
											WHERE staff_id = '".$page."'") ;
							
			                if( !empty($knowledgelist) ){
			                    for ( $i = 0 ; $i < count($knowledgelist) ; $i++ ){
			                    	$mysqli->query("INSERT INTO staff_knowledge
			                    					(staff_id, knowledge_id, created_at, updated_at) VALUES
			                    					('".$page."', '".$knowledgelist[$i]."', '".TODAYDATE."', '".TODAYDATE."')") ;
			                    }
			                }

			                // department check list
							$departmentlist = $_POST['department'] ;
							$mysqli->query("DELETE FROM staff_department
											WHERE staff_id = '".$page."'") ;
							
			                if( !empty($departmentlist) ){
			                    for ( $i = 0 ; $i < count($departmentlist) ; $i++ ){
			                    	$mysqli->query("INSERT INTO staff_department
			                    					(staff_id, department_id, created_at, updated_at) VALUES
			                    					('".$page."', '".$departmentlist[$i]."', '".TODAYDATE."', '".TODAYDATE."')") ;
			                    }
			                }

			                // hostel check list
							$hostellist = $_POST['hostel'] ;
							$mysqli->query("DELETE FROM staff_hostel
											WHERE staff_id = '".$page."'") ;
							
			                if( !empty($hostellist) ){
			                    for ( $i = 0 ; $i < count($hostellist) ; $i++ ){
			                    	$mysqli->query("INSERT INTO staff_hostel
			                    					(staff_id, hostel_id, created_at, updated_at) VALUES
			                    					('".$page."', '".$hostellist[$i]."', '".TODAYDATE."', '".TODAYDATE."')") ;
			                    }
			                }

							// add system log
							$array_remark = array('old' => array('staff_name' => $row_page['staff_name']),
									  			  'new' => array('staff_name' => $staff_name)) ;

							

			            }catch( Exception $e ){
			                $error_message .= '<div class="result_error">'.$lang['Sorry something error'].' ('.$e.').</div>' ;
			                $error++;
			            }

			            if( $error == 0 ) {

			                // commit query
			                $mysqli->commit() ; 
			                $error_message = '<div class="result_success">'.$lang['Thank you your staff has been updated'].'</div>' ;

			            }else{
			                $mysqli->rollback() ;
			            }

					}
						
				//}else{
					//$error_message ;
				//}

			// }

			// refresh page
			header("Location:hr-staff.php?page_mode=edit&page=".$page) ;
			$_SESSION['system_result'] = $error_message ;
			exit ;
		}

		// get all ethnic
		$ethnic     = [] ;
		$get_ethnic = $mysqli->query("SELECT * FROM master_ethnic
									  WHERE deleted_at IS NULL") ;
		if ( $get_ethnic->num_rows > 0 ){
			while ( $row_ethnic = $get_ethnic->fetch_assoc() ){
				$ethnic[$row_ethnic['ethnic_id']] = $row_ethnic['ethnic_desc'] ;
			}
		}

		// get all religion
		$religion     = [] ;
		$get_religion = $mysqli->query("SELECT * FROM master_religion
									    WHERE deleted_at IS NULL") ;
		if ( $get_religion->num_rows > 0 ){
			while ( $row_religion = $get_religion->fetch_assoc() ){
				$religion[$row_religion['religion_id']] = $row_religion['religion_desc'] ;
			}
		}

		// get all leave
		$leave     = [] ;
		$get_leave = $mysqli->query("SELECT * FROM setting_leave
									 WHERE deleted_at IS NULL") ;
		if ( $get_leave->num_rows > 0 ){
			while ( $row_leave = $get_leave->fetch_assoc() ){
				$leave[$row_leave['leave_id']] = $row_leave['leave_name'] ;
			}
		}

		// get all sick
		$sick     = [] ;
		$get_sick = $mysqli->query("SELECT * FROM setting_sick
									WHERE deleted_at IS NULL") ;
		if ( $get_sick->num_rows > 0 ){
			while ( $row_sick = $get_sick->fetch_assoc() ){
				$sick[$row_sick['sick_id']] = $row_sick['sick_name'] ;
			}
		}

		// get all job type
		$job_type     = [] ;
		$get_job_type = $mysqli->query("SELECT * FROM master_job_type
										WHERE deleted_at IS NULL") ;
		if ( $get_job_type->num_rows > 0 ){
			while ( $row_job_type = $get_job_type->fetch_assoc() ){
				$job_type[$row_job_type['job_type_id']] = $row_job_type['job_type_desc'] ;
			}
		}

		// get all work days
		$work_type     = [] ;
		$get_work_type = $mysqli->query("SELECT * FROM master_work_type
										 WHERE deleted_at IS NULL") ;
		if ( $get_work_type->num_rows > 0 ){
			while ( $row_work_type = $get_work_type->fetch_assoc() ){
				$work_type[$row_work_type['work_type_id']] = $row_work_type['work_type_desc'] ;
			}
		}

		// get all chief
		$chief     = [] ;
		$get_chief = $mysqli->query("SELECT * FROM setting_chief
								     WHERE deleted_at IS NULL") ;
		if ( $get_chief->num_rows > 0 ){
			while ( $row_chief = $get_chief->fetch_assoc() ){
				$chief[$row_chief['chief_id']] = $row_chief['chief_desc'] ;
			}
		}

		// get all bank
		$bank     = [] ;
		$get_bank = $mysqli->query("SELECT * FROM master_bank
									WHERE deleted_at IS NULL") ;
		if ( $get_bank->num_rows > 0 ){
			while ( $row_bank = $get_bank->fetch_assoc() ){
				$bank[$row_bank['bank_id']] = $row_bank['bank_desc'] ;
			}
		}

		// get all payment transfer
		$payment_transfer     = [] ;
		$get_payment_transfer = $mysqli->query("SELECT * FROM master_payment_transfer
								    		    WHERE deleted_at IS NULL") ;
		if ( $get_payment_transfer->num_rows > 0 ){
			while ( $row_payment_transfer = $get_payment_transfer->fetch_assoc() ){
				$payment_transfer[$row_payment_transfer['payment_transfer_id']] = $row_payment_transfer['payment_transfer_desc'] ;
			}
		}

		// get all payment transfer
		$payment_type     = [] ;
		$get_payment_type = $mysqli->query("SELECT * FROM master_payment_type
								    		WHERE deleted_at IS NULL") ;
		if ( $get_payment_type->num_rows > 0 ){
			while ( $row_payment_type = $get_payment_type->fetch_assoc() ){
				$payment_type[$row_payment_type['payment_type_id']] = $row_payment_type['payment_type_desc'] ;
			}
		}

		// get all payment transfer
		$socso_category     = [] ;
		$get_socso_category = $mysqli->query("SELECT * FROM master_socso_category
								    		  WHERE deleted_at IS NULL") ;
		if ( $get_socso_category->num_rows > 0 ){
			while ( $row_socso_category = $get_socso_category->fetch_assoc() ){
				$socso_category[$row_socso_category['socso_category_id']] = $row_socso_category['socso_category_desc'] ;
			}
		}

		// get all payment transfer
		$tax_status     = [] ;
		$get_tax_status = $mysqli->query("SELECT * FROM master_tax_status
								    	  WHERE deleted_at IS NULL") ;
		if ( $get_tax_status->num_rows > 0 ){
			while ( $row_tax_status = $get_tax_status->fetch_assoc() ){
				$tax_status[$row_tax_status['tax_status_id']] = $row_tax_status['tax_status_desc'] ;
			}
		}

		// get all knowledge
		$knowledge     = [] ;
		$get_knowledge = $mysqli->query("SELECT * FROM setting_knowledge
								    	 WHERE deleted_at IS NULL") ;
		if ( $get_knowledge->num_rows > 0 ){
			while ( $row_knowledge = $get_knowledge->fetch_assoc() ){
				$knowledge[$row_knowledge['knowledge_id']] = $row_knowledge['knowledge_desc'] ;
			}
		}

		// get all hostel
		$hostel     = [] ;
		$get_hostel = $mysqli->query("SELECT * FROM setting_hostel
								     WHERE deleted_at IS NULL") ;
		if ( $get_hostel->num_rows > 0 ){
			while ( $row_hostel = $get_hostel->fetch_assoc() ){
				$hostel[$row_hostel['hostel_id']] = $row_hostel['hostel_desc'] ;
			}
		}

		// get all department
		$department     = [] ;
		$get_department = $mysqli->query("SELECT a.department_id, b.department_desc FROM setting_department a
						   				  LEFT JOIN setting_department_translation b ON ( a.department_id = b.department_id )
								 		  WHERE a.deleted_at IS NULL AND b.lang = 'en'") ;
		if ( $get_department->num_rows > 0 ){
			while ( $row_department = $get_department->fetch_assoc() ){
				$department[$row_department['department_id']] = $row_department['department_desc'] ;
			}
		}

		// get selected knowledge
		$selected_knowledge     = [] ;
		$get_selected_knowledge = $mysqli->query("SELECT * FROM staff_knowledge
								          		  WHERE deleted_at IS NULL AND staff_id = '".$page."'") ;
		if ( $get_selected_knowledge->num_rows > 0 ){
			while ( $row_selected_knowledge = $get_selected_knowledge->fetch_assoc() ){
				$selected_knowledge[] = $row_selected_knowledge['knowledge_id'] ;
			}
		}

		// get selected hostel
		$selected_hostel     = [] ;
		$get_selected_hostel = $mysqli->query("SELECT * FROM staff_hostel
								          	   WHERE deleted_at IS NULL AND staff_id = '".$page."'") ;
		if ( $get_selected_hostel->num_rows > 0 ){
			while ( $row_selected_hostel = $get_selected_hostel->fetch_assoc() ){
				$selected_hostel[] = $row_selected_hostel['hostel_id'] ;
			}
		}

		// get selected department
		$selected_department     = [] ;
		$get_selected_department = $mysqli->query("SELECT * FROM staff_department
								          	   	   WHERE deleted_at IS NULL AND staff_id = '".$page."'") ;
		if ( $get_selected_department->num_rows > 0 ){
			while ( $row_selected_department = $get_selected_department->fetch_assoc() ){
				$selected_department[] = $row_selected_department['department_id'] ;
			}
		}

		// default config
		$default_config_punch = DEFAULTPUNCH ;

		$staff_settings = $row_page['staff_settings'] ;
		if ( $staff_settings != '' ){
			$staff_settings = JsonEncodeDecode('decode', $staff_settings) ;
		}else{
			$staff_settings = [] ;
		}

		$passportimages = [] ;
		$permitimages   = [] ;
		$get_staff_image = $mysqli->query("SELECT * FROM staff_image
								           WHERE deleted_at IS NULL AND staff_id = '".$page."'") ;
		if ( $get_staff_image->num_rows > 0 ){
			while ( $row_staff_image = $get_staff_image->fetch_assoc() ){
				if ( $row_staff_image['type'] == 'passport' ){
					$passportimages[$row_staff_image['image_id']] = $row_staff_image['file_name'] ;
				}
				if ( $row_staff_image['type'] == 'permit' ){
					$permitimages[$row_staff_image['image_id']]   = $row_staff_image['file_name'] ;
				}
			}
		}

		// start header here
		include 'requires/page_header.php';
		include 'requires/page_top.php';

		?>

		<script>
		$(document).ready(function(){
			// jquery validate form
			$("#staff_form").validate({
				ignore: ".ignore",
				invalidHandler: function (form, validator) {
					// full error = 24
					if ( $('.group_1').hasClass('error') ){

					}else if ( $('.group_2').hasClass('error') ){
						$('.nav_item_group_2 a').click() ;
					}else if ( $('.group_3').hasClass('error') ){
						$('.nav_item_group_3 a').click() ;
					}
		        },
		        unhighlight: function (element, errorClass, validClass) {
					console.log(2) ;
		        }
			});

			// Init all select2 elements
		    $('.js-select2').select2();
		  
		    $('form').on('submit', function(e) {
		      var $select2 = $('.js-select2', $(this));
		      
		      // Reset
		      $select2.parents('.form-group').removeClass('is-invalid');
		      
		      if ($select2.val() === '') {
		        
		        // Add is-invalid class when select2 element is required
		        $select2.parents('.form-group').addClass('is-invalid');
		        
		        // Stop submiting
		        e.preventDefault();
		        return false;
		      }
		    });
			
		}) ;
		</script>

		<style>
		.nav-pills>li>a{
			border-radius: 0;
		}
		.panel-primary>.panel-footer, .panel-primary>.panel-heading{
		    background-color: #337ab7;
    		border-color: #337ab7;
    	}
    	.panel-primary{
    		border-color: #337ab7;
    	}
    	.staff_image_box img{
			display: block;
		    float: left;
		    margin-bottom: 5px;
		    margin-right: 5px;
		    width: 70px;
		    height: 70px;
		    border: 1px solid #ccc;
		    border-radius: 5px;
		}
		</style>

		<div class="warper container-fluid">   	
			<div class="page-header"><h1><?= $lang['Staff'] ?> <small><?= $lang[$page_mode] ?></small></h1></div>
			<?php
            if ($_SESSION['system_result'] != ''){
                echo $_SESSION['system_result'] ;
                unset($_SESSION['system_result']) ;
            }
            ?>

            <?php
      //       $mysqli_next_previous = $mysqli->query("SELECT * FROM staff
						// 			  				WHERE deleted_at IS NULL ORDER BY (staff_idno * 1) ASC, staff_idno ASC");
            
      //       $boolean_next = false ;
      //       $temp_id = $previous_id = '' ;
      //       while ($row_next_previous = $mysqli_next_previous->fetch_array(MYSQLI_ASSOC)){
      //           $next_previous_id = $row_next_previous['staff_id'] ;

      //           if ($boolean_next){
      //               $next_id = $next_previous_id ;
      //               $boolean_next = false ;
      //           }

      //           if ($next_previous_id == $page){
      //               $previous_id = $temp_id ;
      //               $boolean_next = true ;
      //           }
                
      //           $temp_id = $next_previous_id ;
      //       }
            
      //       if ($previous_id != '' || $next_id != ''){
      //           echo '
      //           <div class="panel panel-default">
      //               <div class="panel-heading"></div>
      //               <div class="panel-body">
						// '.($previous_id != '' ? '<a href="hr-staff.php?page_mode=edit&page='.$previous_id.'" class="btn btn-purple">'.$lang['Previous'].'</a>' : '').'
						// '.($next_id != '' ? '<a href="hr-staff.php?page_mode=edit&page='.$next_id.'" class="btn btn-purple float_right">'.$lang['Next'].'</a>' : '').'
      //               </div>
      //           </div>' ;
      //       }
			?>

            <div class="panel panel-default">
                <div class="panel-heading"></div> 
                <div class="panel-body">
                    <form method="post" class="form-horizontal" id="staff_form" enctype="multipart/form-data" action="hr-staff.php?page_mode=edit&page=<?= $page ?>&type=edit" novalidate="novalidate">

						<div class="card">
							<div class="card-header d-flex p-0" style="border-bottom: 5px solid #337ab7; margin-bottom:20px">
								<ul class="nav nav-pills ml-auto p-2">
									<li class="nav-item nav_item_group_1 active"><a class="nav-link active" href="#tab_1" data-toggle="tab"><?= $lang['Personal Info'] ?></a></li>
									<!-- <li class="nav-item nav_item_group_2"><a class="nav-link" href="#tab_2" data-toggle="tab"><?= $lang['Tier'] ?></a></li> -->
									<li class="nav-item nav_item_group_2"><a class="nav-link" href="#tab_3" data-toggle="tab"><?= $lang['job'] ?></a></li>
									<li class="nav-item nav_item_group_3"><a class="nav-link" href="#tab_4" data-toggle="tab"><?= $lang['salary'] ?></a></li>
									<!-- <li class="nav-item nav_item_group_4"><a class="nav-link" href="#tab_5" data-toggle="tab"><?= $lang['knowledge'] ?></a></li> -->
									<li class="nav-item nav_item_group_5"><a class="nav-link" href="#tab_6" data-toggle="tab"><?= $lang['Department'] ?></a></li>
									<?php if ( permissionWebsite($row_page_website, 'hr-hostel-list') ){ ?>
										<!-- <li class="nav-item nav_item_group_6"><a class="nav-link" href="#tab_7" data-toggle="tab"><?= $lang['Hostel'] ?></a></li> -->
									<?php } ?>
									<!-- <li class="nav-item nav_item_group_7"><a class="nav-link" href="#tab_8" data-toggle="tab"><?= $lang['setting'] ?></a></li> -->
								</ul>
							</div>

			                <div class="tab-content">
								<div class="tab-pane active" id="tab_1">
									<div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['Personal Info'] ?></div><br/>
			                            <div class="panel-body">

			                            	<?php if ( $submit_type == 'edit' ){ 
			                            		$generatecode     = generateQrcode( '', $row_page['staff_idno'], PATH.'hr-staff-vcard.php?staff_idno='.$row_page['staff_idno'] ) ;
										        $new_code         = $generatecode['url'] ;
			                            		?>
			                            	<div class="form-group">
					                            <div class="col-sm-2 control-label"><?= $lang['Qrcode'] ?></div>
					                            <div class="col-sm-9">
					                            	<a href="<?= $new_code ?>" target="_blank">
						                                <img src="<?= $new_code ?>" style="width:100px;" />
						                            </a>
					                            </div>
					                        </div>
			                            	<?php } ?>

										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Profile Image'] ?></div>
										        <div class="col-sm-9">
										        	<input type="file" name="staff_image" id="staff_image" class="modaldata temporarynotcontrol" accept="image/*" />
										        </div>
										    </div>
										    <div class="form-group">
				                                <div class="col-sm-2 control-label"><?= $lang['preview'] ?></div>
				                                <div class="col-sm-9">
				                                    <?php
				                                    if ( $row_page['staff_image'] != '' ){
				                                        echo '
				                                        <label class="remove_photo"><input type="checkbox" name="remove_photo" class="ui-checkbox tick" value="1">&nbsp;'.$lang['remove_photo'].'</label>
				                                        <img src="'.PATH.'uploads/Staff/'.dataFilter($row_page['staff_image']).'?t='.time().'" width="180" />' ;
				                                    }else{
				                                        echo '
				                                        <input type="hidden" name="remove_photo" value="">
				                                        <input type="text" class="form-control ui-search-input" value="'.$lang['no_image'].'" disabled />' ;	
				                                    }
				                                    ?>
				                                </div>
				                            </div>
			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Staff ID'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <input class="form-control <?= ( $row_page['staff_idno'] != '' ? 'readonlyinput' : '' ) ?> temporarynotcontrol group_1" name="staff_idno" id="staff_idno" maxlength="50" type="text" value="<?= $row_page['staff_idno'] ?>" placeholder="<?= $lang['Staff ID'] ?>"  >
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['fullname'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_name" id="staff_name" type="text" value="<?= $row_page['staff_name'] ?>" placeholder="<?= $lang['fullname'] ?>"   />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Short Name'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_shortname" id="staff_shortname" type="text" value="<?= $row_page['staff_shortname'] ?>" placeholder="<?= $lang['Short Name'] ?>"   />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['email'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_email" id="staff_email" type="text" value="<?= $row_page['staff_email'] ?>" placeholder="<?= $lang['email'] ?>" />
										        </div>
										    </div>
										    <div class="form-group" style="display: none;">
			                            		<div class="col-sm-2 control-label"><?= $lang['username'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_username" id="staff_username" type="text" value="<?= $row_page['staff_username'] ?>" placeholder="<?= $lang['username'] ?>" autocomplete="new-staff_username"  />
										        </div>
										    </div>
										    <div class="form-group" style="display: none;">
			                            		<div class="col-sm-2 control-label"><?= $lang['password'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="password" id="password" type="text" placeholder="<?= $lang['password'] ?>" autocomplete="new-password" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Mobile No'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol group_1" name="staff_mobileno" id="staff_mobileno" type="text" value="<?= $row_page['staff_mobileno'] ?>" placeholder="<?= $lang['Mobile No'] ?>"  />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Gender'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										        	<select name="gender_id" id="gender_id" class="form-control"  >
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $gender as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['gender_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <?php
									        // date in mm/dd/yyyy format; or it can be in other formats as well
											$birthDate = $row_page['staff_birthdate'] ;
											$age       = "(-)" ;
											if( $birthDate!='' && $birthDate !='0000-00-00' ){
												$birthDate = date("Y",strtotime($row_page['staff_birthdate']));
												$age = date("Y") - $birthDate;
												if( $birthDate != '' ){
													$age = "( ".$age." years old )";
												}
											}
									        ?>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Birth Date'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol group_1" name="staff_birthdate" id="staff_birthdate" type="date" value="<?= $row_page['staff_birthdate'] ?>" placeholder="<?= $lang['Birth Date'] ?>"  /><?= $age ?>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Marital Status'] ?></div>
										        <div class="col-sm-9">
										        	<select name="marital_status" id="marital_status" class="chosen-select select2-basic-single form-control group_1">
										        		<option value=""><?= $lang['select'] ?></option>
										        		<option value="Single" <?= $staff_settings['marital_status'] == 'Single' ? 'selected' : '' ?> >Single</option>
										        		<option value="Married" <?= $staff_settings['marital_status'] == 'Married' ? 'selected' : '' ?> >Married</option>
										        		<option value="Divorced" <?= $staff_settings['marital_status'] == 'Divorced' ? 'selected' : '' ?> >Divorced</option>
										        		<option value="Widow" <?= $staff_settings['marital_status'] == 'Widow' ? 'selected' : '' ?> >Widow</option>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Mailing Address'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol group_1" name="mailing_address" id="mailing_address" type="etxt" value="<?= $staff_settings['mailing_address'] ?>" placeholder="<?= $lang['Mailing Address'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Income Tax No'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol group_1" name="income_tax_no" id="income_tax_no" type="etxt" value="<?= $staff_settings['income_tax_no'] ?>" placeholder="<?= $lang['Income Tax No'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Spouse Name'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol group_1" name="spouse_name" id="spouse_name" type="etxt" value="<?= $staff_settings['spouse_name'] ?>" placeholder="<?= $lang['Spouse Name'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Spouse IC'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol group_1" name="spouse_ic" id="spouse_ic" type="etxt" value="<?= $staff_settings['spouse_ic'] ?>" placeholder="<?= $lang['Spouse IC'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Spouse Working'] ?></div>
										        <div class="col-sm-9">
										        	<select name="spouse_working" id="spouse_working" class="chosen-select select2-basic-single form-control group_1">
										        		<option value=""><?= $lang['select'] ?></option>
										        		<option value="Yes" <?= $staff_settings['spouse_working'] == 'Yes' ? 'selected' : '' ?> >Yes</option>
										        		<option value="No" <?= $staff_settings['spouse_working'] == 'No' ? 'selected' : '' ?> >No</option>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Spouse Income Tax'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol group_1" name="spouse_income_tax" id="spouse_income_tax" type="etxt" value="<?= $staff_settings['spouse_income_tax'] ?>" placeholder="<?= $lang['Spouse Income Tax'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['No Children'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol group_1" name="no_children" id="no_children" type="etxt" value="<?= $staff_settings['no_children'] ?>" placeholder="<?= $lang['No Children'] ?>" />
										        </div>
										    </div>

			                            </div>
			                        </div>

			                        <div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['Nationality'] ?></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Country'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										        	<select name="country_id" id="country_id" class="js-select2 chosen-select select2-basic-single form-control group_1"  >
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $country as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['country_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['NRIC'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_icno" id="staff_icno" type="text" value="<?= $row_page['staff_icno'] ?>" placeholder="<?= $lang['NRIC'] ?>" />
										            <small><?= $lang['if not put'] ?> -</small>
										        </div>
										    </div>
										    <div class="form-group" style="display: none;">
			                            		<div class="col-sm-2 control-label"><?= $lang['Passport No'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_passportno" id="staff_passportno" type="text" value="<?= $row_page['staff_passportno'] ?>" placeholder="<?= $lang['Passport No'] ?>" />
										            <small><?= $lang['if not put'] ?> -</small>
										        </div>
										    </div>
										    <div class="form-group" style="display: none;">
			                            		<div class="col-sm-2 control-label"><?= $lang['Passport Expired Date'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_passportexpired" id="staff_passportexpired" type="date" value="<?= $row_page['staff_passportexpired'] ?>" placeholder="<?= $lang['Passport Expired Date'] ?>" />
										            <small><?= $lang['if not put'] ?> -</small>
										        </div>
										    </div>
										    <div class="form-group" style="display: none;">
			                            		<div class="col-sm-2 control-label"><?= $lang['IC Passport Image'] ?></div>
										        <div class="col-sm-9">
										        	<input type="file" name="passportimages[]" id="passportimages" class="modaldata temporarynotcontrol" accept="image/*" multiple />
										        </div>
										    </div>
										    <style type="text/css">
										    	.staff_image_box2 img{
										    		float: none;
										    	}
										    </style>
										    <?php if ( count($passportimages) > 0 ){ ?>
					                            <div class="form-group">
				                                    <div class="col-sm-2 control-label"><?= $lang['preview'] ?></div>
				                                    <div class="col-sm-9">
				                                    	<div class="staff_image_box staff_image_box2 clearfix">
					                                    	<?php 
				                                    		foreach ( $passportimages as $k => $v ){ 
				                                    			if(strpos($v, ".pdf") == true){
				                                    				?>
					                                    			<div style="float: left; padding-right: 5px;">
			                                    						<image src="<?= PATH ?>images/pdf.png" />
				                                    						<div style="float: left;">
				                                    							<a href="viewer.html?file=<?= PATH ?>uploads/StaffImage/<?= $v ?>" target="_blank">View</a>
				                                    						</div>
				                                    						<div style="float: right; padding-right: 5px">
				                                    							<a onclick="return confirm('Are you sure?')" href="hr-staff.php?page_mode=edit&page=<?= $page ?>&staff_image=yes&staff_image_id=<?= $k ?>">Del</a>
				                                    						</div>
				                                    					</div>
					                                    			<?php
				                                    			}
				                                    			else{
				                                    				?>
					                                    			<div style="float: left; padding-right: 5px;">
			                                    						<image src="<?= PATH ?>uploads/StaffImage/<?= $v ?>" />
			                                    						<div style="float: left;">
			                                    							<a href="<?= PATH ?>uploads/StaffImage/b/<?= $v ?>" target="_blank">View</a>
			                                    						</div>
			                                    						<div style="float: right; padding-right: 6px">
			                                    							<a onclick="return confirm('Are you sure?')" href="hr-staff.php?page_mode=edit&page=<?= $page ?>&staff_image=yes&staff_image_id=<?= $k ?>">Del</a>
			                                    						</div>
			                                    					</div>
					                                    			<?php
				                                    			}
					                                    	}
					                                    	?>
							                            </div>
				                                    </div>
				                                </div>
				                            <?php } ?>

			                            </div>
			                        </div>

			                        <div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['Additional Details'] ?></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Ethnic'] ?></div>
										        <div class="col-sm-9">
										        	<select name="ethnic_id" id="ethnic_id" class="form-control group_1">
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $ethnic as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['ethnic_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Religion'] ?></div>
										        <div class="col-sm-9">
										        	<select name="religion_id" id="religion_id" class="form-control group_1">
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $religion as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['religion_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>

			                            </div>
			                        </div>

			                        <div class="panel panel-primary" style="display: none;">
										<div class="panel-heading">Checkup Details</div><br/>
			                            <div class="panel-body">
			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label">Fomema Checkup Date</div>
										        <div class="col-sm-9">
										        	<input class="form-control temporarynotcontrol group_1" name="staff_fonema" id="staff_fonema" type="date" value="<?= $row_page['staff_fonema'] ?>" />
										        </div>
										    </div>
			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label">Fomema Checkup Period (Year)</div>
										        <div class="col-sm-9">
										        	<input class="form-control temporarynotcontrol group_1" name="staff_fenoma_period" id="staff_fonema" type="text" value="<?= $row_page['staff_fenoma_period'] ?>" />
										        </div>
										    </div>
			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label">Typhoid Checkup Date</div>
										        <div class="col-sm-9">
										        	<input class="form-control temporarynotcontrol group_1" name="staff_typhoid" id="staff_typhoid" type="date" value="<?=$row_page['staff_typhoid'] ?>" />
										        </div>
										    </div>
			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label">Covid Test Date</div>
										        <div class="col-sm-9">
										        	<input class="form-control temporarynotcontrol group_1" name="staff_covid_test" id="staff_covid" type="date" value="<?= $row_page['staff_covid_test'] ?>" />
										        </div>
										    </div>
			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label">Covid Injections</div>
										        <div class="col-sm-9">
										        	<input class="form-control temporarynotcontrol group_1" name="staff_covid" id="staff_covid" type="date" value="<?= $row_page['staff_covid'] ?>" />
										        </div>
										    </div>
			                            </div>
			                        </div>

								</div>

								<div class="tab-pane" id="tab_2" style="display: none;">
									<div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['Tier'] ?></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Tier'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										        	<select name="staff_tier" id="staff_tier" class="chosen-select select2-basic-single form-control group_2"  >
										        		<?php foreach( $tier_list as $k => $v ){ 
										        			$check_permission         = false ;
															if ( $get_user_tier['check'] ){
																if ( in_array( $v['tier_id'], $get_user_tier['tiers'] ) ){
																	$check_permission = true ;
																}
															}else{
																$check_permission     = true ;
															}
															if ( $check_permission ){ ?>
										        				<option value="<?= $v['tier_id'] ?>" <?= ( $row_page['staff_tier'] == $v['tier_id'] ? 'selected' : '' ) ?> ><?= $v['title'] ?></option>
										        			<?php 
										        			}
										        		} ?>
										            </select>
										        </div>
										    </div>

										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Achievement'] ?></div>
										        <div class="col-sm-9">
										        	<input class="form-control temporarynotcontrol group_2" name="staff_achievement" id="staff_achievement" type="text" value="<?= ucwords( $row_page['staff_achievement'] ) ?>" readonly placeholder="<?= $lang['Achievement'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Point'] ?></div>
										        <div class="col-sm-9">
										        	<input class="form-control temporarynotcontrol group_2" name="staff_point" id="staff_point" type="text" value="<?= $row_page['staff_point'] ?>" readonly placeholder="<?= $lang['Point'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['star'] ?></div>
										        <div class="col-sm-9">
										        	<input class="form-control temporarynotcontrol group_2" name="staff_star" id="staff_star" type="text" value="<?= $row_page['staff_star'] ?>" readonly placeholder="<?= $lang['star'] ?>" />
										        </div>
										    </div>

										</div>
									</div>
								</div>

								<div class="tab-pane" id="tab_3">
									
									<div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['Employment Info'] ?></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Date Joined'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol group_2" name="staff_date_joined" id="staff_date_joined" type="date" value="<?= $row_page['staff_date_joined'] ?>" placeholder="<?= $lang['Date Joined'] ?>"  />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['End Of Probation'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_probation_end" id="staff_probation_end" type="date" value="<?= $row_page['staff_probation_end'] ?>" placeholder="<?= $lang['End Of Probation'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Date Confirmed'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_date_confirmed" id="staff_date_confirmed" type="date" value="<?= $row_page['staff_date_confirmed'] ?>" placeholder="<?= $lang['Date Confirmed'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Date Resigned'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_date_resigned" id="staff_date_resigned" type="date" value="<?= $row_page['staff_date_resigned'] ?>" placeholder="<?= $lang['Date Resigned'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Run Away'] ?></div>
										        <div class="col-sm-9">
										        	<input type="checkbox" name="staff_run_away" class="temporarynotcontrol" value="yes" 
										        		<?=($row_page['staff_run_away'] == "yes" ? "checked" : "")?>>										            
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Reason of Resign'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_resign_reason" id="staff_resign_reason" type="text" value="<?= $row_page['staff_resign_reason'] ?>" placeholder="<?= $lang['Reason of Resign'] ?>" />
										        </div>
										    </div>

			                            </div>
			                        </div>

			                        <div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['Job Status'] ?> <font color="red">*</font></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Job Position'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
					                            	<select name="job_position_id" id="job_position_id" class="chosen-select select2-basic-single form-control group_2"  >
					                            		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $position as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['job_position_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Job Section'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
					                            	<select name="job_section_id" id="job_section_id" class="chosen-select select2-basic-single form-control group_2"  >
					                            		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $section as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['job_section_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>

			                            </div>
			                        </div>

						        	<?php foreach ( $branch as $k => $v ){ ?>
					        			<input type="hidden" name="branch_id" value="<?= $k ?>">
					        		<?php } ?>
			                        <div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['Employment Status'] ?></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['branch'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <select name="branch_id" id="branch_id" class="form-control group_2"  >
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $branch as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['branch_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Leave'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <select name="leave_id" id="leave_id" class="form-control group_2"  >
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $leave as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['leave_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['sick'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <select name="sick_id" id="sick_id" class="form-control group_2"  >
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $sick as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['sick_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Job Type'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <select name="job_type_id" id="job_type_id" class="form-control group_2"  >
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $job_type as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['job_type_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Job Status'] ?></div>
										        <div class="col-sm-9">
										            <select name="job_status_id" id="job_status_id" class="form-control group_2">
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $job_status as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['job_status_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Work Days'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <select name="work_type_id" id="work_type_id" class="form-control group_2"  >
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $work_type as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['work_type_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Effective Date'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol group_2" name="staff_effective_date" id="staff_effective_date" type="date" value="<?= $row_page['staff_effective_date'] ?>" placeholder="<?= $lang['Effective Date'] ?>" />
										        </div>
										    </div>

			                            </div>
			                        </div>

			                        <div class="panel panel-primary" style="display: none;">
										<div class="panel-heading"><?= $lang['Permit'] ?></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Permit No'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_permitno" id="staff_permitno" type="text" value="<?= $row_page['staff_permitno'] ?>" placeholder="<?= $lang['Permit No'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Permit From'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_permit_start" id="staff_permit_start" type="date" value="<?= $row_page['staff_permit_start'] ?>" placeholder="<?= $lang['Permit From'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Permit To'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_permit_end" id="staff_permit_end" type="date" value="<?= $row_page['staff_permit_end'] ?>" placeholder="<?= $lang['Permit To'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Permit Image'] ?> </div>
										        <div class="col-sm-9">
										        	<input type="file" name="permitimages[]" id="permitimages" class="modaldata temporarynotcontrol" accept="image/*" multiple />
										        </div>
										    </div>
										    <?php if ( count($permitimages) > 0 ){ ?>
					                            <div class="form-group">
				                                    <div class="col-sm-2 control-label"><?= $lang['preview'] ?></div>
				                                    <div class="col-sm-9">
				                                    	<div class="staff_image_box staff_image_box2 clearfix">
				                                    		<?php 
				                                    		foreach ( $permitimages as $k => $v ){ 
				                                    			if(strpos($v, ".pdf") == true){
				                                    				?>
					                                    			<div style="float: left; padding-right: 5px;">
			                                    						<image src="<?= PATH ?>images/pdf.png" />
			                                    						<div style="float: left;">
			                                    							<a href="viewer.html?file=<?= PATH ?>uploads/StaffImage/<?= $v ?>" target="_blank">View</a>
			                                    						</div>
			                                    						<div style="float: right; padding-right: 5px">
			                                    							<a onclick="return confirm('Are you sure?')" href="hr-staff.php?page_mode=edit&page=<?= $page ?>&staff_image=yes&staff_image_id=<?= $k ?>">Del</a>
			                                    						</div>
			                                    					</div>
					                                    			<?php
				                                    			}
				                                    			else{
				                                    				?>
					                                    			<div style="float: left; padding-right: 5px;">
			                                    						<image src="<?= PATH ?>uploads/StaffImage/<?= $v ?>" />
			                                    						<div style="float: left;">
			                                    							<a href="<?= PATH ?>uploads/StaffImage/b/<?= $v ?>" target="_blank">View</a>
			                                    						</div>
			                                    						<div style="float: right; padding-right: 6px">
			                                    							<a onclick="return confirm('Are you sure?')" href="hr-staff.php?page_mode=edit&page=<?= $page ?>&staff_image=yes&staff_image_id=<?= $k ?>">Del</a>
			                                    						</div>
			                                    					</div>
					                                    			<?php
				                                    			}
					                                    	}
					                                    	?>
							                            </div>
				                                    </div>
				                                </div>
				                            <?php } ?>

			                            </div>
			                        </div>

								</div>
								<div class="tab-pane" id="tab_4">
									
									<div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['salary'] ?></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['working_hours'] ?> <font color="red">*</font></div>
										        <div class="col-sm-9">
										            <select name="group_id" id="group_id" class="form-control group_3"  >
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $working_group as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['group_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>

										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Basic Salary'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_salary" id="staff_salary" type="number" value="<?= $row_page['staff_salary'] ?>" placeholder="<?= $lang['Basic Salary'] ?>" step="0.1" />
										        </div>
										    </div>
										<!--
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Contract Salary'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_contract_salary" id="staff_contract_salary" type="number" value="<?= $row_page['staff_contract_salary'] ?>" placeholder="<?= $lang['Contract Salary'] ?>" step="0.1" />
										        </div>
										    </div>
										-->
											<div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Allowance'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_allowance_work" id="staff_allowance_work" type="number" value="<?= $row_page['staff_allowance_work'] ?>" placeholder="<?= $lang['Allowance'] ?>" step="0.1" />
										        </div>
										    </div>

										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Allowance Mobile Topup'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_allowance_topup" id="staff_allowance_topup" type="number" value="<?= $row_page['staff_allowance_topup'] ?>" placeholder="<?= $lang['Allowance Mobile Topup'] ?>" step="0.1" />
										        </div>
										    </div>
										<!--
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Allowance By 1 month working day'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_allowance_work" id="staff_allowance_work" type="number" value="<?= $row_page['staff_allowance_work'] ?>" placeholder="<?= $lang['Allowance'] ?>" step="0.1" />
										        </div>
										    </div>
										-->
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Allowance Food'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_allowance_food" id="staff_allowance_food" type="number" value="<?= $row_page['staff_allowance_food'] ?>" placeholder="<?= $lang['Allowance Food'] ?>" step="0.1" />
										        </div>
										    </div>
											
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Next Review Date'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol group_3" name="staff_salary_nextreview_date" id="staff_salary_nextreview_date" type="date" value="<?= $row_page['staff_salary_nextreview_date'] ?>" placeholder="<?= $lang['Next Review Date'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Effective Date'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol group_3" name="staff_salary_effective_date" id="staff_salary_effective_date" type="date" value="<?= $row_page['staff_salary_effective_date'] ?>" placeholder="<?= $lang['Effective Date'] ?>" />
										        </div>
										    </div>

			                            </div>
			                        </div>

			                        <div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['Statutory Details'] ?></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label">EPF Rate</div>
										        <div class="col-sm-9">
										            <!-- <input class="form-control temporarynotcontrol" name="staff_epf_rate" id="staff_epf_rate" type="number" value="<?= $row_page['staff_epf_rate'] ?>" placeholder="<?= $lang['Employer Epf Rate'] ?>" /> -->
										            <select class="form-control chosen-select select2-basic-single" name="staff_epf_rate_id">
										            	<option value="">Select</option>
										            	<?php 
										            		if(count($epf_rate) > 0){
										            			foreach($epf_rate as $key => $value){
										            				echo '
										            					<option value="'.$key.'" '.($row_page['staff_epf_rate_id']==$key ? 'selected' : '').'>
										            						'.$value['title'].'
										            					</option>
										            				';
										            			}
										            		}
										            	?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['EPF Membership No'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_epfno" id="staff_epfno" type="text" value="<?= $row_page['staff_epfno'] ?>" placeholder="<?= $lang['EPF Membership No'] ?>" />
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Socso Category'] ?></div>
										        <div class="col-sm-9">
										            <select name="socso_category_id" id="socso_category_id" class="form-control group_3 chosen-select select2-basic-single">
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $socso_category as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['socso_category_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label">Socso Rate</div>
										        <div class="col-sm-9">
										            <select class="form-control chosen-select select2-basic-single" name="staff_socso_rate_id">
										            	<option value="">Select</option>
										            	<?php 
										            		if(count($socso_rate) > 0){
										            			foreach($socso_rate as $key => $value){
										            				echo '
										            					<option value="'.$key.'" '.($row_page['staff_socso_rate_id']==$key ? 'selected' : '').'>
										            						'.$value['title'].'
										            					</option>
										            				';
										            			}
										            		}
										            	?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Tax Category'] ?></div>
										        <div class="col-sm-9">
										            <select name="tax_status_id" id="tax_status_id" class="form-control group_3 chosen-select select2-basic-single">
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $tax_status as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['tax_status_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Tax Reference No'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_taxno" id="staff_taxno" type="text" value="<?= $row_page['staff_taxno'] ?>" placeholder="<?= $lang['Tax Reference No'] ?>" />
										        </div>
										    </div>
										    <!--
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Child Relief'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_child_relief" id="staff_child_relief" type="text" value="<?= $row_page['staff_child_relief'] ?>" placeholder="<?= $lang['Child Relief'] ?>" />
										        </div>
										    </div>
											-->
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['EIS Contribution'] ?></div>
										        <div class="col-sm-9">
										            <select name="staff_eis_status" id="staff_eis_status" class="form-control group_3 chosen-select select2-basic-single">
										        		<option value=""><?= $lang['select'] ?></option>
										        		<option value="1" <?= ( $row_page['staff_eis_status'] == '1' ? 'selected' : '' ) ?> ><?= $lang['yes'] ?></option>
										        		<option value="0" <?= ( $row_page['staff_eis_status'] == '0' ? 'selected' : '' ) ?> ><?= $lang['no'] ?></option>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label">EIS Rate</div>
										        <div class="col-sm-9">
										            <select class="form-control chosen-select select2-basic-single" name="staff_eis_rate_id">
										            	<option value="">Select</option>
										            	<?php 
										            		if(count($eis_rate) > 0){
										            			foreach($eis_rate as $key => $value){
										            				echo '
										            					<option value="'.$key.'" '.($row_page['staff_eis_rate_id']==$key ? 'selected' : '').'>
										            						'.$value['title'].'
										            					</option>
										            				';
										            			}
										            		}
										            	?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Muslim Zakat Fund'] ?></div>
										        <div class="col-sm-9">
										            <!-- <input class="form-control temporarynotcontrol" name="staff_muslim_zakat" id="staff_muslim_zakat" type="number" value="<?= $row_page['staff_muslim_zakat'] ?>" placeholder="<?= $lang['Muslim Zakat Fund'] ?>" /> -->
										            <select class="form-control chosen-select select2-basic-single" name="staff_zakat_rate_id">
										            	<option value="">Select</option>
										            	<?php 
										            		if(count($zakat_rate) > 0){
										            			foreach($zakat_rate as $key => $value){
										            				echo '
										            					<option value="'.$key.'" '.($row_page['staff_zakat_rate_id']==$key ? 'selected' : '').'>
										            						'.$value['title'].'
										            					</option>
										            				';
										            			}
										            		}
										            	?>
										            </select>
										        </div>
										    </div>

			                            </div>
			                        </div>

			                        <div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['Payment Details'] ?></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Bank'] ?></div>
										        <div class="col-sm-9">
										            <select name="bank_id" id="bank_id" class="chosen-select select2-basic-single form-control group_3">
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $bank as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['bank_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Payment Type'] ?></div>
										        <div class="col-sm-9">
										            <select name="payment_type_id" id="payment_type_id" class="form-control group_3">
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $payment_type as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['payment_type_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Payment Transfer'] ?></div>
										        <div class="col-sm-9">
										            <select name="payment_transfer_id" id="payment_transfer_id" class="form-control group_3">
										        		<option value=""><?= $lang['select'] ?></option>
										        		<?php foreach ( $payment_transfer as $k => $v ){ ?>
										        			<option value="<?= $k ?>" <?= ( $row_page['payment_transfer_id'] == $k ? 'selected' : '' ) ?> ><?= $v ?></option>
										        		<?php } ?>
										            </select>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label"><?= $lang['Bank Account No'] ?></div>
										        <div class="col-sm-9">
										            <input class="form-control temporarynotcontrol" name="staff_accountno" id="staff_accountno" type="text" value="<?= $row_page['staff_accountno'] ?>" placeholder="<?= $lang['Bank Account No'] ?>" />
										        </div>
										    </div>

			                            </div>
			                        </div>
								</div>
								<div class="tab-pane" id="tab_5">
									
									<div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['knowledge'] ?></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-11">
			                            			<?php foreach ( $knowledge as $k => $v ){ ?>
			                            			<label><input type="checkbox" name="knowledge[]" value="<?= $k ?>" <?= ( in_array($k, $selected_knowledge) ? 'checked' : '' ) ?> > <?= $v ?></label><br />
			                            			<?php } ?>
			                            		</div>
			                            	</div>

			                            </div>
			                        </div>

								</div>
								<div class="tab-pane" id="tab_6">
									
									<div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['Department'] ?> <font color="red">*</font></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-11">
			                            			<?php foreach ( $department as $k => $v ){ ?>
			                            			<label><input   type="checkbox" name="department[]" value="<?= $k ?>" <?= ( in_array($k, $selected_department) ? 'checked' : '' ) ?> > <?= $v ?></label><br />
			                            			<?php } ?>
			                            		</div>
			                            	</div>

			                            </div>
			                        </div>

								</div>
								<div class="tab-pane" id="tab_7">
									
									<div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['Hostel'] ?></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-11">
			                            			<?php foreach ( $hostel as $k => $v ){ ?>
			                            			<label><input type="checkbox" name="hostel[]" value="<?= $k ?>" <?= ( in_array($k, $selected_hostel) ? 'checked' : '' ) ?> > <?= $v ?></label><br />
			                            			<?php } ?>
			                            		</div>
			                            	</div>

			                            </div>
			                        </div>

								</div>
								<div class="tab-pane" id="tab_8">
									
									<div class="panel panel-primary">
										<div class="panel-heading"><?= $lang['setting'] ?></div><br/>
			                            <div class="panel-body">

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;"></div>
										        <div class="col-sm-9">
										        	<b style="text-decoration: underline;">Allow to Approve Resignation</b>
										        </div>
										    </div>

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;">Is Manager</div>
										        <div class="col-sm-9">
										        	<?php
										        	$ismanager_checked = '' ;
										        	if ( $staff_settings['ismanager'] != '' ){
										        		if ( $staff_settings['ismanager'] == 'yes' ){
										        			$ismanager_checked = 'checked' ;
										        		}
										        	}else{
										        		if ( $default_config_switchbranch == 'yes' ){
										        			$ismanager_checked = 'checked' ;
										        		}
										        	}
										        	?>
										            <label><input type="checkbox" name="staff_setting_ismanager" value="yes" <?= $ismanager_checked ?> /> Is Manager</label>
										        </div>
										    </div>
										    <div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;">Is HR Manager</div>
										        <div class="col-sm-9">
										        	<?php
										        	$ishrmanager_checked = '' ;
										        	if ( $staff_settings['ishrmanager'] != '' ){
										        		if ( $staff_settings['ishrmanager'] == 'yes' ){
										        			$ishrmanager_checked = 'checked' ;
										        		}
										        	}else{
										        		if ( $default_config_switchbranch == 'yes' ){
										        			$ishrmanager_checked = 'checked' ;
										        		}
										        	}
										        	?>
										            <label><input type="checkbox" name="staff_setting_ishrmanager" value="yes" <?= $ishrmanager_checked ?> /> Is HR Manager</label>
										        </div>
										    </div>

			                            	<hr />

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;"><?= $lang['Allow Switch Branch'] ?></div>
										        <div class="col-sm-9">
										        	<?php
										        	$switchbranch_checked = '' ;
										        	if ( $staff_settings['switchbranch'] != '' ){
										        		if ( $staff_settings['switchbranch'] == 'yes' ){
										        			$switchbranch_checked = 'checked' ;
										        		}
										        	}else{
										        		if ( $default_config_switchbranch == 'yes' ){
										        			$switchbranch_checked = 'checked' ;
										        		}
										        	}
										        	?>
										            <label><input type="checkbox" name="staff_setting_switchbranch_card" value="yes" <?= $switchbranch_checked ?> /> <?= $lang['Click yes to allow button switch branch'] ?></label>
										        </div>
										    </div>

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;">Allow To View Task Branch Report</div>
										        <div class="col-sm-9">
										        	<?php
										        	$reporttaskbranch_checked = '' ;
										        	if ( $staff_settings['reporttaskbranch'] != '' ){
										        		if ( $staff_settings['reporttaskbranch'] == 'yes' ){
										        			$reporttaskbranch_checked = 'checked' ;
										        		}
										        	}else{
										        		if ( $default_config_reporttaskbranch == 'yes' ){
										        			$reporttaskbranch_checked = 'checked' ;
										        		}
										        	}
										        	?>
										            <label><input type="checkbox" name="staff_setting_reporttaskbranch_card" value="yes" <?= $reporttaskbranch_checked ?> /> Click yes to allow view task branch report</label>
										        </div>
										    </div>

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;">Allow To View Adjustment Branch Report</div>
										        <div class="col-sm-9">
										        	<?php
										        	$reportadjustmentbranch_checked = '' ;
										        	if ( $staff_settings['reportadjustmentbranch'] != '' ){
										        		if ( $staff_settings['reportadjustmentbranch'] == 'yes' ){
										        			$reportadjustmentbranch_checked = 'checked' ;
										        		}
										        	}else{
										        		if ( $default_config_reportadjustmentbranch == 'yes' ){
										        			$reportadjustmentbranch_checked = 'checked' ;
										        		}
										        	}
										        	?>
										            <label><input type="checkbox" name="staff_setting_reportadjustmentbranch_card" value="yes" <?= $reportadjustmentbranch_checked ?> /> Click yes to allow view adjustment branch report</label>
										        </div>
										    </div>

										    <div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;">Allow To Check Recruitment</div>
										        <div class="col-sm-9">
										        	<?php
										        	$checkrecruitment_checked = '' ;
										        	if ( $staff_settings['checkrecruitment'] != '' ){
										        		if ( $staff_settings['checkrecruitment'] == 'yes' ){
										        			$checkrecruitment_checked = 'checked' ;
										        		}
										        	}else{
										        		if ( $default_config_checkrecruitment == 'yes' ){
										        			$checkrecruitment_checked = 'checked' ;
										        		}
										        	}
										        	?>
										            <label><input type="checkbox" name="staff_setting_checkrecruitment" value="yes" <?= $checkrecruitment_checked ?> /> Click yes to allow check recruitment</label>
										        </div>
										    </div>

										    <div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;">Allow Check In Association</div>
										        <div class="col-sm-9">
										        	<?php
										        	$checkassociation_checked = '' ;
										        	if ( $staff_settings['checkassociation'] != '' ){
										        		if ( $staff_settings['checkassociation'] == 'yes' ){
										        			$checkassociation_checked = 'checked' ;
										        		}
										        	}else{
										        		if ( $default_config_checkassociation == 'yes' ){
										        			$checkassociation_checked = 'checked' ;
										        		}
										        	}
										        	?>
										            <label><input type="checkbox" name="staff_setting_checkassociation" value="yes" <?= $checkassociation_checked ?> /> Click yes to allow check in association</label>
										        </div>
										    </div>

										    <div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;">Allow Check In Training</div>
										        <div class="col-sm-9">
										        	<?php
										        	$checktraining_checked = '' ;
										        	if ( $staff_settings['checktraining'] != '' ){
										        		if ( $staff_settings['checktraining'] == 'yes' ){
										        			$checktraining_checked = 'checked' ;
										        		}
										        	}else{
										        		if ( $default_config_checktraining == 'yes' ){
										        			$checktraining_checked = 'checked' ;
										        		}
										        	}
										        	?>
										            <label><input type="checkbox" name="staff_setting_checktraining" value="yes" <?= $checktraining_checked ?> /> Click yes to allow check in training</label>
										        </div>
										    </div>

										    <div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;">Allow Approve Visitation</div>
										        <div class="col-sm-9">
										        	<?php
										        	$approvevisitation_checked = '' ;
										        	if ( $staff_settings['approvevisitation'] != '' ){
										        		if ( $staff_settings['approvevisitation'] == 'yes' ){
										        			$approvevisitation_checked = 'checked' ;
										        		}
										        	}else{
										        		if ( $default_config_approvevisitation == 'yes' ){
										        			$approvevisitation_checked = 'checked' ;
										        		}
										        	}
										        	?>
										            <label><input type="checkbox" name="staff_setting_approvevisitation" value="yes" <?= $approvevisitation_checked ?> /> Click yes to allow approve visitation request</label>
										        </div>
										    </div>

										    <div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;">Allow Check In Visitation</div>
										        <div class="col-sm-9">
										        	<?php
										        	$checkvisitation_checked = '' ;
										        	if ( $staff_settings['checkvisitation'] != '' ){
										        		if ( $staff_settings['checkvisitation'] == 'yes' ){
										        			$checkvisitation_checked = 'checked' ;
										        		}
										        	}else{
										        		if ( $default_config_checkvisitation == 'yes' ){
										        			$checkvisitation_checked = 'checked' ;
										        		}
										        	}
										        	?>
										            <label><input type="checkbox" name="staff_setting_checkvisitation" value="yes" <?= $checkvisitation_checked ?> /> Click yes to allow check in visitation</label>
										        </div>
										    </div>

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;"><?= $lang['Allow Punch'] ?></div>
										        <div class="col-sm-9">
										        	<?php
										        	$punch_checked = '' ;
										        	if ( $staff_settings['punch'] != '' ){
										        		if ( $staff_settings['punch'] == 'yes' ){
										        			$punch_checked = 'checked' ;
										        		}
										        	}else{
										        		if ( $default_config_punch == 'yes' ){
										        			$punch_checked = 'checked' ;
										        		}
										        	}
										        	?>
										            <label><input type="checkbox" name="staff_setting_punch_card" value="yes" <?= $punch_checked ?> /> <?= $lang['Click yes to allow button punch card'] ?></label>
										        </div>
										    </div>

			                            	<div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;">Punch Card Without Checking Branch Geometry</div>
										        <div class="col-sm-9">
										        	<?php
										        	$without_geometry_checked = '' ;
										        	if ( $staff_settings['without_geometry'] != '' ){
										        		if ( $staff_settings['without_geometry'] == 'yes' ){
										        			$without_geometry_checked = 'checked' ;
										        		}
										        	}else{
										        		if ( $default_config_punch == 'yes' ){
										        			$without_geometry_checked = 'checked' ;
										        		}
										        	}
										        	?>
										            <label><input type="checkbox" name="staff_setting_without_geometry" value="yes" <?= $without_geometry_checked ?> /> Tick if no need checking branch geometry</label>
										        </div>
										    </div>

										    <div class="form-group">
			                            		<div class="col-sm-2 control-label" style="padding-top:0;">Vcard Mode</div>
										        <div class="col-sm-9">
										        	<label><input type="radio" name="staff_setting_vcard_mode" value="1" <?= $staff_settings['vcard_mode'] == '1' ? 'checked' : '' ?> /> Designation Only</label>
										        	<label><input type="radio" name="staff_setting_vcard_mode" value="2" <?= $staff_settings['vcard_mode'] == '2' ? 'checked' : '' ?> /> Department Only</label>
										        	<label><input type="radio" name="staff_setting_vcard_mode" value="3" <?= $staff_settings['vcard_mode'] == '3' ? 'checked' : '' ?> /> Department + Designation</label>
										        </div>
										    </div>

			                            </div>
			                        </div>

								</div>
								
							</div>
						</div>

						<?php if ( ( $page_mode == 'new' && permissionCheck($row_user, 'staff-list-new') ) || ( $page_mode == 'edit' && permissionCheck($row_user, 'staff-list-edit') ) ){ ?>
	                        <div class="form-group">
	                            <div class="col-sm-2 control-label"></div>
	                            <div class="col-sm-10">
	                                <button type="submit" class="btn btn-purple" style="float:right"><?= $lang['submit'] ?></button>
	                                <input type="hidden" name="hide" value="1">
	                                <input type="hidden" name="page_status" value="<?= $submit_type ?>">
	                            </div>
	                        </div>  
	                    <?php } ?>

                    </form>
                </div>
            </div>
		</div>
		<?php
		
	break ;

	// all staff list
	case 'resign' :
	case 'run_away' :
	case 'all' :
	default :

		// check permission
		if ( !permissionCheck($row_user, 'staff-list-view') && !permissionCheck($row_user, 'foreign-only') ){
			// echo '<script>alert("Sorry You Don\'t Have The Permission.")</script>';

			header('Location: page-dashboard.php') ;
			exit ;
		}

		// default parameter
		$left_join 		    = '' ;

		$search		  		= escapeString($_GET['search']) ;
		$search_name  		= escapeString($_GET['search_name']) ;
		$search_idno  		= escapeString($_GET['search_idno']) ;
		$search		  		= escapeString($_GET['search']) ;
		$lf_type      		= escapeString($_GET['lf_type']) ;
		$lf_branch    		= escapeString($_GET['lf_branch']) ;
		$lf_resigned  		= escapeString($_GET['lf_resigned']) ;
		$sort_by      		= escapeString($_GET['sort_by']) ;
		$sort_by 	  		= ( $sort_by != '' ? $sort_by : 'staff_idno' ) ;
	    $sort_by_type 		= escapeString($_GET['sort_by_type']) ;
		$sort_by_type 		= ( $sort_by_type != '' ? $sort_by_type : 'asc' ) ;
		$export       		= escapeString($_GET['export']) ;
		$status           	= escapeString($_GET['status']) ;
		$search_mobile      = escapeString($_GET['search_mobile']) ;
		$search_mail        = escapeString($_GET['search_mail']) ;
		$search_tier        = escapeString($_GET['search_tier']) ;
		$search_department  = escapeString($_GET['search_department']) ;
		$search_point       = escapeString($_GET['search_point']) ;
		$search_wallet      = escapeString($_GET['search_wallet']) ;
		$search_star        = escapeString($_GET['search_star']) ;
		$search_achievement = escapeString($_GET['search_achievement']) ;



	    // query type
		$search_query = '' ;

		if($status != ''){
			if($status == 'resign'){
				$search_query    .= " AND (a.staff_date_resigned != '0000-00-00' AND a.staff_date_resigned IS NOT NULL AND (a.staff_run_away = '' || a.staff_run_away IS NULL))" ;
			}elseif($status == 'run-away'){
				$search_query    .= " AND (a.staff_date_resigned != '0000-00-00' AND a.staff_date_resigned IS NOT NULL AND a.staff_run_away = 'yes')" ;
			}elseif($status == 'warning'){

			}
		}

		switch ( $page_mode ){
			case 'resign' :
				$active_menu 	  = 'hr-staff-resgined' ;
				$search_query    .= " AND (a.staff_date_resigned != '0000-00-00' AND a.staff_date_resigned IS NOT NULL AND (a.staff_run_away = '' || a.staff_run_away IS NULL))" ;
			break ;
			case 'run_away' :
				$active_menu 	  = 'hr-staff-run-away' ;
				$search_query    .= " AND (a.staff_date_resigned != '0000-00-00' AND a.staff_date_resigned IS NOT NULL AND a.staff_run_away = 'yes')" ;
			break ;
			default :
				$active_menu 	  = 'hr-staff-list' ;
		}

		// search query
		if( $search != ''){
			$search_query  	.= " AND (a.staff_idno LIKE '%".$search."%' || a.staff_name LIKE '%".$search."%')" ;
		}
		if( $search_name   	!= ''){
			$search_query  	.= " AND a.staff_name LIKE '%".$search_name."%'" ;
		}
		if( $search_mobile 	!= ''){
			$search_query  	.= " AND a.staff_mobileno LIKE '%".$search_mobile."%'" ;
		}
		if( $search_mail   	!= ''){
			$search_query  	.= " AND a.staff_email LIKE '%".$search_mail."%'" ;
		}
		if( $search_tier   	!= ''){
			$search_query  	.= " AND a.staff_tier LIKE '%".$search_tier."%'" ;
		}
		if( $search_department != ''){
			$left_join       = " LEFT JOIN staff_department b ON ( a.staff_id = b.staff_id )" ;
			$search_query  	.= " AND b.department_id = '".$search_department."'" ;
		}
		if( $search_idno   	!= ''){
			$search_query  	.= " AND a.staff_idno LIKE '%".$search_idno."%'" ;
		}
		if( $search_point  	!= ''){
			$search_query  	.= " AND a.staff_point = '".$search_point."'" ;
		}
		if( $search_wallet  != ''){
			$search_query  	.= " AND a.staff_wallet = '".$search_wallet."'" ;
		}
		if( $search_star   	!= ''){
			$search_query  	.= " AND a.staff_star = '".$search_star."'" ;
		}
		if( $search_achievement != ''){
			$search_query  	.= " AND a.staff_achievement LIKE '%".$search_achievement."%'" ;
		}
		if( $lf_type       	!= '' ){
			if( $lf_type   	== 'local' ){
				$search_query .= " AND a.country_id = '1'" ;
			}else{
				$search_query .= " AND a.country_id != '1'" ;
			}
		}
		if ( $lf_branch    	!= '' ){
			$search_query  	.= " AND a.branch_id = '".$lf_branch."'" ;
		}

		if ( $lf_resigned  	!= '' ){
		    $search_query  	.= " AND ( a.staff_date_resigned >= '".$lf_resigned."'  OR a.staff_date_resigned = '0000-00-00' OR a.staff_date_resigned IS NULL )" ;
		}else{
		    $search_query  	.= " AND ( a.staff_date_resigned >= '".date("Y-m-d",time())."' OR a.staff_date_resigned = '0000-00-00' OR a.staff_date_resigned IS NULL )" ;
		}

		// $search_query 	  	.= ( $get_user_tier['check'] ? " AND a.staff_tier IN ( ".implode(', ', $get_user_tier['tiers'])." )" : '' ) ;

		// form submit
		if( $_POST['hide'] == '1' && $_POST['hide_status'] == 'action' ){
			// trash item
			switch( $_POST['page_action'] ){
				case 'trash':
					$mysqli_query = "UPDATE " . staff . " SET
									 deleted_at = '".TODAYDATE."'
									 WHERE staff_id = " ;
					$trash_page = trashPage('staff', $mysqli, $mysqli_query, $_POST['multiple_trash']) ;
				break;
			}
		}
		
		// pagination
		if (isset($page) && !empty($page)) { $product_page = $page ; } else { $product_page = 1 ; } // next and prev page (5 thing need to change)
		$start_from = ($product_page - 1) * LIMIT ; //end next and prev page
		
		// set search url
		$search_url = 'search='.$search.'&search_name='.$search_name.'&search_idno='.$search_idno.'&lf_type='.$lf_type.'&lf_branch='.$lf_branch.'&sort_by='.$sort_by.'&sort_by_type='.$sort_by_type.'&lf_branch='.$lf_branch.'&lf_resigned='.$lf_resigned.'&status='.$status.'&show_all_none_branch_staff='.$show_all_none_branch_staff.'&search_point='.$search_point.'&search_wallet='.$search_wallet.'&search_star='.$search_star.'&search_achievement='.$search_achievement ;

		$show_all_none_branch_staff = escapeString($_GET['show_all_none_branch_staff']);
		if ($show_all_none_branch_staff == 'all') {
			$user_branch_permission_sql = 'and branch_id = "" and staff_name != "" ';
		}

		// page query
		$mysqli_query = "SELECT a.* FROM staff a
						 ".$left_join."
						 WHERE a.deleted_at IS NULL" . $search_query . $user_branch_permission_sql_a ;

		// export excel
		if ( $export == 'yes' ){

			include 'PhpExcel/PHPExcel.php' ;

			$page_filename = 'Staff-'.date( 'Ymd', time() ) ;
		    $objPHPExcel   = new PHPExcel() ;
		    $objPHPExcel->getProperties()
		                ->setCreator(COMPANY)
		                ->setTitle(COMPANY)
		                ->setSubject(COMPANY)
		                ->setDescription(COMPANY)
		                ->setKeywords(COMPANY)
		                ->setCategory(COMPANY) ;

		    $objPHPExcel->getActiveSheet()->setTitle( $page_filename ) ;
		    $objPHPExcel->setActiveSheetIndex(0);
		    $objWriter   = PHPExcel_IOFactory::createWriter( $objPHPExcel, 'Excel5' ) ;

		    // default parameter
		    $count       = 1 ;
		    $char        = 'A' ;
		    $count_staff = 1 ;

		    $array_title = array( 'No.', 'Qrcode', 'ID', 'Name', 'Mobile No','Gender', 'Birth Date','Age','Mailing Address','Marriage Status','Country', "IC", 'Position', 'Status','Ethnic','Religion', 'Date Joined ','Created Date' ) ;

		    $newChar     = $char ;
		    foreach( $array_title as $k => $v ){
                $objPHPExcel->getActiveSheet()->setCellValue( $newChar.$count, $v ) ;
                $newChar++ ;
		    }
		    $count++ ;

			$array_staffidnos     = [] ;
			$staffs_q = $mysqli->query( $mysqli_query." ORDER BY (".$sort_by.' * 1) '.$sort_by_type . ', '.$sort_by.' '.$sort_by_type ) ;
			if ( $staffs_q->num_rows > 0 ){
				while ( $staff    = $staffs_q->fetch_assoc() ){

					$staff_idno   = ucwords($staff['staff_idno']) ;
					if( $staff['country_id'] == '1' ){
						if( $staff['staff_icno'] != '' ){
							$IC   = dataFilter($staff['staff_icno']) ;
						}else{
							$IC   = '-' ;
						}
					}else{
						$IC 	  = '-' ;
					}
				
					if( $staff['country_id'] == '1' ){
						$passport = '-' ;
					}else{
						if( $staff['staff_passportno'] != '-' && $staff['staff_passportexpired'] != '0000-00-00' ){
							$passport = dataFilter($staff['staff_passportexpired']) . ( $staff['staff_passportno'] != '' ? ' ('.dataFilter($staff['staff_passportno']).')' : '' ) ;
						}else{
							$passport = '-' ;
						}
					}
				
					if( $staff['country_id'] == '1' ){
						$permit = '-' ;
					}else{
						if( $staff['staff_permitno'] != '-' && $staff['staff_permit_end'] != '0000-00-00' ){
							$permit = dataFilter($staff['staff_permit_end']) . ( $staff['staff_permitno'] != '' ? ' ('.dataFilter($staff['staff_permitno']).')' : '' ) ;
						}else{
							$permit = '-' ;
						}
					}	

					$birthDate = $staff['staff_birthdate'];
					if($birthDate!='' && $birthDate !='0000-00-00'){
						$birthDate =	date("Y",strtotime($staff['staff_birthdate']));
						//explode the date to get month, day and year

						//get age from date or birthdate
						$age = date("Y") - $birthDate;

						if($birthDate!=''){
							$age = "( ".$age." years old )";
						}else{
							$age = "(-)";
						}
					}else{
						$age = "(-)";
					}

					$staff_settings_excel = jsonEncodeDecode('decode',$staff['staff_settings']);

					$select_ethnic_name = $mysqli->query("SELECT * FROM master_ethnic WHERE ethnic_id = '".$staff['ethnic_id']."' ");
					if($select_ethnic_name->num_rows>0){
						while($row_ethnic_name = $select_ethnic_name->fetch_assoc()){
							$ethic_name = $row_ethnic_name['ethnic_desc'];
						}
					}

					$select_religion_name = $mysqli->query("SELECT * FROM master_religion WHERE religion_id = '".$staff['religion_id']."' ");
					if($select_religion_name->num_rows>0){
						while($row_religion_name = $select_religion_name->fetch_assoc()){
							$religion_name = $row_religion_name['religion_desc'];
						}  
					}

					$newChar       = $char ;
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $count_staff ) ;

	                // for qrcode
	                $qrcode_column = ($newChar++).$count ;
	                $objPHPExcel->getActiveSheet()->setCellValue( $qrcode_column, ' ' ) ;
	                $array_staffidnos[] = [ 'coordinate' => $qrcode_column, 'idno' => $staff_idno, ] ;

	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $staff_idno ) ;
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $staff['staff_name'] ) ;
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $staff['staff_mobileno'] ) ;
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, dataFilter( $gender[$staff['gender_id']] ) ) ;
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, date("d-m-Y",strtotime($staff['staff_birthdate'])) );
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count,  $age );
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count,  $staff_settings_excel['mailing_address'] );
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count,  $staff_settings_excel['marital_status'] );
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $country[$staff['country_id']] ) ;
					$objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $IC ) ;
					// $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $passport ) ;
					// $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $staff['staff_passportno'] ) ;
					// $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $permit ) ;
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, dataFilter( $position[$staff['job_position_id']] ) ) ;
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, dataFilter( $job_status[$staff['job_status_id']] ) ) ;
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $ethic_name) ;
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $religion_name) ;
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, resetDateFormat($staff['staff_date_joined']) ) ;
	                $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, resetDateFormat($staff['created_at']) ) ;
	                // $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, resetDateFormat($staff['staff_covid']) ) ;
	                // $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, resetDateFormat($staff['staff_covid_test']) ) ;
	                // $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, resetDateFormat($staff['staff_fonema']) ) ;
	                // $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $staff['staff_fenoma_period'] ) ;
	                // $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, resetDateFormat($staff['staff_typhoid']) ) ;

	                // $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $staff['staff_point_achievement'] ) ;
	                // $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $staff['staff_point'] ) ;
	                // $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $staff['staff_wallet'] ) ;
	                // $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $staff['staff_star'] ) ;
	                // $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, $tier_list_id[$staff['staff_tier']] ) ;
	                // $objPHPExcel->getActiveSheet()->setCellValue( ($newChar++).$count, ucfirst($staff['staff_achievement']) ) ;

	                $count++ ;
	                $count_staff++ ;
				}
			}


			// start drawing image
			foreach ( $array_staffidnos as $kstaffidnos => $vstaffidnos ){
				// if ( $kstaffidnos == '0' ){
					$generatecode     = generateQrcode( '', $vstaffidnos['idno'], PATH.'hr-staff-vcard.php?staff_idno='.$vstaffidnos['idno'] ) ;

					$qrcode            = $generatecode['url'] ;
					$base64_qrcode     = 'data:image/png;base64,'.base64_encode(file_get_contents($qrcode)) ;
					$gdImage 	       = imagecreatefrompng($base64_qrcode) ;

					$objDrawing        = new PHPExcel_Worksheet_MemoryDrawing() ;
					$objDrawing->setName( $vstaffidnos['idno'] ) ;
					$objDrawing->setImageResource( $gdImage ) ;
					$objDrawing->setRenderingFunction( PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG ) ;
					$objDrawing->setMimeType( PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT ) ;
					$objDrawing->setHeight( 55 ) ;
					$objDrawing->setCoordinates( $vstaffidnos['coordinate'] ) ;
					$objDrawing->setWorksheet( $objPHPExcel->getActiveSheet() ) ;
				// }
			}
			$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight( 40 ) ;


			// start render excel file
		    header( 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' ) ; 
		    header( 'Content-Disposition: attachment;filename="'.$page_filename.'.xls"' ) ;
		    header( 'Cache-Control: max-age=0' ) ;
		    // save to pc
		    ob_clean();
		    $objWriter->save('php://output') ;
		    header( "Refresh: 0" ) ;
			exit ;
		}

		$mysqli_page = $mysqli->query( $mysqli_query . " ORDER BY (".$sort_by.' * 1) '.$sort_by_type.", ".$sort_by." ".$sort_by_type." LIMIT $start_from, " . LIMIT ) ;

		// load pagination
		$page_pagination = nextPrevious($product_page, LIMIT, $search_url, $mysqli_query) ;
		
		// start header here
		include 'requires/page_header.php' ;
		include 'requires/page_top.php' ;

		// reset sort by type
		$sort_by_type = ( $sort_by_type == 'DESC' ? 'ASC' : 'DESC' ) ;
		
		?>
		<!-- Header Ends -->
		<div class="warper container-fluid">   	
			<style type="text/css">
			.table-background-orange td{
				color: #fff ;
   				background-color: #ec9800 !important ;
			}
			.table-background-orange td .fa{
				color: #fff ;
			}
		</style>
			<div class="page-header">
				<h1><?= $lang['Staff'] ?> <small><?= $lang['list'] ?></small></h1>

				<?php if ( permissionCheck($row_user, 'staff-list-new') ){ ?>
					<a href="hr-staff.php?page_mode=new" class="btn btn-purple" target="_blank"><?= $lang['add_new'] ?></a>
				<?php } ?>

				<?php if ( $_SESSION["system_permission"] == 'admin' ){ ?>
					<!-- <a href="hr-staff.php?page_mode=all&show_all_none_branch_staff=all" class="btn btn-purple">Staff Without Branch</a> -->
				<?php } ?>

				<!-- <div  style="float: right;">
					<a href="?page_mode<?= $page_mode.'&'.$search_url ?>&export=yes" target="_blank"><?= $lang['export_as'] ?> Excel</a>
        		</div> -->
			</div>

		    <div class="panel panel-default" id="basic-table-title">
		        <div class="panel-heading"></div>
		        <div class="panel-body">
		            <form method="get" class="form-horizontal" style="max-width:600px;">
		                <div class="form-group">
		                    <label class="col-sm-2 control-label"><?= $lang['Name'] ?></label>
		                    <div class="col-sm-9">
		                        <input type="text" name="search_name" value="<?= $search_name ?>" class="form-control" />
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-sm-2 control-label"><?= $lang['ID No'] ?></label>
		                    <div class="col-sm-9">
		                        <input type="text" name="search_idno" value="<?= $search_idno ?>" class="form-control" />
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-sm-2 control-label"><?= $lang['Mobile'] ?></label>
		                    <div class="col-sm-9">
		                        <input type="text" name="search_mobile" value="<?= $search_mobile ?>" class="form-control" />
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-sm-2 control-label"><?= $lang['email'] ?></label>
		                    <div class="col-sm-9">
		                        <input type="text" name="search_mail" value="<?= $search_mail ?>" class="form-control" />
		                    </div>
		                </div>
		                <div class="form-group" style="display: none;">
		                    <label class="col-sm-2 control-label"><?= $lang['Department'] ?></label>
		                    <div class="col-sm-9">
                                <select name="search_department" class="form-control">
                                    <option value=""><?= $lang['All'] ?></option>
					        		<?php foreach( $department_list as $k => $v ){ ?>
					        			<option value="<?= $v['department_id'] ?>" <?= ( $search_department == $v['department_id'] ? 'selected' : '' ) ?> ><?= $v['department_desc'] ?></option>
					        		<?php } ?>
                                </select>
		                    </div>
		                </div>
		                <div class="form-group" style="display: none;">
		                    <label class="col-sm-2 control-label"><?= $lang['Tier'] ?></label>
		                    <div class="col-sm-9">
                                <select name="search_tier" class="form-control">
                                    <option value=""><?= $lang['All'] ?></option>
					        		<?php foreach( $tier_list as $k => $v ){ ?>
					        			<option value="<?= $v['tier_id'] ?>" <?= ( $search_tier == $v['tier_id'] ? 'selected' : '' ) ?> ><?= $v['title'] ?></option>
					        		<?php } ?>
                                </select>
		                    </div>
		                </div>
		                <div class="form-group" style="display: none;">
		                    <label class="col-sm-2 control-label"><?= $lang['Point'] ?></label>
		                    <div class="col-sm-9">
		                        <input type="text" name="search_point" value="<?= $search_point ?>" class="form-control" />
		                    </div>
		                </div>
		                <div class="form-group" style="display: none;">
		                    <label class="col-sm-2 control-label"><?= $lang['Wallet'] ?></label>
		                    <div class="col-sm-9">
		                        <input type="text" name="search_wallet" value="<?= $search_wallet ?>" class="form-control" />
		                    </div>
		                </div>
		                <div class="form-group" style="display: none;">
		                    <label class="col-sm-2 control-label"><?= $lang['star'] ?></label>
		                    <div class="col-sm-9">
		                        <input type="text" name="search_star" value="<?= $search_star ?>" class="form-control" />
		                    </div>
		                </div>
		                <div class="form-group" style="display: none;">
		                    <label class="col-sm-2 control-label">Achievement</label>
		                    <div class="col-sm-9">
		                        <input type="text" name="search_achievement" value="<?= $search_achievement ?>" class="form-control" />
		                    </div>
		                </div>
                        <div class="form-group" style="display: none;">
                            <label class="col-sm-2 control-label"><?= $lang['L_F'] ?></label>
                            <div class="col-sm-9">
                                <select name="lf_type" class="form-control">
                                    <option value=""><?= $lang['All'] ?></option>
                                    <option value="local" <?= $lf_type == 'local' ? 'selected' : '' ?> ><?= $lang['Local1'] ?></option>
                                    <option value="foreigner" <?= $lf_type == 'foreigner' ? 'selected' : '' ?> ><?= $lang['Foreigner'] ?></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group" style="display: none;">
                            <label class="col-sm-2 control-label"><?= $lang['branch'] ?></label>
                            <div class="col-sm-9">
                                <select name="lf_branch" class="form-control">
                                    <option value=""><?= $lang['All'] ?></option>
                                    <?php
                                    foreach ( $branch as $kk => $vv ){
                                    	echo '<option value="'.$kk.'" '.( $lf_branch == $kk ? 'selected' : '' ).' >'.$vv.'</option>' ;
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
		                <div class="form-group">
                            <label class="col-sm-2 control-label">Status</label>
                            <div class="col-sm-9">
                                <select name="status" class="form-control">
                                    <option value="">Search</option>
                                    <option value="resign" <?= ($status == 'resign' ? 'selected' : '') ?>>Resign</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
		                    <label class="col-sm-2 control-label"><?= $lang['Date Resigned'] ?></label>
		                    <div class="col-sm-9">
		                        <input class="form-control" name="lf_resigned" type="date" value="<?= ($lf_resigned!= '' ? $lf_resigned : date('Y-m-d',time()) ) ?>" placeholder="Date Resigned">
		                    </div>
		                </div>
		                <div class="form-group">
                            <label class="col-sm-2 control-label">View Type</label>
                            <div class="col-sm-9">
                                <select name="export" class="form-control">
                                    <option value="">Search</option>
                                    <option value="yes">View as Excel </option>
                                </select>
                            </div>
                        </div>
		                <div class="form-group">
		                    <div class="col-sm-11">
		                        <input type="hidden" name="page_mode" value="<?= $page_mode ?>" />
		                        <input type="hidden" name="search" value="<?= $search ?>" />
		                        <input type="hidden" name="sort_by" value="<?= $sort_by ?>" />
		                        <input type="hidden" name="sort_by_type" value="<?= $sort_by_type ?>" />
		                        <button type="submit" class="btn btn-purple" style="float:right"><?= $lang['submit'] ?></button>
		                    </div>
		                </div>
		            </form>
		        </div>
		    </div>

            <form method="post">

                <!-- trash -->
                <?php if ( permissionCheck($row_user, 'staff-list-trash') ){ ?>
	                <div class="panel panel-default">
	                    <div class="panel-body">
	                        <select name="page_action" class="form-control selectpicker">
	                            <option value=""><?= $lang['select'] ?></option>
	                            <option value="trash"><?= $lang['move_to_trash'] ?></option>
	                        </select>
	                        <input type="hidden" name="hide" value="1" />
	                        <input type="hidden" name="hide_status" value="action" />
	                        <input type="submit" class="btn btn-purple" value="<?= $lang['submit'] ?>" />
	                    </div>
	                </div>
	            <?php } ?>
	            <!-- end trash -->

                <div class="panel panel-default">
                    <div class="panel-heading"></div>
                    <div class="panel-body">
						<table cellpadding="0" cellspacing="0" border="0" class="responsive table table-striped table-bordered" id="basic-datatable">
							<thead>
								<tr>
									<th><?= $lang['Action'] ?></th>
									<th>
										<div class="custom_dropdown_title">
		                                	<a href="?<?= $search_url ?>&sort_by=staff_idno&sort_by_type=<?= ($sort_by == 'staff_idno' ? $sort_by_type : 'ASC') ?>">
		                                    ID<?= ( $sort_by == 'staff_idno' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
		                                	</a>
		                            	</div>
									</th>
									<th>
										<div class="custom_dropdown_title">
		                                	<a href="?<?= $search_url ?>&sort_by=staff_name&sort_by_type=<?= ($sort_by == 'staff_name' ? $sort_by_type : 'ASC') ?>">
		                                    <?= $lang['Name'] ?><?= ( $sort_by == 'staff_name' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
		                                	</a>
		                            	</div>
									</th>
									<th>
		                            	<span class="custom_dropdown_title">
		                                	<a href="?<?= $search_url ?>&sort_by=gender_id&sort_by_type=<?= ($sort_by == 'gender_id' ? $sort_by_type : 'ASC') ?>">
		                                    <?= $lang['Gender'] ?><?= ( $sort_by == 'gender_id' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
		                                	</a>
		                            	</span>
		                            </th>


									<!-- <th class="custom_dropdown_th">
										<div class="custom_dropdown_title"><?= $lang['L_F'] ?> </div>
										<div class="dropdown custom_dropdown custom_dropdown_lf" id="custom_dropdown_lf" style="display:none;">
											<a href="#" class="dropdown-toggle custom_dropdown_toggle" data-toggle="dropdown"><b class="caret"></b></a>
										    <ul class="dropdown-menu">
										    	<li <?= ($lf_type == '' ? 'class="active"' : '') ?> ><a href="?<?= $search_url ?>&lf_type="><?= $lang['All'] ?></a></li>
										    	<li <?= ($lf_type == 'local' ? 'class="active"' : '') ?> ><a href="?<?= $search_url ?>&lf_type=local"><?= $lang['Local1'] ?></a></li>
										    	<li <?= ($lf_type == 'foreigner' ? 'class="active"' : '') ?> ><a href="?<?= $search_url ?>&lf_type=foreigner"><?= $lang['Foreigner'] ?></a></li>
										    </ul>
										</div>
									</th> -->

									<!-- <?php if ( $STAFFDETAILS == 'show' ){ ?>
										<th class="custom_dropdownbox">
											<span class="custom_dropdown_title">
			                                	<a href="?<?= $search_url ?>&sort_by=staff_icno&sort_by_type=<?= ($sort_by == 'staff_icno' ? $sort_by_type : 'ASC') ?>">
			                                    <?= $lang['IC'] ?><?= ( $sort_by == 'staff_icno' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
			                                	</a>
			                            	</span>
										</th>
										<th class="custom_dropdownbox">
											<span class="custom_dropdown_title">
			                                	<a href="?<?= $search_url ?>&sort_by=staff_passportexpired&sort_by_type=<?= ($sort_by == 'staff_passportexpired' ? $sort_by_type : 'ASC') ?>">
			                                    <?= $lang['Passport'] ?><?= ( $sort_by == 'staff_passportexpired' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
			                                	</a>
			                            	</span>
										</th>
										<th class="custom_dropdownbox">
			                            	<span class="custom_dropdown_title">
			                                	<a href="?<?= $search_url ?>&sort_by=staff_permit_end&sort_by_type=<?= ($sort_by == 'staff_permit_end' ? $sort_by_type : 'ASC') ?>">
			                                    <?= $lang['Permit'] ?><?= ( $sort_by == 'staff_permit_end' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
			                                	</a>
			                            	</span>
										</th>
									<?php } ?> -->

									<th>
		                            	<span class="custom_dropdown_title">
		                                	<a href="?<?= $search_url ?>&sort_by=job_position_id&sort_by_type=<?= ($sort_by == 'job_position_id' ? $sort_by_type : 'ASC') ?>">
		                                    <?= $lang['Designation'] ?><?= ( $sort_by == 'job_position_id' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
		                                	</a>
		                            	</span>
		                            </th>
									<!-- <th class="custom_dropdownbox">
										Department View
									</th>

									<th class="custom_dropdownbox">
										<span class="custom_dropdown_title">
		                                	<a href="?<?= $search_url ?>&sort_by=staff_point_achievement&sort_by_type=<?= ($sort_by == 'staff_point_achievement' ? $sort_by_type : 'ASC') ?>">
		                                    Monthly Point Achievement<?= ( $sort_by == 'staff_point_achievement' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
		                                	</a>
		                            	</span>
									</th>
									<th class="custom_dropdownbox">
										<span class="custom_dropdown_title">
		                                	<a href="?<?= $search_url ?>&sort_by=staff_point&sort_by_type=<?= ($sort_by == 'staff_point' ? $sort_by_type : 'ASC') ?>">
		                                    Point<?= ( $sort_by == 'staff_point' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
		                                	</a>
		                            	</span>
									</th>
									<th class="custom_dropdownbox">
										<span class="custom_dropdown_title">
		                                	<a href="?<?= $search_url ?>&sort_by=staff_wallet&sort_by_type=<?= ($sort_by == 'staff_wallet' ? $sort_by_type : 'ASC') ?>">
		                                    Wallet<?= ( $sort_by == 'staff_wallet' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
		                                	</a>
		                            	</span>
									</th>
									<th class="custom_dropdownbox">
										<span class="custom_dropdown_title">
		                                	<a href="?<?= $search_url ?>&sort_by=staff_star&sort_by_type=<?= ($sort_by == 'staff_star' ? $sort_by_type : 'ASC') ?>">
		                                    Total Star<?= ( $sort_by == 'staff_star' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
		                                	</a>
		                            	</span>
									</th>
									<th class="custom_dropdownbox">
										<span class="custom_dropdown_title">
		                                	<a href="?<?= $search_url ?>&sort_by=staff_tier&sort_by_type=<?= ($sort_by == 'staff_tier' ? $sort_by_type : 'ASC') ?>">
		                                    Tier<?= ( $sort_by == 'staff_tier' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
		                                	</a>
		                            	</span>
									</th>
									<th class="custom_dropdownbox">
										<span class="custom_dropdown_title">
		                                	<a href="?<?= $search_url ?>&sort_by=staff_achievement&sort_by_type=<?= ($sort_by == 'staff_achievement' ? $sort_by_type : 'ASC') ?>">
		                                    Achievement<?= ( $sort_by == 'staff_achievement' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
		                                	</a>
		                            	</span>
									</th> -->

									<th>
		                            	<span class="custom_dropdown_title">
		                                	<a href="?<?= $search_url ?>&sort_by=created_at&sort_by_type=<?= ($sort_by == 'created_at' ? $sort_by_type : 'ASC') ?>">
		                                    <?= $lang['date'] ?><?= ( $sort_by == 'created_at' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
		                                	</a>
		                            	</span>
		                            </th>
									<th>
		                            	<span class="custom_dropdown_title">
		                                	<a href="?<?= $search_url ?>&sort_by=updated_at&sort_by_type=<?= ($sort_by == 'updated_at' ? $sort_by_type : 'ASC') ?>">
		                                    <?= $lang['Last Updated'] ?><?= ( $sort_by == 'updated_at' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
		                                	</a>
		                            	</span>
									</th>
                                    <th width="50"><?= $lang['trash'] ?></th>
								</tr>
							</thead>
							<tbody>
								<?php
								$staff_lists           = [] ;
								$staff_ids             = [] ;
								if( $mysqli_page->num_rows > 0 ){

									while( $row_page   = $mysqli_page->fetch_assoc() ){
										$staff_lists[] = $row_page ;
										$staff_ids[]   = $row_page['staff_id'] ;
									}

									$staff_departments = [] ;
									$select_departments = $mysqli->query( "SELECT a.staff_id, b.department_desc FROM staff_department a
																		   LEFT JOIN setting_department_translation b ON ( a.department_id = b.department_id )
																		   WHERE a.deleted_at IS NULL AND b.lang = 'en' AND a.staff_id IN ( ".implode(', ', $staff_ids)." )" ) ;
									if ( $select_departments->num_rows > 0 ){
										while ( $row_departments = $select_departments->fetch_assoc() ){
											$staff_departments[$row_departments['staff_id']][] = $row_departments['department_desc'] ;
										}
									}

									foreach ( $staff_lists as $k => $row_page ){

										// default variable
										$id          = $row_page['staff_id'] ;
										$staff_idno  = ucwords($row_page['staff_idno']) ;

										if ( $STAFFDETAILS == 'show' ){
	                                        $last_4_class = '' ;
											if ( $row_page['country_id'] != '0' && $row_page['country_id'] != '1' ){
												$last_4_month_passport = date( 'Y-m-d', strtotime( $row_page['staff_passportexpired'].' -2 month' ) ) ;
												$last_4_month_permit   = date( 'Y-m-d', strtotime( $row_page['staff_permit_end'].' -2 month' ) ) ;
												if ( ( $row_page['staff_passportno'] != '-' && TODAYDAY >= $last_4_month_passport ) || ( $row_page['staff_permitno'] != '-' && TODAYDAY >= $last_4_month_permit ) ){
													$last_4_class = 'table-background-orange' ;
												}
												$last_4_month_passport = date( 'Y-m-d', strtotime( $row_page['staff_passportexpired'].' -1 month' ) ) ;
												$last_4_month_permit   = date( 'Y-m-d', strtotime( $row_page['staff_permit_end'].' -1 month' ) ) ;
												if ( ( $row_page['staff_passportno'] != '-' && TODAYDAY >= $last_4_month_passport ) || ( $row_page['staff_permitno'] != '-' && TODAYDAY >= $last_4_month_permit ) ){
													$last_4_class = 'table-background-red' ;
												}
											}

											// staff_birthdate
											$staff_birthdate     = $today_year . date( '-m-d', strtotime( $row_page['staff_birthdate'] ) ) ;

											if ( TODAYDAY == $staff_birthdate || TODAYDAY == date('Y-m-d', strtotime('-1 days',strtotime($staff_birthdate))) ){
												$last_4_class = 'table-background-green' ;
											}
										}

										$check_permission         = false ;
										if ( $get_user_tier['check'] ){
											if ( in_array( $row_page['staff_tier'], $get_user_tier['tiers'] ) ){
												$check_permission = true ;
											}
										}else{
											$check_permission     = true ;
										}

		
										echo '
										 <tr class="odd gradeX '.$last_4_class.'">
										 	<td class="align_center">' ;
										 		if ( $check_permission ){
										 			echo '
											 		<a title="'.$lang['Edit Current'].$lang['Staff'].'" href="hr-staff.php?page_mode=edit&page='.$id.'"><i class="fa fa-edit"></i></a>
											 		<span class="order_print_span">|</span>
											 		<a title="'.$lang['Check staff leave'].'" href="hr-staff-leave.php?staff_id='.$id.'" target="_blank"><i class="fa fa-sign-out" aria-hidden="true"></i></a>
											 		'.(!permissionCheck($row_user, 'staff-list-update') ? '' : '
											 		<span class="order_print_span">|</span>
											 		<a title="'.$lang['Branch Transaction'].'" href="hr-staff-transaction.php?staff_id='.$id.'" target="_blank"><i class="fa fa-exchange" aria-hidden="true"></i></a>') ;
										 		}else{
										 			echo '-' ;
										 		}
										 	echo '
										 	</td>
											<td class="align_center">'.$staff_idno.'</td>
											<td>'.dataFilter($row_page['staff_name']).'</td>
											<td class="align_center">'.dataFilter( $gender[$row_page['gender_id']] ).'</td>
											<!-- <td class="align_center">'.$country[$row_page['country_id']].'</td> -->' ;

											// if ( $STAFFDETAILS == 'show' ){
											// 	echo '
											// 	<td class="align_center">' ;
											// 		if( $row_page['country_id'] == '1' ){
											// 			if( $row_page['staff_icno'] != '' ){
											// 				echo dataFilter($row_page['staff_icno']) ;
											// 			}else{
											// 				echo '-' ;
											// 			}
											// 		}else{
											// 			echo '-' ;
											// 		}
											// 	echo '
											// 	</td>
											// 	<td class="align_center">' ;
											// 		if( $row_page['country_id'] == '1' ){
											// 			echo '-' ;
											// 		}else{
											// 			if( $row_page['staff_passportno'] != '-' && $row_page['staff_passportexpired'] != '0000-00-00' ){
											// 				echo dataFilter($row_page['staff_passportexpired']) . ( $row_page['staff_passportno'] != '' ? ' ('.dataFilter($row_page['staff_passportno']).')' : '' ) ;
											// 			}else{
											// 				echo '-' ;
											// 			}
											// 		}
											// 	echo '
											// 	</td>
											// 	<td class="align_center">' ;
											// 		if( $row_page['country_id'] == '1' ){
											// 			echo '-' ;
											// 		}else{
											// 			if( $row_page['staff_permitno'] != '-' && $row_page['staff_permit_end'] != '0000-00-00' ){
											// 				echo dataFilter($row_page['staff_permit_end']) . ( $row_page['staff_permitno'] != '' ? ' ('.dataFilter($row_page['staff_permitno']).')' : '' ) ;
											// 			}else{
											// 				echo '-' ;
											// 			}
											// 		}
											// 	echo '
											// 	</td>' ;
											// }

											echo '
											<td class="align_center">'.dataFilter( $position[$row_page['job_position_id']] ).'</td>
											<!--
											<td>'.( count($staff_departments[$row_page['staff_id']]) > 0 ? ( implode( '<br />', $staff_departments[$row_page['staff_id']] ) ) : '' ).'</td>
											<td class="align_center">'.$row_page['staff_point_achievement'].'</td>
											<td class="align_center">'.$row_page['staff_point'].'</td>
											<td class="align_center">'.$row_page['staff_wallet'].'</td>
											<td class="align_center">'.$row_page['staff_star'].'</td>
											<td class="align_center">'.$tier_list_id[$row_page['staff_tier']].'</td>
											<td class="align_center">'.ucfirst($row_page['staff_achievement']).'</td>
											-->
											<td class="align_center">'.resetDateFormat($row_page['created_at']).'</td>
											<td class="align_center">'.resetDateFormat($row_page['updated_at']).'</td>
											<td class="align_center">' ;
										 		if ( $check_permission ){
										 			echo '
													<div class="checkbox multiple_trash">
														<input type="checkbox" name="multiple_trash['.$id.']" class="trash_button" value="1">
														<label for="checkbox1"></label>
													</div>' ;
												}
											echo '
											</td>
										</tr>';
									}
								}
								?>
							</tbody>
						</table>
						<?= $page_pagination['page_pagination'] ?>
                    </div>
                </div>
			</form>
		</div>
		<?php
	break ;
}
// footer
include 'requires/page_footer.php' ;
?>