[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/user/ -> user_bulk_delete.php (source)

   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  require_login();
  12  admin_externalpage_setup('userbulk');
  13  require_capability('moodle/user:delete', 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  echo $OUTPUT->header();
  22  
  23  //TODO: add support for large number of users
  24  
  25  if ($confirm and confirm_sesskey()) {
  26      $notifications = '';
  27      list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
  28      $rs = $DB->get_recordset_select('user', "id $in", $params);
  29      foreach ($rs as $user) {
  30          if (!is_siteadmin($user) and $USER->id != $user->id and delete_user($user)) {
  31              unset($SESSION->bulk_users[$user->id]);
  32          } else {
  33              $notifications .= $OUTPUT->notification(get_string('deletednot', '', fullname($user, true)));
  34          }
  35      }
  36      $rs->close();
  37      \core\session\manager::gc(); // Remove stale sessions.
  38      echo $OUTPUT->box_start('generalbox', 'notice');
  39      if (!empty($notifications)) {
  40          echo $notifications;
  41      } else {
  42          echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
  43      }
  44      $continue = new single_button(new moodle_url($return), get_string('continue'), 'post');
  45      echo $OUTPUT->render($continue);
  46      echo $OUTPUT->box_end();
  47  } else {
  48      list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
  49      $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
  50      $usernames = implode(', ', $userlist);
  51      echo $OUTPUT->heading(get_string('confirmation', 'admin'));
  52      $formcontinue = new single_button(new moodle_url('user_bulk_delete.php', array('confirm' => 1)), get_string('yes'));
  53      $formcancel = new single_button(new moodle_url('user_bulk.php'), get_string('no'), 'get');
  54      echo $OUTPUT->confirm(get_string('deletecheckfull', '', $usernames), $formcontinue, $formcancel);
  55  }
  56  
  57  echo $OUTPUT->footer();


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1