1 | <?php
|
---|
2 |
|
---|
3 | class PageUser extends Page
|
---|
4 | {
|
---|
5 | function __construct(System $System)
|
---|
6 | {
|
---|
7 | parent::__construct($System);
|
---|
8 | $this->Title = 'Uživatel';
|
---|
9 | $this->ParentClass = 'PagePortal';
|
---|
10 | }
|
---|
11 |
|
---|
12 | function Panel(string $Title, string $Content, array $Menu = array()): string
|
---|
13 | {
|
---|
14 | if (count($Menu) > 0)
|
---|
15 | foreach ($Menu as $Item)
|
---|
16 | $Title .= '<div class="Action">'.$Item.'</div>';
|
---|
17 | return '<div class="Panel"><div class="Title">'.$Title.'</div><div class="Content">'.$Content.'</div></div>';
|
---|
18 | }
|
---|
19 |
|
---|
20 | function ShowContacts(): string
|
---|
21 | {
|
---|
22 | if (!$this->System->ModuleManager->ModuleRunning('Subject')) return '';
|
---|
23 |
|
---|
24 | $Query = 'SELECT `Contact`.`Value`, `Contact`.`Description`, (SELECT `Name` FROM `ContactCategory` WHERE `ContactCategory`.`Id` = `Contact`.`Category`) AS `Category` '.
|
---|
25 | 'FROM `Contact` WHERE `User` = '.
|
---|
26 | ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'];
|
---|
27 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$Query.') AS T');
|
---|
28 | $DbRow = $DbResult->fetch_row();
|
---|
29 | $PageList = GetPageList('Contacts', $DbRow[0]);
|
---|
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'),
|
---|
38 | array('Name' => 'Description', 'Title' => 'Popis'),
|
---|
39 | );
|
---|
40 | $Order = GetOrderTableHeader('Contacts', $TableColumns, 'Value', 0);
|
---|
41 | $Output .= $Order['Output'];
|
---|
42 | $Query = $Query.' '.$Order['SQL'].$PageList['SQLLimit'];
|
---|
43 | $DbResult = $this->Database->query($Query);
|
---|
44 | while ($Contact = $DbResult->fetch_assoc())
|
---|
45 | {
|
---|
46 | $Output .= '<tr>'.
|
---|
47 | '<td>'.$Contact['Category'].'</td>'.
|
---|
48 | '<td>'.$Contact['Value'].'</td>'.
|
---|
49 | '<td>'.$Contact['Description'].'</td>'.
|
---|
50 | '</tr>';
|
---|
51 | }
|
---|
52 | $Output .= '</table>';
|
---|
53 | $Output .= $PageList['Output'];
|
---|
54 |
|
---|
55 | return $Output;
|
---|
56 | }
|
---|
57 |
|
---|
58 | function ShowUserPanel(): string
|
---|
59 | {
|
---|
60 | $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
|
---|
61 | $Output = '';
|
---|
62 | if ($User->User['Id'] != null)
|
---|
63 | {
|
---|
64 | $Actions = '';
|
---|
65 | foreach (ModuleUser::Cast($this->System->GetModule('User'))->UserPanel as $Action)
|
---|
66 | {
|
---|
67 | if (is_string($Action[0]))
|
---|
68 | {
|
---|
69 | $Class = new $Action[0]($this->System);
|
---|
70 | $Method = $Action[1];
|
---|
71 | $Actions .= $Class->$Method();
|
---|
72 | } else $Actions .= call_user_func($Action).'<br/>';
|
---|
73 | }
|
---|
74 | $Output .= '<div class="Centered"><table id="MainTable"><tr><td style="vertical-align:top;">';
|
---|
75 | $Output .= $this->Panel('Nabídka uživatele', $Actions);
|
---|
76 | $Output .= '</td><td style="vertical-align:top;">';
|
---|
77 | if ($User->User['Id'] != null)
|
---|
78 | {
|
---|
79 | $Form = new Form($this->System->FormManager);
|
---|
80 | $Form->SetClass('UserOptions');
|
---|
81 | $Form->LoadValuesFromDatabase($User->User['Id']);
|
---|
82 | $Form->OnSubmit = '?Action=UserOptionsSave';
|
---|
83 | $Output .= $Form->ShowViewForm();
|
---|
84 |
|
---|
85 | $Output .= '<br/>'.$this->ShowContacts();
|
---|
86 | } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
|
---|
87 |
|
---|
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');
|
---|
91 | return $Output;
|
---|
92 | }
|
---|
93 |
|
---|
94 | function Show(): string
|
---|
95 | {
|
---|
96 | $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
|
---|
97 | $Output = '';
|
---|
98 | if (array_key_exists('Action', $_GET))
|
---|
99 | {
|
---|
100 | $Action = $_GET['Action'];
|
---|
101 | if ($Action == 'LoginForm')
|
---|
102 | {
|
---|
103 | $Form = new Form($this->System->FormManager);
|
---|
104 | $Form->SetClass('UserLogin');
|
---|
105 | $Form->OnSubmit = '?Action=Login';
|
---|
106 | $Output .= $Form->ShowEditForm();
|
---|
107 | $Output .= '<div class="Centered"><a href="?Action=UserRegister">Registrovat se</a> '.
|
---|
108 | '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
|
---|
109 | } else
|
---|
110 | if ($Action == 'Login')
|
---|
111 | {
|
---|
112 | if (array_key_exists('Username', $_POST) and array_key_exists('Password', $_POST))
|
---|
113 | {
|
---|
114 | $Form = new Form($this->System->FormManager);
|
---|
115 | $Form->SetClass('UserLogin');
|
---|
116 | $Form->OnSubmit = '?Action=Login';
|
---|
117 | if (array_key_exists('StayLogged', $_POST) and ($_POST['StayLogged'] == 'on')) $StayLogged = true;
|
---|
118 | else $StayLogged = false;
|
---|
119 | $Result = $User->Login($_POST['Username'], $_POST['Password'], $StayLogged);
|
---|
120 | $Output .= $this->SystemMessage('Přihlášení', $Result);
|
---|
121 | if ($Result <> USER_LOGGED_IN)
|
---|
122 | {
|
---|
123 | $Form->LoadValuesFromForm();
|
---|
124 | $Form->Values['Password'] = '';
|
---|
125 | $Output .= $Form->ShowEditForm();
|
---|
126 | $Output .= '<div class="Centered"><a href="?Action=UserRegister">Registrovat se</a> '.
|
---|
127 | '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
|
---|
128 | } else {
|
---|
129 | //$Output .= '<div class="Centered">Za 5 sekund budete přesměrováni na <a href="?Action=UserMenu">nabídku uživatele</a></div>';
|
---|
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');
|
---|
134 | } else
|
---|
135 | if ($Action == 'Logout')
|
---|
136 | {
|
---|
137 | if ($User->User['Id'] != null)
|
---|
138 | {
|
---|
139 | $Output .= $this->SystemMessage('Odhlášení', $User->Logout());
|
---|
140 | } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
|
---|
141 | } else
|
---|
142 | if ($Action == 'UserOptions')
|
---|
143 | {
|
---|
144 | if ($User->User['Id'] != null)
|
---|
145 | {
|
---|
146 | $Form = new Form($this->System->FormManager);
|
---|
147 | $Form->SetClass('UserOptions');
|
---|
148 | $Form->LoadValuesFromDatabase($User->User['Id']);
|
---|
149 | $Form->OnSubmit = '?Action=UserOptionsSave';
|
---|
150 | $Output .= $Form->ShowEditForm();
|
---|
151 | } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
|
---|
152 | } else
|
---|
153 | if ($Action == 'UserOptionsSave')
|
---|
154 | {
|
---|
155 | $Form = new Form($this->System->FormManager);
|
---|
156 | $Form->SetClass('UserOptions');
|
---|
157 | $Form->LoadValuesFromForm();
|
---|
158 | $Form->SaveValuesToDatabase($User->User['Id']);
|
---|
159 | $Output .= $this->SystemMessage('Nastavení', 'Nastavení uloženo.');
|
---|
160 | ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('User', 'Nastavení uživatele změněno', $Form->Values['Name']);
|
---|
161 | $Form->LoadValuesFromDatabase($User->User['Id']);
|
---|
162 | $Form->OnSubmit = '?Action=UserOptionsSave';
|
---|
163 | $Output .= $Form->ShowEditForm();
|
---|
164 | } else
|
---|
165 | if ($Action == 'UserRegister')
|
---|
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
|
---|
173 | if ($Action == 'UserRegisterConfirm')
|
---|
174 | {
|
---|
175 | $Output .= $this->SystemMessage('Potvrzení registrace',
|
---|
176 | $User->RegisterConfirm($_GET['User'], $_GET['H']));
|
---|
177 | } else
|
---|
178 | if ($Action == 'PasswordRecovery')
|
---|
179 | {
|
---|
180 | $Form = new Form($this->System->FormManager);
|
---|
181 | $Form->SetClass('PasswordRecovery');
|
---|
182 | if ($Form->HasAllPostVariables())
|
---|
183 | {
|
---|
184 | $Form->LoadValuesFromForm();
|
---|
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 | }
|
---|
194 | if ($Result <> USER_PASSWORD_RECOVERY_SUCCESS)
|
---|
195 | {
|
---|
196 | $Output .= $Form->ShowEditForm();
|
---|
197 | }
|
---|
198 | } else
|
---|
199 | {
|
---|
200 | $Form->OnSubmit = '?Action=PasswordRecovery';
|
---|
201 | $Output .= $Form->ShowEditForm();
|
---|
202 | }
|
---|
203 | } else
|
---|
204 | if ($Action == 'PasswordRecoveryConfirm')
|
---|
205 | {
|
---|
206 | $Output .= $this->SystemMessage('Obnova hesla', $User->PasswordRecoveryConfirm($_GET['User'], $_GET['H'], $_GET['P']));
|
---|
207 | } else
|
---|
208 | if ($Action == 'UserRegisterSave')
|
---|
209 | {
|
---|
210 | $Form = new Form($this->System->FormManager);
|
---|
211 | $Form->SetClass('UserRegister');
|
---|
212 | $Form->LoadValuesFromForm();
|
---|
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 | }
|
---|
223 | if ($Result <> USER_REGISTRATED)
|
---|
224 | {
|
---|
225 | $Form->OnSubmit = '?Action=UserRegisterSave';
|
---|
226 | $Output .= $Form->ShowEditForm();
|
---|
227 | }
|
---|
228 | } else
|
---|
229 | if ($Action == 'UserMenu')
|
---|
230 | {
|
---|
231 | $Output = $this->ShowUserPanel();
|
---|
232 | } else $Output = $this->ShowMain();
|
---|
233 | } else $Output = $this->ShowMain();
|
---|
234 | return $Output;
|
---|
235 | }
|
---|
236 |
|
---|
237 | function ShowMain(): string
|
---|
238 | {
|
---|
239 | $Output = 'Nebyla vybrána akce';
|
---|
240 | return $Output;
|
---|
241 | }
|
---|
242 | }
|
---|