forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_bulk_forms.php
115 lines (95 loc) · 4.5 KB
/
user_bulk_forms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->libdir.'/datalib.php');
class user_bulk_action_form extends moodleform {
function definition() {
global $CFG;
$mform =& $this->_form;
$syscontext = context_system::instance();
$actions = array(0=>get_string('choose').'...');
if (has_capability('moodle/user:update', $syscontext)) {
$actions[1] = get_string('confirm');
}
if (has_capability('moodle/site:readallmessages', $syscontext) && !empty($CFG->messaging)) {
$actions[2] = get_string('messageselectadd');
}
if (has_capability('moodle/user:delete', $syscontext)) {
$actions[3] = get_string('delete');
}
$actions[4] = get_string('displayonpage');
if (has_capability('moodle/user:update', $syscontext)) {
$actions[5] = get_string('download', 'admin');
}
if (has_capability('moodle/user:update', $syscontext)) {
$actions[7] = get_string('forcepasswordchange');
}
if (has_capability('moodle/cohort:assign', $syscontext)) {
$actions[8] = get_string('bulkadd', 'core_cohort');
}
$objs = array();
$objs[] =& $mform->createElement('select', 'action', null, $actions);
$objs[] =& $mform->createElement('submit', 'doaction', get_string('go'));
$mform->addElement('group', 'actionsgrp', get_string('withselectedusers'), $objs, ' ', false);
}
}
class user_bulk_form extends moodleform {
function definition() {
$mform =& $this->_form;
$acount =& $this->_customdata['acount'];
$scount =& $this->_customdata['scount'];
$ausers =& $this->_customdata['ausers'];
$susers =& $this->_customdata['susers'];
$total =& $this->_customdata['total'];
$achoices = array();
$schoices = array();
if (is_array($ausers)) {
if ($total == $acount) {
$achoices[0] = get_string('allusers', 'bulkusers', $total);
} else {
$a = new stdClass();
$a->total = $total;
$a->count = $acount;
$achoices[0] = get_string('allfilteredusers', 'bulkusers', $a);
}
$achoices = $achoices + $ausers;
if ($acount > MAX_BULK_USERS) {
$achoices[-1] = '...';
}
} else {
$achoices[-1] = get_string('nofilteredusers', 'bulkusers', $total);
}
if (is_array($susers)) {
$a = new stdClass();
$a->total = $total;
$a->count = $scount;
$schoices[0] = get_string('allselectedusers', 'bulkusers', $a);
$schoices = $schoices + $susers;
if ($scount > MAX_BULK_USERS) {
$schoices[-1] = '...';
}
} else {
$schoices[-1] = get_string('noselectedusers', 'bulkusers');
}
$mform->addElement('header', 'users', get_string('usersinlist', 'bulkusers'));
$objs = array();
$objs[0] =& $mform->createElement('select', 'ausers', get_string('available', 'bulkusers'), $achoices, 'size="15"');
$objs[0]->setMultiple(true);
$objs[1] =& $mform->createElement('select', 'susers', get_string('selected', 'bulkusers'), $schoices, 'size="15"');
$objs[1]->setMultiple(true);
$grp =& $mform->addElement('group', 'usersgrp', get_string('users', 'bulkusers'), $objs, ' ', false);
$mform->addHelpButton('usersgrp', 'users', 'bulkusers');
$mform->addElement('static', 'comment');
$objs = array();
$objs[] =& $mform->createElement('submit', 'addsel', get_string('addsel', 'bulkusers'));
$objs[] =& $mform->createElement('submit', 'removesel', get_string('removesel', 'bulkusers'));
$grp =& $mform->addElement('group', 'buttonsgrp', get_string('selectedlist', 'bulkusers'), $objs, null, false);
$mform->addHelpButton('buttonsgrp', 'selectedlist', 'bulkusers');
$objs = array();
$objs[] =& $mform->createElement('submit', 'addall', get_string('addall', 'bulkusers'));
$objs[] =& $mform->createElement('submit', 'removeall', get_string('removeall', 'bulkusers'));
$grp =& $mform->addElement('group', 'buttonsgrp2', '', $objs, null, false);
$renderer =& $mform->defaultRenderer();
$template = '<label class="qflabel" style="vertical-align:top">{label}</label> {element}';
$renderer->setGroupElementTemplate($template, 'usersgrp');
}
}