Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   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  echo $OUTPUT->header();
  21  
  22  //TODO: add support for large number of users
  23  
  24  if ($confirm and confirm_sesskey()) {
  25      $notifications = '';
  26      list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
  27      $rs = $DB->get_recordset_select('user', "id $in", $params, '', 'id, username, secret, confirmed, auth, firstname, lastname');
  28      foreach ($rs as $user) {
  29          if ($user->confirmed) {
  30              continue;
  31          }
  32          $auth = get_auth_plugin($user->auth);
  33          $result = $auth->user_confirm($user->username, $user->secret);
  34          if ($result != AUTH_CONFIRM_OK && $result != AUTH_CONFIRM_ALREADY) {
  35              $notifications .= $OUTPUT->notification(get_string('usernotconfirmed', '', fullname($user, true)));
  36          }
  37      }
  38      $rs->close();
  39      echo $OUTPUT->box_start('generalbox', 'notice');
  40      if (!empty($notifications)) {
  41          echo $notifications;
  42      } else {
  43          echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
  44      }
  45      $continue = new single_button(new moodle_url($return), get_string('continue'), 'post');
  46      echo $OUTPUT->render($continue);
  47      echo $OUTPUT->box_end();
  48  } else {
  49      list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
  50      $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
  51      $usernames = implode(', ', $userlist);
  52      echo $OUTPUT->heading(get_string('confirmation', 'admin'));
  53      $formcontinue = new single_button(new moodle_url('user_bulk_confirm.php', array('confirm' => 1)), get_string('yes'));
  54      $formcancel = new single_button(new moodle_url('user_bulk.php'), get_string('no'), 'get');
  55      echo $OUTPUT->confirm(get_string('confirmcheckfull', '', $usernames), $formcontinue, $formcancel);
  56  }
  57  
  58  echo $OUTPUT->footer();