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