<?php
// define who may/may not access this page:
if (SableSystem::loggedIn())
{
	SableGeneralFunctions::divertFromPage('home/', '');
}
else
{
	$siteId = 0;
	if (isset($_SERVER['argv'][0])) 
	{
		$params=explode('|', SableSystem::sableDecode($_SERVER['argv'][0]));
		$siteId = ($params[0]==SABLE_DOMAIN_ROOT)?0:$params[0];
	} 
	
	if (isset($_SERVER['argv'][0])) 
	{
		$siteId = isset($_SESSION['site'])?$_SESSION['site']['site_id']:0;
	}
	/*
		Two parameters are passed encoded, 1= the site id and 2=DEMO true or false.
		if Demo, then change the url to the demo url:
	*/
	if ( ((!isset($_SESSION['site']))&&($siteId>0)) || (isset($_SESSION['site']))&&($siteId!=$_SESSION['site']['site_id']) )
	{
		unset($_SESSION['site']); //just in case this is set it is important to reset.
		$_SESSION['site'] = $sableDB->getRow('select * from sites where site_id = '.$siteId);
		$coyTitle = setCoyTitle(); 
		//the following unsets are for security so that we don't keep this data in session variables:
		unset($_SESSION['site']['dbv1']);
		unset($_SESSION['site']['dbv2']);
		unset($_SESSION['site']['dbv3']);
	}

	if (isset($_COOKIE['username'])) $usr = $_COOKIE['username'];
}