<?php
include('global.php');
include('aktuality/rss_generator.php');

class LogShow extends Page
{
  var $FullTitle = 'Zobrazení záznamu operací';
  var $ShortTitle = 'Záznam operací';
  var $RowPerPage = 20;

  function Show()
  {
    if(!$this->System->Modules['User']->CheckPermission('Log', 'Show')) return('Nemáte oprávnění');
    $DbResult = $this->Database->select('Log', 'COUNT(*)');
    $RowTotal = $DbResult->fetch_array();
    $PageMax = $RowTotal[0];
    if(array_key_exists('Page', $_GET)) $Page = $_GET['Page']; else $Page = 0;

    $Output = '<div align="center"><table class="WideTable" style="font-size: small;">';
    $Output .= '<tr><th>Čas</th><th>Uživatel</th><th>Modul</th><th>Operace</th><th>Hodnota</th></tr>';
    $DbResult = $this->Database->query('SELECT Log.*, `User`.`Name` as UserName FROM `Log` LEFT JOIN `User` ON `User`.`Id` = `Log`.`User` ORDER BY Time DESC LIMIT '.$Page * $this->RowPerPage.','.$this->RowPerPage);
    while($DbRow = $DbResult->fetch_assoc())
    {
      $Output .= '<tr><td>'.$DbRow['Time'].'</td><td>'.$DbRow['UserName'].'</td><td>'.$DbRow['Module'].'</td><td>'.$DbRow['Operation'].'</td><td>'.$DbRow['Value'].'</td></tr>';
    }
    $Output .= '</table>';
    $Output .= PagesList('?Page=', $Page, $PageMax, $this->RowPerPage);
    $Output .= '</div>';
    return($Output);
  }
}

if(array_key_exists('Action', $_GET))
{
  if($_GET['Action'] == 'rss')
  {
    $DbResult = $Database->query('SELECT UNIX_TIMESTAMP(Time), Log.*, `User`.`Name` as UserName FROM `Log` LEFT JOIN `User` ON `User`.`Id` = `Log`.`User` ORDER BY Time DESC LIMIT 0, 50');
    while($Row = $DbResult->fetch_assoc())
    {
      $Info = $Row['UserName'].': '.$Row['Module'].' '.$Row['Operation'].' '.$Row['Value'];
      $Items[] = array
      (
        'Title' => $Info,
        'Link' => 'http://'.$Config['Web']['Host'].'/',
        'Description' => $Info,
        'Time' => $Row['UNIX_TIMESTAMP(Time)'],
      );
    }
    echo(GenerateRSS(array(
      'Title' => $Config['Web']['Title'].' - Záznamy operací',
      'Link' => 'http://'.$Config['Web']['Host'].'/',
      'Description' => 'Záznamy operací',
      'WebmasterEmail' => $Config['Web']['AdminEmail'],
      'Items' => $Items)));
  } else
  {
    $System->AddModule(new LogShow());
    $System->Modules['LogShow']->GetOutput();
  }
} else
{
  $System->AddModule(new LogShow());
  $System->Modules['LogShow']->GetOutput();
}

?>
