source: trunk/index.php@ 304

Last change on this file since 304 was 304, checked in by george, 14 years ago
  • Upraveno: Řazení sloupců a stránkování ve zobrazení seznamu podsítí.
  • Property svn:executable set to *
File size: 15.8 KB
Line 
1<?php
2
3include_once('global.php');
4
5class IndexPage extends Page
6{
7 var $Dependencies = array('News');
8 var $FullTitle = '<strong>ZděchovNET</strong> - komunitní počítačová síť';
9 var $ShortTitle = 'Rozcestník';
10
11 function ShowLinks($GroupId)
12 {
13 global $Database;
14
15 $DbResult = $Database->query('SELECT * FROM `HyperlinkGroup` WHERE `Id`='.$GroupId);
16 $HyperlinkGroup = $DbResult->fetch_assoc();
17
18 $Output = '';
19 $DbResult = $Database->query('SELECT * FROM `Hyperlink` WHERE (`Group`='.$GroupId.') AND (`Enable` = 1)');
20 while($HyperLink = $DbResult->fetch_assoc())
21 {
22 if($HyperLink['IconFile'] == '') $HyperLink['IconFile'] = 'clear.png';
23 if(substr($HyperLink['URL'], 0, 4) != 'http') $HyperLink['URL'] = $this->System->Config['Web']['RootFolder'].$HyperLink['URL'];
24 if(($HyperLink['PermissionModule'] == '') or (($HyperLink['PermissionModule'] != '') and $this->System->Modules['User']->CheckPermission($HyperLink['PermissionModule'], $HyperLink['PermissionOperation'])))
25 $Output .= '<img alt="'.$HyperLink['Name'].'" src="images/favicons/'.$HyperLink['IconFile'].'" width="16" height="16" /> <a href="'.$HyperLink['URL'].'">'.$HyperLink['Name'].'</a><br />';
26 }
27 return($this->Panel($HyperlinkGroup['Name'], $Output));
28 }
29
30 function InfoBar()
31 {
32 global $Config;
33
34 $this->Database->select_db($Config['Database']['Database']);
35
36 $Output2 = '';
37
38 $DbResult = $this->Database->query('SELECT COUNT(*) FROM NetworkDevice LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type WHERE NetworkDeviceType.ShowOnline = 1');
39 $DbRow = $DbResult->fetch_array();
40 $TotalComputers = $DbRow[0];
41
42 $DbResult = $this->Database->query('SELECT COUNT(*) FROM NetworkDevice LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type WHERE (NetworkDeviceType.ShowOnline = 1) AND (NetworkDevice.Online = 1)');
43 $DbRow = $DbResult->fetch_array();
44 $OnlineComputers = $DbRow[0];
45
46 $Output = '<img alt="" src="images/favicons/comp.png" width="16" height="16" /> '.$OnlineComputers.' / '.$TotalComputers.' &nbsp; &nbsp; ';
47
48 $DbResult = $this->Database->select('Member', 'COUNT(*)', 'MemberState=0');
49 $DbRow = $DbResult->fetch_array();
50 $TotalUser = $DbRow[0];
51
52 $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');
53 $DbRow = $DbResult->fetch_array();
54 $OnlineUser = $DbRow[0];
55
56 $Output .= '<img alt="" src="images/favicons/house.png" width="16" height="16" /> '.$OnlineUser.' / '.$TotalUser.' &nbsp; &nbsp; ';
57
58 $NetworkUsage = 0;
59 $Output .= '<img alt="" src="images/favicons/usage.png" width="16" height="16" /> '.$NetworkUsage.' % &nbsp; &nbsp; ';
60
61 //$Output .= 'Server běží: '.$this->GetServerUptime().' &nbsp; &nbsp; ';
62
63 if($this->System->Modules['User']->CheckPermission('Finance', 'DisplaySubjectState'))
64 {
65 $DbResult = $this->Database->select('Subject', 'Money', 'Id=(SELECT Subject FROM Member WHERE Id=(SELECT Member FROM User WHERE Id='.$this->System->Modules['User']->User['Id'].'))');
66 if($DbResult->num_rows > 0)
67 {
68 $DbRow = $DbResult->fetch_assoc();
69 $Output2 .= ' &nbsp; &nbsp; <img alt="" src="images/favicons/money.png" width="16" height="16" /> '.$DbRow['Money'].' Kč';
70 }
71 }
72
73 $Output = '<div class="Navigation"><span class="MenuItem">'.$Output.'</span><div class="MenuItem2">&nbsp;'.$Output2.'</div></div>';
74 return($Output);
75 }
76
77 function UserPanel()
78 {
79 $Output = '<a href="'.$this->System->Config['Web']['RootFolder'].'/?Action=UserOptions">Profil</a><br />';
80 if($this->System->Modules['User']->CheckPermission('Finance', 'MemberOptions'))
81 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'?Action=MemberOptions">Domácnost</a><br />';
82 if($this->System->Modules['User']->CheckPermission('Finance', 'DisplaySubjectState'))
83 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/finance/user_state.php">Finance</a><br />';
84 if($this->System->Modules['User']->CheckPermission('Network', 'RegistredHostList'))
85 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/network/user_hosts.php">Počítače</a><br />';
86 if($this->System->Modules['User']->CheckPermission('News', 'Insert'))
87 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/aktuality/?action=add">Vložení aktuality</a><br />';
88 if($this->System->Modules['User']->CheckPermission('EatingPlace', 'Edit'))
89 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/jidelna/menuedit.php">Editace jídelníčků</a><br />';
90 if($this->System->Modules['User']->CheckPermission('Finance', 'Manage'))
91 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/finance/manage.php">Správa financí</a><br />';
92 if($this->System->Modules['User']->CheckPermission('Network', 'Administration'))
93 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/network/administration.php">Správa sítě</a><br />';
94 return($Output);
95 }
96
97 function WebcamPanel()
98 {
99 $Output = $this->System->Modules['Webcam']->ShowImage();
100 return($Output);
101 }
102
103 function OnlineHostList()
104 {
105 $Output = '<span style="font-size: smaller;">';
106 $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');
107 while($Device = $DbResult->fetch_array())
108 {
109 $Output .= $Device['Name'].'<br />';
110 }
111 $Output .= '</span>';
112 return($Output);
113 }
114
115 function ShowBadPayerList()
116 {
117 $Output .= '<div class="PanelTitle">Dlužníci:</div><span style="font-size: smaller;">';
118 $DbResult = $Database->select('Subject', 'Name', 'Money < 0 ORDER BY Money');
119 while($Row = $DbResult->fetch_array())
120 {
121 $Output .= $Row['Name'].'<br />';
122 }
123 $Output .= '</span>';
124 return($Output);
125 }
126
127 function GetServerUptime()
128 {
129 $Data = explode(' ', exec('uptime'));
130 $Data = array_slice($Data, 3, -8);
131 $Uptime = '';
132 foreach($Data as $Item)
133 {
134 if(strpos($Item, ':')) $Uptime .= substr($Item, 0, -1).' hodin';
135 else $Uptime .= $Item.' ';
136 }
137 $Uptime = str_replace('2 days,', '2 dny a', $Uptime);
138 $Uptime = str_replace('3 days,', '3 dny a', $Uptime);
139 $Uptime = str_replace('4 days,', '4 dny a', $Uptime);
140 $Uptime = str_replace('days,', 'dní a', $Uptime);
141 $Uptime = str_replace('day,', 'den a', $Uptime);
142 $Uptime = str_replace('min,', 'minut', $Uptime);
143 return($Uptime);
144 }
145
146 function Panel($Title, $Content, $Menu = array())
147 {
148 if(count($Menu) > 0)
149 foreach($Menu as $Item)
150 $Title .= '<div class="Action">'.$Item.'</div>';
151 return('<div class="Panel"><div class="Title">'.$Title.'</div><div class="Content">'.$Content.'</div></div>');
152 }
153
154 function Show()
155 {
156 global $Database, $Config, $User;
157
158 $Output = '';
159 if(array_key_exists('Action', $_GET))
160 {
161 if($_GET['Action'] == 'CustomizeNewsSave')
162 {
163 $Output .= $this->System->Modules['News']->CustomizeSave();
164 } else
165 if($_GET['Action'] == 'LoginForm')
166 {
167 $Form = new Form('UserLogin');
168 $Form->OnSubmit = '?Action=Login';
169 $Output .= $Form->ShowEditForm();
170 $Output .= '<div class="Centred"><a href="?Action=UserRegister">Registrovat se</a> '.
171 '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
172 } else
173 if($_GET['Action'] == 'Login')
174 {
175 $Form = new Form('UserLogin');
176 $Form->OnSubmit = '?Action=Login';
177 $Result = $this->System->Modules['User']->Login($_POST['Username'], $_POST['Password']);
178 $Output .= $this->SystemMessage('Přihlášení', $Result);
179 if($Result <> USER_LOGGED_IN)
180 {
181 $Form->LoadValuesFromForm();
182 $Form->Values['Password'] = '';
183 $Output .= $Form->ShowEditForm();
184 $Output .= '<div class="Centred"><a href="?Action=UserRegister">Registrovat se</a> '.
185 '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
186 }
187 } else
188 if($_GET['Action'] == 'Logout')
189 {
190 $Output .= $this->SystemMessage('Odhlášení', $this->System->Modules['User']->Logout());
191 } else
192 if($_GET['Action'] == 'UserOptions')
193 {
194 $UserOptions = new Form('UserOptions');
195 $UserOptions->LoadValuesFromDatabase($this->System->Modules['User']->User['Id']);
196 $UserOptions->OnSubmit = '?Action=UserOptionsSave';
197 $Output .= $UserOptions->ShowEditForm();
198 } else
199 if($_GET['Action'] == 'UserOptionsSave')
200 {
201 $UserOptions = new Form('UserOptions', array());
202 $UserOptions->LoadValuesFromForm();
203 $UserOptions->SaveValuesToDatabase($this->System->Modules['User']->User['Id']);
204 $Output .= $this->SystemMessage('Nastavení', 'Nastavení uloženo.');
205 $this->System->Modules['Log']->NewRecord('User', 'Nastavení uživatele změněno', $UserOptions->Values['Name']);
206 $UserOptions->LoadValuesFromDatabase($this->System->Modules['User']->User['Id']);
207 $UserOptions->OnSubmit = '?Action=UserOptionsSave';
208 $Output .= $UserOptions->ShowEditForm();
209 }
210 if($_GET['Action'] == 'UserRegister')
211 {
212 $Form = new Form('UserRegister');
213 $Form->LoadValuesFromForm();
214 $Form->OnSubmit = '?Action=UserRegisterSave';
215 $Output .= $Form->ShowEditForm();
216 } else
217 if($_GET['Action'] == 'UserRegisterConfirm')
218 {
219 $Output .= $this->SystemMessage('Potvrzení registrace', $this->System->Modules['User']->RegisterConfirm($_GET['User'], $_GET['H']));
220 } else
221 if($_GET['Action'] == 'PasswordRecovery')
222 {
223 $Form = new Form('PasswordRecovery');
224 $Form->OnSubmit = '?Action=PasswordRecovery2';
225 $Output .= $Form->ShowEditForm();
226 } else
227 if($_GET['Action'] == 'PasswordRecovery2')
228 {
229 $Form = new Form('PasswordRecovery');
230 $Form->LoadValuesFromForm();
231 $Result = $this->System->Modules['User']->PasswordRecoveryRequest($Form->Values['Name'], $Form->Values['Email']);
232 $Output .= $this->SystemMessage('Obnova hesla', $Result);
233 if($Result <> USER_PASSWORD_RECOVERY_SUCCESS)
234 {
235 $Output .= $Form->ShowEditForm();
236 }
237 } else
238 if($_GET['Action'] == 'PasswordRecoveryConfirm')
239 {
240 $Output .= $this->SystemMessage('Obnova hesla', $this->System->Modules['User']->PasswordRecoveryConfirm($_GET['User'], $_GET['H'], $_GET['P']));
241 } else
242 if($_GET['Action'] == 'UserRegisterSave')
243 {
244 $Form = new Form('UserRegister', array());
245 $Form->LoadValuesFromForm();
246 $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']);
247 $Output .= $this->SystemMessage('Registrace nového účtu', $Result);
248 if($Result <> USER_REGISTRATED)
249 {
250 $Form->OnSubmit = '?Action=UserRegisterSave';
251 $Output .= $Form->ShowEditForm();
252 }
253 } else
254 if($_GET['Action'] == 'MemberOptions')
255 {
256 $UserOptions = new Form('MemberOptions');
257 $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']->User['Member']);
258 $DbRow = $DbResult->fetch_array();
259 foreach($UserOptions->Definition['Items'] as $Index => $Item)
260 {
261 $UserOptions->Values[$Index] = $DbRow[$Index];
262 }
263 $UserOptions->OnSubmit = '?Action=MemberOptionsSave';
264 $Output .= $UserOptions->ShowEditForm();
265 } else
266 if($_GET['Action'] == 'MemberOptionsSave')
267 {
268 $UserOptions = new Form('MemberOptions');
269 $UserOptions->LoadValuesFromForm();
270 if($UserOptions->Values['FamilyMemberCount'] < 0)
271 $UserOptions->Values['FamilyMemberCount'] = 0;
272 if($UserOptions->Values['BillingPeriodNext'] < 2)
273 $UserOptions->Values['BillingPeriodNext'] = 2;
274
275 $DbResult = $this->Database->update('Member', 'Id='.$this->System->Modules['User']->User['Member'], array('InternetTariffNextMonth' => $UserOptions->Values['InternetTariffNextMonth'], 'FamilyMemberCount' => $UserOptions->Values['FamilyMemberCount'], 'BillingPeriodNext' => $UserOptions->Values['BillingPeriodNext']));
276 $DbResult = $this->Database->query('SELECT Subject FROM Member WHERE Id='.$this->System->Modules['User']->User['Member']);
277 $Member = $DbResult->fetch_assoc();
278 $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']));
279 $Output .= $this->SystemMessage('Nastavení', 'Nastavení domácnosti uloženo.');
280 $this->System->Modules['Log']->NewRecord('Member+Subject', 'Nastavení člena/subjektu změněno', $UserOptions->Values['Name']);
281 $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']->User['Member']);
282 $DbRow = $DbResult->fetch_array();
283 foreach($UserOptions->Definition['Items'] as $Index => $Item)
284 {
285 $UserOptions->Values[$Index] = $DbRow[$Index];
286 }
287 $UserOptions->OnSubmit = '?Action=MemberOptionsSave';
288 $Output .= $UserOptions->ShowEditForm();
289 }
290 }
291
292 $Database->select_db($Config['Database']['Database']);
293
294 // Show pannels
295 //if(IsInternetAddr()) echo('Internet'); else echo('LAN');
296 //$Output .= $this->InfoBar();
297 $Output .= '<table id="MainTable"><tr>';
298 $DbResult = $Database->select('PanelColumn', '*');
299 while($PanelColumn = $DbResult->fetch_assoc())
300 {
301 if($PanelColumn != '') $Width = ' width="'.$PanelColumn['Width'].'"';
302 else $Width = '';
303 $Output .= '<td valign="top"'.$Width.'>';
304 $DbResult2 = $Database->query('SELECT * FROM `Panel` WHERE `PanelColumn`='.$PanelColumn['Id'].' ORDER BY `Order`');
305 while($Panel = $DbResult2->fetch_assoc())
306 {
307 if($Panel['Module'] == 'HyperlinkGroup') $Output .= $this->ShowLinks($Panel['Parameters']);
308 else if($Panel['Module'] == 'OnlineHostList') $Output .= $this->Panel('Online počítače', $this->OnlineHostList());
309 else if($Panel['Module'] == 'UserOptions')
310 {
311 if($this->System->Modules['User']->User['Id'] != $this->System->Modules['User']->AnonymousUserId) $Output .= $this->Panel('Přihlášený uživatel', $this->UserPanel());
312 } else
313 if($Panel['Module'] == 'Webcam') $Output .= $this->Panel('Kamery', $this->WebcamPanel());
314 else if($Panel['Module'] == 'NewsGroupList') $Output .= $this->Panel('Aktuality', $this->System->Modules['News']->Show(), array('<a href="?Action=CustomizeNews">Upravit</a>'));
315 }
316 $Output .= '</td>';
317 }
318 $Output .= '</table>';
319 return($Output);
320 }
321}
322
323$System->AddModule(new IndexPage());
324$System->Modules['IndexPage']->GetOutput();
325
326?>
Note: See TracBrowser for help on using the repository browser.