<?php
class Index {

  public $db;
  public $config_variables;
  public $urls;
  public $login;
  public $captcha;
  public $status_messages;

  public function __construct() {
  
    $this->db = new Db_layer();
    $this->config_variables = new Config_variables();
    $this->urls = new Urls();
    $this->login = new Login();
    $this->captcha = new Captcha();
    $this->status_messages = new Status_messages();
    
  }
  
  //---[CZ]: kontrola banu
  public function check_ban() {
    $sql=$this->db->query("SELECT COUNT(*) AS c FROM kcms_bans WHERE ip='".$_SERVER["REMOTE_ADDR"]."'");
    $sql=$this->db->fetch_array($sql);
    return $sql["c"];
  }
  
  public function get_title() {
  
    if ($_GET["gallery"]!="") { echo LANG_GALLERIES." ".$this->current_gallery("name")." | "; }
    if ($_GET["function"]=="registration") { echo LANG_REGISTRATION." | "; }
    if ($_GET["article"]!="") { echo $this->current_article("title")." | "; }
    if ($_GET["function"]=="settings") { echo $this->current_article("title")." | "; }
    if ($_GET["function"]=="search") { echo LANG_SEARCH." &raquo; ".rawurldecode($_GET["string"])." | "; }
    if ($_GET["function"]=="registration") { echo LANG_REGISTRATION." | "; }
    
    if ($_GET["profile"]!="") {
    echo LANG_PROFILE." &raquo; ";
    $sql=$this->db->query("SELECT login, realname FROM ".TABLE_USERS." WHERE login='".htmlspecialchars($_GET["profile"])."'");
    $sql=$this->db->fetch_array($sql);
    if ($sql["realname"]!="") { echo $sql["realname"]; } else { echo $sql["login"]; } echo " | "; }
    
    if ($_GET["section"]!="") { echo LANG_SECTION." ".$this->current_section("name")." | "; }
  
    echo $this->config_variables->get("sitename");
  
  }
  
  public function get_h1_bar() {
  
    if ($_GET["article"]!="") { echo $this->current_article("title"); }
    
    if ($_GET["gallery"]!="") { echo LANG_GALLERIES." &raquo; ".$this->current_gallery("name"); }
    
    if ($_GET["profile"]!="") {
    echo LANG_PROFILE." &raquo; ";
    $sql=$this->db->query("SELECT login, realname FROM ".TABLE_USERS." WHERE login='".htmlspecialchars($_GET["profile"])."'");
    $sql=$this->db->fetch_array($sql);
    if ($sql["realname"]!="") { echo $sql["realname"]; } else { echo $sql["login"]; } }
    
    if ($_GET["function"]=="settings") { echo $this->current_article("title"); }
    if ($_GET["function"]=="search") { echo LANG_SEARCH." &raquo; ".rawurldecode($_GET["string"]); }
    if ($_GET["function"]=="registration") { echo LANG_REGISTRATION; }
    
    if ($_GET["function"]=="" AND $_GET["section"]=="" AND $_GET["article"]=="" AND $_GET["profile"]=="" AND $_GET["gallery"]=="") { echo LANG_HOMEPAGE; }
    
    if ($_GET["section"]!="") { echo LANG_SECTION." &raquo; ".$this->current_section("name"); }
  
  }
  
  //---[CZ]: získání položek sloupců
  public function get_column_items($column) {
  
    $sql=$this->db->query("SELECT name, content FROM kcms_columns WHERE col='$column' AND hidden=0 ORDER by position");
    while($data=$this->db->fetch_array($sql)) {

      echo "<h2>".$this->db->unescape($data["name"])."</h2>\n\n".$this->db->unescape($data["content"])."\n\n";

    }

  }
  
  //---[CZ]: získání sekcí - začátek
  public function get_sections() {
  
    echo "<h2>".LANG_SECTIONS."</h2>\n\n<ul>";
    
    echo "<li"; if ($_GET["section"]=="") { echo " class=\"active-item\""; } echo "><a href=\"".$this->urls->root()."\">".LANG_HOMEPAGE."</a></li>";
    
    //---[CZ]: pokud jsme v nějaké sekci
    if ($_GET["section"]!="") {
    
    //---[CZ]: nejvyšší sekce před rozbalením podsekcí
    $this->sections("0 AND position<=".$this->top_section_position($_GET["section"]));
    
    //---[CZ]: podsekce
    $this->subsections($_GET["section"]);
    
    //---[CZ]: nejvyšší sekce za rozbalením podsekcí
    $this->sections("0 AND position>".$this->top_section_position($_GET["section"]));
    
    //---[CZ]: pokud jsme na HP
    } else { $this->sections(0); }
    
    echo "</ul>";
  
  }
  
  //---[CZ]: hlavní anketa
  public function get_main_poll() {
    
    $count=$this->db->query("SELECT COUNT(*) AS id FROM kcms_polls WHERE visible=1 AND type=1");
    $count=$this->db->fetch_array($count);

    if ($count["id"]>0) {
    
    echo "<h2>".LANG_POLL."</h2>\n\n";

    $random=rand(0, $count["id"]-1);
    
    $poll=$this->db->query("SELECT id, name FROM kcms_polls WHERE visible=1 AND type=1 LIMIT $random,1");
    $poll=$this->db->fetch_array($poll);

    if (!isset($_COOKIE["votet_".$poll["id"]])) { echo "<form action=\"".$this->urls->root()."index.php?action=vote\" method=\"post\">"; }

    echo "<p><strong>".$this->db->unescape($poll["name"])."</strong></p>\n\n<p>";

    $all_votes=0;
    
    $print=$this->db->query("SELECT votes FROM kcms_polls_data WHERE poll=".$poll["id"]."");
    while (list($votes) = $this->db->fetch_row($print)) {
    $all_votes=$all_votes+$votes;
    }

    $print=$this->db->query("SELECT id, answer, votes FROM kcms_polls_data WHERE poll=".$poll["id"]." ORDER by id");
    while (list($id, $answer, $votes) = $this->db->fetch_row($print)) {
    
    if ($votes!=0) { $width=1.25*round((100*$votes)/$all_votes); } else { $width=10; }
    
    if (!isset($_COOKIE["votet_".$poll["id"]])) { echo "<input type=\"radio\" name=\"vote\" value=\"$id\" /> "; }
    
    echo $this->db->unescape($answer)." ($votes)<span class=\"poll\" style=\"width: $width"."px;\"></span>\n";
    
    }
    
    echo "</p>\n\n<p>".LANG_TOTAL_VOTES.": $all_votes</p>\n\n";

    if (!isset($_COOKIE["votet_".$poll["id"]])) { echo "<div>\n\n<p><input type=\"hidden\" name=\"poll_id\" value=\"".$poll["id"]."\" /><input type=\"submit\" class=\"greenbutton\" value=\"".LANG_VOTE."\" /></p>\n\n</div>"; }
    
    echo "</form>";
    
    }
  
  }
  
  //---[CZ]: článková anketa
  public function get_article_poll($id) {
    
    $poll=$this->db->query("SELECT id, name, visible FROM kcms_polls WHERE id=$id");
    $poll=$this->db->fetch_array($poll);
    
    if ($poll["visible"]==1) {

    if (!isset($_COOKIE["votet_".$poll["id"]])) { echo "<form action=\"".$this->urls->root()."index.php?action=vote\" method=\"post\">"; }

    echo "<p><strong>".$this->db->unescape($poll["name"])."</strong></p>\n\n<p>";

    $all_votes=0;
    
    $print=$this->db->query("SELECT votes FROM kcms_polls_data WHERE poll=".$poll["id"]."");
    while (list($votes) = $this->db->fetch_row($print)) {
    $all_votes=$all_votes+$votes;
    }

    $print=$this->db->query("SELECT id, answer, votes FROM kcms_polls_data WHERE poll=".$poll["id"]." ORDER by id");
    while (list($id, $answer, $votes) = $this->db->fetch_row($print)) {
    
    if ($votes!=0) { $width=2*round((100*$votes)/$all_votes); } else { $width=10; }
    
    if (!isset($_COOKIE["votet_".$poll["id"]])) { echo "<input type=\"radio\" name=\"vote\" value=\"$id\" /> "; }
    
    echo $this->db->unescape($answer)." ($votes)<span class=\"poll\" style=\"width: $width"."px;\"></span>\n";
    
    }
    
    echo "</p>\n\n<p>".LANG_TOTAL_VOTES.": $all_votes</p>\n\n";

    if (!isset($_COOKIE["votet_".$poll["id"]])) { echo "<div>\n\n<p><input type=\"hidden\" name=\"poll_id\" value=\"".$poll["id"]."\" /><input type=\"submit\" class=\"greenbutton\" value=\"".LANG_VOTE."\" /></p>\n\n</div>"; }
    
    echo "</form>";
    
    }
  
  }
  
  //---[CZ]: výpis galerií
  public function get_galleries() {
  
    $sql=$this->db->query("SELECT id FROM kcms_images_sections WHERE public=1");

    if ($this->db->num_rows($sql)>0) {
  
    echo "<h2>".LANG_GALLERIES."</h2>\n\n<ul>";
    
    $print=$this->db->query("SELECT quick, name FROM kcms_images_sections WHERE public=1 ORDER by name");
    while($data=$this->db->fetch_array($print)) {
    
    echo "<li"; if ($_GET["gallery"]==$data["quick"]) { echo " class=\"active-item\""; } echo "><a href=\"".$this->urls->gallery($data["quick"])."\">".$data["name"]."</a></li>\n";

    }
    
    }
  
  }
  
  //---[CZ]: přihlašovací formulář
  public function get_login_form() {
  
    if (isset($_SESSION["user_id"])) {
    
    $sql=$this->db->query("SELECT login, realname FROM ".TABLE_USERS." WHERE id=".$_SESSION["user_id"]);
    $sql=$this->db->fetch_array($sql);

    echo "<h2>"; if ($sql["realname"]!="") { echo $sql["realname"]; } else { echo $sql["login"]; } echo "</h2>";
    
    echo "<ul>";
    
    if ($this->login->check_rights()>0) { echo "<li><a href=\"".$this->urls->root()."admin.php\"><strong>".LANG_ADMINISTRATION."</strong></a></li>"; }
    
    echo "<li><a href=\"".$this->urls->profile($sql["login"])."\">".LANG_PROFILE."</a></li>
    <li><a href=\"".$this->urls->root()."index.php?action=logout\"><em>".LANG_LOGOUT."</em></a></li>
    </ul>";

    } else {

    echo "<h2>".LANG_LOGIN."</h2>

    <form action=\"".$this->urls->root()."index.php?action=login\" method=\"post\">

    <div>

    <p><strong>".LANG_USERNAME.":</strong><br /><input type=\"text\" name=\"login\" style=\"width: 130px;\" /></p>

    <p><strong>".LANG_PASSWORD.":</strong><br /><input type=\"password\" name=\"password\" style=\"width: 130px;\" /></p>

    <p><input type=\"submit\" name=\"submit\" value=\"".LANG_LOGIN."\" /> <a href=\"".$this->urls->fction("registration")."\">".LANG_REGISTRATION."</a></p>

    </div>

    </form>";
    
    }
  
  }
  
  //---[CZ]: vyhledávání
  public function get_search() {
  
    echo "<h2>".LANG_SEARCH."</h2>
    
    <form action=\"".$this->urls->fction("search")."\" method=\"post\">

    <div>
    
    <p style=\"text-align: center;\"><input type=\"text\" name=\"search\" style=\"width: 110px;\" /> <input type=\"submit\" value=\"&raquo;\" /></p>
    
    </div>

    </form>";
    
  }
  
  //---[CZ]: vyhledávání
  public function vote() {
  
    if (isset($_POST["vote"]) AND !isset($_COOKIE["votet_".$_POST["poll_id"]])) {
    
    $sql=$this->db->query("SELECT votes FROM kcms_polls_data WHERE id=".intval($_POST["vote"]));
    $sql=$this->db->fetch_array($sql);
  
    $sql=$this->db->query("UPDATE kcms_polls_data SET votes=".($sql["votes"]+1)." WHERE id=".intval($_POST["vote"]));
    
    setcookie("votet_".$_POST["poll_id"], "1", time()+31104000);
    
    header("Location: ".$_SERVER["HTTP_REFERER"]);
    
    }
    
  }

  //---[CZ]: vypsání článků
  public function print_articles() {
  
    if ($_GET["function"]!="search") {
    
    if ($_GET["section"]=="") { $skip=0; $where="published!=0 AND hp=1"; } else {
    
    $skip=$_GET["page"]*$this->config_variables->get("articles_number")-$this->config_variables->get("articles_number");
    
    $where="published!=0 AND published<=".time()." AND section=".intval($_GET["section"]);
    
    $pages=$this->db->query("SELECT id FROM kcms_articles WHERE $where");
    $pages=ceil($this->db->num_rows($pages)/$this->config_variables->get("articles_number"));
    
    }
    
    } else {
    
    $skip=$_GET["page"]*$this->config_variables->get("articles_number")-$this->config_variables->get("articles_number");
    
    $where="published!=0 AND published<=".time()." AND title LIKE '%".rawurldecode($_GET["string"])."%'";
    
    $pages=$this->db->query("SELECT id FROM kcms_articles WHERE $where");
    $pages=ceil($this->db->num_rows($pages)/$this->config_variables->get("articles_number"));
    
    }
    
    $sql=$this->db->query("SELECT id, quick, title, discussion, section, type, perex, text, author, published, pereximg, views FROM kcms_articles WHERE $where ORDER by top DESC, published DESC, type DESC LIMIT $skip,".$this->config_variables->get("articles_number"));
    while(list($id, $quick, $title, $discussion, $section, $type, $perex, $text, $author, $published, $pereximg, $views)=$this->db->fetch_row($sql)) {

    //---[CZ]: titulek článku
    echo "<h2><a href=\"".$this->urls->article($quick)."\">".$this->db->unescape($title)."</a></h2>\n\n";
    
    $this->article_info($id);

    if ($perex!="") {

    echo "<div class=\"perex\">";

    if ($pereximg!="") { echo "<img src=\"$pereximg\" alt=\"".$this->db->unescape(str_replace("\"", "", $title))."\" class=\"perex-img\" />"; }

    echo $this->db->unescape($perex);

    if ($pereximg!="") { echo "<div class=\"float-ending\"><!-- --></div>"; }

    echo "</div>\n\n";

    }
    
    //---[CZ]: pokud je zapnuto, při prázdném perexu zobrazíme rovnou text článku
    if ($perex=="" AND $this->config_variables->get("show_text")==1) { echo $this->db->unescape($text); }
    
    }
    
    if ($_GET["section"]!="") { $this->paging("section", $this->current_section("id"), $pages); }
    
  }
  
  public function paging($type, $id, $pages) {
    
    echo "<h4 style=\"text-align: right;\">";
    
    if ($type=="article") {
    if (URL_TYPE=="static") { $url="/articles/$id/"; $end="/#comments"; }
    if (URL_TYPE=="dynamic") { $url="./index.php?article=$id&amp;page="; $end="#comments"; }
    }
    
    if ($type=="section") {
    if (URL_TYPE=="static") { $url="/sections/$id/"; $end="/"; }
    if (URL_TYPE=="dynamic") { $url="./index.php?section=$id&amp;page="; $end=""; }
    }

    if ($pages>1 AND $_GET["page"]>1) {
    $i=$_GET["page"]-1;
    echo "<a href=\"$url$i$end\">&laquo;</a>&nbsp;&nbsp;";
    }

    if ($pages<=15) {
    
    $i=1;
    while ($i<=$pages) {
    if ($i==$_GET["page"]) { echo " $i"; } else { echo " <a href=\"$url$i$end\">$i</a>"; }
    $i++;
    }

    } else {

    if ($_GET["page"]<7) { if ($_GET["page"]==1) { echo "1"; } else { echo " <a href=\"$url"."1"."$end\">1</a>"; } } else { if ($_GET["page"]==1) { echo "1 ..."; } else { echo " <a href=\"$url"."1"."$end\">1</a> ..."; } }

    $i=$_GET["page"]-5;
    $i2=$_GET["page"]+4;

    while ($i<$i2) {
    $i++;
    if ($i>1 AND $i<$pages) {
    if ($i==$_GET["page"]) { echo " $i"; } else { echo " <a href=\"$url$i$end\">$i</a>"; }
    }
    }

    if ($_GET["page"]>$pages-6) { if ($_GET["page"]==$pages) { echo " $pages"; } else { echo " <a href=\"$url$pages$end\">$pages</a>"; } } else { if ($_GET["page"]==$pages) { echo " ... $pages"; } else { echo " ... <a href=\"$url$pages$end\">$pages</a>"; } }

    }

    if ($pages>1 AND $_GET["page"]<$pages) {
    $i=$_GET["page"]+1;
    echo "&nbsp;&nbsp;&nbsp;<a href=\"$url$i$end\">&raquo;</a>";
    }

    echo "</h4>";
    
  }
  
  public function current_article($column) {
    $sql=$this->db->query("SELECT $column FROM kcms_articles WHERE quick='".$this->db->escape($_GET["article"])."'");
    $sql=$this->db->fetch_array($sql);
    return $this->db->unescape($sql["$column"]);
  }
  
  public function current_section($column) {
    $sql=$this->db->query("SELECT $column FROM kcms_sections WHERE id=".intval($_GET["section"]));
    $sql=$this->db->fetch_array($sql);
    return $this->db->unescape($sql["$column"]);
  }
  
  public function current_gallery($column) {
    $sql=$this->db->query("SELECT name FROM kcms_images_sections WHERE quick='".$this->db->escape($_GET["gallery"])."'");
    $sql=$this->db->fetch_array($sql);
    return $this->db->unescape($sql["$column"]);
  }
  
  public function add_comment() {
  
    //---[CZ]: definování proměnných
    if (!isset($_POST["author"])) { $_POST["author"]=""; }
    if (!isset($_POST["hash"])) { $_POST["hash"]=""; }
  
    if (isset($_SESSION["user_id"]) OR substr(md5($_POST["hash"]), 0, 5)==$_POST["check"]) {
    
    if ($_POST["text"]!="") {
    
    if ($_POST["author"]!="" OR isset($_SESSION["user_id"])) {
    
    if (isset($_SESSION["user_id"])) { $registered_user=1; $nick=$_SESSION["user_id"]; } else { $nick=$_POST["author"]; $registered_user=0; }

    $text=htmlspecialchars($_POST["text"], ENT_NOQUOTES);
    $text=str_replace("\r\n", "<br />", $text);

    if ($this->config_variables->get("use_emoticons")==1) {
    $text=str_replace("[.smile.]", "<img src=\"".$this->urls->root()."components/images/emoticons/", $text);
    $text=str_replace("[./smile.]", ".gif\" alt=\"Emoticon\" />", $text);
    }

    $sql=$this->db->query("INSERT INTO kcms_comments (article, added, author, text, confirmed, user, ip) values (
    ".intval($_GET["article_id"]).", 
    '".time()."', 
    '".htmlspecialchars($nick)."', 
    '$text', 
    '0', 
    $registered_user, 
    '".$_SERVER["REMOTE_ADDR"]."')");
    
    }
    
    }

    }
    
    header("Location: ".$_SERVER["HTTP_REFERER"]);
    
  }
  
  public function print_comments() {
  
    if ($_GET["page"]=="") { $skip=0; } else { $skip=$_GET["page"]*$this->config_variables->get("comments_number")-$this->config_variables->get("comments_number"); }
  
    $comments=$this->db->query("SELECT id FROM kcms_comments WHERE article=".$this->current_article("id"));

    $pages=ceil($this->db->num_rows($comments)/$this->config_variables->get("comments_number"));
  
    if ($this->config_variables->get("sort_comments_from_newest")==1) { $sort="added DESC"; $i=$this->config_variables->get("comments_number")-$skip+1; } else { $sort="added"; $i=$skip; }
    
    $i2=0;
    
    $sql=$this->db->query("SELECT id, article, added, author, text, user, ip FROM kcms_comments WHERE article=".$this->current_article("id")." ORDER BY $sort LIMIT $skip,".$this->config_variables->get("comments_number"));
    while(list($id, $article, $added, $author, $text, $user, $ip)=$this->db->fetch_row($sql)) {
    
    if ($user==1) {
    $author_info=$this->db->query("SELECT login, realname, avatar FROM ".TABLE_USERS." WHERE id=$author");
    $author_info=$this->db->fetch_array($author_info);
    }
    
    if ($this->config_variables->get("sort_comments_from_newest")==1) { $i=$i-1; } else { $i++; }
    
    $i2++;
    
    echo "<div id=\"div$id\">
    
    <div class=\"comment-$i2\">
    
    <p class=\"comment-info\"><strong><em>$i)</em>&nbsp;&nbsp;";
    
    if ($user==1) { echo "<a href=\"".$this->urls->profile($author_info["login"])."\">"; if ($author_info["realname"]!="") { echo $author_info["realname"]; } else { echo $author_info["login"]; } echo "</a>"; } else { echo $this->db->unescape($author); }
    
    echo "</strong> (";
    
    if (date("d.m.Y", $added)==date("d.m.Y", time())) { echo LANG_TODAY." ".date("H:i", $added); } elseif (date("d.m.Y", $added)==date("d.m.Y", time()-86400)) { echo LANG_YESTERDAY." ".date("H:i", $added); } else { echo date("d.m.Y H:i", $added); }
    
    echo ")";

    if (isset($_SESSION["user_id"])) { if ($author==$_SESSION["user_id"] OR $this->login->check_access("comments")==1) { echo " &bull; <a href=\"#$id\" onclick=\"update_comment($id);\">".LANG_EDIT."</a> &bull; <a href=\"#$id\" onclick=\"if (!confirm('".LANG_ARE_YOU_SURE."')) return false; delete_comment($id);\">".LANG_DELETE."</a>"; } }
    
    if ($this->login->check_access("bans")==1) { echo " &bull; $ip"; }
    
    echo "</p>\n\n<p id=\"$id\">";
    
    if ($author_info["avatar"]!="") { echo "<img src=\"".$this->urls->root()."avatars/$author.".$author_info["avatar"]."\" alt=\"".$author_info["login"]."\" class=\"comment-avatar\" />"; }
    
    echo $this->db->unescape($text);
    
    if ($author_info["avatar"]!="") { echo "<span class=\"float-ending\"><!-- --></span>"; }
    
    echo "</p>
    
    </div>
    
    <div class=\"comment-$i2-bottom-corners\"><!-- --></div>
    
    </div>";
    
    if ($i2==2) { $i2=0; }
    
    }
    
    $this->paging("article", $this->current_article("quick"), $pages);
    
  }
  
  //---[CZ]: zobrazení článku
  public function view_article() {
  
    $article=$this->db->query("SELECT perex, pereximg, text, id, views, poll FROM kcms_articles WHERE id=".$this->current_article("id"));
    $article=$this->db->fetch_array($article);
    
    $sql=$this->db->query("UPDATE kcms_articles SET views=".($article["views"]+1)." WHERE id=".$article["id"]);
    
    $this->article_info($article["id"]);

    if ($article["perex"]!="") {

    echo "<div class=\"perex\">";

    if ($article["pereximg"]!="") { echo "<img src=\"".$article["pereximg"]."\" alt=\"".$article["pereximg"]."\" class=\"perex-img\" />"; }

    echo $this->db->unescape($article["perex"]);

    if ($article["pereximg"]!="") { echo "<div class=\"float-ending\"><!-- --></div>"; }

    echo "</div>";

    }
    
    echo $this->db->unescape($article["text"]);
    
    if ($article["poll"]!=0) {
    
    $this->get_article_poll($article["poll"]);
    
    }
    
    echo "<h4>".LANG_ADD_COMMENT."</h4>";
    
    echo "<form action=\"".$this->urls->root()."index.php?action=add_comment&amp;article_id=".$article["id"]."\" method=\"post\">
    
    <div>";
    
    if (!isset($_SESSION["user_id"])) { echo "<p><strong>".LANG_AUTHOR.":</strong><br /><input type=\"text\" name=\"author\" style=\"width: 200px;\" /></p>"; }
    
    echo "<p><strong>".LANG_TEXT.":</strong><br /><textarea name=\"text\" cols=\"60\" rows=\"6\"></textarea></p>";
    
    if (!isset($_SESSION["user_id"])) {
    echo "<p><strong>".LANG_RETYPE_THIS_TEXT."</strong>:</p>";
    $this->captcha->create(1);
    }
    
    echo "<p><input type=\"submit\" class=\"greenbutton\" value=\"".LANG_ADD."\" /></p>";
    
    echo "</div>
    
    </form>";
    
    echo "<script src=\"/components/js/ajax.js\" type=\"text/javascript\"></script>
    
    <h4 id=\"comments\">".LANG_COMMENTS."</h4>";
    
    $this->print_comments();
    
  }
  
  public function article_info($id) {
  
    $article=$this->db->query("SELECT published, text, pereximg, author, section, views FROM kcms_articles WHERE id=$id");
    $article=$this->db->fetch_array($article);
  
    if ($this->config_variables->get("show_article_date")==1 OR $this->config_variables->get("show_article_author")==1 OR $this->config_variables->get("show_article_section")==1 OR $this->config_variables->get("show_article_comments_number")==1 OR $this->config_variables->get("show_article_views_number")==1) {

    echo "<p class=\"article-info\">";
    
    $article_info="";

    //---[CZ]: datum
    if ($this->config_variables->get("show_article_date")==1) {
    if ($article["published"]!=0) {
    if (date("d.m.Y", $article["published"])==date("d.m.Y", time())) { $article_info.=LANG_TODAY." ".date("[H:i]", $article["published"]); }
    elseif (date("d.m.Y", $article["published"])==date("d.m.Y", time()-86400)) { $article_info.=LANG_YESTERDAY." ".date("[H:i]", $article["published"]); }
    else { $article_info.=date("d.m.Y [H:i]", $article["published"]); }
    } else { $article_info.=LANG_NOT_PUBLISHED_YET; }
    }

    //---[CZ]: author
    if ($this->config_variables->get("show_article_author")==1) {
    $article_info.=", ".$this->urls->author_link($article["author"]);
    }

    //---[CZ]: sekce
    if ($this->config_variables->get("show_article_section")==1) {
    $section=$this->db->query("SELECT name FROM kcms_sections WHERE id=".$article["section"]);
    $section=$this->db->fetch_array($section);
    $article_info.=", ".$section["name"];
    }

    //---[CZ]: počet komentářů
    if ($this->config_variables->get("show_article_comments_number")==1) {
    $count_comments=$this->db->query("SELECT id FROM kcms_comments WHERE article=$id");
    $article_info.=", ".LANG_COMMENTED." ".$this->db->num_rows($count_comments)."&times;";
    }

    //---[CZ]: počet zobrazení
    if ($this->config_variables->get("show_article_views_number")==1) { $article_info.=", ".LANG_VIEWED." ".$article["views"]."&times;"; }
    
    echo trim($article_info, " | ");

    echo "</p>";
    
    }
  
  }
  
  //---[CZ]: případné podsekce a jejich rozbalení
  public function subsections($section) {
  
    $print=$this->db->query("SELECT * FROM kcms_sections WHERE hidden!=1 AND id=$section ORDER by position");
    while($data=$this->db->fetch_array($print)) {
    
    if ($data["higher"]!=0) {
  
    $this->subsections($data["higher"]);
  
    }
    
    $this->sections($section);
  
    }

  }
  
  //---[CZ]: zjištění nejvyšší nadsekce
  public function top_section_position($id) {
  
    $i="";
  
    $print=$this->db->query("SELECT position, higher FROM kcms_sections WHERE id=$id");
    while($data=$this->db->fetch_array($print)) {
    
    $i=$data["position"];
    
    if ($data["higher"]!=0) { $print=$this->db->query("SELECT position, higher FROM kcms_sections WHERE id=".$data["higher"]); }
    
    }
    
    return $i;
  
  }
  
  //---[CZ]: vypsání položek menu podle zvolených kritérií
  public function sections($higher) {
  
    $print=$this->db->query("SELECT id, quick, name, highlight, outlink, position, level FROM kcms_sections WHERE hidden!=1 AND higher=$higher ORDER by position");
    while($data=$this->db->fetch_array($print)) {
    
    echo "<li"; if ($_GET["section"]==$data["id"]) { echo " class=\"active-item\""; } echo "><a href=\"";

    if ($data["outlink"]!="") { echo $data["outlink"]; } else { echo $this->urls->section($data["id"]); }

    if ($data["level"]!=0) { $padding=20; if ($data["level"]==1) { $padding=25;} echo "\" style=\"padding-left: ".($data["level"]*$padding)."px;\">"; } else { echo "\">"; } 

    if ($data["highlight"]==1) { echo "<strong>"; }
    echo $this->db->unescape($data["name"]);
    if ($data["highlight"]==1) { echo "</strong>"; }
    echo "</a></li>\n";
    

    }
  
  }

}
?>