<?php
echo "<?phpxml version=\"1.0\" encoding=\"UTF-8\"?>";
?>
<vxml version="2.1">
 <form>
  <block>
  	<prompt>

<?php
	$acode=$_GET['account_number'];
	$pin=$_GET['pin'];
	include('../db.inc.php');
	$sql=mysqli_query($connectionString ,"SELECT * FROM users WHERE number='$acode' AND pin='$pin'");
	if(mysqli_num_rows($sql) == 0) {
		echo "You entered an invalid Account number or pin. Please try again.";
	}
	else {
		$user=mysqli_fetch_array($sql,MYSQLI_ASSOC);
		$firstname=$user['firstname'];
		$lastname=$user['lastname'];
		$number=$user['number'];
		
		$sql=mysqli_query($connectionString ,"SELECT * FROM history WHERE number='$number' ORDER BY date DESC LIMIT 1");
		echo "<sentence>Hello <prosody rate=\"-10%\">$firstname $lastname</prosody></sentence>".
		      "<sentence>Welcome to your account</sentence>";
		if(mysqli_num_rows($sql) == 0) {
			echo "<sentence>There are no transactions on your account.</sentence>";
		}
		else {
			$trans=mysqli_fetch_array($sql,MYSQLI_ASSOC);
			$amount=$trans['amount'];
			$type=$trans['type'];
			$details=$trans['details'];
			$date=substr($trans['date'],0,4)."/".substr($trans['date'],5,2)."/".substr($trans['date'],8,2);
			echo "<sentence>The last transaction on your account was done on <prosody rate=\"-20%\"><say-as interpret-as=\"vxml:date\" format=\"dmy\">$date</say-as></prosody></sentence>";
			echo "<sentence>And the amount was<prosody rate=\"-20%\">$amount of your account currency.</prosody></sentence>";
		}
	}
	
?>
  </prompt>
  <goto next="../nw.vxml#goodbye"/>
  </block>
</form>
</vxml>
