<?php

/*
   +----------------------------------------------------------------------+
   | Global Page                                                          |
   | Author: Adam Goldberg                                                |
   +----------------------------------------------------------------------+
   | Copyright (c) 2008-2009 Adam J Goldberg                              |
   | This file is part of Lifebox.                                        |
   |                                                                      |
   | Lifebox is free software: you can redistribute it and/or modify      |
   | it under the terms of the GNU General Public License as published by |
   | the Free Software Foundation, either version 3 of the License, or    |
   | (at your option) any later version.                                  |
   |                                                                      |
   | Lifebox is distributed in the hope that it will be useful,           |
   | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
   | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
   | GNU General Public License for more details.                         |
   |                                                                      |
   | You should have received a copy of the GNU General Public License    |
   | along with Lifebox.  If not, see <http://www.gnu.org/licenses/>.     |
   +----------------------------------------------------------------------+
   | Includes functions and variable assignments to be included on every  |
   | page on the site.							  |
   +----------------------------------------------------------------------+
*/

if (!include('config.inc.php')) {
	die ('<br />No config/config.inc.php could be found.  Did you copy your config/config.sample.php and edit it?');
}

#Set Paths
ini_set('include_path', ini_get('include_path').
        ':.:/php/includes'.
        ':'.$CONFIG['path'].'adodb'.
	':'.$CONFIG['path'].'Cache-1.5.4'.
	':'.$CONFIG['path'].'Smarty-2.6.20/libs'.
	':'.$CONFIG['path'].'html/classes/'.
	':'.$CONFIG['path'].'html/config/'
        );

require_once 'adodb.inc.php';
require_once 'Smarty.class.php';
require_once 'Timer.inc.php';

/*****************************************************************
 * Start the performance timer.
 *****************************************************************/
$timer = new Timer();
$timer->start();

/*****************************************************************
 * Create Database objects and initialize connections.
 *****************************************************************/

        $db = &ADONewConnection($CONFIG['db_type'] );
        $db->Connect($CONFIG['db_host'],
                      $CONFIG['db_user'],
                      $CONFIG['db_pass'],
                      $CONFIG['db_name']);
        $db->debug = $CONFIG['db_debug'];
        $db->error = $CONFIG['db_error'];

/*****************************************************************
 * Create Smarty object and initialize
 *****************************************************************/
        $smarty = new Smarty;
        $smarty->template_dir = $CONFIG['smarty_templates'];
        $smarty->compile_dir = $CONFIG['smarty_templates_c'];
        #$smarty->config_dir = $CONFIG['smarty_configs'];
        #$smarty->cache_dir = $CONFIG['smarty_cache'];
        $smarty->assign('CONFIG',$CONFIG);
        #$smarty->assign('ERROR',$ERROR);
	$smarty->assign('TEMPLATES',$CONFIG['smarty_templates']);
	$smarty->assign('_POST',$_POST);
	$smarty->assign('_GET',$_GET);
	$smarty->assign('_COOKIE',$_COOKIE);
	$smarty->assign('_SERVER',$_SERVER);
	#$smarty->assign('_SESSION',$_SESSION);
#	$smarty->load_filter('output','trimwhitespace');

/*****************************************************************
 * Include authentication module
 *****************************************************************/
require_once 'auth.inc.php';

/*****************************************************************
 * Create some nice pretty variables
 *****************************************************************/
	if (isset($_GET['a'])) {$a = $_GET['a'];} else { $a = false; }
	if (isset($_GET['s'])) {$s = $_GET['s'];} else { $s = false; }
        if (isset($_GET['a2'])) {$a2 = $_GET['a2'];} else { $a2 = false; }
        if (isset($_GET['s2'])) {$s2 = $_GET['s2'];} else { $s2 = false; }

	#If no A is specified, generate it
	if (!$a) {
		$a_string = substr($_SERVER['REQUEST_URI'],1);
		$slash_pos = strpos($a_string,'/');

		if ($slash_pos) {
			$a = substr($a_string,0,$slash_pos);
		} else {
			$a = $a_string;
		}
	}

	$smarty->assign('s',$s);
	$smarty->assign('a',$a);

/*****************************************************************
 * Assign the global $_USER to smarty
 *****************************************************************/
	$smarty->assign('_USER',$_USER);
	$smarty->assign('_LEVELS',$_LEVELS);

	#If a cache_refresh was specified in the config,
	#implement it here.
	if ($CONFIG['cache_refresh']) {
		header("Cache-Control: max-age=".$CONFIG['cache_refresh'].""); // Cache for 1 hr
	}
?>
