<?php
/******************************************************************************
@Author:     Björn Brockmann, Paul Eppner (paul@twomoons.de)
                             Sven Bräutigam, Jürgen Brändle
@Homepage    http://www.der-dirigent.de
******************************************************************************/

// Output buffering starten
ob_start();

// Magic Quotes ausschalten
set_magic_quotes_runtime (0);

// zeige alle Fehlermeldungen, aber keine Warnhinweise
error_reporting (E_ALL & ~E_NOTICE);

// alle GET, POST und COOKIE wegen Globals_off parsen
ignore_user_abort(true);
if (!(bool) ini_get('register_globals')) import_request_variables('gp');

// Projektkonfiguration laden
include('cms/inc/config.php');

// Session auslesen
if (!empty($rewrite_sid)) $_GET['sid'] = $sid = $rewrite_sid = substr($rewrite_sid, 0, -1);
if (!empty($view)) $dedi = (empty($dedi)) ? $_COOKIE['dedi'] : $dedi;
else $dedi = (empty($sid)) ? $_COOKIE['sid'] : $sid;

// notwendige Dateien includen
require_once ($dedi_path.'inc/config.php');
require_once ($dedi_path.'inc/class.dedi_debug.php');
include_once ($dedi_path.'external/phplib/prepend.php');
include_once ($dedi_path.'inc/class.values_ct.php');
require_once ($dedi_path.'inc/fnc.general.php');
include($dedi_path.'inc/class.user_perms.php');

// Sprache initialisieren
if (!is_numeric($lang)) {
        $lang = $cfg_client['startlang'];
        $dedi_rewrite['start'] = true;
}

// Klassen initialisieren
$deb = &new dedi_debug;
$db = &new DB_dedi;
$val_ct = &new values_ct();

// Konfigurationsparameter einlesen
$cfg_dedi_temp = $val_ct -> get_cfg();
$cfg_dedi = array_merge($cfg_dedi, $cfg_dedi_temp);
unset($cfg_dedi_temp);

// Projekt initialisieren
if (!is_numeric($client)) $client=$load_client;

// Projekt-Konfigurationsparameter einlesen
$cfg_dedi_temp = $val_ct -> get_by_group('cfg_client', $client);
$cfg_client = array_merge($cfg_client, $cfg_dedi_temp);
unset($cfg_dedi_temp);

// db_cache initialisieren
// weil hier erst die $cfg_client und $cfg_dedi initialisiert sind
$db->init_cache(/*init db_cache with $cfg_client and $cfg_dedi*/);

// Sprachdatei einlesen
// ermittle charset der sprache
$sql  = "SELECT charset, name
        FROM ".$dedi_db['lang']."
        WHERE idlang = '$lang'";
$db->query($sql);
$db->next_record();
$lang_charset = $db->f('charset');
$lang_dir = $dedi_path.'tpl/'.$cfg_dedi['skin'].'/lang/'.$db->f('name').'_'.$lang_charset.'/';
if (file_exists ($lang_dir.'lang_general.php')) require_once($lang_dir.'lang_general.php');
else require_once($dedi_path.'tpl/standard/lang/deutsch_iso-8859-1/lang_general.php');
// Backend, oder Frontend?
if (isset($dedi) && (isset($view) || isset($popup) || isset($bbcodepopup))) {
        $is_backend  = true;
        $is_frontend = false;

        if(isset($popup))
                include('cms/inc/popups-wysiwyg.php');
        else if(isset($bbcodepopup))
                include('cms/inc/popups-bbcode.php');
        else if(isset($view)) include('cms/inc/backend.php');
} else {
        $is_backend  = false;
        $is_frontend = true;
        unset($code);
        include ('cms/inc/frontend.php');
}

// eventuelle autostarts ausführen:
$a_location = ($is_frontend) ? 'frontend': 'backend';
if (is_array($cfg_dedi['autostart'][$a_location])) {
        foreach($cfg_dedi['autostart'][$a_location] as $value) include_once $cfg_dedi['dedi_path'] .'plugins/'. $value;
}
if (is_array($cfg_client['autostart'][$a_location])) {
        foreach($cfg_client['autostart'][$a_location] as $value) include_once $cfg_dedi['dedi_path'] .'plugins/'. $value;
}

// Output buffering beenden
$output = '';
$output = ob_get_contents().$deb -> show();
ob_end_clean ();

// Seite komprimieren und ausgeben
if ($cfg_dedi['gzip'] == '1') {
        @ob_start('ob_gzhandler');
        eval($cfg_client['manipulate_output']);
        @ob_end_flush();
} else eval($cfg_client['manipulate_output']);
unset($con_tree, $con_side, $code);
if ($action != 'logout') page_close();
?>