Merge branch 'MDL-55910-31' of https://github.com/LukeCarrier/moodle into MOODLE_31_S...
[moodle.git] / admin / user / user_bulk_confirm.php
blob9bfc65bf8cdcca80ef733d92624c4e2b64b7f7ce
1 <?php
2 /**
3 * script for bulk user delete operations
4 */
6 require_once('../../config.php');
7 require_once($CFG->libdir.'/adminlib.php');
9 $confirm = optional_param('confirm', 0, PARAM_BOOL);
11 require_login();
12 admin_externalpage_setup('userbulk');
13 require_capability('moodle/user:update', context_system::instance());
15 $return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
17 if (empty($SESSION->bulk_users)) {
18 redirect($return);
21 echo $OUTPUT->header();
23 //TODO: add support for large number of users
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, '', 'id, username, secret, confirmed, auth, firstname, lastname');
29 foreach ($rs as $user) {
30 if ($user->confirmed) {
31 continue;
33 $auth = get_auth_plugin($user->auth);
34 $result = $auth->user_confirm($user->username, $user->secret);
35 if ($result != AUTH_CONFIRM_OK && $result != AUTH_CONFIRM_ALREADY) {
36 $notifications .= $OUTPUT->notification(get_string('usernotconfirmed', '', fullname($user, true)));
39 $rs->close();
40 echo $OUTPUT->box_start('generalbox', 'notice');
41 if (!empty($notifications)) {
42 echo $notifications;
43 } else {
44 echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
46 $continue = new single_button(new moodle_url($return), get_string('continue'), 'post');
47 echo $OUTPUT->render($continue);
48 echo $OUTPUT->box_end();
49 } else {
50 list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
51 $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
52 $usernames = implode(', ', $userlist);
53 echo $OUTPUT->heading(get_string('confirmation', 'admin'));
54 $formcontinue = new single_button(new moodle_url('user_bulk_confirm.php', array('confirm' => 1)), get_string('yes'));
55 $formcancel = new single_button(new moodle_url('user_bulk.php'), get_string('no'), 'get');
56 echo $OUTPUT->confirm(get_string('confirmcheckfull', '', $usernames), $formcontinue, $formcancel);
59 echo $OUTPUT->footer();