<?php
include "head.php";
include_head($lang['login_title']);

$query = mysql_query("SELECT jmeno FROM jtcms_uzivatele WHERE id='".$_SESSION['userid']."' LIMIT 1");
$result = mysql_fetch_array($query);


echo '<div class="login_head">';
if ($prava['clanky'] != 3) { echo '<a class="filtr_but add_button" href="articles.php?action=add"><img src="stuff/img/icons/add.png" alt="" /> '.$lang['login_head_article'].'</a>';};
if ($prava['stranky'] != 3) { echo '<a class="filtr_but add_button" href="pages.php?action=add"><img src="stuff/img/icons/add.png" alt="" /> '.$lang['login_head_page'].'</a>';};
echo '<h1><a href="my_account.php" title="'.$result['jmeno'].'">'.$result['jmeno'].'</a></h1>';
echo '</div>';


$query = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='jtcms_verze' LIMIT 1");
$result = mysql_fetch_array($query);

$fp = fsockopen ("cms.jt-cms.com", 80, $errno, $errstr, 30);
if (!$fp) {   
    echo "";
} else {
    fputs ($fp, "GET /verze.php HTTP/1.0\r\nHost: cms.jt-cms.com\r\n\r\n");
    $check_version = "";
    while (!feof($fp)) {
        $check_version .= fgets ($fp,128);
    }
    fclose ($fp);

$check_version = strstr($check_version, "\r\n\r\n");
$check_version = substr($check_version, 4, strlen($check_version) - 4);
};

if (!preg_match("/[1-9]\.[0-9]\.[0-9]/", $check_version)) { 
  $xml = simplexml_load_file("http://cms.jt-cms.com/version_xml.xml");
  $index = 1;

  foreach ($xml->channel->version as $item) {
    if($index > 1){ break; }
    $index++;
    $check_version = $item->designation;
  };
};

if (!preg_match("/[1-9]\.[0-9]\.[0-9]/", $check_version)) {
  $check_version = $result['hodnota'];
  $no_read_version = TRUE;
}; 

if ($check_version > $result['hodnota']) { ?>
  <div class="novaverze">
  <div class="nadpis"><?php echo $lang['login_new_version']; ?></div>
  <p><?php echo $lang['login_new_1']; ?> <span class="verze"><?php echo $result['hodnota']; ?></span> <?php echo $lang['login_new_2']; ?> <span class="verze"><?php if (empty($check_version)) {echo $lang['login_new_ver_error'];} else {echo $check_version;}; ?></span>. <?php echo $lang['login_new_3']; ?></p>  
  </div>
<?php
};
?>
<br />
<table class="login_tabulka aktualne">
<tr class="prvni_tr"><td class="first_a_last" colspan="2"><h2 title="<?php echo $lang['login_table_title']; ?>"><?php echo $lang['login_table_h2']; ?></h2></td></tr>
<?php
$result = mysql_query("SELECT * FROM jtcms_zmenilose WHERE typ='precteni_clanku'");
$query = mysql_fetch_array($result);
$radku = mysql_num_rows($result);

$result2 = mysql_query("SELECT SUM(pocet) AS pocet, COUNT(*) AS pocet_radku FROM jtcms_clanky");
$query2 = mysql_fetch_array($result2);


if ((($query['old'] == $query2['pocet']) && $radku != "0") || $query2['pocet_radku'] == 0) {
echo '<tr><td>0</td><td class="tal">'.$lang['login_table_1'].'</td></tr>';
  if ($query2['pocet_radku'] == 0) {
    $precteni_clanku = 0;
  } else {
    $precteni_clanku = $query2['pocet'];
  };
} else {
   if ($radku == 0) {
   mysql_query("INSERT INTO jtcms_zmenilose (typ,old,datum) VALUES ('precteni_clanku','".$query2['pocet']."',NOW())");
   };
mysql_query("UPDATE jtcms_zmenilose SET old='".$query2['pocet']."', datum=NOW() WHERE typ='precteni_clanku' LIMIT 1");
$pribylo = $query2['pocet']-$query['old'];
echo '<tr><td class="new">'.$pribylo.'</td><td class="tal">'.$lang['login_table_1'].'</td></tr>';
$precteni_clanku = $query2['pocet'];
};


$result = mysql_query("SELECT * FROM jtcms_zmenilose WHERE typ='precteni_stranky'");
$query = mysql_fetch_array($result);
$radku = mysql_num_rows($result);

$result2 = mysql_query("SELECT SUM(pocet) AS pocet, COUNT(*) AS pocet_radku FROM jtcms_stranky");
$query2 = mysql_fetch_array($result2);

if ((($query['old'] == $query2['pocet']) && $radku != "0") || $query2['pocet_radku'] == 0) {
echo '<tr><td>0</td><td class="tal">'.$lang['login_table_2'].'</td></tr>';
  if ($query2['pocet_radku'] == 0) {
    $precteni_stranky = 0;
  } else {
    $precteni_stranky = $query2['pocet'];
  };
} else {
   if ($radku == 0) {
   mysql_query("INSERT INTO jtcms_zmenilose (typ,old,datum) VALUES ('precteni_stranky','".$query2['pocet']."',NOW())");
   };
mysql_query("UPDATE jtcms_zmenilose SET old='".$query2['pocet']."', datum=NOW() WHERE typ='precteni_stranky' LIMIT 1");
$pribylo = $query2['pocet']-$query['old'];
echo '<tr><td class="new">'.$pribylo.'</td><td class="tal">'.$lang['login_table_2'].'</td></tr>';
$precteni_stranky = $query2['pocet'];
};


$result = mysql_query("SELECT * FROM jtcms_zmenilose WHERE typ='komentare_cl'");
$query = mysql_fetch_array($result);
$radku = mysql_num_rows($result);

$result2 = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_komentare_cl");
$query2 = mysql_fetch_array($result2);

if (($query['old'] == $query2['pocet']) && $radku != "0") {
echo '<tr><td>0</td><td class="tal">'.$lang['login_table_3'].'</td></tr>';
$komentare_cl = $query2['pocet'];
} else {
   if ($radku == 0) {
   mysql_query("INSERT INTO jtcms_zmenilose (typ,old,datum) VALUES ('komentare_cl','".$query2['pocet']."',NOW())");
   };
mysql_query("UPDATE jtcms_zmenilose SET old='".$query2['pocet']."', datum=NOW() WHERE typ='komentare_cl' LIMIT 1");
$pribylo = $query2['pocet']-$query['old'];
echo '<tr><td class="new"><a href="comments.php?komentare=clanky">'.$pribylo.'</a></td><td class="tal">'.$lang['login_table_3'].'</td></tr>';
$komentare_cl = $query2['pocet'];
};


$result = mysql_query("SELECT * FROM jtcms_zmenilose WHERE typ='komentare_st'");
$query = mysql_fetch_array($result);
$radku = mysql_num_rows($result);

$result2 = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_komentare_st");
$query2 = mysql_fetch_array($result2);

if (($query['old'] == $query2['pocet']) && $radku != "0") {
echo '<tr><td>0</td><td class="tal">'.$lang['login_table_4'].'</td></tr>';
$komentare_st = $query2['pocet'];
} else {
   if ($radku == 0) {
   mysql_query("INSERT INTO jtcms_zmenilose (typ,old,datum) VALUES ('komentare_st','".$query2['pocet']."',NOW())");
   };
mysql_query("UPDATE jtcms_zmenilose SET old='".$query2['pocet']."', datum=NOW() WHERE typ='komentare_st' LIMIT 1");
$pribylo = $query2['pocet']-$query['old'];
echo '<tr><td class="new"><a href="comments.php?komentare=stranky">'.$pribylo.'</a></td><td class="tal">'.$lang['login_table_4'].'</td></tr>';
$komentare_st = $query2['pocet'];
};
?>
<tr class="posledni_tr"><td class="first_last" colspan="2"></td></tr>
</table>

<?php
$query = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_clanky");
$result = mysql_fetch_array($query);
$clanku = $result['pocet'];

$query = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_stitky");
$result = mysql_fetch_array($query);
$stitku = $result['pocet'];

$query = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_galerie");
$result = mysql_fetch_array($query);
$galerii = $result['pocet'];

$query = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_soubory");
$result = mysql_fetch_array($query);
$souboru = $result['pocet'];

$query = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_soubory_slozky");
$result = mysql_fetch_array($query);
$slozek = $result['pocet'];

$query = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_stranky");
$result = mysql_fetch_array($query);
$stranek = $result['pocet'];

$query = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_kategorie");
$result = mysql_fetch_array($query);
$kategorii = $result['pocet'];

$query = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_banlist");
$result = mysql_fetch_array($query);
$banu = $result['pocet'];

$query = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_uzivatele");
$result = mysql_fetch_array($query);
$uzivatele = $result['pocet'];

$query = mysql_query("SELECT COUNT(*) AS pocet FROM jtcms_skupiny");
$result = mysql_fetch_array($query);
$skupiny = $result['pocet'];

$query = mysql_query("SELECT * FROM jtcms_galerie WHERE pridal='".$id."'");

  $num = 0;
  while ($result = mysql_fetch_array($query)) {
    $adresar = opendir("./data/gal/".$result['id']);
    while ($soubor = readdir($adresar)){
      $num++;
    };
    $num = $num-2;
  };
         
  $fotek = $num;
?>

<table class="login_tabulka statistiky">
<tr class="prvni_tr"><td class="first_a_last" colspan="2"><h2><?php echo $lang['login_statistics']; ?></h2></td></tr>
<tr class="curh" title="<?php echo $lang['login_stat_10'].': '.$precteni_clanku.$lang['login_stat_2'].' '.$komentare_cl; ?>"><td class="tal"><?php echo $lang['login_stat_1']; ?></td><td><?php echo $clanku; ?></td></tr>
<tr class="curh" title="<?php echo $lang['login_stat_9'].': '.$precteni_stranky.$lang['login_stat_4'].' '.$komentare_st; ?>"><td class="tal"><?php echo $lang['login_stat_3']; ?></td><td><?php echo $stranek; ?></td></tr>
<tr><td class="tal"><?php echo $lang['login_stat_11']; ?></td><td><?php echo $stitku; ?></td></tr>
<tr class="curh" title="<?php echo $lang['login_stat_16'].' '.$fotek; ?>"><td class="tal"><?php echo $lang['login_stat_12']; ?></td><td><?php echo $galerii; ?></td></tr>
<tr class="curh" title="<?php echo $lang['login_stat_14'].' '.$slozek.' '.$lang['login_stat_15']; ?>"><td class="tal"><?php echo $lang['login_stat_13']; ?></td><td><?php echo $souboru; ?></td></tr>
<tr><td class="tal"><?php echo $lang['login_stat_5']; ?></td><td><?php echo $kategorii; ?></td></tr>
<tr><td class="tal"><?php echo $lang['login_stat_6']; ?></td><td><?php echo $banu; ?></td></tr>
<tr><td class="tal"><?php echo $lang['login_stat_7']; ?></td><td><?php echo $uzivatele; ?></td></tr>
<tr><td class="tal"><?php echo $lang['login_stat_8']; ?></td><td><?php echo $skupiny; ?></td></tr>
<tr class="posledni_tr"><td class="first_last" colspan="2"></td></tr>
</table>

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

<br /><br />
<div class="login_novinky">
<span><?php echo $lang['login_news']; ?></span><br />
<?php
if (!simplexml_load_file("http://blog.jt-cms.com/rss.php")) {
  echo '<iframe src="http://cms.jt-cms.com/novinky.php"></iframe>';
} else { 
  echo '<div class="news">';

  $xml=simplexml_load_file("http://blog.jt-cms.com/rss.php");
  $index = 1;

  foreach ($xml->channel->item as $item){
    if($index > 1){ break; }
    $index++;
    $link = $item->link;
    $title = $item->title;
    $desc = $item->description;

    echo '<a href="'.$link.'" class="title">'.$title.'</a>';
    echo '<p>'.$desc.'</p>';
    echo '<a href="'.$link.'" class="full">'.$lang['login_news_full'].'</a>';
    echo '<div class="nf"></div>';
  };
  echo '</div>';
};
?>
</div>

<?php
include_end();
?>