<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/


error_reporting (E_ALL ^ E_NOTICE);
//error_reporting (E_ALL);


DBConnect();


// page processing time calculations
list($usec, $sec) = explode(" ",microtime()); 
$StartTime = ((float)$usec + (float)$sec); gs(); 



if ($Settings['iv'] != '3.1') {

	$PageContents = '<div align="center"><br><br><br><br><b>Source file and database versions do not match,<br>possibly due to a software upgrade in progress.<br>Please check back shortly.<br><br><br>If you have uploaded new source files,<br>run the database upgrade script to complete the process.<br><br><br><br><br>Sources version: 3.1<br>Database version: '.$Settings['iv'].'</b></div>';
	
	$PrintableFormat = 'y';
	$FullPageWidth = 'y';
	
	$FontFace = 'Arial';
	$FontSize = '2';
	
	$Colors['BG'] = '#ffffff';
	$Colors['Text'] = '#000000';
	$Colors['Link'] = '#000000';
	$Colors['ALink'] = '#000000';
	$Colors['VLink'] = '#000000';

}
else {


if ($Settings['WindowsQSPatch'] == 'y') {
	$Settings['ScriptName'] .= '?';
}



$CookieName = $Settings['CookieName'];


$BlockLocationDescription[1] = $MsgText[0][7];
$BlockLocationDescription[2] = $MsgText[0][8];
$BlockLocationDescription[3] = $MsgText[0][9];
$BlockLocationDescription[4] = $MsgText[0][10];
$BlockLocationDescription[5] = $MsgText[0][11];
$BlockLocationDescription[6] = $MsgText[0][12];
$BlockLocationDescription[7] = $MsgText[0][13];
$BlockLocationDescription[8] = $MsgText[0][14];




// ========================================================================================
// parse the query string
// ========================================================================================

// build the request_uri variable for systems that don't (grr lol)
if(!isset($_SERVER['REQUEST_URI'])) { 
	if(isset($_SERVER['QUERY_STRING'])) { 
		$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING']; 
	}
	else {
		$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
	}
}

$QS = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];


// preserve the query string for any scripts that wish to use it
$QS = str_replace('.html?', '/', $QS);

// remove any .html from the end of the url
$QS = str_replace('.html', '', $QS);


// break the query string off from the rest of the address
if ($Settings['WindowsQSPatch'] == 'y') {
	list ($LocationPath, $QSData) = explode('?', $QS, 2);
}
else {
	list ($LocationPath, $QSData) = explode('/'.$Settings['ScriptName'], $QS, 2);
}







$BaseURL = $Settings['BaseURL'];
$ImagesURL = $Settings['ImagesURL'];
$IndexURL = $Settings['BaseURL'] . '/' . $Settings['ScriptName'] . '/index.html';
$MainURL = $Settings['BaseURL'] . '/' . $Settings['ScriptName'];

$TemplateImagesURL = $BaseURL . '/templates/' . $Settings['TemplateCode'];




gbi(); // get basic environment information


// if there's something in the query string
if ($QSData != '') {

	$QSData = str_replace('"','',$QSData);
	$QSData = str_replace("'",'',$QSData);
	
	//$QSData = str_replace('%20','',$QSData);
	//$QSData = str_replace(' ','',$QSData);
	$QSData = str_replace('%20',' ',$QSData);

	$QSPieces = explode('/', $QSData);
		
	// [0] = nothing, data starts at [1]
	$Arguments1 = $QSPieces[1];
	$Arguments2 = $QSPieces[2];
	$Arguments3 = $QSPieces[3];
	$Arguments4 = $QSPieces[4];
	$Arguments5 = $QSPieces[5];
	$Arguments6 = $QSPieces[6];
	$Arguments7 = $QSPieces[7];
	$Arguments8 = $QSPieces[8];
	$Arguments9 = $QSPieces[9];
	
	
	if ($Arguments1 == '' || $Arguments1 == 'index') {
		$Arguments1 = 'pages';
		$Arguments2 = 'index';
		
		$QSPieces[1] = 'pages';
		$QSPieces[2] = 'index';
	}
	if ($Arguments1 == 'pages' && $Arguments2 == '') {
		$Arguments2 = 'index';
		
		$QSPieces[1] = 'pages';
		$QSPieces[2] = 'index';
	}
	
}
// if there's nothing in the query string
else {
	// display the index page
	$Arguments1 = 'pages';
	$Arguments2 = 'index';
	
	$QSPieces[1] = 'pages';
	$QSPieces[2] = 'index';
	
	$QSData = '/index';
}


// ========================================================================================

// Set up the timezone offset if not already set from db
if ($Settings['TimezoneOffset'] == '') {
	$Settings['TimezoneOffset'] = (date('Z')/60/60);
	//if (date('I') == 1) {
	//	$Settings['TimezoneOffset']--;
	//}	
}
else {
	if (date('I') == 1) {
		$Settings['TimezoneOffset']++;
	}
}

function GetTimestamp() {
	Global $Settings;
	$ServerToGMT = (date('Z')/60/60);
	$ServerDifference = ($Settings['TimezoneOffset']-$ServerToGMT);
	
	return (time()+($ServerDifference*60*60));
}

// ========================================================================================


	$AlignmentCodes[''] = 'left';
	$AlignmentCodes['L'] = 'left';
	$AlignmentCodes['C'] = 'center';
	$AlignmentCodes['R'] = 'right';


// ========================================================================================
// look for a login data cookie from the browser
// ========================================================================================
$CookieData = $_COOKIE[$CookieName];
if (!get_magic_quotes_gpc()) {
	$CookieData = addslashes($CookieData);
}


$LoggedIn = 'n';
$UserLevel = 0;

// if the cookie exists and isn't empty
if ($CookieData != '' && $CookieData != 'not_logged_in') {

	// split the username and password out
	list ($CookieUsername, $CookiePassword) = split('==', $CookieData, 2);
	
	// if username and password are both not empty
	if ($CookieUsername != '' && $CookiePassword != '') {

		//query the database and validate the input from the login page
		//assign $result to do a lookup up in the database flexcms users table
		//where the username is equal to the database field username, validates password
		$query = "select RecordNumber,Level,Password,DisplayName,SessionLength from `".$Settings['DBPrefix']."core-Users` where Username='$CookieUsername' LIMIT 1";
		$result = mysql_query($query) or die (mysql_error());
		
		// if any rows are returned, the username exists
		if (mysql_num_rows($result) != 0) {
			
			$row = mysql_fetch_array($result);
			// check the password returned from the database against the one in the cookie
			if ($row['Password'] == $CookiePassword ) {
				// passwords match
			    $LoggedIn = 'y';
				
				$UserLevel = $row['Level'];
				$UserNumber = $row['RecordNumber'];
				
				
				if ($row['DisplayName'] != '') {
					$UserDisplayName = addslashes($row['DisplayName']);
				}
				else {
					$UserDisplayName = $CookieUsername;
				}
				
				
				
				if ($Arguments1 != 'count') {
				
					$query2 = "select LastAction,LastLocation from `".$Settings['DBPrefix']."core-RecentActivity` where User='".$CookieUsername."' LIMIT 1";
					$result2 = mysql_query($query2) or die (mysql_error());
					
					// check to see if they're still in the recent activity table
					if (mysql_num_rows($result2) != 0) {
						// if they are, just update their current location and last action
						
						$row2 = mysql_fetch_array($result2);
						if (str_replace('\'', '\\\'', $row2['LastLocation']) != $QSData && $row2['LastLocation'] != $QSData) {
							// if they've gone to a different page
							$query = "update `".$Settings['DBPrefix']."core-RecentActivity` set LastAction='".GetTimestamp()."', LastLocation='".$QSData."', PreviousLocation='".str_replace('\'', '\\\'', $row2['LastLocation'])."' where User='".$CookieUsername."' LIMIT 1";
						}
						else {
							// if they've just refreshed the current page
							$query = "update `".$Settings['DBPrefix']."core-RecentActivity` set LastAction='".GetTimestamp()."' where User='".$CookieUsername."' LIMIT 1";
						}
						$result = mysql_query($query) or die (mysql_error());
					}
					else {
						// if they're not still there, put them back in
					
						$query = "insert into `".$Settings['DBPrefix']."core-RecentActivity` (User,Name,LastLocation,LastAction,SessionLength,UserOrGuest) values ('".$CookieUsername."','".$row['DisplayName']."','".$QSData."','".GetTimestamp()."','10','u')";
						$result = mysql_query($query) or die (mysql_error());
					}
				
					$query = "update `".$Settings['DBPrefix']."core-Users` set LastAction='".GetTimestamp()."' where Username='".$CookieUsername."' LIMIT 1";
					$result = mysql_query($query) or die (mysql_error());
					
				} // end if not just the counter
				
			}
			else{
				// passwords don't match
			 	$LoggedIn = 'n';
			}
		}
		// no rows returned, username doesn't exist
		else {
			$LoggedIn = 'n';
		}
	}
	
}
if ($LoggedIn == 'n' && $Arguments1 != 'count' && ($Arguments1 != 'template_preview' && $Arguments2 != 'count')) {
	$IPAddress = $_SERVER["REMOTE_ADDR"];
	
	$query = "select LastLocation,User from `".$Settings['DBPrefix']."core-RecentActivity` where User='".$IPAddress."' LIMIT 1";
	$result = mysql_query($query) or die (mysql_error());
		
	if (mysql_num_rows($result) != 0) {
		// if any rows are returned, the ip exists
		$row = mysql_fetch_array($result);
		
		if (str_replace('\'', '\\\'', $row['LastLocation']) != $QSData && $row['LastLocation'] != $QSData) {
			// if they've gone to a different page
			$query = "update `".$Settings['DBPrefix']."core-RecentActivity` set LastAction='".GetTimestamp()."', LastLocation='".$QSData."', PreviousLocation='".str_replace('\'', '\\\'', $row['LastLocation'])."' where User='".$IPAddress."' LIMIT 1";
		}
		else {
			// if they've just refreshed the current page
			$query = "update `".$Settings['DBPrefix']."core-RecentActivity` set LastAction='".GetTimestamp()."' where User='".$IPAddress."' LIMIT 1";
		}
		$result = mysql_query($query) or die (mysql_error());
		//print $query;
	}
	else {
		// if no rows are returned, the ip doesn't exist
		$Hostname = @gethostbyaddr($_SERVER["REMOTE_ADDR"]);
		
		$query = "insert into `".$Settings['DBPrefix']."core-RecentActivity` (User,Name,LastLocation,LastAction,SessionLength,UserOrGuest) values ('".$IPAddress."','".$Hostname."','".$QSData."','".GetTimestamp()."','10','g')";
		$result = mysql_query($query) or die (mysql_error());
		
		
		$IPAddressParts = explode('.',$_SERVER["REMOTE_ADDR"]);
			
		$IPquery = "select * from `".$Settings['DBPrefix']."core-ReverseIPs` where IPAddress1='".$IPAddressParts[0]."' and IPAddress2='".$IPAddressParts[1]."' and IPAddress3='".$IPAddressParts[2]."' and IPAddress4='".$IPAddressParts[3]."' and DateCode>='".(GetTimestamp()-(60*60*24*90))."' limit 1";
		$IPresult = mysql_query($IPquery) or die (mysql_error());
		if (mysql_num_rows($IPresult) < 1) {
			
			$IPquery = "select * from `".$Settings['DBPrefix']."core-ReverseIPs` where IPAddress1='".$IPAddressParts[0]."' and IPAddress2='".$IPAddressParts[1]."' and IPAddress3='".$IPAddressParts[2]."' and IPAddress4='".$IPAddressParts[3]."' limit 1";
			$IPresult = mysql_query($IPquery) or die (mysql_error());
			if (mysql_num_rows($IPresult) < 1) {
		
				$IPquery = "insert into `".$Settings['DBPrefix']."core-ReverseIPs` (IPAddress1, IPAddress2, IPAddress3, IPAddress4, Hostname, DateCode) values ('".$IPAddressParts[0]."', '".$IPAddressParts[1]."', '".$IPAddressParts[2]."', '".$IPAddressParts[3]."', '".$Hostname."', '".GetTimestamp()."')";
				$IPresult = mysql_query($IPquery) or die (mysql_error());
				
			}
			else {
			
				$IPquery = "update `".$Settings['DBPrefix']."core-ReverseIPs` set Hostname='".$Hostname."', DateCode='".GetTimestamp()."' where IPAddress1='".$IPAddressParts[0]."' and IPAddress2='".$IPAddressParts[1]."' and IPAddress3='".$IPAddressParts[2]."' and IPAddress4='".$IPAddressParts[3]."' limit 1";
				$IPresult = mysql_query($IPquery) or die (mysql_error());
			
			}
		}
		
		
		//print $query;
	}
	
}

// randomly clean up the recent activity & reverse IPs tables
$RandomNum = rand(0,20);
if (number_format($RandomNum,0) == 10) {
	$query = "delete from `".$Settings['DBPrefix']."core-RecentActivity` where LastAction<".(GetTimestamp()-1800);
	$result = mysql_query($query) or die (mysql_error());
	
	$query = "delete from `".$Settings['DBPrefix']."core-ReverseIPs` where DateCode<".(GetTimestamp()-(60*60*24*90));
	$result = mysql_query($query) or die (mysql_error());
}


// ========================================================================================


// language pack stuff

// remove slashes from language id to avoid any possible attempts to load other code in
$Settings['DefaultLanguage'] = str_replace('/','',$Settings['DefaultLanguage']);

if ($Settings['DefaultLanguage'] == '') {
	$Settings['DefaultLanguage'] = 'english';
}

// see if the file exists
if (file_exists('./languages/inc-core-lang-'.$Settings['DefaultLanguage'].'.php')) {
	$LanguageFileLocated = true;
}
else {
	$Settings['DefaultLanguage'] = 'english';
	// check again for default file
	if (file_exists('./languages/inc-core-lang-'.$Settings['DefaultLanguage'].'.php')) {
		$LanguageFileLocated = true;
	}
	else {
		print 'Error.  Language files could not be loaded.<br><br>Please ensure at least the English FlexCMS language pack is present in the <i>languages</i> folder under the main FlexCMS directory.';
	}
}

if ($LanguageFileLocated == true) {
	include_once('./languages/inc-core-lang-'.$Settings['DefaultLanguage'].'.php');
}


// ========================================================================================


// read in template information

if ($LoggedIn == 'y' && $Arguments1 == 'template_preview' && $Arguments2 != '') {

	ReadPermissions();
	Global $Permissions;
	
		
	if ($Permissions[18] == 'y') {
	
		// remove slashes from template id to avoid any possible attempts to load other code in
		$Arguments2 = str_replace('/','',$Arguments2);
	
		if (file_exists('./templates/'.$Arguments2.'/template.php')) {
			// if the template exists, load it
			include_once('./templates/'.$Arguments2.'/template.php');
			include_once('./templates/'.$Arguments2.'/template_info.php');
			
			
			// re-create some of the system variables
			$IndexURL = $Settings['BaseURL'] . '/' . $Settings['ScriptName'] . '/template_preview/'.$Arguments2.'/pages/index.html';
			$MainURL = $Settings['BaseURL'] . '/' . $Settings['ScriptName'] . '/template_preview/'.$Arguments2;
			$ImagesURL = $Settings['BaseURL'] . '/images';
			$TemplateImagesURL = $Settings['BaseURL'] . '/templates/' . $Arguments2;
			// and, for older scripts and functions which don't use the mainurl variable, adapt the scriptname variable to compensate:
			$Settings['ScriptName'] = $Settings['ScriptName'] . '/template_preview/'.$Arguments2;
			
			
			
			$OverridesArray = explode('%%',$Settings['Overrides']);
			if ($OverridesArray[0] != '') { $FontFace = $OverridesArray[0]; }
			if ($OverridesArray[1] != '') { $FontSize = $OverridesArray[1]; }
			
				
			if ($OverridesArray[15] == '' || $OverridesArray[15] == 1) {
				$TextDecoration[1] = 'underline';
				$TextDecoration[2] = 'underline';
			}
			else if ($OverridesArray[15] == 2) {
				$TextDecoration[1] = 'none';
				$TextDecoration[2] = 'none';
			}
			else if ($OverridesArray[15] == 3) {
				$TextDecoration[1] = 'underline';
				$TextDecoration[2] = 'none';
			}
			else if ($OverridesArray[15] == 4) {
				$TextDecoration[1] = 'none';
				$TextDecoration[2] = 'underline';
			}
	
	
			if ($OverridesArray[16] == '' || $OverridesArray[16] == 1) {
				$TextDecoration[3] = 'underline';
				$TextDecoration[4] = 'underline';
			}
			else if ($OverridesArray[16] == 2) {
				$TextDecoration[3] = 'none';
				$TextDecoration[4] = 'none';
			}
			else if ($OverridesArray[16] == 3) {
				$TextDecoration[3] = 'underline';
				$TextDecoration[4] = 'none';
			}
			else if ($OverridesArray[16] == 4) {
				$TextDecoration[3] = 'none';
				$TextDecoration[4] = 'underline';
			}
			
			
			
			// reassign the variables that have been displaced by the template preview function, 
			// so that all pages and functions hopefully function normally with the other template
			$Arguments1 = $Arguments3;
			$Arguments2 = $Arguments4;
			$Arguments3 = $Arguments5;
			$Arguments4 = $Arguments6;
			$Arguments5 = $Arguments7;
			$Arguments6 = $Arguments8;
			$Arguments7 = $Arguments9;
			$Arguments8 = $QSPieces[10];
			$Arguments9 = $QSPieces[11];
			
			$QSPieces[1] = $QSPieces[3];
			$QSPieces[2] = $QSPieces[4];
			$QSPieces[3] = $QSPieces[5];
			$QSPieces[4] = $QSPieces[6];
			$QSPieces[5] = $QSPieces[7];
			$QSPieces[6] = $QSPieces[8];
			$QSPieces[7] = $QSPieces[9];
			$QSPieces[8] = $QSPieces[10];
			$QSPieces[9] = $QSPieces[11];
			
			
			if ($Arguments1 == '' || $Arguments1 == 'index') {
				$Arguments1 = 'pages';
				$Arguments2 = 'index';
				
				$QSPieces[1] = 'pages';
				$QSPieces[2] = 'index';
			}
			
			
			$TemplatePreview = 'y';
		}
				
	}

}

if ($TemplatePreview != 'y') {

	if (file_exists('./templates/'.$Settings['TemplateCode'].'/template.php')) {
		// if the template referenced in the database exists, load it
		include_once('./templates/'.$Settings['TemplateCode'].'/template.php');
	}
	else {
		// otherwise, load the default so they still get a readable and functional site
		$Settings['TemplateCode'] = 'fine_lines-navy_white';
		include_once('./templates/'.$Settings['TemplateCode'].'/template.php');
	}
	
	// set the block colors if they aren't already
	if ($Colors['BText'] == '') { $Colors['BText'] = $Colors['Text']; }
	if ($Colors['BLink'] == '') { $Colors['BLink'] = $Colors['Link']; }
	if ($Colors['BVLink'] == '') { $Colors['BVLink'] = $Colors['VLink']; }
	if ($Colors['BALink'] == '') { $Colors['BALink'] = $Colors['ALink']; }
	
	$OverridesArray = explode('%%',$Settings['Overrides']);
	// fontface, fontsize, bgcolor, text, link, vlink, alink, btext, blink, bvlink, balink
	if ($OverridesArray[0] != '') { $FontFace = $OverridesArray[0]; }
	if ($OverridesArray[1] != '') { $FontSize = $OverridesArray[1]; }
	if ($OverridesArray[2] != '') { $Colors['BG'] = $OverridesArray[2]; }
	if ($OverridesArray[3] != '') { $Colors['Text'] = $OverridesArray[3]; }
	if ($OverridesArray[4] != '') { $Colors['Link'] = $OverridesArray[4]; }
	if ($OverridesArray[5] != '') { $Colors['VLink'] = $OverridesArray[5]; }
	if ($OverridesArray[6] != '') { $Colors['ALink'] = $OverridesArray[6]; }
	if ($OverridesArray[7] != '') { $Colors['BText'] = $OverridesArray[7]; }
	if ($OverridesArray[8] != '') { $Colors['BLink'] = $OverridesArray[8]; }
	if ($OverridesArray[9] != '') { $Colors['BVLink'] = $OverridesArray[9]; }
	if ($OverridesArray[10] != '') { $Colors['BALink'] = $OverridesArray[10]; }
	if ($OverridesArray[11] != '') { $Colors['BBG'] = $OverridesArray[11]; }
	
	if ($OverridesArray[12] != '') { $FormStyle = $OverridesArray[12]; }
	
	if ($OverridesArray[13] != '') { $Colors['LinkHover'] = $OverridesArray[13]; }
	if ($OverridesArray[14] != '') { $Colors['BLinkHover'] = $OverridesArray[14]; }
	
	
	if ($OverridesArray[15] == '' || $OverridesArray[15] == 1) {
		$TextDecoration[1] = 'underline';
		$TextDecoration[2] = 'underline';
	}
	else if ($OverridesArray[15] == 2) {
		$TextDecoration[1] = 'none';
		$TextDecoration[2] = 'none';
	}
	else if ($OverridesArray[15] == 3) {
		$TextDecoration[1] = 'underline';
		$TextDecoration[2] = 'none';
	}
	else if ($OverridesArray[15] == 4) {
		$TextDecoration[1] = 'none';
		$TextDecoration[2] = 'underline';
	}
	
	
	if ($OverridesArray[16] == '' || $OverridesArray[16] == 1) {
		$TextDecoration[3] = 'underline';
		$TextDecoration[4] = 'underline';
	}
	else if ($OverridesArray[16] == 2) {
		$TextDecoration[3] = 'none';
		$TextDecoration[4] = 'none';
	}
	else if ($OverridesArray[16] == 3) {
		$TextDecoration[3] = 'underline';
		$TextDecoration[4] = 'none';
	}
	else if ($OverridesArray[16] == 4) {
		$TextDecoration[3] = 'none';
		$TextDecoration[4] = 'underline';
	}
	


	include_once('./templates/'.$Settings['TemplateCode'].'/template_info.php');
	
} // end if not loading a different template for preview purposes



// =======================================================================================================================


// ========================================================================================
// Figure out what to write to the page
// ========================================================================================


if ($Arguments1 == 'printable') {
	
	$Arguments1 = $Arguments2;
	$Arguments2 = $Arguments3;
	$Arguments3 = $Arguments4;
	$Arguments4 = $Arguments5;
	$Arguments5 = $Arguments6;
	$Arguments6 = $Arguments7;
	$Arguments7 = $Arguments8;
	$Arguments8 = $Arguments9;
	$Arguments9 = $QSPieces[10];
	
	$QSPieces[1] = $QSPieces[2];
	$QSPieces[2] = $QSPieces[3];
	$QSPieces[3] = $QSPieces[4];
	$QSPieces[4] = $QSPieces[5];
	$QSPieces[5] = $QSPieces[6];
	$QSPieces[6] = $QSPieces[7];
	$QSPieces[7] = $QSPieces[8];
	$QSPieces[8] = $QSPieces[9];
	$QSPieces[9] = $QSPieces[10];
				

	if ($Arguments1 == '' || $Arguments1 == 'index') {
		$Arguments1 = 'pages';
		$Arguments2 = 'index';
		
		$QSPieces[1] = 'pages';
		$QSPieces[2] = 'index';
	}
	
	
	$RedirectString = $Arguments1 . '/' . $Arguments2 . '/' . $Arguments3 . '/' . $Arguments4 . '/' . $Arguments5 . '/' . $Arguments6 . '/' . $Arguments7 . '/' . $Arguments8 . '/' . $Arguments9;
	
	$RedirectString = str_replace('//','',$RedirectString);
	
	if (substr($RedirectString,strlen($RedirectString)-1,1) == '/') {
		$RedirectString = substr($RedirectString,0,strlen($RedirectString)-1);
	}
	
	if ($LoggedIn == 'y' || strpos($_SERVER['HTTP_REFERER'],$RedirectString) !== false) {
		
		$Colors['BG'] = '#ffffff';
		$Colors['Text'] = '#000000';
		$Colors['Link'] = '#000000';
		$Colors['ALink'] = '#000000';
		$Colors['VLink'] = '#000000';
		$Colors['LinkHover'] = '#000000';
		
		$Colors['CLBorder'] = '#000000';			// main calendar border
		$Colors['CLTitleBG'] = '#ffffff';			// top title (month and year, next/prev month links) background
		$Colors['CLTitleText'] = '#000000';			// top title text
		$Colors['CLDaysBG'] = '#ffffff';			// day names background
		$Colors['CLDaysText'] = '#000000';			// day names text
		$Colors['CLCalDaysBG'] = '#ffffff';			// grid squares that are a calendar day
		$Colors['CLFillerDaysBG'] = '#eeeeee';		// grid squares that are fillers (not a day)
		$Colors['CLCurrentDayBG'] = '#dddddd';		// grid square that is today's date
		$Colors['CLDayNumbersText'] = '#000000';	// day numbers text
		$Colors['CLEventTitleText'] = '#000000';	// event title link text
		$Colors['CLEventDetailsText'] = '#000000';	// event details text
		$Colors['CLContentBG'] = '#ffffff';			// content pages bg
		
		
		$Colors['MBBorder'] = '#000000';			// main border
		$Colors['MBBG'] = '#ffffff';				// main background
		$Colors['MBAlternateBG'] = '#f5f5f5';		// alternate background color
		$Colors['MBSpacerLine'] = '#555555';		// spacer line between categories and messages in a thread
		$Colors['MBHeadingText'] = '#000000';		// top headings text
		$Colors['MBHeadingBG'] = '#eeeeee';			// top headings background
		$Colors['MBText'] = '#000000';				// main text
		$Colors['MBQCBorder'] = '#000000';			// quotes and code sections border
		$Colors['MBQCBG'] = '#eeeeee';				// quotes and code sections background
		$Colors['MBQCText'] = '#000000';			// quotes and code sections text
	
		$FormStyle = 'background-color: #ffffff; color: #000000;';
	
		$PrintableFormat = 'y';
	}

}



if ($Arguments1 != '') {

	if ($Arguments1 == 'admin') {
				
		// cr
		$PMP['blocks'] = 'blocks';
		$MFF['blocks'] = 'core';
		$PMP['blocks-edit'] = 'blocks-edit';
		$MFF['blocks-edit'] = 'core';
		$PMP['blocks-edit-save'] = 'blocks-edit-save';
		$MFF['blocks-edit-save'] = 'core';
		$PMP['blocks-new-save'] = 'blocks-new-save';
		$MFF['blocks-new-save'] = 'core';
		$PMP['blocks-priority'] = 'blocks-priority';
		$MFF['blocks-priority'] = 'core';
		$PMP['blocks-delete'] = 'blocks-delete';
		$MFF['blocks-delete'] = 'core';
		$PMP['blocks-delete-confirm'] = 'blocks-delete-confirm';
		$MFF['blocks-delete-confirm'] = 'core';
		
		
		$PMP['pages'] = 'pages';
		$MFF['pages'] = 'core';
		$PMP['pages-edit'] = 'pages-edit';
		$MFF['pages-edit'] = 'core';
		$PMP['pages-edit-ebc'] = 'pages-edit-ebc';
		$MFF['pages-edit-ebc'] = 'core';
		$PMP['pages-edit-save'] = 'pages-edit-save';
		$MFF['pages-edit-save'] = 'core';
		$PMP['pages-new-save'] = 'pages-new-save';
		$MFF['pages-new-save'] = 'core';
		$PMP['pages-delete'] = 'pages-delete';
		$MFF['pages-delete'] = 'core';
		$PMP['pages-delete-confirm'] = 'pages-delete-confirm';
		$MFF['pages-delete-confirm'] = 'core';
		
		$PMP['pages-newcat'] = 'pages-newcat';
		$MFF['pages-newcat'] = 'core';
		$PMP['pages-catedit'] = 'pages-catedit';
		$MFF['pages-catedit'] = 'core';
		$PMP['pages-catedit-save'] = 'pages-catedit-save';
		$MFF['pages-catedit-save'] = 'core';
		
		$PMP['preferences'] = 'preferences';
		$MFF['preferences'] = 'core';
		$PMP['preferences-save'] = 'preferences-save';
		$MFF['preferences-save'] = 'core';
		
		$PMP['templates'] = 'templates';
		$MFF['templates'] = 'core';
		$PMP['templates-save'] = 'templates-save';
		$MFF['templates-save'] = 'core';
		
		$PMP['settings'] = 'settings';
		$MFF['settings'] = 'core';
		$PMP['settings-save'] = 'settings-save';
		$MFF['settings-save'] = 'core';
		
		$PMP['settings-baseurl'] = 'settings-baseurl';
		$MFF['settings-baseurl'] = 'core';
		$PMP['settings-baseurl2'] = 'settings-baseurl2';
		$MFF['settings-baseurl2'] = 'core';
		$PMP['settings-baseurl3'] = 'settings-baseurl3';
		$MFF['settings-baseurl3'] = 'core';
		$PMP['settings-baseurl4'] = 'settings-baseurl4';
		$MFF['settings-baseurl4'] = 'core';
		$PMP['settings-baseurl5'] = 'settings-baseurl5';
		$MFF['settings-baseurl5'] = 'core';
		
		
		//$PMP['sync_keys'] = 'sync_keys';
		//$MFF['sync_keys'] = 'core';
		//$PMP['sync_keys_complete'] = 'sync_keys_complete';
		//$MFF['sync_keys_complete'] = 'core';
		
				
		$PMP['permissions'] = 'permissions';
		$MFF['permissions'] = 'core';
		$PMP['permissions-save'] = 'permissions-save';
		$MFF['permissions-save'] = 'core';
		
		$PMP['levels'] = 'levels';
		$MFF['levels'] = 'core';
		$PMP['levels-save'] = 'levels-save';
		$MFF['levels-save'] = 'core';
		$PMP['levels-new-save'] = 'levels-new-save';
		$MFF['levels-new-save'] = 'core';
		
		$PMP['registration'] = 'registration';
		$MFF['registration'] = 'core';
		$PMP['registration-save'] = 'registration-save';
		$MFF['registration-save'] = 'core';
		
		
		$PMP['countries'] = 'countries';
		$MFF['countries'] = 'core';
		$PMP['countries-save'] = 'countries-save';
		$MFF['countries-save'] = 'core';
		
		$PMP['countries-edit'] = 'countries-edit';
		$MFF['countries-edit'] = 'core';
		$PMP['countries-edit-save'] = 'countries-edit-save';
		$MFF['countries-edit-save'] = 'core';
		
		$PMP['countries-sp-edit'] = 'countries-sp-edit';
		$MFF['countries-sp-edit'] = 'core';
		$PMP['countries-sp-edit-save'] = 'countries-sp-edit-save';
		$MFF['countries-sp-edit-save'] = 'core';
		$PMP['countries-sp-new'] = 'countries-sp-new';
		$MFF['countries-sp-new'] = 'core';
		
		
		
		
		
		$PMP['info'] = 'info';
		$MFF['info'] = 'core';
		
		$PMP['where'] = 'where';
		$MFF['where'] = 'core';
		
		$PMP['users'] = 'users';
		$MFF['users'] = 'core';
		
		
		$PMP['modules'] = 'modules';
		$MFF['modules'] = 'core';
		$PMP['modules-install'] = 'modules-install';
		$MFF['modules-install'] = 'core';
		$PMP['modules-uninstall'] = 'modules-uninstall';
		$MFF['modules-uninstall'] = 'core';
		
		
		
		$PMP['smilies'] = 'smilies';
		$MFF['smilies'] = 'core';
		
		$PMP['smilies-order'] = 'smilies-order';
		$MFF['smilies-order'] = 'core';
		
		$PMP['smilies-edit'] = 'smilies-edit';
		$MFF['smilies-edit'] = 'core';
		$PMP['smilies-editsave'] = 'smilies-editsave';
		$MFF['smilies-editsave'] = 'core';
		
		$PMP['smilies-delete'] = 'smilies-delete';
		$MFF['smilies-delete'] = 'core';
		$PMP['smilies-deleteconfirm'] = 'smilies-deleteconfirm';
		$MFF['smilies-deleteconfirm'] = 'core';
		
		$PMP['smilies-new'] = 'smilies-new';
		$MFF['smilies-new'] = 'core';
		
				
		
		$PMP['images'] = 'images';
		$MFF['images'] = 'core';
		
		$PMP['images_upload'] = 'images_upload';
		$MFF['images_upload'] = 'core';
		
		$PMP['images_delete'] = 'images_delete';
		$MFF['images_delete'] = 'core';
		$PMP['images_delete_confirm'] = 'images_delete_confirm';
		$MFF['images_delete_confirm'] = 'core';
		
		
		
		$PMP['backup'] = 'backup';
		$MFF['backup'] = 'core';
		
		$PMP['backup-create'] = 'backup-create';
		$MFF['backup-create'] = 'core';
		
		$PMP['backup-download'] = 'backup-download';
		$MFF['backup-download'] = 'core';
		
		
		$PMP['backup-restore'] = 'backup-restore';
		$MFF['backup-restore'] = 'core';
		
		$PMP['backup-restore-confirm'] = 'backup-restore-confirm';
		$MFF['backup-restore-confirm'] = 'core';
		$PMP['backup-restore-confirm2'] = 'backup-restore-confirm2';
		$MFF['backup-restore-confirm2'] = 'core';
		
		
		$PMP['maintenancemode'] = 'maintenancemode';
		$MFF['maintenancemode'] = 'core';
		
		$PMP['maintenancemode-save'] = 'maintenancemode-save';
		$MFF['maintenancemode-save'] = 'core';
		
		
		
		$PMP['filemanager'] = 'filemanager';
		$MFF['filemanager'] = 'core';
		
		$PMP['filemanager-functions'] = 'filemanager-functions';
		$MFF['filemanager-functions'] = 'core';
		
				
		
		// calendar
		if ($IM['cl'] == 'y') {
				
			$PMP['calendar_colors'] = 'colors';
			$MFF['calendar_colors'] = 'cl';
			
			$PMP['calendar_colors-save'] = 'colors-save';
			$MFF['calendar_colors-save'] = 'cl';
			
			
			$PMP['calendar'] = 'events';
			$MFF['calendar'] = 'cl';
			
			$PMP['calendar-new_event'] = 'events-new';
			$MFF['calendar-new_event'] = 'cl';
			
			$PMP['calendar-edit'] = 'events-edit';
			$MFF['calendar-edit'] = 'cl';
			
			$PMP['calendar-save'] = 'events-edit-save';
			$MFF['calendar-save'] = 'cl';
			
			$PMP['calendar-delete'] = 'events-delete';
			$MFF['calendar-delete'] = 'cl';
			
			$PMP['calendar-confirmdelete'] = 'events-delete-confirm';
			$MFF['calendar-confirmdelete'] = 'cl';
			
			
			$PMP['calendar_prefs'] = 'prefs';
			$MFF['calendar_prefs'] = 'cl';
		
			$PMP['calendar_prefs-save'] = 'prefs-save';
			$MFF['calendar_prefs-save'] = 'cl';
		
		}
		
		
		// forum
		if ($IM['mb'] == 'y') {	
		
			$PMP['messageboard_colors'] = 'colors';
			$MFF['messageboard_colors'] = 'mb';
				
			$PMP['messageboard_colors-save'] = 'colors-save';
			$MFF['messageboard_colors-save'] = 'mb';
			
						
			$PMP['messageboard_boardsandcats'] = 'boardsandcats';
			$MFF['messageboard_boardsandcats'] = 'mb';
			
			$PMP['messageboard_catorder'] = 'catorder';
			$MFF['messageboard_catorder'] = 'mb';
			$PMP['messageboard_boardorder'] = 'boardorder';
			$MFF['messageboard_boardorder'] = 'mb';
			
			
			$PMP['messageboard_catedit'] = 'catedit';
			$MFF['messageboard_catedit'] = 'mb';
			$PMP['messageboard_cateditsave'] = 'cateditsave';
			$MFF['messageboard_cateditsave'] = 'mb';
			
			$PMP['messageboard_catdelete'] = 'catdelete';
			$MFF['messageboard_catdelete'] = 'mb';
			$PMP['messageboard_catdeleteconfirm'] = 'catdeleteconfirm';
			$MFF['messageboard_catdeleteconfirm'] = 'mb';
			
			
			$PMP['messageboard_boardedit'] = 'boardedit';
			$MFF['messageboard_boardedit'] = 'mb';
			$PMP['messageboard_boardeditsave'] = 'boardeditsave';
			$MFF['messageboard_boardeditsave'] = 'mb';
		
			$PMP['messageboard_boarddelete'] = 'boarddelete';
			$MFF['messageboard_boarddelete'] = 'mb';
			$PMP['messageboard_boarddeleteconfirm'] = 'boarddeleteconfirm';
			$MFF['messageboard_boarddeleteconfirm'] = 'mb';
		
		
			$PMP['messageboard_newboard'] = 'newboard';
			$MFF['messageboard_newboard'] = 'mb';
		
			$PMP['messageboard_newcategory'] = 'newcategory';
			$MFF['messageboard_newcategory'] = 'mb';
		
		
			$PMP['messageboard_prefs'] = 'prefs';
			$MFF['messageboard_prefs'] = 'mb';

			$PMP['messageboard_prefssave'] = 'prefssave';
			$MFF['messageboard_prefssave'] = 'mb';
		
		}
				
		// photos
		if ($IM['pg'] == 'y') {	
				
			$PMP['photos'] = 'photos';
			$MFF['photos'] = 'pg';
			
			$PMP['photos_upload'] = 'photos_upload';
			$MFF['photos_upload'] = 'pg';
			
			$PMP['photos_edit'] = 'photos_edit';
			$MFF['photos_edit'] = 'pg';
			$PMP['photos_edit_save'] = 'photos_edit_save';
			$MFF['photos_edit_save'] = 'pg';
			
			$PMP['photos_delete'] = 'photos_delete';
			$MFF['photos_delete'] = 'pg';
			$PMP['photos_delete_confirm'] = 'photos_delete_confirm';
			$MFF['photos_delete_confirm'] = 'pg';
			
						
			$PMP['photos_galleries'] = 'photos_galleries';
			$MFF['photos_galleries'] = 'pg';
			
			$PMP['photos_new_gallery'] = 'photos_new_gallery';
			$MFF['photos_new_gallery'] = 'pg';
			
			$PMP['photos_gallery_edit'] = 'photos_gallery_edit';
			$MFF['photos_gallery_edit'] = 'pg';
			$PMP['photos_gallery_edit_save'] = 'photos_gallery_edit_save';
			$MFF['photos_gallery_edit_save'] = 'pg';
			
			$PMP['photos_gallery_delete'] = 'photos_gallery_delete';
			$MFF['photos_gallery_delete'] = 'pg';
			$PMP['photos_gallery_delete_confirm'] = 'photos_gallery_delete_confirm';
			$MFF['photos_gallery_delete_confirm'] = 'pg';
			
			
			$PMP['photos_prefs'] = 'photos_prefs';
			$MFF['photos_prefs'] = 'pg';
			$PMP['photos_prefs_save'] = 'photos_prefs_save';
			$MFF['photos_prefs_save'] = 'pg';
				
		}
		
		// counter/stats
		if ($IM['cs'] == 'y') {	
				
			$PMP['stats'] = 'stats';
			$MFF['stats'] = 'cs';
						
			$PMP['stats_pages'] = 'stats_pages';
			$MFF['stats_pages'] = 'cs';
			
			$PMP['stats_pageviews'] = 'stats_pageviews';
			$MFF['stats_pageviews'] = 'cs';
			
			$PMP['stats_referrals'] = 'stats_referrals';
			$MFF['stats_referrals'] = 'cs';
			
			
			$PMP['stats_referrals_sites'] = 'stats_referrals_sites';
			$MFF['stats_referrals_sites'] = 'cs';
			
			
			$PMP['stats_users'] = 'stats_users';
			$MFF['stats_users'] = 'cs';
			
			$PMP['stats_systems'] = 'stats_systems';
			$MFF['stats_systems'] = 'cs';
			
			
			$PMP['stats_prefs'] = 'stats_prefs';
			$MFF['stats_prefs'] = 'cs';
			$PMP['stats_prefs_save'] = 'stats_prefs_save';
			$MFF['stats_prefs_save'] = 'cs';
			
			$PMP['stats_sessions'] = 'stats_sessions';
			$MFF['stats_sessions'] = 'cs';
			
			$PMP['stats_sessions_yesterday'] = 'stats_sessions_yesterday';
			$MFF['stats_sessions_yesterday'] = 'cs';
									
		}
		
		// newsletter
		if ($IM['nl'] == 'y') {	
							
			$PMP['newsletter_compose'] = 'newsletter_compose';
			$MFF['newsletter_compose'] = 'nl';
			$PMP['newsletter_send'] = 'newsletter_send';
			$MFF['newsletter_send'] = 'nl';
			$PMP['newsletter_sendfinal'] = 'newsletter_sendfinal';
			$MFF['newsletter_sendfinal'] = 'nl';
			
			$PMP['newsletter_subscribers'] = 'newsletter_subscribers';
			$MFF['newsletter_subscribers'] = 'nl';
			
			$PMP['newsletter_subscribers_add'] = 'newsletter_subscribers_add';
			$MFF['newsletter_subscribers_add'] = 'nl';
			$PMP['newsletter_subscribers_add_save'] = 'newsletter_subscribers_add_save';
			$MFF['newsletter_subscribers_add_save'] = 'nl';
			
			$PMP['newsletter_subscriber_delete'] = 'newsletter_subscriber_delete';
			$MFF['newsletter_subscriber_delete'] = 'nl';
			$PMP['newsletter_subscriber_delete_confirm'] = 'newsletter_subscriber_delete_confirm';
			$MFF['newsletter_subscriber_delete_confirm'] = 'nl';
			
			$PMP['newsletter_subscriber_delete_bulk'] = 'newsletter_subscriber_delete_bulk';
			$MFF['newsletter_subscriber_delete_bulk'] = 'nl';
			$PMP['newsletter_subscriber_delete_bulk_confirm'] = 'newsletter_subscriber_delete_bulk_confirm';
			$MFF['newsletter_subscriber_delete_bulk_confirm'] = 'nl';
			
			$PMP['newsletter_unconfirmed_delete'] = 'newsletter_unconfirmed_delete';
			$MFF['newsletter_unconfirmed_delete'] = 'nl';
			
		
			$PMP['newsletter_archived'] = 'newsletter_archived';
			$MFF['newsletter_archived'] = 'nl';
			
			$PMP['newsletter_archived_edit'] = 'newsletter_archived_edit';
			$MFF['newsletter_archived_edit'] = 'nl';
			$PMP['newsletter_archived_edit_save'] = 'newsletter_archived_edit_save';
			$MFF['newsletter_archived_edit_save'] = 'nl';
			
			$PMP['newsletter_archived_delete'] = 'newsletter_archived_delete';
			$MFF['newsletter_archived_delete'] = 'nl';
			$PMP['newsletter_archived_delete_confirm'] = 'newsletter_archived_delete_confirm';
			$MFF['newsletter_archived_delete_confirm'] = 'nl';
			
			
			$PMP['newsletter_prefs'] = 'newsletter_prefs';
			$MFF['newsletter_prefs'] = 'nl';
			$PMP['newsletter_prefs_save'] = 'newsletter_prefs_save';
			$MFF['newsletter_prefs_save'] = 'nl';
									
		}
		
		// guestbook
		if ($IM['gb'] == 'y') {	
				
			$PMP['guestbook_manage'] = 'guestbook_manage';
			$MFF['guestbook_manage'] = 'gb';

			$PMP['guestbook_approve'] = 'guestbook_approve';
			$MFF['guestbook_approve'] = 'gb';
			
			$PMP['guestbook_edit'] = 'guestbook_edit';
			$MFF['guestbook_edit'] = 'gb';
			$PMP['guestbook_edit_save'] = 'guestbook_edit_save';
			$MFF['guestbook_edit_save'] = 'gb';
			
			$PMP['guestbook_delete'] = 'guestbook_delete';
			$MFF['guestbook_delete'] = 'gb';
			$PMP['guestbook_delete_confirm'] = 'guestbook_delete_confirm';
			$MFF['guestbook_delete_confirm'] = 'gb';
			
			
			$PMP['guestbook_prefs'] = 'guestbook_prefs';
			$MFF['guestbook_prefs'] = 'gb';
			$PMP['guestbook_prefs_save'] = 'guestbook_prefs_save';
			$MFF['guestbook_prefs_save'] = 'gb';
							
		}
		
		// news/articles
		if ($IM['na'] == 'y') {	
				
			$PMP['articles'] = 'articles';
			$MFF['articles'] = 'na';
			
			$PMP['articles-edit'] = 'articles-edit';
			$MFF['articles-edit'] = 'na';
			$PMP['articles-edit-save'] = 'articles-edit-save';
			$MFF['articles-edit-save'] = 'na';			
			
			$PMP['articles-new-save'] = 'articles-new-save';
			$MFF['articles-new-save'] = 'na';
			
			
			$PMP['articles-cat-new-save'] = 'articles-cat-new-save';
			$MFF['articles-cat-new-save'] = 'na';
			
			$PMP['articles-cat-edit'] = 'articles-cat-edit';
			$MFF['articles-cat-edit'] = 'na';
			$PMP['articles-cat-edit-save'] = 'articles-cat-edit-save';
			$MFF['articles-cat-edit-save'] = 'na';
			
			
			$PMP['articles-generate'] = 'articles-generate';
			$MFF['articles-generate'] = 'na';
			$PMP['articles-generate-submit'] = 'articles-generate-submit';
			$MFF['articles-generate-submit'] = 'na';
			
			
			$PMP['articles-prefs'] = 'articles-prefs';
			$MFF['articles-prefs'] = 'na';
			$PMP['articles-prefs-save'] = 'articles-prefs-save';
			$MFF['articles-prefs-save'] = 'na';
				
		}
		
		// links
		if ($IM['lm'] == 'y') {	
				
			$PMP['links'] = 'links';
			$MFF['links'] = 'lm';
			
			$PMP['links-new'] = 'links-new';
			$MFF['links-new'] = 'lm';
			
			$PMP['links-edit'] = 'links-edit';
			$MFF['links-edit'] = 'lm';
			
			$PMP['links-edit-save'] = 'links-edit-save';
			$MFF['links-edit-save'] = 'lm';
			
			$PMP['links-newcat'] = 'links-newcat';
			$MFF['links-newcat'] = 'lm';
			
			$PMP['links-catedit'] = 'links-catedit';
			$MFF['links-catedit'] = 'lm';
			
			$PMP['links-catedit-save'] = 'links-catedit-save';
			$MFF['links-catedit-save'] = 'lm';
			
			$PMP['links-prefs'] = 'links-prefs';
			$MFF['links-prefs'] = 'lm';
			
			$PMP['links-prefs-save'] = 'links-prefs-save';
			$MFF['links-prefs-save'] = 'lm';
			
		}
		
		// ecommerce
		if ($IM['ec'] == 'y') {	
				
			$PMP['store'] = 'store';
			$MFF['store'] = 'ec';
			
			
			$PMP['store-categories'] = 'store-categories';
			$MFF['store-categories'] = 'ec';
			
			$PMP['store-categories_edit'] = 'store-categories_edit';
			$MFF['store-categories_edit'] = 'ec';
			
			$PMP['store-categories_edit_save'] = 'store-categories_edit_save';
			$MFF['store-categories_edit_save'] = 'ec';
									
			$PMP['store-categories_new'] = 'store-categories_new';
			$MFF['store-categories_new'] = 'ec';
			
			
			$PMP['store-products'] = 'store-products';
			$MFF['store-products'] = 'ec';
			
			$PMP['store-products_edit'] = 'store-products_edit';
			$MFF['store-products_edit'] = 'ec';
			
			$PMP['store-products_edit_save'] = 'store-products_edit_save';
			$MFF['store-products_edit_save'] = 'ec';
			
			$PMP['store-products_new'] = 'store-products_new';
			$MFF['store-products_new'] = 'ec';
			
			$PMP['store-products_new_clone'] = 'store-products_new_clone';
			$MFF['store-products_new_clone'] = 'ec';
			
			$PMP['store-products_new_clone_save'] = 'store-products_new_clone_save';
			$MFF['store-products_new_clone_save'] = 'ec';
			
			
			$PMP['store-products_new_items_bulk'] = 'store-products_new_items_bulk';
			$MFF['store-products_new_items_bulk'] = 'ec';
						
			$PMP['store-products_new_items_bulk_save'] = 'store-products_new_items_bulk_save';
			$MFF['store-products_new_items_bulk_save'] = 'ec';
			
			
			
			$PMP['store-items_edit'] = 'store-items_edit';
			$MFF['store-items_edit'] = 'ec';
			
			$PMP['store-items_edit_save'] = 'store-items_edit_save';
			$MFF['store-items_edit_save'] = 'ec';
			
			$PMP['store-items_new'] = 'store-items_new';
			$MFF['store-items_new'] = 'ec';
			
			$PMP['store-items_new_save'] = 'store-items_new_save';
			$MFF['store-items_new_save'] = 'ec';
			
			
			
			$PMP['store-shipping'] = 'store-shipping';
			$MFF['store-shipping'] = 'ec';
			
			$PMP['store-shipping-new-save'] = 'store-shipping-new-save';
			$MFF['store-shipping-new-save'] = 'ec';
			
			$PMP['store-shipping-edit'] = 'store-shipping-edit';
			$MFF['store-shipping-edit'] = 'ec';
			
			$PMP['store-shipping-edit-save'] = 'store-shipping-edit-save';
			$MFF['store-shipping-edit-save'] = 'ec';
			
			
			$PMP['store-taxes'] = 'store-taxes';
			$MFF['store-taxes'] = 'ec';
			
			$PMP['store-taxes-new'] = 'store-taxes-new';
			$MFF['store-taxes-new'] = 'ec';
			
			$PMP['store-taxes-new-save'] = 'store-taxes-new-save';
			$MFF['store-taxes-new-save'] = 'ec';
			
			$PMP['store-taxes-edit'] = 'store-taxes-edit';
			$MFF['store-taxes-edit'] = 'ec';
			
			$PMP['store-taxes-edit-save'] = 'store-taxes-edit-save';
			$MFF['store-taxes-edit-save'] = 'ec';
			
			
			$PMP['store-reports'] = 'store-reports';
			$MFF['store-reports'] = 'ec';
			
			$PMP['store-inventory'] = 'store-inventory';
			$MFF['store-inventory'] = 'ec';
			
			
			$PMP['store-orders'] = 'store-orders';
			$MFF['store-orders'] = 'ec';
			
			$PMP['store-orderdetails'] = 'store-orderdetails';
			$MFF['store-orderdetails'] = 'ec';
			
			$PMP['store-orders-modify'] = 'store-orders-modify';
			$MFF['store-orders-modify'] = 'ec';
			
			$PMP['store-orders-modify-save'] = 'store-orders-modify-save';
			$MFF['store-orders-modify-save'] = 'ec';
			
			$PMP['store-deleteorder'] = 'store-deleteorder';
			$MFF['store-deleteorder'] = 'ec';
			
			$PMP['store-deleteorder-confirm'] = 'store-deleteorder-confirm';
			$MFF['store-deleteorder-confirm'] = 'ec';
			
			
			$PMP['store-prefs'] = 'store-prefs';
			$MFF['store-prefs'] = 'ec';
			
			$PMP['store-prefs-save'] = 'store-prefs-save';
			$MFF['store-prefs-save'] = 'ec';
		
		}

				
		if ($PMP[$Arguments2] != '') {
			// function/page located
			include_once('./inc-'.$MFF[$Arguments2].'-admin-'.$PMP[$Arguments2].'.php');
			
			$ModuleCode = 'core';
		}
		else {
		
			$PageTitle = $MsgText[0][2];
			$BrowserTitle = $MsgText[0][2];
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a>';
			
			$PageContents = $MsgText[0][3].'<br><br>';
		
		}
		
	}
	else if ($Arguments1 == 'pages') {
	
		// custom page
		
		$PageDisplayed = 'n';
		
		
		$query = "select * from `".$Settings['DBPrefix']."core-Pages` where PageLink='".$Arguments2."' and PageEnabled='1' and MinLevel<=".$UserLevel." and ".GetTimestamp().">=StartDate and ".GetTimestamp()."<=if(EndDate>0,EndDate,4294967295) order by if(EndDate>0,EndDate,4294967295) asc LIMIT 1";
	    	$result = mysql_query($query) or die (mysql_error());
		
		if (mysql_num_rows($result) != 0) {			
	
			$row = mysql_fetch_array($result);
			
			
			if ($row['MetaKeywords'] != '') {
				$Settings['MetaKeywords'] = $row['MetaKeywords'];
			}
			
			if ($row['MetaDescription'] != '') {
				$Settings['MetaDescription'] = $row['MetaDescription'];
			}
			
			
			ReadPermissions();
			Global $Permissions;
			
			$EditLink = '';
			if ($Permissions[18] == 'y' && $row['MinLevel'] <= $UserLevel && $row['MinEditLevel'] <= $UserLevel) {
				$EditLink = '<a href="'.$MainURL.'/admin/pages-edit/'.$row['RecordNumber'].'.html">'.$MsgText[0][155].'</a><br><br>';
				
			}
						
			
			$PageID = $row['RecordNumber'];
			
			$PageCategoriesList[] = $row['PageParent'];
			
			
			$LastParent = $row['PageParent'];
			$LoopCounter = 0;
			
			while ($LastParent != 0 && $LoopCounter < 20) {
				$LoopCounter++;
				
				$query2 = "select * from `".$Settings['DBPrefix']."core-PageCategories` where RecordNumber=".$LastParent." LIMIT 1";
			    $result2 = mysql_query($query2) or die (mysql_error());
				$row2 = mysql_fetch_array($result2);
				
				$PageCategoriesList[] = $row2['Parent'];
				
				$LastParent = $row2['Parent'];
			}
			
			
			
			if ($row['ShowPrintable'] == 1) {
				$ShowPrintableLink = 'y';
			}
			if ($row['ShowEmail'] == 1) {
				$ShowEmailLink = 'y';
			}
		
		
			$PageDisplayed = 'y';
		
			if ($row['TitleImage'] != '') {
				if (substr($row['TitleImage'],0,1) == '/') {
					$row['TitleImage'] = $BaseURL . $row['TitleImage'];
				}
			
				$PageTitle = '<div align="'.$AlignmentCodes[$row['TitleAlignment']].'"><img src="'.$row['TitleImage'].'" alt="'.$row['PageTitle'].'" border="0"></div>';
			}
			else {
				$PageTitle = '<div align="'.$AlignmentCodes[$row['TitleAlignment']].'">'.$row['PageTitle'].'</div>';
			}
			
			
			$row['PageContents'] = str_replace('="{FlexMainURL}','="'.$MainURL,$row['PageContents']);
			$row['PageContents'] = str_replace('="{FlexBaseURL}','="'.$BaseURL,$row['PageContents']);
			
			
			
			if ($IM['na'] == 'y') {
			
				$query_na = "select * from `".$Settings['DBPrefix']."na-Settings`";
				$result_na = mysql_query($query_na) or die (mysql_error());
				while ($row_na = mysql_fetch_array($result_na)) {
					$naSettings[$row_na['Name']] = $row_na['Value'];
				}
			
				function AddArticles($StyleCode,$ArticlesCount,$CategoriesList) {
					Global $Settings, $MainURL, $ImagesURL, $naSettings, $FontFace, $FontSize, $MsgText;
					
					$ArticlesCode = '';
					$ArticlesPrinted = 0;
					
					
					if ($StyleCode == 1 || $StyleCode == 2 || $StyleCode == 3 || $StyleCode == 4) {
						$ArticlesCode = '<table width="100%" border="0" cellpadding="3" cellspacing="0">';
					}
					
					
					if (strpos($ArticlesCount,',') !== false) {
						list($ACOffset,$ACCount) = explode(',',$ArticlesCount);
						$LimitString = intval($ACOffset).','.intval($ACCount);
					}
					else {
						$LimitString = intval($ArticlesCount);
					}
					
					if ($CategoriesList != '') {
					
						$CategoriesArray = explode(',',$CategoriesList);
						for ($i = 0; $i < count($CategoriesArray); $i++) {
							$CategoriesArray[$i] = intval($CategoriesArray[$i]);
						}
						$CategoriesList2 = implode(',',$CategoriesArray);
										
						$query_na = "SELECT * FROM `".$Settings['DBPrefix']."na-Articles` WHERE ApprovedBy!='' AND (Category IN (".$CategoriesList2.") OR Category2 IN (".$CategoriesList2.") OR Category3 IN (".$CategoriesList2.") OR Category4 IN (".$CategoriesList2.") OR Category5 IN (".$CategoriesList2.") OR Category6 IN (".$CategoriesList2.") OR Category7 IN (".$CategoriesList2.") OR Category8 IN (".$CategoriesList2.") OR Category9 IN (".$CategoriesList2.") OR Category10 IN (".$CategoriesList2.")) and PublishDate<='".GetTimestamp()."' ORDER BY PublishDate DESC LIMIT ".$LimitString;
					}
					else {
						$query_na = "SELECT * FROM `".$Settings['DBPrefix']."na-Articles` WHERE ApprovedBy!='' and PublishDate<='".GetTimestamp()."' ORDER BY PublishDate DESC LIMIT ".$LimitString;
					}
		   			$result_na = mysql_query($query_na) or die (mysql_error());
					while ($row_na = mysql_fetch_array($result_na)) {
						
						if ($StyleCode == 1) {
						
							if ($ArticlesPrinted > 0) {
								$ArticlesCode .= '<tr><td colspan="2"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0"></td></tr>';
							}
							
																				
							if ($row_na['Teaser'] == '') {
								$StrippedArticle = strip_tags($row_na['Article']);
																
								if (strlen($StrippedArticle) > $naSettings['TeaserLength']) {
									$TeaserSection = substr($StrippedArticle,0,$naSettings['TeaserLength']);
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
									
									$TeaserSection .= '... <font size="1">[<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$MsgText[7][78].'</a>]</font>';
									$row_na['Title'] = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$row_na['Title'].'</a>';
									$ArticleLinked = 'y';
								}
								else {
									$TeaserSection = $row_na['Article'];
								}
							}
							else {
								$TeaserSection = substr($row_na['Teaser'],0,$naSettings['TeaserLength']);
								
								if (strlen($row_na['Teaser']) > strlen($TeaserSection)) {
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
								} 
								
								$TeaserSection .= '... <font size="1">[<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$MsgText[7][78].'</a>]</font>';
								$row_na['Title'] = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$row_na['Title'].'</a>';
								$ArticleLinked = 'y';
							}
							
									
							
							
							if ($row_na['Image'] != '' && $row_na['ImageType'] > 0) {
								$TypeExtensions[1] = '-thumb.gif';
								$TypeExtensions[2] = '-thumb.jpg';
								$TypeExtensions[3] = '-thumb.png';
								
								if ($ArticleLinked == 'y') {				
									$PhotoStuff = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html"><img src="'.$ImagesURL.'/articles/'.$row_na['Image'].$TypeExtensions[$row_na['ImageType']].'" alt="" border="0"></a>';
								}
								else {
									$PhotoStuff = '<img src="'.$ImagesURL.'/articles/'.$row_na['Image'].$TypeExtensions[$row_na['ImageType']].'" alt="" border="0">';
								}
							}
							else {
								$PhotoStuff = '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0">';
							}
							
							$ArticlesPrinted++;
							$ArticlesCode .= '<tr><td width="90%"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$row_na['Title'].'</b><br>'.$TeaserSection.'</td><td width="10%" align="center">'.$PhotoStuff.'</td></tr>';
						} // end if style 1
						
						else if ($StyleCode == 2) {
						
							if ($ArticlesPrinted > 0) {
								$ArticlesCode .= '<tr><td colspan="2"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0"></td></tr>';
							}
							
																				
							if ($row_na['Teaser'] == '') {
								$StrippedArticle = strip_tags($row_na['Article']);
								$TeaserSection = substr($StrippedArticle,0,$naSettings['TeaserLength']);
								
								if (strlen($StrippedArticle) > $naSettings['TeaserLength']) {
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
									
									$TeaserSection .= '... <font size="1">[<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$MsgText[7][78].'</a>]</font>';
									$row_na['Title'] = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$row_na['Title'].'</a>';
									$ArticleLinked = 'y';
								}
							}
							else {
								$TeaserSection = substr($row_na['Teaser'],0,$naSettings['TeaserLength']);
								
								if (strlen($row_na['Teaser']) > strlen($TeaserSection)) {
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
								} 
								
								$TeaserSection .= '... <font size="1">[<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$MsgText[7][78].'</a>]</font>';
								$row_na['Title'] = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$row_na['Title'].'</a>';
								$ArticleLinked = 'y';
							}
							
									
							
							
							if ($row_na['Image'] != '' && $row_na['ImageType'] > 0) {
								$TypeExtensions[1] = '-thumb.gif';
								$TypeExtensions[2] = '-thumb.jpg';
								$TypeExtensions[3] = '-thumb.png';
								
								if ($ArticleLinked == 'y') {				
									$PhotoStuff = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html"><img src="'.$ImagesURL.'/articles/'.$row_na['Image'].$TypeExtensions[$row_na['ImageType']].'" alt="" border="0"></a>';
								}
								else {
									$PhotoStuff = '<img src="'.$ImagesURL.'/articles/'.$row_na['Image'].$TypeExtensions[$row_na['ImageType']].'" alt="" border="0">';
								}
							}
							else {
								$PhotoStuff = '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0">';
							}
							
							$ArticlesPrinted++;
							$ArticlesCode .= '<tr><td width="10%" align="center">'.$PhotoStuff.'</td><td width="90%"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$row_na['Title'].'</b><br>'.$TeaserSection.'</td></tr>';
						} // end if style 2
						
						else if ($StyleCode == 3) {
						
							if ($ArticlesPrinted > 0) {
								$ArticlesCode .= '<tr><td colspan="2"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0"></td></tr>';
							}
							
																				
							if ($row_na['Teaser'] == '') {
								$StrippedArticle = strip_tags($row_na['Article']);
								$TeaserSection = substr($StrippedArticle,0,$naSettings['TeaserLength']);
								
								if (strlen($StrippedArticle) > $naSettings['TeaserLength']) {
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
									
									$TeaserSection .= '... <font size="1">[<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$MsgText[7][78].'</a>]</font>';
									$row_na['Title'] = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$row_na['Title'].'</a>';
									$ArticleLinked = 'y';
								}
							}
							else {
								$TeaserSection = substr($row_na['Teaser'],0,$naSettings['TeaserLength']);
								
								if (strlen($row_na['Teaser']) > strlen($TeaserSection)) {
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
								} 
								
								$TeaserSection .= '... <font size="1">[<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$MsgText[7][78].'</a>]</font>';
								$row_na['Title'] = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$row_na['Title'].'</a>';
								$ArticleLinked = 'y';
							}
							
									
							
							
							if ($row_na['Image'] != '' && $row_na['ImageType'] > 0) {
								$TypeExtensions[1] = '.gif';
								$TypeExtensions[2] = '.jpg';
								$TypeExtensions[3] = '.png';
								
								if ($ArticleLinked == 'y') {				
									$PhotoStuff = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html"><img src="'.$ImagesURL.'/articles/'.$row_na['Image'].$TypeExtensions[$row_na['ImageType']].'" alt="" border="0"></a>';
								}
								else {
									$PhotoStuff = '<img src="'.$ImagesURL.'/articles/'.$row_na['Image'].$TypeExtensions[$row_na['ImageType']].'" alt="" border="0">';
								}
							}
							else {
								$PhotoStuff = '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0">';
							}
							
							$ArticlesPrinted++;
							$ArticlesCode .= '<tr><td width="90%" valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$row_na['Title'].'</b><br>'.$TeaserSection.'</td><td width="10%" align="center">'.$PhotoStuff.'</td></tr>';
						} // end if style 3
						
						else if ($StyleCode == 4) {
						
							if ($ArticlesPrinted > 0) {
								$ArticlesCode .= '<tr><td colspan="2"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0"></td></tr>';
							}
							
																				
							if ($row_na['Teaser'] == '') {
								$StrippedArticle = strip_tags($row_na['Article']);
								$TeaserSection = substr($StrippedArticle,0,$naSettings['TeaserLength']);
								
								if (strlen($StrippedArticle) > $naSettings['TeaserLength']) {
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
									
									$TeaserSection .= '... <font size="1">[<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$MsgText[7][78].'</a>]</font>';
									$row_na['Title'] = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$row_na['Title'].'</a>';
									$ArticleLinked = 'y';
								}
							}
							else {
								$TeaserSection = substr($row_na['Teaser'],0,$naSettings['TeaserLength']);
								
								if (strlen($row_na['Teaser']) > strlen($TeaserSection)) {
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
									while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') {
										$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
									}
								} 
								
								$TeaserSection .= '... <font size="1">[<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$MsgText[7][78].'</a>]</font>';
								$row_na['Title'] = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html">'.$row_na['Title'].'</a>';
								$ArticleLinked = 'y';
							}
							
									
							
							
							if ($row_na['Image'] != '' && $row_na['ImageType'] > 0) {
								$TypeExtensions[1] = '.gif';
								$TypeExtensions[2] = '.jpg';
								$TypeExtensions[3] = '.png';
								
								if ($ArticleLinked == 'y') {				
									$PhotoStuff = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html"><img src="'.$ImagesURL.'/articles/'.$row_na['Image'].$TypeExtensions[$row_na['ImageType']].'" alt="" border="0"></a>';
								}
								else {
									$PhotoStuff = '<img src="'.$ImagesURL.'/articles/'.$row_na['Image'].$TypeExtensions[$row_na['ImageType']].'" alt="" border="0">';
								}
							}
							else {
								$PhotoStuff = '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0">';
							}
							
							$ArticlesPrinted++;
							$ArticlesCode .= '<tr><td width="10%" align="center">'.$PhotoStuff.'</td><td width="90%" valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$row_na['Title'].'</b><br>'.$TeaserSection.'</td></tr>';
						} // end if style 4
						
						
						
					} // end while rows loop
					
					
					if ($StyleCode == 1 || $StyleCode == 2 || $StyleCode == 3 || $StyleCode == 4) {
						$ArticlesCode .= '</table>';
					}
					
				
					return $ArticlesCode;
				}
			
			
				$StringMatches = substr_count($row['PageContents'],'{FlexCMS-Articles');
				for ($i = 1; $i <= $StringMatches; $i++) {
					$row['PageContents'] = preg_replace("/\{FlexCMS\-Articles\|(\d+)\|([\d,]*)\|([\d,]*)\}/ie", "AddArticles('\\1','\\2','\\3')", $row['PageContents']);
				}
				
			}
			
			
			
			
			if ($row['BrowserTitle'] != '') {
				$BrowserTitle = $row['BrowserTitle'];
			}
			else {			
				$BrowserTitle = $row['PageTitle'];
			}
			
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > '.$row['PageTitle'];
			
			
			if ($row['PageType'] != '') {
			
				if ($row['PageType'] == 'Photo1') {
				
					list ($PageTypeStuff, $PageContents) = explode('%*%*%*%*%',$row['PageContents'],2);
				
					list ($PhotoURL, $PhotoCaption, $PhotoPosition) = explode('#&#&#&#',$PageTypeStuff,3);
					
					if (substr($PhotoURL,0,5) != 'http:' && substr($PhotoURL,0,1) != '.') {
						if (substr($PhotoURL,0,1) != '/') {
							$PhotoURL = $BaseURL . '/images/uploaded/' . $PhotoURL;
						}
						else {
							$PhotoURL = $BaseURL . $PhotoURL;
						}
					}
					
					
					$row['PageContents'] = '<table width="5" align="'.$AlignmentCodes[$PhotoPosition].'" border="0" cellpadding="10" cellspacing="0"><tr><td align="center"><img src="'.$PhotoURL.'"><br><font size="1">'.$PhotoCaption.'</font></td></tr></table>'.$PageContents;
					
				}
			
			}
			
				
			
			if ($row['EnablePHP'] == '1') {
			// php enabled
			
				ob_start();
				eval($row['PageContents']);
				$BufferContents = ob_get_clean();
							
				$PageContents = $BufferContents;
						
			}
			else {
			// php not enabled
				
				//if ($row['NLtoBR'] == '1') {
				//	$row['PageContents'] = nl2br($row['PageContents']);
				//}
				
				$PageContents = '<style>p { margin-top: 0; margin-bottom: 0; }</style><div align="'.$AlignmentCodes[$row['PageAlignment']].'">'.$row['PageContents'].'</div>';
				
				
				if ($row['ConvertLinks'] == '1') {
					# convert email addresses to mailto links 
					//$PageContents = preg_replace("/([\w\.-]+)(@)([\w\.-]+)/e", "'<a href=\"mailto:\\0\">\\0</a>'", $PageContents);
										
					if (strpos($PageContents,'@',0) !== false && strpos($PageContents,'mailto:',0) === false) {
				
						$StringLength1 = rand(8, 14);
						$StringLength2 = rand(6, 15);
						$CharactersArray = array ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0');								
						$Random1 = 'a';
						$Random2 = 'b';
						for ($i = 1; $i <= $StringLength1; $i++) {
							$RandomNum = rand(1, 62);
							$Random1 .= $CharactersArray[$RandomNum];
						}
						for ($i = 1; $i <= $StringLength2; $i++) {
							$RandomNum = rand(1, 62);
							$Random2 .= $CharactersArray[$RandomNum];
						}
					
					
						$PageContents = preg_replace("/([\w\.-]+)(@)([\w\.-]+)/ie", "'<script language=\"JavaScript\">var '.\$Random1.' = \'\\1\'; var '.\$Random2.' = \'\\3\'; document.write(\'<a href=\"mai\'+\'lto:\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'\">\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'</a>\');</script>'", $PageContents);			
				
					} // end if @ found in contents
					
					
					# convert http urls to hyperlinks 
					//$PageContents = preg_replace("/(http:\/\/)([\w\.-]+)/e", "'<a href=\"\\0\" target=\"_blank\">\\0</a>'", $PageContents);
					$PageContents = preg_replace("/([^\">]http:\/\/)([a-zA-Z0-9-.\/]+)([,.]?[ ]?)/e", "'<a href=\"\\0\" target=\"_blank\">\\0</a>'", $PageContents); 
				}
				
				
				
				if (strpos($PageContents,'[',0) !== false && strpos($PageContents,']',0) !== false) {
				
					for ($i = 33; $i <= 126; $i++) {
				$HTMLCodes[chr($i)] = $i;
			}
					
			
			//$SearchChars[] = ';';
			//$ReplacementChars[] = '&#'.$HTMLCodes[';'].';';
			$CharsToReplaceArray[';'] = 1;
			
			$SearchChars[] = '[';
			$ReplacementChars[] = '&#'.$HTMLCodes['['].';';
			$CharsToReplaceArray['['] = 1;
			
			$SearchChars[] = '/';
			$ReplacementChars[] = '&#'.$HTMLCodes['/'].';';
			$CharsToReplaceArray['/'] = 1;
			
			$SearchChars[] = ']';
			$ReplacementChars[] = '&#'.$HTMLCodes[']'].';';
			$CharsToReplaceArray[']'] = 1;
			
			
			$CharsToReplaceArray['&'] = 1;
			
			$CharsToReplaceArray['#'] = 1;
			
			$CharsToReplaceArray['l'] = 1;
			$CharsToReplaceArray['t'] = 1;
			
			
			for ($w = 0; $w <= 9; $w++) {
				$CharsToReplaceArray[$w] = 1;			
			}
			
			
			
			
			// smilies setup
				$query8 = "select * from `".$Settings['DBPrefix']."core-Smilies` where Enabled=1";
				$result8 = mysql_query($query8) or die (mysql_error());
				while ($row8 = mysql_fetch_array($result8)) {
				
					if ($row8['InsertCode'] != '') {
						$SmiliesCount++;
						$SmilieCodes[] = $row8['InsertCode'];
						$SmilieFiles[$row8['InsertCode']] = $row8['ImageLink'];
						$SmilieDescriptions[$row8['InsertCode']] = $row8['Description'];
					}
					if ($row8['InsertCode2'] != '') {
						$SmiliesCount++;
						$SmilieCodes[] = $row8['InsertCode2'];
						$SmilieFiles[$row8['InsertCode2']] = $row8['ImageLink'];
						$SmilieDescriptions[$row8['InsertCode2']] = $row8['Description'];
					}
					if ($row8['InsertCode3'] != '') {
						$SmiliesCount++;
						$SmilieCodes[] = $row8['InsertCode3'];
						$SmilieFiles[$row8['InsertCode3']] = $row8['ImageLink'];
						$SmilieDescriptions[$row8['InsertCode3']] = $row8['Description'];
					}
					if ($row8['InsertCode4'] != '') {
						$SmiliesCount++;
						$SmilieCodes[] = $row8['InsertCode4'];
						$SmilieFiles[$row8['InsertCode4']] = $row8['ImageLink'];
						$SmilieDescriptions[$row8['InsertCode4']] = $row8['Description'];
					}
					if ($row8['InsertCode5'] != '') {
						$SmiliesCount++;
						$SmilieCodes[] = $row8['InsertCode5'];
						$SmilieFiles[$row8['InsertCode5']] = $row8['ImageLink'];
						$SmilieDescriptions[$row8['InsertCode5']] = $row8['Description'];
					}
									
				}
				
				if ($SmiliesCount > 0) {
				
					for ($i = 0; $i < $SmiliesCount; $i++) {
						for ($h = 0; $h < ($SmiliesCount-1); $h++) {
						
							if (strlen($SmilieCodes[$h]) < strlen($SmilieCodes[$h+1])) {
									
								$Swap1 = $SmilieCodes[$h+1];
																	
								$SmilieCodes[$h+1] = $SmilieCodes[$h];
																
								$SmilieCodes[$h] = $Swap1;
									
							}
									
						}
					}
				
				
				
					for ($i = 0; $i < $SmiliesCount; $i++) {
									
						for ($x = 0; $x < strlen($SmilieCodes[$i]); $x++) {
						
							$CurrentChar = substr($SmilieCodes[$i], $x, 1);
		
							if ($CharsToReplaceArray[$CurrentChar] != 1) {
							
								$SearchChars[] = $CurrentChar;
								$ReplacementChars[] = '&#'.$HTMLCodes[$CurrentChar].';';
							
							}
						
						}
					
					}
				
				
				
					for ($i = 0; $i < $SmiliesCount; $i++) {
					
						/*
						$SmiliesSearchArray[] = ' '.$SmilieCodes[$i];
						$SmiliesSearchArray[] = '>'.$SmilieCodes[$i];
						
						if (substr($SmilieFiles[$SmilieCodes[$i]],0,4) != 'http') {
							$SmilieFiles[$SmilieCodes[$i]] = $ImagesURL . '/smilies/' . $SmilieFiles[$SmilieCodes[$i]]; 
						}
						
						$SmiliesReplaceArray[] = ' <img src="'.$SmilieFiles[$SmilieCodes[$i]].'" alt="'.$SmilieDescriptions[$SmilieCodes[$i]].'">';
						$SmiliesReplaceArray[] = '><img src="'.$SmilieFiles[$SmilieCodes[$i]].'" alt="'.$SmilieDescriptions[$SmilieCodes[$i]].'">';
						*/
						
						
						$SmiliesSearchArray[] = ' ' . $SmilieCodes[$i];
						
						if (substr($SmilieFiles[$SmilieCodes[$i]],0,4) != 'http') {
							$SmilieFiles[$SmilieCodes[$i]] = $ImagesURL . '/smilies/' . $SmilieFiles[$SmilieCodes[$i]]; 
						}
						
						$SmiliesReplaceArray[] = '<img src="'.$SmilieFiles[$SmilieCodes[$i]].'" alt="'.$SmilieDescriptions[$SmilieCodes[$i]].'">';
												
					
					}
				
				}
				else {
				
					$DoSmilies = false;
				
				}
			// end smilies setup
			
			
			
					$LowerCaseMessage = strtolower($PageContents);
				
				
				
				
				
				// smilies
				//if ($DoSmilies != false) {		
					$PageContents = str_replace($SmiliesSearchArray, $SmiliesReplaceArray, $PageContents);
				//}
				
				
				if ($row['NLtoBR'] == '1') {
					$PageContents = str_replace("\n", '<br>', $PageContents);
					//$PageContents = str_replace("\r", '', $PageContents);
				}
				
				
				
				// horizontal rule (hr)
				$PageContents = str_replace('[hr]', '<hr>', $PageContents);
				
				
				// font faces and sizes
				$PageContents = preg_replace("/(\[font=)(.*?)(\])/i", "<font face=\"\\2\">", $PageContents);
				$PageContents = preg_replace("/(\[size=)(.*?)(\])/i", "<font size=\"\\2\">", $PageContents);
				
				$PageContents = str_replace('[/font]', '</font>', $PageContents);
				$PageContents = str_replace('[/size]', '</font>', $PageContents);
				
				
				// bold
				$PageContents = preg_replace("/(\[b\])(.*?)(\[\/b\])/i", "<b>\\2</b>", $PageContents);
				//$PageContents = str_replace('[b]', '<b>', $PageContents);
				//$PageContents = str_replace('[/b]', '</b>', $PageContents);
				//$PageContents = preg_replace("/\[b\]/i", "<b>", $PageContents); 
				//$PageContents = preg_replace("/\[\/b\]/i", "</b>", $PageContents); 
				
				// italics
				$PageContents = preg_replace("/(\[i\])(.*?)(\[\/i\])/i", "<i>\\2</i>", $PageContents);
				//$PageContents = str_replace('[i]', '<i>', $PageContents);
				//$PageContents = str_replace('[/i]', '</i>', $PageContents);
				//$PageContents = preg_replace("/\[i\]/i", "<i>", $PageContents); 
				//$PageContents = preg_replace("/\[\/i\]/i", "</i>", $PageContents);
				
				// underline
				$PageContents = preg_replace("/(\[u\])(.*?)(\[\/u\])/i", "<u>\\2</u>", $PageContents);
				//$PageContents = str_replace('[u]', '<u>', $PageContents);
				//$PageContents = str_replace('[/u]', '</u>', $PageContents); 
				//$PageContents = preg_replace("/\[\/u\]/i", "</u>", $PageContents);
				
				
				// colors
				$ColorCodes['black'] = '#000000';
				$ColorCodes['white'] = '#ffffff';
				$ColorCodes['red'] = '#ff0000';
				$ColorCodes['yellow'] = '#ffff00';
				$ColorCodes['green'] = '#008000';
				$ColorCodes['grey'] = '#888888';
				$ColorCodes['burgundy'] = '#990000';
				$ColorCodes['orange'] = '#ff9900';
				$ColorCodes['purple'] = '#9900ff';
				$ColorCodes['cream'] = '#ffffcc';
				$ColorCodes['teal'] = '#008080';
				$ColorCodes['salmon'] = '#ffcccc';
				$ColorCodes['blue'] = '#0000ff';
				$ColorCodes['pink'] = '#ff33cc';
				$ColorCodes['navy'] = '#003399';
				$ColorCodes['lightblue'] = '#33ccff';
				$ColorCodes['mauve'] = '#666699';
				$ColorCodes['limegreen'] = '#00ff00';
				
				//$PageContents = preg_replace("/(\[color\=)([a-zA-Z]+)(\])/i", "<font color=\"\\2\">", $PageContents);
				$StringMatches = substr_count($PageContents,'[color=');
				for ($i = 1; $i <= $StringMatches; $i++) {				
					$PageContents = preg_replace("/(\[color\=)(.*?)(\])(.*?)(\[\/color\])/ie", "'<font color=\"'.\$ColorCodes['\\2'].'\">'.stripslashes('\\4').'</font>'", $PageContents);
				}
				 
				//$PageContents = preg_replace("/(\[\/color\])/", "</font>", $PageContents); 
				  
				
				// urls
				$PageContents = preg_replace("/(\[url=)(.*?)(\])(.*?)(\[\/url\])/ie", "'<a href=\"\\2\" target=\"_blank\"><font color=\"'.\$Colors['Link'].'\">\\4</font></a>'", $PageContents);
				$PageContents = preg_replace("/(\[url\])(.*?)(\[\/url\])/ie", "'<a href=\"\\2\" target=\"_blank\"><font color=\"'.\$Colors['Link'].'\">\\2</font></a>'", $PageContents);
				
					
				// images
				$PageContents = preg_replace("/(\[img\])(.*?)(\[\/img\])/i", "<img src=\"\\2\" border=\"0\" alt=\"\">", $PageContents);
				
				
				// emails
				
				// if [email] exists in the message
				if (strpos($LowerCaseMessage,'[email]',0) !== false) {
				
					$StringLength1 = rand(8, 14);
					$StringLength2 = rand(6, 15);
					$CharactersArray = array ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0');								
					$Random1 = 'a';
					$Random2 = 'b';
					for ($i = 1; $i <= $StringLength1; $i++) {
						$RandomNum = rand(1, 62);
						$Random1 .= $CharactersArray[$RandomNum];
					}
					for ($i = 1; $i <= $StringLength2; $i++) {
						$RandomNum = rand(1, 62);
						$Random2 .= $CharactersArray[$RandomNum];
					}
				
				
					$PageContents = preg_replace("/(\[email\])(.*?)(@)(.*?)(\[\/email\])/ie", "'<script language=\"JavaScript\">var '.\$Random1.' = \'\\2\'; var '.\$Random2.' = \'\\4\'; document.write(\'<a href=\"mai\'+\'lto:\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'\"><font color=\"'.\$Colors['MBText'].'\">\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'</font></a>\');</script>'", $PageContents);			
				
				} // end if [email] found in message
				
				
				// alignment
				/*
				$PageContents = str_replace('[left]', '<div align="left">', $PageContents);
				$PageContents = str_replace('[/left]', '</div>', $PageContents);
				$PageContents = str_replace('[center]', '<div align="center">', $PageContents);
				$PageContents = str_replace('[/center]', '</div>', $PageContents);
				$PageContents = str_replace('[right]', '<div align="right">', $PageContents);
				$PageContents = str_replace('[/right]', '</div>', $PageContents);
				*/
				$PageContents = preg_replace("/(\[left\])(.*?)(\[\/left\])/i", "<div align=\"left\">\\2</div>", $PageContents);
				$PageContents = preg_replace("/(\[center\])(.*?)(\[\/center\])/i", "<div align=\"center\">\\2</div>", $PageContents);
				$PageContents = preg_replace("/(\[right\])(.*?)(\[\/right\])/i", "<div align=\"right\">\\2</div>", $PageContents);
				
				
					
				// end of pattern matching
				
				
				
				} // end if processing codes
				else {
			
					if ($row['NLtoBR'] == '1') {
						$PageContents = nl2br($PageContents);
					}
			
				}
					
			} // end if php not enabled
			
			
			$PageContents = $EditLink.$PageContents;
			
			
			
		} // end if page found
		
	
		if ($PageDisplayed != 'y') {
		
				$query333 = "select MinLevel from `".$Settings['DBPrefix']."core-Pages` where PageLink='".$Arguments2."' and PageEnabled='1' and ".GetTimestamp().">=StartDate and ".GetTimestamp()."<=if(EndDate>0,EndDate,4294967295) order by if(EndDate>0,EndDate,4294967295) asc LIMIT 1";
			    $result333 = mysql_query($query333) or die (mysql_error());
				$row333 = mysql_fetch_array($result333);
		
				if ($row333['MinLevel'] > 0 && $LoggedIn != 'y') {
					// redirect to login page
										
					RedirectToLogin();
				}
				else {
					// logging in aint gonna help em :-P
		
					$PageTitle = $MsgText[0][2];
					$BrowserTitle = $MsgText[0][2];
					$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a>';
			
					$PageContents = $MsgText[0][3].'<br><br>';
				}
		
		}

	} // end if custom page
	else {
	
		// cr
		$PMP['login'] = 'login';
		$MFF['login'] = 'core';
		$PMP['login-submit'] = 'login-submit';
		$MFF['login-submit'] = 'core';
		$PMP['login-submit-nf'] = 'login-submit-nf';
		$MFF['login-submit-nf'] = 'core';
		
		$PMP['logout'] = 'logout';
		$MFF['logout'] = 'core';
		
		$PMP['lost_password'] = 'lost_password';
		$MFF['lost_password'] = 'core';
		$PMP['lost_password-send'] = 'lost_password-send';
		$MFF['lost_password-send'] = 'core';
		$PMP['lost_password-unlock'] = 'lost_password-unlock';
		$MFF['lost_password-unlock'] = 'core';
		$PMP['lost_password-save'] = 'lost_password-save';
		$MFF['lost_password-save'] = 'core';
		
		$PMP['lost_username'] = 'lost_username';
		$MFF['lost_username'] = 'core';
		$PMP['lost_username-send'] = 'lost_username-send';
		$MFF['lost_username-send'] = 'core';
		
		
		$PMP['register'] = 'register';
		$MFF['register'] = 'core';
		$PMP['register-submit'] = 'register-submit';
		$MFF['register-submit'] = 'core';
		$PMP['register-verify'] = 'register-verify';
		$MFF['register-verify'] = 'core';
		
		$PMP['options'] = 'options';
		$MFF['options'] = 'core';
		
		
		$PMP['notifications'] = 'notifications';
		$MFF['notifications'] = 'core';
		$PMP['notifications-save'] = 'notifications-save';
		$MFF['notifications-save'] = 'core';
		
		
		$PMP['profile'] = 'profile';
		$MFF['profile'] = 'core';
		$PMP['profile-edit'] = 'profile-edit';
		$MFF['profile-edit'] = 'core';
		$PMP['profile-edit-save'] = 'profile-edit-save';
		$MFF['profile-edit-save'] = 'core';
		
		
		$PMP['search'] = 'search';
		$MFF['search'] = 'core';
		$PMP['search-results'] = 'search-results';
		$MFF['search-results'] = 'core';
		
		
		$PMP['email'] = 'email';
		$MFF['email'] = 'core';
		
		$PMP['email-submit'] = 'email-submit';
		$MFF['email-submit'] = 'core';
		
		
		// cl
		if ($IM['cl'] == 'y') {
			$PMP['calendar'] = 'idx';
			$MFF['calendar'] = 'cl';
		}
		
		// mb
		if ($IM['mb'] == 'y') {
			$PMP['forum'] = 'idx';
			$MFF['forum'] = 'mb';
		}
		
		// pg
		if ($IM['pg'] == 'y') {
			$PMP['photos'] = 'idx';
			$MFF['photos'] = 'pg';
		}
		
		// cs
		if ($IM['cs'] == 'y') {
			$PMP['count'] = 'main';
			$MFF['count'] = 'cs';
		}
		
		// nl
		if ($IM['nl'] == 'y') {
			$PMP['newsletter'] = 'idx';
			$MFF['newsletter'] = 'nl';
		}
		
		// gb
		if ($IM['gb'] == 'y') {
			$PMP['guestbook'] = 'idx';
			$MFF['guestbook'] = 'gb';
		}
		
		// na
		if ($IM['na'] == 'y') {
			$PMP['articles'] = 'idx';
			$MFF['articles'] = 'na';
		}
		
		// lm
		if ($IM['lm'] == 'y') {
			$PMP['links'] = 'idx';
			$MFF['links'] = 'lm';
		}
		
		// ecommerce
		if ($IM['ec'] == 'y') {	
				
			$PMP['store'] = 'idx';
			$MFF['store'] = 'ec';
									
		}
		
		
		if ($PMP[$Arguments1] != '') {
			// pre-made page
			
			if ($MFF[$Arguments1] == '') {
				$MFF[$Arguments1] = 'core';
			}
			
			include_once('./inc-'.$MFF[$Arguments1].'-'.$PMP[$Arguments1].'.php');
			
			$ModuleCode = $MFF[$Arguments1];
		}
		
		else {
		
			$PageTitle = $MsgText[0][2];
			$BrowserTitle = $MsgText[0][2];
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a>';
			
			$PageContents = $MsgText[0][3].'<br><br>';
		
		}
		
	}
	
} // end if $Arguments1 != ''
// ========================================================================================


else {
		
	$PageTitle = $MsgText[0][2];
	$BrowserTitle = $MsgText[0][2];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a>';
			
	$PageContents = $MsgText[0][3].'<br><br>';
		
}


// =============================
// =============================

		if ($Arguments1 == 'admin' || $Arguments1 == 'options' || $Arguments1 == 'notifications' || $Arguments1 == 'profile-edit') {
			$LocationBar = $LocationBar.'<br><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="16" alt=""><br>';
		}
		else {
			if ($Settings['ShowNavigationLinks'] == 'allbuthome' || $Settings['ShowNavigationLinks'] == 'allpages') {
				if ($Arguments1 == 'pages' && $Arguments2 == 'index') {
					$LocationBar = '<img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""><br>';
				}
				else {
					$LocationBar = $LocationBar.'<br><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="16" alt=""><br>';
				}
			}
			else {
				$LocationBar = '<img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""><br>';
			}
		}
		
		
		
		if (($ShowPrintableLink == 'y' || $ShowEmailLink == 'y') && strpos($QSData,'printable') === false) {
		
			if ($Settings['PEAlignment'] == '') {
				$Settings['PEAlignment'] = 'R';
			}
		
			if ($ShowPrintableLink == 'y') {
				$PrintablePart = '<td><a href="'.$MainURL.'/printable'.$QSData.'.html" target="_blank"><img src="'.$ImagesURL.'/admin/icon_print.gif" width="16" height="16" alt="" border="0"></a></td>
      <td><font face="'.$FontFace.'" size="1">&nbsp;<a href="'.$MainURL.'/printable'.$QSData.'.html" target="_blank">'.$MsgText[7][63].'</a></td>
      <td><img src="'.$ImagesURL.'/admin/spacer.gif" width="15" height="1" alt="" border="0"></td>';
			}
			if ($ShowEmailLink == 'y') {
				$EmailPart = '<td><script>
				function EmailPage(PageLink) {
				
					var WindowProperties = \'width=450,height=500,left=\' + (screen.width-450)/2 + \',top=\' + (screen.height-500)/2 + \',location=no,menubar=no,directories=no,toolbar=no,status=no,scrollbars=no,resizable=yes\';

					var EmailWindowCode = window.open(\''.$MainURL.'/email/\'+PageLink+\'.html\',\'EmailPage\',WindowProperties);
								
				}			
				</script><a href="javascript:EmailPage(\''.str_replace('/','+++',$QSData).'\');"><img src="'.$ImagesURL.'/admin/icon_email.gif" width="16" height="16" alt="" border="0"></a></td>
      <td><font face="'.$FontFace.'" size="1">&nbsp;<a href="javascript:EmailPage(\''.str_replace('/','+++',$QSData).'\');">'.$MsgText[7][64].'</a>&nbsp;&nbsp;</td>';
			}
		
			$PageContents = '<div align="'.$AlignmentCodes[$Settings['PEAlignment']].'"><table border="0" cellpadding="0" cellspacing="0">
    <tr>
      '.$PrintablePart.'
      '.$EmailPart.'
    </tr>
</table></div><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="10" alt="" border="0"><br>'.$PageContents;
		
		}


		
        $TemplateTags[rc('67656E657261746F72',3)] = $Settings['SPN'];

	
		if ($Settings[rc('41646453697465546F5469746C65',3)] == 'all' || ($Settings[rc('41646453697465546F5469746C65',3)] == 'allbuthome' && ($Arguments1 != 'pages' || $Arguments2 != 'index')) || ($Settings[rc('41646453697465546F5469746C65',3)] == '' && ($Arguments1 != 'pages' || $Arguments2 != 'index'))) {
			
			if ($BrowserTitle != '') {
				if ($Settings[rc('065100100083105116101084111084105116108101083101112',5)] == '') {
					$Settings[rc('065100100083105116101084111084105116108101083101112',5)] = '--';
				}
				$BrowserTitle .= ' '.$Settings[rc('065100100083105116101084111084105116108101083101112',5)].' ';
			}
			
			if ($Settings[rc('076111110103083105116101078097109101',5)] != '') {
		        	$TemplateTags[rc('7469746C65',3)] = $BrowserTitle . $Settings[rc('076111110103083105116101078097109101',5)];
		        }
		        else {
		        	$TemplateTags[rc('7469746C65',3)] = $BrowserTitle . $Settings[rc('123151164145116141155145',4)];
		        }
		
		}
		else {
		
			$TemplateTags[rc('7469746C65',3)] = $BrowserTitle;
		
		}
		
		
		
        	$TemplateTags[rc('617574686F72',3)] = $Settings[rc('083105116101078097109101',5)].rc('040055055040120157167145162145144040142171040',4).$Settings['SPN'].rc('032040',5).$Settings['SPURL'].rc('041',5);
        		
		
		if ($Settings[rc('737062',3)] == 'y' || $Settings[rc('154166154',4)] < 3) {
			if ($Settings['SPFLW'] > 0 && $Settings['SPFLH'] > 0) {
				$WHPortion =' width="'.$Settings['SPFLW'].'" height="'.$Settings['SPFLH'].'"';
			}
				
			$PB = '<font face="'.$FontFace.'" size="1">'.$MsgText[0][578].' <a href="'.$Settings['SPURL'].'" target="_blank" class="FooterColors">'.$Settings['SPN'].'</a><br><a href="'.$Settings['SPURL'].'" target="_blank"><img src="'.$Settings['SPFL'].'" border="0"'.$WHPortion.' alt="'.$MsgText[0][578].' '.$Settings['SPN'].'"></a></font>';
		}
		else if ($Settings[rc('737062',3)] == 'l') {
			$PB = '<font face="'.$FontFace.'" size="1">'.$MsgText[0][578].' <a href="'.$Settings['SPURL'].'" target="_blank" class="FooterColors">'.$Settings['SPN'].'</a></font>';
		}
		else if ($Settings[rc('737062',3)] == 'i') {
			$PB = '<font face="'.$FontFace.'" size="1"><a href="'.$Settings['SPURL'].'" target="_blank"><img src="'.$Settings['SPFL'].'" border="0"'.$WHPortion.' alt="'.$MsgText[0][578].' '.$Settings['SPN'].'"></a></font>';
		}
			
		
		$TemplateTags[rc('146157157164145162',4)] .= '<div align="center"><br><font face="'.$FontFace.'" size="'.$FontSize.'">'.$Settings[rc('067111112121114105103104116',5)].'<br><br>';

		if ($Settings[rc('123150157167102157164164157155114157147151156',4)] == 'y' && $LoggedIn != 'y') {
			if ($Settings[rc('437573746F6D4C6F67696E436F6465',3)] != '') {
				$BottomLogin = '<div align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/login.html" class="FooterColors">'.$Settings[rc('437573746F6D4C6F67696E436F6465',3)].'</a></div><br>';
			}
			else {
				$BottomLogin = '<div align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/login.html" class="FooterColors">'.$MsgText[0][576].'</a></div><br>';
			}
		}
		
		
		if ($IM['cs'] == 'y') {
		
			$EncodedString = '';
			for ($i = 0; $i < strlen($QSData); $i++) {
			
				$CurrentConversion = '';
				
				$CurrentConversion = ord(substr($QSData,$i,1));
				
				if ($CurrentConversion < 10) {
					$CurrentConversion = '00'.$CurrentConversion;
				}
				else if ($CurrentConversion < 100) {
					$CurrentConversion = '0'.$CurrentConversion;
				}
				
				$EncodedString .= $CurrentConversion;
		
			}
			
		
			$TemplateTags[rc('666F6F746572',3)] .= '<script language="Javascript">var CounterURL = "'.$MainURL.'/count/'.rand(0,999999).'/"; var CurrentPage = "'.$EncodedString.'";</script><script language="Javascript" src="'.$BaseURL.'/flex_cs.js"></script><noscript><img src="'.$MainURL.'/count/'.rand(0,999999).'/'.$EncodedString.'" width="1" height="1" alt="" border="0"></noscript>';

			$TemplateTags['counteronly'] = '<script language="Javascript">var CounterURL = "'.$MainURL.'/count/'.rand(0,999999).'/"; var CurrentPage = "'.$EncodedString.'";</script><script language="Javascript" src="'.$BaseURL.'/flex_cs.js"></script><noscript><img src="'.$MainURL.'/count/'.rand(0,999999).'/'.$EncodedString.'" width="1" height="1" alt="" border="0"></noscript>';

		}


		
		$TemplateTags['description'] = $Settings['MetaDescription'];
        	$TemplateTags['keywords'] = $Settings['MetaKeywords'];



///////// start blocks setup

		if ($PrintableFormat != 'y') {

		if ($PageID != '') {
			$PagesPart = ' or PagesList LIKE \'%-'.$PageID.',%\'';
			
			for ($x = 0; $x < count($PageCategoriesList); $x++) {
				$PageCatsPart .= ' or PageCatsList LIKE \'%-'.$PageCategoriesList[$x].',%\'';
			}
		}
		else if ($ModuleCode != '') {
			$ModulesPart = ' or ModulesList LIKE \'%-'.$ModuleCode.',%\'';
		}
		
		//query the database and load blocks data.  load only enabled blocks, and sort them by block priority.
		$query = "select * from `".$Settings['DBPrefix']."core-Blocks` where BlockEnabled='1' and MinLevel<=".$UserLevel." and ((PagesList='' and PageCatsList='' and ModulesList='') ".$PagesPart.$PageCatsPart.$ModulesPart.") ORDER BY BlockLocation,BlockPriority asc";
		$result = mysql_query($query) or die (mysql_error());
		//print '<font color="#ffffff" size="3">'.$query.'</font>';
		
		// find largest location id
		$LargestLocationNumber = 0;
		
		// if any rows are returned, enabled blocks exist
		if (mysql_num_rows($result) != 0) {
			
			while ($row = mysql_fetch_array($result)) { 
            
				//$AllBlocksCount++;
				
				if ($row['MinLevel'] > -1 || $LoggedIn != 'y') {
				// weed out blocks set to guest only if the user is logged in
				
					if ($row['TitleImage'] != '') {
						if (substr($row['TitleImage'],0,1) == '/') {
							$row['TitleImage'] = $BaseURL . $row['TitleImage'];
						}
						$row['BlockTitle'] = '<img src="'.$row['TitleImage'].'" alt="'.$row['BlockTitle'].'" title="'.$row['BlockTitle'].'" border="0">';
					}
				
					$BlocksArray[$row['BlockLocation']]['BlockType'][] = $row['BlockType'];
					$BlocksArray[$row['BlockLocation']]['BlockLocation'][] = $row['BlockLocation'];
					$BlocksArray[$row['BlockLocation']]['BlockName'][] = $row['BlockName'];
					$BlocksArray[$row['BlockLocation']]['BlockTitle'][] = $row['BlockTitle'];
					$BlocksArray[$row['BlockLocation']]['BlockContents'][] = $row['BlockContents'];
					$BlocksArray[$row['BlockLocation']]['BlockAlignment'][] = $row['BlockAlignment'];
					$BlocksArray[$row['BlockLocation']]['TitleAlignment'][] = $row['TitleAlignment'];
					$BlocksArray[$row['BlockLocation']]['NLtoBR'][] = $row['NLtoBR'];
					$BlocksArray[$row['BlockLocation']]['ConvertLinks'][] = $row['ConvertLinks'];
					$BlocksArray[$row['BlockLocation']]['EnablePHP'][] = $row['EnablePHP'];
					
					if ($LargestLocationNumber < $row['BlockLocation']) {
						$LargestLocationNumber = $row['BlockLocation'];
					}
					
				}
				
			
			}
			
		}
		
		$AlignmentCodes[''] = 'left';
		$AlignmentCodes['L'] = 'left';
		$AlignmentCodes['C'] = 'center';
		$AlignmentCodes['R'] = 'right';
		
		$TitleAlignmentCodes[''] = 'center';
		$TitleAlignmentCodes['L'] = 'left';
		$TitleAlignmentCodes['C'] = 'center';
		$TitleAlignmentCodes['R'] = 'right';
		
		$TagCode[1] = 'leftblocks';
		$TagCode[2] = 'rightblocks';
		$TagCode[3] = 'topcenterblocks';
		$TagCode[4] = 'bottomcenterblocks';
		$TagCode[5] = 'topfullblocks';
		$TagCode[6] = 'bottomfullblocks';
		$TagCode[7] = 'topbannerblocks';
		$TagCode[8] = 'logoblock';
		
		
		for ($LocationCounter = 1; $LocationCounter <= $LargestLocationNumber; $LocationCounter++){
		
			// left blocks column
			//if ($LocationCounter == 1 && count($BlocksArray['1']) > 0) { $TemplateTags['leftblocks'] = '<td width="'.$LeftColumnWidth.'" valign="top">'; }
			// right blocks column			
			//else if ($LocationCounter == 2 && count($BlocksArray['2']) > 0) { $TemplateTags['rightblocks'] = '<td width="'.$ColumnSpacing.'"></td><td width="'.$RightColumnWidth.'" valign="top">'; }
			
		
			for ($Counter = 0; $Counter <= (count($BlocksArray[$LocationCounter]['BlockType']) - 1); $Counter++){
			
				if ($BlocksArray[$LocationCounter]['NLtoBR'][$Counter] == '1') {
					$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = nl2br($BlocksArray[$LocationCounter]['BlockContents'][$Counter]);
				}
		
				if ($BlocksArray[$LocationCounter]['ConvertLinks'][$Counter] == '1') {
				
					# convert email addresses to mailto links 
					//$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = preg_replace("/([\w\.-]+)(@)([\w\.-]+)/e", "'<a href=\"mailto:\\0\">\\0</a>'", $BlocksArray[$LocationCounter]['BlockContents'][$Counter]);
										
					if (strpos($BlocksArray[$LocationCounter]['BlockContents'][$Counter],'@',0) !== false) {
				
						$StringLength1 = rand(8, 14);
						$StringLength2 = rand(6, 15);
						$CharactersArray = array ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0');								
						$Random1 = 'a';
						$Random2 = 'b';
						for ($i = 1; $i <= $StringLength1; $i++) {
							$RandomNum = rand(1, 62);
							$Random1 .= $CharactersArray[$RandomNum];
						}
						for ($i = 1; $i <= $StringLength2; $i++) {
							$RandomNum = rand(1, 62);
							$Random2 .= $CharactersArray[$RandomNum];
						}
					
					
						$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = preg_replace("/([\w\.-]+)(@)([\w\.-]+)/ie", "'<script language=\"JavaScript\">var '.\$Random1.' = \'\\1\'; var '.\$Random2.' = \'\\3\'; document.write(\'<a href=\"mai\'+\'lto:\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'\" class=\"BlockColors\">\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'</a>\');</script>'", $BlocksArray[$LocationCounter]['BlockContents'][$Counter]);			
				
					} // end if @ found in contents
					

					# convert http urls to hyperlinks 
					$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = preg_replace("/(http:\/\/)([\w\.-]+)/ie", "'<a href=\"\\0\" target=\"_blank\" class=\"BlockColors\">\\0</a>'", $BlocksArray[$LocationCounter]['BlockContents'][$Counter]); 				
				
				}
									
				
				if ($BlocksArray[$LocationCounter]['BlockType'][$Counter] != '') {
				// pre-made block selected
				
					list ($PMBFamily, $PMBNumber) = split ('-',$BlocksArray[$LocationCounter]['BlockType'][$Counter],2);
					
					if ($PMBFamily == 'cr') {
					// core pre-made blocks
						
						if ($PMBNumber == '1' && $BlocksArray[$LocationCounter]['BlockContents'][$Counter] != '') {
						// menu
						
							
							
														
							$MenuItemsArray = explode ('^^^^',$BlocksArray[$LocationCounter]['BlockContents'][$Counter]);
							// the first line is the separator, everything after that is menu items
																
							if ($MenuItemsArray[0] != '') {
								list ($MenuItemSpacer, $MenuHeader, $MenuFooter) = explode('%%%',$MenuItemsArray[0]);
							}
							else {
								$MenuHeader = '';
								$MenuFooter = '';
								if ($LocationCounter == 1 || $LocationCounter == 2) {
									$MenuItemSpacer = '<br>';
								}
								else {
									$MenuItemSpacer = '&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;';
								}
							}
							
							
							$MenuTextA = '';
							$MenuImageA = '';
							$MenuCodeA = '';
							$MenuLinkA = '';
							$MenuPriorityA = '';
							
														
							// >>>> starts at one, as the first item is the spacer
							for ($g = 1; $g < count($MenuItemsArray); $g++) {
								
								if ($MenuItemsArray[$g] != '') {
	
									list ($MenuText, $MenuImage, $MenuCode, $MenuLink, $MenuPermissions, $MenuEnabled, $MenuPriority) = explode ('%%%',$MenuItemsArray[$g]);
								
									if ($MenuPriority == '') {
										// if the menu priority is empty, set it to 0 for tracking and sorting purposes
										$MenuPriority = 0;
									}

									if (($MenuPermissions == 'g' && $LoggedIn != 'y') || ($MenuPermissions != 'g' && $UserLevel >= $MenuPermissions) && $MenuEnabled == 1) {
									// if the user is a guest and the block is for guests only, or if the block isn't
									// for guests only and their permissions are high enough to see it
								
										$MenuTextA[] = $MenuText;
										$MenuImageA[] = $MenuImage;
										$MenuCodeA[] = $MenuCode;
										$MenuLinkA[] = $MenuLink;
										$MenuPriorityA[] = $MenuPriority;
								
									} // end if should be displayed
							
								} // end if row != ''
								
							} // end loop
							
							
							for ($g = 0; $g < count($MenuPriorityA); $g++) {
								for ($h = 0; $h < count($MenuPriorityA)-1; $h++) {

									if ($MenuPriorityA[$h] > $MenuPriorityA[$h+1]) {
									
										$Swap1 = $MenuTextA[$h+1];
										$Swap2 = $MenuImageA[$h+1];
										$Swap3 = $MenuCodeA[$h+1];
										$Swap4 = $MenuLinkA[$h+1];
										$Swap5 = $MenuPriorityA[$h+1];
										
										$MenuTextA[$h+1] = $MenuTextA[$h];
										$MenuImageA[$h+1] = $MenuImageA[$h];
										$MenuCodeA[$h+1] = $MenuCodeA[$h];
										$MenuLinkA[$h+1] = $MenuLinkA[$h];
										$MenuPriorityA[$h+1] = $MenuPriorityA[$h];
										
										$MenuTextA[$h] = $Swap1;
										$MenuImageA[$h] = $Swap2;
										$MenuCodeA[$h] = $Swap3;
										$MenuLinkA[$h] = $Swap4;
										$MenuPriorityA[$h] = $Swap5;
									
									}
								
								}
							}
							
							// reset the contents so the new generated stuff can go there
							$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = '';
							
							for ($g = 0; $g < count($MenuPriorityA); $g++) {
								
								if ($MenuCodeA[$g] != '') {
									// custom code to print, so print that
																	
									if ($BlocksArray[$LocationCounter]['BlockContents'][$Counter] != '') {
										$BlocksArray[$LocationCounter]['BlockContents'][$Counter] .= $MenuItemSpacer.$MenuCodeA[$g];
									}
									else {
										$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = $MenuCodeA[$g];
									}
								
								}
								else {
									// no code, so figure out what to print
																
									if (substr($MenuLinkA[$g],0,5) == 'http:' || substr($MenuLinkA[$g],0,6) == 'https:' || substr($MenuLinkA[$g],0,4) == 'ftp:') {
										$FinalLink = $MenuLinkA[$g];
									}
									else {
										$FinalLink = $BaseURL. '/' . $Settings['ScriptName'] . '/' .$MenuLinkA[$g].'.html';
									}
									
									if ($MenuImageA[$g] != '') {
										$VisibleLink = '<img src="'.$ImagesURL.'/menu/'.$MenuImageA[$g].'" border="0" alt="'.$MenuTextA[$g].'">';
									}
									else {
										$VisibleLink = $MenuTextA[$g];
									}
									
									
									if ($BlocksArray[$LocationCounter]['BlockContents'][$Counter] != '') {
										$BlocksArray[$LocationCounter]['BlockContents'][$Counter] .= $MenuItemSpacer.'<a href="'.$FinalLink.'" class="BlockColors">'.$VisibleLink.'</a>';
									}
									else {
										$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = '<a href="'.$FinalLink.'" class="BlockColors">'.$VisibleLink.'</a>';
									}
								
								} // end if no code
								
						
							} // end loop
							
							$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = $MenuHeader . $BlocksArray[$LocationCounter]['BlockContents'][$Counter] . $MenuFooter;
							
						} // end if $PMBNumber == '1'
						
						else if ($PMBNumber == '2') {
						// users online
						
							$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = '';
							$UsersOnline = '';
							$GuestsCount = '';
							
							//query the database and load blocks data.  load only enabled blocks, and sort them by block priority.
							//$query69 = "select Username from `".$Settings['DBPrefix']."core-Users` where LastAction+(SessionLength*60)>='".GetTimestamp()."' ORDER BY Username ASC";
							$query69 = "select User,Name,LastAction,SessionLength,UserOrGuest from `".$Settings['DBPrefix']."core-RecentActivity` where LastAction>=".(GetTimestamp()-1800)." and SessionLength>0 ORDER BY Name ASC";
							$result69 = mysql_query($query69) or die (mysql_error());
																
							while ($row = mysql_fetch_array($result69)) { 
							
								if ($row['SessionLength'] > 0) {
								
									if ($row['LastAction']+($row['SessionLength']*60) >= GetTimestamp()) {
									
										if ($row['UserOrGuest'] == 'u') {
											$UsersCount++;
											
											if ($row['Name'] == '') { $row['Name'] = $row['User']; }
									
											if ($UsersOnline != '') {
												if ($LoggedIn == 'y') {
													$UsersOnline .= ', <a href="'.$MainURL.'/profile/'.$row['User'].'.html" class="BlockColors">'.$row['Name'].'</a>';
													
												}
												else {
													$UsersOnline .= ', <font color="'.$Colors['BText'].'">'.$row['Name'].'</font>';
												}
											}
											else {
												if ($LoggedIn == 'y') {
													$UsersOnline = '<a href="'.$MainURL.'/profile/'.$row['User'].'.html" class="BlockColors">'.$row['Name'].'</a>';
												}
												else {
													$UsersOnline = '<font color="'.$Colors['BText'].'">'.$row['Name'].'</font>';
												}
											}
											
										}
										else {
											$GuestsCount++;
										}
																				
									}
								
								}
						
							}
							
							if ($UsersOnline != '' & $GuestsCount > 0) { $UsersOnline .= '<br>'; }
							
							if ($GuestsCount > 0) {
								if ($GuestsCount == 1) {
									$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = $UsersOnline.'1 Guest';
								}
								else if ($GuestsCount > 1) {
									$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = $UsersOnline.$GuestsCount.' Guests';
								}
							}					
							else {
								$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = $UsersOnline;
							}
							
							ReadPermissions();
							Global $Permissions;
							// if the user has permission to view the where are they now report, and more users than just them are online
							if ($Permissions[11] == 'y' && (($UsersCount+$GuestsCount) > 1)) {
								$BlocksArray[$LocationCounter]['BlockContents'][$Counter] .= '<br><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="2" alt="" border="0"><br><font size="1"><a href="'.$MainURL.'/admin/where.html" class="BlockColors">'.$MsgText[0][523].'</a></font>';
							}
							
						
						} // end if $PMBNumber == '2'
						else if ($PMBNumber == '3' && $BlocksArray[$LocationCounter]['BlockContents'][$Counter] != '') {
							
							// random link						
						
							//print $row['BlockContents'];
							$ItemsArray = explode ('^^^^',$BlocksArray[$LocationCounter]['BlockContents'][$Counter]);
							// the first line is the separator, everything after that is menu items
																
							if ($ItemsArray[0] != '') {
								list ($LinksCount, $LinkPrefix, $LinkSuffix) = explode('%%%',$ItemsArray[0]);
							}
							if ($LinksCount < 1) { $LinksCount = 1; }
							if ($LinkPrefix == '') {
								if ($LocationCounter == 1 || $LocationCounter == 2) {
									$LinkPrefix = '';
								}
								else {
									$LinkPrefix = '&nbsp;&nbsp;- ';
								}
							}
							if ($LinkSuffix == '') {
								if ($LocationCounter == 1 || $LocationCounter == 2) {
									$LinkSuffix = '<br>';
								}
								else {
									$LinkSuffix = '&nbsp;&nbsp;';
								}
							}
							
							
							
						
							$LinkTextA = '';
							$LinkURLA = '';
							
														
							// >>>> starts at one, as the first item is the spacer
							for ($g = 1; $g < count($ItemsArray); $g++) {
								
								if ($ItemsArray[$g] != '') {
						
									list ($LinkText,$LinkURL) = explode ('%%%',$ItemsArray[$g]);
													
												
									$LinkTextA[] = $LinkText;
									$LinkURLA[] = $LinkURL;
								
											
								} // end if row != ''
													
							} // end loop
							
							
							if (!is_array($LinkTextA)) {
								$LinksCount = 0;
							}
							else if ($LinksCount > count($LinkTextA)) {
								$LinksCount = count($LinkTextA);
							}
							
							$ArrayLength = count($LinkTextA)-1;
							
							
							// reset the contents so the new generated stuff can go there
							$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = '';
							
							for ($g = 0; $g < $LinksCount; $g++) {
							
								$RandomNum = rand(0,$ArrayLength);
								
								$BlocksArray[$LocationCounter]['BlockContents'][$Counter] .= $LinkPrefix.'<a href="'.$LinkURLA[$RandomNum].'" target="_blank" class="BlockColors">'.$LinkTextA[$RandomNum].'</a>'.$LinkSuffix;


								// move the last item in the array up to the position of the one
								//that was just selected, then shorten the array by one.  this
								// prevents the same item from being selected again.
								$LinkTextA[$RandomNum] = $LinkTextA[$ArrayLength];
								$LinkURLA[$RandomNum] = $LinkURLA[$ArrayLength];
								
								$ArrayLength--;
								
						
							} // end loop
							
						
						} // end if $PMBNumber == '3'
						else if ($PMBNumber == '5' && $BlocksArray[$LocationCounter]['BlockContents'][$Counter] != '') {
						// links to pages
						
							ReadPermissions();
							Global $Permissions;
							
						
							$ItemsArray = '';
							$ItemsArray = explode ('^^^^',$BlocksArray[$LocationCounter]['BlockContents'][$Counter]);
		
							// first line is used for settings
							if ($ItemsArray[0] != '') {
								list ($ItemSpacer, $Header, $Footer) = explode('%%%',$ItemsArray[0]);
							}
							else {
								$Header = '';
								$Footer = '';
								if ($LocationCounter == 1 || $LocationCounter == 2) {
									$ItemSpacer = '<br>';
								}
								else {
									$ItemSpacer = '&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;';
								}
							}
							
							$Links = '';
							$IDs = '';
							$Titles = '';
							$Priorities = '';
							$Images = '';
							$MOImages = '';
							
							
							$MOPartA = '';
							$MOPartB = '';
							
								
							for ($g = 1; $g < count($ItemsArray); $g++) {
								list ($Link, $ID, $Title, $Priority, $Image, $MOImage) = explode('%%%',$ItemsArray[$g]);
								$Links[] = $Link;
								$IDs[] = $ID;
								$Titles[] = $Title;
								$Priorities[] = $Priority;
								$Images[] = $Image;
								$MOImages[] = $MOImage;
							}
							
							
							// sort by name
							for ($g = 0; $g < count($Titles); $g++) {
								for ($h = 0; $h < count($Titles)-1; $h++) {
					
									if ($Titles[$h] > $Titles[$h+1]) {
														
										$Swap1 = $Links[$h+1];
										$Swap4 = $IDs[$h+1];
										$Swap2 = $Titles[$h+1];
										$Swap3 = $Priorities[$h+1];
										$Swap5 = $Images[$h+1];
										$Swap6 = $MOImages[$h+1];
																				
										$Links[$h+1] = $Links[$h];
										$IDs[$h+1] = $IDs[$h];
										$Titles[$h+1] = $Titles[$h];
										$Priorities[$h+1] = $Priorities[$h];
										$Images[$h+1] = $Images[$h];
										$MOImages[$h+1] = $MOImages[$h];
																				
										$Links[$h] = $Swap1;
										$IDs[$h] = $Swap4;
										$Titles[$h] = $Swap2;
										$Priorities[$h] = $Swap3;
										$Images[$h] = $Swap5;
										$MOImages[$h] = $Swap6;
																		
									}
													
								}
							}
							
							// then re-sort by priority
							for ($g = 0; $g < count($Titles); $g++) {
								for ($h = 0; $h < count($Titles)-1; $h++) {
					
									if ($Priorities[$h] > $Priorities[$h+1]) {
														
										$Swap1 = $Links[$h+1];
										$Swap4 = $IDs[$h+1];
										$Swap2 = $Titles[$h+1];
										$Swap3 = $Priorities[$h+1];
										$Swap5 = $Images[$h+1];
										$Swap6 = $MOImages[$h+1];
																				
										$Links[$h+1] = $Links[$h];
										$IDs[$h+1] = $IDs[$h];
										$Titles[$h+1] = $Titles[$h];
										$Priorities[$h+1] = $Priorities[$h];
										$Images[$h+1] = $Images[$h];
										$MOImages[$h+1] = $MOImages[$h];
																				
										$Links[$h] = $Swap1;
										$IDs[$h] = $Swap4;
										$Titles[$h] = $Swap2;
										$Priorities[$h] = $Swap3;
										$Images[$h] = $Swap5;
										$MOImages[$h] = $Swap6;
																		
									}
													
								}
							}
																		
							$FinalContents = '';
							for ($g = 0; $g < count($Titles); $g++) {
							
								if ($FinalContents != '') {
									$SpacerPrint = $ItemSpacer;
								}
								else {
									$SpacerPrint = '';
								}
								
								
								if ($Images[$g] != '') {
									if (substr($Images[$g],0,7) != 'http://') {
										$Images[$g] = $BaseURL.'/images/uploaded/'.$Images[$g];
									}
									if ($MOImages[$g] != '') {
										if (substr($MOImages[$g],0,7) != 'http://') {
											$MOImages[$g] = $BaseURL.'/images/uploaded/'.$MOImages[$g];
										}
										
										$RandomNum = rand(5555,99999);
										
										$MOPartA = ' onMouseOver="img'.$RandomNum.'.src=\''.$MOImages[$g].'\'" onMouseOut="img'.$RandomNum.'.src=\''.$Images[$g].'\'"';
										
										$MOPartB = ' NAME="img'.$RandomNum.'" onLoad="tempImg=new Image(0,0); tempImg.src=\''.$MOImages[$g].'\'"';
									}
									else {
										$MOPartA = '';
										$MOPartB = '';
									}
								
									$Titles[$g] = '<IMG'.$MOPartB.' SRC="'.$Images[$g].'" alt="'.$Titles[$g].'" title="'.$Titles[$g].'" border="0">';
								}
								else {
									$MOPartA = '';
									$MOPartB = '';
								}
																													
									
								if ($Links[$g] != '') {
									$FinalContents .= $SpacerPrint.'<A HREF="'.$Links[$g].'"'.$MOPartA.' class="BlockColors">'.$Titles[$g].'</a>';
								}
								else if (substr($IDs[$g],0,6) != 'pages/') {
									if ($IDs[$g] == 'login' && $LoggedIn == 'y') {
										// do nothing, since they don't need a login link when they're logged in
									}
									else if ($IDs[$g] == 'logout' && $LoggedIn != 'y') {
										// do nothing, since they don't need a logout link when they're a guest
									}
									else if ($IDs[$g] == 'register' && ($Settings['AllowGuestRegistrations'] != 'y' || ($LoggedIn == 'y' && $Permissions[10] != 'y'))) {
										// do nothing, since they shouldn't see a register link if they're logged in
										// or if guest registrations aren't allowed
									}
									else if ($IDs[$g] == 'options' && $LoggedIn != 'y') {
										// do nothing, since they don't need a control panel link when they're a guest
									}
									else if ($IDs[$g] == 'profile-edit' && $LoggedIn != 'y') {
										// do nothing, since they don't need a profile edit link when they're a guest
									}
									else if ($IDs[$g] == 'calendar' && $IM['cl'] != 'y') {
										// do nothing, since the required module isn't installed
									}
									else if ($IDs[$g] == 'forum' && $IM['mb'] != 'y') {
										// do nothing, since the required module isn't installed
									}
									else if ($IDs[$g] == 'photos' && $IM['pg'] != 'y') {
										// do nothing, since the required module isn't installed
									}
									else if ($IDs[$g] == 'guestbook' && $IM['gb'] != 'y') {
										// do nothing, since the required module isn't installed
									}
									else if (substr($IDs[$g],0,10) == 'newsletter' && $IM['nl'] != 'y') {
										// do nothing, since the required module isn't installed
									}
									else if ($IDs[$g] == 'articles' && $IM['na'] != 'y') {
										// do nothing, since the required module isn't installed
									}
									else if ($IDs[$g] == 'links' && $IM['lm'] != 'y') {
										// do nothing, since the required module isn't installed
									}
									else if ($IDs[$g] == 'store' && $IM['ec'] != 'y') {
										// do nothing, since the required module isn't installed
									}
									else {
										if ($IDs[$g] == '' && $Images[$g] != '') {
											$FinalContents .= $SpacerPrint.$Titles[$g];
										}
										else {
											$FinalContents .= $SpacerPrint.'<a href="'.$MainURL.'/'.$IDs[$g].'.html"'.$MOPartA.' class="BlockColors">'.$Titles[$g].'</a>';
										}
									}
								}
								else if (substr($IDs[$g],0,6) == 'pages/') {
									if ($PageListLoaded != 'y') {
									
										$query55 = "select * from `".$Settings['DBPrefix']."core-Pages` where MinLevel<='".$UserLevel."' and ".GetTimestamp().">=StartDate and ".GetTimestamp()."<=if(EndDate>0,EndDate,4294967295)";
										$result55 = mysql_query($query55) or die (mysql_error());
										while ($row55 = mysql_fetch_array($result55)) {
											$PageVisible[$row55['PageLink']] = 'y';
										}
										
										$PageListLoaded = 'y';
									}
									
									
									if ($PageVisible[substr($IDs[$g],6)] == 'y') {
										$FinalContents .= $SpacerPrint.'<a href="'.$MainURL.'/'.$IDs[$g].'.html"'.$MOPartA.' class="BlockColors">'.$Titles[$g].'</a>';
									}
									else {
										// do nothing, they can't see the content so they shouldn't see the link
									}
									
								}
							
							
							
							}
											
							
							$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = $Header.$FinalContents.$Footer;
							
						
						} // end if $PMBNumber == '5'
					
					}
					else if ($PMBFamily == 'cl' && $IM['cl'] == 'y') {
					// calendar pre-made blocks
					
						if ($PMBNumber == 1) {
						
							$FinalContents = '';
						
							$query = "select * from `".$Settings['DBPrefix']."cl-Settings`";
							$result = mysql_query($query) or die (mysql_error());
								while ($row = mysql_fetch_array($result)) {
								$clSettings[$row['Name']] = $row['Value'];
							}
							
							
							
							$OverridesArray = explode('%%',$clSettings['ColorOverrides']);
							
							
							if ($OverridesArray[1] != '') { 
							$Colors['CLBorder'] = $OverridesArray[1];			// main calendar border
							}
							if ($OverridesArray[2] != '') {
							$Colors['CLTitleBG'] = $OverridesArray[2];			// top title (month and year, next/prev month links) background
							}
							if ($OverridesArray[3] != '') {
							$Colors['CLTitleText'] = $OverridesArray[3];			// top title text
							}
							if ($OverridesArray[4] != '') {
							$Colors['CLDaysBG'] = $OverridesArray[4];			// day names background
							}
							if ($OverridesArray[5] != '') {
							$Colors['CLDaysText'] = $OverridesArray[5];			// day names text
							}
							if ($OverridesArray[6] != '') {
							$Colors['CLCalDaysBG'] = $OverridesArray[6];			// grid squares that are a calendar day
							}
							if ($OverridesArray[7] != '') {
							$Colors['CLFillerDaysBG'] = $OverridesArray[7];		// grid squares that are fillers (not a day)
							}
							if ($OverridesArray[8] != '') {
							$Colors['CLCurrentDayBG'] = $OverridesArray[8];		// grid square that is today's date
							}
							if ($OverridesArray[9] != '') {
							$Colors['CLDayNumbersText'] = $OverridesArray[9];	// day numbers text
							}
							if ($OverridesArray[10] != '') {
							$Colors['CLEventTitleText'] = $OverridesArray[10];	// event title link text
							}
							if ($OverridesArray[11] != '') {
							$Colors['CLEventDetailsText'] = $OverridesArray[11];	// event details text
							}
							if ($OverridesArray[12] != '') {
							$Colors['CLContentBG'] = $OverridesArray[12];	// content pages bg
							}
							
						
							
							$query55 = "select * from `".$Settings['DBPrefix']."core-Settings` where Name='TimezoneOffset' limit 1";
							$result55 = mysql_query($query55) or die (mysql_error());
							$row55 = mysql_fetch_array($result55);
							if ($row55['Value'] != '') {		
								$TZO = (($row55['Value']+5)*3600);
							}
							
						
						
								$aMonth = date('n',GetTimestamp());
								$aYear = date('Y',GetTimestamp());
										
								
								
								$aDayNames = array ('', strtoupper(substr($MsgText[0][27],0,1)), strtoupper(substr($MsgText[0][28],0,1)), strtoupper(substr($MsgText[0][29],0,1)), strtoupper(substr($MsgText[0][30],0,1)), strtoupper(substr($MsgText[0][31],0,1)), strtoupper(substr($MsgText[0][32],0,1)), strtoupper(substr($MsgText[0][33],0,1)));
								
								
								
								$aMonthStartTimestamp = mktime(0,0,0,$aMonth,1,$aYear);
								
								$aLastMonthTimestamp = mktime(0,0,0,($aMonth-1),1,$aYear);
								$aNextMonthTimestamp = mktime(0,0,0,($aMonth+1),1,$aYear);
								
								$aDaysInMonth = date('t',$aMonthStartTimestamp);
								//$FinalContents .= $aDaysInMonth.'<br>';
								
								$aGetDateArray = getdate($aMonthStartTimestamp);
								$aTodayDateArray = getdate(GetTimestamp());
								
								$aGetLastMonthDateArray = getdate($aLastMonthTimestamp);
								$aGetNextMonthDateArray = getdate($aNextMonthTimestamp);
						
								
								
								$aquery55 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where DateCode>=".($aMonthStartTimestamp+$TZO)." and DateCode<".($aNextMonthTimestamp-1+$TZO)." order by DateCode asc";
								$aresult55 = mysql_query($aquery55) or die (mysql_error());
								while ($arow55 = mysql_fetch_array($aresult55)) {
								
									$aquery559 = "select * from `".$Settings['DBPrefix']."cl-Events` where RecordNumber='".$arow55['EventID']."' limit 1";
									$aresult559 = mysql_query($aquery559) or die (mysql_error());
									$arow559 = mysql_fetch_array($aresult559);
									
									if ($arow559['MinLevel'] <= $UserLevel) {
								
										$aDateSplit = getdate($arow55['DateCode']-$TZO);
									
										$aEventsExist[$aDateSplit['year']][$aDateSplit['mon']][$aDateSplit['mday']] = 'y';
										
									}
													
								} 
								
								
								
								$FinalContents .= '<div align="center"><table width="98%" cellpadding=0 cellspacing=0 border=0><tr><td bgcolor="'.$Colors['CLBorder'].'">			
								<table width="100%" cellpadding=1 cellspacing=1 border=0><tr><td colspan="7" width="98%" bgcolor="'.$Colors['CLTitleBG'].'">		
								<table width="100%" cellpadding=3 cellspacing=0 border=0><tr><td width="100%" align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['CLTitleText'].'"><font size="2"><b>'.$MsgText[0][33+date('n',$aMonthStartTimestamp)].' '.date('Y',$aMonthStartTimestamp).'</b></font></td></tr></table>
								</td></tr>';

	
								$FinalContents .= '<tr>';
								
								for ($acol = 1; $acol <= 7; $acol++) {
			
									$FinalContents .= '<td bgcolor="'.$Colors['CLDaysBG'].'"><div align="center"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['CLDaysText'].'"><b>'.$aDayNames[$acol].'</b></div></td>';
									
								}
								
								$FinalContents .= '</tr>';
										
								$aMonthDay = 0;
								$arow = 0;
								$aFirstDayFound = null;
								while (($aMonthDay + 1) <= $aDaysInMonth) {
									
									$arow++;
									$FinalContents .= '<tr>';
								
									
									for ($acol = 1; $acol <= 7; $acol++) {
									
										$aCell = (($arow - 1) * 7) + $acol;
										
										$aCalendarDay = 'n';
										
										if (($aMonthDay + 1) > $aDaysInMonth) {
											$aCalendarDay = 'n';		
										}
										else {
										
											if (!$aFirstDayFound) {
												if (($aGetDateArray['wday'] + 1) == $aCell) {
													$aMonthDay = 1;
													$aFirstDayFound = 'y';
													
													$aCalendarDay = 'y';					
												}
												else {
													$aCalendarDay = 'n';
												}
											}
											else {
												$aMonthDay++;
												
												$aCalendarDay = 'y';
												
											}
										
										} // end if still not past the end of the month
									
										if ($aCalendarDay == 'y') {
										
																
											if ($aMonth == $aTodayDateArray['mon'] && $aYear == $aTodayDateArray['year'] && $aMonthDay == $aTodayDateArray['mday']) {
												$aBGColor = $Colors['CLCurrentDayBG'];
											}
											else {
												$aBGColor = $Colors['CLCalDaysBG'];
											}
											
															
											if ($aEventsExist[$aYear][$aMonth][$aMonthDay] == 'y') {
												$FinalContents .= '<td height="100%" bgcolor="'.$aBGColor.'" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/calendar/day/'.$aMonthDay.'/'.$aMonth.'/'.$aYear.'.html" class="BlockColors"><font color="'.$Colors['CLDayNumbersText'].'">' . $aMonthDay .'</font></a></b></td>';
											}
											else {
												$FinalContents .= '<td height="100%" bgcolor="'.$aBGColor.'" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">' . $aMonthDay . '</td>';
											}
											
						
										}
										else {
											$FinalContents .= '<td bgcolor="'.$Colors['CLFillerDaysBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;</td>';
										}
			
									} // end for (column cells)
			
									$FinalContents .= '</tr>';
		
								} // end while (rows)
		
		
		
								$FinalContents .= '<tr><td colspan="7" width="98%" bgcolor="'.$Colors['CLTitleBG'].'">
								
								<table width="100%" cellpadding=3 cellspacing=0 border=0><tr><td width="100%" align="center" valign="middle"><font face="'.$FontFace.'"><a href="'.$MainURL.'/calendar.html" class="BlockColors"><font size="1" color="'.$Colors['CLTitleText'].'"><b>'.$MsgText[1][104].'</b></font></a></td></tr></table></td></tr>';
		
		
								$FinalContents .= '</table></td></tr></table>';
								
								
								$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = $FinalContents;
						
						} // end if $PMBNumber == '1'
					
					}
				
				}
				
								
				
				if ($BlocksArray[$LocationCounter]['EnablePHP'][$Counter] == '1') {
					
					ob_start();
					eval($BlocksArray[$LocationCounter]['BlockContents'][$Counter]);
					$BufferContents = ob_get_clean();
					
					$BlocksArray[$LocationCounter]['BlockContents'][$Counter] = $BufferContents;
					
				}
				
				
							
				if ($BlocksArray[$LocationCounter]['BlockContents'][$Counter] != '') {
					// if the block has contents, add it to the array to build
								
					$BuildBlocksArray['TitleAlignment'][$LocationCounter][] = $TitleAlignmentCodes[$BlocksArray[$LocationCounter]['TitleAlignment'][$Counter]];
					$BuildBlocksArray['BlockTitle'][$LocationCounter][] = $BlocksArray[$LocationCounter]['BlockTitle'][$Counter];
					$BuildBlocksArray['BlockAlignment'][$LocationCounter][] = $AlignmentCodes[$BlocksArray[$LocationCounter]['BlockAlignment'][$Counter]];
					$BuildBlocksArray['BlockContents'][$LocationCounter][] = $BlocksArray[$LocationCounter]['BlockContents'][$Counter];
					
				}
				
	
			
			} // end for $Counter (individual blocks)
		
		
	
	} // end for $LocationCounter (various block locations)
	
	
	// now actually build the blocks with the template structure
	for ($LocationCounter = 1; $LocationCounter <= $LargestLocationNumber; $LocationCounter++){

		for ($Counter = 0; $Counter <= (count($BuildBlocksArray['TitleAlignment'][$LocationCounter]) - 1); $Counter++){
		
			//function BuildBlock($TitleAlignment,$Title,$ContentsAlignment,$Contents,$BlockLocation,$NumberAtLocation,$TotalAtLocation)
			
			$TemplateTags[$TagCode[$LocationCounter]] .= BuildBlock($BuildBlocksArray['TitleAlignment'][$LocationCounter][$Counter], $BuildBlocksArray['BlockTitle'][$LocationCounter][$Counter], $BuildBlocksArray['BlockAlignment'][$LocationCounter][$Counter], $BuildBlocksArray['BlockContents'][$LocationCounter][$Counter], $LocationCounter, ($Counter+1), count($BuildBlocksArray['TitleAlignment'][$LocationCounter]));
					
		
		}
		
	}
	
	

////////// end blocks setup
	} // end if $PrintableFormat != 'y'


} // end if versions match


// call the function to print the final page to the browser
PrintFinalPage();



// ==========================================================


function VerifyCleanString($StringToUse, $VerifyMode) {

	if ($VerifyMode == 1) {
		// email addresses
		
		$FinalString = '';
		
		if (strpos($StringToUse,' ') === false && strpos($StringToUse,'@') == strrpos($StringToUse,'@') && strpos($StringToUse,'@') !== false && strpos($StringToUse,'.') !== false) { 
			// if no spaces, at least one dot(.), and one @
		
			for ($i = 0; $i < strlen($StringToUse); $i++) {
				$CurrentChar = substr($StringToUse,$i,1);
		
				// 33 = !
				// 35-38 = #$%&
				// 42-57 = *+,-./ 0-9
				// 63-90 = ?@ A-Z
				// 95 = _
				// 97-122 = a-z
				// 124 = |
				// 126 = ~
			
				$CurCharNum = ord($CurrentChar);
			
				if (
				$CurCharNum == 33 ||
				($CurCharNum >= 35 && $CurCharNum <= 38) ||
				($CurCharNum >= 42 && $CurCharNum <= 57) || 
				($CurCharNum >= 63 && $CurCharNum <= 90) ||
				$CurCharNum == 95 ||
				($CurCharNum >= 97 && $CurCharNum <= 122) ||
				$CurCharNum == 124 ||
				$CurCharNum == 126
				) {
					$FinalString .= $CurrentChar;
				}
				
			}
							
		}
		
	}
	else if ($VerifyMode == 2) {
		// general text strings (names, etc)
		
		$FinalString = '';
		for ($i = 0; $i < strlen($StringToUse); $i++) {
			$CurrentChar = substr($StringToUse,$i,1);
		
			// 32-58 = [space]!"#$%&'()*+,-./ 0-9
			// 63-91 = ?@ A-Z [
			// 93-126 = ]^_` a-z {|}~
						
			$CurCharNum = ord($CurrentChar);
			
			if (
			($CurCharNum >= 32 && $CurCharNum <= 58) ||
			($CurCharNum >= 63 && $CurCharNum <= 91) || 
			($CurCharNum >= 93 && $CurCharNum <= 126)
			) {
				$FinalString .= $CurrentChar;
			}
							
		}
	}
	else if ($VerifyMode == 3) {
		// text strings with any 'regular' characters (tabs allowed, no line breaks)
		
		$FinalString = '';
		for ($i = 0; $i < strlen($StringToUse); $i++) {
			$CurrentChar = substr($StringToUse,$i,1);
					
			$CurCharNum = ord($CurrentChar);
			
			if ($CurCharNum == 9 || ($CurCharNum >= 32 && $CurCharNum <= 126)) {
				$FinalString .= $CurrentChar;
			}
							
		}
	}
	else if ($VerifyMode == 4) {
		// text strings with any 'regular' characters (tabs and line breaks allowed too)
		
		$FinalString = '';
		for ($i = 0; $i < strlen($StringToUse); $i++) {
			$CurrentChar = substr($StringToUse,$i,1);
					
			$CurCharNum = ord($CurrentChar);
			
			if ($CurCharNum == 9 || $CurCharNum == 10 || $CurCharNum == 13 || ($CurCharNum >= 32 && $CurCharNum <= 126)) {
				$FinalString .= $CurrentChar;
			}
							
		}
	}

	
	return $FinalString;
}


function RedirectToLogin() {

	Global $Arguments1, $Arguments2, $Arguments3, $Arguments4, $Arguments5, $Arguments6, $Arguments7, $Arguments8, $Arguments9;
	Global $MainURL;

	
	$RedirectString = $Arguments1 . '/' . $Arguments2 . '/' . $Arguments3 . '/' . $Arguments4 . '/' . $Arguments5 . '/' . $Arguments6 . '/' . $Arguments7 . '/' . $Arguments8 . '/' . $Arguments9;
	
	$RedirectString = str_replace('//','',$RedirectString);
	
	if (substr($RedirectString,strlen($RedirectString)-1,1) == '/') {
		$RedirectString = substr($RedirectString,0,strlen($RedirectString)-1);
	}
	
	$RedirectString = str_replace('/','+++',$RedirectString);

	
	header('Location: ' . $MainURL . '/login/' . $RedirectString);	

}


function DBConnect() {

	Global $Settings, $DBConnected;

	if ($DBConnected != 'y') {
	
		include_once('./settings.php');
	
       		mysql_connect($DBServer, $DBUser, $DBPass) or die ("Could not connect to database");
	
        	mysql_select_db($DBDatabase) or die ("Could not select database");
		
		$DBConnected = 'y';
		
		
		$Settings['DBPrefix'] = $DBPrefix;
		
	}	
	
}


function ReadPermissions() {

	Global $Permissions, $UserLevel, $Settings;
	
	
	$query = "select Permissions from `".$Settings['DBPrefix']."core-Permissions` where Level=".$UserLevel." LIMIT 1";
    	$result = mysql_query($query) or die (mysql_error());
	
	$row = mysql_fetch_array($result);
	
	if ($row['Permissions'] == 'a') {
		for ($i = 1; $i <= 1000; $i++) {
			$Permissions[$i] = 'y';
		}
	}
	else {
		$PA = split('-',$row['Permissions']);
		
		for ($i = 0; $i < count($PA); $i++) {
			if ($PA[$i] > 0) {
				$Permissions[$PA[$i]] = 'y';
				
				if ($PA[$i] == 3) {
					$Permissions[18] = 'y';
					$Permissions[19] = 'y';
					$Permissions[20] = 'y';
				}
			}
		}
	}
}

function ReadFormArguments() {
	
	Global $FormArguments;
	
	foreach ($_POST as $PostKey=>$PostValue){
		if (!get_magic_quotes_gpc()) {
			$PostValue = addslashes($PostValue);
		}
		$FormArguments[$PostKey] = $PostValue;
	}    

}

function gs() {

	Global $Settings;

	$query = "select * from `".$Settings['DBPrefix']."core-Settings`";
	$result = mysql_query($query) or die (mysql_error());
	while ($row = mysql_fetch_array($result)) {
		$Settings[$row['Name']] = $row['Value'];
	}
	
	$Settings['FilesCHMOD'] = octdec($Settings['FilesCHMOD']);
	$Settings['FoldersCHMOD'] = octdec($Settings['FoldersCHMOD']);
	
	
	if ($Settings['NewLKS']) {
		$LK = $Settings['NewLKS'];
		$Settings['lvl'] = (substr_count($LK,chr(88))+substr_count($LK,chr(89))+substr_count($LK,chr(90)));
		
		
		for ($i = 0; $i < strlen($LK); $i++) {
			if (ord(substr($LK,$i,1)) < 71 || ord(substr($LK,$i,1)) > 90) {
				$LK2 .= substr($LK,$i,1);
			}
		}
		
		for ($i = 0; $i < strlen($LK2); $i=$i+2) {
			$URL .= chr(hexdec(substr($LK2,$i,2)));
		}
		
		$Settings['BaseURL'] = $URL;
	}
		
	
	$Settings[rc('099099100',5)]++;
	$SettingsLoaded = 'y'; mc();

}

function mc() {

	Global $Settings, $IM;
	
	$MCAa = array(45,49,52,57,48,65,27,36,59,24); gl();
	
	$SMA = explode('-',$Settings[rc('77,49',1)]);


	$MCone = (substr($Settings[rc('77,50',1)],0,strlen($Settings[rc('77,50',1)])-1)/5);

	$MCtwo = (substr($Settings[rc('77,51',1)],2,strlen($Settings[rc('77,51',1)])-6)/275);
	
	$Settings[rc('4D4341',3)] = (rc($MCAa[$Settings[rc('108,118,108',1)]],1)+1);
					
	if ($MCtwo <= $Settings[rc('4D4341',3)] && $MCone == strlen($Settings[rc('77,49',1)]) && $MCtwo == count($SMA)) {
		if (strlen($Settings[rc('77,49',1)]) > 0) {
			$Settings[rc('4D4342',3)] = count($SMA);
	
			for ($i = 0; $i < $Settings[rc('4D4342',3)]; $i++) {
				$IM[$SMA[$i]] = rc('121',1);
			}
			
			$Settings[rc('6B73',3)] = '';
		}
		else {
			$LFD = rc('35',3);
		}
	}
	else {
		//$LFD = rc('071',4);
		$LFD = rc('071',4); $Settings[rc('4D31',3)] = '';
	}
	
	if ($LFD > 1) {
		//$Settings[rc('107,115',1)] = 'y';
		//$Settings[rc('77,49',1)] = rc('76,70,68',1);
		$Settings[rc('4D4342',3)] = 0;
	}
			
	
	$Settings[rc('636364',3)]++;	

}

function redirect($RedirectURL) {

	if ($Settings['RedirectionPatch'] != 'y') {
		header('Location: '.$RedirectURL);
	}
	else {
		header('Refresh: 0; URL='.$RedirectURL);
	}

}

function gl() {

	/*
	Global $Settings;

	if ($Settings[rc('6C766C',3)] != (strlen($Settings[rc('108,50',1)])-7)) {
		$Settings[rc('154166154',4)] = rc('49',1);
		$Settings[rc('6B73',3)] = 'y';
	}
	if ($Settings[rc('154166154',4)] != (12-strlen($Settings[rc('6C33',3)]))) {
		$Settings[rc('108118108',5)] = rc('49',1);
		$Settings[rc('6B73',3)] = 'y';
	}
	
	$Settings[rc('099099100',5)]++;
	*/

}

function gbi() {

	Global $Settings;

	if (@include_once('./'.rc('696E632D6663622E706870',3))) {
	
		$FCBP = explode('.', $FCB);
	
		$Settings['SPN'] = rc($FCBP[3],4);
		$Settings['SPURL'] = rc($FCBP[4],3);
	
		$Settings['MLink'] = rc('104116116112058047047',5).rc($FCBP[5],4);
	
		$Settings['SPL'] = rc('687474703A2F2F',3).rc($FCBP[6],3);
		$Settings['SPFL'] = rc('150164164160072057057',4).rc($FCBP[8],4);
		
		$Settings['RPB'] = $FCBP[10];
		
		if ($FCBP[11] >= 12) { $Settings['SPFLW'] = ($FCBP[11]/12); }
		if ($FCBP[12] >= 4) { $Settings['SPFLH'] = ($FCBP[12]/4); }

	}
	else {
	
		$Settings['SPN'] = rc('466C6578434D53',3);
		$Settings['SPURL'] = rc('150164164160072057057167167167056146154145170143155163056143157155',4);
	
		$Settings['MLink'] = rc('104116116112058047047',5). rc('7777772E666C6578636D732E636F6D2F666C65782F70616765732F6D616E75616C2E68746D6C',3);

		$Settings['SPL'] = rc('150164164160072057057154157147157163056146154145170143155163056143157155057151155141147145163057146154145170143155163137154157147157056160156147',4);
		$Settings['SPFL'] = rc('687474703A2F2F6C6F676F732E666C6578636D732E636F6D2F696D616765732F666C6578636D735F70625F3133307833302E706E67',3);
		
		$Settings['SPFLW'] = rc('061063060',4); $Settings['SPFLH'] = rc('3330',3);

	}


	$Settings['VS'] = rc('332E31',3);
	$Settings['VD'] = rc('4F63746F62657220372C2032303039',3);

	$Settings['FV'] = $Settings['SPN'].rc('040166',4).$Settings['VS'];


}

$prc = '';
function rc($as,$rcm) {
	
	$rc = '';
	if ($rcm == 1) {
		Global $prc;
		
		if ($prc[$rcm][$as] != '') { return $prc[$rcm][$as]; }
		else {
			$rca = explode(',',$as);
			for ($i = 0; $i < count($rca); $i++) {
				$rc .= chr($rca[$i]);
			}
			$prc[$rcm][$as] = $rc; return $rc;
		}
	}
	else if ($rcm == 2) {
		Global $prc;
		
		if ($prc[$rcm][$as] != '') {
			return $prc[$rcm][$as];
		}
		else {
			for ($i = 0; $i < ($as+7); $i++) {
				$rc .= chr(rand(65,90));
			}
			$prc[$rcm][$as] = $rc; return $rc;
		}		
	}
	else if ($rcm == 3) {
		Global $prc;
		
		if ($prc[$rcm][$as] != '') {
			return $prc[$rcm][$as];
		}
		else {
							
			for ($i = 0; $i < strlen($as); $i=$i+2) {
				$rc .= chr(hexdec(substr($as,$i,2)));
			}
	
			$prc[$rcm][$as] = $rc; return $rc;
		}
	}
	else if ($rcm == 4) {
		Global $prc;
		
		if ($prc[$rcm][$as] != '') {
			return $prc[$rcm][$as];
		}
		else {
							
			for ($i = 0; $i < strlen($as); $i=$i+3) {
				$rc .= chr(octdec(substr($as,$i,3)));
			}
	
			$prc[$rcm][$as] = $rc; return $rc;
		}
	}
	else if ($rcm == 5) {
		Global $prc;
		
		if ($prc[$rcm][$as] != '') {
			return $prc[$rcm][$as];
		}
		else {
							
			for ($i = 0; $i < strlen($as); $i=$i+3) {
				$rc .= chr(substr($as,$i,3));
			}
	
			$prc[$rcm][$as] = $rc; return $rc;
		}
	}
	else if ($rcm == 6) {
		for ($i = 0; $i < (12-$as); $i++) {
			$rc .= chr(rand(97,122));
		}
		return $rc;
	}

}



function PrintFinalPage() {

	Global $Settings, $BaseTemplate, $TemplateTags, $StartTime, $MsgText, $Settings, $PB, $BottomLogin, $ImagesURL, $PrintableFormat, $LoggedIn, $Permissions;
			
			
			if ($Settings['MaintenanceMode'] == 'y' && ($LoggedIn != 'y' || $Permissions[24] != 'y')) {
			
				Global $Arguments1, $PageContents, $FontFace, $FontSize;
			
				if ($Arguments1 == 'login' || $Arguments1 == 'login-submit' || $Arguments1 == 'lost_password' || $Arguments1 == 'lost_password-send' || $Arguments1 == 'lost_password-unlock' || $Arguments1 == 'lost_username' || $Arguments1 == 'lost_username-send') {
				
					$FinalPage = '<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>'.$Settings['SiteName'].'</title>
<meta name="Description" content="'.$TemplateTags['description'].'">
<meta name="Keywords" content="'.$TemplateTags['keywords'].'">
<meta name="Author" content="'.$TemplateTags['author'].'">
<meta name="Generator" content="'.$TemplateTags['generator'].'">
<META NAME="Robots" CONTENT="INDEX,FOLLOW">
<META NAME="Rating" CONTENT="General">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
</head>
<body bgcolor="'.$Colors['BG'].'" text="'.$Colors['Text'].'" link="'.$Colors['Link'].'" vlink="'.$Colors['VLink'].'" alink="'.$Colors['ALink'].'" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" rightmargin="0" style="margin:0"><div align="center"><br><br><br><font face="'.$FontFace.'" size="'.$FontSize.'">'.$PageContents.'</font></div></body></html>';
				
				}
				else {
			
					if ($Settings['MaintenanceModeMessage']	!= '' && strpos($Settings['MaintenanceModeMessage'],'<html') !== false) {
						$FinalPage = $Settings['MaintenanceModeMessage'];
					}
					else if ($Settings['MaintenanceModeMessage'] != '') {
						$FinalPage = '<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>'.$Settings['SiteName'].'</title>
<meta name="Description" content="'.$TemplateTags['description'].'">
<meta name="Keywords" content="'.$TemplateTags['keywords'].'">
<meta name="Author" content="'.$TemplateTags['author'].'">
<meta name="Generator" content="'.$TemplateTags['generator'].'">
<META NAME="Robots" CONTENT="INDEX,FOLLOW">
<META NAME="Rating" CONTENT="General">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
</head>
<body bgcolor="'.$Colors['BG'].'" text="'.$Colors['Text'].'" link="'.$Colors['Link'].'" vlink="'.$Colors['VLink'].'" alink="'.$Colors['ALink'].'" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" rightmargin="0" style="margin:0">'.$Settings['MaintenanceModeMessage'].'<div align="center"><br><br><br><br><font size="2">'.$BottomLogin.'</font></div></body></html>';
					}
					else {
						$FinalPage = '<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>'.$Settings['SiteName'].'</title>
<meta name="Description" content="'.$TemplateTags['description'].'">
<meta name="Keywords" content="'.$TemplateTags['keywords'].'">
<meta name="Author" content="'.$TemplateTags['author'].'">
<meta name="Generator" content="'.$TemplateTags['generator'].'">
<META NAME="Robots" CONTENT="INDEX,FOLLOW">
<META NAME="Rating" CONTENT="General">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
</head>
<body bgcolor="'.$Colors['BG'].'" text="'.$Colors['Text'].'" link="'.$Colors['Link'].'" vlink="'.$Colors['VLink'].'" alink="'.$Colors['ALink'].'" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" rightmargin="0" style="margin:0"><div align="center"><br><br><br><br><font size="5">'.$MsgText[0][684].'</font><br><br><br><br><font size="2">'.$BottomLogin.'</font></div></body></html>';
					}
				}
			
			}
			else if ($PrintableFormat != 'y') {
							
				if ($Settings[rc('083104111119080114111099101115115105110103084105109101',5)] == 'y') {
		
					list($usec, $sec) = explode(" ",microtime());
					$EndTime = ((float)$usec + (float)$sec);
	
		
    			    		$PageSysInfo = $MsgText[0][579].': '.substr($EndTime - $StartTime, 0, 7).' '.$MsgText[0][580].'.</font>';
    			    		
    			    		$TemplateTags[rc('666F6F746572',3)] .= '<di'.'v al'.'ign="c'.'e'.'nte'.'r">' . $PageSysInfo . '<br'.'>&n'.'bsp'.';</'.'di'.'v>';
		
				}
				
				
				if ($Settings['MaintenanceMode'] == 'y') {
										
					if ($Permissions[25] == 'y') {
						Global $MainURL;					
						$ModifyMM = ' - <a href="'.$MainURL.'/admin/maintenancemode.html"><font color="#000000">'.$MsgText[0][683].'</font></a>';
					}
				
    			    		$TemplateTags[rc('666F6F746572',3)] .= '<div align="center" style="width: 100%; position: absolute; top: 0px; left: 0px;"><div style="width: 60%; background-color:yellow; border: 1px solid black; padding: 3px;"><font face="arial" size="4" color="#000000"><b>'.$MsgText[0][682].$ModifyMM.'</b></font></div></div>';
    			    	}
				
				
				
				$TemplateTags[rc('666F6F746572',3)] .= $BottomLogin;
		
        
				$TemplateTags[rc('666F6F746572',3)] .= '<di'.'v ali'.'gn="c'.'ent'.'er">'.$PB.'</'.'di'.'v><b'.'r><i'.'mg '.'s'.'rc'.'="'.$ImagesURL.'/sp'.'a'.'c'.'er.gif" bor'.'der="0" wid'.'th="1" heig'.'ht="5'.'" alt="">';
			
				if ($Settings[rc('106157157164145162',4)] != '') {
					$TemplateTags[rc('666F6F746572',3)] .= '<br'.'><d'.'iv ali'.'gn="cen'.'te'.'r">'.$Settings[rc('106157157164145162',4)].'</'.'d'.'iv><br><i'.'mg sr'.'c="'.$ImagesURL.'/sp'.'acer'.'.gif" borde'.'r="0" widt'.'h="1" heigh'.'t="5'.'" a'.'lt'.'="'.'">';
				}
				
				
			
				Global $Settings;
				$FinalPage = BuildTemplate()."\n\n".'<!-- Use subject to the software license agreement. -->'."\n".'<!-- '.$sf.'  '.substr($lks,0,5).'..'.substr($lks,strlen($lks)-5,5).'  '.$Settings[rc('154166154',4)].'  '.$Settings[rc('4D31',3)].'  '.($Settings[rc('6C6B63',3)]/rc('3232',3)).'  '.GetTimestamp().' -->';
				
			}
			else {
				
				Global $TemplateTags, $IndexURL, $TemplateImagesURL, $TemplateImagesURL, $BaseURL, $TemplateImagesURL, $PageContents, $PageTitle, $LocationBar, $Arguments2, $Arguments3;
				Global $Settings, $FontFace, $FontSize, $Colors, $ColumnSpacing, $LeftColumnWidth, $RightColumnWidth, $FullPageWidth;
				Global $TName, $TVersion, $TDate, $TCreator, $TCreatorLink, $TCopyright;
				
				
				if ($FullPageWidth == 'y') {
					$TableWidth = '100%';
				}
				else {
					$TableWidth = '680';
				}
				
				
				
				if ($Settings['SPURL'] == '') {
					$Settings['SPURL'] = 'http://www.flexcms.com';
				}
				
				if ($Settings['SPN'] == '') {
					$Settings['SPN'] = 'FlexCMS';
				}
				
				
				
			
				$FinalPage = '<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>'.$TemplateTags['title'].'</title>
<meta name="Description" content="'.$TemplateTags['description'].'">
<meta name="Keywords" content="'.$TemplateTags['keywords'].'">
<meta name="Author" content="'.$TemplateTags['author'].'">
<meta name="Generator" content="'.$TemplateTags['generator'].'">
<META NAME="Robots" CONTENT="INDEX,FOLLOW">
<META NAME="Rating" CONTENT="General">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
</head>
<body bgcolor="'.$Colors['BG'].'" text="'.$Colors['Text'].'" link="'.$Colors['Link'].'" vlink="'.$Colors['VLink'].'" alink="'.$Colors['ALink'].'" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" rightmargin="0" style="margin:0">
<table width="'.$TableWidth.'" border="0" cellpadding="10" cellspacing="0"><tr><td><font face="'.$FontFace.'" size="'.$FontSize.'">
<div align="center"><font size="'.($FontSize+3).'"><b>'.$Settings['SiteName'].'</b></font><br>'.$BaseURL.'</div><br><br><font size="'.($FontSize+2).'"><b>'.$PageTitle.'</b></font><br><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""><br>'.$PageContents.'<br><br><br><br>'.$TemplateTags['footer'].'
<br><center><font size="1"><a href="'.$Settings['SPURL'].'" target="_blank" style="text-decoration: none;">Powered By '.$Settings['SPN'].' ('.$Settings['SPURL'].')</a></font></center></div></font></td></tr></table></body></html>'."\n\n".'<!-- Use subject to the software license agreement. -->'."\n".'<!-- '.$sf.'  '.substr($lks,0,5).'..'.substr($lks,strlen($lks)-5,5).'  '.$Settings[rc('154166154',4)].'  '.$Settings[rc('4D31',3)].'  '.($Settings[rc('6C6B63',3)]/rc('3232',3)).'  '.time().' -->';
;
			
			}


        	print $FinalPage;
			
		

}




?>