Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   1  <?php
   2  /**
   3  * script for bulk user force password change
   4  */
   5  
   6  require_once('../../config.php');
   7  require_once ('lib.php');
   8  require_once($CFG->libdir.'/adminlib.php');
   9  
  10  $confirm = optional_param('confirm', 0, PARAM_BOOL);
  11  
  12  admin_externalpage_setup('userbulk');
  13  require_capability('moodle/user:update', context_system::instance());
  14  
  15  $return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
  16  
  17  if (empty($SESSION->bulk_users)) {
  18      redirect($return);
  19  }
  20  
  21  $PAGE->set_primary_active_tab('siteadminnode');
  22  $PAGE->set_secondary_active_tab('users');
  23  
  24  echo $OUTPUT->header();
  25  
  26  if ($confirm and confirm_sesskey()) {
  27      // only force password change if user may actually change the password
  28      $authsavailable = get_enabled_auth_plugins();
  29      $changeable = array();
  30  
  31      foreach($authsavailable as $authplugin) {
  32          if (!$auth = get_auth_plugin($authplugin)) {
  33              continue;
  34          }
  35          if ($auth->is_internal() and $auth->can_change_password()) {
  36              $changeable[$authplugin] = true;
  37          }
  38      }
  39  
  40      $parts = array_chunk($SESSION->bulk_users, 300);
  41      foreach ($parts as $users) {
  42          list($in, $params) = $DB->get_in_or_equal($users);
  43          $rs = $DB->get_recordset_select('user', "id $in", $params);
  44          foreach ($rs as $user) {
  45              if (!empty($changeable[$user->auth])) {
  46                  set_user_preference('auth_forcepasswordchange', 1, $user->id);
  47                  unset($SESSION->bulk_users[$user->id]);
  48              } else {
  49                  echo $OUTPUT->notification(get_string('forcepasswordchangenot', '', fullname($user, true)));
  50              }
  51          }
  52          $rs->close();
  53      }
  54      echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
  55      echo $OUTPUT->continue_button($return);
  56  
  57  } else {
  58      list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
  59      $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname', 0, MAX_BULK_USERS);
  60      $usernames = implode(', ', $userlist);
  61      if (count($SESSION->bulk_users) > MAX_BULK_USERS) {
  62          $usernames .= ', ...';
  63      }
  64      echo $OUTPUT->heading(get_string('confirmation', 'admin'));
  65      $formcontinue = new single_button(new moodle_url('/admin/user/user_bulk_forcepasswordchange.php', array('confirm' => 1)), get_string('yes'));
  66      $formcancel = new single_button(new moodle_url('/admin/user/user_bulk.php'), get_string('no'), 'get');
  67      echo $OUTPUT->confirm(get_string('forcepasswordchangecheckfull', '', $usernames), $formcontinue, $formcancel);
  68  }
  69  
  70  echo $OUTPUT->footer();