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 delete operations
   4  */
   5  
   6  require_once('../../config.php');
   7  require_once($CFG->libdir.'/adminlib.php');
   8  
   9  $confirm = optional_param('confirm', 0, PARAM_BOOL);
  10  
  11  admin_externalpage_setup('userbulk');
  12  require_capability('moodle/user:update', context_system::instance());
  13  
  14  $return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
  15  
  16  if (empty($SESSION->bulk_users)) {
  17      redirect($return);
  18  }
  19  
  20  $PAGE->set_primary_active_tab('siteadminnode');
  21  $PAGE->set_secondary_active_tab('users');
  22  
  23  echo $OUTPUT->header();
  24  
  25  //TODO: add support for large number of users
  26  
  27  if ($confirm and confirm_sesskey()) {
  28      $notifications = '';
  29      list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
  30      $rs = $DB->get_recordset_select('user', "id $in", $params, '', 'id, username, secret, confirmed, auth, firstname, lastname');
  31      foreach ($rs as $user) {
  32          if ($user->confirmed) {
  33              continue;
  34          }
  35          $auth = get_auth_plugin($user->auth);
  36          $result = $auth->user_confirm($user->username, $user->secret);
  37          if ($result != AUTH_CONFIRM_OK && $result != AUTH_CONFIRM_ALREADY) {
  38              $notifications .= $OUTPUT->notification(get_string('usernotconfirmed', '', fullname($user, true)));
  39          }
  40      }
  41      $rs->close();
  42      echo $OUTPUT->box_start('generalbox', 'notice');
  43      if (!empty($notifications)) {
  44          echo $notifications;
  45      } else {
  46          echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
  47      }
  48      $continue = new single_button(new moodle_url($return), get_string('continue'), 'post');
  49      echo $OUTPUT->render($continue);
  50      echo $OUTPUT->box_end();
  51  } else {
  52      list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
  53      $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
  54      $usernames = implode(', ', $userlist);
  55      echo $OUTPUT->heading(get_string('confirmation', 'admin'));
  56      $formcontinue = new single_button(new moodle_url('user_bulk_confirm.php', array('confirm' => 1)), get_string('yes'));
  57      $formcancel = new single_button(new moodle_url('user_bulk.php'), get_string('no'), 'get');
  58      echo $OUTPUT->confirm(get_string('confirmcheckfull', '', $usernames), $formcontinue, $formcancel);
  59  }
  60  
  61  echo $OUTPUT->footer();