1 | <?php
|
---|
2 |
|
---|
3 | include_once('Common/RSS.php');
|
---|
4 |
|
---|
5 | class LogShow extends Page
|
---|
6 | {
|
---|
7 | var $FullTitle = 'Zobrazení záznamu operací';
|
---|
8 | var $ShortTitle = 'Záznam operací';
|
---|
9 | var $RowPerPage = 20;
|
---|
10 |
|
---|
11 | function Show()
|
---|
12 | {
|
---|
13 | if(count($this->System->PathItems) > 1)
|
---|
14 | {
|
---|
15 | if($this->System->PathItems[1] == 'rss') return($this->ShowRSS());
|
---|
16 | else return(PAGE_NOT_FOUND);
|
---|
17 | } else return($this->ShowList());
|
---|
18 | }
|
---|
19 |
|
---|
20 | function ShowRSS()
|
---|
21 | {
|
---|
22 | $this->SimplePage = true;
|
---|
23 | $this->FormatHTML = false;
|
---|
24 |
|
---|
25 | if(!$this->System->Models['User']->CheckPermission('Log', 'Show')) return('Nemáte oprávnění');
|
---|
26 | $DbResult = $this->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');
|
---|
27 | while($Row = $DbResult->fetch_assoc())
|
---|
28 | {
|
---|
29 | $Info = $Row['UserName'].': '.$Row['Module'].' '.$Row['Operation'].' '.$Row['Value'];
|
---|
30 | $Items[] = array
|
---|
31 | (
|
---|
32 | 'Title' => $Info,
|
---|
33 | 'Link' => 'http://'.$this->System->Config['Web']['Host'].'/',
|
---|
34 | 'Description' => $Info,
|
---|
35 | 'Time' => $Row['UNIX_TIMESTAMP(Time)'],
|
---|
36 | );
|
---|
37 | }
|
---|
38 | $RSS = new RSS();
|
---|
39 | $RSS->Title = $this->System->Config['Web']['Title'].' - Záznamy operací';
|
---|
40 | $RSS->Link = 'http://'.$this->System->Config['Web']['Host'].'/';
|
---|
41 | $RSS->Description = 'Záznamy operací';
|
---|
42 | $RSS->WebmasterEmail = $this->System->Config['Web']['AdminEmail'];
|
---|
43 | $RSS->Items = $Items;
|
---|
44 | return($RSS->Generate());
|
---|
45 | }
|
---|
46 |
|
---|
47 | function ShowList()
|
---|
48 | {
|
---|
49 | if(!$this->System->Models['User']->CheckPermission('Log', 'Show')) return('Nemáte oprávnění');
|
---|
50 | $DbResult = $this->Database->select('Log', 'COUNT(*)');
|
---|
51 | $RowTotal = $DbResult->fetch_array();
|
---|
52 | $PageMax = $RowTotal[0];
|
---|
53 | if(array_key_exists('Page', $_GET)) $Page = $_GET['Page']; else $Page = 0;
|
---|
54 |
|
---|
55 | $Output = '<div align="center"><table class="WideTable" style="font-size: small;">';
|
---|
56 | $Output .= '<tr><th>Čas</th><th>Uživatel</th><th>Modul</th><th>Operace</th><th>Hodnota</th></tr>';
|
---|
57 | $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);
|
---|
58 | while($DbRow = $DbResult->fetch_assoc())
|
---|
59 | {
|
---|
60 | $Output .= '<tr><td>'.$DbRow['Time'].'</td><td>'.$DbRow['UserName'].'</td><td>'.$DbRow['Module'].'</td><td>'.$DbRow['Operation'].'</td><td>'.$DbRow['Value'].'</td></tr>';
|
---|
61 | }
|
---|
62 | $Output .= '</table>';
|
---|
63 | $Output .= PagesList('?Page=', $Page, $PageMax, $this->RowPerPage);
|
---|
64 | $Output .= '</div>';
|
---|
65 | return($Output);
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | class Log extends Model
|
---|
70 | {
|
---|
71 | function __construct($Database, $System)
|
---|
72 | {
|
---|
73 | parent::__construct($Database, $System);
|
---|
74 | $this->Name = 'Log';
|
---|
75 | $this->AddPropertyDateTime('Time');
|
---|
76 | $this->AddPropertyOneToMany('User', 'User');
|
---|
77 | $this->AddPropertyString('Module');
|
---|
78 | $this->AddPropertyString('Operation');
|
---|
79 | $this->AddPropertyString('Value');
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | class ModuleLog extends Module
|
---|
84 | {
|
---|
85 | function __construct($Database, $System)
|
---|
86 | {
|
---|
87 | parent::__construct($Database, $System);
|
---|
88 | $this->Name = 'Log';
|
---|
89 | $this->Version = '1.0';
|
---|
90 | $this->Creator = 'Chronos';
|
---|
91 | $this->License = 'GNU/GPL';
|
---|
92 | $this->Description = 'Logging of user operations';
|
---|
93 | $this->Dependencies = array('User');
|
---|
94 | $this->SupportedModels = array('Log');
|
---|
95 | }
|
---|
96 |
|
---|
97 | function Install()
|
---|
98 | {
|
---|
99 | parent::Install();
|
---|
100 | }
|
---|
101 |
|
---|
102 | function UnInstall()
|
---|
103 | {
|
---|
104 | parent::UnInstall();
|
---|
105 | }
|
---|
106 |
|
---|
107 | function Init()
|
---|
108 | {
|
---|
109 | $this->System->Pages['log'] = 'LogShow';
|
---|
110 | }
|
---|
111 |
|
---|
112 | function NewRecord($Module, $Operation, $Value = '')
|
---|
113 | {
|
---|
114 | $this->Database->insert('Log', array('Time' => 'NOW()',
|
---|
115 | 'User' => $this->System->Module['User']->Models['User']->User['Id'], 'Module' => $Module,
|
---|
116 | 'Operation' => $Operation, 'Value' => $Value));
|
---|
117 | //echo($this->Database->LastQuery);
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | ?>
|
---|