<?php
// Error Reporting
error_reporting(E_ALL);

// Configuration
require('config.php');

// Install 
if (!defined('HTTP_SERVER')) {
	header('Location: install/index.php');
	exit;
}

// Security
ini_set('register_globals', 'Off');

if (ini_get('register_globals')) {
	exit('Error: register_globals is enabled!');
} 

// Page Time
$time = (time() + microtime());

// Locator
include(DIR_LIBRARY . 'locator.php');
$locator =& new Locator();

// Config
$config =& $locator->get('config');

// Database
$database =& $locator->get('database');

// Settings
$settings = $database->getRows("select * from setting where type = 'catalog' or type = 'global'");

foreach ($settings as $setting) {
	$config->set($setting['key'], $setting['value']);
}

// Language
$language =& $locator->get('language');

// Template
$template =& $locator->get('template');

// Character Set
$template->set('charset', $language->get('charset'));

// Text Direction 
$template->set('direction', $language->get('direction'));

// Language Code
$template->set('code', $language->get('code'));

// Base URL
if (@$_SERVER['HTTPS'] != 'on') {
	$template->set('base', HTTP_SERVER);
} else {
	$template->set('base', HTTPS_SERVER);
}

// Request
$request =& $locator->get('request');

// Response
$response =& $locator->get('response');

// Controller
$controller =& $locator->get('controller');
	
// Router
$router =& $locator->get('router');

// Controller Directory
$controller->setDirectory(DIR_CONTROLLER);

// Default Controller
$controller->setDefault('home', 'index');

// Error Controller
$controller->setError('error', 'index');

// Route Request
$router->route($request);

// Dispatch
$controller->dispatch($request);

// Output
$response->output();

// Parse Time
if ($config->get('config_parse_time')) {
	echo($language->get('text_time', round((time() + microtime()) - $time, 4)));
}
?>