<?php

define('DS', DIRECTORY_SEPARATOR);
define('APP_PATH_ROOT', dirname(__FILE__));
define('APP_PATH_LIB', APP_PATH_ROOT . '/se-lib');
define('APP_PATH_WWW', APP_PATH_ROOT);
define('APP_PATH_CONFIG', APP_PATH_ROOT . DS . 'config');

//session_save_path("./tmp") ;
session_start();

date_default_timezone_set('Europe/Warsaw');// PHP 5 >= 5.1.0 required by date functions

error_reporting(1);
ini_set('error_reporting', 1);
ini_set('display_startup_errors','1'); 
//display_startup_errors(0);

#TEST $_SESSION['DEBUG'] = 3;// TODO: TEST
if (!isset($_SESSION['DEBUG'])) $_SESSION['DEBUG'] = 0;// set default value


if (file_exists(APP_PATH_ROOT . "/config/.config_{$_SERVER['SERVER_NAME']}.php")) {
	require APP_PATH_ROOT . "/config/.config_{$_SERVER['SERVER_NAME']}.php";
}

if (file_exists(APP_PATH_ROOT . "/.config.php")) include APP_PATH_ROOT . "/.config.php";


require_once APP_PATH_ROOT . "/superedit-SEF.php";
SEF('DEBUG_S');

require_once APP_PATH_LIB . '/' . 'Lib.php';
Lib::loadClass('V');
Lib::loadClass('DB');
Lib::loadClass('User');
Lib::loadClass('SE_Layout');
Lib::loadClass('S');

S::init();// init session variables if not exists
User::auth();// die if not logged in

S::timeoutUpdate(true);// User is authorized - update logout time

#Bzyk @ 2009-02-11 - dodatkowe funkcje dla BIALL-NET
if (file_exists(APP_PATH_ROOT . "/function2.php")) require APP_PATH_ROOT . "/function2.php";

//STD INCLUDE 2010-01-14
require APP_PATH_ROOT . "/superedit-logistyka.php";

SEF("M_DIST_CLAIM_DATE");
SEF("M_DIST_FILES");
SEF("K_OD_KOGO");
SEF("GORA");
SEF("WIEVTABLE");

if (file_exists(APP_PATH_ROOT . "/229dodaj_functions.php")) include APP_PATH_ROOT . "/229dodaj_functions.php";


// register globals
$MENU_INIT = isset($_REQUEST['MENU_INIT'])? $_REQUEST['MENU_INIT'] : null;
$ARG1 = isset($_REQUEST['ARG1'])? $_REQUEST['ARG1'] : null;
$ARG1_VAL = isset($_REQUEST['ARG1_VAL'])? $_REQUEST['ARG1_VAL'] : null;

if ('YES' != V::get('HEADER_NOT_INIT', '', $_REQUEST)) SE_Layout::gora();
if (!V::get('AUTHORIZE_IP', '', $_SESSION)) AUTHORIZE_IP($_SERVER['REMOTE_ADDR']);

SEF("TREE");
SEF("TREEJS");

if ($_SESSION['DEBUG']) echo "FUNCTION_INIT()";
DETECT_TABLE_COLUMN();// TODO: $thiss tworzone na podstawie 'CURRENT_MENU' ustawianej w MENU_INIT, teraz raczej zbedne wywolanie
SEF('FUNCTION_INIT');
FUNCTION_INIT();
if ($_SESSION['DEBUG']) echo "MENU_INIT()";
SEF('MENU');
SEF('MENU_INIT');
MENU_INIT();

SE_Layout::dol();
if ($_SESSION['DEBUG']) {
	echo"<hr>_POST:\n<br><pre>";
	print_r($_POST);
	echo "<hr>_SESSION:\n<br>";
	print_r($_SESSION);
	echo"<hr>\n_GET:<br>\n";
	print_r($_GET);
	echo'</pre>';
}
