From 8f6ba17fcfc5952fdda24653c8ccb8d74b0b61de Mon Sep 17 00:00:00 2001 From: Anthony Borrow Date: Mon, 16 Nov 2009 17:16:03 +0000 Subject: [PATCH] =?utf8?q?MDL-19608=20-=20adding=20bulk=20user=20action=20?= =?utf8?q?to=20force=20password=20change,=20credit=20to=20I=C3=B1aki=20Are?= =?utf8?q?naza=20for=20the=20patch?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- admin/user/user_bulk.php | 1 + admin/user/user_bulk_forcepasswordchange.php | 53 ++++++++++++++++++++ admin/user/user_bulk_forms.php | 3 ++ lang/en_utf8/moodle.php | 2 + 4 files changed, 59 insertions(+) create mode 100644 admin/user/user_bulk_forcepasswordchange.php diff --git a/admin/user/user_bulk.php b/admin/user/user_bulk.php index 8639236e66..e414626855 100755 --- a/admin/user/user_bulk.php +++ b/admin/user/user_bulk.php @@ -25,6 +25,7 @@ if ($data = $action_form->get_data()) { case 4: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_display.php'); case 5: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_download.php'); case 6: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_enrol.php'); + case 7: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_forcepasswordchange.php'); } } diff --git a/admin/user/user_bulk_forcepasswordchange.php b/admin/user/user_bulk_forcepasswordchange.php new file mode 100644 index 0000000000..6cebe4ae97 --- /dev/null +++ b/admin/user/user_bulk_forcepasswordchange.php @@ -0,0 +1,53 @@ +libdir.'/adminlib.php'); + +$confirm = optional_param('confirm', 0, PARAM_BOOL); + +require_login(); +admin_externalpage_setup('userbulk'); +require_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM)); + +$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; + +if (empty($SESSION->bulk_users)) { + redirect($return); +} + +admin_externalpage_print_header(); + +//TODO: add support for large number of users + +if ($confirm and confirm_sesskey()) { + $primaryadmin = get_admin(); + + $in = implode(',', $SESSION->bulk_users); + if ($rs = $DB->get_recordset_select('user', "id IN ($in)", null)) { + foreach ($rs as $user) { + if ($primaryadmin->id != $user->id and $USER->id != $user->id + and set_user_preference('auth_forcepasswordchange', 1, $user->id)) { + unset($SESSION->bulk_users[$user->id]); + } else { + echo $OUTPUT->notification(get_string('forcepasswordchangenot', '', fullname($user, true))); + } + } + $rs->close; + } + redirect($return, get_string('changessaved')); + +} else { + $in = implode(',', $SESSION->bulk_users); + $userlist = $DB->get_records_select_menu('user', "id IN ($in)", null, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname'); + $usernames = implode(', ', $userlist); + echo $OUTPUT->heading(get_string('confirmation', 'admin')); + $formcontinue = html_form::make_button('user_bulk_forcepasswordchange.php', array('confirm' => 1), get_string('yes')); + $formcancel = html_form::make_button('user_bulk.php', $optionsno, get_string('no'), 'get'); + echo $OUTPUT->confirm(get_string('forcepasswordchangecheckfull', '', $usernames), $formcontinue, $formcancel); +} + +echo $OUTPUT->footer(); +?> diff --git a/admin/user/user_bulk_forms.php b/admin/user/user_bulk_forms.php index d9d9aae7b0..6bce8cce47 100644 --- a/admin/user/user_bulk_forms.php +++ b/admin/user/user_bulk_forms.php @@ -27,6 +27,9 @@ class user_bulk_action_form extends moodleform { if (has_capability('moodle/role:assign', $syscontext)){ $actions[6] = get_string('enrolmultipleusers', 'admin'); } + if (has_capability('moodle/user:update', $syscontext)) { + $actions[7] = get_string('forcepasswordchange'); + } $objs = array(); $objs[] =& $mform->createElement('select', 'action', null, $actions); $objs[] =& $mform->createElement('submit', 'doaction', get_string('go')); diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index 1401497431..011d1f3aa4 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -704,7 +704,9 @@ $string['forcedmode'] = 'forced mode'; $string['forcelanguage'] = 'Force language'; $string['forceno'] = 'Do not force'; $string['forcepasswordchange'] = 'Force password change'; +$string['forcepasswordchangecheckfull'] = 'Are you absolutely sure you want to force a password change to $a ?'; $string['forcepasswordchangehelp'] = 'Prompt user to change it on their next login'; +$string['forcepasswordchangenot'] = 'Could not force a password change to $a'; $string['forcepasswordchangenotice'] = 'You must change your password to proceed.'; $string['forcetheme'] = 'Force theme'; $string['forgotaccount'] = 'Lost password?'; -- 2.39.5