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

Last change on this file since 597 was 597, checked in by chronos, 12 years ago
  • Přidáno: Akce zobrazovat přes sjednocenou funkci ShowAction.
  • Přidáno: Chybějící tabulka Model pro seznam modelů.
  • Property svn:executable set to *
File size: 20.4 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../../Common/Global.php');
4
5class ModulePortal extends AppModule
6{
7 function __construct($System)
8 {
9 parent::__construct($System);
10 $this->Name = 'Portal';
11 $this->Version = '1.0';
12 $this->Creator = 'Chronos';
13 $this->License = 'GNU/GPLv3';
14 $this->Description = 'Community portal.';
15 $this->Dependencies = array('News');
16 }
17
18 function DoInstall()
19 {
20 }
21
22 function DoUninstall()
23 {
24 }
25
26 function DoStart()
27 {
28 $this->System->RegisterPage('', 'PagePortal');
29 $this->System->FormManager->RegisterClass('MemberOptions', array(
30 'Title' => 'Nastavení domácnosti',
31 'Table' => '(SELECT Member.Id, Member.FamilyMemberCount, Subject.Name, Subject.AddressStreet, Subject.AddressTown, Subject.AddressPSC, Subject.IC, Subject.DIC FROM Member JOIN Subject ON Subject.Id = Member.Subject)',
32 'Items' => array(
33 'Name' => array('Type' => 'String', 'Caption' => 'Fakturační jméno', 'Default' => ''),
34 'AddressStreet' => array('Type' => 'String', 'Caption' => 'Ulice', 'Default' => 'Zděchov'),
35 'AddressTown' => array('Type' => 'String', 'Caption' => 'Město', 'Default' => 'Zděchov'),
36 'AddressPSC' => array('Type' => 'String', 'Caption' => 'PSČ', 'Default' => '75607'),
37 'AddressCountry' => array('Type' => 'TCountry', 'Caption' => 'Země', 'Default' => '1'),
38 'IC' => array('Type' => 'String', 'Caption' => 'IČ', 'Default' => ''),
39 'DIC' => array('Type' => 'String', 'Caption' => 'DIČ', 'Default' => ''),
40 'FamilyMemberCount' => array('Type' => 'Integer', 'Caption' => 'Počet osob v domácnosti', 'Default' => '', 'Suffix' => 'osob'),
41 'BillingPeriodNext' => array('Type' => 'TFinanceBillingPeriod', 'Caption' => 'Požadované fakturované období', 'Default' => ''),
42 ),
43 ));
44 $this->System->FormManager->RegisterClass('UserOptions', array(
45 'Title' => 'Základní nastavení',
46 'Table' => 'User',
47 'SubmitText' => 'Uložit',
48 'Items' => array(
49 'Login' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno', 'Default' => ''),
50 'Salt' => array('Type' => 'RandomHash', 'Caption' => 'Sůl', 'Default' => ''),
51 'Password' => array('Type' => 'Password', 'Caption' => 'Heslo', 'Default' => ''),
52 'Name' => array('Type' => 'String', 'Caption' => 'Zobrazované jméno', 'Default' => ''),
53 'Email' => array('Type' => 'String', 'Caption' => 'E-mail', 'Default' => ''),
54 'PhoneNumber' => array('Type' => 'String', 'Caption' => 'Telefón', 'Default' => ''),
55 'ICQ' => array('Type' => 'String', 'Caption' => 'ICQ', 'Default' => ''),
56 ),
57 ));
58 $this->System->FormManager->RegisterClass('UserRegister', array(
59 'Title' => 'Registrace uživatele',
60 'SubmitText' => 'Registrovat',
61 'Table' => 'User',
62 'Items' => array(
63 'Login' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno', 'Default' => ''),
64 'Password' => array('Type' => 'Password', 'Caption' => 'Heslo', 'Default' => ''),
65 'Password2' => array('Type' => 'Password', 'Caption' => 'Potvrzení hesla', 'Default' => ''),
66 'Name' => array('Type' => 'String', 'Caption' => 'Zobrazované jméno', 'Default' => ''),
67 'Email' => array('Type' => 'String', 'Caption' => 'E-mail', 'Default' => ''),
68 'PhoneNumber' => array('Type' => 'String', 'Caption' => 'Telefón', 'Default' => ''),
69 'ICQ' => array('Type' => 'String', 'Caption' => 'ICQ', 'Default' => ''),
70 ),
71 ));
72 $this->System->FormManager->RegisterClass('PasswordRecovery', array(
73 'Title' => 'Obnova hesla',
74 'SubmitText' => 'Obnovit',
75 'Table' => '',
76 'Items' => array(
77 'Name' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno', 'Default' => ''),
78 'Email' => array('Type' => 'String', 'Caption' => 'E-mail', 'Default' => ''),
79 ),
80 ));
81 $this->System->FormManager->RegisterClass('UserLogin', array(
82 'Title' => 'Přihlášení uživatele',
83 'SubmitText' => 'Přihlásit',
84 'Table' => '',
85 'Items' => array(
86 'Username' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno', 'Default' => ''),
87 'Password' => array('Type' => 'Password', 'Caption' => 'Heslo', 'Default' => ''),
88 ),
89 ));
90
91 }
92
93 function DoStop()
94 {
95 }
96}
97
98class PagePortal extends Page
99{
100 var $FullTitle = 'Zděchovský rozcestník';
101 var $ShortTitle = 'Rozcestník';
102
103 function ShowActions($ActionGroup)
104 {
105 $Output = '';
106 $DbResult = $this->Database->query('SELECT `Id` FROM `Action` '.
107 'WHERE (`Action`.`Group`='.$ActionGroup['Id'].') AND (`Action`.`Enable` = 1)');
108 while($Action = $DbResult->fetch_assoc())
109 {
110 $Output .= $this->System->ShowAction($Action['Id']);
111 }
112 return($this->Panel($ActionGroup['Name'], $Output));
113 }
114
115 function InfoBar()
116 {
117 $Output2 = '';
118
119 $DbResult = $this->Database->query('SELECT COUNT(*) FROM NetworkDevice LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type WHERE NetworkDeviceType.ShowOnline = 1');
120 $DbRow = $DbResult->fetch_array();
121 $TotalComputers = $DbRow[0];
122
123 $DbResult = $this->Database->query('SELECT COUNT(*) FROM NetworkDevice LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type WHERE (NetworkDeviceType.ShowOnline = 1) AND (NetworkDevice.Online = 1)');
124 $DbRow = $DbResult->fetch_array();
125 $OnlineComputers = $DbRow[0];
126
127 $Output = '<img alt="" src="images/favicons/comp.png" width="16" height="16" /> '.$OnlineComputers.' / '.$TotalComputers.' &nbsp; &nbsp; ';
128
129 $DbResult = $this->Database->select('Member', 'COUNT(*)', '1');
130 $DbRow = $DbResult->fetch_array();
131 $TotalUser = $DbRow[0];
132
133 $DbResult = $this->Database->query('SELECT COUNT(DISTINCT(Member)) FROM NetworkDevice '.
134 'LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type '.
135 'WHERE NetworkDeviceType.ShowOnline = 1 AND NetworkDevice.Online = 1');
136 $DbRow = $DbResult->fetch_array();
137 $OnlineUser = $DbRow[0];
138
139 $Output .= '<img alt="" src="images/favicons/house.png" width="16" height="16" /> '.$OnlineUser.' / '.$TotalUser.' &nbsp; &nbsp; ';
140
141 $NetworkUsage = 0;
142 $Output .= '<img alt="" src="images/favicons/usage.png" width="16" height="16" /> '.$NetworkUsage.' % &nbsp; &nbsp; ';
143
144 //$Output .= 'Server běží: '.$this->GetServerUptime().' &nbsp; &nbsp; ';
145
146 if($this->System->User->CheckPermission('Finance', 'DisplaySubjectState'))
147 {
148 $DbResult = $this->Database->select('MemberPayment', 'Cash', 'Member=(SELECT Customer FROM UserCustomerRel WHERE Id='.$this->System->User->User['Id'].')');
149 if($DbResult->num_rows > 0)
150 {
151 $DbRow = $DbResult->fetch_assoc();
152 $Output2 .= ' &nbsp; &nbsp; <img alt="" src="images/favicons/money.png" width="16" height="16" /> '.$DbRow['Cash'].' Kč';
153 }
154 }
155
156 $Output = '<div class="Navigation"><span class="MenuItem">'.$Output.'</span><div class="MenuItem2">&nbsp;'.$Output2.'</div></div>';
157 return($Output);
158 }
159
160 function UserPanel()
161 {
162 $Output = '<a href="'.$this->System->Link('/?Action=UserOptions').'">Profil</a><br />';
163 if($this->System->User->CheckPermission('Finance', 'MemberOptions'))
164 $Output .= '<a href="'.$this->System->Link('/?Action=MemberOptions').'">Domácnost</a><br />';
165 if($this->System->User->CheckPermission('Finance', 'DisplaySubjectState'))
166 $Output .= '<a href="'.$this->System->Link('/finance/platby/').'">Finance</a><br />';
167 if($this->System->User->CheckPermission('Network', 'RegistredHostList'))
168 $Output .= '<a href="'.$this->System->Link('/network/user-hosts/').'">Počítače</a><br />';
169 if($this->System->User->CheckPermission('News', 'Insert'))
170 $Output .= '<a href="'.$this->System->Link('/aktuality/?action=add').'">Vložení aktuality</a><br />';
171 if($this->System->User->CheckPermission('EatingPlace', 'Edit'))
172 $Output .= '<a href="'.$this->System->Link('/jidelna/menuedit.php').'">Úprava jídelníčků</a><br />';
173 if($this->System->User->CheckPermission('Finance', 'Manage'))
174 $Output .= '<a href="'.$this->System->Link('/finance/sprava/').'">Správa financí</a><br />';
175 if($this->System->User->CheckPermission('IS', 'Manage'))
176 $Output .= '<a href="'.$this->System->Link('/is/').'">Správa dat</a><br />';
177 return($Output);
178 }
179
180 function WebcamPanel()
181 {
182 $Output = $this->System->ModuleManager->Modules['WebCam']->ShowImage();
183 return($Output);
184 }
185
186 function OnlineHostList()
187 {
188 $Output = '<span style="font-size: smaller;">';
189 $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');
190 while($Device = $DbResult->fetch_array())
191 {
192 $Output .= $Device['Name'].'<br />';
193 }
194 $Output .= '</span>';
195 return($Output);
196 }
197
198 function ShowBadPayerList()
199 {
200 $Output .= '<div class="PanelTitle">Dlužníci:</div><span style="font-size: smaller;">';
201 $DbResult = $Database->select('Subject', 'Name', 'Money < 0 ORDER BY Money');
202 while($Row = $DbResult->fetch_array())
203 {
204 $Output .= $Row['Name'].'<br />';
205 }
206 $Output .= '</span>';
207 return($Output);
208 }
209
210 function Panel($Title, $Content, $Menu = array())
211 {
212 if(count($Menu) > 0)
213 foreach($Menu as $Item)
214 $Title .= '<div class="Action">'.$Item.'</div>';
215 return('<div class="Panel"><div class="Title">'.$Title.'</div><div class="Content">'.$Content.'</div></div>');
216 }
217
218 function Show()
219 {
220 $Output = '';
221 if(array_key_exists('Action', $_GET))
222 {
223 $Action = $_GET['Action'];
224 if($Action == 'CustomizeNewsSave')
225 {
226 $Output .= $this->System->ModuleManager->Modules['News']->CustomizeSave();
227 } else
228 if($Action == 'LoginForm')
229 {
230 $Form = new Form($this->System->FormManager);
231 $Form->SetClass('UserLogin');
232 $Form->OnSubmit = '?Action=Login';
233 $Output .= $Form->ShowEditForm();
234 $Output .= '<div class="Centred"><a href="?Action=UserRegister">Registrovat se</a> '.
235 '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
236 } else
237 if($Action == 'Login')
238 {
239 if(array_key_exists('Username', $_POST) and array_key_exists('Password', $_POST))
240 {
241 $Form = new Form($this->System->FormManager);
242 $Form->SetClass('UserLogin');
243 $Form->OnSubmit = '?Action=Login';
244 $Result = $this->System->User->Login($_POST['Username'], $_POST['Password']);
245 $Output .= $this->SystemMessage('Přihlášení', $Result);
246 if($Result <> USER_LOGGED_IN)
247 {
248 $Form->LoadValuesFromForm();
249 $Form->Values['Password'] = '';
250 $Output .= $Form->ShowEditForm();
251 $Output .= '<div class="Centred"><a href="?Action=UserRegister">Registrovat se</a> '.
252 '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
253 } else {
254 //$Output .= '<div class="Centred">Za 5 sekund budete přesměrováni na <a href="?Action=UserMenu">nabídku uživatele</a></div>';
255 //Header('refresh:5;url=?Action=UserMenu');
256 Header('Location: ?Action=UserMenu');
257 }
258 } else $Output .= $this->SystemMessage('Přihlášení', 'Nezadány přihlašovací údaje');
259 } else
260 if($Action == 'Logout')
261 {
262 if($this->System->User->User['Id'] != null)
263 {
264 $Output .= $this->SystemMessage('Odhlášení', $this->System->User->Logout());
265 } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
266 } else
267 if($Action == 'UserOptions')
268 {
269 if($this->System->User->User['Id'] != null)
270 {
271 $Form = new Form($this->System->FormManager);
272 $Form->SetClass('UserOptions');
273 $Form->LoadValuesFromDatabase($this->System->User->User['Id']);
274 $Form->OnSubmit = '?Action=UserOptionsSave';
275 $Output .= $Form->ShowEditForm();
276 } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
277 } else
278 if($Action == 'UserOptionsSave')
279 {
280 $Form = new Form($this->System->FormManager);
281 $Form->SetClass('UserOptions');
282 $Form->LoadValuesFromForm();
283 $Form->SaveValuesToDatabase($this->System->User->User['Id']);
284 $Output .= $this->SystemMessage('Nastavení', 'Nastavení uloženo.');
285 $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'Nastavení uživatele změněno', $Form->Values['Name']);
286 $Form->LoadValuesFromDatabase($this->System->User->User['Id']);
287 $Form->OnSubmit = '?Action=UserOptionsSave';
288 $Output .= $Form->ShowEditForm();
289 } else
290 if($Action == 'UserRegister')
291 {
292 $Form = new Form($this->System->FormManager);
293 $Form->SetClass('UserRegister');
294 //$Form->LoadValuesFromForm();
295 $Form->OnSubmit = '?Action=UserRegisterSave';
296 $Output .= $Form->ShowEditForm();
297 } else
298 if($Action == 'UserRegisterConfirm')
299 {
300 $Output .= $this->SystemMessage('Potvrzení registrace',
301 $this->System->User->RegisterConfirm($_GET['User'], $_GET['H']));
302 } else
303 if($Action == 'PasswordRecovery')
304 {
305 $Form = new Form($this->System->FormManager);
306 $Form->SetClass('PasswordRecovery');
307 $Form->OnSubmit = '?Action=PasswordRecovery2';
308 $Output .= $Form->ShowEditForm();
309 } else
310 if($Action == 'PasswordRecovery2')
311 {
312 $Form = new Form($this->System->FormManager);
313 $Form->SetClass('PasswordRecovery');
314 $Form->LoadValuesFromForm();
315 $Result = $this->System->User->PasswordRecoveryRequest($Form->Values['Name'], $Form->Values['Email']);
316 $Output .= $this->SystemMessage('Obnova hesla', $Result);
317 if($Result <> USER_PASSWORD_RECOVERY_SUCCESS)
318 {
319 $Output .= $Form->ShowEditForm();
320 }
321 } else
322 if($Action == 'PasswordRecoveryConfirm')
323 {
324 $Output .= $this->SystemMessage('Obnova hesla', $this->System->User->PasswordRecoveryConfirm($_GET['User'], $_GET['H'], $_GET['P']));
325 } else
326 if($Action == 'UserRegisterSave')
327 {
328 $Form = new Form($this->System->FormManager);
329 $Form->SetClass('UserRegister');
330 $Form->LoadValuesFromForm();
331 $Result = $this->System->User->Register($Form->Values['Login'], $Form->Values['Password'],
332 $Form->Values['Password2'], $Form->Values['Email'], $Form->Values['Name'], $Form->Values['PhoneNumber'], $Form->Values['ICQ']);
333 $Output .= $this->SystemMessage('Registrace nového účtu', $Result);
334 if($Result <> USER_REGISTRATED)
335 {
336 $Form->OnSubmit = '?Action=UserRegisterSave';
337 $Output .= $Form->ShowEditForm();
338 }
339 } else
340 if($Action == 'MemberOptions')
341 {
342 $Form = new Form($this->System->FormManager);
343 $Form->SetClass('MemberOptions');
344 $DbResult = $this->Database->query('SELECT Customer FROM UserCustomerRel WHERE User='.$this->System->User->User['Id']);
345 if($DbResult->num_rows > 0)
346 {
347 $CustomerUserRel = $DbResult->fetch_assoc();
348 $DbResult = $this->Database->query('SELECT Member.Id, '.
349 'Member.FamilyMemberCount, Member.BillingPeriodNext, Subject.Name, Subject.AddressStreet, '.
350 'Subject.AddressTown, Subject.AddressPSC, Subject.AddressCountry, Subject.IC, Subject.DIC FROM Member JOIN Subject '.
351 'ON Subject.Id = Member.Subject WHERE Member.Id='.$CustomerUserRel['Customer']);
352 $DbRow = $DbResult->fetch_array();
353 foreach($Form->Definition['Items'] as $Index => $Item)
354 {
355 $Form->Values[$Index] = $DbRow[$Index];
356 }
357 $Form->OnSubmit = '?Action=MemberOptionsSave';
358 $Output .= $Form->ShowEditForm();
359 } else $Output .= $this->SystemMessage('Chyba', 'Nejste zákazníkem');
360 } else
361 if($Action == 'MemberOptionsSave')
362 {
363 $Form = new Form($this->System->FormManager);
364 $Form->SetClass('MemberOptions');
365 $Form->LoadValuesFromForm();
366 if($Form->Values['FamilyMemberCount'] < 0)
367 $Form->Values['FamilyMemberCount'] = 0;
368 if($Form->Values['BillingPeriodNext'] < 2)
369 $Form->Values['BillingPeriodNext'] = 2;
370
371 $DbResult = $this->Database->update('Member', 'Id='.$this->System->User->User['Member'],
372 array('FamilyMemberCount' => $Form->Values['FamilyMemberCount'],
373 'BillingPeriodNext' => $Form->Values['BillingPeriodNext']));
374 $DbResult = $this->Database->query('SELECT Subject FROM Member WHERE Id='.$this->System->User->User['Member']);
375 $Member = $DbResult->fetch_assoc();
376 $DbResult = $this->Database->update('Subject', 'Id='.$Member['Subject'],
377 array('Name' => $Form->Values['Name'], 'AddressStreet' => $Form->Values['AddressStreet'],
378 'AddressTown' => $Form->Values['AddressTown'], 'AddressCountry' => $Form->Values['AddressCountry'],
379 'AddressPSC' => $Form->Values['AddressPSC'], 'IC' => $Form->Values['IC'],
380 'DIC' => $Form->Values['DIC']));
381 $Output .= $this->SystemMessage('Nastavení', 'Nastavení domácnosti uloženo.');
382 $this->System->ModuleManager->Modules['Log']->NewRecord('Member+Subject', 'Nastavení člena/subjektu změněno',
383 $Form->Values['Name']);
384 $DbResult = $this->Database->query('SELECT Member.Id, Member.FamilyMemberCount, Member.BillingPeriodNext, '.
385 'Subject.Name, Subject.AddressStreet, Subject.AddressTown, Subject.AddressPSC, '.
386 'Subject.AddressCountry, Subject.IC, Subject.DIC FROM Member JOIN Subject '.
387 'ON Subject.Id = Member.Subject WHERE Member.Id='.$this->System->User->User['Member']);
388 $DbRow = $DbResult->fetch_array();
389 foreach($Form->Definition['Items'] as $Index => $Item)
390 {
391 $Form->Values[$Index] = $DbRow[$Index];
392 }
393 $Form->OnSubmit = '?Action=MemberOptionsSave';
394 $Output .= $Form->ShowEditForm();
395 } else
396 if($Action == 'UserMenu')
397 {
398 $Output = $this->ShowUserPanel();
399 } else $Output = $this->ShowMain();
400 } else $Output = $this->ShowMain();
401 return($Output);
402 }
403
404 function ShowMain()
405 {
406 $Output = '';
407 $DbResult = $this->Database->query('SELECT * FROM `ActionGroup`');
408 while($DbRow = $DbResult->fetch_assoc())
409 $ActionGroups[$DbRow['Id']] = $DbRow;
410
411 // Show pannels
412 //if(IsInternetAddr()) echo('Internet'); else echo('LAN');
413 //$Output .= $this->InfoBar();
414 $Output .= '<table id="MainTable"><tr>';
415 $DbResult = $this->Database->select('PanelColumn', '*');
416 while($PanelColumn = $DbResult->fetch_assoc())
417 {
418 if($PanelColumn != '') $Width = ' width="'.$PanelColumn['Width'].'"';
419 else $Width = '';
420 $Output .= '<td valign="top"'.$Width.'>';
421 $DbResult2 = $this->Database->query('SELECT * FROM `Panel` WHERE `PanelColumn`='.$PanelColumn['Id'].' ORDER BY `Order`');
422 while($Panel = $DbResult2->fetch_assoc())
423 {
424 if($Panel['Module'] == 'ActionGroup') $Output .= $this->ShowActions($ActionGroups[$Panel['Parameters']]);
425 else if($Panel['Module'] == 'OnlineHostList') $Output .= $this->Panel('Online počítače', $this->OnlineHostList());
426 else if($Panel['Module'] == 'UserOptions')
427 {
428 //if($this->System->User->User['Id'] != null) $Output .= $this->Panel('Přihlášený uživatel', $this->UserPanel());
429 } else
430 if($Panel['Module'] == 'Webcam') $Output .= $this->Panel('Kamery', $this->WebcamPanel());
431 else if($Panel['Module'] == 'NewsGroupList')
432 $Output .= $this->Panel('Aktuality', $this->System->ModuleManager->Modules['News']->Show(), array('<a href="?Action=CustomizeNews">Upravit</a>'));
433 }
434 $Output .= '</td>';
435 }
436 $Output .= '</tr></table>';
437 return($Output);
438 }
439
440 function ShowUserPanel()
441 {
442 $Output = '';
443 if($this->System->User->User['Id'] != null)
444 {
445 $Output .= '<div class="Centred"><table id="MainTable"><tr><td>';
446 $Output .= $this->Panel('Nabídka uživatele', $this->UserPanel());
447 $Output .= '</td><td>';
448 //$Output .= $this->Panel('Přehled', $this->UserPanel());
449 $Output .= '</td></tr></table></div>';
450 } else $Output .= $this->SystemMessage('Oprávnění', 'Nejste přihlášen');
451 return($Output);
452 }
453}
Note: See TracBrowser for help on using the repository browser.