2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once('../../config.php');
26 require_once($CFG->libdir
.'/adminlib.php');
27 require_once($CFG->dirroot
.'/'.$CFG->admin
.'/user/lib.php');
28 require_once($CFG->dirroot
.'/'.$CFG->admin
.'/user/user_bulk_forms.php');
30 admin_externalpage_setup('userbulk');
32 if (!isset($SESSION->bulk_users
)) {
33 $SESSION->bulk_users
= array();
35 // Create the user filter form.
36 $ufiltering = new user_filtering();
38 // Create the bulk operations form.
39 $actionform = new user_bulk_action_form();
40 $actionform->set_data(['returnurl' => $PAGE->url
->out_as_local_url(false)]);
41 if ($data = $actionform->get_data()) {
42 if ($data->passuserids
) {
43 // This means we called the form from /admin/user.php or similar and the userids should be taken from the form
44 // data and not from $SESSION->bulk_users. For backwards compatibility we still set $SESSION->bulk_users.
45 $users = preg_split('/,/', $data->userids
, -1, PREG_SPLIT_NO_EMPTY
);
46 $SESSION->bulk_users
= array_combine($users, $users);
48 // Check if an action should be performed and do so.
49 $bulkactions = $actionform->get_actions();
50 if (array_key_exists($data->action
, $bulkactions)) {
51 redirect(new moodle_url($bulkactions[$data->action
]->url
, ['returnurl' => $data->returnurl ?
: null]));
56 $userbulkform = new user_bulk_form(null, get_selection_data($ufiltering));
58 if ($data = $userbulkform->get_data()) {
59 if (!empty($data->addall
)) {
60 add_selection_all($ufiltering);
62 } else if (!empty($data->addsel
)) {
63 if (!empty($data->ausers
)) {
64 if (in_array(0, $data->ausers
)) {
65 add_selection_all($ufiltering);
67 foreach ($data->ausers
as $userid) {
71 if (!isset($SESSION->bulk_users
[$userid])) {
72 $SESSION->bulk_users
[$userid] = $userid;
78 } else if (!empty($data->removeall
)) {
79 $SESSION->bulk_users
= array();
81 } else if (!empty($data->removesel
)) {
82 if (!empty($data->susers
)) {
83 if (in_array(0, $data->susers
)) {
84 $SESSION->bulk_users
= array();
86 foreach ($data->susers
as $userid) {
90 unset($SESSION->bulk_users
[$userid]);
96 // Reset the form selections.
98 $userbulkform = new user_bulk_form(null, get_selection_data($ufiltering));
100 echo $OUTPUT->header();
102 $ufiltering->display_add();
103 $ufiltering->display_active();
105 $userbulkform->display();
107 $actionform->display();
109 echo $OUTPUT->footer();