<?php

include_once('global.php');

class IndexPage extends Page
{
  var $Dependencies = array('News');
  var $FullTitle = '';
  var $ShortTitle = '';

  function Show()
  {
    $FormUserLogin = array(
      'Title' => 'Přihlášení',
      'SubmitButtonText' => 'Přihlásit',
      'Items' => array(
        array('Name' => 'UserName', 'Type' => TypeStringId, 'Caption' => 'Jméno', 'Value' => ''),
        array('Name' => 'Password', 'Type' => TypePasswordId, 'Caption' => 'Heslo', 'Value' => ''),
      ),
    );
    $FormUserRegister = array
    (
      'Title' => 'Registrace uživatele',
      'Table' => 'User',
      'SubmitButtonText' => 'Registrovat',
      'Items' => array(
        array('Name' => 'UserName', 'Type' => TypeStringId, 'Caption' => 'Přihlašovací jméno', 'Value' => ''),
        array('Name' => 'Password', 'Type' => TypePasswordId, 'Caption' => 'Heslo', 'Value' => ''),
        array('Name' => 'Password2', 'Type' => TypePasswordId, 'Caption' => 'Potvrzení hesla', 'Value' => ''),
        array('Name' => 'Email', 'Type' => TypeStringId, 'Caption' => 'E-mail', 'Value' => ''),
        array('Name' => 'FirstName', 'Type' => TypeStringId, 'Caption' => 'Křestní jméno', 'Value' => ''),
        array('Name' => 'SecondName', 'Type' => TypeStringId, 'Caption' => 'Příjmení', 'Value' => ''),
      ),
    );

    $Output = '<table class="base"><tr><td class="menu">';
    if(array_key_exists('Action', $_GET))
    {
      if($_GET['Action'] == 'Login')
      {
        $Form = new Form();
        $Form->Definition = $FormUserLogin;
        $Form->LoadValuesFromForm();
        $Output .= $this->SystemMessage('Přihlášení', $this->System->Modules['User']->Login($Form->Values['UserName'], $Form->Values['Password']));
      } else
      if($_GET['Action'] == 'Logout')
      {
        $Output .= $this->SystemMessage('Odhlášení', $this->System->Modules['User']->Logout());
      } else
      if($_GET['Action'] == 'LoginForm')
      {
        $Form = new Form();
        $Form->Definition = $FormUserLogin;
        $Form->OnSubmit = '?Action=Login';
        $Output .= $Form->ShowEditForm();
      } else
      if($_GET['Action'] == 'UserRegister')
      {
        $Form = new Form();
        $Form->Definition = $FormUserRegister;
        $Form->OnSubmit = '?Action=UserRegisterSave';
        $Output .= $Form->ShowEditForm();
      } else
      if($_GET['Action'] == 'UserRegisterConfirm')
      {
          $Output .= $this->SystemMessage('Potvrzení registrace', $this->System->Modules['User']->RegisterConfirm($_GET['User'], $_GET['H']));
      } else
      if($_GET['Action'] == 'UserRegisterSave')
      {
        $Form = new Form();
        $Form->Definition = $FormUserRegister;
        $Form->LoadValuesFromForm();
        $Output .= $this->SystemMessage('Registrace', $this->System->Modules['User']->Register($Form->Values['Name'], $Form->Values['Password'], $Form->Values['Password2'], $Form->Values['Email'], $Form->Values['FirstName'], $Form->Values['SecondName']));
      }
    }
    if($this->System->Modules['User']->User['Id'] == 0)
    {
      //if(!array_key_exists('Action', $_GET))
      {
        $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/?Action=LoginForm">Přihlášení</a><br /><a href="'.$this->System->Config['Web']['RootFolder'].'/?Action=UserRegister">Registrace</a>';
        $Form = new Form();
        $Form->Definition = $FormUserLogin;
        $Form->OnSubmit = '?Action=Login';
        $Output .= $Form->ShowEditForm();
      }
    }
    else
    {
      $Output .= $this->System->Modules['User']->User['UserName'].' <a href="'.$this->System->Config['Web']['RootFolder'].'/?Action=Logout">Odhlásit</a>';
      $Output .= '<br /><br />';
      $Output .= ShowMenu();
      $Output .= '</td><td class="main">';
      $Output .= Output();
      $Output .= '</td></tr></table></body></html>';
    }
    return($Output);
  }
}

$System->AddModule(new IndexPage());
$System->Modules['IndexPage']->GetOutput();
//var_dump(get_defined_vars());
//print_r($_GLOBAL);

?>
