<?php
//print 'dirname='.dirname(__FILE__).'<br>';
//print 'docroot='.$_SERVER['DOCUMENT_ROOT'].'<br>';
/*
    part-db version 0.1
    Copyright (C) 2005 Christoph Lechner
    http://www.cl-projects.de/

    part-db version 0.2+
    Copyright (C) 2009 K. Jacobs and others (see authors.php)
    http://code.google.com/p/part-db/

    This program 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 2
    of the License, or (at your option) any later version.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

    $Id: startup.php 510 2012-08-03 weinbauer73@gmail.com $

    Changelog (sorted by date):
        [DATE]      [NICKNAME]          [CHANGES]
        2012-09-03  kami89              - created
		2013-01-26  teiger 				- modifi for Windows
*/

   /*
    * This file must be included in every PHP file which produces HTML output!
    */

    /********************************************************************************
    *
    *   define an exception handler for uncaught exceptions
    *
    *********************************************************************************/

    function exception_handler($e)
    {
        print "<br><br><strong>Es ist ein schwerwiegender Fehler aufgetreten:</strong><br><br>".
                nl2br($e->getMessage()).'<br><br>'.
                '(Exception wurde geworfen in '.$e->getFile().', Zeile '.$e->getLine().')';
    }

    set_exception_handler('exception_handler');

    /********************************************************************************
    *
    *   define directory constants of the part-db installation
    *
    *********************************************************************************/

    // directory to the part-db installation, without slash at the end (e.g. "/var/www/part-db")
    define('BASE', dirname(__FILE__));

    // server-directory without slash at the end (e.g. "/var/www")
    //define('DOCUMENT_ROOT', rtrim($_SERVER['DOCUMENT_ROOT'], '/'));
	define('DOCUMENT_ROOT', rtrim($_SERVER['DOCUMENT_ROOT'], '\/'));
	
    // the part-db installation directory without document root, with slash at the end (e.g. "/part-db/")
    define('BASE_RELATIVE', '');
	//define('BASE_RELATIVE', str_replace(DOCUMENT_ROOT, '', BASE.DIRECTORY_SEPARATOR));
	
    /********************************************************************************
    *
    *   include config files
    *
    *********************************************************************************/

    include_once(BASE.'/config_defaults.php'); // first, we load all default values of the $config array...

    if (is_readable(BASE.'/config.php'))
        include_once(BASE.'/config.php'); // ...and then we overwrite them with the user settings, if they exist

    if (count($manual_config) > 0) // $manual_config is defined in "config_defaults.php" and can be filled in "config.php"
        $config = array_merge($config, $manual_config); // if there are manual configs, add them to $config

    /********************************************************************************
    *
    *   set internal encoding / timezone / locale / error reporting
    *
    *********************************************************************************/

    if ($config['debug']['enable'])
    {
        error_reporting(E_ALL & ~E_STRICT);
        ini_set("display_errors", 1);
    }

    mb_internal_encoding($config['html']['http_charset']);
    date_default_timezone_set($config['timezone']);
    setlocale(LC_ALL, $config['language']);

    /********************************************************************************
    *
    *   start session
    *
    *********************************************************************************/

    session_name('Part-DB');
    session_start();

    /********************************************************************************
    *
    *   autoload function for classes
    *
    *********************************************************************************/

    function __autoload($classname)
    {
        if (strpos($classname, 'vlib') === 0)
            include_once(BASE.'/lib/vlib/'.$classname.'.php');
        else
            include_once(BASE.'/lib/class.'.$classname.'.php');
    }

    /********************************************************************************
    *
    *   include libraries
    *
    *********************************************************************************/

    include_once(BASE.'/lib/lib.functions.php');
    include_once(BASE.'/lib/lib.debug.php');
    include_once(BASE.'/lib/lib.php');

?>
