<?php
if ($_GET['action'] == "add" or $_GET['action'] == "edit") {$tinymce = 1;} else {$tinymce = 2;};
$druh = "stranky";
$meta = '<link rel="stylesheet" type="text/css" href="stuff/tools/fancybox/jquery.fancybox-1.3.4.css" media="screen" />';
$meta2 = '<script type="text/javascript" src="stuff/tools/fancybox/jquery.fancybox-1.3.4.pack.js"></script>';
$meta_end = '<script type="text/javascript" src="stuff/tools/fancybox/jt_cms_set.js"></script>';
include "head.php";
include_head($lang['pages_title'], $druh, $tinymce);

if (!isset($_GET['action'])) {$_GET['action'] = "default";};
switch ($_GET['action']) {

case "add" :

echo '<h1>'.$lang['pages_add_page'].'</h1>';
echo '<br />';


if (!empty($_POST)) {

  $nazev = $_POST['nazev'];
  $obsah = $_POST['obsah'];
  $komentare = $_POST['komentare'];
  $menu_zob = $_POST['menu_zob'];
  $menu_por = $_POST['menu_por'];

  if (!empty($nazev) && !empty($obsah)  && !empty($komentare) && !empty($menu_zob) && $menu_por != "" && is_numeric($menu_por)) {
  
    $nazev = mysql_real_escape_string($nazev);
    $obsah = mysql_real_escape_string($obsah);
    $komentare = mysql_real_escape_string($komentare);
    $menu_zob = mysql_real_escape_string($menu_zob);
    $menu_por = mysql_real_escape_string($menu_por);

    mysql_query("INSERT INTO jtcms_stranky (obsah,nazev,datum,pocet,pridal,kom_pov,menu_zob,menu_por) VALUES ('".$obsah."','".$nazev."',NOW(),'0','".$_SESSION['userid']."','".$komentare."','".$menu_zob."','".$menu_por."')");
    Header("Location: pages.php?work=added&nazev=".rawurlencode($nazev));
    echo '<script type="text/javascript">location.replace("pages.php?work=added&nazev='.rawurlencode($nazev).'")</script>';
    
  } else {  
    echo '<div class="oznameni_div">';
    echo '<div class="chyba">'.$lang['pages_error'].'</div>';
    if (empty($nazev)) {echo '<li>'.$lang['pages_er_1'].'</li>';};
    if (empty($obsah)) {echo '<li>'.$lang['pages_er_2'].'</li>';};
    if (empty($komentare)) {echo '<li>'.$lang['pages_er_3'].'</li>';};
    if (empty($menu_zob)) {echo '<li>'.$lang['pages_er_10'].'</li>';};
    if ($menu_por == "") {echo '<li>'.$lang['pages_er_11'].'</li>';};
    if (!is_numeric($menu_por)) {echo '<li>'.$lang['pages_er_12'].'</li>';};
    echo '</div>';
  };
  
 };
?>

<form method="post" action="pages.php?action=add" id="stranka_form">
<label for="st_nazev"><?php echo $lang['pages_name']; ?>:</label> <input type="text" name="nazev" id="st_nazev" class="input"<?php if (!empty($_POST['nazev'])) {echo ' value="'.htmlspecialchars($_POST['nazev']).'"';}; ?> /><br />
<br />
<label for="st_obsah"><?php echo $lang['pages_content']; ?>:</label><br />
<textarea name="obsah" id="st_obsah" wrap="hard" class="<?php if (!$tinymce_p) {echo 'obsah';} else {echo 'obsah_tiny';}; ?>"><?php if (!empty($_POST['obsah'])) {echo htmlspecialchars($_POST['obsah']);}; ?></textarea>
<br /><br />

<div class="nastaveni_nadpis" onclick="$('.nastaveni').slideToggle();"><?php echo $lang['pages_extended_setting']; ?></div>

<div class="nastaveni">

<div class="nadpis"><img src="stuff/img/icons/comments.png" alt="" /> <?php echo $lang['pages_comments']; ?>:</div>
<div class="moznosti">
<input type="radio" name="komentare" id="komentare1" value="1"<?php if (!empty($_POST)) {if ($_POST['komentare'] == 1) {echo ' checked';};} else {echo ' checked';}; ?> /> <label for="komentare1"><?php echo $lang['pages_comments_1']; ?></label><br />
<input type="radio" name="komentare" id="komentare2" value="2"<?php if (!empty($_POST) && $_POST['komentare'] == 2) {echo ' checked';}; ?> /> <label for="komentare2"><?php echo $lang['pages_comments_2']; ?></label><br />
</div>

<div class="nf"></div>
<br />

<div class="nadpis"><img src="stuff/img/icons/list.png" alt="" /> <?php echo $lang['pages_view_in_menu']; ?>:</div>
<div class="moznosti">
<input type="radio" name="menu_zob" id="menu_zob1" value="1"<?php if (!empty($_POST)) {if ($_POST['menu_zob'] == 1) {echo ' checked';};} else {echo ' checked';}; ?> /> <label for="menu_zob1"><?php echo $lang['pages_number_in_menu_1']; ?></label><br />
<input type="radio" name="menu_zob" id="menu_zob2" value="2"<?php if (!empty($_POST) && $_POST['menu_zob'] == 2) {echo ' checked';}; ?> /> <label for="menu_zob2"><?php echo $lang['pages_number_in_menu_2']; ?></label><br />
</div>

<div class="nf"></div>
<br />

<div class="nadpis"><img src="stuff/img/icons/numbered list.png" alt="" /> <?php echo $lang['pages_number_in_menu']; ?>:</div>
<div class="moznosti">
<select name="menu_por" size="1" class="pocet input">
<option value="0"> 0
<?php $query = mysql_query("SELECT MAX(menu_por) AS max_menu_por, COUNT(*) AS pocet FROM jtcms_stranky");
$result = mysql_fetch_array($query);
$max = $result['max_menu_por']+1;

for($i=1;$i<($result['pocet']+3);$i++) {
echo '<option value="'.$i.'"';
if (!empty($_POST) && $_POST['menu_por'] == $i) {echo ' selected';} elseif ($max == $i) {echo ' selected';};
echo ' /> '.$i;
}; ?>
</select>
</div>

<div class="nf"></div>

</div>

<br /><br />
<div class="nf"></div>

<input type="submit" name="submit" value="<?php echo $lang['pages_save_page']; ?>" class="submit" />
</form>

<?php
break;

case "edit" : 
$id = $_GET['id']; 
$query = mysql_query("SELECT * FROM jtcms_stranky WHERE id='".$id."' LIMIT 1");
$radku = mysql_num_rows($query);
$result = mysql_fetch_array($query);

echo '<h1>'.$lang['pages_edit_page'].'</h1><br />';

 if (empty($id) or $radku == 0 or ($prava == 2 && $result['pridal'] != $_SESSION['userid'])) {
    echo '<div class="oznameni_div">';
    echo '<div class="chyba">'.$lang['pages_error'].'</div>';
    if (empty($id)) {echo '<p>'.$lang['pages_er_4'].'</p>';};
    if ($radku == 0) {echo '<p>'.$lang['pages_er_5'].'</p>';};
    if ($prava == 2 && $result['pridal'] != $_SESSION['userid']) {echo '<p>'.$lang['pages_er_9'].'</p>';};
    echo '</div>';
    
    include_end();
    exit();
  };
  
if (!empty($_POST)) {

  $nazev = $_POST['nazev'];
  $obsah = $_POST['obsah'];
  $pridal = $_POST['pridal'];
  $komentare = $_POST['komentare'];
  $menu_zob = $_POST['menu_zob'];
  $menu_por = $_POST['menu_por'];
  $pocet = $_POST['pocet'];

  if (!empty($nazev) && !empty($obsah) && !empty($pridal) && !empty($komentare) && !empty($menu_zob) && $menu_por != "" && is_numeric($menu_por) && $pocet != "" && is_numeric($pocet)) {
  
   $obsah = mysql_real_escape_string($obsah);
   $nazev = mysql_real_escape_string($nazev);
   $pocet = mysql_real_escape_string($pocet);
   $pridal = mysql_real_escape_string($pridal);
   $komentare = mysql_real_escape_string($komentare);
   $menu_por = mysql_real_escape_string($menu_por);
   $menu_zob = mysql_real_escape_string($menu_zob);

    mysql_query("UPDATE jtcms_stranky SET obsah='".$obsah."', nazev='".$nazev."', pocet='".$pocet."', pridal='".$pridal."', kom_pov='".$komentare."', menu_por='".$menu_por."', menu_zob='".$menu_zob."' WHERE id='".$id."' LIMIT 1");
    Header("Location: pages.php?work=edited&nazev=".rawurlencode($nazev));
    echo '<script type="text/javascript">location.replace("pages.php?work=edited&nazev='.rawurlencode($nazev).'")</script>';
    
  } else {  
    echo '<div class="oznameni_div">';
    echo '<div class="chyba">'.$lang['pages_error'].'</div>';
    if (empty($nazev)) {echo '<li>'.$lang['pages_er_1'].'</li>';};
    if (empty($obsah)) {echo '<li>'.$lang['pages_er_2'].'</li>';};
    if ($pocet == "") {echo '<li>'.$lang['pages_er_6'].'</li>';};
    if (!is_numeric($pocet)) {echo '<li>'.$lang['pages_er_7'].'</li>';};
    if (empty($pridal)) {echo '<li>'.$lang['pages_er_8'].'</li>';};
    if (empty($komentare)) {echo '<li>'.$lang['pages_er_3'].'</li>';};
    if (empty($menu_zob)) {echo '<li>'.$lang['pages_er_10'].'</li>';};
    if ($menu_por == "") {echo '<li>'.$lang['pages_er_11'].'</li>';};
    if (!is_numeric($menu_por)) {echo '<li>'.$lang['pages_er_12'].'</li>';};
    echo '</div>';
  };
  
 };
 
$query_user = mysql_query("SELECT id, jmeno FROM jtcms_uzivatele ORDER BY id DESC");
?>

<form method="post" action="pages.php?action=edit&amp;id=<?php echo $id; ?>" id="stranka_form">
<label for="st_nazev"><?php echo $lang['pages_name']; ?>:</label> <input type="text" name="nazev" id="st_nazev" class="input" value="<?php if (empty($_POST['nazev'])) {echo htmlspecialchars($result['nazev']);} else {echo htmlspecialchars($_POST['nazev']);}; ?>" /><br />
<br />
<label for="st_obsah"><?php echo $lang['pages_content']; ?>:</label><br />
<textarea name="obsah" id="st_obsah" wrap="hard" class="<?php if (!$tinymce_p) {echo 'obsah';} else {echo 'obsah_tiny';}; ?>"><?php if (empty($_POST['obsah'])) {echo htmlspecialchars($result['obsah']);} else {echo htmlspecialchars($_POST['obsah']);}; ?></textarea>
<br /><br />

<div class="nastaveni_nadpis" onclick="$(this).next().slideToggle();"><?php echo $lang['pages_extended_setting']; ?></div>

<div class="nastaveni">


<div class="nadpis"><img src="stuff/img/icons/comments.png" alt="" /> <?php echo $lang['pages_comments']; ?>:</div>
<div class="moznosti">
<input type="radio" name="komentare" value="1"<?php if (empty($_POST)) {if ($result['kom_pov'] == 1) {echo ' checked';};} else {if ($_POST['komentare'] == 1) {echo ' checked';};}; ?> /> <?php echo $lang['pages_comments_1']; ?><br />
<input type="radio" name="komentare" value="2"<?php if (empty($_POST)) {if ($result['kom_pov'] == 2) {echo ' checked';};} else {if ($_POST['komentare'] == 2) {echo ' checked';};}; ?> /> <?php echo $lang['pages_comments_2']; ?><br />
</div>

<div class="nf"></div>
<br />

<div class="nadpis"><img src="stuff/img/icons/list.png" alt="" /> <?php echo $lang['pages_view_in_menu']; ?>:</div>
<div class="moznosti">
<input type="radio" name="menu_zob" id="menu_zob1" value="1"<?php if (empty($_POST)) {if ($result['menu_zob'] == 1) {echo ' checked';};} else {if ($_POST['menu_zob'] == 1) {echo ' checked';};}; ?> /> <label for="menu_zob1"><?php echo $lang['pages_number_in_menu_1']; ?></label><br />
<input type="radio" name="menu_zob" id="menu_zob2" value="2"<?php if (empty($_POST)) {if ($result['menu_zob'] == 2) {echo ' checked';};} else {if ($_POST['menu_zob'] == 2) {echo ' checked';};}; ?> /> <label for="menu_zob2"><?php echo $lang['pages_number_in_menu_2']; ?></label><br />
</div>

<div class="nf"></div>
<br />

<div class="nadpis"><img src="stuff/img/icons/numbered list.png" alt="" /> <?php echo $lang['pages_number_in_menu']; ?>:</div>
<div class="moznosti">
<select name="menu_por" size="1" class="pocet input">
<option value="0"> 0
<?php $pocet_st = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_stranky");
$pocet_st = mysql_fetch_array($pocet_st);

for($i=1;$i<($pocet_st['pocet']+3);$i++) {
echo '<option value="'.$i.'"';
if (empty($_POST)) {if ($result['menu_por'] == $i) {echo ' selected';};} else {if ($_POST['menu_por'] == $i) {echo ' selected';};};
echo ' /> '.$i;
}; ?>
</select>
</div>

<div class="nf"></div>
<br />

<div class="nadpis"><img src="stuff/img/icons/calculator.png" alt="" /> <?php echo $lang['pages_number_of_read']; ?>:</div>
<div class="moznosti">
<input type="text" name="pocet" class="input pocet" value="<?php if (empty($_POST['pocet'])) {echo htmlspecialchars($result['pocet']);} else {echo htmlspecialchars($_POST['pocet']);}; ?>" />
</div>

<div class="nf"></div>
<?php if ($prava == 1) { ?>
<br />

<div class="nadpis"><img src="stuff/img/icons/user.png" alt="" /> <?php echo $lang['pages_author']; ?>:</div>
<div class="moznosti">
<select name="pridal" size="1" class="input pridal"> 
<?php 
while ($result_user = mysql_fetch_array($query_user)) {
echo '<option value="'.$result_user['id'].'"';
if (empty($_POST)) {if ($result['pridal'] == $result_user['id']) {echo ' selected';};} elseif ($_POST['pridal'] == $result_user['id']) {echo ' selected';};
echo ' />'.$result_user['jmeno'];
};
?>
</select>
</div>
<div class="nf"></div>
<?php }; ?>

</div>

<div class="kod_vlozeni" id="kod">
<?php echo $lang['pages_code']; ?><br />
<textarea wrap="hard">
<?php
echo '<?php
  $jtcms_mode = "page";
  $jtcms_page = '.$id.';
  include "admin/jtcms_show.php";
?'.'>';
?>
</textarea>
<br /><br />
<?php echo $lang['pages_code_des']; ?>
</div>

<br /><br />
<div class="nf"></div>

<input type="submit" name="submit" value="<?php echo $lang['pages_save_page']; ?>" class="submit" />
</form>

<?php
break;

case "delete" :

$id = $_GET['id']; 
$query = mysql_query("SELECT * FROM jtcms_stranky WHERE id='".$id."' LIMIT 1");
$radku = mysql_num_rows($query);
$result = mysql_fetch_array($query);
$nazev = $result['nazev'];

 if (empty($id) or $radku == 0 or ($prava == 2 && $result['pridal'] != $_SESSION['userid'])) {
    echo '<h1>'.$lang['pages_delete_page'].'</h1><br />';
    echo '<div class="oznameni_div">';
    echo '<div class="chyba">'.$lang['pages_error'].'</div>';
    if (empty($id)) {echo '<p>'.$lang['pages_er_4'].'</p>';};
    if ($radku == 0) {echo '<p>'.$lang['pages_er_5'].'</p>';};
    if ($prava == 2 && $result['pridal'] != $_SESSION['userid']) {echo '<p>'.$lang['pages_er_9'].'</p>';};
    echo '</div>';
    
    include_end();
    exit();
  }; 
  
    mysql_query("DELETE FROM jtcms_stranky WHERE id='".$id."' LIMIT 1");
    mysql_query("DELETE FROM jtcms_komentare_st WHERE stranka='".$id."'");
    Header("Location: pages.php?work=deleted&nazev=".rawurlencode($nazev));
    echo '<script type="text/javascript">location.replace("pages.php?work=deleted&nazev='.rawurlencode($nazev).'")</script>';  

break;

case "read" :
$id = $_GET['id']; 
$query = mysql_query("SELECT * FROM jtcms_stranky WHERE id='".intval($id)."' LIMIT 1");
$radku = mysql_num_rows($query);
$result = mysql_fetch_array($query);
  
 if (empty($id) or $radku == 0) {
    echo '<br />';
    echo '<div class="oznameni_div">';
    echo '<div class="chyba">'.$lang['pages_error'].'</div>';
    if (empty($id)) {echo '<p>'.$lang['pages_er_4'].'</p>';};
    if ($radku == 0) {echo '<p>'.$lang['pages_er_5'].'</p>';};
    echo '</div>';
    
    include_end();
    exit();
  };

if (($prava == 2 && $result['pridal'] == $_SESSION['userid']) or $prava == 1) {  
  echo '<a href="pages.php?action=edit&amp;id='.$result['id'].'" class="filtr_but"><img src="stuff/img/icons/edit.png" alt="" /> '.$lang['pages_edit_page'].'</a>';
};

echo '<div class="art_pag_read">';
echo '<h1>'.$result['nazev'].'</h1>';
echo '<br />';
show_content($result['obsah']);
echo '</div>';
echo '<br />';
echo '<br />';

  $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='".intval($id)."' ORDER BY id");
} else {
  $query_kom = mysql_query("SELECT * FROM jtcms_komentare_st WHERE stranka='".intval($id)."' ORDER BY id DESC");
};

$radku = mysql_num_rows($query_kom);

if ($radku == 0) {
  echo '<div class="kom_strankovani">'.$lang['pages_no_comments'].'</div>';
} else {
  $druh = "stranky";
  while ($result = mysql_fetch_array($query_kom)) {
    show_comment("clanky", "stranky");
  };
};

break;

default : 

echo '<h1>'.$lang['pages_pages'].'</h1>';
echo '<br />';

if (!isset($_GET['work'])) {$_GET['work'] = "default";};
switch ($_GET['work']) {
case "added" :
echo '<div class="oznameni_div">';
echo '<p>'.$lang['pages_page'].' <span class="blue">'.stripslashes($_GET['nazev']).'</span> '.$lang['pages_work_1'];
if ($prava == 1) {echo '<br />'.$lang['pages_work_2'];};
echo '</p>';
echo '</div>';
break;

case "edited" :
echo '<div class="oznameni_div">';
echo '<p>'.$lang['pages_page'].' <span class="blue">'.stripslashes($_GET['nazev']).'</span> '.$lang['pages_work_3'].'</p>';
echo '</div>';
break;

case "deleted" :
echo '<div class="oznameni_div">';
echo '<p>'.$lang['pages_page'].' <span class="blue">'.stripslashes($_GET['nazev']).'</span> '.$lang['pages_work_4'].'</p>';
echo '</div>';
break;

};
?>
<a href="pages.php?action=add" class="pridat_tlacitko fl"><img src="stuff/img/icons/create.png" alt="+" /> <?php echo $lang['pages_add_page']; ?></a>
<div class="filtr_but" onclick='$(this).next().slideToggle();'><img src="stuff/img/icons/hierarchy.png" alt="" /> <?php echo $lang['pages_filtr']; ?></div>

<form method="post" action="pages.php" class="filtr_div"<?php if (!empty($_POST)) {echo ' style="display: block;"';}; ?>>

  <select name="autor" size="1" class="input">
    <option value="" />--- <?php echo $lang['pages_fil_all_authors']; ?> ---
    <?php $query = mysql_query("SELECT id, jmeno FROM jtcms_uzivatele ORDER BY id");
    while ($result = mysql_fetch_array($query)) {
      echo '<option value="'.$result['id'].'"';
      if (!empty($_POST['autor']) && $_POST['autor'] == $result['id']) {echo ' selected';};
      echo ' />'.$result['jmeno']."\n";
    }; ?>
  <select>

  <select name="menu" size="1" class="input">
    <option value="" />--- <?php echo $lang['pages_fil_all_menu']; ?> ---
    <option value="1"<?php if (!empty($_POST['menu']) && $_POST['menu'] == 1) {echo ' selected';}; ?> /><?php echo $lang['pages_fil_menu_1']."\n"; ?>
    <option value="2"<?php if (!empty($_POST['menu']) && $_POST['menu'] == 2) {echo ' selected';}; ?> /><?php echo $lang['pages_fil_menu_2']."\n"; ?>
  </select>
  
  <select name="kom_pov" size="1" class="input">
    <option value="" />--- <?php echo $lang['pages_fil_all_comments']; ?> ---
    <option value="1"<?php if (!empty($_POST['kom_pov']) && $_POST['kom_pov'] == 1) {echo ' selected';}; ?>  /><?php echo $lang['articles_fil_kom_pov_1']."\n"; ?>
    <option value="2"<?php if (!empty($_POST['kom_pov']) && $_POST['kom_pov'] == 2) {echo ' selected';}; ?>  /><?php echo $lang['articles_fil_kom_pov_2']."\n"; ?>
  </select>

  <input type="submit" name="submit" value="<?php echo $lang['pages_filtr']; ?>" class="submit" />
</form>

<div class="nf"></div>

<?php
if (!empty($_POST)) {
  $autor = $_POST['autor'];
  $menu = $_POST['menu'];
  $kom_pov = $_POST['kom_pov'];
  
  $vypocet = $autor+$menu+$kom_pov;
  
  if ($vypocet != 0) {
    $dotaz = " WHERE ";
    if (!empty($autor)) {$dotaz .= "pridal='".$autor."' and ";};
    if (!empty($menu)) {$dotaz .= "menu_zob='".$menu."' and ";};
    if (!empty($kom_pov)) {$dotaz .= "kom_pov='".$kom_pov."' and ";};
    
    $dotaz = preg_replace("~ and $~i", "", $dotaz);

  } else {
    $dotaz = "";
  };
} else {
  $dotaz = "";
};

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

  if ($pocet > $limit && empty($_POST)) {   
      $pocet_stran = $pocet/$limit;
  
    if (isset($_GET['strana'])) {
      $strana = $_GET['strana'];
    } else {
      $strana = 1;
    }; 
           
    $query = mysql_query("SELECT * FROM jtcms_stranky ORDER BY id DESC LIMIT ".$limit." OFFSET ".($limit*($strana-1)));
  } else {
    $query = mysql_query("SELECT * FROM jtcms_stranky".$dotaz." ORDER BY id DESC");
  };
  
  $radku = mysql_num_rows($query);

?>

<table class="tabulka_stranky" id="vypis">
<tr class="prvni_tr">
  <td class="td1 first">&nbsp;<?php echo $lang['pages_page']; ?></td>
  <td class="td2"><?php echo $lang['pages_author']; ?></td>
  <td class="td3"><img src="stuff/img/icons/list.png" alt="<?php echo $lang['pages_view_in_menu_table']; ?>" title="<?php echo $lang['pages_view_in_menu_table']; ?>" /></td>
  <td class="td4"><img src="stuff/img/icons/numbered list.png" alt="<?php echo $lang['pages_number_in_menu']; ?>" title="<?php echo $lang['pages_number_in_menu']; ?>" /></td>
  <td class="td5"><img src="stuff/img/icons/comments.png" alt="<?php echo $lang['pages_number_of_comments']; ?>" title="<?php echo $lang['pages_number_of_comments']; ?>" /></td>
  <td class="td6 last"><?php echo $lang['pages_date']; ?></td>
</tr>
<?php
  if (!empty($_POST)) {
    echo '<tr><td colspan="6" class="filtr_zrus_td">';
    echo '<a href="pages.php" class="filtr_zrus">'.$lang['pages_fil_cancel_filter'].'</a>';
    echo $lang['pages_fil_total'].' <strong>'.$radku.'</strong>';
    echo '</td></tr>';
  };

if ($radku == 0) {
  echo '<tr><td colspan="6" style="text-align: center; padding: 5px;">';
    if (empty($_POST)) {echo $lang['pages_no_pages'];} else {echo $lang['pages_no_pages_post'];};
  echo '</td></tr>';
  echo '</table>';
} else {

  while ($result = mysql_fetch_array($query)) {
    $query2 = mysql_query("SELECT jmeno FROM jtcms_uzivatele WHERE id='".$result['pridal']."' LIMIT 1");
    $result2 = mysql_fetch_array($query2);
    $query3 = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_komentare_st WHERE stranka='".$result['id']."'");
    $result3 = mysql_fetch_array($query3);

    echo '<tr>';
    echo '<td>&nbsp;<a href="pages.php?action=read&amp;id='.$result['id'].'">'.$result['nazev'].'</a></td>';
    echo '<td>'.$result2['jmeno'].'</td>';
    echo '<td class="menu_zob_td">';
      switch ($result['menu_zob']) {
        case "1" : echo '<img src="stuff/img/icons/tick.png" alt="'.$lang['pages_number_in_menu_1'].'" title="'.$lang['pages_number_in_menu_1'].'" />'; break;
        case "2" : echo '<img src="stuff/img/icons/delete.png" alt="'.$lang['pages_number_in_menu_2'].'" title="'.$lang['pages_number_in_menu_2'].'" />'; break;
      };
    echo '</td>';
    echo '<td>';
      if ($result['menu_zob'] == 1) {
        echo $result['menu_por'];
      } else {
        echo '<span class="prazdno">-</span>';
      };
    echo '</td>';
    echo '<td>';
      if ($result3['pocet'] == 0) {
        echo '<span class="prazdno">'.$result3['pocet'].'</span>';
      } else {
        if ($prava['komentare'] != 3) {
          echo '<a href="comments.php?action=article-page&amp;id='.$result['id'].'&amp;druh=stranky" title="'.$lang['pages_view_comments'].'">'.$result3['pocet'].'</a>';
        } else {
          echo $result3['pocet'];
        };
      };
    echo '</td>';
    echo '<td class="datum">'; 
      echo '<div class="datum" title="'.StrFTime("%H:%M %d.%m.%Y", strtotime($result["datum"])).'">'.StrFTime("%d.%m.%Y", strtotime($result["datum"])).'</div>';   
    if (($prava == 2 && $result['pridal'] == $_SESSION['userid']) or $prava == 1) {
        echo '<div class="links">';
          if ($skupina['zacleneni'] == 1) {echo '<a href="set_integration.php?action=page&amp;id='.$result['id'].'" title="'.$lang['pages_view_code'].'"><img src="stuff/img/icons/wizard.png" alt="'.$lang['pages_view_code'].'" /></a>';};
          echo '<a href="pages.php?action=edit&amp;id='.$result['id'].'" title="'.$lang['pages_edit_page'].'"><img src="stuff/img/icons/edit.png" alt="'.$lang['pages_edit_page'].'" /></a>';
          echo '<img src="stuff/img/icons/trash.png" class="smaz" alt="'.$lang['pages_delete_page'].'" title="'.$lang['pages_delete_page'].'" onclick="smaz_st(\''.$result['id'].'\',\''.$result['nazev'].'\')" />';
        echo '</div>';
      };      
    echo '</td>';
    echo '</tr>';
    echo "\n";
  };
  
  echo '</table>';

    if ($pocet > $limit && empty($_POST)) {
    echo '<br /><br />';
    echo '<div class="kom_strankovani">';
    echo $lang['pages_go_to_page'].': ';
    for($c=1; $c<$pocet_stran+1; $c++) {
        echo '<a href="?strana='.$c.'#vypis"';
        if (($_GET['strana'] == $c) || (!isset($_GET['strana']) && $c == 1)) {echo ' class="aktiv"';};
        echo '>'.$c.'</a>'."\n";
    };
    echo '</div>';
    };
};
};
?>
<script type="text/javascript">
function smaz_st(id, nazev){
jConfirm("<?php echo $lang['pages_really_del_1']; ?> "+nazev+" <?php echo $lang['pages_really_del_2']; ?>", "<?php echo $lang['pages_really_del_headline']; ?>", function(r) {
    if (r == true) {location.replace("pages.php?action=delete&id="+id);};
});
};

function smaz_kom(id, jmeno, druh){
jConfirm("<?php echo $lang['comments_really_del_1']; ?> "+id+" <?php echo $lang['comments_really_del_2']; ?> "+jmeno+"?", "<?php echo $lang['comments_really_del_headline']; ?>", function(r) {
    if (r == true) {location.replace("comments.php?action=delete&id="+id+"&druh="+druh);};
});
};

function ban_user(ip, jmeno){
jConfirm("<?php echo $lang['comments_really_del_3']; ?> "+ip+"<?php echo $lang['comments_really_del_4']; ?> "+jmeno+"?", "<?php echo $lang['comments_really_del_headline']; ?>", function(r) {
    if (r == true) {location.replace("set_banlist.php?ip="+ip+"&duvod=<?php echo rawurlencode($lang['comments_really_default_reason']); ?>");};
});
};
</script>
<?php
include_end();
?>