<?php

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


$dp_id = $_POST['docpos_id'];

$appid = $_POST['appid'];


$sql = "select doc_position, email, passport_no, phone_no from applicant_table where app_id= '$appid'";

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

$last_position=get_position_name($row["doc_position"], $con);
$new_position=get_position_name($_POST["docpos_id"], $con);

$sql ="UPDATE `applicant_table` SET `doc_position`='$dp_id'  WHERE `app_id`='$appid'";
mysqli_query($con,$sql);

// update doc position in doc log table 
$userid=get_session_user_id($con);
$sql ="insert into `docpos_log_table` (docpos_log_appid, docpos_log_dposid, docpos_log_userid) values ('$appid', '$dp_id', '$userid') ";
mysqli_query($con,$sql);

/*if($new_position=="In Transit to Post"){

	$sql ="UPDATE `applicant_table` SET `intransittopost_date`='$now' WHERE `app_id`='$appid'";
	mysqli_query($con,$sql);
}

if($new_position=="Origination Scan"){
	$sql ="UPDATE `applicant_table` SET `originationscan_date`='$now' WHERE `app_id`='$appid'";
	mysqli_query($con,$sql);
}

if($new_position=="Delivered to Embassy"){

	$sql ="UPDATE `applicant_table` SET `deliveredtoembassy_date`='$now' WHERE `app_id`='$appid'";
	mysqli_query($con,$sql);
}

if($new_position=="Ready for Pickup"){

	$sql ="UPDATE `applicant_table` SET `readyforpickup_date`='$now' WHERE `app_id`='$appid'";
	mysqli_query($con,$sql);
}

if($new_position=="Picked Up"){

	$sql ="UPDATE `applicant_table` SET `pickedup_date`='$now' WHERE `app_id`='$appid'";
	mysqli_query($con,$sql);
}
*/
ver_update_history('Document position has been updated from <b>'.$last_position.'</b> to <b>'.$new_position.'</b> by', $appid, $con);


if($new_position=="Processing"){
////// 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);

	// $sms_box="Dear Applicant, Passport No:".$row["passport_no"].", Your Visa Application status has been updated and your passport is ready for delivery. Visit your pre-selected Thai Visa Application Center location to pick up your passport.
	// Regards - Thai Visa Application Center"; 
	// //$hashtext=$row["c_pass"]." is your PryntStudio.com account password";
 //    //$url='http://180.210.190.230:5959/httpapi/sendsms?userId=saimon&password=Saimon123&smsText='.$sms_box.'&commaSeperatedReceiverNumbers='.$row["phone_cell"].'';
 //    $url='https://powersms.banglaphone.net.bd/httpapi/sendsms?userId=saimon&password=Saimon123&smsText='.$sms_box.'&commaSeperatedReceiverNumbers='.$row["phone_no"].'';
 //    $url = preg_replace("/ /", "%20", $url);
 //    $response = file_get_contents($url);
    
	///////////// ends //////////
}
?>