source: trunk/Modules/User/UserPage.php

Last change on this file was 954, checked in by chronos, 20 months ago
  • Added: Require configuration for user registration and password recovery that user is a human.
File size: 9.2 KB
RevLine 
[634]1<?php
2
3class PageUser extends Page
4{
[887]5 function __construct(System $System)
6 {
7 parent::__construct($System);
[912]8 $this->Title = 'Uživatel';
[887]9 $this->ParentClass = 'PagePortal';
10 }
[634]11
[887]12 function Panel(string $Title, string $Content, array $Menu = array()): string
[634]13 {
[873]14 if (count($Menu) > 0)
15 foreach ($Menu as $Item)
[634]16 $Title .= '<div class="Action">'.$Item.'</div>';
[874]17 return '<div class="Panel"><div class="Title">'.$Title.'</div><div class="Content">'.$Content.'</div></div>';
[634]18 }
19
[887]20 function ShowContacts(): string
[694]21 {
[895]22 if (!$this->System->ModuleManager->ModuleRunning('Subject')) return '';
23
[826]24 $Query = 'SELECT `Contact`.`Value`, `Contact`.`Description`, (SELECT `Name` FROM `ContactCategory` WHERE `ContactCategory`.`Id` = `Contact`.`Category`) AS `Category` '.
[694]25 'FROM `Contact` WHERE `User` = '.
[887]26 ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'];
[694]27 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$Query.') AS T');
28 $DbRow = $DbResult->fetch_row();
[825]29 $PageList = GetPageList('Contacts', $DbRow[0]);
[694]30
31 $Output = '<div>Kontakty</div>';
32 $Output .= $PageList['Output'];
33 $Output .= '<table class="WideTable" style="font-size: small;">';
34
35 $TableColumns = array(
36 array('Name' => 'Category', 'Title' => 'Skupina'),
37 array('Name' => 'Value', 'Title' => 'Hodnota'),
[826]38 array('Name' => 'Description', 'Title' => 'Popis'),
[694]39 );
[825]40 $Order = GetOrderTableHeader('Contacts', $TableColumns, 'Value', 0);
[694]41 $Output .= $Order['Output'];
42 $Query = $Query.' '.$Order['SQL'].$PageList['SQLLimit'];
43 $DbResult = $this->Database->query($Query);
[873]44 while ($Contact = $DbResult->fetch_assoc())
[694]45 {
[826]46 $Output .= '<tr>'.
47 '<td>'.$Contact['Category'].'</td>'.
48 '<td>'.$Contact['Value'].'</td>'.
49 '<td>'.$Contact['Description'].'</td>'.
[895]50 '</tr>';
[694]51 }
52 $Output .= '</table>';
53 $Output .= $PageList['Output'];
54
[874]55 return $Output;
[694]56 }
57
[887]58 function ShowUserPanel(): string
[634]59 {
[887]60 $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
[634]61 $Output = '';
[887]62 if ($User->User['Id'] != null)
[693]63 {
[738]64 $Actions = '';
[887]65 foreach (ModuleUser::Cast($this->System->GetModule('User'))->UserPanel as $Action)
[738]66 {
[873]67 if (is_string($Action[0]))
[738]68 {
69 $Class = new $Action[0]($this->System);
[828]70 $Method = $Action[1];
71 $Actions .= $Class->$Method();
[738]72 } else $Actions .= call_user_func($Action).'<br/>';
73 }
[901]74 $Output .= '<div class="Centered"><table id="MainTable"><tr><td style="vertical-align:top;">';
[634]75 $Output .= $this->Panel('Nabídka uživatele', $Actions);
[694]76 $Output .= '</td><td style="vertical-align:top;">';
[887]77 if ($User->User['Id'] != null)
[693]78 {
79 $Form = new Form($this->System->FormManager);
80 $Form->SetClass('UserOptions');
[887]81 $Form->LoadValuesFromDatabase($User->User['Id']);
[693]82 $Form->OnSubmit = '?Action=UserOptionsSave';
83 $Output .= $Form->ShowViewForm();
[694]84
85 $Output .= '<br/>'.$this->ShowContacts();
[693]86 } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
87
[634]88 //$Output .= $this->Panel('Přehled', $this->UserPanel());
89 $Output .= '</td></tr></table></div>';
90 } else $Output .= $this->SystemMessage('Oprávnění', 'Nejste přihlášen');
[874]91 return $Output;
[634]92 }
93
[887]94 function Show(): string
[738]95 {
[887]96 $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
[738]97 $Output = '';
[873]98 if (array_key_exists('Action', $_GET))
[634]99 {
100 $Action = $_GET['Action'];
[873]101 if ($Action == 'LoginForm')
[634]102 {
103 $Form = new Form($this->System->FormManager);
104 $Form->SetClass('UserLogin');
105 $Form->OnSubmit = '?Action=Login';
106 $Output .= $Form->ShowEditForm();
[901]107 $Output .= '<div class="Centered"><a href="?Action=UserRegister">Registrovat se</a> '.
[634]108 '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
109 } else
[873]110 if ($Action == 'Login')
[634]111 {
[873]112 if (array_key_exists('Username', $_POST) and array_key_exists('Password', $_POST))
[634]113 {
114 $Form = new Form($this->System->FormManager);
115 $Form->SetClass('UserLogin');
116 $Form->OnSubmit = '?Action=Login';
[873]117 if (array_key_exists('StayLogged', $_POST) and ($_POST['StayLogged'] == 'on')) $StayLogged = true;
[693]118 else $StayLogged = false;
[887]119 $Result = $User->Login($_POST['Username'], $_POST['Password'], $StayLogged);
[634]120 $Output .= $this->SystemMessage('Přihlášení', $Result);
[873]121 if ($Result <> USER_LOGGED_IN)
[634]122 {
123 $Form->LoadValuesFromForm();
124 $Form->Values['Password'] = '';
125 $Output .= $Form->ShowEditForm();
[901]126 $Output .= '<div class="Centered"><a href="?Action=UserRegister">Registrovat se</a> '.
[634]127 '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
128 } else {
[901]129 //$Output .= '<div class="Centered">Za 5 sekund budete přesměrováni na <a href="?Action=UserMenu">nabídku uživatele</a></div>';
[634]130 //Header('refresh:5;url=?Action=UserMenu');
131 Header('Location: ?Action=UserMenu');
132 }
133 } else $Output .= $this->SystemMessage('Přihlášení', 'Nezadány přihlašovací údaje');
[693]134 } else
[873]135 if ($Action == 'Logout')
[634]136 {
[887]137 if ($User->User['Id'] != null)
[634]138 {
[887]139 $Output .= $this->SystemMessage('Odhlášení', $User->Logout());
[634]140 } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
141 } else
[873]142 if ($Action == 'UserOptions')
[693]143 {
[887]144 if ($User->User['Id'] != null)
[634]145 {
146 $Form = new Form($this->System->FormManager);
147 $Form->SetClass('UserOptions');
[887]148 $Form->LoadValuesFromDatabase($User->User['Id']);
[634]149 $Form->OnSubmit = '?Action=UserOptionsSave';
150 $Output .= $Form->ShowEditForm();
151 } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
152 } else
[873]153 if ($Action == 'UserOptionsSave')
[634]154 {
155 $Form = new Form($this->System->FormManager);
156 $Form->SetClass('UserOptions');
157 $Form->LoadValuesFromForm();
[887]158 $Form->SaveValuesToDatabase($User->User['Id']);
[634]159 $Output .= $this->SystemMessage('Nastavení', 'Nastavení uloženo.');
[887]160 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('User', 'Nastavení uživatele změněno', $Form->Values['Name']);
161 $Form->LoadValuesFromDatabase($User->User['Id']);
[634]162 $Form->OnSubmit = '?Action=UserOptionsSave';
163 $Output .= $Form->ShowEditForm();
164 } else
[873]165 if ($Action == 'UserRegister')
[634]166 {
167 $Form = new Form($this->System->FormManager);
168 $Form->SetClass('UserRegister');
169 //$Form->LoadValuesFromForm();
170 $Form->OnSubmit = '?Action=UserRegisterSave';
171 $Output .= $Form->ShowEditForm();
172 } else
[873]173 if ($Action == 'UserRegisterConfirm')
[634]174 {
[693]175 $Output .= $this->SystemMessage('Potvrzení registrace',
[887]176 $User->RegisterConfirm($_GET['User'], $_GET['H']));
[634]177 } else
[873]178 if ($Action == 'PasswordRecovery')
[634]179 {
180 $Form = new Form($this->System->FormManager);
181 $Form->SetClass('PasswordRecovery');
[922]182 if ($Form->HasAllPostVariables())
[634]183 {
[922]184 $Form->LoadValuesFromForm();
[954]185 if ($Form->Values['IsHuman'] == 1)
186 {
187 $Result = $User->PasswordRecoveryRequest($Form->Values['Name'], $Form->Values['Email']);
188 $Output .= $this->SystemMessage('Obnova hesla', $Result);
189 } else
190 {
191 $Result = USER_NOT_HUMAN;
192 $Output .= $this->SystemMessage('Nejsi člověk. Strojům není dovoleno obnovovat heslo.', $Result);
193 }
[922]194 if ($Result <> USER_PASSWORD_RECOVERY_SUCCESS)
195 {
196 $Output .= $Form->ShowEditForm();
197 }
198 } else
199 {
200 $Form->OnSubmit = '?Action=PasswordRecovery';
[634]201 $Output .= $Form->ShowEditForm();
[693]202 }
[634]203 } else
[873]204 if ($Action == 'PasswordRecoveryConfirm')
[634]205 {
[887]206 $Output .= $this->SystemMessage('Obnova hesla', $User->PasswordRecoveryConfirm($_GET['User'], $_GET['H'], $_GET['P']));
[634]207 } else
[873]208 if ($Action == 'UserRegisterSave')
[634]209 {
210 $Form = new Form($this->System->FormManager);
211 $Form->SetClass('UserRegister');
212 $Form->LoadValuesFromForm();
[954]213 if ($Form->Values['IsHuman'] == 1)
214 {
215 $Result = $User->Register($Form->Values['Login'], $Form->Values['Password'],
216 $Form->Values['Password2'], $Form->Values['Email'], $Form->Values['Name']);
217 $Output .= $this->SystemMessage('Registrace nového účtu', $Result);
218 } else
219 {
220 $Result = USER_NOT_HUMAN;
221 $Output .= $this->SystemMessage('Nejsi člověk. Strojům není dovoleno se registrovat.', $Result);
222 }
[873]223 if ($Result <> USER_REGISTRATED)
[634]224 {
225 $Form->OnSubmit = '?Action=UserRegisterSave';
226 $Output .= $Form->ShowEditForm();
227 }
[693]228 } else
[873]229 if ($Action == 'UserMenu')
[634]230 {
231 $Output = $this->ShowUserPanel();
232 } else $Output = $this->ShowMain();
233 } else $Output = $this->ShowMain();
[874]234 return $Output;
[738]235 }
[693]236
[887]237 function ShowMain(): string
[738]238 {
239 $Output = 'Nebyla vybrána akce';
[874]240 return $Output;
[738]241 }
[873]242}
Note: See TracBrowser for help on using the repository browser.