<?

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

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

$TotalPrice = 0;
$TotalStudents = 0;

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

	CheckGlobalEscapes( $tp );

	if( $tp->IsEscape("MEMBERS") )
	{
		
		// Connect
		$db = mysql_connect("localhost", $gblMySqlUser, $gblMySqlPass);
		mysql_select_db($gblMySqlDb, $db);
		
		// Retrieve data
		$query = "SELECT * FROM payment WHERE site = '" . $gblSiteName . "' ORDER BY active, createdate DESC";		
		$result = mysql_query($query, $db);
		
		$RowIndex = 0;
						
		// Loop results
		for( $RowIndex = 0; $a = mysql_fetch_array($result); $RowIndex++ )
		{
			$Record = new PhpSqlRow;
			$Record->SetAsArray($a);
					
			if( $Record->GetValue("active") == "1" )
			{
				if( $Record->GetValue("price") > 0 ) $TotalPrice += $Record->GetValue("price");				
				$TotalStudents += $Record->GetValue("students");
				$TotalBooks += $Record->GetValue("bookquantity");
			}

			$tpElem = new PhpTemplate;						
			for( $tpElem->Start( $tp->GetEscapeArgument() ); $tpElem->NextAndEchoOutput(); ) 
			{
			
				CheckGlobalEscapes($tpElem);
				
				if( $tpElem->IsEscape("ID") ) echo $Record->GetValue("id");
				else if( $tpElem->IsEscape("PRICE") ) echo $Record->GetValue("price");
				else if( $tpElem->IsEscape("NAME") ) echo $Record->GetValue("firstname") . " " . $Record->GetValue("lastname");
				else if( $tpElem->IsEscape("DATE") ) echo $Record->GetValue("createdate");
				else if( $tpElem->IsEscape("EMAIL") ) echo $Record->GetValue("email");
				else if( $tpElem->IsEscape("STUDENTS") ) echo $Record->GetValue("students");
				else if( $tpElem->IsEscape("BOOKS") ) echo $Record->GetValue("bookquantity");
				else if( $tpElem->IsEscape("IF-ACTIVE") )
				{
					if( $Record->GetValue("active") == "1" )
						echo $tpElem->GetEscapeArgument();
				}
				else if( $tpElem->IsEscape("IF-NOT-ACTIVE") )
				{
					if( $Record->GetValue("active") != "1" )
						echo $tpElem->GetEscapeArgument();
				}
				else if( $tpElem->IsEscape("IF-ODD-ROW") && ($RowIndex % 2) == 1 ) echo $tpElem->GetEscapeArgument();								
			}
			
		}			
				
	}
	else if( $tp->IsEscape("TOTAL-PRICE") ) echo number_format($TotalPrice, 2, ".", "");
	else if( $tp->IsEscape("TOTAL-STUDENTS") ) echo $TotalStudents;
	else if( $tp->IsEscape("TOTAL-BOOKS") ) echo $TotalBooks;


}

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

?>
