<?php  
//include_once('../etc/db.php');
	ini_set('session.name',"ebossadmin");
    session_start();
    /* cek referer & host sama/x */
	/*if ((isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']))) {
		if (strtolower(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST)) != strtolower($_SERVER['HTTP_HOST'])) {
		// referer not from the same domain
		header('HTTP/1.1 401 Unauthorized', false, 401);
		include($_SERVER['DOCUMENT_ROOT']."/401.php");
		die();
		}
	}*/
	/* cek referer & host sama/x */
	$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
	$doublecek=explode("?",basename(htmlentities(htmlspecialchars($actual_link))));
	if(!file_exists(basename(strtok($actual_link,'?')))){
		header('HTTP/1.0 404 Not Found', false, 404);
		include($_SERVER['DOCUMENT_ROOT']."/404.php");
		die();
	}elseif(preg_match("/%3Cscript/",htmlentities(htmlspecialchars($actual_link)))){
		header('HTTP/1.1 403 forbidden', false, 403);
		include($_SERVER['DOCUMENT_ROOT']."/403.php");
		die();
	}elseif(preg_match("/%20/",$doublecek[1])){
		header('HTTP/1.1 403 forbidden', false, 403);
		include($_SERVER['DOCUMENT_ROOT']."/403.php");
		die();
	}elseif(preg_match("/\./", htmlentities(htmlspecialchars($_REQUEST['sysapp'])))){
		header('HTTP/1.1 400 Bad Request', false, 400);
		include($_SERVER['DOCUMENT_ROOT']."/400.php");
		die();
	}elseif(isset($_REQUEST['sysapp']) && !preg_match("/\./", htmlentities(htmlspecialchars($_REQUEST['sysapp'])))){//case dapat session dari app
        session_destroy();
        $sysapp=$_REQUEST['sysapp'];
		list($sysapp,$sidbuang)=explode("?",basename(htmlentities(htmlspecialchars($sysapp))));
        include($_SERVER['DOCUMENT_ROOT']."/$sysapp/bosconf/config.php");
		$APPFEE_LOGIN="https://$_SERVER[HTTP_HOST]/$MAIN_DIR/appfee/adm/index.php?sysapp=$SYS_DIR";
        setcookie("base_url",$BASE_URL, time() + (86400 * 30), "/");
        ini_set('session.name',"ebossadmin");
        session_start();
        $_SESSION['sys_dir']=$SYS_DIR;//NI YANG PAKAI. LAIN2 tak pakai lagi
        $_SESSION['db_name']=$DB_NAME;
        $_SESSION['main_sid']=$MAIN_SID;
        $_SESSION['base_url']=$BASE_URL;
    }elseif(isset($_SESSION['sys_dir'])){//case dapat session dari home dir
        $sysapp=$_SESSION['sys_dir'];
        include($_SERVER['DOCUMENT_ROOT']."/$sysapp/bosconf/config.php");
		$APPFEE_LOGIN="https://$_SERVER[HTTP_HOST]/$MAIN_DIR/appfee/adm/index.php?sysapp=$SYS_DIR";
        setcookie("base_url",$BASE_URL, time() + (86400 * 30), "/");
	}elseif($doublecek[1]==""){
		header('HTTP/1.1 400 Bad Request', false, 400);
		include($_SERVER['DOCUMENT_ROOT']."/400.php");
		die();
    }
	/*
$sysapp=$_REQUEST['sysapp'];
if($sysapp==""){

}
include($_SERVER['DOCUMENT_ROOT']."/$sysapp/bosconf/config.php");
*/
include("$MYINI/etc/ini.php");

$link=mysqli_connect($DB_HOST,$DB_USER,$DB_PASS,$DB_NAME);
if (mysqli_connect_errno()){
	echo "Failed to connect to MySQL $DB_NAME: " . mysqli_connect_error();
	exit;
}

if($MAIN_SID!="")
        $sql="select * from sch where id='$MAIN_SID'";
    else
        $sql="select * from sch where id='0'";
	
    $res=mysqli_query($link,$sql)or die("$sql failed:".mysqli_error($link));
    $row=mysqli_fetch_assoc($res);
	 $bos_config=$row['bos_config'];
	 $content = $bos_config;
    $decoded = json_decode($content,true);
    if(is_array($decoded)){//apai tambah tgk ada data baru process
        foreach($decoded as $key => $val) {
            //echo "$".$key."=".$val."<br>";
            ${$key}=$val;
        }
    }

	if($LG==""){$LG="BI";}
	if($NUMBER_FORMAT_DECIMAL==""){$NUMBER_FORMAT_DECIMAL="2";}
	if($NUMBER_FORMAT_COMMA==""){$NUMBER_FORMAT_COMMA=",";}
	if($COUNTRYCODE=="")$COUNTRYCODE="MALAYSIA";
    /* db configuration */

$cyear=date('Y');
include_once("../lib/language_$LG.php");
/*
$flag=$_REQUEST['flag'];
if($flag){
	include_once('../etc/session.php');
	echo $_SESSION['username'];
}
*/
$sid=$_REQUEST['sid'];
?>
<!DOCTYPE html>
<!-- Template Name: Packet - Responsive Admin Template build with Twitter Bootstrap 3.x | Author: ClipTheme -->
<!--[if IE 8]><html class="ie8" lang="en"><![endif]-->
<!--[if IE 9]><html class="ie9" lang="en"><![endif]-->
<!--[if !IE]><!-->
<html lang="en">
	<!--<![endif]-->
	<!-- start: HEAD -->
	<head>
		<title><?php echo $lg_welcome;?></title>
		<?php include_once($_SERVER['DOCUMENT_ROOT']."/assets/mylib/myheader_setting.php");?>
		<?php include($_SERVER['DOCUMENT_ROOT']."/assets/mylib/sys_header.php");?>
		<link rel="stylesheet" href="/bower_components/sweetalert/dist/sweetalert.css">
		<script src="/bower_components/sweetalert/dist/sweetalert-dev.js"></script>
		<script>
		function check_image(filename) {
			var hash = {'.png'  : 1,'.gif' : 1,'.jpeg' : 1,'.jpg' : 1,};
			var re = /\..+$/;
			var ext = filename.slice(filename.lastIndexOf(".")).toLowerCase();
			if (hash[ext]) {
				return true;
			} else {
				alert("<?php echo $lg_invalid_file;?> PNG, JPG, GIF.");
				$('input[name="file1"]').val('');
				return false;
			}
		}
		
		function check_resume(filename) {
			var hash = {'.pdf'  : 1,'.doc' : 1,'.docx' : 1,'.odt' : 1,'.rtf' : 1,};
			var re = /\..+$/;
			var ext = filename.slice(filename.lastIndexOf(".")).toLowerCase();
			if (hash[ext]) {
				return true;
			} else {
				alert("<?php echo $lg_invalid_file;?> DOC, DOCX, PDF, ODT, RTF.");
				$('input[name="file2"]').val('');
				return false;
			}
		}
		
		function loadJSON(file, callback) {   

			var xobj = new XMLHttpRequest();
			xobj.overrideMimeType("application/json");
			xobj.open('GET', file, true); // Replace 'my_data' with the path to your file
			xobj.onreadystatechange = function () {
				  if (xobj.readyState == 4 && xobj.status == 200) {
					// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
					callback(xobj.responseText);
				  }
			};
			xobj.send(null);  
		 }

		function getBandar() {
			
			var state = document.getElementById("applicantstate").value;
			document.getElementById("applicantcity").value="";
			document.getElementById("applicantdistrict").value="";
			
			$("#applicantcity").empty();
			$("#applicantdistrict").empty();
			state=state.replace( /\s/g, '');
//			alert(state);
			 loadJSON("../lib/City"+state+".json", function(response) {
			
					var actual_JSON = JSON.parse(response);
					var options ="";
					options += "<option><?php echo $lg_select;?></option>";	
					Object.values(actual_JSON.bandar).forEach(function(values) {
						options += "<option>" + values + "</option>";
					});
					$("#applicantcity").html(options);
					
				});
			
		}
		function getDaerah() {
			
			var state = document.getElementById("applicantstate").value;
			state=state.replace( /\s/g, '');
			 loadJSON("../lib/District"+state+".json", function(response) {
					//alert(response);
					var actual_JSON = JSON.parse(response);
					var options2 ="";
					options2 += "<option><?php echo $lg_select;?></option>";	
					Object.values(actual_JSON.daerah).forEach(function(values) {
						options2 += "<option>" + values + "</option>";
					});
					$("#applicantdistrict").html(options2);
					
				});
			
		}

		function getcitizenship(){
			loadJSON("../lib/worldcountries.json", function(response) {
					//alert(response);
					var actual_JSON = JSON.parse(response);
					var options3 ="";
					options3 += "<option><?php echo $lg_select;?></option>";	
					Object.values(actual_JSON.country).forEach(function(values) {
						options3 += "<option>" + values + "</option>";
					});
					$("#applicantcitizen").html(options3);
					
				});
		}
		</script>
	</head>
<!-- end: HEAD -->
	<body >

	<div class="modal-content no-border">
		<div class="modal-header mybg-dark-blue myprint-hidden">
			<div class="pull-left">
				<h4 class="text-white no-margin text-uppercase" id="myModalLabel"> <?php echo "$lg_online_job_application_form $flag";?> 
				</h4>
			</div>
		</div>
	</div>
	<div class="modal-body bg-light-grey">
				<input type="hidden" name="transid" id="transid" value="<?php echo time(); ?>">
				<input type="hidden" name="sysapp" id="sysapp" value="<?php echo $sysapp; ?>">
				<input type="hidden" name="sid" id="sid" value="<?php echo $sid; ?>">
				<div class="row">
					<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
						<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_position_applied";?> *</span>
									<select class="form-control input-sm" name="applyfor" id="applyfor">
									<?php 
										if($applicantjob==""){$selected="selected";}else{$selected="";}
											echo "<option value=\"\" $selected>- $lg_select -</option>";
										$sql="select * from type where grp='job_offer' and val='1' and (sid=0 or sid='$sid') order by prm";
										$res=mysqli_query($link,$sql)or die("query failed:".mysqli_error($link));
										while($row=mysqli_fetch_assoc($res)){
											$s= strtoupper($row['prm']);
											if($applicantjob==$s){$selected="selected";}else{$selected="";}
											echo "<option value=\"$s\" $selected>$s</option>";
										}
									?>
									</select>
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_applicant_name";?> *</span>
										<input class="form-control input-sm" name="applicantname" type="text" id="applicantname" value="<?php echo $applicantname;?>">
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_ic";?> *</span>
										<input class="form-control input-sm" name="applicantic" type="text" id="applicantic" placeholder="890812128787" value="<?php echo $applicantic;?>">
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_birth_date";?>*</span>
								<select class="form-control input-sm" name="applicantbday" id="applicantbday">
									<?php
									if($applicantbday==""){$selected="selected";}else{$selected="";}
										echo "<option value=\"\" $selected>$lg_select</option>";
									for($day=1;$day<=31;$day++){
										$day=sprintf('%02d',$day);
										if($day==$applicantbday){$selected="selected";}else{$selected="";}
										echo "<option value=\"$day\" $selected>$day</option>";
									}
									?>
								</select>
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_birth_month";?> *</span>
								<select class="form-control input-sm" name="applicantbmonth" id="applicantbmonth">
									<?php
									if($applicantbmonth==""){$selected="selected";}else{$selected="";}
									echo "<option value=\"\" $selected>$lg_select</option>";
									for($month=1;$month<=12;$month++){
										$month=sprintf('%02d',$month);
										if($applicantbmonth==$month){$selected="selected";}else{$selected="";}
										echo "<option value=\"$month\" $selected>$month</option>";
									}
									?>
								</select>
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_birth_year";?> *</span>
								<select class="form-control input-sm" name="applicantbyear" id="applicantbyear">
								<?php
								if($applicantbyear==""){$selected="selected";}else{$selected="";}
									echo "<option value=\"\" $selected>$lg_select</option>";
								for($latestyear=$cyear-17;$latestyear>($cyear-65);$latestyear--){
									if($applicantbyear==$latestyear){$selected="selected";}else{$selected="";}
									echo "<option value=\"$latestyear\" $selected>$latestyear</option>";
								}
								?>
								</select>
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_birth_place";?> *</span>
								<select class="form-control input-sm" name="applicantbplace" id="applicantbplace">
								<?php 
									if($applicantbplace==""){$selected="selected";}else{$selected="";}
										echo "<option value=\"\" $selected>- $lg_select-</option>";
									$sql="select name from state union select distinct(bplace) as name from workreg";
									$res=mysqli_query($link,$sql)or die("query failed:".mysqli_error($link));
									while($row=mysqli_fetch_assoc($res)){
										$s=$row['name'];
										if($applicantbplace==$s){$selected="selected";}else{$selected="";}
										echo "<option value=\"$s\" $selected>$s</option>";
									}
								?>
								</select>
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
							<div class="form-group">
								<span class="text-bold"><?php echo $lg_other;?></span><br>
								<input type="checkbox" class="input-sm" name="otherbirthplace" onclick="if(this.checked)showhide('div_show_filter'); else showhide('div_show_filter');">
							</div>
						</div>
						<div id="div_show_filter" class="no-print printhidden" <?php if(!$showfilter) echo "style=\"display: none;\"";?>>
							<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
								<span class="text-bold"><?php echo "$lg_birth_place ";?><?php echo "($lg_other)";?></span><br>
								<input class="form-control input-sm" name="otherbirthplace" type="text" id="otherbirthplace" value="">
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_sex";?> *</span>
								<select class="form-control input-sm" name="applicantsex" id="applicantsex" >
								<?php 
									if($applicantsex==""){$selected="selected";}else{$selected="";}
										echo "<option value=\"\" $selected>- $lg_select-</option>";
									$sql="select * from type where grp='sex'";
									$res=mysqli_query($link,$sql)or die("query failed:".mysqli_error($link));
									while($row=mysqli_fetch_assoc($res)){
												$s=$row['prm'];
												$v=$row['val'];
												if($applicantsex==$v){$selected="selected";}else{$selected="";}
												echo "<option value=\"$v\" $selected>$s</option>";
									}
								?>
								</select>          
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_race";?> *</span>
								<select class="form-control input-sm" name="applicantrace" id="applicantrace" >
								<?php 
									if($applicantrace==""){$selected="selected";}else{$selected="";}
										echo "<option value=\"\" $selected>- $lg_select-</option>";
									$sql="select * from type where grp='race'";
									$res=mysqli_query($link,$sql)or die("query failed:".mysqli_error($link));
									while($row=mysqli_fetch_assoc($res)){
												$s=$row['prm'];
												if($applicantrace==$s){$selected="selected";}else{$selected="";}
												echo "<option value=\"$s\" $selected>$s</option>";
									}
								?>
								</select>          
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_religion";?> *</span>
								<select class="form-control input-sm" name="applicantreligion" id="applicantreligion" >
								<?php 
									if($applicantreligion==""){$selected="selected";}else{$selected="";}
										echo "<option value=\"\" $selected>- $lg_select-</option>";
									$sql="select * from type where grp='religion'";
									$res=mysqli_query($link,$sql)or die("query failed:".mysqli_error($link));
									while($row=mysqli_fetch_assoc($res)){
												$s=$row['prm'];
												if(strtoupper($applicantreligion)==strtoupper($s)){$selected="selected";}else{$selected="";}
												echo "<option value=\"$s\" $selected>$s</option>";
									}
								?>
								</select>          
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_citizenship";?> *</span>
								<select class="form-control input-sm" name="applicantcitizen" id="applicantcitizen" >
								<?php 
									if($applicantcitizenship==""){$selected="selected";}else{$selected="";}
										echo "<option value=\"\" $selected>- $lg_select-</option>";
										$getcountry=json_decode(file_get_contents("../lib/worldcountries.json"),true);
										$countryoption="";
										$bilcountry=0;
										foreach($getcountry["country"] as $keycountry){
											$bilcountry++;
											if($applicantcitizenship==$keycountry){$selected="selected";}else{$selected="";}
											echo "<option value=\"$keycountry\" $selected>$keycountry</option>";
											if($bilcountry>=count($getcountry["country"]) && $applicantcitizenship!=$keycountry && $applicantcitizenship!=""){
											echo "<option value=\"$applicantcitizenship\" selected>$applicantcitizenship</option>";
											}
										}
								?>
								</select>          
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_email";?> *</span>
								<input class="form-control input-sm" name="applicantmel" type="text" id="applicantmel" value="<?php echo $applicantmel;?>">
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_address";?> (<?php echo $lg_line;?> 1)*</span>
								<input class="form-control input-sm" name="applicantaddr" id="applicantaddr" type="text" value="<?php echo $applicantaddr;?>" >
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_address";?> (<?php echo $lg_line;?> 2)*</span>
								<input class="form-control input-sm" name="applicantaddr1" id="applicantaddr1" type="text" value="<?php echo $applicantaddr1;?>" >
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_state";?> *</span>
								<select class="form-control input-sm" name="applicantstate" id="applicantstate" onchange="getBandar('<?php echo $MYLIB;?>')">
								<?php 
										echo "<option value=\"\">- $lg_select-</option>";
									$sql="select * from state";
									$res=mysqli_query($link,$sql)or die("query failed:".mysqli_error($link));
									while($row=mysqli_fetch_assoc($res)){
												$s=$row['name'];
												if($applicantstate==$s){$selected="selected";}else{$selected="";}
												echo "<option value=\"$s\" $selected>$s</option>";
									}
								?>
								</select>          
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_city";?> *</span>
								<select class="form-control input-sm" name="applicantcity" id="applicantcity" onchange="getDaerah('<?php echo $MYLIB;?>')">
										<option value="">- <?php echo $lg_select;?> -</option>
								</select> 
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_district";?> *</span>
								<select class="form-control input-sm" name="applicantdistrict" id="applicantdistrict">
										<option value="">- <?php echo $lg_select;?> -</option>
										
								</select>
							</div>
						</div>
						<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_postcode";?> *</span>
								<input class="form-control input-sm" name="applicantpostcode" id="applicantpostcode" type="text" value="<?php echo $applicantpcode;?>" > 
							</div>
						</div>

					</div>

					<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_marital_status";?> *</span>
								<select class="form-control input-sm" name="applicantmstatus" id="applicantmstatus">
								<?php 
									if($applicantmstatus==""){$selected="selected";}else{$selected="";}
										echo "<option value=\"\" $selected>- $lg_select -</option>";
									$sql="select * from type where grp='marital_status' order by val";
									$res=mysqli_query($link,$sql)or die("query failed:".mysqli_error($link));
									while($row=mysqli_fetch_assoc($res)){
												$s=$row['prm'];
												if($applicantmstatus==$s){$selected="selected";}else{$selected="";}
												echo "<option value=\"$s\" $selected>$s</option>";
									}
								?>
								</select>
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_no_of_child";?></span>
								<select class="form-control input-sm" name="applicantbilanak" id="applicantbilanak">
								<?php 
									if($applicantbilanak==""){$selected="selected";}else{$selected="";}
										echo "<option value=\"\">- $lg_select -</option>";
									for($i = 0; $i <= 14; $i++){
											if($applicantbilanak==$i && $applicantbilanak!=""){$selected="selected";}else{$selected="";}
											if($i==0){$idisplay=$lg_none;}else{$idisplay=$i;}
											echo "<option value=\"$i\" $selected>$idisplay</option>";
									}
								?>
								</select>
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_telephone";?> *</span>
								<input class="form-control input-sm" name="applicanttel" id="applicanttel" type="text" value="<?php echo $applicanttel;?>">
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_tel_mobile";?> *</span>
								<input class="form-control input-sm" name="applicanthp" type="text" id="applicanthp" value="<?php echo $applicanthp;?>">
							</div>
						</div>
						
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_name_of $lg_university/$lg_college/$lg_school";?> *</span>
								<input class="form-control input-sm" name="applicantinstitution" id="applicantinstitution" type="text" value="<?php echo $applicantinstitution;?>" > 
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_academic_level";?> *</span>
								<select name="applicanthiedu" id="applicanthiedu" class="form-control input-sm">
									<?php 
										if($applicanthiedu==""){$selected="selected";}else{$selected="";}
											echo "<option value=\"\" $selected>- Select -</option>";
										$sql="select * from type where grp='kelulusan' and (sid=0 or sid='$sid') and val='1' order by val";   
										$res=mysqli_query($link,$sql)or die("$sql failed:".mysqli_error($link));
										while($row=mysqli_fetch_assoc($res)){
											$s=$row['prm'];
											$c=$row['code'];
											if($applicanthiedu==$c){$selected="selected";}else{$selected="";}
											echo "<option value=\"$c\" $selected>$s</option>";
										} 	
									?>
								</select>
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "CGPA / $lg_grade";?> *</span>
								<input type="text" name="applicantcgpa" id="applicantcgpa" class="form-control input-sm" value="<?php echo $applicantcgpa;?>">
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_course";?> *</span>
								<input type="text" name="applicantcoz" id="applicantcoz" class="form-control input-sm" value="<?php echo $applicantcoz;?>">
							</div>
						</div>
						<div class="col-xs-10 col-sm-10 col-md-4 col-lg-4">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_serious $lg_illness";?> *</span>
								<input class="form-control input-sm" name="applicantill" id="applicantill" type="text" value="<?php echo $applicantill;?>" >
							</div>
						</div>
						<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
							<div class="form-group">
								<span class="text-bold"><?php echo $lg_none;?></span><br>
								<input type="checkbox" class="input-sm" name="cill" onclick="if(this.checked)$('#applicantill').val('None'); else $('#applicantill').val('');">
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_working_experience";?> *</span>
								<select name="applicantexyear" id="applicantexyear" class="form-control input-sm">
									<?php 
										if($applicantexyear==""){$selected="selected";}else{$selected="";}
										echo "<option value=\"\" $selected>- Year -</option>";																	
										for($i=1;$i<=20;$i++){
											if($applicantexyear==$i){$selected="selected";}else{$selected="";}
											echo "<option value=\"$i\" $selected>$i</option>";
										}
										?>
								</select>
							</div>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
						<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
								<span class="text-bold"><?php echo "$lg_driving_license";?></span>
						</div>
						<div class="row">
						<?php
						$ll=explode(',',$applicantlesen);
						$ln=explode(',',"A,B,B1,B2,B3,C,D,E,E1,E2,F,G,H,I,J");
						 for ($i=0;$i<count($ln);$i++){
								$ck="";
								for ($j=0;$j<count($ll);$j++){
									if($ln[$i]==$ll[$j]){
										$ck="checked";
										break;
									}
								}
						?>
						<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
							<label class="checkbox-inline" style="margin:0 10px 0 0;">
							<input type="checkbox" name="ln[]" value="<?php echo $ln[$i];?>" <?php echo $ck;?>/><?php echo $ln[$i];?>
							</label>
						</div>
						<?php }?>
						</div>
						</div>
						<div class="col-xs-10 col-sm-10 col-md-4 col-lg-4">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_own_transport";?></span>
							</div>
						</div>
						<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
							<div class="form-group">
							<label class="checkbox-inline" style="margin:0 10px 0 0;">
							<input type="checkbox" name="applicantowntransport" id="applicantowntransport" value="1" <?php if($applicantowntransport) echo "checked";?>/><?php echo "$lg_yes";?>
							</label>
							</div>
						</div>
						<div class="col-xs-10 col-sm-10 col-md-4 col-lg-4">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_need_accomodation";?></span>
							</div>
						</div>
						<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
							<div class="form-group">
							<label class="checkbox-inline" style="margin:0 10px 0 0;">
							<input type="checkbox" name="applicantaccomodation" id="applicantaccomodation" value="1" <?php if($applicantaccomodation) echo "checked";?>/><?php echo "$lg_yes";?>
							</label>
							</div>
						</div>
						<div class="col-xs-2 col-sm-2 col-md-3 col-lg-3">
								<div class="form-group">
								<span class="text-bold"><?php echo "$lg_picture";?> *</span>
								</div>
						</div>
						<div class="col-xs-10 col-sm-10 col-md-9 col-lg-9">
							<div class="form-group">
							<?php if($img!=""){?>
								<a href="<?php echo "$DIR_DATA";?>/job/<?php echo "$img";?>">
								Download <img src="<?php echo "$MYLIB";?>/img/user12.png"  height="10">
								</a>                        
							<?php } ?>
							<input style="padding-left: 0;" class="form-control input-sm" name="file1" type="file" id="file1" onChange="check_image(this.value);">
							</div>
						</div>
						<div class="col-xs-2 col-sm-2 col-md-3 col-lg-3">
							<div class="form-group">
								<span class="text-bold"><?php echo "$lg_resume";?> *</span>
							</div>
						</div>
						<div class="col-xs-10 col-sm-10 col-md-9 col-lg-9">
							<div class="form-group">
							<?php if($att!=""){?>
								<a href="<?php echo "$DIR_DATA";?>/job/<?php echo "$att";?>">
								Download <img src="<?php echo "$MYLIB";?>/img/attach16.png"  height="10"></a>                        
							<?php } ?>
							<input style="padding-left: 0;" class="form-control input-sm" name="file2" type="file" id="file2" onChange="check_resume(this.value);">
							</div>
						</div>
					</div>
				</div>
				



			<div class="modal-footer">
				<button type="button" class="btn btn-primary" onclick="regnew()">
					<?php echo $lg_send;?>
				</button>
			</div>

				
			</div>

<script>
function successform(title,hint){
	swal({
		title: title,
		text: hint,
		type: "success",
		confirmButtonColor: "#007AFF"
	},
	function(isConfirm){
	  if (isConfirm) {
		top.location.href="<?php echo $BASE_URL;?>";
	  }
	});
}

function regnew(){
	var applyfor = $('#applyfor').val();
	if(applyfor==""){
		alert("<?php echo $lg_please_select.' \"'.$lg_position_applied.'\"';?>");
		$('#applyfor').focus();
		return false;
	}

	var applicantname = $('#applicantname').val();
	if(applicantname==""){
		alert("<?php echo $lg_please_fill.' \"'.$lg_name.'\"';?>");
		$('#applicantname').focus();
		return false;
	}

	var applicantic = $('#applicantic').val();
	if (applicantic ==""){
		 alert("<?php echo $lg_please_fill.' \"'.$lg_ic.'\"';?>");
		 $('#applicantic').focus();
		 return false;
	}

	var applicantbday = $('#applicantbday').val();
	if (applicantbday ==""){
		 alert("<?php echo $lg_please_select.' \"'.$lg_birth_date.'\"';?>");
		 $('#applicantbday').focus();
		 return false;
	}

	var applicantbmonth = $('#applicantbmonth').val();
	if (applicantbmonth ==""){
		 alert("<?php echo $lg_please_select.' \"'.$lg_birth_month.'\"';?>");
		 $('#applicantbmonth').focus();
		 return false;
	}

	var applicantbyear = $('#applicantbyear').val();
	if (applicantbyear ==""){
		 alert("<?php echo $lg_please_select.' \"'.$lg_birth_year.'\"';?>");
		 $('#applicantbyear').focus();
		 return false;
	}

	var applicantbplace = $('#applicantbplace').val();
	var otherbirthplace = $('#otherbirthplace').val();
	// alert(applicantbplace);
	// alert(otherbirthplace);
	if (applicantbplace =="" && otherbirthplace==""){
		 alert("<?php echo $lg_please_select.' \"'.$lg_birth_place.'\"';?>");
		 $('#applicantbplace').focus();
		 return false;
	}else if (applicantbplace =="" && otherbirthplace!=""){
		var applicantbplace=otherbirthplace;
	}
	// alert(applicantbplace);

	var applicantsex = $('#applicantsex').val();
	if (applicantsex ==""){
		 alert("<?php echo $lg_please_select.' \"'.$lg_gender.'\"';?>");
		 // $('#applicantsex').focus();
		 return false;
	}

	var applicantrace = $('#applicantrace').val();
	if (applicantrace ==""){
		 alert("<?php echo $lg_please_select.' \"'.$lg_race.'\"';?>");
		 $('#applicantrace').focus();
		 return false;
	}

	var applicantreligion = $('#applicantreligion').val();
	if (applicantreligion ==""){
		 alert("<?php echo $lg_please_select.' \"'.$lg_religion.'\"';?>");
		 $('#applicantreligion').focus();
		 return false;
	}

	var applicantcitizen = $('#applicantcitizen').val();
	if (applicantcitizen ==""){
		 alert("<?php echo $lg_please_select.' \"'.$lg_citizenship.'\"';?>");
		 $('#applicantcitizen').focus();
		 return false;
	}

	var applicantmel = $('#applicantmel').val();
	if(applicantmel==""){
		 alert("<?php echo $lg_please_fill.' \"'.$lg_email.'\"';?>");
		 $('#applicantmel').focus();
		 return false;
	}
	var atpos = applicantmel.indexOf("@");
	var dotpos = applicantmel.lastIndexOf(".");
	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=applicantmel.length) {
		alert("<?php echo $lg_invalid_email;?>");
		$('#applicantmel').focus();
		return false;
	}

	var applicantaddr = $('#applicantaddr').val();
	if(applicantaddr==""){
		 alert("<?php echo $lg_please_fill.' \"'.$lg_address.'\"';?>");
		 $('#applicantaddr').focus();
		 return false;
	}

	var applicantaddr1 = $('#applicantaddr1').val();
	if(applicantaddr1==""){
		 alert("<?php echo $lg_please_fill.' \"'.$lg_address.'\"';?>");
		 $('#applicantaddr1').focus();
		 return false;
	}
	
	var applicantstate = $('#applicantstate').val();
	if(applicantstate==""){
		 alert("<?php echo $lg_state;?>");
		 $('#applicantstate').focus();
		 return false;
	}

	var applicantcity = $('#applicantcity').val();
	if(applicantcity=="" || applicantcity=="<?php echo $lg_select;?>"){
		 alert("<?php echo $lg_city;?>");
		 $('#applicantcity').focus();
		 return false;
	}

	var applicantdistrict = $('#applicantdistrict').val();
	if(applicantdistrict=="" || applicantdistrict=="<?php echo $lg_select;?>"){
		 alert("<?php echo $lg_district;?>");
		 $('#applicantdistrict').focus();
		 return false;
	}

	var applicantpostcode = $('#applicantpostcode').val();
	if(applicantpostcode==""){
		 alert("<?php echo $lg_please_fill.' \"'.$lg_postcode.'\"';?>");
		 $('#applicantpostcode').focus();
		 return false;
	}

	var applicantmstatus = $('#applicantmstatus').val();
	if (applicantmstatus ==""){
		 alert("<?php echo $lg_please_select.' \"'.$lg_marital_status.'\"';?>");
		 $('#applicantmstatus').focus();
		 return false;
	}

	var applicanttel = $('#applicanttel').val();
	if(applicanttel==""){
		 alert("<?php echo $lg_please_fill.' \"'.$lg_telephone.'\"';?>");
		 $('#applicanttel').focus();
		 return false;
	}
	
	var applicanthp = $('#applicanthp').val();
	if(applicanthp==""){
		 alert("<?php echo $lg_please_fill.' \"'.$lg_tel_mobile.'\"';?>");
		 $('#applicanthp').focus();
		 return false;
	}

	var applicantinstitution = $('#applicantinstitution').val();
	if(applicantinstitution==""){
		 alert("<?php echo $lg_alert_institution;?>");
		 $('#applicantinstitution').focus();
		 return false;
	}

	var applicanthiedu = $('#applicanthiedu').val();
	if(applicanthiedu==""){
		 alert("<?php echo $lg_alert_education;?>");
		 $('#applicanthiedu').focus();
		 return false;
	}

	var applicantcgpa = $('#applicantcgpa').val();
	if(applicantcgpa==""){
		 alert("<?php echo $lg_alert_cgpa;?>");
		 $('#applicantcgpa').focus();
		 return false;
	}

	var applicantcoz = $('#applicantcoz').val();
	if(applicantcoz==""){
		 alert("<?php echo $lg_alert_course;?>");
		 $('#applicantcoz').focus();
		 return false;
	}

	var file1 = document.getElementById('file1').value;
	if(file1==""){
		alert("<?php echo $lg_alert_picture;?>");
		$('#file1').focus();
		return;
	}

	var file2 = document.getElementById('file2').value;
	if(file2==""){
		alert("<?php echo $lg_alert_resume;?>");
		$('#file2').focus();
		return;
	}

	/* data wajib backend */
	var transid = $('#transid').val();
	var sysapp= $('#sysapp').val();
	var sid= $('#sid').val();
	/* data wajib backend */

	/* data xmandatori */
	var applicantbilanak = $('#applicantbilanak').val();
	var applicantill = $('#applicantill').val();
	var ln = [];
	var arrln=[];
	$.each($("input[name='ln[]']:checked"), function(){
		arrln.push($(this).next('label').text());
		ln.push($(this).val());
	});
	var applicantexyear= $('#applicantexyear').val();
	var applicantowntransport = $('#applicantowntransport').val();
	var applicantaccomodation = $('#applicantaccomodation').val();
	/* data xmandatori */
	//alert(ln);

	var datapost = new FormData();
		datapost.append('sysapp', sysapp);
		datapost.append('transid', transid);
		datapost.append('sid', sid);
		datapost.append('op', 'regnew');
		datapost.append('applyfor', applyfor);
		datapost.append('applicantname', applicantname);
		datapost.append('applicantic', applicantic);
		datapost.append('applicantbday', applicantbday);
		datapost.append('applicantbmonth', applicantbmonth);
		datapost.append('applicantbyear', applicantbyear);
		datapost.append('applicantbplace', applicantbplace);
		datapost.append('applicantsex', applicantsex);
		datapost.append('applicantrace', applicantrace);
		datapost.append('applicantreligion', applicantreligion);
		datapost.append('applicantcitizen', applicantcitizen);
		datapost.append('applicantmel', applicantmel);
		datapost.append('applicantaddr', applicantaddr);
		datapost.append('applicantaddr1', applicantaddr1);
		datapost.append('applicantstate', applicantstate);
		datapost.append('applicantcity', applicantcity);
		datapost.append('applicantdistrict', applicantdistrict);
		datapost.append('applicantpostcode', applicantpostcode);
		datapost.append('applicantmstatus', applicantmstatus);
		datapost.append('applicantbilanak', applicantbilanak);
		datapost.append('applicanttel', applicanttel);
		datapost.append('applicanthp', applicanthp);
		datapost.append('applicantinstitution', applicantinstitution);
		datapost.append('applicanthiedu', applicanthiedu);
		datapost.append('applicantcgpa', applicantcgpa);
		datapost.append('applicantcoz', applicantcoz);
		datapost.append('applicantill', applicantill);
		datapost.append('applicantexyear', applicantexyear);
		datapost.append('ln', ln);
		datapost.append('applicantowntransport', applicantowntransport);
		datapost.append('applicantaccomodation', applicantaccomodation);
		datapost.append('file1', $('#file1')[0].files[0]);
		datapost.append('file2', $('#file2')[0].files[0]);
		console.log(datapost);
			$.ajax({
			   type: "POST",
			   url: "job_model.php",
			   processData: false, // important
			   contentType: false, // important
			   data: datapost,
			   dataType:'json',
			   enctype: 'multipart/form-data',
			   success: function(data){
				 if(data.status == true){
					 //alert("We Will Be Proccess Your Form");
					 var title = '<?php echo $lg_successfully_registered;?>';
					 var hint = '<?php echo $lg_we_will_be_proccess_your_form_thank_you;?>';
					 window.location.href="job_success.php?transid="+data.transid+"&sysapp="+data.sysapp;
					 //successform(title,hint);
					 //alert(data.message);
				}else{
					alert(data.message);
					console.log(data.message);
				}

			   },
			  error: function(XMLHttpRequest, textStatus, errorThrown) { 
				alert("Status: " + textStatus+", Error: " + errorThrown+", Pageload: "+XMLHttpRequest.responseText);
			  }
			});
   }

</script>

<script>
	$('#bday').datepicker({
		dateFormat: 'yy-mm-dd',
		changeYear: true,
		changeMonth: true
		});
</script>
<!-- start: MAIN JAVASCRIPTS -->
		<?php include($_SERVER['DOCUMENT_ROOT']."/assets/mylib/sys_footer.php");?>
		<!-- end: MAIN JAVASCRIPTS -->
		
	</body>
</html>