source: branches/php/Module/User/Controller.php@ 112

Last change on this file since 112 was 112, checked in by chronos, 11 years ago
  • Odstraněno: Ukončovací PHP značka ze všech souborů.
File size: 5.7 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../../Base/HTML/AddWebObject.php');
4include_once(dirname(__FILE__).'/../../Base/HTML/EditWebObject.php');
5include_once(dirname(__FILE__).'/../../Base/HTML/ViewWebObject.php');
6include_once(dirname(__FILE__).'/../../Base/HTML/ListWebObject.php');
7include_once(dirname(__FILE__).'/../../Base/HTML/Controller.php');
8
9class UserLoginWebObject extends AddWebObject
10{
11 function __construct($System)
12 {
13 parent::__construct($System);
14 $this->Columns = array(
15 'UserName' => array(
16 'Type' => 'String',
17 ),
18 'Password' => array(
19 'Type' => 'Password',
20 ),
21 );
22 $this->Groups = array(
23 'UserLogin',
24 );
25 $this->Actions = array(
26 array('Name' => 'UserLogin', 'Module' => 'User', 'Action' => 'Login'),
27 );
28 }
29
30 function AddProcessRow($Row)
31 {
32 return($Row);
33 }
34}
35
36class UserEditWebObject extends EditWebObject
37{
38 function __construct($System)
39 {
40 parent::__construct($System);
41 $this->Table = 'User';
42 $this->SQL = 'SELECT * FROM User';
43 $this->Columns = array(
44 'UserName' => array(
45 'Type' => 'String',
46 'SQL' => 'Name',
47 'ReadOnly' => true,
48 ),
49 'Password' => array(
50 'Type' => 'Password',
51 'SQL' => 'Password',
52 'ReadOnly' => false,
53 ),
54 'FullName' => array(
55 'Type' => 'String',
56 'SQL' => 'FullName',
57 'ReadOnly' => false,
58 'Group' => 1,
59 ),
60 'Email' => array(
61 'Type' => 'String',
62 'SQL' => 'Email',
63 'ReadOnly' => false,
64 'Group' => 1,
65 ),
66 );
67 $this->Groups = array(
68 'UserLogin',
69 'UserDetails',
70 );
71 $this->Actions = array(
72 array('Name' => 'Save', 'Module' => 'User', 'Action' => 'Edit'),
73 );
74 }
75
76 function SaveProcessRow($Row)
77 {
78 if($Row['Password'] != '""')
79 {
80 $Salt = $this->System->User->GetPasswordSalt();
81 $Row['Salt'] = '"'.$Salt.'"';
82 $Row['Password'] = 'SHA1(CONCAT("'.substr($Row['Password'], 1, -1).'", "'.$Salt.'"))';
83 } else unset($Row['Password']);
84 return($Row);
85 }
86}
87
88class UserViewWebObject extends ViewWebObject
89{
90 function __construct($System)
91 {
92 parent::__construct($System);
93 $this->Table = 'User';
94 $this->SQLJoin = '';
95 $this->Columns = array(
96 'UserName' => array(
97 'Type' => 'String',
98 'SQL' => 'Name',
99 'ReadOnly' => true,
100 ),
101 'Password' => array(
102 'Type' => 'Password',
103 'SQL' => 'Password',
104 'ReadOnly' => false,
105 ),
106 'Member' => array(
107 'Type' => 'PointerToMember',
108 'SQL' => 'Member',
109 'ReadOnly' => true,
110 ),
111 'FullName' => array(
112 'Type' => 'String',
113 'SQL' => 'FullName',
114 'ReadOnly' => false,
115 'Group' => 1,
116 ),
117 'Email' => array(
118 'Type' => 'String',
119 'SQL' => 'Email',
120 'ReadOnly' => false,
121 'Group' => 1,
122 ),
123 );
124 $this->Groups = array(
125 'UserLogin',
126 'UserDetails',
127 );
128 $this->Actions = array(
129 array('Name' => 'Save', 'Module' => 'User', 'Action' => 'Edit'),
130 );
131 }
132
133 function AddProcessRow($Row)
134 {
135 return($Row);
136 }
137}
138
139class UserListWebObject extends ListWebObject
140{
141 function __construct($System)
142 {
143 parent::__construct($System);
144 $this->Table = 'User';
145 $this->SQLJoin = 'WHERE Company='.$this->System->User->Data['Company'];
146 $this->DefaultOrder = array(
147 array('Column' => 'UserName', 'Direction' => 0),
148 );
149 $this->Columns = array(
150 'UserName' => array(
151 'Type' => 'String',
152 'SQL' => 'Name',
153 'ReadOnly' => true,
154 ),
155 'FullName' => array(
156 'Type' => 'String',
157 'SQL' => 'FullName',
158 'ReadOnly' => false,
159 'Group' => 1,
160 ),
161 'Email' => array(
162 'Type' => 'String',
163 'SQL' => 'Email',
164 'ReadOnly' => false,
165 'Group' => 1,
166 ),
167 );
168 $this->Actions = array(
169 array('Name' => 'View', 'Module' => 'User', 'Action' => 'View'),
170 );
171 }
172}
173
174class UserController extends Controller
175{
176 function __construct($System)
177 {
178 parent::__construct($System);
179 $this->Name = 'User';
180 $this->DefaultAction = 'Login';
181 $this->ActionMap = array(
182 'View' => 'View',
183 //'Delete' => 'Delete',
184 'Edit' => 'Edit',
185 //'Add' => 'Add',
186 'Logout' => 'Logout',
187 'Login' => 'Login',
188 'ListPanel' => 'ListPanel',
189 'List' => 'ItemList',
190 );
191 }
192 function Login()
193 {
194 $Output = '';
195 if(array_key_exists('Mode', $_GET)) $Mode = $_GET['Mode'];
196 else $Mode = '';
197 if($Mode == 'Store')
198 {
199 $this->System->Navigation->UnsetParameter('Mode');
200 try {
201 $UserId = $this->System->User->GetByNamePassword($_POST['UserName'], $_POST['Password']);
202 $this->System->UserOnline->Login($UserId);
203 $this->System->User->Id = $this->System->UserOnline->User;
204 $this->System->User->LoadData();
205
206 $_GET['M'] = $this->System->DefaultModule;
207 unset($_GET['A']);
208 $_GET['Panel'] = 1;
209 $Output = $this->System->GetModuleOutput();
210 } catch (UserNotFoundException $E)
211 {
212 $Output .= $this->System->Output->SystemMessage($this->System->Localization->Translate('UserNotFound'));
213 }
214 } else
215 {
216 $LiftItem = new UserLoginWebObject($this->System);
217 $Output .= $this->System->HTML->Panel($this->System->Localization->Translate('UserLogin'),
218 $LiftItem->Show());
219 }
220 return($Output);
221 }
222
223 function Logout()
224 {
225 $this->System->UserOnline->Logout();
226 $this->System->User->Id = $this->System->UserOnline->User;
227 $this->System->User->LoadData();
228 $Output = $this->System->Output->SystemMessage($this->System->Localization->Translate('UserLoggedOut'));
229 return($Output);
230 }
231}
Note: See TracBrowser for help on using the repository browser.