1 | <?php
|
---|
2 |
|
---|
3 | class Page
|
---|
4 | {
|
---|
5 | var $System;
|
---|
6 | var $Database;
|
---|
7 | var $RawPage;
|
---|
8 | var $Title;
|
---|
9 |
|
---|
10 | function __construct($System)
|
---|
11 | {
|
---|
12 | $this->System = &$System;
|
---|
13 | $this->Database = &$System->Database;
|
---|
14 | $this->RawPage = false;
|
---|
15 | }
|
---|
16 |
|
---|
17 | function Show()
|
---|
18 | {
|
---|
19 | return('');
|
---|
20 | }
|
---|
21 |
|
---|
22 | function GetOutput()
|
---|
23 | {
|
---|
24 | $Output = $this->Show();
|
---|
25 | return($Output);
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | class PageEdit extends Page
|
---|
30 | {
|
---|
31 | var $Table;
|
---|
32 | var $Definition;
|
---|
33 | var $ItemActions;
|
---|
34 |
|
---|
35 | function __construct($System)
|
---|
36 | {
|
---|
37 | parent::__construct($System);
|
---|
38 | $this->Table = '';
|
---|
39 | $this->Definition = array();
|
---|
40 | $this->ItemActions = array(
|
---|
41 | array('Name' => T('View'), 'URL' => '?action=view&id=#Id'),
|
---|
42 | );
|
---|
43 | $this->AllowEdit = false;
|
---|
44 | if($this->AllowEdit) $this->ItemActions[] = array('Name' => T('Delete'), 'URL' => '?action=remove&id=#Id');
|
---|
45 | }
|
---|
46 |
|
---|
47 | function Show()
|
---|
48 | {
|
---|
49 | $Output = '';
|
---|
50 | if(array_key_exists('action', $_GET))
|
---|
51 | {
|
---|
52 | if($_GET['action'] == 'add') $Output .= $this->AddItem();
|
---|
53 | else if($_GET['action'] == 'view') $Output .= $this->ViewItem();
|
---|
54 | else if($_GET['action'] == 'edit') $Output .= $this->ModifyItem();
|
---|
55 | else if($_GET['action'] == 'remove') $Output .= $this->RemoveItem();
|
---|
56 | else if($_GET['action'] == 'delete') $Output .= $this->DeleteItem();
|
---|
57 | else $Output .= ShowMessage(T('Unknown action'), MESSAGE_CRITICAL);
|
---|
58 | } else $Output .= $this->ViewList();
|
---|
59 | return($Output);
|
---|
60 | }
|
---|
61 |
|
---|
62 | function ViewItem()
|
---|
63 | {
|
---|
64 | $DbResult = $this->Database->query('SELECT * FROM ('.$this->TableSQL.') AS `T` WHERE `Id`='.$_GET['id']);
|
---|
65 | if($DbResult->num_rows > 0)
|
---|
66 | {
|
---|
67 | $DbRow = $DbResult->fetch_assoc();
|
---|
68 |
|
---|
69 | $Output = T('Item').
|
---|
70 | '<table>';
|
---|
71 | foreach($this->Definition as $DefIndex => $Def)
|
---|
72 | {
|
---|
73 | $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->ViewControl($Def['Type'], $DefIndex, $DbRow[$DefIndex]).'</tr>';
|
---|
74 | }
|
---|
75 | $Output .= '<tr>'.
|
---|
76 | '</table>';
|
---|
77 | } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
|
---|
78 | if($this->AllowEdit)
|
---|
79 | {
|
---|
80 | $Output .= '<a href="?action=add">'.T('Add').'</a> ';
|
---|
81 | $Output .= '<a href="?action=edit&id='.$_GET['id'].'">'.T('Edit').'</a> ';
|
---|
82 | $Output .= '<a href="?action=delete&id='.$_GET['id'].'">'.T('Add').'</a> ';
|
---|
83 | }
|
---|
84 | $Output .= '<a href="?">'.T('List').'</a><br/>';
|
---|
85 | return($Output);
|
---|
86 | }
|
---|
87 |
|
---|
88 | function ViewList()
|
---|
89 | {
|
---|
90 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$this->TableSQL.') AS `T`');
|
---|
91 | $DbRow = $DbResult->fetch_row();
|
---|
92 | $PageList = GetPageList($DbRow[0]);
|
---|
93 | $Output = $PageList['Output'];
|
---|
94 |
|
---|
95 | $Output .= '<table class="BaseTable">';
|
---|
96 | $TableColumns = array();
|
---|
97 | foreach($this->Definition as $Index => $Def)
|
---|
98 | if($Def['InList'])
|
---|
99 | $TableColumns[] = array('Name' => $Index, 'Title' => $Def['Title']);
|
---|
100 | if(count($this->ItemActions) > 0)
|
---|
101 | $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
|
---|
102 |
|
---|
103 | $Order = GetOrderTableHeader($TableColumns, 'Name', 0);
|
---|
104 | $Output .= $Order['Output'];
|
---|
105 |
|
---|
106 | $DbResult = $this->Database->query('SELECT * FROM ('.$this->Table.') '.$Order['SQL'].$PageList['SQLLimit']);
|
---|
107 | while($Item = $DbResult->fetch_assoc())
|
---|
108 | {
|
---|
109 | $Output .= '<tr>';
|
---|
110 | foreach($this->Definition as $Index => $Def)
|
---|
111 | if($Def['InList'])
|
---|
112 | {
|
---|
113 | if($Def['Type'] == 'URL') $Output .= '<td><a href="'.$Item[$Index].'">'.$Item[$Index].'</a></td>';
|
---|
114 | else $Output .= '<td>'.$Item[$Index].'</td>';
|
---|
115 | }
|
---|
116 | if(count($this->ItemActions) > 0)
|
---|
117 | {
|
---|
118 | $Output .= '<td>';
|
---|
119 | foreach($this->ItemActions as $Index => $Action)
|
---|
120 | {
|
---|
121 | $URL = $Action['URL'];
|
---|
122 | if(strpos($URL, '#Id')) $URL = str_replace('#Id', $Item['Id'], $URL);
|
---|
123 | $Output .= '<a href="'.$URL.'">'.$Action['Name'].'</a> ';
|
---|
124 | }
|
---|
125 | $Output .= '</td>';
|
---|
126 | }
|
---|
127 | $Output .= '</tr>';
|
---|
128 | }
|
---|
129 | $Output .= '</table>';
|
---|
130 | if($this->AllowEdit) $Output .= '<a href="?action=add">'.T('Add').'</a><br/>';
|
---|
131 | return($Output);
|
---|
132 | }
|
---|
133 |
|
---|
134 | function AddItem()
|
---|
135 | {
|
---|
136 | $Output = '';
|
---|
137 | if($this->System->User->Licence(LICENCE_USER))
|
---|
138 | {
|
---|
139 | if(array_key_exists('finish', $_GET))
|
---|
140 | {
|
---|
141 | $Items = array();
|
---|
142 | foreach($this->Definition as $Index => $Def)
|
---|
143 | {
|
---|
144 | $Items[$Index] = $_POST[$Index];
|
---|
145 | }
|
---|
146 | $this->Database->insert($this->Table, $Items);
|
---|
147 | $Output = ShowMessage(T('Item added'), MESSAGE_INFORMATION);
|
---|
148 | } else
|
---|
149 | {
|
---|
150 | $Output .= '<form action="?action=add&finish=1" method="post">'.
|
---|
151 | '<fieldset><legend>'.T('New item').'</legend>'.
|
---|
152 | '<table>';
|
---|
153 | foreach($this->Definition as $DefIndex => $Def)
|
---|
154 | {
|
---|
155 | $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->GetControl($Def['Type'], $DefIndex, '').'</tr>';
|
---|
156 | }
|
---|
157 | $Output .= '<tr><td colspan="2"><input type="submit" value="'.T('Add').'" /></td></tr>'.
|
---|
158 | '</table>'.
|
---|
159 | '</fieldset>'.
|
---|
160 | '</form>';
|
---|
161 | }
|
---|
162 | } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
|
---|
163 | return($Output);
|
---|
164 | }
|
---|
165 |
|
---|
166 | function DeleteItem()
|
---|
167 | {
|
---|
168 | if($this->System->User->Licence(LICENCE_USER))
|
---|
169 | {
|
---|
170 | $this->Database->query('DELETE FROM `'.$this->Table.'` WHERE (`User`='.$this->System->User->Id.') AND (`Id`='.($_GET['id'] * 1).')');
|
---|
171 | $Output = ShowMessage(T('Record removed'));
|
---|
172 | } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
|
---|
173 | return($Output);
|
---|
174 | }
|
---|
175 |
|
---|
176 | function GetControl($Type, $Name, $Value)
|
---|
177 | {
|
---|
178 | if($Type == 'Text') $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>';
|
---|
179 | else if($Type == 'Boolean') $Output = '<input type="checkbox" name="'.$Name.'"/>';
|
---|
180 | else $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>';
|
---|
181 | return($Output);
|
---|
182 | }
|
---|
183 |
|
---|
184 | function ViewControl($Type, $Name, $Value)
|
---|
185 | {
|
---|
186 | if($Type == 'Text') $Output = $Value;
|
---|
187 | else if($Type == 'URL') $Output = '<a href="'.$Value.'">'.$Value.'</a>';
|
---|
188 | else if($Type == 'Boolean') $Output = $Value;
|
---|
189 | else $Output = $Value;
|
---|
190 | return($Output);
|
---|
191 | }
|
---|
192 | }
|
---|