<?

////////////////////////////////
$EnforceSession = false;
include "includes/includes.php";
////////////////////////////////

$PaymentStatus = request("payment_status");
if( $PaymentStatus != "Completed" ) exit;

$OrderString = request("custom");
$OrderVariables = split("\|", $OrderString);

$OrderType = $OrderVariables[0];
$OrderNumber = $OrderVariables[1];
$OrderID = $OrderVariables[2];

$Record = SelectSingleRow("SELECT * FROM payment WHERE id = " . $OrderNumber);
$Students = $Record->GetValue("students");
$Price = $Record->GetValue("price");
$FirstName = $Record->GetValue("firstname");
$LastName = $Record->GetValue("lastname");
$Address = $Record->GetValue("address");
$City = $Record->GetValue("city");
$State = $Record->GetValue("state");
$Zip = $Record->GetValue("zip");
$Phone = $Record->GetValue("phone");
$Email = $Record->GetValue("email");

// Header
include "includes/header.php";

// Begin Template
$tp = new PhpTemplate;
for( $tp->StartFromFile( "templates/" . strtolower($OrderType) . "_success.template" ); $tp->NextAndEchoOutput(); ) 
{

	CheckGlobalEscapes( $tp );	
	
	if( $tp->IsEscape("STUDENT-AMOUNT") ) echo $Students;
	else if( $tp->IsEscape("FIRST-NAME") ) echo $FirstName;
	else if( $tp->IsEscape("LAST-NAME") ) echo $LastName;
	else if( $tp->IsEscape("ADDRESS") ) echo $Address;
	else if( $tp->IsEscape("CITY") ) echo $City;
	else if( $tp->IsEscape("STATE") ) echo $State;
	else if( $tp->IsEscape("ZIP") ) echo $Zip;
	else if( $tp->IsEscape("PRICE") ) echo $Price;
	else if( $tp->IsEscape("PHONE") ) echo $Phone;
	else if( $tp->IsEscape("EMAIL") ) echo $Email;
	else if( $tp->IsEscape("STUDENTS") )
	{
	
		// Connect to database
		$db = mysql_connect("localhost", $gblMySqlUser, $gblMySqlPass);
		mysql_select_db($gblMySqlDb, $db);

		// Load questions / answers
		$RowIndex = 0;
		$query = "SELECT * FROM student WHERE paymentid = " . $OrderNumber;
		$result = mysql_query($query, $db);
		while($a = mysql_fetch_array($result))
		{				
			$Record = new PhpSqlRow;
			$Record->SetAsArray($a);
			$RowIndex++;

			$tpElem = new PhpTemplate;				
			for( $tpElem->Start( $tp->GetEscapeArgument() ); $tpElem->NextAndEchoOutput(); ) 
			{
				CheckGlobalEscapes( $tpElem );
				
				if( $tpElem->IsEscape("NAME") ) echo $Record->GetValue("name");
				else if( $tpElem->IsEscape("USERNAME") ) echo $Record->GetValue("username");
				else if( $tpElem->IsEscape("PASSWORD") ) echo $Record->GetValue("password");
				else if( $tpElem->IsEscape("AGE") ) echo $Record->GetValue("age");
	
			}

		}
		
	}
	
}

// Footer
include "includes/footer.php";

?>