<?php
include_once('common.php');
?>
<?php  
	require_once('lib/nusoap.php');
	session_start();
	$WebserviceAddress = $_SESSION['WebserviceAddress'];
	$Site = $_SESSION['Site'];

	$client = new nusoap_client($WebserviceAddress,'wsdl');
	$client ->soap_defencoding = 'UTF-8';
	if(isset($_POST['confirm_booking'])){
		if(isset($_POST['existing_patient']) && $_POST['existing_patient']==1){
			$existing_patient = 'True';
		}else{
			$existing_patient = 'False';
		}
		$_POST['end_time'] = date("H:i", strtotime('+40 minutes', strtotime($_POST['appointment_time'])));

		$appointment_date = $_POST['appointment_date'].' '.$_POST['appointment_time'].' '.$_POST['end_time'];
		$_SESSION['appointment_date'] = $_POST['appointment_date'].' '.$_POST['appointment_time'];
		$param1 = array(
			'argstring1'=>$Site,
			'argString2'=>$appointment_date,
			'argString3'=>$_POST['firstname'].' '.$_POST['lastname'].','.$existing_patient.','.$_POST['postcode'].','.$_POST['dob'].','.$_POST['mobile'].','.$_POST['email'].",".$_POST['comment'],
			'argString4'=>"1".','.$_POST['appointmentTypes']
		);

		//echo "<pre>";
		//print_r ($param1);
		//echo "</pre>"; die;
		
		$result = $client->call('PostAppointment',$param1);		
		if(isset($result['PostAppointmentResult']) && $result['PostAppointmentResult']=='Success'){
			$status = 'success';
		}else{
			$status = 'failed';
		}
	}else{
		$status = 'failed';
	}

	header('Location: confirmation.php?status='.$status);

?>