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