<?php
ini_set("display_errors", 0);
error_reporting(0);
include_once "admin/config.php";
include_once "admin/stuff/func/show.php";

$ip = $_SERVER['REMOTE_ADDR'];
$dnesnidatum = StrFTime("%Y-%m-%d %H:%M:%S", Time());
$banlist = mysql_query("SELECT * FROM jtcms_banlist WHERE ip='".mysql_real_escape_string($ip)."' and druh='2' LIMIT 1");
$banlist_r = mysql_num_rows($banlist);

if ($banlist_r != 0) {
  $banlist = mysql_fetch_array($banlist);
  Header("Location: admin/error.php?error=3&ip=".rawurlencode($banlist['ip']));
  echo '<script type="text/javascript">location.replace("admin/error.php?error=3&ip='.rawurlencode($banlist['ip']).'")</script>';
};

$znakova_sada = mysql_query("SELECT hodnota2 FROM jtcms_nastaveni WHERE typ='znakova_sada' LIMIT 1");
$znakova_sada = mysql_fetch_array($znakova_sada);
$znakova_sada = $znakova_sada['hodnota2'];

$jazyk_query = mysql_query("SELECT hodnota, hodnota2 FROM jtcms_nastaveni WHERE typ='jazyk' LIMIT 1");
$jazyk_result = mysql_fetch_array($jazyk_query);
$jazyk_hodnota = $jazyk_result['hodnota'];
$jazyk_setlocale = $jazyk_result['hodnota2'];

SetLocale(LC_ALL, $jazyk_setlocale.".".$znakova_sada);

if (!isset($_GET['jtcms-article']) && !isset($_GET['jtcms-category']) && !isset($_GET['jtcms-page']) && !isset($_GET['jtcms-tag']) && !isset($_GET['jtcms-author']) && !isset($jtcms_mode)) {

  $limit = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='pocet_clanku' LIMIT 1");
  $limit = mysql_fetch_array($limit);
  $limit = $limit['hodnota'];
  
    $pocet = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_clanky");
    $pocet = mysql_fetch_array($pocet);
    $pocet = $pocet['pocet'];

  if ($pocet > $limit) {   
      $pocet_stran = $pocet/$limit;
  
    if (isset($_GET['page'])) {
      $strana = $_GET['page'];
    } else {
      $strana = 1;
    }; 
           
    $query = mysql_query("SELECT * FROM jtcms_clanky WHERE status='1' and datum<='".$dnesnidatum."' ORDER BY datum DESC LIMIT ".$limit." OFFSET ".($limit*($strana-1)));
  } else {
    $query = mysql_query("SELECT * FROM jtcms_clanky WHERE status='1' and datum<='".$dnesnidatum."' ORDER BY datum DESC");
  };

  while ($result = mysql_fetch_array($query)) {
    $pridal = mysql_query("SELECT id, jmeno FROM jtcms_uzivatele WHERE id='".$result['pridal']."' LIMIT 1");
    $pridal = mysql_fetch_array($pridal);
    $pridal = '<a href="?jtcms-author='.$pridal['id'].'">'.$pridal['jmeno'].'</a>';
  
    $pridal_text = mysql_query("SELECT jmeno FROM jtcms_uzivatele WHERE id='".$result['pridal']."' LIMIT 1");
    $pridal_text = mysql_fetch_array($pridal_text);
    $pridal_text = $pridal_text['jmeno'];
    
    $komentare = mysql_query("SELECT COUNT(*) AS komentare FROM jtcms_komentare_cl WHERE clanek='".$result['id']."'");
    $komentare = mysql_fetch_array($komentare);
    $komentare = $komentare['komentare'];
    
    $kategorie = mysql_query("SELECT nazev FROM jtcms_kategorie WHERE id='".$result['kategorie']."' LIMIT 1");
    $kategorie = mysql_fetch_array($kategorie);
    $kategorie = $kategorie['nazev'];
    
    if (!empty($result["obrazek"]) && file_exists("./admin/data/art_img/".$result["obrazek"])) {
      $img = getimagesize("./admin/data/art_img/".$result['obrazek']);
      $img_width = $img[0];
      $img_height = $img[1];
     };     
    
    if (!empty($result['stitky'])) {
      $stitky_pole = explode(";",$result['stitky']);
      $i = 0;
      for ($p = 0; $p < count($stitky_pole); ++$p){
        $query2 = mysql_query("SELECT * FROM jtcms_stitky WHERE id='".$stitky_pole[$p]."' and datum<='".$dnesnidatum."' LIMIT 1");
        $radku2 = mysql_num_rows($query2);
        
        if ($radku2 != 0) {
          $result2 = mysql_fetch_array($query2);    
          $stitky_a[$i] = '<a href="?jtcms-tag='.$result2['id'].'">'.$result2['nazev'].'</a>';
          $stitky_text[$i] = $result2['nazev'];
          $i++;
        };
      };
    };
    
    include "admin/stuff/templates/template_1.php";

  };
  
  $nastaveni = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='strankovani' LIMIT 1");
  $nastaveni = mysql_fetch_array($nastaveni);

  if ($pocet > $limit && $nastaveni['hodnota'] == 1) {  
   include "admin/stuff/templates/template_3.php";
  };
};

if (isset($_GET['jtcms-tag']) &&!empty($_GET['jtcms-tag']) && !isset($_GET['jtcms-article']) && !isset($_GET['jtcms-category']) && !isset($_GET['jtcms-page']) && !isset($_GET['jtcms-author']) && !isset($jtcms_mode)) {

   $id = $_GET['jtcms-tag'];
   $query = mysql_query("SELECT * FROM jtcms_stitky WHERE id='".mysql_real_escape_string($id)."' and datum<='".$dnesnidatum."' LIMIT 1");
   $result = mysql_fetch_array($query);
   $radku = mysql_num_rows($query);
   
   if ($radku == 0) {
     Header("Location: admin/error.php?error=8");
     echo '<script type="text/javascript">location.replace("error.php?error=8")</script>';     
   };
   
  $limit = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='pocet_clanku' LIMIT 1");
  $limit = mysql_fetch_array($limit);
  $limit = $limit['hodnota'];
  
    $pocet = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_clanky");
    $pocet = mysql_fetch_array($pocet);
    $pocet = $pocet['pocet'];

  if ($pocet > $limit) {   
      $pocet_stran = $pocet/$limit;
  
    if (isset($_GET['page'])) {
      $strana = $_GET['page'];
    } else {
      $strana = 1;
    }; 
           
    $query = mysql_query("SELECT * FROM jtcms_clanky WHERE status='1' and datum<='".$dnesnidatum."' and ((stitky LIKE '%;".$id.";%' or stitky LIKE '".$id.";%' or stitky LIKE '%;".$id."') or stitky='".$id."') ORDER BY datum DESC LIMIT ".$limit." OFFSET ".($limit*($strana-1)));
  } else {
    $query = mysql_query("SELECT * FROM jtcms_clanky WHERE status='1' and datum<='".$dnesnidatum."' and ((stitky LIKE '%;".$id.";%' or stitky LIKE '".$id.";%' or stitky LIKE '%;".$id."') or stitky='".$id."') ORDER BY datum DESC");
  };

  while ($result = mysql_fetch_array($query)) {
    $pridal = mysql_query("SELECT id, jmeno FROM jtcms_uzivatele WHERE id='".$result['pridal']."' LIMIT 1");
    $pridal = mysql_fetch_array($pridal);
    $pridal = '<a href="?jtcms-author='.$pridal['id'].'">'.$pridal['jmeno'].'</a>';
  
    $pridal_text = mysql_query("SELECT jmeno FROM jtcms_uzivatele WHERE id='".$result['pridal']."' LIMIT 1");
    $pridal_text = mysql_fetch_array($pridal_text);
    $pridal_text = $pridal_text['jmeno'];
    
    $komentare = mysql_query("SELECT COUNT(*) AS komentare FROM jtcms_komentare_cl WHERE clanek='".$result['id']."'");
    $komentare = mysql_fetch_array($komentare);
    $komentare = $komentare['komentare'];
    
    $kategorie = mysql_query("SELECT nazev FROM jtcms_kategorie WHERE id='".$result['kategorie']."' LIMIT 1");
    $kategorie = mysql_fetch_array($kategorie);
    $kategorie = $kategorie['nazev'];
    
    if (!empty($result["obrazek"]) && file_exists("./admin/data/art_img/".$result["obrazek"])) {
      $img = getimagesize("./admin/data/art_img/".$result['obrazek']);
      $img_width = $img[0];
      $img_height = $img[1];
     };
    
    if (!empty($result['stitky'])) {
      $stitky_pole = explode(";",$result['stitky']);
      $i = 0;
      for ($p = 0; $p < count($stitky_pole); ++$p){
        $query2 = mysql_query("SELECT * FROM jtcms_stitky WHERE id='".$stitky_pole[$p]."' and datum<='".$dnesnidatum."' LIMIT 1");
        $radku2 = mysql_num_rows($query2);
        
        if ($radku2 != 0) {
          $result2 = mysql_fetch_array($query2);    
          $stitky_a[$i] = '<a href="?jtcms-tag='.$result2['id'].'">'.$result2['nazev'].'</a>';
          $stitky_text[$i] = $result2['nazev'];
          $i++;
        };
      };
    };
    
    include "admin/stuff/templates/template_1.php";  
  };
  
  $nastaveni = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='strankovani' LIMIT 1");
  $nastaveni = mysql_fetch_array($nastaveni);

  if ($pocet > $limit && $nastaveni['hodnota'] == 1) {  
   include "admin/stuff/templates/template_3.php";
  };
};

if (isset($_GET['jtcms-author']) && !empty($_GET['jtcms-author']) && !isset($_GET['jtcms-article']) && !isset($_GET['jtcms-category']) && !isset($_GET['jtcms-page']) && !isset($jtcms_mode)) {
 
  $id = $_GET['jtcms-author'];
  $query = mysql_query("SELECT * FROM jtcms_uzivatele WHERE id='".mysql_real_escape_string($id)."' LIMIT 1");
  $result = mysql_fetch_array($query);
  $radku = mysql_num_rows($query);
  
  if ($radku == 0) {
     Header("Location: admin/error.php?error=10");
     echo '<script type="text/javascript">location.replace("error.php?error=10")</script>';   
  };
  
  include "admin/stuff/templates/template_13.php";
};

if (isset($_GET['jtcms-article']) && !empty($_GET['jtcms-article']) && !isset($_GET['jtcms-category']) && !isset($_GET['jtcms-page']) && !isset($_GET['jtcms-author']) && !isset($jtcms_mode)) {

   $id = $_GET['jtcms-article'];
   $query = mysql_query("SELECT * FROM jtcms_clanky WHERE id='".mysql_real_escape_string($id)."' and datum<='".$dnesnidatum."' and (status='1' or status='3') LIMIT 1");
   $result = mysql_fetch_array($query);
   $radku = mysql_num_rows($query);
   
   if ($radku == 0) {
     Header("Location: admin/error.php?error=5&id=".$id);
     echo '<script type="text/javascript">location.replace("error.php?error=5&id='.$id.'")</script>';     
   };
   
   if (!isset($_GET['jtcms-kom'])) {
     $pocet = $result['pocet'];
     $pocet++;
     mysql_query("UPDATE jtcms_clanky SET pocet='".$pocet."' WHERE id='".$id."' LIMIT 1");
   };
   
    $pridal = mysql_query("SELECT id, jmeno FROM jtcms_uzivatele WHERE id='".$result['pridal']."' LIMIT 1");
    $pridal = mysql_fetch_array($pridal);
    $pridal = '<a href="?jtcms-author='.$pridal['id'].'">'.$pridal['jmeno'].'</a>';
  
    $pridal_text = mysql_query("SELECT jmeno FROM jtcms_uzivatele WHERE id='".$result['pridal']."' LIMIT 1");
    $pridal_text = mysql_fetch_array($pridal_text);
    $pridal_text = $pridal_text['jmeno'];
    
    $komentare = mysql_query("SELECT COUNT(*) AS komentare FROM jtcms_komentare_cl WHERE clanek='".$result['id']."'");
    $komentare = mysql_fetch_array($komentare);
    $komentare = $komentare['komentare'];
    
    $kategorie = mysql_query("SELECT nazev FROM jtcms_kategorie WHERE id='".$result['kategorie']."' LIMIT 1");
    $kategorie = mysql_fetch_array($kategorie);
    $kategorie = $kategorie['nazev'];
    
    if (!empty($result["obrazek"]) && file_exists("./admin/data/art_img/".$result["obrazek"])) {
      $img = getimagesize("./admin/data/art_img/".$result['obrazek']);
      $img_width = $img[0];
      $img_height = $img[1];
     };
    
    if (!empty($result['stitky'])) {
      $stitky_pole = explode(";",$result['stitky']);
      $i = 0;
      for ($p = 0; $p < count($stitky_pole); ++$p){
        $query2 = mysql_query("SELECT * FROM jtcms_stitky WHERE id='".$stitky_pole[$p]."' and datum<='".$dnesnidatum."' LIMIT 1");
        $radku2 = mysql_num_rows($query2);
        
        if ($radku2 != 0) {
          $result2 = mysql_fetch_array($query2);    
          $stitky_a[$i] = '<a href="?jtcms-tag='.$result2['id'].'">'.$result2['nazev'].'</a>';
          $stitky_text[$i] = $result2['nazev'];
          $i++;
        };
      };
    };  
    
    $result['pocet']++;
   
   include "admin/stuff/templates/template_2.php";
   
   $nastaveni = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='komentare' LIMIT 1");
   $nastaveni = mysql_fetch_array($nastaveni);
   
   if (($result['kom_pov'] == 1 or $result['kom_pov'] == 2) && $nastaveni['hodnota'] == 1) {
     
     include "admin/stuff/templates/template_8.php";
     
     if (!empty($_POST)) {
     
       $banlist = mysql_query("SELECT * FROM jtcms_banlist WHERE ip='".mysql_real_escape_string($ip)."' and druh='1' LIMIT 1");
       $banlist_r = mysql_num_rows($banlist);
     
       $jmeno = htmlspecialchars($_POST['jtcms_jmeno']);
       $mail = htmlspecialchars($_POST['jtcms_mail']);
       $web = htmlspecialchars($_POST['jtcms_web']);
       $obsah = htmlspecialchars($_POST['jtcms_obsah']);
       
       if (!empty($jmeno) && !empty($obsah) && $banlist_r == 0) {
         
         $jmeno = mysql_real_escape_string($jmeno);
         $mail = mysql_real_escape_string($mail);
         $web = mysql_real_escape_string($web);
         $obsah = mysql_real_escape_string($obsah);
         
         if ($web) {if (!ereg("^http://", $web)) {$web = "http://".$web;};};
         
           mysql_query("INSERT INTO jtcms_komentare_cl (clanek,jmeno,mail,web,obsah,ip,datum) VALUES ('".$id."','".$jmeno."','".$mail."','".$web."','".$obsah."','".$ip."',NOW())");
           Header("Location: ?jtcms-article=".$id."&jtcms-kom=added#jtcms-kom-form");
           echo '<script type="text/javascript">location.replace("?jtcms-article='.$id.'&jtcms-kom=added#jtcms-kom-form")</script>';

       } else {
       
         if ($banlist_r != 0) {
           $banlist = mysql_fetch_array($banlist);
           Header("Location: admin/error.php?error=4&ip=".rawurlencode($banlist['ip']));
           echo '<script type="text/javascript">location.replace("admin/error.php?error=4&ip='.rawurlencode($banlist['ip']).'")</script>';
         };
       
         include "admin/stuff/templates/template_10.php";
       
       };
     
     };
     
       $nastaveni = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='komentare_raz' LIMIT 1");
       $nastaveni = mysql_fetch_array($nastaveni);
     
     if ($nastaveni['hodnota'] == 1) {
       $query_kom = mysql_query("SELECT * FROM jtcms_komentare_cl WHERE clanek='".$id."' ORDER BY id");
     } else {
       $query_kom = mysql_query("SELECT * FROM jtcms_komentare_cl WHERE clanek='".$id."' ORDER BY id DESC");
     };
     
     $radku = mysql_num_rows($query_kom);
     
     if ($radku == 0) {
       include "admin/stuff/templates/template_9.php";
     } else {
       while ($result = mysql_fetch_array($query_kom)) {
         include "admin/stuff/templates/template_7.php";
       };
     };
   };
};

if (((isset($jtcms_mode) && $jtcms_mode == "page" && isset($jtcms_page) && !empty($jtcms_page)) or (isset($_GET['jtcms-page']) && !empty($_GET['jtcms-page']))) && !isset($_GET['jtcms-category']) && !isset($_GET['jtcms-author']) && !isset($_GET['jtcms-article'])) {

   if (!empty($_GET['jtcms-page'])) {$id = $_GET['jtcms-page'];} else {$id = $jtcms_page;};
   $query = mysql_query("SELECT * FROM jtcms_stranky WHERE id='".mysql_real_escape_string($id)."' LIMIT 1");
   $result = mysql_fetch_array($query);
   $radku = mysql_num_rows($query);
   
   if ($radku == 0) {
     Header("Location: admin/error.php?error=6&id=".$id);
     echo '<script type="text/javascript">location.replace("error.php?error=6&id='.$id.'")</script>';     
   };
      
   if (!isset($_GET['jtcms-kom'])) {
     $pocet = $result['pocet'];
     $pocet++;
     mysql_query("UPDATE jtcms_stranky SET pocet='".$pocet."' WHERE id='".$id."' LIMIT 1");
   };
      
    $pridal = mysql_query("SELECT id, jmeno FROM jtcms_uzivatele WHERE id='".$result['pridal']."' LIMIT 1");
    $pridal = mysql_fetch_array($pridal);
    $pridal = '<a href="?jtcms-author='.$pridal['id'].'">'.$pridal['jmeno'].'</a>';
  
    $pridal_text = mysql_query("SELECT jmeno FROM jtcms_uzivatele WHERE id='".$result['pridal']."' LIMIT 1");
    $pridal_text = mysql_fetch_array($pridal_text);
    $pridal_text = $pridal_text['jmeno'];
    
    $komentare = mysql_query("SELECT COUNT(*) AS komentare FROM jtcms_komentare_st WHERE clanek='".$result['id']."'");
    $komentare = mysql_fetch_array($komentare);
    $komentare = $komentare['komentare'];
                                          
   include "admin/stuff/templates/template_4.php";
   
   $nastaveni = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='komentare' LIMIT 1");
   $nastaveni = mysql_fetch_array($nastaveni);
   
   if (($result['kom_pov'] == 1 or $result['kom_pov'] == 3) && $nastaveni['hodnota'] == 1) {
     
     include "admin/stuff/templates/template_8.php";
     
     if (!empty($_POST)) {
     
       $banlist = mysql_query("SELECT * FROM jtcms_banlist WHERE ip='".mysql_real_escape_string($ip)."' and druh='1' LIMIT 1");
       $banlist_r = mysql_num_rows($banlist);
     
       $jmeno = htmlspecialchars($_POST['jtcms_jmeno']);
       $mail = htmlspecialchars($_POST['jtcms_mail']);
       $web = htmlspecialchars($_POST['jtcms_web']);
       $obsah = htmlspecialchars($_POST['jtcms_obsah']);
       
       if (!empty($jmeno) && !empty($obsah)) {
         
         $jmeno = mysql_real_escape_string($jmeno);
         $mail = mysql_real_escape_string($mail);
         $web = mysql_real_escape_string($web);
         $obsah = mysql_real_escape_string($obsah);
         
         if ($web) {if (!ereg("^http://", $web)) {$web = "http://".$web;};};
         
           mysql_query("INSERT INTO jtcms_komentare_st (stranka,jmeno,mail,web,obsah,ip,datum) VALUES ('".$id."','".$jmeno."','".$mail."','".$web."','".$obsah."','".$ip."',NOW())");
           Header("Location: ?jtcms-page=".$id."&jtcms-kom=added#jtcms-kom-form");
           echo '<script type="text/javascript">location.replace("?jtcms-page='.$id.'&jtcms-kom=added#jtcms-kom-form")</script>';

       } else {

         if ($banlist_r != 0) {
           $banlist = mysql_fetch_array($banlist);
           Header("Location: admin/error.php?error=4&ip=".rawurlencode($banlist['ip']));
           echo '<script type="text/javascript">location.replace("admin/error.php?error=4&ip='.rawurlencode($banlist['ip']).'")</script>';
         };
       
         include "admin/stuff/templates/template_10.php";
       
       };
     
     };
     
       $nastaveni = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='komentare_raz' LIMIT 1");
       $nastaveni = mysql_fetch_array($nastaveni);
     
     if ($nastaveni['hodnota'] == 1) {
       $query_kom = mysql_query("SELECT * FROM jtcms_komentare_st WHERE stranka='".$id."' ORDER BY id");
     } else {
       $query_kom = mysql_query("SELECT * FROM jtcms_komentare_st WHERE stranka='".$id."' ORDER BY id DESC");
     };
     
     $radku = mysql_num_rows($query_kom);
     
     if ($radku == 0) {
       include "admin/stuff/templates/template_9.php";
     } else {
       while ($result = mysql_fetch_array($query_kom)) {
         include "admin/stuff/templates/template_7.php";
       };
     };
   };
   unset($jtcms_mode);
   unset($jtcms_page);
};

if (isset($_GET['jtcms-category']) && !empty($_GET['jtcms-category']) && !isset($_GET['jtcms-page']) && !isset($_GET['jtcms-author']) && !isset($_GET['jtcms-article']) && !isset($_GET['jtcms-author']) && !isset($jtcms_mode)) {

  $kategorie = $_GET['jtcms-category'];

  $limit = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='pocet_clanku' LIMIT 1");
  $limit = mysql_fetch_array($limit);
  $limit = $limit['hodnota'];
  
    $pocet = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_clanky WHERE kategorie='".$kategorie."'");
    $pocet = mysql_fetch_array($pocet);
    $pocet = $pocet['pocet'];

  if ($pocet > $limit) {   
      $pocet_stran = $pocet/$limit;
  
    if (isset($_GET['page'])) {
      $strana = $_GET['page'];
    } else {
      $strana = 1;
    }; 
           
    $query = mysql_query("SELECT * FROM jtcms_clanky WHERE kategorie='".$kategorie."' and status='1' and datum<='".$dnesnidatum."' ORDER BY datum DESC LIMIT ".$limit." OFFSET ".($limit*($strana-1)));
  } else {
    $query = mysql_query("SELECT * FROM jtcms_clanky WHERE kategorie='".$kategorie."' and status='1' and datum<='".$dnesnidatum."' ORDER BY datum DESC");
  };

  while ($result = mysql_fetch_array($query)) {
    $pridal = mysql_query("SELECT id, jmeno FROM jtcms_uzivatele WHERE id='".$result['pridal']."' LIMIT 1");
    $pridal = mysql_fetch_array($pridal);
    $pridal = '<a href="?jtcms-author='.$pridal['id'].'">'.$pridal['jmeno'].'</a>';
  
    $pridal_text = mysql_query("SELECT jmeno FROM jtcms_uzivatele WHERE id='".$result['pridal']."' LIMIT 1");
    $pridal_text = mysql_fetch_array($pridal_text);
    $pridal_text = $pridal_text['jmeno'];
    
    $komentare = mysql_query("SELECT COUNT(*) AS komentare FROM jtcms_komentare_cl WHERE clanek='".$result['id']."'");
    $komentare = mysql_fetch_array($komentare);
    $komentare = $komentare['komentare'];
    
    $kategorie = mysql_query("SELECT nazev FROM jtcms_kategorie WHERE id='".$result['kategorie']."' LIMIT 1");
    $kategorie = mysql_fetch_array($kategorie);
    $kategorie = $kategorie['nazev'];
    
    if (!empty($result["obrazek"]) && file_exists("./admin/data/art_img/".$result["obrazek"])) {
      $img = getimagesize("./admin/data/art_img/".$result['obrazek']);
      $img_width = $img[0];
      $img_height = $img[1];
     };     
    
    if (!empty($result['stitky'])) {
      $stitky_pole = explode(";",$result['stitky']);
      $i = 0;
      for ($p = 0; $p < count($stitky_pole); ++$p){
        $query2 = mysql_query("SELECT * FROM jtcms_stitky WHERE id='".$stitky_pole[$p]."' and datum<='".$dnesnidatum."' LIMIT 1");
        $radku2 = mysql_num_rows($query2);
        
        if ($radku2 != 0) {
          $result2 = mysql_fetch_array($query2);    
          $stitky_a[$i] = '<a href="?jtcms-tag='.$result2['id'].'">'.$result2['nazev'].'</a>';
          $stitky_text[$i] = $result2['nazev'];
          $i++;
        };
      };
    };    
    
    include "admin/stuff/templates/template_1.php";

  };

  $nastaveni = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='strankovani' LIMIT 1");
  $nastaveni = mysql_fetch_array($nastaveni);

  if ($pocet > $limit && $nastaveni['hodnota'] == 1) {  
   include "admin/stuff/templates/template_3.php";
  };
};

if (isset($jtcms_mode) && $jtcms_mode == "rss" && !isset($_GET['jtcms-category']) && !isset($_GET['jtcms-page']) && !isset($_GET['jtcms-author']) && !isset($_GET['jtcms-article'])) {

  header('Expires: ' . gmdate('D, d M Y H:i:s') . '  GMT');
  header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . '  GMT');
  header('Content-Type: text/xml; charset='.$znakova_sada); 

  $nastaveni = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='nazev_www' LIMIT 1");
  $nastaveni = mysql_fetch_array($nastaveni);
  $nazev_www = $nastaveni['hodnota'];
  
  $nastaveni = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='popis_www' LIMIT 1");
  $nastaveni = mysql_fetch_array($nastaveni);
  $popis_www = $nastaveni['hodnota'];
  
  $dnesnidatum = StrFTime("%Y-%m-%d %H:%M:%S", Time());
  if (!isset($jtcms_rss_cesta)) {$jtcms_rss_cesta = "/";}; 

  echo '<?xml version="1.0" encoding="'.$znakova_sada.'"?'.'>';
  echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
    echo '<channel>';
      echo '<title>'.clean_rss_text($nazev_www).'</title>';
      echo '<link>http://'.$_SERVER['HTTP_HOST'].'/</link>';
      echo '<description>'.clean_rss_text($popis_www).'</description>';
      echo '<language>'.$jazyk_hodnota.'</language>';

      echo '<atom:link href="http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'" rel="self" type="application/rss+xml" />';

    $query = mysql_query("SELECT * FROM jtcms_clanky WHERE status='1' and datum<='".$dnesnidatum."' ORDER BY datum DESC");
    while($result = mysql_fetch_array($query)) { 

  echo '<item>';
    echo '<pubDate>'.date("r", strtotime($result['datum'])).'</pubDate>';
    echo '<title>'.clean_rss_text($result['nazev']).'</title>';
    echo '<link>http://'.$_SERVER['HTTP_HOST'].$jtcms_rss_cesta.'?jtcms-article='.$result['id'].'</link>';
    echo '<guid>http://'.$_SERVER['HTTP_HOST'].$jtcms_rss_cesta.'?jtcms-article='.$result['id'].'</guid>';
    if ($result['kom_pov'] == 1) { 
    echo '<comments>http://'.$_SERVER['HTTP_HOST'].$jtcms_rss_cesta.'?jtcms-article='.$result['id'].'#jtcms-kom-form'.'</comments>';
    }; 
    echo '<description>'.clean_rss_text($result['perex']).'</description>';  
  echo '</item>';
  echo "\n";
   }; 
    echo '</channel>';
  echo '</rss>';
  
  unset($jtcms_mode);
  unset($jtcms_rss_cesta);
};

?>