MDL-77891 core_calendar: support display of mod iconurl
[moodle.git] / admin / user / user_bulk_forms.php
blob2dcf4c5c3f89c5871651aa2da8c9e269538254d4
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * Bulk user action forms
20 * @package core
21 * @copyright Moodle
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->libdir.'/formslib.php');
28 require_once($CFG->libdir.'/datalib.php');
30 /**
31 * Bulk user action form
33 * @copyright Moodle
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class user_bulk_action_form extends moodleform {
38 /**
39 * Returns an array of action_link's of all bulk actions available for this user.
41 * @return array of action_link objects
43 public function get_actions(): array {
45 global $CFG;
47 $syscontext = context_system::instance();
48 $actions = [];
49 if (has_capability('moodle/user:update', $syscontext)) {
50 $actions['confirm'] = new action_link(
51 new moodle_url('/admin/user/user_bulk_confirm.php'),
52 get_string('confirm'));
54 if (has_capability('moodle/site:readallmessages', $syscontext) && !empty($CFG->messaging)) {
55 $actions['message'] = new action_link(
56 new moodle_url('/admin/user/user_bulk_message.php'),
57 get_string('messageselectadd'));
59 if (has_capability('moodle/user:delete', $syscontext)) {
60 $actions['delete'] = new action_link(
61 new moodle_url('/admin/user/user_bulk_delete.php'),
62 get_string('delete'));
64 $actions['displayonpage'] = new action_link(
65 new moodle_url('/admin/user/user_bulk_display.php'),
66 get_string('displayonpage'));
68 if (has_capability('moodle/user:update', $syscontext)) {
69 $actions['download'] = new action_link(
70 new moodle_url('/admin/user/user_bulk_download.php'),
71 get_string('download', 'admin'));
74 if (has_capability('moodle/user:update', $syscontext)) {
75 $actions['forcepasswordchange'] = new action_link(
76 new moodle_url('/admin/user/user_bulk_forcepasswordchange.php'),
77 get_string('forcepasswordchange'));
79 if (has_capability('moodle/cohort:assign', $syscontext)) {
80 $actions['addtocohort'] = new action_link(
81 new moodle_url('/admin/user/user_bulk_cohortadd.php'),
82 get_string('bulkadd', 'core_cohort'));
85 // Any plugin can append actions to this list by implementing a callback
86 // <component>_bulk_user_actions() which returns an array of action_link.
87 // Each new action's key should have a frankenstyle prefix to avoid clashes.
88 // See MDL-38511 for more details.
89 $moreactions = get_plugins_with_function('bulk_user_actions', 'lib.php');
90 foreach ($moreactions as $plugintype => $plugins) {
91 foreach ($plugins as $pluginfunction) {
92 $actions += $pluginfunction();
96 return $actions;
101 * Form definition
103 public function definition() {
104 global $CFG;
106 $mform =& $this->_form;
108 $actions = [0 => get_string('choose') . '...'];
109 $bulkactions = $this->get_actions();
110 foreach ($bulkactions as $key => $action) {
111 $actions[$key] = $action->text;
113 $objs = array();
114 $objs[] =& $mform->createElement('select', 'action', null, $actions);
115 $objs[] =& $mform->createElement('submit', 'doaction', get_string('go'));
116 $mform->addElement('group', 'actionsgrp', get_string('withselectedusers'), $objs, ' ', false);
121 * Bulk user form
123 * @copyright Moodle
124 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
126 class user_bulk_form extends moodleform {
129 * Form definition
131 public function definition() {
133 $mform =& $this->_form;
134 $acount =& $this->_customdata['acount'];
135 $scount =& $this->_customdata['scount'];
136 $ausers =& $this->_customdata['ausers'];
137 $susers =& $this->_customdata['susers'];
138 $total =& $this->_customdata['total'];
140 $achoices = array();
141 $schoices = array();
143 if (is_array($ausers)) {
144 if ($total == $acount) {
145 $achoices[0] = get_string('allusers', 'bulkusers', $total);
146 } else {
147 $a = new stdClass();
148 $a->total = $total;
149 $a->count = $acount;
150 $achoices[0] = get_string('allfilteredusers', 'bulkusers', $a);
152 $achoices = $achoices + $ausers;
154 if ($acount > MAX_BULK_USERS) {
155 $achoices[-1] = '...';
158 } else {
159 $achoices[-1] = get_string('nofilteredusers', 'bulkusers', $total);
162 if (is_array($susers)) {
163 $a = new stdClass();
164 $a->total = $total;
165 $a->count = $scount;
166 $schoices[0] = get_string('allselectedusers', 'bulkusers', $a);
167 $schoices = $schoices + $susers;
169 if ($scount > MAX_BULK_USERS) {
170 $schoices[-1] = '...';
173 } else {
174 $schoices[-1] = get_string('noselectedusers', 'bulkusers');
177 $mform->addElement('header', 'users', get_string('usersinlist', 'bulkusers'));
179 $objs = array();
180 $objs[0] =& $mform->createElement('select', 'ausers', get_string('available', 'bulkusers'), $achoices, 'size="15"');
181 $objs[0]->setMultiple(true);
182 $objs[1] =& $mform->createElement('select', 'susers', get_string('selected', 'bulkusers'), $schoices, 'size="15"');
183 $objs[1]->setMultiple(true);
185 $grp =& $mform->addElement('group', 'usersgrp', get_string('users', 'bulkusers'), $objs, ' ', false);
186 $mform->addHelpButton('usersgrp', 'users', 'bulkusers');
188 $mform->addElement('static', 'comment');
190 $objs = array();
191 $objs[] =& $mform->createElement('submit', 'addsel', get_string('addsel', 'bulkusers'));
192 $objs[] =& $mform->createElement('submit', 'removesel', get_string('removesel', 'bulkusers'));
193 $grp =& $mform->addElement('group', 'buttonsgrp', get_string('selectedlist', 'bulkusers'), $objs, null, false);
194 $mform->addHelpButton('buttonsgrp', 'selectedlist', 'bulkusers');
195 $objs = array();
196 $objs[] =& $mform->createElement('submit', 'addall', get_string('addall', 'bulkusers'));
197 $objs[] =& $mform->createElement('submit', 'removeall', get_string('removeall', 'bulkusers'));
198 $grp =& $mform->addElement('group', 'buttonsgrp2', '', $objs, null, false);
200 $renderer =& $mform->defaultRenderer();
201 $template = '<label class="qflabel" style="vertical-align:top">{label}</label> {element}';
202 $renderer->setGroupElementTemplate($template, 'usersgrp');