Location: PHPKode > projects > Aratix > admin/index.php
<?php
/*
** Aratix
** Version 0.1.0beta8 (Anubis)
**
** Autor: Manuel Burghammer
** E-Mail: hide@address.com
** Homepage: http://www.xitara.net
**
** File: index.php - Version 0.1.0 build 195
** Position: /
** Last Modified: 28.06.2006 - 23:02:47
*/

define('ARATIX_ADMIN_PART', 1);

/* Debugging einstellen:
**
** 0 - Kein Logfile
** 1 - LOG
** 2 - WARN
** 3 - ERROR
** 4 - DEBUG
*/
$debug_level = 0;

$current_path = dirname(__FILE__) . "/../";
include $current_path . 'inc/init.inc.php';
include $current_path . 'admin/inc/core.inc.php';

if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] == "login"){
	if(get('action') == ""){
		$content->assign("is_login", TRUE);
		$is_login = TRUE;
	}
	else
		unset($is_login);
}

// $charset = $config->charset($language);
$site_title = $config->get("title");
$generator = $config->get("generator");
$core_version = $config->get("version");
$folder = $config->get("folder");
$action = get('action');

/* Login
**
** TODO:
** Bei einer fehlerhaften Anmeldung
** eine entsprechende Fehlerseite
** aufrufen
*/
if($action == "login"){
	if(($session = login($db, $config)) == FALSE){
		echo "Login fehlgeschlagen!";
		exit();
	}
	else{
		$module = "start";
	}
}

/* Statusüberprüfung
**
** Feststellen, ob User eingeloggt ist
** (auf vorhandene Session prüfen).
**
** Falls keine Session übergeben wurde,
** wird der Status "2" (Gast) vergeben.
**
** Falls eine Session übergeben wurde,
** wird diese in der Datenbank geprüft
** und der entsprechende Status zurück
** gegeben und ein String mit
**
** $session
** $ident
**
** erzeugt. Die Ident ist ein MD5-String
** des Loginnamens und muss mit der Session
** in der Datenbank zusammenpassen.
*/
if(!isset($is_login)){
	if(!get('session') && !isset($session)){
		die("Keine berechtigung!");
	}
	else{
		if(!isset($session))
			$session = get('session');
		if($action != "login")
			$ident = get('ident');
		else
			$ident = MD5(get('login'));

		$user_status = update_session($db, $session, $ident);

		if($user_status == FALSE)
			die("Fehler in der Session.");

		$user_name = $db->read(TB_SESSION, "user", "user_md5='" . $ident . "'");
		$session_string = "session=" . $session . "&ident=" . $ident . "&";
	}
}
// Header mit Charset senden
header("Content-type: text/html; charset=" . $charset);

echo <<<EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta name="generator" content="$generator $core_version" />
	<meta http-equiv="content-type" content="text/html; charset=$charset" />
	<title>$site_title</title>
	<link rel="stylesheet" type="text/css" href="css/global.css" />

EOF;

if(get('module')){
	if(file_exists("../modules/module_" . get('module') . "/css/module_" . get('module') . ".css"))
		echo "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"../modules/module_" . get('module') . "/css/module_" . get('module') . ".css\" />\n";
	else
		echo "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/" . get('module') . ".css\" />\n";
}
if(get('block'))
		echo "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"../blocks/block_" . get('block') . "/css/block_" . get('block') . ".css\" />\n";

if(get('module') == "pages" && ($action == "add" || $action == "edit")){
	echo <<<EOF
<!-- tinyMCE -->
<script language="javascript" type="text/javascript" src="../extern/tiny_mce/tiny_mce_gzip.php"></script>
<script language="javascript" type="text/javascript">
	// Notice: The simple theme does not use all options some of them are limited to the advanced theme
	tinyMCE.init({
		mode : "exact",
        elements : "page_area",
		theme : "advanced",
		language: "de",
		docs_language: "de",
		external_image_list_url : "../modules/module_images/image_list.php",
		convert_urls : false
	});
</script>
<!-- /tinyMCE -->
EOF;
}

echo <<<EOF
</head>
EOF;

if(get('module') == "pages")
	echo "<body onload=\"init();\">\n";
else
	echo "<body>\n";

// Template-Engine initialisieren und Verzeichnisse definieren
$content->template_dir = "templates";
$content->compile_dir = "templates_c";

if(get('module') || get('block')){
	if(($module = ucfirst(get('module'))) == "")
		$module = ucfirst(get('block'));

	$class = new $module;
	$module = strtolower($module);
}
else{
	$content->assign("update_string", check_update());
	$module = "start"; // Falls kein module Übergeben wurde dann Startseite aufrufen
}
if(get('action')){
	$action = get('action');

	if(strpos($action, "change_") !== FALSE){
		$class->$action($db, get('id'), get('new_position'));
		$action = "overview";
	}
}

if(!isset($is_login)){
	$content->assign("session_string", $session_string);
	$content->assign("session", $session);
	$content->assign("ident", $ident);
}
if($action != "" && $action != "login")
	$content->assign("template", $module . "_" . $action);
else
	$content->assign("template", $module);

if($action != "" && isset($class)){
	$array = $class->$action($db, get('ident')); // Array mit den ganzen Seitendaten erzeugen ...
	$content->assign($action . "_array", $array); // ... und an smarty Übergeben

	if(file_exists("inc/" . $module . ".inc.php"))
		include_once("inc/" . $module . ".inc.php");
}

/* Module und Blöcke auslesen, für die
** ein Adminbereich existiert
** und an Smarty übergeben
*/
$extension_list1 = $db->read_array(TB_MODULES, "*, id AS module", "admin='true' AND active='true'", "name ASC");
$extension_list2 = $db->read_array(TB_BLOCKS, "*, id AS block", "admin='true' AND active='true'", "name ASC");

$extension_list = array_merge($extension_list1, $extension_list2);
arsort($extension_list);
// print_r($extension_list);
$extensions = array();
$extension_count = 1;

foreach($extension_list as $extension_item){
	if(isset($extension_item['block']))
		$extension_art = "block";
	if(isset($extension_item['module']))
		$extension_art = "module";

	$class_name = ucfirst($extension_item['name']);
	${$extension_item['name']} = new $class_name;

	if(isset(${$extension_item['name']}->menu_item)){
		$extensions['heading'][$extension_item['name']] = $config->i18n($extension_art . "_" . $extension_item['name']);
		$extensions['art'][$extension_item['name']] = $extension_art;
		$extension_temp = ${$extension_item['name']}->menu_item;

		foreach($extension_temp as $extension){
			if($extension == "")
				$extensions['items'][$extension_item['name']][$extension] = "";
			else
				$extensions['items'][$extension_item['name']][$extension] = $config->i18n($extension_art . "_" . $extension_item['name'] . "_" . $extension);
		}
	}
	$extension_count++;
}
// print_r($extensions);
$content->assign("extensions", $extensions);

/* Templates ausgeben
*/
$content->display('header.tpl');
$content->display('index.tpl');
$content->display('footer.tpl');

echo <<<EOF
</body>
</html>

EOF;

$db->disconnect($db->connect_id);
?>
Return current item: Aratix