<?php
$HOME_DIR   = '/home/dateyou/';
$GLOBALS['HOME_DIR'] = $HOME_DIR;
$CLASS_ROOT = $HOME_DIR .'php/';
$GLOBALS['CLASS_ROOT'] = $CLASS_ROOT;
set_include_path(get_include_path() .":$CLASS_ROOT");

$path = $_GET['path'];
$args = explode('/', $path);

require_once('sys/RequestRegistry.php');
$reqReg = RequestRegistry::getInstance();

$n = count($args);
$package = 'home';
if ($n == 0)
    $action = 'index';
else {
    $action = end($args);
    if (strlen($action) == 0)
        $action = 'index';
    if ($n > 1 && strlen($args[0]) != 0)
        $package = $args[0];
    if ($n > 2) {
        for ($i = 1; $i < ($n-1); ++$i)
            $reqReg->set('arg'. $i, $args[$i]);
    }
}

if (strpos($action, '-'))
    $action = adjustAction($action);

$reqReg->setAction($action);
$reqReg->setPackage($package);

//foreach ($args as $arg)
    //echo '<br>'. $arg;

require_once('util/Timer.php');
$timer = new Timer();
$timer->startTimer();
require_once('sys/Controller.php');


Controller::run($action);
echo '<!-- Time: '. $timer->getTime() .'ms -->';

//log the referer
/*
$referer = $_SERVER['HTTP_REFERER'];
$ip = $_SERVER['REMOTE_ADDR'];
$reqst = $_SERVER['REQUEST_URI'];
$log = $CLASS_ROOT .'scriptlog/accesslog.txt';
if ($fh = fopen($log, 'a')) {
    fwrite($fh, date("m/d/y  H:i:s") .' - '. $ip .' - '. $reqst .' - '. $referer ."\n");
    fclose($fh);
}
*/


function adjustAction($str) {
    $parts = preg_split('/-/', $str, 5);
    $str = '';
    foreach ($parts as $part)
        $str .= ucfirst($part);
    return $str;
}
?>
