Title = 'Uživatel'; $this->ParentClass = 'PagePortal'; } function Panel(string $Title, string $Content, array $Menu = array()): string { if (count($Menu) > 0) foreach ($Menu as $Item) $Title .= '
'.$Item.'
'; return '
'.$Title.'
'.$Content.'
'; } function ShowContacts(): string { if (!$this->System->ModuleManager->ModuleRunning('Subject')) return ''; $Query = 'SELECT `Contact`.`Value`, `Contact`.`Description`, (SELECT `Name` FROM `ContactCategory` WHERE `ContactCategory`.`Id` = `Contact`.`Category`) AS `Category` '. 'FROM `Contact` WHERE `User` = '. ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id']; $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$Query.') AS T'); $DbRow = $DbResult->fetch_row(); $PageList = GetPageList('Contacts', $DbRow[0]); $Output = '
Kontakty
'; $Output .= $PageList['Output']; $Output .= ''; $TableColumns = array( array('Name' => 'Category', 'Title' => 'Skupina'), array('Name' => 'Value', 'Title' => 'Hodnota'), array('Name' => 'Description', 'Title' => 'Popis'), ); $Order = GetOrderTableHeader('Contacts', $TableColumns, 'Value', 0); $Output .= $Order['Output']; $Query = $Query.' '.$Order['SQL'].$PageList['SQLLimit']; $DbResult = $this->Database->query($Query); while ($Contact = $DbResult->fetch_assoc()) { $Output .= ''. ''. ''. ''. ''; } $Output .= '
'.$Contact['Category'].''.$Contact['Value'].''.$Contact['Description'].'
'; $Output .= $PageList['Output']; return $Output; } function ShowUserPanel(): string { $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; if ($User->User['Id'] != null) { $Actions = ''; foreach (ModuleUser::Cast($this->System->GetModule('User'))->UserPanel as $Action) { if (is_string($Action[0])) { $Class = new $Action[0]($this->System); $Method = $Action[1]; $Actions .= $Class->$Method(); } else $Actions .= call_user_func($Action).'
'; } $Output .= '
'; $Output .= $this->Panel('Nabídka uživatele', $Actions); $Output .= ''; if ($User->User['Id'] != null) { $Form = new Form($this->System->FormManager); $Form->SetClass('UserOptions'); $Form->LoadValuesFromDatabase($User->User['Id']); $Form->OnSubmit = '?Action=UserOptionsSave'; $Output .= $Form->ShowViewForm(); $Output .= '
'.$this->ShowContacts(); } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen'); //$Output .= $this->Panel('Přehled', $this->UserPanel()); $Output .= '
'; } else $Output .= $this->SystemMessage('Oprávnění', 'Nejste přihlášen'); return $Output; } function Show(): string { $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; if (array_key_exists('Action', $_GET)) { $Action = $_GET['Action']; if ($Action == 'LoginForm') { $Form = new Form($this->System->FormManager); $Form->SetClass('UserLogin'); $Form->OnSubmit = '?Action=Login'; $Output .= $Form->ShowEditForm(); $Output .= '
Registrovat se '. 'Obnova zapomenutého hesla
'; } else if ($Action == 'Login') { if (array_key_exists('Username', $_POST) and array_key_exists('Password', $_POST)) { $Form = new Form($this->System->FormManager); $Form->SetClass('UserLogin'); $Form->OnSubmit = '?Action=Login'; if (array_key_exists('StayLogged', $_POST) and ($_POST['StayLogged'] == 'on')) $StayLogged = true; else $StayLogged = false; $Result = $User->Login($_POST['Username'], $_POST['Password'], $StayLogged); $Output .= $this->SystemMessage('Přihlášení', $Result); if ($Result <> USER_LOGGED_IN) { $Form->LoadValuesFromForm(); $Form->Values['Password'] = ''; $Output .= $Form->ShowEditForm(); $Output .= '
Registrovat se '. 'Obnova zapomenutého hesla
'; } else { //$Output .= '
Za 5 sekund budete přesměrováni na nabídku uživatele
'; //Header('refresh:5;url=?Action=UserMenu'); Header('Location: ?Action=UserMenu'); } } else $Output .= $this->SystemMessage('Přihlášení', 'Nezadány přihlašovací údaje'); } else if ($Action == 'Logout') { if ($User->User['Id'] != null) { $Output .= $this->SystemMessage('Odhlášení', $User->Logout()); } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen'); } else if ($Action == 'UserOptions') { if ($User->User['Id'] != null) { $Form = new Form($this->System->FormManager); $Form->SetClass('UserOptions'); $Form->LoadValuesFromDatabase($User->User['Id']); $Form->OnSubmit = '?Action=UserOptionsSave'; $Output .= $Form->ShowEditForm(); } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen'); } else if ($Action == 'UserOptionsSave') { $Form = new Form($this->System->FormManager); $Form->SetClass('UserOptions'); $Form->LoadValuesFromForm(); $Form->SaveValuesToDatabase($User->User['Id']); $Output .= $this->SystemMessage('Nastavení', 'Nastavení uloženo.'); ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('User', 'Nastavení uživatele změněno', $Form->Values['Name']); $Form->LoadValuesFromDatabase($User->User['Id']); $Form->OnSubmit = '?Action=UserOptionsSave'; $Output .= $Form->ShowEditForm(); } else if ($Action == 'UserRegister') { $Form = new Form($this->System->FormManager); $Form->SetClass('UserRegister'); //$Form->LoadValuesFromForm(); $Form->OnSubmit = '?Action=UserRegisterSave'; $Output .= $Form->ShowEditForm(); } else if ($Action == 'UserRegisterConfirm') { $Output .= $this->SystemMessage('Potvrzení registrace', $User->RegisterConfirm($_GET['User'], $_GET['H'])); } else if ($Action == 'PasswordRecovery') { $Form = new Form($this->System->FormManager); $Form->SetClass('PasswordRecovery'); if ($Form->HasAllPostVariables()) { $Form->LoadValuesFromForm(); if ($Form->Values['IsHuman'] == 1) { $Result = $User->PasswordRecoveryRequest($Form->Values['Name'], $Form->Values['Email']); $Output .= $this->SystemMessage('Obnova hesla', $Result); } else { $Result = USER_NOT_HUMAN; $Output .= $this->SystemMessage('Nejsi člověk. Strojům není dovoleno obnovovat heslo.', $Result); } if ($Result <> USER_PASSWORD_RECOVERY_SUCCESS) { $Output .= $Form->ShowEditForm(); } } else { $Form->OnSubmit = '?Action=PasswordRecovery'; $Output .= $Form->ShowEditForm(); } } else if ($Action == 'PasswordRecoveryConfirm') { $Output .= $this->SystemMessage('Obnova hesla', $User->PasswordRecoveryConfirm($_GET['User'], $_GET['H'], $_GET['P'])); } else if ($Action == 'UserRegisterSave') { $Form = new Form($this->System->FormManager); $Form->SetClass('UserRegister'); $Form->LoadValuesFromForm(); if ($Form->Values['IsHuman'] == 1) { $Result = $User->Register($Form->Values['Login'], $Form->Values['Password'], $Form->Values['Password2'], $Form->Values['Email'], $Form->Values['Name']); $Output .= $this->SystemMessage('Registrace nového účtu', $Result); } else { $Result = USER_NOT_HUMAN; $Output .= $this->SystemMessage('Nejsi člověk. Strojům není dovoleno se registrovat.', $Result); } if ($Result <> USER_REGISTRATED) { $Form->OnSubmit = '?Action=UserRegisterSave'; $Output .= $Form->ShowEditForm(); } } else if ($Action == 'UserMenu') { $Output = $this->ShowUserPanel(); } else $Output = $this->ShowMain(); } else $Output = $this->ShowMain(); return $Output; } function ShowMain(): string { $Output = 'Nebyla vybrána akce'; return $Output; } }