<?

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

$Record = SelectSingleRow("SELECT * FROM ad WHERE site = '" . $gblSiteName . "'");

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

	$ad = request("txtAd");
	
	// If record exists then update, else insert
	if( $Record->GetValue("site") != "" )
		SqlExecute("UPDATE ad SET ad = '" . str_replace("'", "''", $ad) . "' WHERE site = '" . $gblSiteName . "'");
	else
		SqlExecute("INSERT INTO ad (site, ad) VALUES ('" . $gblSiteName . "', ad = '" . str_replace("'", "''", $ad) . "')");
	
	// Return to main page
	header("Location: main.php?" . $GlobalQuery);
	exit;

}
else
{
	$ad = $Record->GetValue("ad");
}

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

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

	CheckGlobalEscapes( $tp );
	if( $tp->IsEscape("AD") )
		echo $ad;

}

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

?>
