3 * script for bulk user delete operations
6 require_once('../../config.php');
7 require_once($CFG->libdir
.'/adminlib.php');
9 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
11 admin_externalpage_setup('userbulk');
12 require_capability('moodle/user:delete', context_system
::instance());
14 $returnurl = optional_param('returnurl', '', PARAM_LOCALURL
);
15 $return = new moodle_url($returnurl ?
: '/admin/user/user_bulk.php');
17 if (empty($SESSION->bulk_users
)) {
21 $PAGE->set_primary_active_tab('siteadminnode');
22 $PAGE->set_secondary_active_tab('users');
24 echo $OUTPUT->header();
26 //TODO: add support for large number of users
28 if ($confirm and confirm_sesskey()) {
30 list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users
);
31 $rs = $DB->get_recordset_select('user', "deleted = 0 and id $in", $params);
32 foreach ($rs as $user) {
33 if (!is_siteadmin($user) and $USER->id
!= $user->id
and delete_user($user)) {
34 unset($SESSION->bulk_users
[$user->id
]);
36 $notifications .= $OUTPUT->notification(get_string('deletednot', '', fullname($user, true)));
40 \core\session\manager
::gc(); // Remove stale sessions.
41 echo $OUTPUT->box_start('generalbox', 'notice');
42 if (!empty($notifications)) {
45 echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
47 $continue = new single_button($return, get_string('continue'), 'post');
48 echo $OUTPUT->render($continue);
49 echo $OUTPUT->box_end();
51 list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users
);
52 $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
53 $usernames = implode(', ', $userlist);
54 echo $OUTPUT->heading(get_string('confirmation', 'admin'));
55 $formcontinue = new single_button(new moodle_url('user_bulk_delete.php',
56 ['confirm' => 1, 'returnurl' => $returnurl]), get_string('yes'));
57 $formcancel = new single_button($return, get_string('no'), 'get');
58 echo $OUTPUT->confirm(get_string('deletecheckfull', '', $usernames), $formcontinue, $formcancel);
61 echo $OUTPUT->footer();