<?php

include('../db_con.php');
include 'methodlist.php';

session_start();

//var_dump($_POST);
//die();

$dp_id = $_POST['appstatus_id'];

$skuList = explode(PHP_EOL, $_POST['updateids']);

for ($i = 0; $i < count($skuList); $i++) {

      
	$sku=rtrim($skuList[$i]);
    

	if($_POST['idtype']==1){

		$sql = "select app_id, appstatus, email, passport_no from applicant_table where v_uid= '$sku' ";	
	}

	if($_POST['idtype']==2){

		$sql = "select app_id, appstatus, email, passport_no from applicant_table where passport_no LIKE '$sku' ";	
	}
	//echo $sql;


	$result = mysqli_query($con,$sql);
	$row = mysqli_fetch_array($result);

	$last_position=get_app_status_name($row["status"], $con);
	$new_position=get_app_status_name($_POST["appstatus_id"], $con);

	$sql ="UPDATE `applicant_table` SET `appstatus`='$dp_id'  WHERE `app_id`='$row[app_id]'";

	//echo $sql;
	mysqli_query($con,$sql);

	// if($new_position=="Delivered to Embassy"){
	// 	$sql ="UPDATE `applicant_table` SET `online_submissiondate`='$now' WHERE `app_id`='$row[app_id]'";
	// 	mysqli_query($con,$sql);		
	// }
	// if($new_position=="Ready for Pickup"){
	// 	$sql ="UPDATE `applicant_table` SET `pickedupdate`='$now' WHERE `app_id`='$row[app_id]'";
	// 	mysqli_query($con,$sql);		
	// }


	ver_update_history('Application status has been updated from <b>'.$last_position.'</b> to <b>'.$new_position.'</b> by', $row["app_id"],$con);

	// if($new_position=="Delivered to Embassy"){
	// 	////// get email address to send email /////

	// 	$toEmail = $row["email"];

	// 	$subject = "Your Visa Application Status has been Updated";

	// 	$headers  = 'MIME-Version: 1.0' . "\r\n";
	// 	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

	// 	$headers .= 'From: Saimon Visa Application Center <no-reply@saimongroup.com>' . "\r\n";

	// 	$msg_box="Dear Applicant,<br/><br/>
	// 	Passport No:".$row["passport_no"]."<br/><br/> 
	// 	Your Visa Application status has been updated and submitted for processing.
	// 	<br/><br/> Thank you for your interest in Saimon Group.   
	// 	<br/><br/> Regards - 
	// 	<br/> Customer Support Service
	// 	<br/>Singapore Visa Application Center"; 

	// 	mail($toEmail,$subject,$msg_box,$headers);

	// 	///////////// ends //////////
	// }

	// if($new_position=="Ready for Pickup"){
	// ////// get email address to send email /////

	// 	$toEmail = $row["email"];

	// 	$subject = "Your Visa Application Status has been Updated";

	// 	$headers  = 'MIME-Version: 1.0' . "\r\n";
	// 	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

	// 	$headers .= 'From: Saimon Visa Application Center <no-reply@saimongroup.com>' . "\r\n";

	// 	$msg_box="Dear Applicant,<br/><br/>
	// 	Passport No:".$row["passport_no"]."<br/><br/> 
	// 	Your Visa Application status has been updated and your passport is ready for delivery.<br/>
	// 	You do not need to contact our customer support. Simply, visit your pre-selected Singapore Visa Application Center location to pick up your passport.
	// 	<br/><br/> Thank you for your interest in Saimon Group.   
	// 	<br/><br/> Regards - 
	// 	<br/> Customer Support Service
	// 	<br/>Singapore Visa Application Center"; 

	// 	mail($toEmail,$subject,$msg_box,$headers);

	// 	///////////// ends //////////
	// }

}

header('Location: apptracksall.php?msg=2');

?>