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

Last change on this file since 548 was 548, checked in by chronos, 12 years ago
  • Odstraněno: Ukončovací PHP značka.
  • Property svn:executable set to *
File size: 20.2 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'],
239 $Form->Values['Password2'], $Form->Values['Email'], $Form->Values['Name'], $Form->Values['PhoneNumber'], $Form->Values['ICQ']);
240 $Output .= $this->SystemMessage('Registrace nového účtu', $Result);
241 if($Result <> USER_REGISTRATED)
242 {
243 $Form->OnSubmit = '?Action=UserRegisterSave';
244 $Output .= $Form->ShowEditForm();
245 }
246 } else
247 if($_GET['Action'] == 'MemberOptions')
248 {
249 $Form = new Form($this->System->FormManager);
250 $Form->SetClass('MemberOptions');
251 $DbResult = $this->Database->query('SELECT Customer FROM UserCustomerRel WHERE User='.$this->System->User->User['Id']);
252 if($DbResult->num_rows > 0)
253 {
254 $CustomerUserRel = $DbResult->fetch_assoc();
255 $DbResult = $this->Database->query('SELECT Member.Id, '.
256 'Member.FamilyMemberCount, Member.BillingPeriodNext, Subject.Name, Subject.AddressStreet, '.
257 'Subject.AddressTown, Subject.AddressPSC, Subject.AddressCountry, Subject.IC, Subject.DIC FROM Member JOIN Subject '.
258 'ON Subject.Id = Member.Subject WHERE Member.Id='.$CustomerUserRel['Customer']);
259 $DbRow = $DbResult->fetch_array();
260 foreach($Form->Definition['Items'] as $Index => $Item)
261 {
262 $Form->Values[$Index] = $DbRow[$Index];
263 }
264 $Form->OnSubmit = '?Action=MemberOptionsSave';
265 $Output .= $Form->ShowEditForm();
266 } else $Output .= $this->SystemMessage('Chyba', 'Nejste zákazníkem');
267 } else
268 if($_GET['Action'] == 'MemberOptionsSave')
269 {
270 $Form = new Form($this->System->FormManager);
271 $Form->SetClass('MemberOptions');
272 $Form->LoadValuesFromForm();
273 if($Form->Values['FamilyMemberCount'] < 0)
274 $Form->Values['FamilyMemberCount'] = 0;
275 if($Form->Values['BillingPeriodNext'] < 2)
276 $Form->Values['BillingPeriodNext'] = 2;
277
278 $DbResult = $this->Database->update('Member', 'Id='.$this->System->User->User['Member'],
279 array('FamilyMemberCount' => $Form->Values['FamilyMemberCount'],
280 'BillingPeriodNext' => $Form->Values['BillingPeriodNext']));
281 $DbResult = $this->Database->query('SELECT Subject FROM Member WHERE Id='.$this->System->User->User['Member']);
282 $Member = $DbResult->fetch_assoc();
283 $DbResult = $this->Database->update('Subject', 'Id='.$Member['Subject'],
284 array('Name' => $Form->Values['Name'], 'AddressStreet' => $Form->Values['AddressStreet'],
285 'AddressTown' => $Form->Values['AddressTown'], 'AddressCountry' => $Form->Values['AddressCountry'],
286 'AddressPSC' => $Form->Values['AddressPSC'], 'IC' => $Form->Values['IC'],
287 'DIC' => $Form->Values['DIC']));
288 $Output .= $this->SystemMessage('Nastavení', 'Nastavení domácnosti uloženo.');
289 $this->System->ModuleManager->Modules['Log']->NewRecord('Member+Subject', 'Nastavení člena/subjektu změněno',
290 $Form->Values['Name']);
291 $DbResult = $this->Database->query('SELECT Member.Id, Member.FamilyMemberCount, Member.BillingPeriodNext, '.
292 'Subject.Name, Subject.AddressStreet, Subject.AddressTown, Subject.AddressPSC, '.
293 'Subject.AddressCountry, Subject.IC, Subject.DIC FROM Member JOIN Subject '.
294 'ON Subject.Id = Member.Subject WHERE Member.Id='.$this->System->User->User['Member']);
295 $DbRow = $DbResult->fetch_array();
296 foreach($Form->Definition['Items'] as $Index => $Item)
297 {
298 $Form->Values[$Index] = $DbRow[$Index];
299 }
300 $Form->OnSubmit = '?Action=MemberOptionsSave';
301 $Output .= $Form->ShowEditForm();
302 }
303 }
304
305 $DbResult = $this->Database->query('SELECT * FROM `ActionGroup`');
306 while($DbRow = $DbResult->fetch_assoc())
307 $ActionGroups[$DbRow['Id']] = $DbRow;
308
309 // Show pannels
310 //if(IsInternetAddr()) echo('Internet'); else echo('LAN');
311 //$Output .= $this->InfoBar();
312 $Output .= '<table id="MainTable"><tr>';
313 $DbResult = $this->Database->select('PanelColumn', '*');
314 while($PanelColumn = $DbResult->fetch_assoc())
315 {
316 if($PanelColumn != '') $Width = ' width="'.$PanelColumn['Width'].'"';
317 else $Width = '';
318 $Output .= '<td valign="top"'.$Width.'>';
319 $DbResult2 = $this->Database->query('SELECT * FROM `Panel` WHERE `PanelColumn`='.$PanelColumn['Id'].' ORDER BY `Order`');
320 while($Panel = $DbResult2->fetch_assoc())
321 {
322 if($Panel['Module'] == 'ActionGroup') $Output .= $this->ShowActions($ActionGroups[$Panel['Parameters']]);
323 else if($Panel['Module'] == 'OnlineHostList') $Output .= $this->Panel('Online počítače', $this->OnlineHostList());
324 else if($Panel['Module'] == 'UserOptions')
325 {
326 if($this->System->User->User['Id'] != null) $Output .= $this->Panel('Přihlášený uživatel', $this->UserPanel());
327 } else
328 if($Panel['Module'] == 'Webcam') $Output .= $this->Panel('Kamery', $this->WebcamPanel());
329 else if($Panel['Module'] == 'NewsGroupList')
330 $Output .= $this->Panel('Aktuality', $this->System->ModuleManager->Modules['News']->Show(), array('<a href="?Action=CustomizeNews">Upravit</a>'));
331 }
332 $Output .= '</td>';
333 }
334 $Output .= '</tr></table>';
335 return($Output);
336 }
337}
338
339class ModulePortal extends AppModule
340{
341 function __construct($System)
342 {
343 parent::__construct($System);
344 $this->Name = 'Portal';
345 $this->Version = '1.0';
346 $this->Creator = 'Chronos';
347 $this->License = 'GNU/GPLv3';
348 $this->Description = 'Community portal.';
349 $this->Dependencies = array('News');
350 }
351
352 function Install()
353 {
354 }
355
356 function Uninstall()
357 {
358 }
359
360 function Start()
361 {
362 parent::Start();
363 $this->System->RegisterPage('', 'PagePortal');
364 $this->System->FormManager->RegisterClass('MemberOptions', array(
365 'Title' => 'Nastavení domácnosti',
366 '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)',
367 'Items' => array(
368 'Name' => array('Type' => 'String', 'Caption' => 'Fakturační jméno', 'Default' => ''),
369 'AddressStreet' => array('Type' => 'String', 'Caption' => 'Ulice', 'Default' => 'Zděchov'),
370 'AddressTown' => array('Type' => 'String', 'Caption' => 'Město', 'Default' => 'Zděchov'),
371 'AddressPSC' => array('Type' => 'String', 'Caption' => 'PSČ', 'Default' => '75607'),
372 'AddressCountry' => array('Type' => 'TCountry', 'Caption' => 'Země', 'Default' => '1'),
373 'IC' => array('Type' => 'String', 'Caption' => 'IČ', 'Default' => ''),
374 'DIC' => array('Type' => 'String', 'Caption' => 'DIČ', 'Default' => ''),
375 'FamilyMemberCount' => array('Type' => 'Integer', 'Caption' => 'Počet osob v domácnosti', 'Default' => '', 'Suffix' => 'osob'),
376 'BillingPeriodNext' => array('Type' => 'TFinanceBillingPeriod', 'Caption' => 'Požadované fakturované období', 'Default' => ''),
377 ),
378 ));
379 $this->System->FormManager->RegisterClass('UserOptions', array(
380 'Title' => 'Základní nastavení',
381 'Table' => 'User',
382 'SubmitText' => 'Uložit',
383 'Items' => array(
384 'Login' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno', 'Default' => ''),
385 'Salt' => array('Type' => 'RandomHash', 'Caption' => 'Sůl', 'Default' => ''),
386 'Password' => array('Type' => 'Password', 'Caption' => 'Heslo', 'Default' => ''),
387 'Name' => array('Type' => 'String', 'Caption' => 'Zobrazované jméno', 'Default' => ''),
388 'Email' => array('Type' => 'String', 'Caption' => 'E-mail', 'Default' => ''),
389 'PhoneNumber' => array('Type' => 'String', 'Caption' => 'Telefón', 'Default' => ''),
390 'ICQ' => array('Type' => 'String', 'Caption' => 'ICQ', 'Default' => ''),
391 ),
392 ));
393 $this->System->FormManager->RegisterClass('UserRegister', array(
394 'Title' => 'Registrace uživatele',
395 'SubmitText' => 'Registrovat',
396 'Table' => 'User',
397 'Items' => array(
398 'Login' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno', 'Default' => ''),
399 'Password' => array('Type' => 'Password', 'Caption' => 'Heslo', 'Default' => ''),
400 'Password2' => array('Type' => 'Password', 'Caption' => 'Potvrzení hesla', 'Default' => ''),
401 'Name' => array('Type' => 'String', 'Caption' => 'Zobrazované jméno', 'Default' => ''),
402 'Email' => array('Type' => 'String', 'Caption' => 'E-mail', 'Default' => ''),
403 'PhoneNumber' => array('Type' => 'String', 'Caption' => 'Telefón', 'Default' => ''),
404 'ICQ' => array('Type' => 'String', 'Caption' => 'ICQ', 'Default' => ''),
405 ),
406 ));
407 $this->System->FormManager->RegisterClass('PasswordRecovery', array(
408 'Title' => 'Obnova hesla',
409 'SubmitText' => 'Obnovit',
410 'Table' => '',
411 'Items' => array(
412 'Name' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno', 'Default' => ''),
413 'Email' => array('Type' => 'String', 'Caption' => 'E-mail', 'Default' => ''),
414 ),
415 ));
416 $this->System->FormManager->RegisterClass('UserLogin', array(
417 'Title' => 'Přihlášení uživatele',
418 'SubmitText' => 'Přihlásit',
419 'Table' => '',
420 'Items' => array(
421 'Username' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno', 'Default' => ''),
422 'Password' => array('Type' => 'Password', 'Caption' => 'Heslo', 'Default' => ''),
423 ),
424 ));
425
426 }
427
428 function Stop()
429 {
430 }
431}
Note: See TracBrowser for help on using the repository browser.