<?php
//echo('/includes/sysinit.php: ...1...<br />');

//phpinfo();
//if (file_exists(SABLE_WORKING_PATH.'config/sable_cfg.php'))
date_default_timezone_set('GMT');
$sysPath = '';
$SABLE_DEMO_SYSTEM = 'true';
if (defined('SABLE_WORKING_PATH'))
{
	//echo('/includes/sysinit.php: ...1A...<br />');
	//$sysPath = SABLE_WORKING_PATH.'config/';
	$sysPath = SABLE_WORKING_PATH;
	//require_once(SABLE_WORKING_PATH.'config/sable_cfg.php');
}
else
{
//	echo('/includes/sysinit.php: "__DIR__" = '.__DIR__.'<br />');
	if (file_exists(__DIR__.'/../config/sable_cfg.php'))
	{
		//echo('/includes/sysinit.php: ...1B...<br />');
		$sysPath = __DIR__.'/../'; 
		//require_once(__DIR__.'/../config/sable_cfg.php');
	}
	else
	{
		if (file_exists('../config/sable_cfg.php'))
		{
			//echo('/includes/sysinit.php: ...1C...<br />');
			$sysPath = '../';
			//require_once('../config/sable_cfg.php');
		}
		else
		{
			//echo('/includes/sysinit.php: ...1D...<br />');
			$sysPath = '';
			//require_once('config/sable_cfg.php');
		}
	}
}

require_once($sysPath.'config/sable_cfg.php');

//echo('/includes/sysinit.php: ...1E...<br />');
ini_set('upload_max_filesize', 	'5M');
ini_set('post_max_size', 		'5M');
if (SABLE_ENABLE_ERRORS === true) ini_set('display_errors', E_ALL & ~E_NOTICE); else ini_set('display_errors', 0);

//echo('/includes/sysinit.php: ...2...<br />');
include_once(SABLE_CLASS_PATH.'sable_debug.php');//SableDebug::
require_once(SABLE_CLASS_PATH.'sable_db.php');
$sableDB = new SableDB();
//echo('/includes/sysinit.php: ...3...<br />');
//Define system classes:
require_once(SABLE_CLASS_PATH.'sable_db_functions.php');//SableDBFunctions::
require_once(SABLE_CLASS_PATH.'sable_general_functions.php');//SableGeneralFunctions::
require_once(SABLE_CLASS_PATH.'sable_system.php'); //SableSystem::
require_once(SABLE_CLASS_PATH.'sable_validation_functions.php'); //SableValidationFunctions::

//echo('/includes/sysinit.php: ...5...<br />');
SableSystem::buildArgvArgc(); //server doesn't hold this information!
//echo('/includes/sysinit.php: ...6...<br />');

//if (SableSystem::currentDir() !== 'lib')
{
	//echo('111111<br />');
	if (empty(session_id())) 
	{
		unset($_SESSION);
		session_start();
		SableDBFunctions::updateSessionVars();
	}
	//echo('222222<br />');
	$prefix = SableSystem::setSessionPrefix(); //sets both $prefix and $_SESSION['prefix'] to the necessary prefix value.
	//echo('333333<br />');
	SableSystem::verifySession();
	//echo('444444<br />');
}

//initialise module specific instructions (used in module "_func.php" file):
$_SESSION['module']['add'] 		= 1;
$_SESSION['module']['edit'] 	= 1;
$_SESSION['module']['modify'] 	= 1;
$_SESSION['module']['delete'] 	= 1;

//echo('/includes/sysinit.php: ...7...<br />');
$coyTitle 	= SableGeneralFunctions::setCoyTitle();
$ual = 0;
if (isset($_SESSION['user']['access_level']))
{
	$ual 		= intval($_SESSION['user']['access_level']);
	$_SESSION['user']['access_level'] = intval($_SESSION['user']['access_level']);
}
//phpinfo();
//echo('/includes/sysinit.php: ...fin...<br />');
if (SableSystem::loggedIn()) include(SABLE_INCLUDES_PATH.'userinit.php');
header('x-powered-by: Jona Solutions - jona.co.za');