Merge branch 'w14_MDL-38753_m23_ocicount' of git://github.com/skodak/moodle into...
[moodle.git] / admin / user / user_bulk_confirm.php
blobc7ba604ea5e9b57f93a4eb4bedfded170d477951
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', get_context_instance(CONTEXT_SYSTEM));
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 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;
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 echo $OUTPUT->notification(get_string('usernotconfirmed', '', fullname($user, true)));
38 $rs->close();
39 redirect($return, get_string('changessaved'));
41 } else {
42 list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
43 $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
44 $usernames = implode(', ', $userlist);
45 echo $OUTPUT->heading(get_string('confirmation', 'admin'));
46 $formcontinue = new single_button(new moodle_url('user_bulk_confirm.php', array('confirm' => 1)), get_string('yes'));
47 $formcancel = new single_button(new moodle_url('user_bulk.php'), get_string('no'), 'get');
48 echo $OUTPUT->confirm(get_string('confirmcheckfull', '', $usernames), $formcontinue, $formcancel);
51 echo $OUTPUT->footer();