<?php

// Redirection to secure connection
if(!array_key_exists('HTTPS', $_SERVER)) 
{
//  Header('Location: https://'.$_SERVER['HTTP_HOST'].substr($_SERVER["SCRIPT_NAME"], 4));
//  die();
}

include('../global.php');
ShowHeader();

include('home.php');
include('user.php');
$User = new User();

if(!array_key_exists('op', $_GET)) $_GET['op'] = '';
$Operation = addslashes($_GET['op']);
switch($Operation)
{  
  case 'Login':
    $User->Login(addslashes($_POST['username']), addslashes($_POST['password']));
    break;
  case 'Logout':
    $User->Logout();
    break;
  case 'AddMessage':
    if($User->Check())
    {
      $Database->select_db('wow');
      $Database->insert('gm_news', array('author' => $_SESSION['UserId'], 'text' => addslashes($_POST['text']), 'time' => 'NOW()'));
      //echo('Zpráva vložena.<br>');
    }
    break;
  default:
}

if($User->Check()) Show();
else {
  
  echo('<h3>Správa serveru:</h3><br><strong>Přihlášení:</strong><br>
<form action="?op=Login" method="post">
<table>
<tr><td>Jméno:</td><td><input name="username" type="text"></td></tr>
<tr><td>Heslo:</td><td><input name="password" type="password"></td></tr>
<tr><td colspan=2"><input type="submit" value="Přihlásit"></td></tr>
</table>
</form>');

}

//echo(phpinfo());
ShowFooter();

?>
