<?

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

$Error = "";

if( request("SUBMIT") == "true" )
{

	// Set data
	$UserName = trim(request("txtUserName"));
	$Password = trim(request("txtPassword"));

	// Validate data
	if( $UserName == "" ) $Error .= "<LI>Please enter your username.</LI>";
	if( $Password == "" ) $Error .= "<LI>Please enter your password.</LI>";
	
	// Validate login
	if( $Error == "" )
	{
		$Record = SelectSingleRow("SELECT id FROM admin WHERE username = '" . SQLEncode($UserName) . "' AND password = '" . SQLEncode($Password) . "' AND site = '" . $gblSiteName . "'");
		if( $Record->GetValue("id") != "" )
		{
			// Log user in
			header("Location: main.php?AdminID=" . $Record->GetValue("id"));
			exit;
		}
		else
			$Error .= "<LI>Invalid login</LI>";
	}
	
}

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

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

	CheckGlobalEscapes( $tp );
	
	if( $tp->IsEscape("IF-ERROR") )
	{
		if( $Error != "" )
			$tp->PushArgumentToStream();
	}
	else if( $tp->IsEscape("ERROR") )
		echo $Error;
	
}

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

?>
