<?php
session_start();
ini_set("display_errors", 0);
error_reporting(0);

Header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0', true);
Header('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT', true);
Header('Last-Modified', gmdate("D, d M Y H:i:s")." GMT", true);
Header('Pragma', 'no-cache', true);

if (file_exists("install.php")) {
  Header("Location: error.php?error=2");
  echo '<script type="text/javascript">location.replace("error.php?error=2")</script>';
  exit();
};

if (!file_exists("config.php")) {
  Header("Location: error.php?error=7");
  echo '<script type="text/javascript">location.replace("error.php?error=7")</script>';
  exit();
};

include "config.php";

if (isset($_SESSION['username']) && isset($_SESSION['userpassword'])) {
  $jmeno = mysql_real_escape_string($_SESSION['username']);
  $heslo = mysql_real_escape_string($_SESSION['userpassword']);
} elseif (isset($_COOKIE["jtcms_jmeno"]) && isset($_COOKIE["jtcms_heslo"])) {
  $jmeno = mysql_real_escape_string($_COOKIE["jtcms_jmeno"]);
  $heslo = mysql_real_escape_string($_COOKIE["jtcms_heslo"]);
} else {
  Header("Location: error.php?error=1");
  echo '<script type="text/javascript">location.replace("error.php?error=1")</script>';
  exit();
};  
  
  $query = mysql_query("SELECT id FROM jtcms_uzivatele WHERE jmeno='".$jmeno."' and heslo='".$heslo."'");
  $radku = mysql_num_rows($query);
  
if ($radku == 1) {
  $result = mysql_fetch_array($query);
  $_SESSION['userid'] = $result['id'];
} else {
  Header("Location: error.php?error=1");
  echo '<script type="text/javascript">location.replace("error.php?error=1")</script>';
  exit();
};

$user_info = mysql_query("SELECT set_jazyk, set_jazyk2, set_vzhled, set_tinymce, skupina, jmeno FROM jtcms_uzivatele WHERE id='".intval($_SESSION['userid'])."' LIMIT 1");
$user_info = mysql_fetch_array($user_info);

if (empty($user_info['set_jazyk']) or empty($user_info['set_jazyk2'])) {
  $query_lang = mysql_query("SELECT hodnota, hodnota2 FROM jtcms_nastaveni WHERE typ='jazyk' LIMIT 1");
  $query_lang = mysql_fetch_array($query_lang);
  $set_lang = $query_lang['hodnota'];
  $set_lang2 = $query_lang['hodnota2'];
} else {
  $set_lang = $user_info['set_jazyk2'];
  $set_lang2 = $user_info['set_jazyk'];
};  

if (empty($user_info['set_vzhled'])) {
  $theme = mysql_query("SELECT hodnota FROM jtcms_nastaveni WHERE typ='vzhled' LIMIT 1");
  $theme = mysql_fetch_array($theme);
  $theme = $theme['hodnota'];
} else {
  $theme = $user_info['set_vzhled'];
};


$skupina = $user_info['skupina'];
$jmeno = $user_info['jmeno'];

$prava = mysql_query("SELECT * FROM jtcms_skupiny WHERE id='".$skupina."' LIMIT 1");
$prava = mysql_fetch_array($prava);

if (isset($druh)) {$prava = $prava["$druh"];};

include "stuff/lang/".$set_lang2.".php";
include "stuff/func/general.php";
?>