MDL-61899 tool_dataprivacy: Fixes during integration review
[moodle.git] / admin / user / user_bulk_forcepasswordchange.php
blob203f69c47ee72a40ba6d848a6ee22691d9a87b96
1 <?php
2 /**
3 * script for bulk user force password change
4 */
6 require_once('../../config.php');
7 require_once('lib.php');
8 require_once($CFG->libdir.'/adminlib.php');
10 $confirm = optional_param('confirm', 0, PARAM_BOOL);
12 require_login();
13 admin_externalpage_setup('userbulk');
14 require_capability('moodle/user:update', context_system::instance());
16 $return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
18 if (empty($SESSION->bulk_users)) {
19 redirect($return);
22 echo $OUTPUT->header();
24 if ($confirm and confirm_sesskey()) {
25 // only force password change if user may actually change the password
26 $authsavailable = get_enabled_auth_plugins();
27 $changeable = array();
29 foreach($authsavailable as $authplugin) {
30 if (!$auth = get_auth_plugin($authplugin)) {
31 continue;
33 if ($auth->is_internal() and $auth->can_change_password()) {
34 $changeable[$authplugin] = true;
38 $parts = array_chunk($SESSION->bulk_users, 300);
39 foreach ($parts as $users) {
40 list($in, $params) = $DB->get_in_or_equal($users);
41 $rs = $DB->get_recordset_select('user', "id $in", $params);
42 foreach ($rs as $user) {
43 if (!empty($changeable[$user->auth])) {
44 set_user_preference('auth_forcepasswordchange', 1, $user->id);
45 unset($SESSION->bulk_users[$user->id]);
46 } else {
47 echo $OUTPUT->notification(get_string('forcepasswordchangenot', '', fullname($user, true)));
50 $rs->close();
52 echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
53 echo $OUTPUT->continue_button($return);
55 } else {
56 list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
57 $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname', 0, MAX_BULK_USERS);
58 $usernames = implode(', ', $userlist);
59 if (count($SESSION->bulk_users) > MAX_BULK_USERS) {
60 $usernames .= ', ...';
62 echo $OUTPUT->heading(get_string('confirmation', 'admin'));
63 $formcontinue = new single_button(new moodle_url('/admin/user/user_bulk_forcepasswordchange.php', array('confirm' => 1)), get_string('yes'));
64 $formcancel = new single_button(new moodle_url('/admin/user/user_bulk.php'), get_string('no'), 'get');
65 echo $OUTPUT->confirm(get_string('forcepasswordchangecheckfull', '', $usernames), $formcontinue, $formcancel);
68 echo $OUTPUT->footer();