Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
/**
3
* script for bulk user force password change
4
*/
5
 
6
require_once('../../config.php');
7
require_once('lib.php');
8
require_once($CFG->libdir.'/adminlib.php');
9
 
10
$confirm = optional_param('confirm', 0, PARAM_BOOL);
11
 
12
admin_externalpage_setup('userbulk');
13
require_capability('moodle/user:update', context_system::instance());
14
 
15
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
16
$return = new moodle_url($returnurl ?: '/admin/user/user_bulk.php');
17
 
18
if (empty($SESSION->bulk_users)) {
19
    redirect($return);
20
}
21
 
22
$PAGE->set_primary_active_tab('siteadminnode');
23
$PAGE->set_secondary_active_tab('users');
24
 
25
echo $OUTPUT->header();
26
 
27
if ($confirm and confirm_sesskey()) {
28
    // only force password change if user may actually change the password
29
    $authsavailable = get_enabled_auth_plugins();
30
    $changeable = array();
31
 
32
    foreach($authsavailable as $authplugin) {
33
        if (!$auth = get_auth_plugin($authplugin)) {
34
            continue;
35
        }
36
        if ($auth->is_internal() and $auth->can_change_password()) {
37
            $changeable[$authplugin] = true;
38
        }
39
    }
40
 
41
    $parts = array_chunk($SESSION->bulk_users, 300);
42
    foreach ($parts as $users) {
43
        list($in, $params) = $DB->get_in_or_equal($users);
44
        $rs = $DB->get_recordset_select('user', "id $in", $params);
45
        foreach ($rs as $user) {
46
            if (!empty($changeable[$user->auth])) {
47
                set_user_preference('auth_forcepasswordchange', 1, $user->id);
48
                unset($SESSION->bulk_users[$user->id]);
49
            } else {
50
                echo $OUTPUT->notification(get_string('forcepasswordchangenot', '', fullname($user, true)));
51
            }
52
        }
53
        $rs->close();
54
    }
55
    echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
56
    echo $OUTPUT->continue_button($return);
57
 
58
} else {
59
    list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
60
    $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname', 0, MAX_BULK_USERS);
61
    $usernames = implode(', ', $userlist);
62
    if (count($SESSION->bulk_users) > MAX_BULK_USERS) {
63
        $usernames .= ', ...';
64
    }
65
    echo $OUTPUT->heading(get_string('confirmation', 'admin'));
66
    $formcontinue = new single_button(new moodle_url('/admin/user/user_bulk_forcepasswordchange.php',
67
        ['confirm' => 1, 'returnurl' => $returnurl]), get_string('yes'));
68
    $formcancel = new single_button($return, get_string('no'), 'get');
69
    echo $OUTPUT->confirm(get_string('forcepasswordchangecheckfull', '', $usernames), $formcontinue, $formcancel);
70
}
71
 
72
echo $OUTPUT->footer();