﻿<?php

// SQL injection hack protection
foreach($_POST as $Index => $Item) $_POST[$Index] = addslashes($Item);
foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item);

if(file_exists('inc/config.php')) include_once('inc/config.php');
  else die('Nenalezen soubor inc/config.php. Vytvořte jej z předlohy config.sample.php.');

if(array_key_exists('RealmIndex', $_POST))
{
  setcookie('RealmIndex', $_POST['RealmIndex']);
  $_COOKIE['RealmIndex'] = $_POST['RealmIndex'];
}
if(array_key_exists('RealmIndex', $_GET))
{
  setcookie('RealmIndex', $_GET['RealmIndex']);
  $_COOKIE['RealmIndex'] = $_GET['RealmIndex'];
}
$RealmList = $Config['Mangos']['RealmList'];
$FirstRealm = array_shift($RealmList);
if(!array_key_exists('RealmIndex', $_COOKIE)) $_COOKIE['RealmIndex'] = $FirstRealm['Id'];
  else 
  {
    if(!array_key_exists($_COOKIE['RealmIndex'], $Config['Mangos']['RealmList']))
      $_COOKIE['RealmIndex'] = $FirstRealm['Id'];
  }
  
session_start();
include_once('inc/error.php');
include_once('inc/database.php');
include_once('inc/module.php');
include_once('inc/html.php');
include_once('inc/system.php');
include_once('inc/player.php');
include_once('inc/server.php');
include_once('inc/realm.php');

// classes start
$System = new System($Config);
$db = $System->Database;
$player = new Player($db);
$server = new Server($System, 1);
$html = new Html(0, $db);
$html->Start();
if(isset($_COOKIE['hof-random']) and $_COOKIE['hof-random'] == 'no') $num_headers = 1;
  else $num_headers = 8;

echo('<div id="page">'.
  '<div id="header" style="background-image: url(imgs/web/headers/header'.rand(0, $num_headers - 1).'.jpg);"></div>'.
  '<div id="top"></div>'.
  '<div id="menu">');

$ServerMenuItems = array(
  array('link' => '?page=main', 'Text' => 'Úvod'),
  array('link' => '?page=begin', 'Text' => 'Jak začít'),
  array('link' => '?page=register', 'Text' => 'Registrace'),
  array('link' => '?page=acc', 'Text' => 'Správa účtu'),
  array('link' => 'forum/', 'Text' => 'Fórum'),
  array('link' => '?page=server', 'Text' => 'Server'),
  array('link' => '?page=gmteam', 'Text' => 'GM Tým'),
  //array('link' => 'bug_tracker/', 'Text' => 'Nahlaš chybu'),
  array('link' => 'gallery/', 'Text' => 'Galerie'),
  array('link' => '?page=download', 'Text' => 'Stahování'),
  array('link' => '?page=links', 'Text' => 'Odkazy'),
  array('link' => '?page=banlist', 'Text' => 'Bany'),
  array('link' => '?page=dotation', 'Text' => 'Dotace'),
  array('link' => '?page=teamspeak', 'Text' => 'Team speak'),
  array('link' => '?page=client', 'Text' => 'HoF Client'),
  array('link' => '?page=search', 'Text' => 'Vyhledávání'),    
  array('link' => '?page=realmlist', 'Text' => 'Světy'),    
);

$RealmMenuItems = array(
  array('link' => '?page=online', 'Text' => 'Online hráči'),
  array('link' => '#', 'Text' => 'Mapa hráčů', 'OnClick' => "popup('../minimanager/pomm/pomm.php?realmid=".$_COOKIE['RealmIndex']."', 1000, 800); return false;"),
  array('link' => '?page=tophraci', 'Text' => 'Nej hráči'),
  array('link' => '?page=guildy', 'Text' => 'Spolky'),
  array('link' => 'armory/', 'Text' => 'Armory'),
  array('link' => '?page=gh', 'Text' => 'Domky spolků'),
  array('link' => '?page=arena', 'Text' => 'Arény'),
  array('link' => '?page=events', 'Text' => 'Události'),
  //array('link' => '?page=gmlog', 'Text' => 'GM log'),
  array('link' => '?page=commands', 'Text' => 'Příkazy'),
);

echo('<br /><br />');
echo('<div class="mainmenu">');
foreach($ServerMenuItems as $Item)
{
  if(array_key_exists('OnClick', $Item)) $OnClick = ' onclick="'.$Item['OnClick'].'"';
    else $OnClick = '';
  if(array_key_exists('Target', $Item)) $Target = ' target="'.$Item['Target'].'"';
    else $Target = '';

  echo('<a href="'.$Item['link'].'"'.$OnClick.$Target.'>'.$Item['Text'].'</a><br />');
}
echo('</div>');

echo($server->RealmSelection('Menu'));

echo('<br /><br />');
echo('<div class="mainmenu">');
foreach($RealmMenuItems as $Item)
{
  if(array_key_exists('OnClick', $Item)) $OnClick = ' onclick="'.$Item['OnClick'].'"';
    else $OnClick = '';
  if(array_key_exists('Target', $Item)) $Target = ' target="'.$Item['Target'].'"';
    else $Target = '';

  echo('<a href="'.$Item['link'].'"'.$OnClick.$Target.'>'.$Item['Text'].'</a><br />');
}
echo('</div>');

echo('<div class="Banners">'.
  '<strong>Naše ikonka :</strong><br />'.
  '<a href="'.$Config['Web']['BaseURL'].'"><img src="imgs/web/hof_ban.png" alt="WoW Server Heroes of Fantasy" /></a><br />'.
  '<strong>Odkazy :</strong><br />'.
  '<a href="http://servery.wowresource.eu/"><img src="http://servery.wowresource.eu/templates/img/bannery/banner_maly.gif" alt="WoW Server status" /></a><br />'.
  '<a href="http://www.wowhead.com"><img src="http://www.wowhead.com/images/badge_88x31.gif" width="88" height="31" alt="" /></a><br />'.
  '<a href="http://wowpreklad.zdechov.net/"><img src="http://wowpreklad.zdechov.net/banners/baner_88_31.jpg" alt="baner_http://wowpreklad.zdechov.net/" height="31" width="88" /></a><br />'.
  '<strong>Statistika :</strong><br />'.
  '<a href="http://www.toplist.cz/"><img src="http://toplist.cz/count.asp?logo=mc&amp;ID=324802" width="88" height="60" alt="counter" /></a><br /><br />'.
  'Počet přístupů: <br /><a href="http://counter.cnw.cz/">'.
  '<img src="http://counter.cnw.cz/monika.cgi?wowzdechov&amp;7&amp;000000&amp;FFFFFF&amp;on" alt="CNW:Counter" /></a>'.
  '<script type="text/javascript">
  <!--
  document.write("<a href=\"http://counter.cnw.cz\" target=\"_parent\"><img src=\"http://counter.cnw.cz/trackit.cgi?wowzdechov&amp;t4&amp;" + escape(top.document.referrer) + "\" alt=\"CNW:Tracker\" border=\"0\" width=\"0\" height=\"0\"></a>");
  // -->
  </script>'.
  '</div>'.
  '</div>'.
  '<div id="content">');

// obsah start
$include = 1;
if(isset($_GET['logout']) and $player->Check())
{
  echo('<center>');
  $player->Logout();
  echo('</center>');
  $include = 0;
}
if($include == 1)
{
  if(isset($_GET['page'])) include_once($html->Pager($_GET['page'], 'pages', 'main'));
    else include_once('pages/main.php');
}
echo('</div>'.
'<div id="footer"><br /><div id="copyright"><a href="?page=autori">Vývoj webu</a></div></div></div>');

$html->Stop();
$db->close();

?>
