<?PHP
/*
* phpMyPurchasing
* Jason Gerfen [hide@address.com]
*
* index.php - index or main page
*/
if (file_exists('scripts/inc.config.php')) {
require 'scripts/inc.config.php';
// ensure we are being called from our configured host
if ($defined['hostname']===$_SERVER['SERVER_NAME']) {
// obtain default options
$defined = array_merge($defined, $handles['misc']->getDefaults());
$defined = array_merge($defined, $handles['misc']->getAuthentication());
$accessList = $handles['misc']->getAccessList();
// copy and filter incoming data
$get = @array_map($handles['val']->ValidateXSS, $_GET);
$post = @array_map($handles['val']->ValidateXSS, $_POST);
$sess = @array_map($handles['val']->ValidateXSS, $_SESSION);
$serv = @array_map($handles['val']->ValidateXSS, $_SERVER);
// handle logging of requests, remote data
$handles['logs']->process($serv);
//define the template and cache directories
$handles['tpl']->strTemplateDir = $defined['templates'];
$handles['tpl']->strCacheDir = '/tmp';
$flag = (!empty($post)) ? $flag = "TRUE" : $flag = "FALSE";
// gather up some information for the token
if ((!isset($_SESSION['token']))||(!is_resource($handles['session']))) {
$handles['session'] = new dbSession($defined['timeout']);
}
$_SESSION['referrer'] = $serv['HTTP_REFERER'];
// perform authentication
$authenticated = $handles['auth']->DecideAuth($_SESSION['token'], $post['user'], $post['pass'], $serv);
$class = ($authenticated===0) ? $class = "good" : $class = "error";
// include our header file
$handles['tpl']->assign('TITLE', $defined['title'], NULL, NULL);
$handles['tpl']->assign('ip', $serv['REMOTE_ADDR'], NULL, NULL);
$handles['tpl']->assign('logo', $defined['logo'], NULL, NULL);
$handles['tpl']->assign('templates', $defined['templates'], NULL, NULL);
$handles['tpl']->assign('timeout', $defined['timeout'], NULL, NULL);
$handles['tpl']->display('header.tpl', $flag, NULL);
// process authentication and load appropriate template
if ($authenticated !== 0) {
$error = '<div class="'.$class.'">' . $handles['err']->detLoginErr($authenticated) . '</div>';
$use = 'content-login.tpl';
} else {
// determine our template
switch($get['do']) {
case '0x00a0':
$ele = 'tabMain';
$use = 'content-authenticated.tpl';
break;
case '0x00b0':
$ele = 'tabPurchasing';
$use = 'content-purchasing.tpl';
break;
case '0x00c0':
$ele = 'tabReports';
$use = 'content-reports.tpl';
break;
case '0x00d0':
$ele = 'tabConfiguration';
$use = 'content-configuration.tpl';
break;
case '0x00e0':
$ele = 'tabPermissions';
$use = 'content-permissions.tpl';
break;
case '0x00f0':
$ele = 'tabExit';
$use = 'content-exit.tpl';
break;
default:
$ele = 'tabMain';
$use = 'content-login.tpl';
break;
}
}
$handles['tpl']->assign('ERROR',$error,NULL,NULL);
$handles['tpl']->assign($ele, $handles['tpl']->assign( NULL, NULL, $use, $flag ), NULL, NULL);
$handles['tpl']->display('main.tpl', $flag, NULL);
// call our footer file
$handles['tpl']->assign('copyright', $defined['copyright'], NULL, NULL);
$handles['tpl']->assign('FOOTER', $footer, NULL, NULL);
$handles['tpl']->display('footer.tpl', $flag, NULL);
} else {
echo "Cannot be called from anywhere other then our defined host";
}
} else {
echo "Configuration file not found";
}
if ($defined['debug']==="true") {
$handles['debug']->ShowDebug($_GET, $post, $_REQUEST, $sess, $handles);
}
?>