Changeset 48 for trunk


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

Legend:

Unmodified
Added
Removed
  • trunk/Config/Config.sample.php

    r39 r48  
    1414$Config['Web']['AdminEmail'] = 'robie@centrum.cz';
    1515$Config['Web']['Title'] = 'Tanec';
     16$Config['Web']['AdminPassword'] = rand(1, 10000000);
  • trunk/Modules/Meet/MeetPage.php

    r46 r48  
    5959
    6060    $DbResult = $this->Database->query('SELECT COUNT(*) FROM (SELECT *, '.
    61       '(SELECT MeetSource.Name FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceName FROM `MeetItem`) AS T WHERE '.$Where);
     61      '(SELECT MeetSource.Name FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceName FROM `MeetItem`) AS T WHERE (T.Hidden=0) AND '.$Where);
    6262    $DbRow = $DbResult->fetch_row();
    6363    $PageList = GetPageList($DbRow[0]);
     
    8282    $Output .= $Order['Output'];
    8383    $DbResult = $this->Database->query('SELECT * FROM (SELECT *, (SELECT MeetSource.Name FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceName, '.
    84       '(SELECT MeetSource.URL FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceURL FROM MeetItem) AS T WHERE '.
     84      '(SELECT MeetSource.URL FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceURL FROM MeetItem) AS T WHERE (T.Hidden=0) AND '.
    8585      $Where.$Order['SQL'].$PageList['SQLLimit']);
    8686    while($MeetItem = $DbResult->fetch_assoc())
     
    149149      $id = $this->System->PathItems[2] * 1;
    150150    } else return 'Položka nenalezena';
     151    if ($this->System->IsAdmin())
     152    {
     153      if (array_key_exists('hide', $_GET)) $this->Database->update('MeetItem', 'Id='.$id, array('Hidden' => 1));
     154      if (array_key_exists('unhide', $_GET)) $this->Database->update('MeetItem', 'Id='.$id, array('Hidden' => 0));
     155    }
     156
    151157    $Output .= '<div class="title">Inzerát</div>';
    152158    $Gender = array('', 'Muž', 'Žena');
     
    172178        '<tr><th>Zdroj importu</th><td><a href="'.$MeetItem['SourceURL'].'">'.$MeetItem['SourceName'].'</a></td></tr>';
    173179      $Output .= '</table>';
     180      if ($this->System->IsAdmin()) {
     181        if ($MeetItem['Hidden'] == '1')
     182          $Output .= '<div>Skrytá položka <a href="?unhide">Zviditelnit</a></div>';
     183          else $Output .= '<div>Viditelná položka <a href="?hide">Skrýt</a></div>';
     184      }
    174185    } else $Output .= 'Položka nenalezena';
    175186    return $Output;
     
    197208
    198209    $DbResult = $this->Database->select('MeetItem', '*, (SELECT MeetSource.Name FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceName, '.
    199       '(SELECT MeetSource.URL FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceURL', '1 ORDER BY `Time` DESC LIMIT 30');
     210      '(SELECT MeetSource.URL FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceURL', '`Hidden`=0 ORDER BY `Time` DESC LIMIT 30');
    200211    while($MeetItem = $DbResult->fetch_assoc())
    201212    {
  • trunk/SQL/Update.php

    r44 r48  
    5252ALTER TABLE `MeetItem`
    5353  ADD COLUMN `RemoteId` VARCHAR(255) NULL DEFAULT NULL AFTER `TimeImport`;
     54
     55-- rev 48
     56ALTER TABLE `MeetItem`
     57  ADD COLUMN `Hidden` INT NULL DEFAULT '0' AFTER `RemoteId`;
  • 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.