Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

admin/useredit.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: useredit.php 9390 2002-04-04 16:14:47Z br $
5 //
6 // Created on: <20-Sep-2000 13:32:11 ce>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "classes/INIFile.php" );
28 // include_once( "classes/eztemplate.php" );
29 // include_once( "classes/ezhttptool.php" );
30
31 $ini =& eZINI::instance( 'site.ini' );
32 $Language = $ini->variable( "eZUserMain", "Language" );
33 $error_msg = false;
34 $error = new eZINI( "kernel/ezuser/admin/intl/" . $Language . "/useredit.php.ini", false );
35
36 // include_once( "ezmail/classes/ezmail.php" );
37 // include_once( "classes/ezlog.php" );
38 // include_once( "ezuser/classes/ezuser.php" );
39 // include_once( "ezuser/classes/ezusergroup.php" );
40
41 require( "kernel/ezuser/admin/admincheck.php" );
42
43 if ( isset( $_POST['DeleteUsers'] ) )
44 {
45 $Action = "DeleteUsers";
46 }
47
48 if ( isset( $_POST['Back'] ) )
49 {
50 eZHTTPTool::header( "Location: /user/userlist/" );
51 exit();
52 }
53
54
55 // do not allow editing users with root access while you do not.
56 $currentUser = eZUser::currentUser();
57
58 if( isset( $_POST['UserID'] ) && $_POST['UserID'] != '' )
59 {
60 $editUser = new eZUser( $_POST['UserID'] );
61 if( !$currentUser->hasRootAccess() && $editUser->hasRootAccess() )
62 {
63 $info = urlencode( "Can't edit a user with root priveliges." );
64 eZHTTPTool::header( "Location: /error/403?Info=$info" );
65 exit();
66 }
67 }
68
69 if ( $Action == "insert" )
70 {
71 if ( eZPermission::checkPermission( $user, "eZUser", "UserAdd" ) )
72 {
73 if ( $_POST['Login'] != "" &&
74 $_POST['Email'] != "" &&
75 $_POST['FirstName'] != "" &&
76 $_POST['LastName'] != "" &&
77 $_POST['SimultaneousLogins'] != "")
78 {
79 if ( ( $_POST['Password'] == $_POST['VerifyPassword'] ) && ( strlen( $_POST['VerifyPassword'] ) > 2 ) )
80 {
81 $user = new eZUser();
82 $user->setLogin( $_POST['Login'] );
83 if ( !$user->exists( $user->login() ) )
84 {
85 $tmp[0] = $_POST['Email'];
86 if ( eZMail::validate( $tmp[0] ) )
87 {
88 $user->setPassword( $_POST['Password'] );
89 $user->setEmail( $_POST['Email'] );
90 $user->setAccountNumber( $_POST['AccountNumber'] );
91 $user->setFirstName( $_POST['FirstName'] );
92 $user->setLastName( $_POST['LastName'] );
93 $user->setSignature( $_POST['Signature'] );
94 $user->setSimultaneousLogins( $_POST['SimultaneousLogins'] );
95
96 if ( $_POST['InfoSubscription'] == "on" )
97 $user->setInfoSubscription( true );
98 else
99 $user->setInfoSubscription( false );
100
101 $user->store();
102 eZPBLog::writeNotice( "User created: " . $_POST['FirstName'] . " " . $_POST['LastName'] ." (" . $_POST['Login'] .") ". $_POST['Email'] . " " . $_POST['SimultaneousLogins'] . " from IP: " . $_SERVER['REMOTE_ADDR'] );
103
104 // Add user to groups
105 $GroupArray = array_unique( array_merge( $_POST['GroupArray'], $_POST['MainGroup'] ) );
106 $group = new eZUserGroup();
107 $user->get( $user->id() );
108 $user->removeGroups();
109 foreach ( $GroupArray as $GroupID )
110 {
111 $group = new eZUserGroup();
112 // $user->get( $user->id() );
113 // $user->removeGroups();
114 $group->get( $GroupID );
115 if ( ( $group->isRoot() && $currentUser->hasRootAccess() ) || !$group->isRoot() )
116 {
117 $group->adduser( $user );
118 $groupname = $group->name();
119 eZPBLog::writeNotice( "User added to group: $groupname from IP: " . $_SERVER['REMOTE_ADDR'] );
120 }
121 }
122
123 $user->setGroupDefinition( $MainGroup );
124 $Action = false;
125 eZHTTPTool::header( "Location: /user/userlist/" );
126 exit();
127 }
128 else
129 {
130 $error_msg = $error->variable( "strings", "error_email" );
131 }
132 }
133 else
134 {
135 $error_msg = $error->variable( "strings", "error_user_exists" );
136 }
137
138 }
139 else
140 {
141 $error_msg = $error->variable( "strings", "error_password" );
142 }
143 }
144 else
145 {
146 $error_msg = $error->variable( "strings", "error_missingdata" );
147 }
148 }
149 else
150 {
151 $error_msg = $error->variable( "strings", "error_norights" );
152 }
153 }
154
155 if ( $Action == "update" )
156 {
157 if ( eZPermission::checkPermission( $user, "eZUser", "UserModify" ) )
158 {
159 if( isset( $_POST['Login'] ) )
160 $Login = $_POST['Login'];
161 if( isset( $_POST['Email'] ) )
162 $Email = $_POST['Email'];
163 if( isset( $_POST['FirstName'] ) )
164 $FirstName = $_POST['FirstName'];
165 if( isset( $_POST['LastName'] ) )
166 $LastName = $_POST['LastName'];
167
168 if( isset( $_POST['AccountNumber'] ) )
169 $AccountNumber = $_POST['AccountNumber'];
170 if( isset( $_POST['Signature'] ) )
171 $Signature = $_POST['Signature'];
172 if( isset( $_POST['SimultaneousLogins'] ) )
173 $SimultaneousLogins = $_POST['SimultaneousLogins'];
174 if( isset( $_POST['InfoSubscription'] ) )
175 $InfoSubscription = $_POST['InfoSubscription'];
176 if( isset( $_POST['Password'] ) )
177 $Password = $_POST['Password'];
178 if( isset( $_POST['VerifyPassword'] ) )
179 $VerifyPassword = $_POST['VerifyPassword'];
180 if( isset( $_POST['UserID'] ) )
181 $UserID = $_POST['UserID'];
182
183 if ( $Email != "" &&
184 $FirstName != "" &&
185 $LastName != "" &&
186 $SimultaneousLogins != "")
187 {
188 if ( ( ( $Password == $VerifyPassword ) && ( strlen( $VerifyPassword ) > 2 ) ) ||
189 ( ( $Password == $VerifyPassword ) && ( strlen( $VerifyPassword ) == 0 ) ) )
190 {
191 $user->setLogin( $Login );
192 {
193 if ( eZMail::validate( $Email ) )
194 {
195 $user = new eZUser();
196 $user->get( $UserID );
197
198 $user->setEmail( $Email );
199 $user->setSignature( $Signature );
200
201 if ( $InfoSubscription == "on" )
202 $user->setInfoSubscription( true );
203 else
204 $user->setInfoSubscription( false );
205
206 $user->setFirstName( $FirstName );
207 $user->setLastName( $LastName );
208 $user->setAccountNumber( $AccountNumber );
209 $user->setSimultaneousLogins( $SimultaneousLogins );
210
211 if ( strlen( $Password ) > 0 )
212 {
213 $user->setPassword( $Password );
214 }
215
216 $user->store();
217 eZPBLog::writeNotice( "User updated: $FirstName $LastName ($Login) $Email from IP: " . $_SERVER['REMOTE_ADDR'] );
218
219 // Remove user from groups
220 $user->removeGroups();
221
222 // Add user to groups
223 if( isset( $_POST['GroupArray'] ) && isset( $_POST['MainGroup'] ) )
224 {
225 $GroupArray = array_unique( array_merge( $_POST['GroupArray'], array( $_POST['MainGroup'] ) ) );
226 }
227 else {
228 $GroupArray[] = $_POST['MainGroup'];
229 }
230 $group = new eZUserGroup();
231 $user->get( $user->id() );
232 $user->removeGroups();
233 foreach ( $GroupArray as $GroupID )
234 {
235 $group = new eZUserGroup();
236 // $user->get( $user->id() );
237 // $user->removeGroups();
238 $group->get( $GroupID );
239 // if ( ( $group->isRoot() && $currentUser->hasRootAccess() ) || !$group->isRoot() )
240 {
241 $group->adduser( $user );
242 $groupname = $group->name();
243 eZPBLog::writeNotice( "User added to group: $groupname from IP: " . $_SERVER['REMOTE_ADDR'] );
244 }
245 }
246
247 $user->setGroupDefinition( $_POST['MainGroup'] );
248 eZHTTPTool::header( "Location: /user/userlist/" );
249 exit();
250 }
251 else
252 {
253 $error_msg = $error->variable( "strings", "error_email" );
254 }
255 }
256
257 }
258 else
259 {
260 $error_msg = $error->variable( "strings", "error_password" );
261 }
262 }
263 else
264 {
265 $error_msg = $error->variable( "strings", "error_missingdata" );
266 }
267 }
268 else
269 {
270 $error_msg = $error->variable( "strings", "error_norights" );
271 }
272 $ActionValue = "update";
273 }
274
275 if ( $Action == "delete" )
276 {
277 if ( eZPermission::checkPermission( $user, "eZUser", "UserDelete" ) )
278 {
279 $user = new eZUser();
280 $user->get( $UserID );
281 $firstName = $user->firstName();
282 $lastName = $user->lastName();
283 $email = $user->email();
284 $login = $user->login();
285 $accountNumber = $user->accountNumber();
286 $simultaneousLogins = $user->simultaneousLogins();
287
288 $user->delete();
289
290 eZPBLog::writeNotice( "User deleted: $firstname $lastname ($login) $email $simultaneousLogins from IP: $REMOTE_ADDR" );
291 eZHTTPTool::header( "Location: /user/userlist/" );
292 exit();
293 }
294 else
295 {
296 $error_msg = $error->variable( "strings", "error_norights" );
297 }
298 }
299 $currentUser = eZUser::currentUser();
300 if ( $Action == "DeleteUsers" )
301 {
302 if( eZPermission::checkPermission( $user, "eZUser", "UserDelete" ) )
303 {
304 if ( count ( $UserArrayID ) != 0 )
305 {
306 foreach( $UserArrayID as $UserID )
307 {
308 $user = new eZUser( $UserID );
309 $login = $user->login();
310 if( $user->hasRootAccess() && !$currentUser->hasRootAccess() )
311 {
312 $currentLogin = $currentUser->login();
313 eZPBLog::writeNotice( "$currentLogin failed to delete user $login since he can't delete users with root privelidges." );
314 }
315 else
316 {
317 $firstName = $user->firstName();
318 $lastName = $user->lastName();
319 $email = $user->email();
320 $login = $user->login();
321 $simultaneousLogins = $user->simultaneousLogins();
322
323 $user->delete();
324
325 eZPBLog::writeNotice( "User deleted: $firstname $lastname ($login) $email $simultaneousLogins from IP: $REMOTE_ADDR" );
326 }
327 }
328 }
329 }
330 eZHTTPTool::header( "Location: /user/userlist/" );
331 exit();
332 }
333
334 $t = new eZTemplate( "kernel/ezuser/admin/" . $ini->variable( "eZUserMain", "AdminTemplateDir" ),
335 "kernel/ezuser/admin/" . "/intl", $Language, "useredit.php" );
336 $t->setAllStrings();
337
338 $t->set_file( array(
339 "user_edit" => "useredit.tpl"
340 ) );
341
342 $t->set_block( "user_edit", "main_group_item_tpl", "main_group_item" );
343 $t->set_block( "user_edit", "group_item_tpl", "group_item" );
344
345 if ( $Action == "new" )
346 {
347 $FirstName = "";
348 $Lastname = "";
349 $Email = "";
350 $Login = "";
351 $Phone = "";
352 $Signature = "";
353 $UserID = eZUser::currentUser()->ID;
354 $AccountNumber = "";
355 $SimultaneousLogins = $ini->variable( "eZUserMain", "DefaultSimultaneousLogins" );
356 }
357
358 $ActionValue = "insert";
359
360 if ( $Action == "update" )
361 {
362 $ActionValue = "update";
363 }
364
365 $headline = new eZINI( "kernel/ezuser/admin/intl/" . $Language . "/useredit.php.ini", false );
366 $t->set_var( "head_line", $headline->variable( "strings", "head_line_insert" ) );
367
368 $group = new eZUserGroup();
369
370 $groupList = $group->getAll();
371
372
373 $user = 0;
374 $t->set_var( "read_only", "" );
375 $user = new eZUser();
376
377 if( isset( $_POST['UserID'] ) )
378 $UserID = $_POST['UserID'];
379
380 $user->get( $UserID );
381
382 if ( $Action == "edit" )
383 {
384 /*
385 $messages =& eZForumMessage::lastMessages( 10 , $user, $UserID );
386 echo "<pre>";
387 print_r($messages);
388 echo "</pre>";
389 exit;
390 */
391 if( $user->infoSubscription() == true )
392 $InfoSubscription = "checked";
393 else
394 $InfoSubscription = "";
395
396 $FirstName = $user->firstName();
397 $LastName = $user->lastName();
398 $Email = $user->email();
399 $Login = $user->login();
400 $AccountNumber = $user->accountNumber();
401 $Signature = $user->signature();
402 $SimultaneousLogins = $user->simultaneousLogins();
403
404 $headline = new eZINI( "kernel/ezuser/admin/intl/" . $Language . "/useredit.php.ini", false );
405 $t->set_var( "head_line", $headline->variable( "strings", "head_line_edit" ) );
406
407 $t->set_var( "read_only", "readonly=readonly" );
408
409 $ActionValue = "update";
410 }
411 else // either new or failed edit... must put htmlspecialchars on stuff we got from form.
412 {
413 $Login = false;
414 $Email = false;
415 $FirstName = false;
416 $LastName = false;
417 $Signature = false;
418 $SimultaneousLogins = false;
419 $InfoSubscription = false;
420
421
422 if( isset( $_POST['Login'] ) )
423 $Login = $_POST['Login'];
424 if( isset( $_POST['Email'] ) )
425 $Email = $_POST['Email'];
426 if( isset( $_POST['FirstName'] ) )
427 $FirstName = $_POST['FirstName'];
428 if( isset( $_POST['LastName'] ) )
429 $LastName = $_POST['LastName'];
430 if( isset( $_POST['Phone'] ) )
431 $Phone = $_POST['Phone'];
432 if( isset( $_POST['Signature'] ) )
433 $Signature = $_POST['Signature'];
434 if( isset( $_POST['SimultaneousLogins'] ) )
435 $SimultaneousLogins = $_POST['SimultaneousLogins'];
436 if( isset( $_POST['InfoSubscription'] ) )
437 $InfoSubscription = $_POST['InfoSubscription'];
438 if( isset( $_POST['UserID'] ) )
439 $UserID = $_POST['UserID'];
440
441 $FirstName = htmlspecialchars( $FirstName );
442 $LastName = htmlspecialchars( $LastName );
443 $Phone = htmlspecialchars( $Phone );
444 $LastName = htmlspecialchars( $LastName );
445 $Login = htmlspecialchars( $Login );
446 $AccountNumber = htmlspecialchars( $AccountNumber );
447 $Signature = htmlspecialchars( $Signature );
448 $Email = htmlspecialchars( $Email );
449 }
450
451 $mainGroup = $user->groupDefinition();
452 $groupArray = $user->groups();
453 foreach ( $groupList as $groupItem )
454 {
455 $t->set_var( "group_name", $groupItem->name() );
456 $t->set_var( "group_id", $groupItem->id() );
457
458 if ( $mainGroup == $groupItem->id() )
459 $t->set_var( "main_selected", "selected" );
460 else
461 $t->set_var( "main_selected", "" );
462
463 // add validation code here. $user->isValid();
464 if ( $user )
465 {
466 $found = false;
467 foreach ( $groupArray as $group )
468 {
469 if ( $group->id() == $groupItem->id() && $group->id() != $mainGroup )
470 {
471 $found = true;
472 }
473 }
474 if ( $found == true )
475 $t->set_var( "selected", "selected" );
476 else
477 $t->set_var( "selected", "" );
478 }
479 else
480 {
481 $t->set_var( "selected", "" );
482 }
483
484 $t->parse( "main_group_item", "main_group_item_tpl", true );
485 $t->parse( "group_item", "group_item_tpl", true );
486 }
487
488 $t->set_var( "info_subscription", $InfoSubscription );
489 $t->set_var( "error", $error_msg );
490 $t->set_var( "first_name_value", $FirstName );
491 $t->set_var( "last_name_value", $LastName );
492 $t->set_var( "email_value", $Email );
493 $t->set_var( "phone_value", $Phone );
494 $t->set_var( "login_value", $Login );
495 $t->set_var( "account_number_value", $AccountNumber );
496 $t->set_var( "signature", $Signature );
497 $t->set_var( "password_value", "" );
498 $t->set_var( "verify_password_value", "" );
499 $t->set_var( "action_value", $ActionValue );
500 $t->set_var( "user_id", $UserID );
501 $t->set_var( "simultaneouslogins_value", $SimultaneousLogins );
502 $t->pparse( "output", "user_edit" );
503
504 ?>
$Password
$Password
Definition: admin/seti.php:21
$t
if( $Action=="DeleteUsers") $t
Definition: admin/useredit.php:334
$Email
$Email
Definition: admin/useredit.php:414
$mainGroup
$mainGroup
Definition: admin/useredit.php:451
$user
$user
Definition: admin/useredit.php:373
$LastName
$LastName
Definition: admin/useredit.php:416
$SimultaneousLogins
$SimultaneousLogins
Definition: admin/useredit.php:418
$currentUser
if(isset( $_POST['DeleteUsers'])) if(isset( $_POST['Back'])) $currentUser
Definition: admin/useredit.php:56
$groupArray
$groupArray
Definition: admin/useredit.php:452
$FirstName
$FirstName
Definition: admin/useredit.php:415
$AccountNumber
$AccountNumber
Definition: admin/useredit.php:446
$groupList
$groupList
Definition: admin/useredit.php:370
$Language
$Language
Definition: admin/useredit.php:32
$ini
$ini
Definition: admin/useredit.php:31
$Phone
$Phone
Definition: admin/useredit.php:443
$headline
if( $Action=="update") $headline
Definition: admin/useredit.php:365
$InfoSubscription
$InfoSubscription
Definition: admin/useredit.php:419
$error_msg
$error_msg
Definition: admin/useredit.php:33
$group
$group
Definition: admin/useredit.php:368
$ActionValue
if( $Action=="new") $ActionValue
Definition: admin/useredit.php:358
$Signature
$Signature
Definition: admin/useredit.php:417
$error
$error
Definition: admin/useredit.php:34
$Login
$Login
Definition: admin/useredit.php:445
$tmp
$tmp
Definition: bugview.php:99
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZINI
Reads and writes .ini style configuration files.
eZMail\validate
static validate( $address)
Definition: ezmail.php:599
eZPBLog\writeNotice
static writeNotice( $notice)
Definition: ezpblog.php:166
eZPermission\checkPermission
static checkPermission( $user, $moduleName, $permissionName)
Definition: ezpermission.php:430
eZTemplate
Definition: eztemplate.php:107
eZUserGroup
Definition: ezusergroup.php:66
eZUser
Definition: ezuser.php:76
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$Action
$Action
Definition: companysearch.php:80
$accountNumber
$accountNumber
Definition: corporate_account.php:60
exit
exit
Definition: folder.php:81
$GroupID
$GroupID
Definition: rssheadlines.php:51
$UserID
$UserID
Definition: todoedit.php:122
$VerifyPassword
if(( $ForceSSL=="enabled")) elseif( $ForceSSL=="disabled") $VerifyPassword
Definition: userwithaddress.php:76
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.