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 = '
'; $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 .= ' | '; } $Output .= '