]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19608 - adding bulk user action to force password change, credit to IƱaki Arenaza...
authorAnthony Borrow <arborrow@jesuits.net>
Mon, 16 Nov 2009 17:16:03 +0000 (17:16 +0000)
committerAnthony Borrow <arborrow@jesuits.net>
Mon, 16 Nov 2009 17:16:03 +0000 (17:16 +0000)
admin/user/user_bulk.php
admin/user/user_bulk_forcepasswordchange.php [new file with mode: 0644]
admin/user/user_bulk_forms.php
lang/en_utf8/moodle.php

index 8639236e66d6e9e7626413af584c3a9d7762928f..e4146268558e2b50b42d9c940654491de6ab6824 100755 (executable)
@@ -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 (file)
index 0000000..6cebe4a
--- /dev/null
@@ -0,0 +1,53 @@
+<?php //$Id$
+/**
+* script for bulk user force password change
+*/
+
+require_once('../../config.php');
+require_once($CFG->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();
+?>
index d9d9aae7b09ce74bfe4e3c75a319cb6b1e14b343..6bce8cce47c825958b635ca8ba6fbc41aa50157b 100644 (file)
@@ -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'));
index 14014974319db20a2fbd915e59d77d826bb451a2..011d1f3aa429e553ba68d80513ad9807f474b756 100644 (file)
@@ -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?';