b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: main ] [ index: main ] [ all elements ]

Source for file user.ctrl.php

Documentation is available at user.ctrl.php

  1. <?php
  2.  
  3. if!defined('EVO_MAIN_INIT') ) die'Please, do not access this page directly.' );
  4.  
  5. /**
  6.  * @var AdminUI_general 
  7.  */
  8. global $AdminUI;
  9.  
  10. param'user_tab''string' );
  11. ifempty($user_tab) )
  12. {
  13.     $user_tab 'identity';
  14. }
  15.  
  16. $AdminUI->set_path'users'$user_tab );
  17.  
  18.  
  19. param'user_ID''integer'NULL );    // Note: should NOT be memorized (would kill navigation/sorting) use memorize_param() if needed
  20.  
  21. /**
  22.  * @global boolean true, if user is only allowed to edit his profile
  23.  */
  24. $user_profile_only $current_User->check_perm'users''view' );
  25.  
  26. if$user_profile_only )
  27. // User has no permissions to view: he can only edit his profile
  28.  
  29.     ifisset($user_ID&& $user_ID != $current_User->ID )
  30.     // User is trying to edit something he should not: add error message (Should be prevented by UI)
  31.         $Messages->addT_('You have no permission to view other users!')'error' );
  32.     }
  33.  
  34.     // Make sure the user only edits himself:
  35.     $user_ID $current_User->ID;
  36.     ifin_array$actionarray'update''edit''default_settings' ) ) )
  37.     {
  38.         $action 'edit';
  39.     }
  40. }
  41.  
  42. /*
  43.  * Load editable objects and set $action (while checking permissions)
  44.  */
  45.  
  46. $UserCache get_UserCache();
  47.  
  48. ifis_null($user_ID) )
  49. // User selected
  50.     if$action == 'update' && $user_ID == )
  51.     // we create a new user
  52.         $edited_User new User();
  53.         $edited_User->set_datecreated$localtimenow );
  54.     }
  55.     elseif( ($edited_User $UserCache->get_by_ID$user_IDfalse )) === false )
  56.     {    // We could not find the User to edit:
  57.         unset$edited_User );
  58.         forget_param'user_ID' );
  59.         $Messages->addsprintfT_('Requested &laquo;%s&raquo; object does not exist any longer.')T_('User') )'error' );
  60.         $action 'list';
  61.     }
  62.  
  63.     if$action != 'view' )
  64.     // check edit permissions
  65.         if$current_User->check_perm'users''edit' )
  66.             && $edited_User->ID != $current_User->ID )
  67.         // user is only allowed to _view_ other user's profiles
  68.             $Messages->addT_('You have no permission to edit other users!')'error' );
  69.             $action 'view';
  70.         }
  71.         elseif$demo_mode )
  72.         // Demo mode restrictions: admin/demouser cannot be edited
  73.             if$edited_User->ID == || $edited_User->login == 'demouser' )
  74.             {
  75.                 $Messages->addT_('You cannot edit the admin and demouser profile in demo mode!')'error' );
  76.  
  77.                 ifstrpos$action'delete_' === || $action == 'promote' )
  78.                 {   // Fallback to list/view action
  79.                     header_redirectregenerate_url'ctrl,action''ctrl=users&amp;action=list' ) );
  80.                 }
  81.                 else
  82.                 {
  83.                     $action 'view';
  84.                 }
  85.             }
  86.         }
  87.     }
  88. }
  89.  
  90. /*
  91.  * Perform actions, if there were no errors:
  92.  */
  93. if!$Messages->count('error') )
  94. // no errors
  95.     switch$action )
  96.     {
  97.         case 'new':
  98.             // We want to create a new user:
  99.             ifisset$edited_User ) )
  100.             // We want to use a template
  101.                 $new_User $edited_User// Copy !
  102.                 $new_User->set'ID');
  103.                 $edited_User $new_User;
  104.             }
  105.             else
  106.             // We use an empty user:
  107.                 $edited_User new User();
  108.             }
  109.  
  110.             // Determine if the user must validate before using the system:
  111.             $edited_User->set'validated'$Settings->get('newusers_mustvalidate') );
  112.             break;
  113.  
  114.         case 'remove_avatar':
  115.             // Check that this action request is not a CSRF hacked request:
  116.             $Session->assert_received_crumb'user' );
  117.  
  118.             ifempty($edited_User|| !is_object($edited_User) )
  119.             {
  120.                 $Messages->add'No user set!' )// Needs no translation, should be prevented by UI.
  121.                 $action 'list';
  122.                 break;
  123.             }
  124.  
  125.             if!$current_User->check_perm'users''edit' && $edited_User->ID != $current_User->ID )
  126.             // user is only allowed to update him/herself
  127.                 $Messages->addT_('You are only allowed to update your own profile!')'error' );
  128.                 $action 'view';
  129.                 break;
  130.             }
  131.  
  132.             $edited_User->set'avatar_file_ID'NULLtrue );
  133.  
  134.             $edited_User->dbupdate();
  135.  
  136.             $Messages->addT_('Avatar has been removed.')'success' );
  137.  
  138.             header_redirect'?ctrl=user&user_tab=avatar&user_ID='.$edited_User->ID303 )// will save $Messages into Session
  139.             /* EXITED */
  140.             break;
  141.  
  142.         case 'update':
  143.             // Update existing user OR create new user:
  144.             ifempty($edited_User|| !is_object($edited_User) )
  145.             {
  146.                 $Messages->add'No user set!' )// Needs no translation, should be prevented by UI.
  147.                 $action 'list';
  148.                 break;
  149.             }
  150.  
  151.             // Check that this action request is not a CSRF hacked request:
  152.             $Session->assert_received_crumb'user' );
  153.  
  154.             //$reload_page = false; // We set it to true, if a setting changes that needs a page reload (locale, admin skin, ..)
  155.  
  156.             if!$current_User->check_perm'users''edit' && $edited_User->ID != $current_User->ID )
  157.             // user is only allowed to update him/herself
  158.                 $Messages->addT_('You are only allowed to update your own profile!')'error' );
  159.                 $action 'view';
  160.                 break;
  161.             }
  162.  
  163.             // load data from request
  164.             if!$edited_User->load_from_Request() )
  165.             {    // We have found validation errors:
  166.                 $action 'edit';
  167.                 break;
  168.             }
  169.  
  170.             // if new user is true then it will redirect to user list after user has been created
  171.             $is_new_user $edited_User->ID == true false;
  172.  
  173.             // Update user
  174.             $is_password_form param'password_form''boolean'false );
  175.             if$edited_User->dbsave() )
  176.             {
  177.                 if$is_new_user )
  178.                     $msg T_('New user has been created.');
  179.                 elseif$is_password_form )
  180.                     $msg T_('Password has been changed.');
  181.                 else
  182.                     $msg T_('Profile has been updated.');
  183.                 $Messages->add($msg'success');
  184.             }
  185.  
  186.             // Update user settings:
  187.             ifparam'preferences_form''boolean'false ) )
  188.             {
  189.                 if$UserSettings->dbupdate() )
  190.                 {
  191.                     $Messages->addT_('User feature settings have been changed.')'success');
  192.                 }
  193.  
  194.                 // PluginUserSettings
  195.                 load_funcs('plugins/_plugin.funcs.php');
  196.  
  197.                 $any_plugin_settings_updated false;
  198.                 $Plugins->restart();
  199.                 while$loop_Plugin $Plugins->get_next() )
  200.                 {
  201.                     $pluginusersettings $loop_Plugin->GetDefaultUserSettings$tmp_params array('for_editing'=>true) );
  202.                     ifempty($pluginusersettings) )
  203.                     {
  204.                         continue;
  205.                     }
  206.  
  207.                     // Loop through settings for this plugin:
  208.                     foreach$pluginusersettings as $set_name => $set_meta )
  209.                     {
  210.                         autoform_set_param_from_request$set_name$set_meta$loop_Plugin'UserSettings'$edited_User );
  211.                     }
  212.  
  213.                     // Let the plugin handle custom fields:
  214.                     $ok_to_update $Plugins->call_method$loop_Plugin->ID'PluginUserSettingsUpdateAction'$tmp_params array(
  215.                         'User' => $edited_User'action' => 'save' ) );
  216.  
  217.                     if$ok_to_update === false )
  218.                     {
  219.                         $loop_Plugin->UserSettings->reset();
  220.                     }
  221.                     elseif$loop_Plugin->UserSettings->dbupdate() )
  222.                     {
  223.                         $any_plugin_settings_updated true;
  224.                     }
  225.                 }
  226.  
  227.                 if$any_plugin_settings_updated )
  228.                 {
  229.                     $Messages->addT_('Usersettings of Plugins have been updated.')'success' );
  230.                 }
  231.             }
  232.  
  233.             if$is_new_user )
  234.             {
  235.                 header_redirectregenerate_url'ctrl,action''ctrl=users&amp;action=list''''&' )303 );
  236.             }
  237.             else
  238.             {
  239.                 header_redirectregenerate_url'''user_ID='.$edited_User->ID.'&action=edit&user_tab='.$user_tab'''&' )303 );
  240.             }
  241.             break;
  242.  
  243.         case 'default_settings':
  244.             // Check that this action request is not a CSRF hacked request:
  245.             $Session->assert_received_crumb'user' );
  246.  
  247.             $reload_page false// We set it to true, if a setting changes that needs a page reload (locale, admin skin, ..)
  248.  
  249.             // Admin skin:
  250.             $cur_admin_skin $UserSettings->get('admin_skin');
  251.  
  252.             $UserSettings->delete'admin_skin'$edited_User->ID );
  253.             if$cur_admin_skin
  254.                     && $UserSettings->get('admin_skin'$edited_User->ID != $cur_admin_skin
  255.                     && ($edited_User->ID == $current_User->ID) )
  256.             // admin_skin has changed:
  257.                 $reload_page true;
  258.             }
  259.  
  260.             // Remove all UserSettings where a default exists:
  261.             foreach$UserSettings->_defaults as $k => $v )
  262.             {
  263.                 $UserSettings->delete$k$edited_User->ID );
  264.             }
  265.  
  266.             // Update user settings:
  267.             if$UserSettings->dbupdate() ) $Messages->addT_('User feature settings have been changed.')'success');
  268.  
  269.             // PluginUserSettings
  270.             $any_plugin_settings_updated false;
  271.             $Plugins->restart();
  272.             while$loop_Plugin $Plugins->get_next() )
  273.             {
  274.                 $pluginusersettings $loop_Plugin->GetDefaultUserSettings$tmp_params array('for_editing'=>true) );
  275.  
  276.                 ifempty($pluginusersettings) )
  277.                 {
  278.                     continue;
  279.                 }
  280.  
  281.                 foreach$pluginusersettings as $k => $l_meta )
  282.                 {
  283.                     ifisset($l_meta['layout']|| empty($l_meta['no_edit']) )
  284.                     // a layout "setting" or not for editing
  285.                         continue;
  286.                     }
  287.  
  288.                     $loop_Plugin->UserSettings->delete($k$edited_User->ID);
  289.                 }
  290.  
  291.                 // Let the plugin handle custom fields:
  292.                 $ok_to_update $Plugins->call_method$loop_Plugin->ID'PluginUserSettingsUpdateAction'$tmp_params array(
  293.                     'User' => $edited_User'action' => 'reset' ) );
  294.  
  295.                 if$ok_to_update === false )
  296.                 {
  297.                     $loop_Plugin->UserSettings->reset();
  298.                 }
  299.                 elseif$loop_Plugin->UserSettings->dbupdate() )
  300.                 {
  301.                     $any_plugin_settings_updated true;
  302.                 }
  303.             }
  304.             if$any_plugin_settings_updated )
  305.             {
  306.                 $Messages->addT_('Usersettings of Plugins have been updated.')'success' );
  307.             }
  308.  
  309.             // Always display the profile again:
  310.             $action 'edit';
  311.  
  312.             if$reload_page )
  313.             // reload the current page through header redirection:
  314.                 header_redirectregenerate_url'''user_ID='.$edited_User->ID.'&action='.$action'''&' ) )// will save $Messages into Session
  315.             }
  316.             break;
  317.     }
  318. }
  319.  
  320.  
  321. $AdminUI->breadcrumbpath_initfalse );  // fp> I'm playing with the idea of keeping the current blog in the path here...
  322. $AdminUI->breadcrumbpath_addT_('Users')'?ctrl=users' );
  323. $AdminUI->breadcrumbpath_add$edited_User->login'?ctrl=user&amp;user_ID='.$edited_User->ID );
  324. switch$user_tab )
  325. {
  326.     case 'identity':
  327.         $AdminUI->breadcrumbpath_addT_('Identity')'?ctrl=user&amp;user_ID='.$edited_User->ID.'&amp;user_tab='.$user_tab );
  328.         break;
  329.     case 'avatar':
  330.         $AdminUI->breadcrumbpath_addT_('Avatar')'?ctrl=user&amp;user_ID='.$edited_User->ID.'&amp;user_tab='.$user_tab );
  331.         break;
  332.     case 'password':
  333.         $AdminUI->breadcrumbpath_addT_('Change password')'?ctrl=user&amp;user_ID='.$edited_User->ID.'&amp;user_tab='.$user_tab );
  334.         break;
  335.     case 'preferences':
  336.         $AdminUI->breadcrumbpath_addT_('Preferences')'?ctrl=user&amp;user_ID='.$edited_User->ID.'&amp;user_tab='.$user_tab );
  337.         break;
  338. }
  339.  
  340. // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
  341. $AdminUI->disp_html_head();
  342.  
  343. // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
  344. $AdminUI->disp_body_top();
  345.  
  346. /*
  347.  * Display appropriate payload:
  348.  */
  349. switch$action )
  350. {
  351.     case 'nil':
  352.         // Display NO payload!
  353.         break;
  354.  
  355.     case 'new':
  356.     case 'view':
  357.     case 'edit':
  358.     default:
  359.  
  360.         switch$user_tab )
  361.         {
  362.             case 'identity':
  363.                 // Display user identity form:
  364.                 $AdminUI->disp_view'users/views/_user_identity.form.php' );
  365.                 break;
  366.             case 'avatar':
  367.                 // Display user avatar form:
  368.                 if$Settings->get('allow_avatars') )
  369.                 {
  370.                     $AdminUI->disp_view'users/views/_user_avatar.form.php' );
  371.                 }
  372.                 break;
  373.             case 'password':
  374.                 // Display user password form:
  375.                 $AdminUI->disp_view'users/views/_user_password.form.php' );
  376.                 break;
  377.             case 'preferences':
  378.                 // Display user preferences form:
  379.                 $AdminUI->disp_view'users/views/_user_preferences.form.php' );
  380.                 break;
  381.         }
  382.  
  383.         break;
  384. }
  385.  
  386.  
  387. // Display body bottom, debug info and close </html>:
  388. $AdminUI->disp_global_footer();
  389.  
  390. /*
  391.  * $Log: user.ctrl.php,v $
  392.  * Revision 1.10  2010/01/30 18:55:35  blueyed
  393.  * Fix "Assigning the return value of new by reference is deprecated" (PHP 5.3)
  394.  *
  395.  * Revision 1.9  2010/01/17 16:15:24  sam2kb
  396.  * Localization clean-up
  397.  *
  398.  * Revision 1.8  2010/01/10 23:24:09  fplanque
  399.  * crumbs...
  400.  *
  401.  * Revision 1.7  2010/01/03 17:45:21  fplanque
  402.  * crumbs & stuff
  403.  *
  404.  * Revision 1.6  2009/12/12 19:14:06  fplanque
  405.  * made avatars optional + fixes on img props
  406.  *
  407.  * Revision 1.5  2009/12/06 22:55:18  fplanque
  408.  * Started breadcrumbs feature in admin.
  409.  * Work in progress. Help welcome ;)
  410.  * Also move file settings to Files tab and made FM always enabled
  411.  *
  412.  * Revision 1.4  2009/12/01 01:52:08  fplanque
  413.  * Fixed issue with Debuglog in case of redirect -- Thanks @blueyed for help.
  414.  *
  415.  * Revision 1.3  2009/11/30 22:42:44  blueyed
  416.  * Fix updating user preferences. This might break something else, please review.
  417.  *
  418.  * Revision 1.2  2009/11/21 13:35:00  efy-maxim
  419.  * log
  420.  *
  421.  */
  422. ?>

Documentation generated on Sat, 06 Mar 2010 03:58:53 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).