From b37a5ab1a667281f8fad3bdaf7c8a95a8626ea3a Mon Sep 17 00:00:00 2001 From: Vadimon Date: Fri, 5 Feb 2010 17:57:06 +0700 Subject: [PATCH] Bulk action for turning off force password change --- admin/user/user_bulk.php | 1 + admin/user/user_bulk_forms.php | 3 + admin/user/user_bulk_unforcepasswordchange.php | 70 ++++++++++++++++++++++++ lang/en_utf8/moodle.php | 2 + 4 files changed, 76 insertions(+), 0 deletions(-) create mode 100644 admin/user/user_bulk_unforcepasswordchange.php diff --git a/admin/user/user_bulk.php b/admin/user/user_bulk.php index bdf8be9..47f9e89 100644 --- a/admin/user/user_bulk.php +++ b/admin/user/user_bulk.php @@ -25,6 +25,7 @@ if ($data = $action_form->get_data(false)) { 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_forcepasswordchange.php'); + case 7: redirect($CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk_unforcepasswordchange.php'); } } diff --git a/admin/user/user_bulk_forms.php b/admin/user/user_bulk_forms.php index c5bbeb7..f672678 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/user:update', $syscontext)) { $actions[6] = get_string('forcepasswordchange'); } + if (has_capability('moodle/user:update', $syscontext)) { + $actions[7] = get_string('forcepasswordchangedisable'); + } $objs = array(); $objs[] =& $mform->createElement('select', 'action', null, $actions); diff --git a/admin/user/user_bulk_unforcepasswordchange.php b/admin/user/user_bulk_unforcepasswordchange.php new file mode 100644 index 0000000..b982365 --- /dev/null +++ b/admin/user/user_bulk_unforcepasswordchange.php @@ -0,0 +1,70 @@ +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(); + +if ($confirm and confirm_sesskey()) { + // only force password change if user may actually change the password + $authsavailable = get_list_of_plugins('auth'); + $changeable = array(); + foreach($authsavailable as $authname) { + if (!$auth = get_auth_plugin($authname)) { + continue; + } + if (@$auth->is_internal() and @$auth->can_change_password()) { // plugins may not be configured yet, not nice :-( + $changeable[$authname] = true; + } + } + + $parts = array_chunk($SESSION->bulk_users, 300); + foreach ($parts as $users) { + $in = implode(',', $users); + if ($rs = get_recordset_select('user', "id IN ($in)")) { + while ($user = rs_fetch_next_record($rs)) { + if (!empty($changeable[$user->auth])) { + set_user_preference('auth_forcepasswordchange', 0, $user->id); + unset($SESSION->bulk_users[$user->id]); + } else { + notify(get_string('forcepasswordchangenot', '', fullname($user, true))); + } + } + rs_close($rs); + } + } + notify(get_string('changessaved'), 'notifysuccess'); + print_continue($return); + +} else { + $in = implode(',', $SESSION->bulk_users); + $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname', 0, MAX_BULK_USERS); + $usernames = implode(', ', $userlist); + if (count($SESSION->bulk_users) > MAX_BULK_USERS) { + $usernames .= ', ...'; + } + $optionsyes = array(); + $optionsyes['confirm'] = 1; + $optionsyes['sesskey'] = sesskey(); + print_heading(get_string('confirmation', 'admin')); + notice_yesno(get_string('forcepasswordchangedisablecheckfull', '', $usernames), 'user_bulk_unforcepasswordchange.php', 'user_bulk.php', $optionsyes, NULL, 'post', 'get'); +} + +admin_externalpage_print_footer(); +?> diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index ff524ea..f91a971 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -679,6 +679,8 @@ $string['forcedmode'] = 'forced mode'; $string['forcelanguage'] = 'Force language'; $string['forceno'] = 'Do not force'; $string['forcepasswordchange'] = 'Force password change'; +$string['forcepasswordchangedisable'] = 'Turn off Force password change'; +$string['forcepasswordchangedisablecheckfull'] = 'Are you absolutely sure you want to turn off force a password change to $a ?'; $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'; -- 1.6.5.1.1367.gcd48