Name = 'Portal'; $this->Version = '1.0'; $this->Creator = 'Chronos'; $this->License = 'GNU/GPLv3'; $this->Description = 'Community portal.'; $this->Dependencies = array(ModuleNews::GetName(), ModuleUser::GetName()); $this->Models = array(Panel::GetClassName(), PanelColumn::GetClassName()); } function DoInsertSampleData(): void { $ActionGroup1 = $this->Database->insert('ActionGroup', array('Name' => 'Síť')); $ActionGroup2 = $this->Database->insert('ActionGroup', array('Name' => 'Místní organizace')); $ActionGroup3 = $this->Database->insert('ActionGroup', array('Name' => 'Stránky občanů')); $ActionGroup4 = $this->Database->insert('ActionGroup', array('Name' => 'Vyhledávání')); $ActionGroup5 = $this->Database->insert('ActionGroup', array('Name' => 'Užitečné')); $ActionGroup6 = $this->Database->insert('ActionGroup', array('Name' => 'Zábava')); $ActionGroup7 = $this->Database->insert('ActionGroup', array('Name' => 'Hostované stránky')); $ActionGroup8 = $this->Database->insert('ActionGroup', array('Name' => 'Prodej počítačů')); $ActionGroup9 = $this->Database->insert('ActionGroup', array('Name' => 'Různé')); $PanelColumn1 = $this->Database->insert('PanelColumn', array('Width' => '')); $PanelColumn2 = $this->Database->insert('PanelColumn', array('Width' => '')); $PanelColumn3 = $this->Database->insert('PanelColumn', array('Width' => '70%')); $this->Database->insert('Panel', array('Module' => 'ActionGroup', 'Parameters' => $ActionGroup1, 'Order' => 2, 'PanelColumn' => $PanelColumn1)); $this->Database->insert('Panel', array('Module' => 'ActionGroup', 'Parameters' => $ActionGroup4, 'Order' => 1, 'PanelColumn' => $PanelColumn2)); $this->Database->insert('Panel', array('Module' => 'ActionGroup', 'Parameters' => $ActionGroup5, 'Order' => 2, 'PanelColumn' => $PanelColumn2)); $this->Database->insert('Panel', array('Module' => 'ActionGroup', 'Parameters' => $ActionGroup6, 'Order' => 3, 'PanelColumn' => $PanelColumn2)); $this->Database->insert('Panel', array('Module' => 'ActionGroup', 'Parameters' => $ActionGroup2, 'Order' => 4, 'PanelColumn' => $PanelColumn2)); $this->Database->insert('Panel', array('Module' => 'ActionGroup', 'Parameters' => $ActionGroup3, 'Order' => 5, 'PanelColumn' => $PanelColumn2)); $this->Database->insert('Panel', array('Module' => 'NewsGroupList', 'Parameters' => '', 'Order' => 2, 'PanelColumn' => $PanelColumn3)); $this->Database->insert('Panel', array('Module' => 'Webcam', 'Parameters' => '', 'Order' => 3, 'PanelColumn' => $PanelColumn1)); $this->Database->insert('Panel', array('Module' => 'UserOptions', 'Parameters' => '', 'Order' => 1, 'PanelColumn' => $PanelColumn3)); $this->Database->insert('Panel', array('Module' => 'ActionGroup', 'Parameters' => $ActionGroup9, 'Order' => 1, 'PanelColumn' => $PanelColumn1)); $this->Database->insert('Panel', array('Module' => 'Meteo', 'Parameters' => '', 'Order' => 4, 'PanelColumn' => $PanelColumn1)); } function DoStart(): void { Core::Cast($this->System)->RegisterPage([''], 'PagePortal'); $this->System->FormManager->RegisterClass('MemberOptions', array( 'Title' => 'Nastavení zákazníka', 'SQL' => '(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)', 'Table' => 'MemberOptions', 'Items' => array( 'Name' => array('Type' => 'String', 'Caption' => 'Fakturační jméno', 'Default' => ''), 'AddressStreet' => array('Type' => 'String', 'Caption' => 'Ulice', 'Default' => 'Zděchov'), 'AddressTown' => array('Type' => 'String', 'Caption' => 'Město', 'Default' => 'Zděchov'), 'AddressPSC' => array('Type' => 'String', 'Caption' => 'PSČ', 'Default' => '75607'), 'AddressCountry' => array('Type' => 'TCountry', 'Caption' => 'Země', 'Default' => '1'), 'IC' => array('Type' => 'String', 'Caption' => 'IČ', 'Default' => ''), 'DIC' => array('Type' => 'String', 'Caption' => 'DIČ', 'Default' => ''), 'FamilyMemberCount' => array('Type' => 'Integer', 'Caption' => 'Počet bydlících osob', 'Default' => '', 'Suffix' => 'osob'), ), )); ModuleUser::Cast(Core::Cast($this->System)->GetModule('User'))->UserPanel[] = array('PagePortal', 'UserPanel'); } } class PanelColumn extends Model { static function GetModelDesc(): ModelDesc { $Desc = new ModelDesc(self::GetClassName()); $Desc->AddString('Width'); return $Desc; } } class Panel extends Model { static function GetModelDesc(): ModelDesc { $Desc = new ModelDesc(self::GetClassName()); $Desc->AddString('Module'); $Desc->AddString('Parameters'); $Desc->AddInteger('Order'); $Desc->AddInteger('PanelColumn'); return $Desc; } } class PagePortal extends Page { function __construct(System $System) { parent::__construct($System); $this->Title = 'Rozcestník'; $this->Description = 'Zděchovský rozcestník'; } function ShowActions(array $ActionGroup): string { $Output = ''; $DbResult = $this->Database->query('SELECT `Id` FROM `Action` '. 'WHERE (`Action`.`Group`='.$ActionGroup['Id'].') AND (`Action`.`Enable` = 1)'); while ($Action = $DbResult->fetch_assoc()) { $Output .= ModuleSystem::Cast($this->System->GetModule('System'))->ShowAction($Action['Id']).'
'; } return $this->Panel($ActionGroup['Name'], $Output); } function InfoBar(): string { $Output2 = ''; $DbResult = $this->Database->query('SELECT COUNT(*) FROM NetworkDevice LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type WHERE NetworkDeviceType.ShowOnline = 1'); $DbRow = $DbResult->fetch_array(); $TotalComputers = $DbRow[0]; $DbResult = $this->Database->query('SELECT COUNT(*) FROM NetworkDevice LEFT JOIN NetworkDeviceType ON NetworkDeviceType.Id = NetworkDevice.Type WHERE (NetworkDeviceType.ShowOnline = 1) AND (NetworkDevice.Online = 1)'); $DbRow = $DbResult->fetch_array(); $OnlineComputers = $DbRow[0]; $Output = ' '.$OnlineComputers.' / '.$TotalComputers.'     '; $DbResult = $this->Database->select('Member', 'COUNT(*)', '1'); $DbRow = $DbResult->fetch_array(); $TotalUser = $DbRow[0]; $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'); $DbRow = $DbResult->fetch_array(); $OnlineUser = $DbRow[0]; $Output .= ' '.$OnlineUser.' / '.$TotalUser.'     '; $NetworkUsage = 0; $Output .= ' '.$NetworkUsage.' %     '; //$Output .= 'Server běží: '.$this->GetServerUptime().'     '; if (ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('Finance', 'DisplaySubjectState')) { $DbResult = $this->Database->select('MemberPayment', 'Cash', 'Member=(SELECT Customer FROM UserCustomerRel WHERE Id='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].')'); if ($DbResult->num_rows > 0) { $DbRow = $DbResult->fetch_assoc(); $Output2 .= '     '.$DbRow['Cash'].' Kč'; } } $Output = ''; return $Output; } function UserPanel(): string { $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = 'Profil
'; if ($User->CheckPermission('Finance', 'MemberOptions')) $Output .= 'Fakturační adresa
'; if ($User->CheckPermission('Finance', 'DisplaySubjectState')) $Output .= 'Finance
'; if ($User->CheckPermission('Customer', 'DisplayCustomerDocuments')) $Output .= 'Dokumenty
'; if ($User->CheckPermission('Network', 'RegistredHostList')) $Output .= 'Počítače
'; if ($User->CheckPermission('News', 'Insert')) $Output .= 'Vložení aktuality
'; if ($User->CheckPermission('EatingPlace', 'Edit')) $Output .= 'Úprava jídelníčků
'; if ($User->CheckPermission('Finance', 'Manage')) $Output .= 'Správa financí
'; if ($User->CheckPermission('IS', 'Manage')) $Output .= 'Správa dat
'; return $Output; } function WebcamPanel(): string { $Output = ModuleWebCam::Cast($this->System->GetModule('WebCam'))->ShowImage(); return $Output; } function MeteoPanel(): string { $Output = 'Počasí - Meteostanice Zděchov'; return $Output; } function OnlineHostList(): string { $Output = ''; $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`'); while ($Device = $DbResult->fetch_array()) { $Output .= $Device['Name'].'
'; } $Output .= '
'; return $Output; } function ShowBadPayerList(): string { $Output = '
Dlužníci:
'; $DbResult = $this->Database->select('Subject', 'Name', 'Money < 0 ORDER BY Money'); while ($Row = $DbResult->fetch_array()) { $Output .= $Row['Name'].'
'; } $Output .= '
'; return $Output; } function Panel(string $Title, string $Content, array $Menu = array()): string { if (count($Menu) > 0) { foreach ($Menu as $Item) { $Title .= '
'.$Item.'
'; } } return '
'.$Title.'
'.$Content.'
'; } function Show(): string { $Output = ''; if (array_key_exists('Action', $_GET)) { $Action = $_GET['Action']; if ($Action == 'CustomizeNewsSave') { $Output .= ModuleNews::Cast($this->System->GetModule('News'))->CustomizeSave(); } else if ($Action == 'MemberOptions') { $DbResult = $this->Database->query('SELECT `Customer` FROM `UserCustomerRel` '. 'WHERE `User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id']); while ($CustomerUserRel = $DbResult->fetch_assoc()) { $DbResult2 = $this->Database->query('SELECT `Member`.`Id`, '. '`Member`.`FamilyMemberCount`, `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`='.$CustomerUserRel['Customer']); $Form = new Form($this->System->FormManager); $Form->SetClass('MemberOptions'); $DbRow = $DbResult2->fetch_array(); foreach ($Form->Definition['Items'] as $Index => $Item) { $Form->Values[$Index] = $DbRow[$Index]; } $Form->OnSubmit = '?Action=MemberOptionsSave&Id='.$CustomerUserRel['Customer']; $Output .= $Form->ShowEditForm(); } } else if ($Action == 'MemberOptionsSave') { $Form = new Form($this->System->FormManager); $Form->SetClass('MemberOptions'); $Form->LoadValuesFromForm(); if ($Form->Values['FamilyMemberCount'] < 0) $Form->Values['FamilyMemberCount'] = 0; $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; $DbResult = $this->Database->query('SELECT `Customer` FROM `UserCustomerRel` '. 'WHERE `User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id']); $CustomerUserRel = $DbResult->fetch_assoc(); $CustomerId = $CustomerUserRel['Customer']; $DbResult = $this->Database->update('Member', 'Id='.$CustomerId, array('FamilyMemberCount' => $Form->Values['FamilyMemberCount'])); $DbResult = $this->Database->query('SELECT Subject FROM Member WHERE Id='.$CustomerId); $Member = $DbResult->fetch_assoc(); $DbResult = $this->Database->update('Subject', 'Id='.$Member['Subject'], array('Name' => $Form->Values['Name'], 'AddressStreet' => $Form->Values['AddressStreet'], 'AddressTown' => $Form->Values['AddressTown'], 'AddressCountry' => $Form->Values['AddressCountry'], 'AddressPSC' => $Form->Values['AddressPSC'], 'IC' => $Form->Values['IC'], 'DIC' => $Form->Values['DIC'])); $Output .= $this->SystemMessage('Nastavení', 'Nastavení zákazníka uloženo.'); ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('Member+Subject', 'Nastavení zákazníka/subjektu změněno', $Form->Values['Name']); $DbResult = $this->Database->query('SELECT Member.Id, Member.FamilyMemberCount, '. '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='.$CustomerId); $DbRow = $DbResult->fetch_array(); foreach ($Form->Definition['Items'] as $Index => $Item) { $Form->Values[$Index] = $DbRow[$Index]; } $Form->OnSubmit = '?Action=MemberOptionsSave'; $Output .= $Form->ShowEditForm(); } } else $Output = $this->ShowMain(); return $Output; } function ShowMain(): string { $Output = ''; $DbResult = $this->Database->query('SELECT * FROM `ActionGroup`'); $ActionGroups = array(); while ($DbRow = $DbResult->fetch_assoc()) $ActionGroups[$DbRow['Id']] = $DbRow; // Show pannels //if (IsInternetAddr()) echo('Internet'); else echo('LAN'); //$Output .= $this->InfoBar(); $Output .= ''; $DbResult = $this->Database->select('PanelColumn', '*'); while ($PanelColumn = $DbResult->fetch_assoc()) { if ($PanelColumn != '') $Width = ' width="'.$PanelColumn['Width'].'"'; else $Width = ''; $Output .= ''; } $Output .= '
'; $DbResult2 = $this->Database->query('SELECT * FROM `Panel` WHERE `PanelColumn`='.$PanelColumn['Id'].' ORDER BY `Order`'); while ($Panel = $DbResult2->fetch_assoc()) { if ($Panel['Module'] == 'ActionGroup') $Output .= $this->ShowActions($ActionGroups[$Panel['Parameters']]); else if ($Panel['Module'] == 'OnlineHostList') $Output .= $this->Panel('Online počítače', $this->OnlineHostList()); else if ($Panel['Module'] == 'UserOptions') { //if (ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'] != null) $Output .= $this->Panel('Přihlášený uživatel', $this->UserPanel()); } else if ($Panel['Module'] == 'Webcam') $Output .= $this->Panel('Kamery', $this->WebcamPanel()); if ($Panel['Module'] == 'Meteo') $Output .= $this->Panel('Meteostanice', $this->MeteoPanel()); else if ($Panel['Module'] == 'NewsGroupList') $Output .= $this->Panel('Aktuality', ModuleNews::Cast($this->System->GetModule('News'))->Show(), array('Upravit')); } $Output .= '
'; return $Output; } }