MDL-20852: Condition system - problems if you delete a module that another one had...
[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 }
51471f2a 27 if (has_capability('moodle/role:assign', $syscontext)){
192a0a69 28 $actions[6] = get_string('enrolmultipleusers', 'admin');
29 }
cd1edf9e 30 $objs = array();
31 $objs[] =& $mform->createElement('select', 'action', null, $actions);
32 $objs[] =& $mform->createElement('submit', 'doaction', get_string('go'));
33 $mform->addElement('group', 'actionsgrp', get_string('withselectedusers'), $objs, ' ', false);
34 }
35}
36
37class user_bulk_form extends moodleform {
38 function definition() {
39
40 $mform =& $this->_form;
41 $acount =& $this->_customdata['acount'];
42 $scount =& $this->_customdata['scount'];
43 $ausers =& $this->_customdata['ausers'];
44 $susers =& $this->_customdata['susers'];
45 $total =& $this->_customdata['total'];
46
47 $achoices = array();
48 $schoices = array();
49
50 if (is_array($ausers)) {
51 if ($total == $acount) {
52 $achoices[0] = get_string('allusers', 'bulkusers', $total);
53 } else {
54 $a = new object();
55 $a->total = $total;
56 $a->count = $acount;
57 $achoices[0] = get_string('allfilteredusers', 'bulkusers', $a);
58 }
59 $achoices = $achoices + $ausers;
60
61 if ($acount > MAX_BULK_USERS) {
62 $achoices[-1] = '...';
63 }
64
65 } else {
66 $achoices[-1] = get_string('nofilteredusers', 'bulkusers', $total);
67 }
68
69 if (is_array($susers)) {
70 $a = new object();
71 $a->total = $total;
72 $a->count = $scount;
73 $schoices[0] = get_string('allselectedusers', 'bulkusers', $a);
74 $schoices = $schoices + $susers;
75
76 if ($scount > MAX_BULK_USERS) {
77 $schoices[-1] = '...';
78 }
79
80 } else {
81 $schoices[-1] = get_string('noselectedusers', 'bulkusers');
82 }
83
84 $mform->addElement('header', 'users', get_string('usersinlist', 'bulkusers'));
85
86 $objs = array();
87 $objs[0] =& $mform->createElement('select', 'ausers', get_string('available', 'bulkusers'), $achoices, 'size="15"');
88 $objs[0]->setMultiple(true);
89 $objs[1] =& $mform->createElement('select', 'susers', get_string('selected', 'bulkusers'), $schoices, 'size="15"');
90 $objs[1]->setMultiple(true);
91
92
93 $grp =& $mform->addElement('group', 'usersgrp', get_string('users'), $objs, ' ', false);
444598e9 94 $grp->setHelpButton(array('lists', get_string('users'), 'bulkusers'));
cd1edf9e 95
96 $mform->addElement('static', 'comment');
97
98 $objs = array();
99 $objs[] =& $mform->createElement('submit', 'addsel', get_string('addsel', 'bulkusers'));
100 $objs[] =& $mform->createElement('submit', 'removesel', get_string('removesel', 'bulkusers'));
101 $objs[] =& $mform->createElement('submit', 'addall', get_string('addall', 'bulkusers'));
102 $objs[] =& $mform->createElement('submit', 'removeall', get_string('removeall', 'bulkusers'));
103 $grp =& $mform->addElement('group', 'buttonsgrp', get_string('selectedlist', 'bulkusers'), $objs, array(' ', '<br />'), false);
444598e9 104 $grp->setHelpButton(array('selectedlist', get_string('selectedlist', 'bulkusers'), 'bulkusers'));
cd1edf9e 105
106 $renderer =& $mform->defaultRenderer();
107 $template = '<label class="qflabel" style="vertical-align:top">{label}</label> {element}';
108 $renderer->setGroupElementTemplate($template, 'usersgrp');
109 }
110}