<?php

/**
    \mainpage

     @version r254
     Gantilah tempalte ini dengan kata-aktamu sendiri. Cari di index.php


    Released under both BSD license and Lesser GPL library license. You can choose which license
    you prefer.

    PHP's database access functions are not standardised. This creates a need for a database
    class library to hide the differences between the different database API's (encapsulate
    the differences) so we can easily switch databases.

    We currently support MySQL, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, DB2,
    Informix, PostgreSQL, FrontBase, Interbase (Firebird and Borland variants), Foxpro, Access,
    ADO, SAP DB, SQLite and ODBC. We have had successful reports of connecting to Progress and
    other databases via ODBC.

    Latest Download at http://php.weblogs.com/adodb<br>
    Manual is at http://php.weblogs.com/adodb_manual

 */
// for perfomance testing
function getmicrotime() {
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
}
$time_start = getmicrotime();
//////
/*
Development note:
- riddle: session first or security first?
- riddle: is it necessary to put sql file into separate directory?
- riddle: how to call a web service if we don't know how to obfuscate url?
- riddle: is it necessary to "require_once"/"include_once" all required script?
- riddle: session destroy. which is better, with or without set cookie?
- riddle: with the new url type feature, it breaks the web service again :(
- todo: short type url seems slow down everything, consider to "session-ing" short to long url map
    (see Dispatcher::TranslateRequest)
- todo: make security more secure, it seems every session would be tagged with a unique id
    composed of client address, host, etc. every request must be checked against that
    unique id. this method seems suitable for preventing session hijacking
- todo: needs a more powerful http redirector
- consideration: moving main/* to /* (ie. no more "main" directory)
- todo: new web service handler/method to answer the riddle mentioned above,
    might be a new special dispatcher
- todo: make database class more friendly, ie. no need to load sql separately and
    not a constructor's parameter, done but still not satisfiying
- todo: make database class no more adodb-ish
- todo: performance tunning (but this is almost impossible since we use patTemplate as
    our templating engine)
*/


// init error handler: beyond these lines, $err is a reserved variable
// $err is considered as a "super" global variable used throughout the script
$err = NULL; // not yet implemented

// load configuration: beyond these lines, $cfg is a reserved variable
// $cfg is considered as a "super" global variable used throughout the script
require_once 'main/lib/gtfw/configuration/Configuration.class.php';
// $cfg =& new Configuration();
// $cfg->mConfigDirectory = 'config/';
//
// $cfg->Load('organization.conf.ini', 'ini');
// $cfg->Load('application.conf.php', 'default');

GTFWConfiguration::SetConfigDirectory('config/');
GTFWConfiguration::Load('application.conf.php', 'default');
GTFWConfiguration::Load('organization.conf.ini', 'ini');

// init sanitizer: beyond these lines, $sntz is a reserved variable
// $sntz is considered as a "super" global variable used throughout the script
require_once 'main/lib/gtfw/sanitizer/Sanitizer.class.php';
require_once 'main/lib/gtfw/sanitizer/SanitizerFactory.class.php';
$sntz =& new SanitizerFactory();

// prepare/resume session: beyond these lines, $sess is a reserved variable
// $sess is considered as a "super" global variable used throughout the script
require_once 'main/lib/gtfw/session/Session.class.php';
$sess =& new Session();
$sess->Start();

// init database: beyond these lines, $db is a reserved variable
// $db is considered as a "super" global variable used throughout the script
require_once 'main/lib/gtfw/database/Database.class.php';
$db = array(); // maintain a list of connection to different databases

// init security: beyond these lines, $sec is a reserved variable
// $sec is considered as a "super" global variable used throughout the script
require_once 'main/lib/gtfw/security/UserGroup.class.php';
require_once 'main/lib/gtfw/security/User.class.php';
require_once 'main/lib/gtfw/security/Security.class.php';
$sec =& new Security();
$sec->LoadSql('main/lib/gtfw/security/security.sql.php');
$sec->Initialize();

// init log application
require_once 'main/lib/gtfw/log/log.class.php';
$log = new Log();

// about to dispatch: beyond these lines, $dispt is a reserved variable
// $dispt is considered as a "super" global variable used throughout the script
require_once 'main/lib/gtfw/dispatcher/Dispatcher.class.php';
$dispt =& new Dispatcher();
//$dispt->LoadSql('main/lib/gtfw/dispatcher/dispatcher.sql.php');
//$dispt->LoadSql();
$dispt->Dispatch();

/*
//print_r($db);
// echo '<pre>';
// print_r($_SESSION);
// print_r($_COOKIE);
// echo session_id();
// echo "\n";
// $request_header = apache_request_headers();
// foreach ($request_header as $k => $v) {
//    echo "$k: $v\n";
// }
//var_dump($sec);
//var_dump($cfg);
// echo '</pre>';
// /// for performance testing
// $time_end = getmicrotime();
// $time = $time_end - $time_start;
// echo "Page rendered in $time seconds";


/**/
/// for performance testing
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "Page rendered in $time seconds";
///
/**/
?>
