Changeset 48 for trunk/index.php


Ignore:
Timestamp:
Dec 22, 2019, 11:43:06 PM (4 years ago)
Author:
chronos
Message:
  • Added: Allow to login as administrator.
  • Added: Allow to hide meet items.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/index.php

    r39 r48  
    3434    $this->PageHeaders = array();
    3535    $this->Bars = array();
     36  }
     37
     38  function IsAdmin()
     39  {
     40    return ($_SESSION['IsAdmin'] == 1);
    3641  }
    3742
     
    7075    return($PathItems);
    7176  }
    72  
     77
    7378  function RegisterPage($Path, $Handler)
    7479  {
     
    149154    }
    150155  }
    151  
     156
    152157  function RunCommon()
    153158  {
     
    226231    }
    227232    // MeetItems
    228     $DbResult = $this->Database->query('SELECT `Id`,`Time` FROM `MeetItem`');
     233    $DbResult = $this->Database->query('SELECT `Id`,`Time` FROM `MeetItem` WHERE (`Hidden`=0)');
    229234    while ($DbRow = $DbResult->fetch_array())
    230235    {
     
    242247}
    243248
    244 
    245 $Revision = 36; // Subversion revision
    246 $DatabaseRevision = 36; // SQL structure revision
    247 $ReleaseTime = strtotime('2019-05-05');
     249class PageLogin extends Page
     250{
     251  function Show()
     252  {
     253    global $Config;
     254
     255    $Output = '';
     256    if (array_key_exists('login', $_GET))
     257    {
     258      if (array_key_exists('password', $_POST))
     259      {
     260        if ($_POST['password'] == $Config['Web']['AdminPassword'])
     261        {
     262          $_SESSION['IsAdmin'] = 1;
     263          $Output .= 'Úspěšně přihlášen jako správce.';
     264        } else {
     265          $_SESSION['IsAdmin'] = 0;
     266          $Output .= 'Heslo není správné.';
     267          $Output .= $this->ShowLoginForm();
     268        }
     269      } else {
     270        $Output .= 'Chybí heslo.';
     271        $Output .= $this->ShowLoginForm();
     272      }
     273    } else
     274    if (array_key_exists('logoff', $_GET))
     275    {
     276      $_SESSION['IsAdmin'] = 0;
     277      $Output .= 'Odhlášení úspěšné';
     278      $Output .= $this->ShowLoginForm();
     279    } else {
     280      $Output .= $this->ShowLoginForm();
     281    }
     282    if ($this->System->IsAdmin()) $Output .= '<div>Jsi přihlášen jako správce. <a href="?logoff">Odhlásit</a></div>';
     283    return $Output;
     284  }
     285
     286  function ShowLoginForm()
     287  {
     288    return '<form method="post" action="?login">'.
     289        'Heslo: <input type="password" name="password" value=""/><br/>'.
     290        '<input type="submit" value="Přihlásit"/>'.
     291        '</form>';
     292  }
     293}
     294
     295$Revision = 48; // Subversion revision
     296$DatabaseRevision = 48; // SQL structure revision
     297$ReleaseTime = strtotime('2019-12-22');
    248298
    249299$Application = new ApplicationTanec();
     
    255305$Application->RegisterPage('robots.txt', 'PageRobots');
    256306$Application->RegisterPage('sitemap.xml', 'PageSiteMap');
     307$Application->RegisterPage('admin', 'PageLogin');
    257308$Application->Run();
Note: See TracChangeset for help on using the changeset viewer.