source: trunk/Modules/FrontPage/FrontPage.php@ 383

Last change on this file since 383 was 383, checked in by chronos, 13 years ago
  • Přidáno: Kostra základního systémového modulu System.
  • Přidáno: Obsluha datových typů pro HTML kód a HTTP protokol.
  • Upraveno: Do ViewList zkopírování generování tabulky se stránkováním a řazením.
File size: 17.5 KB
Line 
1<?php
2
3class IndexPage extends Page
4{
5 var $Dependencies = array('News');
6 var $FullTitle = 'Zděchovský rozcestník';
7 var $ShortTitle = '';
8
9 function ShowLinks($HyperlinkGroup)
10 {
11 $Output = '';
12 $DbResult = $this->Database->query('SELECT * FROM `Hyperlink` WHERE (`Group`='.$HyperlinkGroup['Id'].') AND (`Enable` = 1)');
13 while($HyperLink = $DbResult->fetch_assoc())
14 {
15 if($HyperLink['IconFile'] == '') $HyperLink['IconFile'] = 'clear.png';
16 if(substr($HyperLink['URL'], 0, 4) != 'http') $HyperLink['URL'] = $this->System->Config['Web']['RootFolder'].$HyperLink['URL'];
17 if(($HyperLink['PermissionModule'] == '') or (($HyperLink['PermissionModule'] != '') and $this->System->Modules['User']->Models['User']->CheckPermission($HyperLink['PermissionModule'], $HyperLink['PermissionOperation'])))
18 $Output .= '<img alt="'.$HyperLink['Name'].'" src="images/favicons/'.$HyperLink['IconFile'].'" width="16" height="16" /> <a href="'.$HyperLink['URL'].'">'.$HyperLink['Name'].'</a><br />';
19 }
20 return($this->Panel($HyperlinkGroup['Name'], $Output));
21 }
22
23 function InfoBar()
24 {
25 global $Config;
26
27 $this->Database->select_db($Config['Database']['Database']);
28
29 $Output2 = '';
30
31 $DbResult = $this->Database->query('SELECT COUNT(*) FROM NetworkDevice LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type WHERE NetworkDeviceType.ShowOnline = 1');
32 $DbRow = $DbResult->fetch_array();
33 $TotalComputers = $DbRow[0];
34
35 $DbResult = $this->Database->query('SELECT COUNT(*) FROM NetworkDevice LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type WHERE (NetworkDeviceType.ShowOnline = 1) AND (NetworkDevice.Online = 1)');
36 $DbRow = $DbResult->fetch_array();
37 $OnlineComputers = $DbRow[0];
38
39 $Output = '<img alt="" src="images/favicons/comp.png" width="16" height="16" /> '.$OnlineComputers.' / '.$TotalComputers.' &nbsp; &nbsp; ';
40
41 $DbResult = $this->Database->select('Member', 'COUNT(*)', 'MemberState=0');
42 $DbRow = $DbResult->fetch_array();
43 $TotalUser = $DbRow[0];
44
45 $DbResult = $this->Database->query('SELECT COUNT(DISTINCT(Member)) FROM NetworkDevice LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type 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->Modules['User']->Models['User']->CheckPermission('Finance', 'DisplaySubjectState'))
57 {
58 $DbResult = $this->Database->select('Subject', 'Money', 'Id=(SELECT Subject FROM Member WHERE Id=(SELECT Member FROM User WHERE Id='.$this->System->Modules['User']->Models['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['Money'].' 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->Config['Web']['RootFolder'].'/?Action=UserOptions">Profil</a><br />';
73 if($this->System->Modules['User']->Models['User']->CheckPermission('Finance', 'MemberOptions'))
74 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'?Action=MemberOptions">Domácnost</a><br />';
75 if($this->System->Modules['User']->Models['User']->CheckPermission('Finance', 'DisplaySubjectState'))
76 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/finance/uzivatel/">Finance</a><br />';
77 if($this->System->Modules['User']->Models['User']->CheckPermission('Network', 'RegistredHostList'))
78 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/sit/registrovane-pocitace/">Počítače</a><br />';
79 if($this->System->Modules['User']->Models['User']->CheckPermission('News', 'Insert'))
80 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/aktuality/?action=add">Vložení aktuality</a><br />';
81 if($this->System->Modules['User']->Models['User']->CheckPermission('EatingPlace', 'Edit'))
82 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/jidelna/edit/">Editace jídelníčků</a><br />';
83 if($this->System->Modules['User']->Models['User']->CheckPermission('Finance', 'Manage'))
84 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/finance/sprava/">Správa financí</a><br />';
85 if($this->System->Modules['User']->Models['User']->CheckPermission('Network', 'Administration'))
86 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/sit/sprava/">Správa sítě</a><br />';
87 return($Output);
88 }
89
90 function WebcamPanel()
91 {
92 $Output = $this->System->Modules['WebCam']->ShowImage();
93 return($Output);
94 }
95
96 function OnlineHostList()
97 {
98 $Output = '<span style="font-size: smaller;">';
99 $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');
100 while($Device = $DbResult->fetch_array())
101 {
102 $Output .= $Device['Name'].'<br />';
103 }
104 $Output .= '</span>';
105 return($Output);
106 }
107
108 function ShowBadPayerList()
109 {
110 $Output .= '<div class="PanelTitle">Dlužníci:</div><span style="font-size: smaller;">';
111 $DbResult = $Database->select('Subject', 'Name', 'Money < 0 ORDER BY Money');
112 while($Row = $DbResult->fetch_array())
113 {
114 $Output .= $Row['Name'].'<br />';
115 }
116 $Output .= '</span>';
117 return($Output);
118 }
119
120 function Panel($Title, $Content, $Menu = array())
121 {
122 if(count($Menu) > 0)
123 foreach($Menu as $Item)
124 $Title .= '<div class="Action">'.$Item.'</div>';
125 return('<div class="Panel"><div class="Title">'.$Title.'</div><div class="Content">'.$Content.'</div></div>');
126 }
127
128 function Show()
129 {
130 global $Database, $Config, $User;
131
132 $Output = '';
133 if(array_key_exists('Action', $_GET))
134 {
135 if($_GET['Action'] == 'CustomizeNewsSave')
136 {
137 $Output .= $this->System->Modules['News']->CustomizeSave();
138 } else
139 if($_GET['Action'] == 'LoginForm')
140 {
141 $Form = new UserLoginView($this->Database);
142 $Form->OnSubmit = '?Action=Login';
143 $Output .= $Form->ShowEditForm();
144 $Output .= '<div class="Centred"><a href="?Action=UserRegister">Registrovat se</a> '.
145 '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
146 } else
147 if($_GET['Action'] == 'Login')
148 {
149 $Form = new UserLoginView($this->Database);
150 $Form->OnSubmit = '?Action=Login';
151 $Result = $this->System->Modules['User']->Models['User']->Login($_POST['Username'], $_POST['Password']);
152 $Output .= $this->SystemMessage('Přihlášení', $Result);
153 if($Result <> USER_LOGGED_IN)
154 {
155 $Form->LoadValuesFromForm();
156 $Form->Values['Password'] = '';
157 $Output .= $Form->ShowEditForm();
158 $Output .= '<div class="Centred"><a href="?Action=UserRegister">Registrovat se</a> '.
159 '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
160 }
161 } else
162 if($_GET['Action'] == 'Logout')
163 {
164 $Output .= $this->SystemMessage('Odhlášení', $this->System->Modules['User']->Models['User']->Logout());
165 } else
166 if($_GET['Action'] == 'UserOptions')
167 {
168 $UserOptions = new UserOptionsView($this->Database);
169 $UserOptions->LoadValuesFromDatabase($this->System->Modules['User']->Models['User']->User['Id']);
170 $UserOptions->OnSubmit = '?Action=UserOptionsSave';
171 $Output .= $UserOptions->ShowEditForm();
172 } else
173 if($_GET['Action'] == 'UserOptionsSave')
174 {
175 $UserOptions = new UserOptionsView($this->Dstabase, array());
176 $UserOptions->LoadValuesFromForm();
177 $UserOptions->SaveValuesToDatabase($this->System->Modules['User']->Models['User']->User['Id']);
178 $Output .= $this->SystemMessage('Nastavení', 'Nastavení uloženo.');
179 $this->System->Modules['Log']->NewRecord('User', 'Nastavení uživatele změněno', $UserOptions->Values['Name']);
180 $UserOptions->LoadValuesFromDatabase($this->System->Modules['User']->Models['User']->User['Id']);
181 $UserOptions->OnSubmit = '?Action=UserOptionsSave';
182 $Output .= $UserOptions->ShowEditForm();
183 }
184 if($_GET['Action'] == 'UserRegister')
185 {
186 $Form = new UserRegisterView($this->Database);
187 $Form->LoadValuesFromForm();
188 $Form->OnSubmit = '?Action=UserRegisterSave';
189 $Output .= $Form->ShowEditForm();
190 } else
191 if($_GET['Action'] == 'UserRegisterConfirm')
192 {
193 $Output .= $this->SystemMessage('Potvrzení registrace', $this->System->Modules['User']->Models['User']->RegisterConfirm($_GET['User'], $_GET['H']));
194 } else
195 if($_GET['Action'] == 'PasswordRecovery')
196 {
197 $Form = new PasswordRecoveryView($this->Database);
198 $Form->OnSubmit = '?Action=PasswordRecovery2';
199 $Output .= $Form->ShowEditForm();
200 } else
201 if($_GET['Action'] == 'PasswordRecovery2')
202 {
203 $Form = new PasswordRecoveryView($this->Database);
204 $Form->LoadValuesFromForm();
205 $Result = $this->System->Modules['User']->Models['User']->PasswordRecoveryRequest($Form->Values['Name'], $Form->Values['Email']);
206 $Output .= $this->SystemMessage('Obnova hesla', $Result);
207 if($Result <> USER_PASSWORD_RECOVERY_SUCCESS)
208 {
209 $Output .= $Form->ShowEditForm();
210 }
211 } else
212 if($_GET['Action'] == 'PasswordRecoveryConfirm')
213 {
214 $Output .= $this->SystemMessage('Obnova hesla', $this->System->Modules['User']->Models['User']->PasswordRecoveryConfirm($_GET['User'], $_GET['H'], $_GET['P']));
215 } else
216 if($_GET['Action'] == 'UserRegisterSave')
217 {
218 $Form = new UserRegisterView($this->Database, array());
219 $Form->LoadValuesFromForm();
220 $Result = $this->System->Modules['User']->Models['User']->Register($Form->Values['Login'], $Form->Values['Password'], $Form->Values['Password2'], $Form->Values['Email'], $Form->Values['Name'], $Form->Values['PhoneNumber'], $Form->Values['ICQ']);
221 $Output .= $this->SystemMessage('Registrace nového účtu', $Result);
222 if($Result <> USER_REGISTRATED)
223 {
224 $Form->OnSubmit = '?Action=UserRegisterSave';
225 $Output .= $Form->ShowEditForm();
226 }
227 } else
228 if($_GET['Action'] == 'MemberOptions')
229 {
230 $UserOptions = new MemberOptionsView($this->Database);
231 $DbResult = $this->Database->query('SELECT Member.Id, Member.InternetTariffNextMonth, Member.FamilyMemberCount, Member.BillingPeriodNext, Subject.Name, Subject.AddressStreet, Subject.AddressTown, Subject.AddressPSC, Subject.IC, Subject.DIC FROM Member JOIN Subject ON Subject.Id = Member.Subject WHERE Member.Id='.$this->System->Modules['User']->Models['User']->User['Member']);
232 $DbRow = $DbResult->fetch_array();
233 foreach($UserOptions->Items as $Index => $Item)
234 {
235 $UserOptions->Values[$Index] = $DbRow[$Index];
236 }
237 $UserOptions->OnSubmit = '?Action=MemberOptionsSave';
238 $Output .= $UserOptions->ShowEditForm();
239 } else
240 if($_GET['Action'] == 'MemberOptionsSave')
241 {
242 $UserOptions = new MemberOptionsView($this->Database);
243 $UserOptions->LoadValuesFromForm();
244 if($UserOptions->Values['FamilyMemberCount'] < 0)
245 $UserOptions->Values['FamilyMemberCount'] = 0;
246 if($UserOptions->Values['BillingPeriodNext'] < 2)
247 $UserOptions->Values['BillingPeriodNext'] = 2;
248
249 $DbResult = $this->Database->update('Member', 'Id='.$this->System->Modules['User']->Models['User']->User['Member'], array('InternetTariffNextMonth' => $UserOptions->Values['InternetTariffNextMonth'], 'FamilyMemberCount' => $UserOptions->Values['FamilyMemberCount'], 'BillingPeriodNext' => $UserOptions->Values['BillingPeriodNext']));
250 $DbResult = $this->Database->query('SELECT Subject FROM Member WHERE Id='.$this->System->Modules['User']->Models['User']->User['Member']);
251 $Member = $DbResult->fetch_assoc();
252 $DbResult = $this->Database->update('Subject', 'Id='.$Member['Subject'], array('Name' => $UserOptions->Values['Name'], 'AddressStreet' => $UserOptions->Values['AddressStreet'], 'AddressTown' => $UserOptions->Values['AddressTown'], 'AddressPSC' => $UserOptions->Values['AddressPSC'], 'IC' => $UserOptions->Values['IC'], 'DIC' => $UserOptions->Values['DIC']));
253 $Output .= $this->SystemMessage('Nastavení', 'Nastavení domácnosti uloženo.');
254 $this->System->Modules['Log']->NewRecord('Member+Subject', 'Nastavení člena/subjektu změněno', $UserOptions->Values['Name']);
255 $DbResult = $this->Database->query('SELECT Member.Id, Member.InternetTariffNextMonth, Member.FamilyMemberCount, Member.BillingPeriodNext, Subject.Name, Subject.AddressStreet, Subject.AddressTown, Subject.AddressPSC, Subject.IC, Subject.DIC FROM Member JOIN Subject ON Subject.Id = Member.Subject WHERE Member.Id='.$this->System->Modules['User']->Models['User']->User['Member']);
256 $DbRow = $DbResult->fetch_array();
257 foreach($UserOptions->Items as $Index => $Item)
258 {
259 $UserOptions->Values[$Index] = $DbRow[$Index];
260 }
261 $UserOptions->OnSubmit = '?Action=MemberOptionsSave';
262 $Output .= $UserOptions->ShowEditForm();
263 }
264 }
265
266 $Database->select_db($Config['Database']['Database']);
267
268 $DbResult = $Database->query('SELECT * FROM `HyperlinkGroup`');
269 while($DbRow = $DbResult->fetch_assoc())
270 $HyperlinkGroups[$DbRow['Id']] = $DbRow;
271
272
273 // Show pannels
274 //if(IsInternetAddr()) echo('Internet'); else echo('LAN');
275 //$Output .= $this->InfoBar();
276 $Output .= '<table id="MainTable"><tr>';
277 $DbResult = $this->Database->select('PanelColumn', '*');
278 while($PanelColumn = $DbResult->fetch_assoc())
279 {
280 if($PanelColumn != '') $Width = ' width="'.$PanelColumn['Width'].'"';
281 else $Width = '';
282 $Output .= '<td valign="top"'.$Width.'>';
283 $DbResult2 = $Database->query('SELECT * FROM `Panel` WHERE `PanelColumn`='.$PanelColumn['Id'].' ORDER BY `Order`');
284 while($Panel = $DbResult2->fetch_assoc())
285 {
286 if($Panel['Module'] == 'HyperlinkGroup') $Output .= $this->ShowLinks($HyperlinkGroups[$Panel['Parameters']]);
287 else if($Panel['Module'] == 'OnlineHostList') $Output .= $this->Panel('Online počítače', $this->OnlineHostList());
288 else if($Panel['Module'] == 'UserOptions')
289 {
290 if($this->System->Modules['User']->Models['User']->User['Id'] != $this->System->Modules['User']->Models['User']->AnonymousUserId)
291 $Output .= $this->Panel('Přihlášený uživatel', $this->UserPanel());
292 } else
293 if(($Panel['Module'] == 'Webcam') and (array_key_exists('WebCam', $this->System->Modules)))
294 $Output .= $this->Panel('Kamery', $this->WebcamPanel());
295 else if($Panel['Module'] == 'NewsGroupList') $Output .= $this->Panel('Aktuality', $this->System->Modules['News']->Show(), array('<a href="?Action=CustomizeNews">Upravit</a>'));
296 }
297 $Output .= '</td>';
298 }
299 $Output .= '</table>';
300 return($Output);
301 }
302}
303
304class Hyperlink extends Model
305{
306 function __construct($Database, $System)
307 {
308 parent::__construct($Database, $System);
309 $this->Name = 'Hyperlink';
310 $this->AddPropertyString('Name');
311 $this->AddPropertyString('URL');
312 $this->AddPropertyOneToMany('Group', 'HyperlinkGroup');
313 $this->AddPropertyString('IconFile');
314 $this->AddPropertyString('PermissionModule');
315 $this->AddPropertyString('PermissionOperation');
316 $this->AddPropertyBoolean('Enable');
317 }
318}
319
320class HyperlinkGroup extends Model
321{
322 function __construct($Database, $System)
323 {
324 parent::__construct($Database, $System);
325 $this->Name = 'HyperlinkGroup';
326 $this->AddPropertyString('Name');
327 }
328}
329
330class Panel extends Model
331{
332 function __construct($Database, $System)
333 {
334 parent::__construct($Database, $System);
335 $this->Name = 'Panel';
336 $this->AddPropertyString('Module');
337 $this->AddPropertyString('Parameters');
338 $this->AddPropertyInteger('Order');
339 $this->AddPropertyOneToMany('PanelColumn', 'PanelColumn');
340 }
341}
342
343class PanelColumn extends Model
344{
345 function __construct($Database, $System)
346 {
347 parent::__construct($Database, $System);
348 $this->Name = 'PanelColumn';
349 $this->AddPropertyString('Width');
350 }
351}
352
353class ModuleFrontPage extends Module
354{
355 function __construct($Database, $System)
356 {
357 parent::__construct($Database, $System);
358 $this->Name = 'FrontPage';
359 $this->Version = '1.0';
360 $this->Creator = 'Chronos';
361 $this->License = 'GNU/GPL';
362 $this->Description = 'Main page of community network portal';
363 $this->Dependencies = array('User', 'News', 'TV', 'Map', 'Chat', 'WebCam');
364 $this->SupportedModels = array('Hyperlink', 'HyperlinkGroup', 'Panel', 'PanelColumn');
365 }
366
367 function Init()
368 {
369 $this->System->Pages[''] = 'IndexPage';
370 }
371
372 function Install()
373 {
374 parent::Install();
375 }
376
377 function UnInstall()
378 {
379 parent::UnInstall();
380 }
381}
382
383?>
Note: See TracBrowser for help on using the repository browser.