<?php
error_reporting(E_ALL);

//---[CZ]: složka s třídami
define("CLASSES_PATH", "components/classes/");

//---[CZ]: načteme soubor s DB údaji
include "config.php";

//---[CZ]: definování proměnných
if (!isset($_GET["action"])) { $_GET["action"]=""; }
if (!isset($_GET["f"])) { $_GET["f"]="overview"; }

// ######
// ######
// ######

//---[CZ]: načteme potřebné třídy
include CLASSES_PATH."Db_layer.php";
include CLASSES_PATH."Admin.php";
include CLASSES_PATH."Login.php";
include CLASSES_PATH."Status_messages.php";
include CLASSES_PATH."Config_variables.php";

$admin=new Admin();
$login=new Login();
$status=new Status_messages();
$config_variables=new Config_variables();

// ######
// ######
// ######

//---[CZ]: uložení konfiguračních proměnných
if ($_GET["f"]=="options" AND isset($_POST["submit"])) {
$admin->save($_POST["lang"], "lang");
$admin->save($_POST["theme"], "theme");
$admin->save($_POST["sitename"], "sitename");
$admin->save($_POST["table_users"], "table_users");
$admin->save($_POST["paging_number"], "paging_number");
$admin->save($_POST["date_format"], "date_format");
$admin->save($_POST["locked_forums_writing_rights"], "locked_forums_writing_rights");
$admin->save($_POST["locked_topics_writing_rights"], "locked_topics_writing_rights");
$admin->save($_POST["topic_delete_rights"], "topic_delete_rights");
$admin->save($_POST["post_delete_rights"], "post_delete_rights");
$admin->save($_POST["topic_lock_and_unlock_rights"], "topic_lock_and_unlock_rights");
$admin->save($_POST["items_replace_rights"], "items_replace_rights");
$admin->save($_POST["top_links"], "top_links");
}

//---[CZ]: uložení meta tagů
if ($_GET["f"]=="meta_tags" AND isset($_POST["submit"])) {
$admin->save($_POST["meta_copyright"], "meta_copyright");
$admin->save($_POST["meta_desc"], "meta_desc");
$admin->save($_POST["meta_keywords"], "meta_keywords");
}

//---[CZ]: vybereme tabulku s uživateli
define("TABLE_USERS", $config_variables->get("table_users"));

//---[CZ]: načteme jazykový soubor
include ("languages/".$config_variables->get("lang").".php");

//---[CZ]: odstartujeme session
session_start();

//---[CZ]: automatické přihlášení
if (isset($_COOKIE["kboard_autologin1"]) AND !isset($_SESSION["user_id"])) { $login->autologin(); }

//---[CZ]: přihlášení
if ($_GET["action"]=="login") { $login->login(); }

//---[CZ]: odhlášení
if ($_GET["action"]=="logout") { $login->logout(); }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $config_variables->get("lang"); ?>">
<head>
<meta name="Author" content="Powered by K:Board v<?php echo $config_variables->get("version"); ?>, (c) 2008-2009 Stepan Matl, kboard.stepanmatl.cz" />
<meta name="Copyright" content="<?php echo strip_tags($config_variables->get("meta_copyright")); ?>" />
<meta name="Keywords" content="<?php echo $config_variables->get("meta_keywords"); ?>" />
<meta name="Robots" content="noindex, nofollow" />
<meta name="Description" content="<?php echo $config_variables->get("meta_desc"); ?>" />
<meta http-equiv="Content-language" content="<?php echo $config_variables->get("lang"); ?>" />
<meta http-equiv="Cache-control" content="public" />
<meta http-equiv="Content-type" content="application/xhtml+xml; charset=utf-8" />
<link rel="Stylesheet" href="./themes/admin.css" type="text/css" />
<link rel="Shortcut icon" href="./components/images/favicon/favicon.ico" type="image/x-icon" />
<link rel="Icon" href="./components/images/favicon/favicon.ico" type="image/x-icon" />
<title><?php echo LANG_ADMINISTRATION." - ".$config_variables->get("sitename"); ?></title>
</head>
<body>
<script type="text/javascript">
/* <![CDATA[ */
function openWindow(link) {
  otevrit=window.open(link);
  return (typeof(otevrit)=='object')?true:false;
}
/* ]]> */
</script>

<div id="header"><?php echo $config_variables->get("sitename"); ?></div>

<h1><?php echo LANG_ADMINISTRATION; ?></h1>

<div id="content">

<div id="left-column">

<ul>
<li><a href="./admin.php"><?php echo LANG_OVERVIEW; ?></a></li>
<li><a href="./index.php"><?php echo LANG_FORUM_INDEX; ?></a></li>
</ul>

<?php if ($login->check_rights()>0): ?>

<h2><?php echo LANG_CONTENT; ?></h2>

<ul>
<li><a href="./admin.php?f=categories"><?php echo LANG_CATEGORIES; ?></a></li>
<li><a href="./admin.php?f=forums"><?php echo LANG_FORUMS; ?></a></li>
<li><a href="./admin.php?f=ranks"><?php echo LANG_RANKS; ?></a></li>
</ul>

<h2><?php echo LANG_SETTINGS; ?></h2>

<ul>
<li><a href="./admin.php?f=options"><?php echo LANG_OPTIONS; ?></a></li>
<li><a href="./admin.php?f=meta_tags"><?php echo LANG_META_TAGS; ?></a></li>
<li><a href="./admin.php?f=users"><?php echo LANG_USERS; ?></a></li>
<li><a href="./admin.php?f=banns"><?php echo LANG_BANNS; ?></a></li>
<li><a href="./admin.php?f=mail_messages"><?php echo LANG_MAIL_MESSAGES; ?></a></li>
</ul>

<ul>
<li><a href="./admin.php?action=logout"><em><?php echo LANG_LOGOUT; ?></em></a></li>
</ul>

<?php else: ?>

<h2><?php echo LANG_LOGIN; ?></h2>

<form action="./admin.php?action=login" method="post">

<div>

<p><strong><?php echo LANG_USERNAME; ?>:</strong><br /><input type="text" name="login" /></p>

<p><strong><?php echo LANG_PASSWORD; ?>:</strong><br /><input type="password" name="password" /></p>

</div>

<div>

<p><input type="submit" name="submit" value="<?php echo LANG_LOGIN; ?>" /></p>

</div>

</form>

<?php endif; ?>

</div>

<div id="right-column">

<?php
$access_denied=0;
if ($login->check_rights()>0) {
if (isset($_GET["f"])) {
include "components/pages_admin/".$_GET["f"].".php";
}
} else { $access_denied=1; }
if ($access_denied==1) { echo "<h3>".LANG_YOU_HAVE_NOT_ACCESS_TO_THIS_SECTION."</h3>"; }
?>

</div>

<div class="float-ending"><!-- --></div>

</div>

<div id="footer">
<div class="float-left"><?php echo $config_variables->get("meta_copyright")."</div>
<div class=\"float-right\">powered by <a href=\"http://kboard.stepanmatl.cz\">K:Board</a> v".$config_variables->get("version")."</div>\n"; ?>
<div class="float-ending"><!-- --></div>
</div>
</body>
</html>