<?

////////////////////////////////
$EnforceSession = true;
$bDummyDataTipExclude = true;
include "includes/includes.php";
////////////////////////////////

$MemberID = request("memberid");

if( request("active") != "" )
{

	if( request("active") == "false" )
	{
		SqlExecute("UPDATE payment SET active = 0 WHERE id = " . $MemberID);
		SqlExecute("UPDATE student SET active = 0 WHERE paymentid = " . $MemberID);
	}
	else if( request("active") == "true" )
	{
		SqlExecute("UPDATE payment SET active = 1 WHERE id = " . $MemberID);
		SqlExecute("UPDATE student SET active = 1 WHERE paymentid = " . $MemberID);		
	}

}

// Load data
$Record = SelectSingleRow("SELECT * FROM payment WHERE id = " . $MemberID);
$Students = $Record->GetValue("students");
$Price = $Record->GetValue("price");
$Name = $Record->GetValue("name");
$Address = $Record->GetValue("address");
$City = $Record->GetValue("city");
$State = $Record->GetValue("state");
$Zip = $Record->GetValue("zip");
$Phone = $Record->GetValue("phone");
$Email = $Record->GetValue("email");
$Active = $Record->GetValue("active");
$CreateDate = $Record->GetValue("createdate");
$BookQuantity = $Record->GetValue("bookquantity");

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

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

	CheckGlobalEscapes( $tp );
	
	if( $tp->IsEscape("STUDENTS-AMOUNT") ) echo $Students;
	else if( $tp->IsEscape("PRICE") ) echo $Price;
	else if( $tp->IsEscape("NAME") ) echo $Name;
	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("EMAIL") ) echo $Email;
	else if( $tp->IsEscape("PHONE") ) echo $Phone;
	else if( $tp->IsEscape("CREATEDATE") ) echo $CreateDate;	
	else if( $tp->IsEscape("BOOKS") ) echo $BookQuantity;
	else if( $tp->IsEscape("IF-ACTIVE") )
	{
		if( $Active == "1" )
			$tp->PushArgumentToStream();
	}
	else if( $tp->IsEscape("IF-NOT-ACTIVE") )
	{
		if( $Active != "1" )
			$tp->PushArgumentToStream();
	}	
	else if( $tp->IsEscape("STUDENTS") )
	{
		
		// Connect
		$db = mysql_connect("localhost", $gblMySqlUser, $gblMySqlPass);
		mysql_select_db($gblMySqlDb, $db);
		
		// Retrieve data
		$query = "SELECT * FROM student WHERE paymentid = " . $MemberID . " ORDER BY name";
		$result = mysql_query($query, $db);
		
		$RowIndex = 0;
						
		// Loop results
		for( $RowIndex = 0; $a = mysql_fetch_array($result); $RowIndex++ )
		{
			$Record = new PhpSqlRow;
			$Record->SetAsArray($a);
			
			$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( $tpElem->IsEscape("IF-ODD-ROW") ) 
				{
					if( $RowIndex % 2 == 0 )
						echo $tpElem->GetEscapeArgument();								
				}
			}
			
		}			
				
	}


}

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

?>
