source: trunk/Modules/Portal/Portal.php@ 533

Last change on this file since 533 was 533, checked in by chronos, 12 years ago
  • Opraveno: Ukládání položek ve správě dat.
  • Opraveno: Kontrola oprávnění při zobrazení aktualit.
  • Opraveno: Zobrazení seznamu uživatelů a jejich přidružených počítačů i v případě, že jednomu uživateli je přidruženo více zákazníků.
  • Property svn:executable set to *
File size: 16.4 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../../Common/Global.php');
4
5class PagePortal extends Page
6{
7 var $FullTitle = 'Zděchovský rozcestník';
8 var $ShortTitle = 'Rozcestník';
9
10 function ShowActions($ActionGroup)
11 {
12 $Output = '';
13 $DbResult = $this->Database->query('SELECT *, `ActionIcon`.`Name` AS `Icon` FROM `Action` LEFT JOIN `ActionIcon` ON `ActionIcon`.`Id` = `Action`.`Icon` '.
14 'WHERE (`Group`='.$ActionGroup['Id'].') AND (`Enable` = 1)');
15 while($Action = $DbResult->fetch_assoc())
16 {
17 if($Action['Icon'] == '') $Action['Icon'] = 'clear.png';
18 if(substr($Action['URL'], 0, 4) != 'http') $Action['URL'] = $this->System->Link($Action['URL']);
19 if(($Action['PermissionModule'] == '') or (($Action['PermissionModule'] != '') and $this->System->User->User->CheckPermission($Action['PermissionModule'], $Action['PermissionOperation'])))
20 $Output .= '<img alt="'.$Action['Title'].'" src="images/favicons/'.$Action['Icon'].'" width="16" height="16" /> <a href="'.$Action['URL'].'">'.$Action['Title'].'</a><br />';
21 }
22 return($this->Panel($ActionGroup['Name'], $Output));
23 }
24
25 function InfoBar()
26 {
27 $Output2 = '';
28
29 $DbResult = $this->Database->query('SELECT COUNT(*) FROM NetworkDevice LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type WHERE NetworkDeviceType.ShowOnline = 1');
30 $DbRow = $DbResult->fetch_array();
31 $TotalComputers = $DbRow[0];
32
33 $DbResult = $this->Database->query('SELECT COUNT(*) FROM NetworkDevice LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type WHERE (NetworkDeviceType.ShowOnline = 1) AND (NetworkDevice.Online = 1)');
34 $DbRow = $DbResult->fetch_array();
35 $OnlineComputers = $DbRow[0];
36
37 $Output = '<img alt="" src="images/favicons/comp.png" width="16" height="16" /> '.$OnlineComputers.' / '.$TotalComputers.' &nbsp; &nbsp; ';
38
39 $DbResult = $this->Database->select('Member', 'COUNT(*)', '1');
40 $DbRow = $DbResult->fetch_array();
41 $TotalUser = $DbRow[0];
42
43 $DbResult = $this->Database->query('SELECT COUNT(DISTINCT(Member)) FROM NetworkDevice '.
44 'LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type '.
45 'WHERE NetworkDeviceType.ShowOnline = 1 AND NetworkDevice.Online = 1');
46 $DbRow = $DbResult->fetch_array();
47 $OnlineUser = $DbRow[0];
48
49 $Output .= '<img alt="" src="images/favicons/house.png" width="16" height="16" /> '.$OnlineUser.' / '.$TotalUser.' &nbsp; &nbsp; ';
50
51 $NetworkUsage = 0;
52 $Output .= '<img alt="" src="images/favicons/usage.png" width="16" height="16" /> '.$NetworkUsage.' % &nbsp; &nbsp; ';
53
54 //$Output .= 'Server běží: '.$this->GetServerUptime().' &nbsp; &nbsp; ';
55
56 if($this->System->User->CheckPermission('Finance', 'DisplaySubjectState'))
57 {
58 $DbResult = $this->Database->select('MemberPayment', 'Cash', 'Member=(SELECT Customer FROM UserCustomerRel WHERE Id='.$this->System->User->User['Id'].')');
59 if($DbResult->num_rows > 0)
60 {
61 $DbRow = $DbResult->fetch_assoc();
62 $Output2 .= ' &nbsp; &nbsp; <img alt="" src="images/favicons/money.png" width="16" height="16" /> '.$DbRow['Cash'].' Kč';
63 }
64 }
65
66 $Output = '<div class="Navigation"><span class="MenuItem">'.$Output.'</span><div class="MenuItem2">&nbsp;'.$Output2.'</div></div>';
67 return($Output);
68 }
69
70 function UserPanel()
71 {
72 $Output = '<a href="'.$this->System->Link('/?Action=UserOptions').'">Profil</a><br />';
73 if($this->System->User->CheckPermission('Finance', 'MemberOptions'))
74 $Output .= '<a href="'.$this->System->Link('/?Action=MemberOptions').'">Domácnost</a><br />';
75 if($this->System->User->CheckPermission('Finance', 'DisplaySubjectState'))
76 $Output .= '<a href="'.$this->System->Link('/finance/platby/').'">Finance</a><br />';
77 if($this->System->User->CheckPermission('Network', 'RegistredHostList'))
78 $Output .= '<a href="'.$this->System->Link('/network/user-hosts/').'">Počítače</a><br />';
79 if($this->System->User->CheckPermission('News', 'Insert'))
80 $Output .= '<a href="'.$this->System->Link('/aktuality/?action=add').'">Vložení aktuality</a><br />';
81 if($this->System->User->CheckPermission('EatingPlace', 'Edit'))
82 $Output .= '<a href="'.$this->System->Link('/jidelna/menuedit.php').'">Úprava jídelníčků</a><br />';
83 if($this->System->User->CheckPermission('Finance', 'Manage'))
84 $Output .= '<a href="'.$this->System->Link('/finance/sprava/').'">Správa financí</a><br />';
85 if($this->System->User->CheckPermission('Network', 'Administration'))
86 $Output .= '<a href="'.$this->System->Link('/network/administration/').'">Správa sítě</a><br />';
87 if($this->System->User->CheckPermission('IS', 'Manage'))
88 $Output .= '<a href="'.$this->System->Link('/is/').'">Správa dat</a><br />';
89 return($Output);
90 }
91
92 function WebcamPanel()
93 {
94 $Output = $this->System->ModuleManager->Modules['WebCam']->ShowImage();
95 return($Output);
96 }
97
98 function OnlineHostList()
99 {
100 $Output = '<span style="font-size: smaller;">';
101 $DbResult = $this->Database->query('SELECT NetworkDevice.Name FROM NetworkDevice LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type WHERE (NetworkDeviceType.ShowOnline = 1) AND (NetworkDevice.Online = 1) ORDER BY NetworkDevice.Name');
102 while($Device = $DbResult->fetch_array())
103 {
104 $Output .= $Device['Name'].'<br />';
105 }
106 $Output .= '</span>';
107 return($Output);
108 }
109
110 function ShowBadPayerList()
111 {
112 $Output .= '<div class="PanelTitle">Dlužníci:</div><span style="font-size: smaller;">';
113 $DbResult = $Database->select('Subject', 'Name', 'Money < 0 ORDER BY Money');
114 while($Row = $DbResult->fetch_array())
115 {
116 $Output .= $Row['Name'].'<br />';
117 }
118 $Output .= '</span>';
119 return($Output);
120 }
121
122 function Panel($Title, $Content, $Menu = array())
123 {
124 if(count($Menu) > 0)
125 foreach($Menu as $Item)
126 $Title .= '<div class="Action">'.$Item.'</div>';
127 return('<div class="Panel"><div class="Title">'.$Title.'</div><div class="Content">'.$Content.'</div></div>');
128 }
129
130 function Show()
131 {
132 $Output = '';
133 if(array_key_exists('Action', $_GET))
134 {
135 if($_GET['Action'] == 'CustomizeNewsSave')
136 {
137 $Output .= $this->System->ModuleManager->Modules['News']->CustomizeSave();
138 } else
139 if($_GET['Action'] == 'LoginForm')
140 {
141 $Form = new Form($this->System->FormManager);
142 $Form->SetClass('UserLogin');
143 $Form->OnSubmit = '?Action=Login';
144 $Output .= $Form->ShowEditForm();
145 $Output .= '<div class="Centred"><a href="?Action=UserRegister">Registrovat se</a> '.
146 '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
147 } else
148 if($_GET['Action'] == 'Login')
149 {
150 if(array_key_exists('Username', $_POST) and array_key_exists('Password', $_POST))
151 {
152 $Form = new Form($this->System->FormManager);
153 $Form->SetClass('UserLogin');
154 $Form->OnSubmit = '?Action=Login';
155 $Result = $this->System->User->Login($_POST['Username'], $_POST['Password']);
156 $Output .= $this->SystemMessage('Přihlášení', $Result);
157 if($Result <> USER_LOGGED_IN)
158 {
159 $Form->LoadValuesFromForm();
160 $Form->Values['Password'] = '';
161 $Output .= $Form->ShowEditForm();
162 $Output .= '<div class="Centred"><a href="?Action=UserRegister">Registrovat se</a> '.
163 '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
164 }
165 } else $Output .= $this->SystemMessage('Přihlášení', 'Nezadány přihlašovací údaje');
166 } else
167 if($_GET['Action'] == 'Logout')
168 {
169 if($this->System->User->User['Id'] != null)
170 {
171 $Output .= $this->SystemMessage('Odhlášení', $this->System->User->Logout());
172 } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
173 } else
174 if($_GET['Action'] == 'UserOptions')
175 {
176 if($this->System->User->User['Id'] != null)
177 {
178 $Form = new Form($this->System->FormManager);
179 $Form->SetClass('UserOptions');
180 $Form->LoadValuesFromDatabase($this->System->User->User['Id']);
181 $Form->OnSubmit = '?Action=UserOptionsSave';
182 $Output .= $Form->ShowEditForm();
183 } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
184 } else
185 if($_GET['Action'] == 'UserOptionsSave')
186 {
187 $Form = new Form($this->System->FormManager);
188 $Form->SetClass('UserOptions');
189 $Form->LoadValuesFromForm();
190 $Form->SaveValuesToDatabase($this->System->User->User['Id']);
191 $Output .= $this->SystemMessage('Nastavení', 'Nastavení uloženo.');
192 $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'Nastavení uživatele změněno', $Form->Values['Name']);
193 $Form->LoadValuesFromDatabase($this->System->User->User['Id']);
194 $Form->OnSubmit = '?Action=UserOptionsSave';
195 $Output .= $Form->ShowEditForm();
196 }
197 if($_GET['Action'] == 'UserRegister')
198 {
199 $Form = new Form($this->System->FormManager);
200 $Form->SetClass('UserRegister');
201 //$Form->LoadValuesFromForm();
202 $Form->OnSubmit = '?Action=UserRegisterSave';
203 $Output .= $Form->ShowEditForm();
204 } else
205 if($_GET['Action'] == 'UserRegisterConfirm')
206 {
207 $Output .= $this->SystemMessage('Potvrzení registrace',
208 $this->System->User->RegisterConfirm($_GET['User'], $_GET['H']));
209 } else
210 if($_GET['Action'] == 'PasswordRecovery')
211 {
212 $Form = new Form($this->System->FormManager);
213 $Form->SetClass('PasswordRecovery');
214 $Form->OnSubmit = '?Action=PasswordRecovery2';
215 $Output .= $Form->ShowEditForm();
216 } else
217 if($_GET['Action'] == 'PasswordRecovery2')
218 {
219 $Form = new Form($this->System->FormManager);
220 $Form->SetClass('PasswordRecovery');
221 $Form->LoadValuesFromForm();
222 $Result = $this->System->User->PasswordRecoveryRequest($Form->Values['Name'], $Form->Values['Email']);
223 $Output .= $this->SystemMessage('Obnova hesla', $Result);
224 if($Result <> USER_PASSWORD_RECOVERY_SUCCESS)
225 {
226 $Output .= $Form->ShowEditForm();
227 }
228 } else
229 if($_GET['Action'] == 'PasswordRecoveryConfirm')
230 {
231 $Output .= $this->SystemMessage('Obnova hesla', $this->System->User->PasswordRecoveryConfirm($_GET['User'], $_GET['H'], $_GET['P']));
232 } else
233 if($_GET['Action'] == 'UserRegisterSave')
234 {
235 $Form = new Form($this->System->FormManager);
236 $Form->SetClass('UserRegister');
237 $Form->LoadValuesFromForm();
238 $Result = $this->System->User->Register($Form->Values['Login'], $Form->Values['Password'], $Form->Values['Password2'], $Form->Values['Email'], $Form->Values['Name'], $Form->Values['PhoneNumber'], $Form->Values['ICQ']);
239 $Output .= $this->SystemMessage('Registrace nového účtu', $Result);
240 if($Result <> USER_REGISTRATED)
241 {
242 $Form->OnSubmit = '?Action=UserRegisterSave';
243 $Output .= $Form->ShowEditForm();
244 }
245 } else
246 if($_GET['Action'] == 'MemberOptions')
247 {
248 $Form = new Form($this->System->FormManager);
249 $Form->SetClass('MemberOptions');
250 $DbResult = $this->Database->query('SELECT Customer FROM UserCustomerRel WHERE User='.$this->System->User->User['Id']);
251 if($DbResult->num_rows > 0)
252 {
253 $CustomerUserRel = $DbResult->fetch_assoc();
254 $DbResult = $this->Database->query('SELECT Member.Id, '.
255 'Member.FamilyMemberCount, Member.BillingPeriodNext, Subject.Name, Subject.AddressStreet, '.
256 'Subject.AddressTown, Subject.AddressPSC, Subject.AddressCountry, Subject.IC, Subject.DIC FROM Member JOIN Subject '.
257 'ON Subject.Id = Member.Subject WHERE Member.Id='.$CustomerUserRel['Customer']);
258 $DbRow = $DbResult->fetch_array();
259 foreach($Form->Definition['Items'] as $Index => $Item)
260 {
261 $Form->Values[$Index] = $DbRow[$Index];
262 }
263 $Form->OnSubmit = '?Action=MemberOptionsSave';
264 $Output .= $Form->ShowEditForm();
265 } else $Output .= $this->SystemMessage('Chyba', 'Nejste zákazníkem');
266 } else
267 if($_GET['Action'] == 'MemberOptionsSave')
268 {
269 $Form = new Form($this->System->FormManager);
270 $Form->SetClass('MemberOptions');
271 $Form->LoadValuesFromForm();
272 if($Form->Values['FamilyMemberCount'] < 0)
273 $Form->Values['FamilyMemberCount'] = 0;
274 if($Form->Values['BillingPeriodNext'] < 2)
275 $Form->Values['BillingPeriodNext'] = 2;
276
277 $DbResult = $this->Database->update('Member', 'Id='.$this->System->User->User['Member'],
278 array('FamilyMemberCount' => $Form->Values['FamilyMemberCount'],
279 'BillingPeriodNext' => $Form->Values['BillingPeriodNext']));
280 $DbResult = $this->Database->query('SELECT Subject FROM Member WHERE Id='.$this->System->User->User['Member']);
281 $Member = $DbResult->fetch_assoc();
282 $DbResult = $this->Database->update('Subject', 'Id='.$Member['Subject'],
283 array('Name' => $Form->Values['Name'], 'AddressStreet' => $Form->Values['AddressStreet'],
284 'AddressTown' => $Form->Values['AddressTown'], 'AddressCountry' => $Form->Values['AddressCountry'],
285 'AddressPSC' => $Form->Values['AddressPSC'], 'IC' => $Form->Values['IC'],
286 'DIC' => $Form->Values['DIC']));
287 $Output .= $this->SystemMessage('Nastavení', 'Nastavení domácnosti uloženo.');
288 $this->System->ModuleManager->Modules['Log']->NewRecord('Member+Subject', 'Nastavení člena/subjektu změněno',
289 $Form->Values['Name']);
290 $DbResult = $this->Database->query('SELECT Member.Id, Member.FamilyMemberCount, Member.BillingPeriodNext, '.
291 'Subject.Name, Subject.AddressStreet, Subject.AddressTown, Subject.AddressPSC, '.
292 'Subject.AddressCountry, Subject.IC, Subject.DIC FROM Member JOIN Subject '.
293 'ON Subject.Id = Member.Subject WHERE Member.Id='.$this->System->User->User['Member']);
294 $DbRow = $DbResult->fetch_array();
295 foreach($Form->Definition['Items'] as $Index => $Item)
296 {
297 $Form->Values[$Index] = $DbRow[$Index];
298 }
299 $Form->OnSubmit = '?Action=MemberOptionsSave';
300 $Output .= $Form->ShowEditForm();
301 }
302 }
303
304 $DbResult = $this->Database->query('SELECT * FROM `ActionGroup`');
305 while($DbRow = $DbResult->fetch_assoc())
306 $ActionGroups[$DbRow['Id']] = $DbRow;
307
308 // Show pannels
309 //if(IsInternetAddr()) echo('Internet'); else echo('LAN');
310 //$Output .= $this->InfoBar();
311 $Output .= '<table id="MainTable"><tr>';
312 $DbResult = $this->Database->select('PanelColumn', '*');
313 while($PanelColumn = $DbResult->fetch_assoc())
314 {
315 if($PanelColumn != '') $Width = ' width="'.$PanelColumn['Width'].'"';
316 else $Width = '';
317 $Output .= '<td valign="top"'.$Width.'>';
318 $DbResult2 = $this->Database->query('SELECT * FROM `Panel` WHERE `PanelColumn`='.$PanelColumn['Id'].' ORDER BY `Order`');
319 while($Panel = $DbResult2->fetch_assoc())
320 {
321 if($Panel['Module'] == 'ActionGroup') $Output .= $this->ShowActions($ActionGroups[$Panel['Parameters']]);
322 else if($Panel['Module'] == 'OnlineHostList') $Output .= $this->Panel('Online počítače', $this->OnlineHostList());
323 else if($Panel['Module'] == 'UserOptions')
324 {
325 if($this->System->User->User['Id'] != null) $Output .= $this->Panel('Přihlášený uživatel', $this->UserPanel());
326 } else
327 if($Panel['Module'] == 'Webcam') $Output .= $this->Panel('Kamery', $this->WebcamPanel());
328 else if($Panel['Module'] == 'NewsGroupList')
329 $Output .= $this->Panel('Aktuality', $this->System->ModuleManager->Modules['News']->Show(), array('<a href="?Action=CustomizeNews">Upravit</a>'));
330 }
331 $Output .= '</td>';
332 }
333 $Output .= '</tr></table>';
334 return($Output);
335 }
336}
337
338class ModulePortal extends AppModule
339{
340 function __construct($System)
341 {
342 parent::__construct($System);
343 $this->Name = 'Portal';
344 $this->Version = '1.0';
345 $this->Creator = 'Chronos';
346 $this->License = 'GNU/GPLv3';
347 $this->Description = 'Community portal.';
348 $this->Dependencies = array('News');
349 }
350
351 function Install()
352 {
353 }
354
355 function Uninstall()
356 {
357 }
358
359 function Start()
360 {
361 parent::Start();
362 $this->System->RegisterPage('', 'PagePortal');
363 }
364
365 function Stop()
366 {
367 }
368}
369
370?>
Note: See TracBrowser for help on using the repository browser.