<?php
$druh = "uzivatele";
include "head.php";
$menu2 = include_menu("uzivatele");
include_head($lang['set_users_title'], $druh);

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

case "add" :

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



if (!empty($_POST)) {

  $jmeno = $_POST['jmeno'];
  $mail = $_POST['mail'];
  $heslo = $_POST['heslo'];
  $heslo2 = $_POST['heslo2'];
  $skupina = $_POST['skupina'];
  
  $query = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_uzivatele WHERE jmeno='".mysql_real_escape_string($jmeno)."'");
  $result = mysql_fetch_array($query);
  
  if (!empty($jmeno) && !empty($mail) && !empty($heslo) && !empty($heslo2) && $heslo == $heslo2 && !empty($skupina) && $result['pocet'] == 0) {
    
  $jmeno = mysql_real_escape_string($jmeno);
  $mail = mysql_real_escape_string($mail);
  $heslo = sha1($heslo);
  $heslo = mysql_real_escape_string($heslo);
  $skupina = mysql_real_escape_string($skupina);
  
     mysql_query("INSERT INTO jtcms_uzivatele (jmeno,mail,heslo,skupina,datum_reg,posledni_pr) VALUES ('".$jmeno."','".$mail."','".$heslo."','".$skupina."',NOW(),NOW())");
     Header("Location: set_users.php?work=added&jmeno=".rawurlencode($jmeno));
     echo '<script type="text/javascript">location.replace("set_users.php?work=added&jmeno='.rawurlencode($jmeno).'")</script>';     
     
  } else {
    echo '<div class="oznameni_div">';
    echo '<div class="chyba">'.$lang['set_users_error'].'</div>';
    if (empty($jmeno)) {echo '<li>'.$lang['set_users_er_1'].'</li>';};
    if (empty($mail)) {echo '<li>'.$lang['set_users_er_16'].'</li>';};
    if (empty($heslo) || empty($heslo2)) {echo '<li>'.$lang['set_users_er_3'].'</li>';};
    if ($heslo != $heslo2) {echo '<li>'.$lang['set_users_er_3'].'</li>';};
    if (empty($skupina)) {echo '<li>'.$lang['set_users_er_4'].'</li>';};
    if ($result['pocet'] != 0) {echo '<li>'.$lang['set_users_er_5'].'</li>';};
    echo '</div>';  
  };

};

$query = mysql_query("SELECT id, nazev FROM jtcms_skupiny ORDER BY id");
?>

<form method="post" action="set_users.php?action=add" id="users_form">
<label for="users_jmeno"><?php echo $lang['set_users_form_1']; ?></label><input type="text" name="jmeno" id="users_jmeno" class="input"<?php if (isset($_POST['jmeno']) && !empty($_POST['jmeno'])) {echo ' value="'.$_POST['jmeno'].'"';}; ?> /><br />
<label for="users_mail"><?php echo $lang['set_users_form_5']; ?></label><input type="text" name="mail" id="users_mail" class="input"<?php if (isset($_POST['mail']) && !empty($_POST['mail'])) {echo ' value="'.$_POST['mail'].'"';}; ?> /><br />
<label for="users_heslo"><?php echo $lang['set_users_form_2']; ?></label><input type="password" name="heslo" id="users_heslo" class="input" /><br />
<label for="users_heslo2"><?php echo $lang['set_users_form_3']; ?></label><input type="password" name="heslo2" id="users_heslo2" class="input" /><br />
<label for="users_prava"><?php echo $lang['set_users_form_4']; ?></label>
<select id="users_prava" name="skupina" size="1" class="input">
<option value="" />--- <?php echo $lang['set_users_select_group']; ?> ---
<?php
while ($result = mysql_fetch_array($query)) {
  echo '<option value="'.$result['id'].'"';
  if (!empty($_POST['skupina']) && $_POST['skupina'] == $result['id']) {echo ' selected';};
  echo ' />'.$result['nazev']."\n";
};
?>
</select>
<br /><br />
<input type="submit" name="submit" value="<?php echo $lang['set_users_submit']; ?>" class="submit" />
</form>

<?php
break;

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

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

 if (empty($id) or $radku == 0) {
    echo '<div class="oznameni_div">';
    echo '<div class="chyba">'.$lang['set_users_error'].'</div>';
    if (empty($id)) {echo '<p>'.$lang['set_users_er_6'].'</p>';};
    if ($radku == 0) {echo '<p>'.$lang['set_users_er_7'].'</p>';};
    echo '</div>';
    
    include_end();
    exit();
  };
  
if (!empty($_POST)) {
  $id = $_GET['id'];
  $jmeno = $_POST['jmeno'];
  $mail = $_POST['mail'];
  $skupina = $_POST['skupina'];
  $heslo = $_POST['heslo'];
  $heslo2 = $_POST['heslo2'];
  
  if (!empty($id) && !empty($mail) && !empty($jmeno) && !empty($skupina)) {
  
    $query = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_uzivatele WHERE skupina='1'");
    $result = mysql_fetch_array($query);
    
    $query2 = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_uzivatele WHERE id='".$id."' and skupina='1'");
    $result2 = mysql_fetch_array($query2);
    
    if ($result['pocet'] == 1 && $result2['pocet'] == 1 && $skupina != 1) {
      echo '<div class="oznameni_div">';
      echo '<div class="chyba">'.$lang['set_users_error'].'</div>';
      echo '<p>'.$lang['set_users_er_8'].'</p>';
      echo '</div>';
    
      include_end();
      exit();
    };
    
    $mail = mysql_real_escape_string($mail);
    $jmeno = mysql_real_escape_string($jmeno);
    $prava = mysql_real_escape_string($prava);
  
    if (!empty($heslo) && !empty($heslo2) && $heslo == $heslo2) {
      $heslo = sha1($heslo);
      $heslo = mysql_real_escape_string($heslo);
      mysql_query("UPDATE jtcms_uzivatele SET jmeno='".$jmeno."', mail='".$mail."', skupina='".$skupina."', heslo='".$heslo."' WHERE id='".$id."' LIMIT 1");
    } else {
      mysql_query("UPDATE jtcms_uzivatele SET jmeno='".$jmeno."', mail='".$mail."', skupina='".$skupina."' WHERE id='".$id."' LIMIT 1");
    };
        
    Header("Location: set_users.php?work=edited&jmeno=".rawurlencode($jmeno));
    echo '<script type="text/javascript">location.replace("set_users.php?work=edited&jmeno='.rawurlencode($jmeno).'")</script>';
      
  } else {
    echo '<div class="oznameni_div">';
    echo '<div class="chyba">'.$lang['set_users_error'].'</div>';
    if (empty($id)) {echo '<li>'.$lang['set_users_er_6'].'</li>';};
    if (empty($jmeno)) {echo '<li>'.$lang['set_users_er_1'].'</li>';};
    if (empty($mail)) {echo '<li>'.$lang['set_users_er_16'].'</li>';};
    if (empty($skupina)) {echo '<li>'.$lang['set_users_er_9'].'</li>';};
    echo '</div>';    
  };

};

$skupiny_query = mysql_query("SELECT id, nazev FROM jtcms_skupiny ORDER BY id");
?>

<form method="post" action="set_users.php?action=edit&amp;id=<?php echo $id; ?>" id="users_form">
<label for="users_jmeno"><?php echo $lang['set_users_form_1']; ?></label><input type="text" name="jmeno" id="users_jmeno" class="input" value="<?php if (empty($_POST['jmeno'])) {echo $result['jmeno'];} else {echo $_POST['jmeno'];}; ?>" /><br />
<label for="users_mail"><?php echo $lang['set_users_form_5']; ?></label><input type="text" name="mail" id="users_mail" class="input" value="<?php if (empty($_POST['mail'])) {echo $result['mail'];} else {echo $_POST['mail'];}; ?>" /><br />
<label for="users_heslo"><?php echo $lang['set_users_form_2']; ?></label><input type="password" name="heslo" id="users_heslo" class="input" /><br />
<label for="users_heslo2"><?php echo $lang['set_users_form_3']; ?></label><input type="password" name="heslo2" id="users_heslo2" class="input" /><br />
<label for="users_prava"><?php echo $lang['set_users_form_4']; ?></label>
<select id="users_prava" name="skupina" size="1" class="input">
<option value="" />--- <?php echo $lang['set_users_select_group']; ?> ---
<?php
while ($skupiny_result = mysql_fetch_array($skupiny_query)) {
  echo '<option value="'.$skupiny_result['id'].'"';
  if (empty($_POST['skupina'])) {if ($skupiny_result['id'] == $result['skupina']) {echo ' selected';};} else {if ($_POST['skupina'] == $skupiny_result['id']) {echo ' selected';};};
  echo ' />'.$skupiny_result['nazev']."\n";
};
?>
</select>
<br /><br />
<input type="submit" name="submit" value="<?php echo $lang['set_users_submit2']; ?>" class="submit" />
</form>
<br /><br />
<p align="center"><?php echo $lang['set_users_instruction_1']; ?><br />
<?php echo $lang['set_users_instruction_2']; ?></p>
<?php
break;

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

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

 if (empty($id) or $radku == 0 or $id == $_SESSION['userid']) {
    echo '<div class="oznameni_div">';
    echo '<div class="chyba">'.$lang['set_users_error'].'</div>';
    if (empty($id)) {echo '<p>'.$lang['set_users_er_6'].'</p>';};
    if ($radku == 0) {echo '<p>'.$lang['set_users_er_7'].'</p>';};
    if ($id == $_SESSION['userid']) {echo '<p>'.$lang['set_users_er_17'].'</p>';};
    echo '</div>';
    
    include_end();
    exit();
  };

    $query3 = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_uzivatele WHERE skupina='1'");
    $result3 = mysql_fetch_array($query3);
    
    $query2 = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_uzivatele WHERE id='".$id."' and skupina='1'");
    $result2 = mysql_fetch_array($query2);
    
    if ($result3['pocet'] == 1 && $result2['pocet'] == 1) {
      echo '<div class="oznameni_div">';
      echo '<div class="chyba">'.$lang['set_users_error'].'</div>';
      echo '<p>'.$lang['set_users_er_10'].'</p>';
      echo '</div>';
    
      include_end();
      exit();
    };
?>
<form method="post" action="set_users.php?action=delete&amp;id=<?php echo $id; ?>" id="users_del_form">
  <input type="radio" name="typ" id="set_users_typ1" value="1" checked /><label for="set_users_typ1"><?php echo $lang['set_users_deltyp_1']; ?></label>
  <select name="autor" size="1" class="input">
    <?php $query = mysql_query("SELECT id, jmeno FROM jtcms_uzivatele ORDER BY id");
    while ($result = mysql_fetch_array($query)) {
      if ($result['id'] != $id) {
        echo '<option value="'.$result['id'].'"';
        if (!empty($_POST['autor']) && $_POST['autor'] == $result['id']) {echo ' selected';};
        echo ' />'.$result['jmeno']."\n";
      };
    }; ?>  
  </select><br /><br />
  <input type="radio" name="typ" id="set_users_typ2" value="2" /><label for="set_users_typ2"><?php echo $lang['set_users_deltyp_2']; ?></label>
    <br /><br />
  <input type="submit" name="submit" value="<?php echo $lang['set_users_user_delete']; ?>" class="submit" />
</form>
  
<?php
if (!empty($_POST)) { 

  $typ = $_POST['typ'];
    
  if (!empty($typ)) {
  
    switch ($typ) {
      case "1" :
        $autor = $_POST['autor'];
        
        mysql_query("UPDATE jtcms_clanky SET pridal='".$autor."' WHERE pridal='".$id."'");
        mysql_query("UPDATE jtcms_stranky SET pridal='".$autor."' WHERE pridal='".$id."'");
        mysql_query("UPDATE jtcms_kategorie SET pridal='".$autor."' WHERE pridal='".$id."'");
        mysql_query("UPDATE jtcms_stitky SET pridal='".$autor."' WHERE pridal='".$id."'");
        mysql_query("UPDATE jtcms_galerie SET pridal='".$autor."' WHERE pridal='".$id."'");
        mysql_query("UPDATE jtcms_soubory_slozky SET pridal='".$autor."' WHERE pridal='".$id."'");
        mysql_query("UPDATE jtcms_soubory SET pridal='".$autor."' WHERE pridal='".$id."'");
        mysql_query("DELETE FROM jtcms_uzivatele WHERE id='".$id."' LIMIT 1");    
      
      break;
      case "2" :
        $query7 = mysql_query("SELECT * FROM jtcms_clanky WHERE obrazek!=''");
        
        while ($result7 = mysql_fetch_array($query7)) {
          unlink("./data/art_img/".$result7['obrazek']);
        };
        
        mysql_query("DELETE FROM jtcms_clanky WHERE pridal='".$id."'");
        mysql_query("DELETE FROM jtcms_stranky WHERE pridal='".$id."'");
        mysql_query("DELETE FROM jtcms_kategorie WHERE pridal='".$id."'");
        $query3 = mysql_query("SELECT * FROM jtcms_stitky WHERE pridal='".$id."'");
        
        while ($result3 = mysql_fetch_array($query3)) {
          $idecko = $result3['id'];        
          $query2 = mysql_query("SELECT id, stitky FROM jtcms_clanky WHERE stitky LIKE '%;".$idecko.";%' or stitky LIKE '".$idecko.";%' or stitky LIKE '%;".$idecko."' or stitky='".$idecko."'");    
          while ($result2 = mysql_fetch_array($query2)) {          
            $stitky = $result2['stitky'];
            if (preg_match(";", $stitky)) {  
              $stitky = str_replace(";".$idecko.";", ";", $stitky);
              $stitky = str_replace(";".$idecko, "", $stitky);
              $stitky = str_replace($idecko.";", "", $stitky);
            } else {
              $stitky = "";
            };
      
            mysql_query("UPDATE jtcms_clanky SET stitky='".$stitky."' WHERE id='".$result2['id']."' LIMIT 1");
          };
        };
        mysql_query("DELETE FROM jtcms_stitky WHERE pridal='".$id."'");
        
        $query4 = mysql_query("SELECT * FROM jtcms_galerie WHERE pridal='".$id."'");

        while ($result4 = mysql_fetch_array($query4)) {
        $adresar = opendir("data/gal/".$result4['id']."/");
          while ($soubor = readdir($adresar)){
               if (!is_dir($soubor)) {
                unlink("./data/gal/".$result4['id']."/".$soubor);
              };
          };
        rmdir("./data/gal/".$result4['id']."/");
        };
    
        mysql_query("DELETE FROM jtcms_galerie WHERE pridal='".$id."'");
        
        $query5 = mysql_query("SELECT * FROM jtcms_soubory WHERE pridal='".$id."'");
        
        while ($result5 = mysql_fetch_array($query5)) {
          unlink("./data/files/".$result5['slozka']."/".$result5['nazev']);  
        };
        
        mysql_query("DELETE FROM jtcms_soubory WHERE pridal='".$id."'");
        
        $query6 = mysql_query("SELECT * FROM jtcms_soubory_slozky WHERE pridal='".$id."'");
        
        while ($result6 = mysql_fetch_array($query6)) {
        $adresar = opendir("data/files/".$result6['id']."/");
          while ($soubor = readdir($adresar)){
               if (!is_dir($soubor)) {
                unlink("./data/files/".$result6['id']."/".$soubor);
              };
          };
        rmdir("./data/files/".$result6['id']."/");
        };
        
        mysql_query("DELETE FROM jtcms_soubory_slozky WHERE pridal='".$id."'");
        mysql_query("DELETE FROM jtcms_uzivatele WHERE id='".$id."' LIMIT 1");  
      break;
    };
    Header("Location: set_users.php?work=deleted&jmeno=".rawurlencode($jmeno));
    echo '<script type="text/javascript">location.replace("set_users.php?work=deleted&jmeno='.rawurlencode($jmeno).'")</script>';    
  } else {
    echo '<div class="oznameni_div">';
    echo '<div class="chyba">'.$lang['set_users_error'].'</div>';
    if (empty($typ)) {echo '<li>'.$lang['set_users_er_15'].'</li>';};
    echo '</div>'; 
  };
};

break;

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

 if (empty($id) or $radku == 0) {
    echo '<div class="oznameni_div">';
    echo '<div class="chyba">'.$lang['set_users_error'].'</div>';
    if (empty($id)) {echo '<p>'.$lang['set_users_er_6'].'</p>';};
    if ($radku == 0) {echo '<p>'.$lang['set_users_er_7'].'</p>';};
    echo '</div>';
    
    include_end();
    exit();
  };
  
    
  $query_cat = mysql_query("SELECT id, nazev, datum, pridal FROM jtcms_kategorie WHERE pridal='".$id."' ORDER BY datum DESC");
  $query_art_in_cat = mysql_query("SELECT id, nazev, pridal FROM jtcms_kategorie WHERE pridal='".$id."'");
  $radku_cat = mysql_num_rows($query_cat);
  
  $query_gal = mysql_query("SELECT * FROM jtcms_galerie WHERE pridal='".$id."' ORDER BY datum DESC");
  $query_photos_in_gal = mysql_query("SELECT id, nazev, pridal FROM jtcms_galerie WHERE pridal='".$id."'");
  $radku_gal = mysql_num_rows($query_gal);

  $query_pag = mysql_query("SELECT id, nazev, datum, pridal FROM jtcms_stranky WHERE pridal='".$id."' ORDER BY datum DESC");
  $query_pag_kom = mysql_query("SELECT id, nazev, pridal FROM jtcms_stranky WHERE pridal='".$id."'");
  $radku_pag = mysql_num_rows($query_pag);
  
  $query_art = mysql_query("SELECT id, nazev, datum, pridal FROM jtcms_clanky WHERE pridal='".$id."' ORDER BY datum DESC");
  $query_art_kom = mysql_query("SELECT id, nazev, pridal FROM jtcms_clanky WHERE pridal='".$id."'");
  $radku_art = mysql_num_rows($query_art);
  
  

  $art_view = mysql_query("SELECT SUM(pocet) AS precteni FROM jtcms_clanky WHERE pridal='".$id."'");
  $art_view = mysql_fetch_array($art_view);
  $art_view = set_zero_is_empty($art_view['precteni']);
    
  $art_with_img = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_clanky WHERE pridal='".$id."' and obrazek!=''");
  $art_with_img = mysql_fetch_array($art_with_img);
  $art_with_img = set_zero_is_empty($art_with_img['pocet']);
  
  $kom_dotaz = "";
  while ($kom = mysql_fetch_array($query_art_kom)) {
    $kom_dotaz .= "clanek='".$kom['id']."' OR ";
  };
  $kom_dotaz = preg_replace("/ OR $/", "", $kom_dotaz);
  
  $kom_dotaz = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_komentare_cl WHERE ".$kom_dotaz);
  $kom_pocet_art = mysql_fetch_array($kom_dotaz);
  $kom_pocet_art = set_zero_is_empty($kom_pocet_art['pocet']);
  
  $pag_view = mysql_query("SELECT SUM(pocet) AS precteni FROM jtcms_stranky WHERE pridal='".$id."'");
  $pag_view = mysql_fetch_array($pag_view);
  $pag_view = set_zero_is_empty($pag_view['precteni']);
  
  $kom_dotaz = "";
  while ($kom = mysql_fetch_array($query_pag_kom)) {
    $kom_dotaz .= "stranka='".$kom['id']."' OR ";
  };
  $kom_dotaz = preg_replace("/ OR $/", "", $kom_dotaz);
  
  $kom_dotaz = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_komentare_st WHERE ".$kom_dotaz);
  $kom_pocet_pag = mysql_fetch_array($kom_dotaz);
  $kom_pocet_pag = set_zero_is_empty($kom_pocet_pag['pocet']);
  
  $art_in_cat = 0;
  while ($art_in_cat_res = mysql_fetch_array($query_art_in_cat)) {
    $query_art_cat = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_clanky WHERE kategorie='".$art_in_cat_res['id']."'");
    $result_art_cat = mysql_fetch_array($query_art_cat);
    $result_art_cat = $result_art_cat['pocet'];
    $art_in_cat = $art_in_cat+$result_art_cat;
  };
  
  $num = 0;
  while ($result_photos_in_gal = mysql_fetch_array($query_photos_in_gal)) {
    $adresar = opendir("./data/gal/".$result_photos_in_gal['id']);
    while ($soubor = readdir($adresar)){
      $num++;
    };
    $num = $num-2;
  };
         
  $photos_in_gal = $num;

  $query_max_view_art = mysql_query("SELECT u.* FROM jtcms_uzivatele u ORDER BY (SELECT SUM(pocet) AS pocet FROM jtcms_clanky WHERE pridal=u.id) DESC");
  $max_view_count_art = 1;
  while ($result_max_view_art = mysql_fetch_array($query_max_view_art)) {
    $max_view_art[$max_view_count_art] = $result_max_view_art['id'];
    $max_view_count_art++;
  };

  $max_view_art = array_flip($max_view_art);
  
  $query_max_view_pag = mysql_query("SELECT u.* FROM jtcms_uzivatele u ORDER BY (SELECT SUM(pocet) AS pocet FROM jtcms_stranky WHERE pridal=u.id) DESC");
  $max_view_count_pag = 1;
  while ($result_max_view_pag = mysql_fetch_array($query_max_view_pag)) {
    $max_view_pag[$max_view_count_pag] = $result_max_view_pag['id'];
    $max_view_count_pag++;
  };

  $max_view_pag = array_flip($max_view_pag);
  
  $files = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_soubory WHERE pridal='".$id."'");
  $files = mysql_fetch_array($files);
  $files = $files['pocet'];
  
  $folders = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_soubory_slozky WHERE pridal='".$id."'");
  $folders = mysql_fetch_array($folders);
  $folders = $folders['pocet'];
?>

<div class="filtr_but" onclick="$('.set_users_admin_info').slideToggle();"><img src="stuff/img/icons/shield.png" alt="" /> <?php echo $lang['set_users_admin_info']; ?></div>
<div class="filtr_but" onclick="$('.set_users_statistics').slideToggle();"><img src="stuff/img/icons/statistics.png" alt="" /> <?php echo $lang['set_users_statistics']; ?></div>

<h1 class="tal"><?php echo $lang['set_users_user_detail'].' '.$result['jmeno']; ?></h1>
<br />

<div class="set_users_admin_info">
<?php 
  echo '<li><img src="stuff/img/icons/computer.png" alt="" />'.$lang['set_users_last_ip'].' '.$result['posledni_ip'].' <img src="stuff/img/icons/ban_user16.png" alt="'.$lang['set_users_ban_ip'].'" title="'.$lang['set_users_ban_ip'].'" class="smaz" onclick="ban_user(\''.$result['posledni_ip'].'\')" /></li>';
  echo '<li><img src="stuff/img/icons/calendar.png" alt="" />'.$lang['set_users_register_date'].' '.$result['datum_reg'].'</li>';
  echo '<li><img src="stuff/img/icons/date.png" alt="" />'.$lang['set_users_last_login'].' '.$result['posledni_pr'].'</li>';
?>
</div>

<div class="set_users_statistics">
<table class="uzivatele_stat_tabulka">
<tr class="prvni_tr"><td class="td1"></td><td class="td2"></td><td class="td3"></td></tr>
<?php
  echo '<tr class="first_tr"><td class="first"><img src="stuff/img/icons/lists.png" alt="" /></td><td>'.$lang['set_users_stat_1'].'</td><td class="result last">'.$radku_art.'</td></tr>';
echo "\n\r";
  echo '<tr class="bg"><td class="first"></td><td>'.$lang['set_users_stat_2'].'</td><td class="result last">'.$art_view.'</td></tr>';
echo "\n\r";
  echo '<tr class="bg"><td class="first"></td><td>'.$lang['set_users_stat_11'].'</td><td class="result last">'.$art_with_img.'</td></tr>';
echo "\n\r";
  echo '<tr class="last_tr"><td class="first"></td><td>'.$lang['set_users_stat_3'].'</td><td class="result last">'.$kom_pocet_art.'</td></tr>';
echo "\n\r";
  echo '<tr><td><img src="stuff/img/icons/text.png" alt="" /></td><td>'.$lang['set_users_stat_4'].'</td><td class="result">'.$radku_pag.'</td></tr>';
echo "\n\r";
  echo '<tr><td></td><td>'.$lang['set_users_stat_5'].'</td><td class="result">'.$pag_view.'</td></tr>';
echo "\n\r";
    echo '<tr><td></td><td>'.$lang['set_users_stat_6'].'</td><td class="result">'.$kom_pocet_pag.'</td></tr>';
echo "\n\r";
  echo '<tr class="first_tr"><td class="first"><img src="stuff/img/icons/open folder.png" alt="" /></td><td>'.$lang['set_users_stat_7'].'</td><td class="result last">'.$radku_cat.'</td></tr>';
echo "\n\r";
    echo '<tr class="last_tr"><td class="first"></td><td>'.$lang['set_users_stat_8'].'</td><td class="result last">'.$art_in_cat.'</td></tr>';
echo "\n\r";
  echo '<tr><td><img src="stuff/img/icons/camera.png" alt="" /></td><td>'.$lang['set_users_stat_9'].'</td><td class="result">'.$radku_gal.'</td></tr>';
echo "\n\r";
    echo '<tr><td></td><td>'.$lang['set_users_stat_10'].'</td><td class="result">'.$photos_in_gal.'</td></tr>';
echo "\n\r";
  echo '<tr class="first_tr"><td class="first"><img src="stuff/img/icons/software.png" alt="" /></td><td>'.$lang['set_users_stat_15'].'</td><td class="result last">'.$files.'</td></tr>';
echo "\n\r";
    echo '<tr class="last_tr"><td class="first"></td><td>'.$lang['set_users_stat_16'].'</td><td class="result last">'.$folders.'</td></tr>';
echo "\n\r";

  echo '<tr><td><img src="stuff/img/icons/monitor.png" alt="" /></td><td>'.$lang['set_users_stat_14'].'</td><td></td></tr>';
echo "\n\r";    
  echo '<tr><td></td><td>'.$lang['set_users_stat_12'].'</td><td class="result">'.$max_view_art[$id].'</td></tr>';
echo "\n\r";
  echo '<tr><td></td><td>'.$lang['set_users_stat_13'].'</td><td class="result">'.$max_view_pag[$id].'</td></tr>';
echo "\n\r";
?>
</table>
</div>

<?php

  
  echo '<h2>'.$lang['set_users_categories'].'</h2>';
  
echo '<div class="user_detail_div">';
  if ($radku_cat == 0) {
     
    echo '<p>'.$lang['set_users_er_11'].'</p>';
      
  } else { 
   
    while ($result = mysql_fetch_array($query_cat)) {
      echo '<li>';
      switch ($prava['kategorie']) {
        case "1" : 
          echo '<a href="categories.php?action=detail&amp;kategorie='.$result['id'].'" title="'.$lang['set_users_date_of_add'].' '.StrFTime("%H:%M %d.%m.%Y", strtotime($result['datum'])).'">'.$result['nazev'].'</a>';
        break;
        case "2" : 
          if ($result['pridal'] == $_SESSION['userid']) {
            echo '<a href="categories.php?action=detail&amp;kategorie='.$result['id'].'" title="'.$lang['set_users_date_of_add'].' '.StrFTime("%H:%M %d.%m.%Y", strtotime($result['datum'])).'">'.$result['nazev'].'</a>';
          } else {
            echo '<span title="'.$lang['set_users_date_of_add'].' '.StrFTime("%H:%M %d.%m.%Y", strtotime($result['datum'])).'">'.$result['nazev'].'</span>';
          };
        break;
      };
      echo '</li>';
      echo "\n\r";
    };
    
  };
echo '</div>';
  echo '<br />';

  
  echo '<h2>'.$lang['set_users_galleries'].'</h2>';

echo '<div class="user_detail_div">';  
  if ($radku_gal == 0) {
  
    echo '<p>'.$lang['set_users_er_14'].'</p>';
      
  } else { 
   
    while ($result = mysql_fetch_array($query_gal)) {
      echo '<li>';
      switch ($prava['kategorie']) {
        case "1" : 
          echo '<a href="galleries.php?action=edit&amp;id='.$result['id'].'" title="'.$lang['set_users_date_of_add'].' '.StrFTime("%H:%M %d.%m.%Y", strtotime($result['datum'])).'">'.$result['nazev'].'</a>';
        break;
        case "2" : 
          if ($result['pridal'] == $_SESSION['userid']) {
            echo '<a href="galleries.php?action=edit&amp;id='.$result['id'].'" title="'.$lang['set_users_date_of_add'].' '.StrFTime("%H:%M %d.%m.%Y", strtotime($result['datum'])).'">'.$result['nazev'].'</a>';
          } else {
            echo '<span title="'.$lang['set_users_date_of_add'].' '.StrFTime("%H:%M %d.%m.%Y", strtotime($result['datum'])).'">'.$result['nazev'].'</span>';
          };
        break;
      };
      echo '</li>';
      echo "\n\r";
    };

  };
echo '</div>';
  echo '<br />';
  
  
  echo '<h2>'.$lang['set_users_pages'].'</h2>';
  
echo '<div class="user_detail_div">';  
  if ($radku_pag == 0) {

    echo '<p>'.$lang['set_users_er_12'].'</p>';
      
  } else { 
  
    while ($result = mysql_fetch_array($query_pag)) {
      echo '<li>';
      switch ($prava['stranky']) {
        case "1" : 
          echo '<a href="pages.php?action=read&amp;id='.$result['id'].'" title="'.$lang['set_users_date_of_add'].' '.StrFTime("%H:%M %d.%m.%Y", strtotime($result['datum'])).'">'.$result['nazev'].'</a>';
        break;
        case "2" : 
          if ($result['pridal'] == $_SESSION['userid']) {
            echo '<a href="pages.php?action=edit&amp;id='.$result['id'].'" title="'.$lang['set_users_date_of_add'].' '.StrFTime("%H:%M %d.%m.%Y", strtotime($result['datum'])).'">'.$result['nazev'].'</a>';
          } else {
            echo '<span title="'.$lang['set_users_date_of_add'].' '.StrFTime("%H:%M %d.%m.%Y", strtotime($result['datum'])).'">'.$result['nazev'].'</span>';
          };
        break;
      };
      echo '</li>';
      echo "\n\r";
    };

  };
echo '</div>';
  echo '<br />';
  
  
  echo '<h2>'.$lang['set_users_articles'].'</h2>';

echo '<div class="user_detail_div">';  
  if ($radku_art == 0) {

    echo '<p>'.$lang['set_users_er_13'].'</p>';
      
  } else { 
  
    while ($result = mysql_fetch_array($query_art)) {
      echo '<li>';
      switch ($prava['clanky']) {
        case "1" : 
          echo '<a href="articles.php?action=read&amp;id='.$result['id'].'" title="'.$lang['set_users_date_of_add'].' '.StrFTime("%H:%M %d.%m.%Y", strtotime($result['datum'])).'">'.$result['nazev'].'</a>';
        break;
        case "2" : 
          if ($result['pridal'] == $_SESSION['userid']) {
            echo '<a href="articles.php?action=edit&amp;id='.$result['id'].'" title="'.$lang['set_users_date_of_add'].' '.StrFTime("%H:%M %d.%m.%Y", strtotime($result['datum'])).'">'.$result['nazev'].'</a>';
          } else {
            echo '<span title="'.$lang['set_users_date_of_add'].' '.StrFTime("%H:%M %d.%m.%Y", strtotime($result['datum'])).'">'.$result['nazev'].'</span>';
          };
        break;
      };
      echo '</li>';
      echo "\n\r";
    };
  };
echo '</div>';
  echo '<br />';

break;

default :

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

if (!isset($_GET['work'])) {$_GET['work'] = "default";};
switch ($_GET['work']) {
case "added" :
echo '<div class="oznameni_div">';
echo '<p>'.$lang['set_users_user'].' <span class="blue">'.stripslashes($_GET['jmeno']).'</span> '.$lang['set_users_work_1'].'</p>';
echo '</div>';
break;

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

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

};


$query = mysql_query("SELECT * FROM jtcms_uzivatele ORDER BY id");
$radku = mysql_num_rows($query); ?>

<a href="set_users.php?action=add" class="pridat_tlacitko fl"><img src="stuff/img/icons/create.png" alt="+" /> <?php echo $lang['set_users_user_add']; ?></a>

<div class="nf"></div>
<br />
<table class="uzivatele_tabulka">
<tr class="prvni_tr">
  <td class="td1 first"><?php echo $lang['set_users_name']; ?></td>
  <td class="td2"><?php echo $lang['set_users_mail']; ?></td>
  <td class="td3 last"><?php echo $lang['set_users_group']; ?></td>
</tr>
<?php
  while ($result = mysql_fetch_array($query)) {
    $query2 = mysql_query("SELECT nazev FROM jtcms_skupiny WHERE id='".$result['skupina']."' LIMIT 1");
    $result2 = mysql_fetch_array($query2);
    
    echo '<tr>';
    echo '<td>&nbsp;<a href="set_users.php?action=detail&amp;id='.$result['id'].'">'.$result['jmeno'].'</a></td>';
    echo '<td>'.$result['mail'].'</td>';
    echo '<td>';
      echo '<div class="links">';
       echo '<div>';
        echo '<a href="set_users.php?action=edit&amp;id='.$result['id'].'" title="'.$lang['set_users_user_edit'].'"><img src="stuff/img/icons/edit.png" alt="'.$lang['set_users_user_edit'].'" /></a>';
        echo '<img src="stuff/img/icons/trash.png" title="'.$lang['set_users_user_delete'].'" class="smaz" alt="'.$lang['set_users_user_delete'].'" onclick="smaz_uz(\''.$result['id'].'\',\''.$result['jmeno'].'\')" />';
       echo '</div>';
      echo '</div>';
      echo $result2['nazev'];
    echo '</td>';
    echo '</tr>';
    echo "\n";
  }; 

echo '</table>';
};
?>
<script type="text/javascript">
function smaz_uz(id, jmeno){
jConfirm("<?php echo $lang['set_users_really_del_1']; ?> "+jmeno+"?", "<?php echo $lang['set_users_really_del_headline']; ?>", function(r) {
    if (r == true) {location.replace("set_users.php?action=delete&id="+id);};
});
};

function ban_user(ip, jmeno){
jConfirm("<?php echo $lang['set_users_really_ban_1']; ?> "+ip+"?", "<?php echo $lang['set_users_really_del_headline']; ?>", function(r) {
    if (r == true) {location.replace("set_banlist.php?ip="+ip);};
});
};
</script>
<?php
include_end();
?>