source: trunk/Modules/User/PageUser.php

Last change on this file was 10, checked in by chronos, 19 months ago
  • Fixed: More class type casting.
File size: 9.0 KB
Line 
1<?php
2
3class PageUser extends Page
4{
5 function __construct(System $System)
6 {
7 parent::__construct($System);
8 $this->Title = 'Uživatel';
9 $this->Description = 'Uživatel';
10 $this->ParentClass = 'PagePortal';
11 }
12
13 function Panel($Title, $Content, $Menu = array())
14 {
15 if (count($Menu) > 0)
16 foreach ($Menu as $Item)
17 $Title .= '<div class="Action">'.$Item.'</div>';
18 return '<div class="Panel"><div class="Title">'.$Title.'</div><div class="Content">'.$Content.'</div></div>';
19 }
20
21 function ShowContacts()
22 {
23 $Query = 'SELECT `Contact`.`Value`, `Contact`.`Description`, (SELECT `Name` FROM `ContactCategory` WHERE `ContactCategory`.`Id` = `Contact`.`Category`) AS `Category` '.
24 'FROM `Contact` WHERE `User` = '.
25 Core::Cast($this->System)->User->User['Id'];
26 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$Query.') AS T');
27 $DbRow = $DbResult->fetch_row();
28 $PageList = GetPageList('Contacts', $DbRow[0]);
29
30 $Output = '<div>Kontakty</div>';
31 $Output .= $PageList['Output'];
32 $Output .= '<table class="WideTable" style="font-size: small;">';
33
34 $TableColumns = array(
35 array('Name' => 'Category', 'Title' => 'Skupina'),
36 array('Name' => 'Value', 'Title' => 'Hodnota'),
37 array('Name' => 'Description', 'Title' => 'Popis'),
38 );
39 $Order = GetOrderTableHeader('Contacts', $TableColumns, 'Value', 0);
40 $Output .= $Order['Output'];
41
42 $Query = $Query.' '.$Order['SQL'].$PageList['SQLLimit'];
43
44 $DbResult = $this->Database->query($Query);
45 while ($Contact = $DbResult->fetch_assoc())
46 {
47 $Output .= '<tr>'.
48 '<td>'.$Contact['Category'].'</td>'.
49 '<td>'.$Contact['Value'].'</td>'.
50 '<td>'.$Contact['Description'].'</td>'.
51 '</tr>';
52 }
53 $Output .= '</table>';
54 $Output .= $PageList['Output'];
55
56 return $Output;
57 }
58
59 function ShowUserPanel()
60 {
61 $Output = '';
62 if (Core::Cast($this->System)->User->User['Id'] != null)
63 {
64 $Actions = '';
65 foreach ($this->System->ModuleManager->Modules['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="Centred"><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 (Core::Cast($this->System)->User->User['Id'] != null)
78 {
79 $Form = new Form(Core::Cast($this->System)->FormManager);
80 $Form->SetClass('UserOptions');
81 $Form->LoadValuesFromDatabase(Core::Cast($this->System)->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 $Output = '';
97 if (array_key_exists('Action', $_GET))
98 {
99 $Action = $_GET['Action'];
100 if ($Action == 'LoginForm')
101 {
102 $Form = new Form(Core::Cast($this->System)->FormManager);
103 $Form->SetClass('UserLogin');
104 $Form->OnSubmit = '?Action=Login';
105 $Output .= $Form->ShowEditForm();
106 $Output .= '<div class="Centred"><a href="?Action=UserRegister">Registrovat se</a> '.
107 '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
108 } else
109 if ($Action == 'Login')
110 {
111 if (array_key_exists('Username', $_POST) and array_key_exists('Password', $_POST))
112 {
113 $Form = new Form(Core::Cast($this->System)->FormManager);
114 $Form->SetClass('UserLogin');
115 $Form->OnSubmit = '?Action=Login';
116 if (array_key_exists('StayLogged', $_POST) and ($_POST['StayLogged'] == 'on')) $StayLogged = true;
117 else $StayLogged = false;
118 $Result = Core::Cast($this->System)->User->Login($_POST['Username'], $_POST['Password'], $StayLogged);
119 $Output .= $this->SystemMessage('Přihlášení', $Result);
120 if ($Result <> USER_LOGGED_IN)
121 {
122 $Form->LoadValuesFromForm();
123 $Form->Values['Password'] = '';
124 $Output .= $Form->ShowEditForm();
125 $Output .= '<div class="Centred"><a href="?Action=UserRegister">Registrovat se</a> '.
126 '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
127 } else {
128 //$Output .= '<div class="Centred">Za 5 sekund budete přesměrováni na <a href="?Action=UserMenu">nabídku uživatele</a></div>';
129 //Header('refresh:5;url=?Action=UserMenu');
130 Header('Location: ?Action=UserMenu');
131 }
132 } else $Output .= $this->SystemMessage('Přihlášení', 'Nezadány přihlašovací údaje');
133 } else
134 if ($Action == 'Logout')
135 {
136 if (Core::Cast($this->System)->User->User['Id'] != null)
137 {
138 $Output .= $this->SystemMessage('Odhlášení', Core::Cast($this->System)->User->Logout());
139 } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
140 } else
141 if ($Action == 'UserOptions')
142 {
143 if (Core::Cast($this->System)->User->User['Id'] != null)
144 {
145 $Form = new Form(Core::Cast($this->System)->FormManager);
146 $Form->SetClass('UserOptions');
147 $Form->LoadValuesFromDatabase(Core::Cast($this->System)->User->User['Id']);
148 $Form->OnSubmit = '?Action=UserOptionsSave';
149 $Output .= $Form->ShowEditForm();
150 } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
151 } else
152 if ($Action == 'UserOptionsSave')
153 {
154 $Form = new Form(Core::Cast($this->System)->FormManager);
155 $Form->SetClass('UserOptions');
156 $Form->LoadValuesFromForm();
157 $Form->SaveValuesToDatabase(Core::Cast($this->System)->User->User['Id']);
158 $Output .= $this->SystemMessage('Nastavení', 'Nastavení uloženo.');
159 $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'Nastavení uživatele změněno', $Form->Values['Name']);
160 $Form->LoadValuesFromDatabase(Core::Cast($this->System)->User->User['Id']);
161 $Form->OnSubmit = '?Action=UserOptionsSave';
162 $Output .= $Form->ShowEditForm();
163 } else
164 if ($Action == 'UserRegister')
165 {
166 $Form = new Form(Core::Cast($this->System)->FormManager);
167 $Form->SetClass('UserRegister');
168 //$Form->LoadValuesFromForm();
169 $Form->OnSubmit = '?Action=UserRegisterSave';
170 $Output .= $Form->ShowEditForm();
171 } else
172 if ($Action == 'UserRegisterConfirm')
173 {
174 $Output .= $this->SystemMessage('Potvrzení registrace',
175 Core::Cast($this->System)->User->RegisterConfirm($_GET['User'], $_GET['H']));
176 } else
177 if ($Action == 'PasswordRecovery')
178 {
179 $Form = new Form(Core::Cast($this->System)->FormManager);
180 $Form->SetClass('PasswordRecovery');
181 $Form->OnSubmit = '?Action=PasswordRecovery2';
182 $Output .= $Form->ShowEditForm();
183 } else
184 if ($Action == 'PasswordRecovery2')
185 {
186 $Form = new Form(Core::Cast($this->System)->FormManager);
187 $Form->SetClass('PasswordRecovery');
188 $Form->LoadValuesFromForm();
189 $Result = Core::Cast($this->System)->User->PasswordRecoveryRequest($Form->Values['Name'], $Form->Values['Email']);
190 $Output .= $this->SystemMessage('Obnova hesla', $Result);
191 if ($Result <> USER_PASSWORD_RECOVERY_SUCCESS)
192 {
193 $Output .= $Form->ShowEditForm();
194 }
195 } else
196 if ($Action == 'PasswordRecoveryConfirm')
197 {
198 $Output .= $this->SystemMessage('Obnova hesla', Core::Cast($this->System)->User->PasswordRecoveryConfirm($_GET['User'], $_GET['H'], $_GET['P']));
199 } else
200 if ($Action == 'UserRegisterSave')
201 {
202 $Form = new Form(Core::Cast($this->System)->FormManager);
203 $Form->SetClass('UserRegister');
204 $Form->LoadValuesFromForm();
205 $Result = Core::Cast($this->System)->User->Register($Form->Values['Login'], $Form->Values['Password'],
206 $Form->Values['Password2'], $Form->Values['Email'], $Form->Values['Name']);
207 $Output .= $this->SystemMessage('Registrace nového účtu', $Result);
208 if ($Result <> USER_REGISTRATED)
209 {
210 $Form->OnSubmit = '?Action=UserRegisterSave';
211 $Output .= $Form->ShowEditForm();
212 }
213 } else
214 if ($Action == 'UserMenu')
215 {
216 $Output = $this->ShowUserPanel();
217 } else $Output = $this->ShowMain();
218 } else $Output = $this->ShowMain();
219 return $Output;
220 }
221
222 function ShowMain()
223 {
224 $Output = 'Nebyla vybrána akce';
225 return $Output;
226 }
227}
Note: See TracBrowser for help on using the repository browser.