<?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["function"])) { $_GET["function"]="overview"; }
if (!isset($_GET["tab"])) { $_GET["tab"]=""; }
if (!isset($_GET["part"])) { $_GET["part"]=""; }

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

//---[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";
include CLASSES_PATH."Urls.php";

$admin=new Admin();
$login=new Login();
$config_variables=new Config_variables();
$urls=new Urls();
$status_messages=new Status_messages();

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

//---[CZ]: uložení konfiguračních proměnných
if ($_GET["function"]=="options" AND $_GET["tab"]=="" AND isset($_POST["submit"])) {
if (!isset($_POST["show_article_date"])) { $_POST["show_article_date"]=0; }
if (!isset($_POST["show_article_section"])) { $_POST["show_article_section"]=0; }
if (!isset($_POST["show_article_comment_number"])) { $_POST["show_article_comment_number"]=0; }
if (!isset($_POST["show_article_views_number"])) { $_POST["show_article_views_number"]=0; }
if (!isset($_POST["show_article_author"])) { $_POST["show_article_author"]=0; }

$admin->save($_POST["lang"], "lang");
$admin->save($_POST["sitename"], "sitename");
$admin->save($_POST["login_for_comments"], "login_for_comments");
$admin->save($_POST["show_text"], "show_text");
$admin->save($_POST["sort_sections_by_name"], "sort_sections_by_name");
$admin->save($_POST["sort_images_by_name"], "sort_images_by_name");
$admin->save($_POST["sort_comments_from_newest"], "sort_comments_from_newest");
$admin->save($_POST["articles_number"], "articles_number");
$admin->save($_POST["comments_number"], "comments_number");
$admin->save($_POST["theme"], "theme");
$admin->save($_POST["template"], "template");
$admin->save($_POST["use_emoticons"], "use_emoticons");
$admin->save($_POST["show_article_date"], "show_article_date");
$admin->save($_POST["show_article_section"], "show_article_section");
$admin->save($_POST["show_article_comments_number"], "show_article_comments_number");
$admin->save($_POST["show_article_views_number"], "show_article_views_number");
$admin->save($_POST["show_article_author"], "show_article_author");
$admin->save($_POST["table_users"], "table_users");
}

//---[CZ]: uložení meta tagů
if ($_GET["function"]=="options" AND $_GET["tab"]=="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]: uložení nastavení přístupu
if ($_GET["function"]=="options" AND $_GET["tab"]=="access" AND isset($_POST["submit"])) {
$admin->save($_POST["rights_overview"], "rights_overview");
$admin->save($_POST["rights_add_content"], "rights_add_content");
$admin->save($_POST["rights_edit_content"], "rights_edit_content");
$admin->save($_POST["rights_my_content"], "rights_my_content");
$admin->save($_POST["rights_images"], "rights_images");
$admin->save($_POST["rights_files"], "rights_files");
$admin->save($_POST["rights_sections"], "rights_sections");
$admin->save($_POST["rights_comments"], "rights_comments");
$admin->save($_POST["rights_unverified_articles"], "rights_unverified_articles");
$admin->save($_POST["rights_unpublished_articles"], "rights_unpublished_articles");
$admin->save($_POST["rights_archive"], "rights_archive");
$admin->save($_POST["rights_polls"], "rights_polls");
$admin->save($_POST["rights_options"], "rights_options");
$admin->save($_POST["rights_users"], "rights_users");
$admin->save($_POST["rights_mail_messages"], "rights_mail_messages");
$admin->save($_POST["rights_bans"], "rights_bans");
}

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

//---[CZ]: zvolíme typ URL
define("URL_TYPE", $config_variables->get("url_type"));

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

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

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

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

//---[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:CMS v<?php echo $config_variables->get("version"); ?>, (c) 2008-2009 Štěpán Mátl, kcms.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>
<link rel="Stylesheet" href="./components/widgeditor/css/widgEditor.css" type="text/css" />
<link rel="stylesheet" href="./components/slimbox/css/slimbox2.css" type="text/css" />
<script type="text/javascript" src="./components/widgeditor/scripts/widgEditor.js"></script>
<script type="text/javascript" src="./components/js/jquery.js"></script>
<script type="text/javascript" src="./components/slimbox/js/slimbox2.js"></script>
</head>
<body>

<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<?php if ($_GET["function"]=="overview") { echo " class=\"active-item\""; } ?>><a href="./admin.php"><?php echo LANG_OVERVIEW; ?></a></li>
<li><a href="./index.php"><strong><?php echo LANG_HOMEPAGE; ?></strong></a></li>
</ul>

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

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

<ul>
<li<?php if ($_GET["function"]=="add_content") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=add_content"><?php echo LANG_ADD_CONTENT; ?></a></li>
<li<?php if ($_GET["function"]=="my_content") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=my_content"><?php echo LANG_MY_CONTENT; ?></a></li>
<li<?php if ($_GET["function"]=="sections") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=sections"><?php echo LANG_SECTIONS." &amp; ".LANG_COLUMNS; ?></a></li>
<li<?php if ($_GET["function"]=="images") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=images"><?php echo LANG_IMAGES; ?></a></li>
<li<?php if ($_GET["function"]=="files") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=files"><?php echo LANG_FILES; ?></a></li>
</ul>

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

<ul>
<li<?php if ($_GET["function"]=="comments") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=comments"><?php echo LANG_COMMENTS; ?></a></li>
<li<?php if ($_GET["function"]=="unverified_articles") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=unverified_articles"><?php echo LANG_UNVERIFIED_ARTICLES; ?></a></li>
<li<?php if ($_GET["function"]=="unpublished_articles") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=unpublished_articles"><?php echo LANG_UNPUBLISHED_ARTICLES; ?></a></li>
<li<?php if ($_GET["function"]=="archive") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=archive"><?php echo LANG_ARCHIVE; ?></a></li>
<li<?php if ($_GET["function"]=="polls") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=polls"><?php echo LANG_POLLS; ?></a></li>
</ul>

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

<ul>
<li<?php if ($_GET["function"]=="options") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=options"><?php echo LANG_OPTIONS; ?></a></li>
<li<?php if ($_GET["function"]=="users") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=users"><?php echo LANG_USERS; ?></a></li>
<li<?php if ($_GET["function"]=="bans") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=bans"><?php echo LANG_BANS; ?></a></li>
<li<?php if ($_GET["function"]=="mail_messages") { echo " class=\"active-item\""; } ?>><a href="./admin.php?function=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["function"])) {
include "components/pages_admin/".$_GET["function"].".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://kcms.stepanmatl.cz\">K:CMS</a> v".$config_variables->get("version")."</div>\n"; ?>
<div class="float-ending"><!-- --></div>
</div>
</body>
</html>