<?php

session_start();
require_once "./core/php/functions.php";

header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");


require_once "./core/config.php";
require_once "./lib/db/config.php";
require_once "./lib/db/DbSimple/Generic.php";

$err=array();

$DB = DbSimple_Generic::connect('mysql://'.$config['db']['login'].':'.$config['db']['pass'].'@'.$config['db']['host'].'/'.$config['db']['name']);
$DB->setErrorHandler('databaseErrorHandler');
$DB->query("SET NAMES 'utf8'");

function databaseErrorHandler($message, $info) {
	if (!error_reporting()) return;
	$err[]='SQL Error: '.$message;
	error($info);
} 

if ($_SERVER['REQUEST_METHOD']=="POST" && $_POST['login'] && $_POST['pass']){
	login();
}


if(!$_SESSION['logined']) die();

$mod=preg_replace('/[^a-z_]/','',$_GET['mod']);
$sub=preg_replace('/[^a-z_]/','',$_GET['sub']);
$act=preg_replace('/[^a-zA-Z_]/','',$_GET['act']);

$array_data = array("GET" => $_GET,"POST" => $_POST);
$array_data = json_encode($array_data);

if($sub&&$mod&&file_exists("./modules/".$mod."/sub/".$sub."/php/".$sub.".php")){
	include "./modules/".$mod."/sub/".$sub."/php/".$sub.".php";
	$app = &new $mod; 
} elseif($mod&&file_exists("./modules/".$mod."/php/".$mod.".php")){
	include "./modules/".$mod."/php/".$mod.".php";
	$app = &new $mod; 
} elseif($mod=='maintree'&&file_exists("./core/php/".$mod.".php")){
	include "./core/php/".$mod.".php";
	$app = &new $mod; 
} else {
	die();
}

?>
