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

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