<?php // 2010/06/28
/*
Copyright (c) 2010, TCMS
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// This is not the website entry point; you'll find that
// at www/index.php, which just calls this file.
// The reason is to keep this file inaccessible to browsers.
// Most of this file is to do with setting up the environment.
// All the actual page content is generated elsewhere.
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/Monaco');
// Set the error and exception handlers.
set_error_handler("my_error_handler");
set_exception_handler('defaultException');
// Set up the path.
// All PHP files are kept where browsers can't access them.
$path = "../php";
set_include_path('.' . PATH_SEPARATOR . $path
. PATH_SEPARATOR . "$path/common"
. PATH_SEPARATOR . "$path/lib"
. PATH_SEPARATOR . "$path/template"
. PATH_SEPARATOR . get_include_path());
// Start the session.
session_start();
// Support files that will be needed everywhere.
include_once "fn.php";
include_once "db.php";
include_once "html.php";
include_once "base.php";
include_once "exception.php";
// The 'host' file contains the MySQL hostname and other things.
$props = FN::getProperties("$path/host", FALSE);
FN::setProperties($props);
$title = $props['title'];
$template = $props['template'];
$language = $props['language'];
$session = $props['session'];
DB::setTablePrefix($props['prefix']);
//print_r($_REQUEST); echo"<br>";
// Check if this is a call to admin.
// Also, if this is the first time we've run there will be
// a file called "install" which forces a trip to the admin.
if (file_exists("install") || isset($_REQUEST['admin']))
{
require_once "admin.php";
$head = new HEAD("$title Admin");
$body = new DIV("pagecentre", NULL, new Admin($head, $props));
}
else
{
// Connect to the database.
DB::connect($props['sqlhost'], $props['sqluser'], $props['sqlpassword'],
$props['sqldatabase']);
// Count hits.
require_once "statistics.php";
$statistics = new Statistics();
$statistics->countHit();
// Set the default language.
$sessLang = "$session-language";
if (!isset($_SESSION[$sessLang]))
{
$id = DB::selectValue("language", "id", "WHERE code='$language'");
if (!$id) $id = 1;
$_SESSION[$sessLang] = $id;
}
// Check the language ID is a number; if not, force it.
// This should never be the case but it causes problems...
if (!is_numeric($_SESSION[$sessLang])) $_SESSION[$sessLang] = 1;
// If a template is given, use it.
if (isset($_REQUEST['template'])) $template = $_REQUEST['template'];
require_once "$template.php";
// Create the HEAD.
$head = new HEAD($title);
// Add the default CSS file.
$head->addCSS("css/default.css");
// This is where we build the page content.
// If the request parameter "popup" is set,
// just use the template as it is.
// Otherwise, place it in a DIV so it floats in the center of the window.
if (isset($_REQUEST['popup']))
$body = new $template($head);
else
$body = new DIV("pagecentre", NULL,
new DIV("pagecentre2", NULL, new $template($head)));
}
// Create a document object and send it back.
$document = new DOCUMENT($head, new BODY($body));
echo $document->getHTML();
// end
////////////////////////////////////////////////////////////////////////////
// Our custom error handler.
function my_error_handler ($errno, $errstr, $errfile, $errline, $errcontent)
{
echo "<font color='red'><b>An Error Occured!</b></font><br />";
echo "<font color='#000'>";
echo "<b>Error In File:</b> $errfile<br />";
echo "<b>Error On Line:</b> $errline<br />";
echo "<b>Error Number:</b> $errno<br />";
echo "<b>Error Description:</b> $errstr<br />";
echo "</font>";
exit;
}
////////////////////////////////////////////////////////////////////////////
// Catch any exceptions that weren't handled anywhere else.
function defaultException($e)
{
header('HTTP/1.x 555 Program Error');
print $e->showExceptionInfo(TRUE);
exit;
}
?>
|