Source for file user.ctrl.php
Documentation is available at user.ctrl.php
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
param( 'user_tab', 'string' );
$AdminUI->set_path( 'users', $user_tab );
param( 'user_ID', 'integer', NULL ); // Note: should NOT be memorized (would kill navigation/sorting) use memorize_param() if needed
* @global boolean true, if user is only allowed to edit his profile
$user_profile_only =
! $current_User->check_perm( 'users', 'view' );
{ // User has no permissions to view: he can only edit his profile
if( isset
($user_ID) &&
$user_ID !=
$current_User->ID )
{ // User is trying to edit something he should not: add error message (Should be prevented by UI)
$Messages->add( T_('You have no permission to view other users!'), 'error' );
// Make sure the user only edits himself:
$user_ID =
$current_User->ID;
if( ! in_array( $action, array( 'update', 'edit', 'default_settings' ) ) )
* Load editable objects and set $action (while checking permissions)
if( $action ==
'update' &&
$user_ID ==
0 )
{ // we create a new user
$edited_User =
new User();
$edited_User->set_datecreated( $localtimenow );
elseif( ($edited_User =
& $UserCache->get_by_ID( $user_ID, false )) ===
false )
{ // We could not find the User to edit:
$Messages->add( sprintf( T_('Requested «%s» object does not exist any longer.'), T_('User') ), 'error' );
{ // check edit permissions
if( ! $current_User->check_perm( 'users', 'edit' )
&&
$edited_User->ID !=
$current_User->ID )
{ // user is only allowed to _view_ other user's profiles
$Messages->add( T_('You have no permission to edit other users!'), 'error' );
{ // Demo mode restrictions: admin/demouser cannot be edited
if( $edited_User->ID ==
1 ||
$edited_User->login ==
'demouser' )
$Messages->add( T_('You cannot edit the admin and demouser profile in demo mode!'), 'error' );
if( strpos( $action, 'delete_' ) ===
0 ||
$action ==
'promote' )
{ // Fallback to list/view action
* Perform actions, if there were no errors:
if( !$Messages->count('error') )
// We want to create a new user:
if( isset
( $edited_User ) )
{ // We want to use a template
$new_User =
$edited_User; // Copy !
$new_User->set( 'ID', 0 );
$edited_User =
& $new_User;
{ // We use an empty user:
$edited_User =
new User();
// Determine if the user must validate before using the system:
$edited_User->set( 'validated', ! $Settings->get('newusers_mustvalidate') );
// Check that this action request is not a CSRF hacked request:
$Session->assert_received_crumb( 'user' );
if( empty($edited_User) ||
!is_object($edited_User) )
$Messages->add( 'No user set!' ); // Needs no translation, should be prevented by UI.
if( !$current_User->check_perm( 'users', 'edit' ) &&
$edited_User->ID !=
$current_User->ID )
{ // user is only allowed to update him/herself
$Messages->add( T_('You are only allowed to update your own profile!'), 'error' );
$edited_User->set( 'avatar_file_ID', NULL, true );
$edited_User->dbupdate();
$Messages->add( T_('Avatar has been removed.'), 'success' );
header_redirect( '?ctrl=user&user_tab=avatar&user_ID='.
$edited_User->ID, 303 ); // will save $Messages into Session
// Update existing user OR create new user:
if( empty($edited_User) ||
!is_object($edited_User) )
$Messages->add( 'No user set!' ); // Needs no translation, should be prevented by UI.
// Check that this action request is not a CSRF hacked request:
$Session->assert_received_crumb( 'user' );
//$reload_page = false; // We set it to true, if a setting changes that needs a page reload (locale, admin skin, ..)
if( !$current_User->check_perm( 'users', 'edit' ) &&
$edited_User->ID !=
$current_User->ID )
{ // user is only allowed to update him/herself
$Messages->add( T_('You are only allowed to update your own profile!'), 'error' );
// load data from request
if( !$edited_User->load_from_Request() )
{ // We have found validation errors:
// if new user is true then it will redirect to user list after user has been created
$is_new_user =
$edited_User->ID ==
0 ?
true :
false;
$is_password_form =
param( 'password_form', 'boolean', false );
if( $edited_User->dbsave() )
$msg =
T_('New user has been created.');
elseif( $is_password_form )
$msg =
T_('Password has been changed.');
$msg =
T_('Profile has been updated.');
$Messages->add($msg, 'success');
if( param( 'preferences_form', 'boolean', false ) )
if( $UserSettings->dbupdate() )
$Messages->add( T_('User feature settings have been changed.'), 'success');
$any_plugin_settings_updated =
false;
while( $loop_Plugin =
& $Plugins->get_next() )
$pluginusersettings =
$loop_Plugin->GetDefaultUserSettings( $tmp_params =
array('for_editing'=>
true) );
if( empty($pluginusersettings) )
// Loop through settings for this plugin:
foreach( $pluginusersettings as $set_name =>
$set_meta )
// Let the plugin handle custom fields:
$ok_to_update =
$Plugins->call_method( $loop_Plugin->ID, 'PluginUserSettingsUpdateAction', $tmp_params =
array(
'User' =>
& $edited_User, 'action' =>
'save' ) );
if( $ok_to_update ===
false )
$any_plugin_settings_updated =
true;
if( $any_plugin_settings_updated )
$Messages->add( T_('Usersettings of Plugins have been updated.'), 'success' );
// Check that this action request is not a CSRF hacked request:
$Session->assert_received_crumb( 'user' );
$reload_page =
false; // We set it to true, if a setting changes that needs a page reload (locale, admin skin, ..)
$cur_admin_skin =
$UserSettings->get('admin_skin');
$UserSettings->delete( 'admin_skin', $edited_User->ID );
&&
$UserSettings->get('admin_skin', $edited_User->ID ) !=
$cur_admin_skin
&&
($edited_User->ID ==
$current_User->ID) )
{ // admin_skin has changed:
// Remove all UserSettings where a default exists:
foreach( $UserSettings->_defaults as $k =>
$v )
$UserSettings->delete( $k, $edited_User->ID );
if( $UserSettings->dbupdate() ) $Messages->add( T_('User feature settings have been changed.'), 'success');
$any_plugin_settings_updated =
false;
while( $loop_Plugin =
& $Plugins->get_next() )
$pluginusersettings =
$loop_Plugin->GetDefaultUserSettings( $tmp_params =
array('for_editing'=>
true) );
if( empty($pluginusersettings) )
foreach( $pluginusersettings as $k =>
$l_meta )
if( isset
($l_meta['layout']) ||
! empty($l_meta['no_edit']) )
{ // a layout "setting" or not for editing
// Let the plugin handle custom fields:
$ok_to_update =
$Plugins->call_method( $loop_Plugin->ID, 'PluginUserSettingsUpdateAction', $tmp_params =
array(
'User' =>
& $edited_User, 'action' =>
'reset' ) );
if( $ok_to_update ===
false )
$any_plugin_settings_updated =
true;
if( $any_plugin_settings_updated )
$Messages->add( T_('Usersettings of Plugins have been updated.'), 'success' );
// Always display the profile again:
{ // reload the current page through header redirection:
$AdminUI->breadcrumbpath_init( false ); // fp> I'm playing with the idea of keeping the current blog in the path here...
$AdminUI->breadcrumbpath_add( T_('Users'), '?ctrl=users' );
$AdminUI->breadcrumbpath_add( $edited_User->login, '?ctrl=user&user_ID='.
$edited_User->ID );
$AdminUI->breadcrumbpath_add( T_('Identity'), '?ctrl=user&user_ID='.
$edited_User->ID.
'&user_tab='.
$user_tab );
$AdminUI->breadcrumbpath_add( T_('Avatar'), '?ctrl=user&user_ID='.
$edited_User->ID.
'&user_tab='.
$user_tab );
$AdminUI->breadcrumbpath_add( T_('Change password'), '?ctrl=user&user_ID='.
$edited_User->ID.
'&user_tab='.
$user_tab );
$AdminUI->breadcrumbpath_add( T_('Preferences'), '?ctrl=user&user_ID='.
$edited_User->ID.
'&user_tab='.
$user_tab );
// Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
$AdminUI->disp_html_head();
// Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
$AdminUI->disp_body_top();
* Display appropriate payload:
// Display user identity form:
$AdminUI->disp_view( 'users/views/_user_identity.form.php' );
// Display user avatar form:
if( $Settings->get('allow_avatars') )
$AdminUI->disp_view( 'users/views/_user_avatar.form.php' );
// Display user password form:
$AdminUI->disp_view( 'users/views/_user_password.form.php' );
// Display user preferences form:
$AdminUI->disp_view( 'users/views/_user_preferences.form.php' );
// Display body bottom, debug info and close </html>:
$AdminUI->disp_global_footer();
* $Log: user.ctrl.php,v $
* Revision 1.10 2010/01/30 18:55:35 blueyed
* Fix "Assigning the return value of new by reference is deprecated" (PHP 5.3)
* Revision 1.9 2010/01/17 16:15:24 sam2kb
* Revision 1.8 2010/01/10 23:24:09 fplanque
* Revision 1.7 2010/01/03 17:45:21 fplanque
* Revision 1.6 2009/12/12 19:14:06 fplanque
* made avatars optional + fixes on img props
* Revision 1.5 2009/12/06 22:55:18 fplanque
* Started breadcrumbs feature in admin.
* Work in progress. Help welcome ;)
* Also move file settings to Files tab and made FM always enabled
* Revision 1.4 2009/12/01 01:52:08 fplanque
* Fixed issue with Debuglog in case of redirect -- Thanks @blueyed for help.
* Revision 1.3 2009/11/30 22:42:44 blueyed
* Fix updating user preferences. This might break something else, please review.
* Revision 1.2 2009/11/21 13:35:00 efy-maxim