<?

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

$RegID = request("RegID");

$Record = SelectSingleRow("SELECT * FROM payment WHERE id = '" . $RegID . "'");
$OrderNumber = $Record->GetValue("id");
$OrderID = $Record->GetValue("orderid");
$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");
$BookQuantity = $Record->GetValue("bookquantity");

// Spit out the header
include "includes/header.php";

// Begin Template
$tp = new PhpTemplate;
for( $tp->StartFromFile( "templates/verify.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("BOOKS") ) echo $BookQuantity;
	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 = " . $RegID;
		$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");
				else if( $tpElem->IsEscape("DIFFICULTY") ) echo $Record->GetValue("difficulty");
	
			}

		}
		
	}
	else if( $tp->IsEscape("PAYMENT-FORM") )
	{
	
		// Load information
		$ProductName = "Registration";

		// TESTING		
		//$Price = "0.01";

		$tpElem = new PhpTemplate;
		for( $tpElem->StartFromFile( "templates/post_payment.template" ); $tpElem->NextAndEchoOutput(); ) 
		{
			CheckGlobalEscapes( $tpElem );
			if( $tpElem->IsEscape("ITEM-NAME") )
				echo $ProductName;
			else if( $tpElem->IsEscape("ORDER-TYPE") )
				echo "Registration";
			else if( $tpElem->IsEscape("AMOUNT") )
				echo number_format($Price, 2, ".", "");
			else if( $tpElem->IsEscape("FIRST-NAME") )
				echo $FirstName;
			else if( $tpElem->IsEscape("LAST-NAME") )
				echo $LastName;
			else if( $tpElem->IsEscape("ADDRESS") )
				echo $Address;
			else if( $tpElem->IsEscape("CITY") )
				echo $City;
			else if( $tpElem->IsEscape("STATE") )
				echo $State;
			else if( $tpElem->IsEscape("ZIP") )
				echo $Zip;
			else if( $tpElem->IsEscape("EMAIL") )
				echo $Email;
			else if( $tpElem->IsEscape("PHONE") )
				echo $Phone;
			else if( $tpElem->IsEscape("ORDER-ID") )
				echo $OrderID;
			else if( $tpElem->IsEscape("ORDER-NUMBER") )
				echo $OrderNumber;
		}
	
	}
}

// Spit out the footer
include "includes/footer.php";

?>
