<?php

include "config.php";

// select rights
$userinfo=mysql_query("SELECT rights FROM kcms_users WHERE id='".$_COOKIE["user_id"]."'");
$userinfo=mysql_fetch_array($userinfo);
if ($userinfo["rights"]=="") { $rights=0; } else { $rights=$userinfo["rights"]; }

// actions
if ($f=="options" AND $_POST["submit"]!="") {

$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($selected_language)."' WHERE variable='lang'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($sitename)."' WHERE variable='sitename'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($login_for_comments)."' WHERE variable='login_for_comments'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($show_text)."' WHERE variable='show_text'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($sort_sections_by_name)."' WHERE variable='sort_sections_by_name'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($articles_number)."' WHERE variable='articles_number'", $dbserver);
$column="left";
include "components/formater.php";
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($left_column)."' WHERE variable='left_column'", $dbserver);
$column="right";
include "components/formater.php";
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($right_column)."' WHERE variable='right_column'", $dbserver);
$column="";
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($selected_theme)."' WHERE variable='theme'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($show_news_box)."' WHERE variable='show_news_box'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($show_promo_box)."' WHERE variable='show_promo_box'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($news_box_items)."' WHERE variable='news_box_items'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($promo_box_items)."' WHERE variable='promo_box_items'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($show_infolane)."' WHERE variable='show_infolane'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($show_sitename)."' WHERE variable='show_sitename'", $dbserver);
if ($header_wallpaper=="/gallery/") { $header_wallpaper=""; }
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($header_wallpaper)."' WHERE variable='header_wallpaper'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($header_wallpaper_height)."' WHERE variable='header_wallpaper_height'", $dbserver);

}

if ($f=="meta_tags" AND $_POST["submit"]!="") {
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($meta_copyright)."' WHERE variable='meta_copyright'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($meta_keywords)."' WHERE variable='meta_keywords'", $dbserver);
$sql=mysql_query("UPDATE kcms_variables SET value='".addslashes($meta_desc)."' WHERE variable='meta_desc'", $dbserver);
}

if ($a=="delete_article" AND $id!="") {
if ($rights>=2) { $secure=""; } else { $secure=" AND author='".$_COOKIE["user_id"]."'"; }
$sql=mysql_query("DELETE FROM kcms_articles WHERE id='".addslashes($id)."'$secure", $dbserver);
}

if ($rights>=2) {

if ($a=="delete_comment" AND $id!="") {
$sql=mysql_query("DELETE FROM kcms_comments WHERE id='".addslashes($id)."'", $dbserver);
}

if ($a=="confirm_comment" AND $id!="") {
$save=mysql_query("UPDATE kcms_comments SET confirmed='1' WHERE id='".addslashes($id)."'", $dbserver);
}

}

if ($rights>=3) {

if ($a=="publish_article" AND $hour!="" AND $minute!="" AND $cancel!=1) {
$save=mysql_query("UPDATE kcms_articles SET published='".mktime($hour, $minute, 0, $month, $day, $year)."', publisher='".$_COOKIE["user_id"]."' WHERE id='".addslashes($id)."'", $dbserver);
}

if ($a=="publish_article" AND $cancel==1) {
$save=mysql_query("UPDATE kcms_articles SET published='0', publisher='' WHERE id='".addslashes($id)."'", $dbserver);
}

}

// loading variables...
$sql=mysql_query("SELECT * FROM kcms_variables");
while($item=mysql_fetch_array($sql)) {
${$item["variable"]}=stripslashes(${$item["variable"]}=$item["value"]);
${$item["variable"]}=str_replace("&", "&amp;", ${$item["variable"]}=$item["value"]);
${$item["variable"]}=str_replace("&amp;copy;", "&copy;", ${$item["variable"]}=$item["value"]);
${$item["variable"]}=str_replace("&amp;amp;", "&amp;", ${$item["variable"]}=$item["value"]);
}

$column="left";
include "components/deformater.php";
$column="right";
include "components/deformater.php";
$column="";

include ("languages/".$lang.".php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo ($lang); ?>" lang="<?php echo ($lang); ?>">
<head>
<meta name="Author" content="Powered by K:CMS v<?php echo "$version"; ?>, &copy; 2008 Stepan Matl, matl-soft.cz" />
<meta name="Copyright" content="<?php echo (strip_tags($meta_copyright)); ?>" />
<meta name="Keywords" content="<?php echo ($meta_keywords); ?>" />
<meta name="Robots" content="index, follow" />
<meta name="Description" content="<?php echo ($meta_desc); ?>" />
<meta http-equiv="Content-language" content="<?php echo ($lang); ?>" />
<meta http-equiv="Cache-control" content="public" />
<meta http-equiv="Content-type" content="application/xhtml+xml; charset=utf-8" />
<link rel="Stylesheet" href="./styles/admin.css" type="text/css" />
<link rel="Shortcut icon" href="./components/images/favicon.ico" type="image/x-icon" />
<link rel="Icon" href="./components/images/favicon.ico" type="image/x-icon" />
<title><?php echo "$lang_administration - $sitename"; ?></title>
</head>
<body>
<script type="text/javascript">
/* <![CDATA[ */
function openWindow(link) {
  otevrit=window.open(link);
  return (typeof(otevrit)=='object')?true:false;
}
/* ]]> */
</script>

<div class="header"><?php echo ($sitename); ?></div>
<h1><?php echo ($lang_administration); ?></h1>

<div class="main">

<div class="left-column">

<ul>
<li><a href="./admin.php"><?php echo($lang_overview); ?></a></li>
<li><a href="./"><?php echo($lang_homepage); ?></a></li>
</ul>

<?php if ($rights>0): ?>

<div class="menu-title"><?php echo($lang_content); ?></div>

<ul>
<li><a href="./admin.php?f=add_article"><?php echo($lang_add_article); ?></a></li>
<li><a href="./admin.php?f=my_articles"><?php echo($lang_my_articles); ?></a></li>
<li><a href="./admin.php?f=sections"><?php echo($lang_sections); ?></a></li>
<li><a href="./admin.php?f=images"><?php echo($lang_images); ?></a></li>
<li><a href="./admin.php?f=files"><?php echo($lang_files); ?></a></li>
</ul>

<div class="menu-title"><?php echo($lang_organization); ?></div>

<ul>
<li><a href="./admin.php?f=comments"><?php echo($lang_comments); ?></a></li>
<li><a href="./admin.php?f=confirm_articles"><?php echo($lang_confirm_articles); ?></a></li>
<li><a href="./admin.php?f=publish_articles"><?php echo($lang_publish_articles); ?></a></li>
<li><a href="./admin.php?f=articles_archive"><?php echo($lang_articles_archive); ?></a></li>
</ul>

<div class="menu-title"><?php echo($lang_settings); ?></div>

<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=backup"><?php echo($lang_backup); ?></a></li>
</ul>

<?php else: ?>

<div class="menu-title"><?php echo($lang_index_account); ?></div>

<p class="a-right"><?php echo($lang_index_you_can_get_login_here); ?></p>

<?php endif; ?>

</div>

<div class="right-column">

<?php
if ($rights>0) {
if ($f!="") {
include "components/$f.php";
} else { include "components/overview.php"; }
} else { $access_denied=1; }
if ($access_denied==1) { echo "<h3>$lang_index_you_have_not_access_to_this_section</h3>"; }
?>

</div>

<div class="cb"><!-- --></div>

</div>

<p class="footer">

<?php echo "$meta_copyright<em>Powered by <a href=\"http://www.matl-soft.cz/k-cms/\">K:CMS</a> v$version, &copy; 2008 Stepan Matl.</em>\n\n"; ?></p>

</body>
</html>