2009-11-01 10:42:45 +00:00
|
|
|
<?php
|
2007-08-07 07:26:58 +00:00
|
|
|
/**
|
|
|
|
* script for bulk user delete operations
|
|
|
|
*/
|
|
|
|
|
2007-08-15 05:30:49 +00:00
|
|
|
require_once('../../config.php');
|
2007-08-07 07:26:58 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
|
|
|
|
2007-11-13 08:43:20 +00:00
|
|
|
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
|
|
|
|
|
|
|
admin_externalpage_setup('userbulk');
|
2012-07-23 14:33:02 +08:00
|
|
|
require_capability('moodle/user:delete', context_system::instance());
|
2007-08-07 07:26:58 +00:00
|
|
|
|
2007-11-13 08:43:20 +00:00
|
|
|
$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
|
|
|
|
|
|
|
|
if (empty($SESSION->bulk_users)) {
|
|
|
|
redirect($return);
|
2007-08-07 07:26:58 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 08:05:53 +00:00
|
|
|
echo $OUTPUT->header();
|
2007-11-13 08:43:20 +00:00
|
|
|
|
|
|
|
//TODO: add support for large number of users
|
|
|
|
|
|
|
|
if ($confirm and confirm_sesskey()) {
|
2013-05-31 11:00:40 +08:00
|
|
|
$notifications = '';
|
2009-11-17 10:21:29 +00:00
|
|
|
list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
|
2018-07-19 17:27:08 +01:00
|
|
|
$rs = $DB->get_recordset_select('user', "deleted = 0 and id $in", $params);
|
2010-12-30 00:41:47 +01:00
|
|
|
foreach ($rs as $user) {
|
|
|
|
if (!is_siteadmin($user) and $USER->id != $user->id and delete_user($user)) {
|
|
|
|
unset($SESSION->bulk_users[$user->id]);
|
|
|
|
} else {
|
2013-05-31 11:00:40 +08:00
|
|
|
$notifications .= $OUTPUT->notification(get_string('deletednot', '', fullname($user, true)));
|
2007-11-13 08:43:20 +00:00
|
|
|
}
|
2007-08-07 07:26:58 +00:00
|
|
|
}
|
2010-12-30 00:41:47 +01:00
|
|
|
$rs->close();
|
2013-09-08 08:38:52 +02:00
|
|
|
\core\session\manager::gc(); // Remove stale sessions.
|
2013-05-31 11:00:40 +08:00
|
|
|
echo $OUTPUT->box_start('generalbox', 'notice');
|
|
|
|
if (!empty($notifications)) {
|
|
|
|
echo $notifications;
|
|
|
|
} else {
|
|
|
|
echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
|
|
|
|
}
|
|
|
|
$continue = new single_button(new moodle_url($return), get_string('continue'), 'post');
|
|
|
|
echo $OUTPUT->render($continue);
|
|
|
|
echo $OUTPUT->box_end();
|
2007-11-13 08:43:20 +00:00
|
|
|
} else {
|
2009-11-17 10:21:29 +00:00
|
|
|
list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
|
|
|
|
$userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
|
2007-11-13 08:43:20 +00:00
|
|
|
$usernames = implode(', ', $userlist);
|
2009-08-06 08:17:12 +00:00
|
|
|
echo $OUTPUT->heading(get_string('confirmation', 'admin'));
|
2010-01-03 20:47:13 +00:00
|
|
|
$formcontinue = new single_button(new moodle_url('user_bulk_delete.php', array('confirm' => 1)), get_string('yes'));
|
2010-09-27 08:45:59 +00:00
|
|
|
$formcancel = new single_button(new moodle_url('user_bulk.php'), get_string('no'), 'get');
|
2009-08-20 08:39:07 +00:00
|
|
|
echo $OUTPUT->confirm(get_string('deletecheckfull', '', $usernames), $formcontinue, $formcancel);
|
2007-08-07 07:26:58 +00:00
|
|
|
}
|
2007-11-13 08:43:20 +00:00
|
|
|
|
2009-08-06 14:12:46 +00:00
|
|
|
echo $OUTPUT->footer();
|