-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmins_potential_selector.php
57 lines (46 loc) · 1.94 KB
/
admins_potential_selector.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
<?php
require_once($CFG->dirroot.'/user/selector/lib.php');
class admins_potential_selector extends user_selector_base {
/**
* @param string $name control name
* @param array $options should have two elements with keys groupid and courseid.
*/
public function __construct() {
global $CFG, $USER;
$admins = explode(',', $CFG->siteadmins);
parent::__construct('addselect', array('multiselect'=>false, 'exclude'=>$admins));
}
public function find_users($search) {
global $CFG, $DB;
list($wherecondition, $params) = $this->search_sql($search, '');
$fields = 'SELECT ' . $this->required_fields_sql('');
$countfields = 'SELECT COUNT(1)';
$sql = " FROM {user}
WHERE $wherecondition AND mnethostid = :localmnet AND username REGEXP '[a-zA-Z]'";
$order = ' ORDER BY lastname ASC, firstname ASC';
$params['localmnet'] = $CFG->mnet_localhost_id; // it could be dangerous to make remote users admins and also this could lead to other problems
// Check to see if there are too many to show sensibly.
if (!$this->is_validating()) {
$potentialcount = $DB->count_records_sql($countfields . $sql, $params);
if ($potentialcount > 100) {
return $this->too_many_results($search, $potentialcount);
}
}
$availableusers = $DB->get_records_sql($fields . $sql . $order, $params);
if (empty($availableusers)) {
return array();
}
if ($search) {
$groupname = get_string('potusersmatching', 'role', $search);
} else {
$groupname = get_string('potusers', 'role');
}
return array($groupname => $availableusers);
}
protected function get_options() {
global $CFG;
$options = parent::get_options();
$options['file'] = $CFG->admin . '/roles/lib.php';
return $options;
}
}