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