-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlib.php
147 lines (117 loc) · 4.93 KB
/
lib.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
require_once($CFG->dirroot.'/user/filters/lib.php');
define('ACTIONS_LANG_PREFIX', 'bulkuseractions_');
if (!defined('MAX_BULK_USERS')) {
define('MAX_BULK_USERS', 2000);
}
function add_selection_all($ufiltering) {
global $SESSION, $DB, $CFG;
list($sqlwhere, $params) = $ufiltering->get_sql_filter("id<>:exguest AND deleted <> 1", array('exguest'=>$CFG->siteguest));
if ($rs = $DB->get_recordset_select('user', $sqlwhere, $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname')) {
foreach ($rs as $user) {
if (!isset($SESSION->bulk_users[$user->id])) {
$SESSION->bulk_users[$user->id] = $user->id;
}
}
$rs->close();
}
}
function get_selection_data($ufiltering) {
global $SESSION, $DB, $CFG;
// get the SQL filter
list($sqlwhere, $params) = $ufiltering->get_sql_filter("id<>:exguest AND deleted <> 1", array('exguest'=>$CFG->siteguest));
$total = $DB->count_records_select('user', "id<>:exguest AND deleted <> 1", array('exguest'=>$CFG->siteguest));
$acount = $DB->count_records_select('user', $sqlwhere, $params);
$scount = count($SESSION->bulk_users);
$userlist = array('acount'=>$acount, 'scount'=>$scount, 'ausers'=>false, 'susers'=>false, 'total'=>$total);
$userlist['ausers'] = $DB->get_records_select_menu('user', $sqlwhere, $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname', 0, MAX_BULK_USERS);
if ($scount) {
if ($scount < MAX_BULK_USERS) {
$in = implode(',', $SESSION->bulk_users);
} else {
$bulkusers = array_slice($SESSION->bulk_users, 0, MAX_BULK_USERS, true);
$in = implode(',', $bulkusers);
}
$userlist['susers'] = $DB->get_records_select_menu('user', "id IN ($in)", null, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
}
return $userlist;
}
function check_action_capabilities($action, $require = false) {
global $CFG;
$requirecapability = NULL;
if (file_exists($CFG->dirroot.'/'.$CFG->admin.'/tool/advuserbulk/actions/'.$action.'/settings.php')) {
include($CFG->dirroot.'/'.$CFG->admin.'/tool/advuserbulk/actions/'.$action.'/settings.php');
}
if (is_null($requirecapability)) {
if ($require) {
print_error('action_nocaps');
}
return false;
} else if (is_string($requirecapability)) {
$caps = array( $requirecapability );
} else if (is_array($requirecapability)) {
$caps = $requirecapability;
} else {
if ($require) {
print_error('action_nocaps');
}
return false;
}
$syscontext = get_context_instance(CONTEXT_SYSTEM);
foreach ($caps as $cap) {
if ($require) {
require_capability($cap, $syscontext);
} else {
if (!has_capability($cap, $syscontext)) {
return false;
}
}
}
return true;
}
function advuserbulk_get_string($identifier, $component, $a = NULL) {
global $CFG;
$identifier = clean_param($identifier, PARAM_STRINGID);
if (empty($identifier)) {
throw new coding_exception('Invalid string identifier. Most probably some illegal character is part of the string identifier. Please fix your get_string() call and string definition');
}
if (empty($component)) {
throw new coding_exception('Parameter \'component\' for function advuserbulk_get_string() can not be empty. ');
}
if (strpos($component, ACTIONS_LANG_PREFIX) !== 0) {
throw new coding_exception('Function advuserbulk_get_string() must be called only for actions strings (component \''.ACTIONS_LANG_PREFIX.'XXX\')');
}
$dir = substr($component, strlen(ACTIONS_LANG_PREFIX));
$lang = current_language();
$string = array();
if (file_exists("$CFG->dirroot/$CFG->admin/tool/advuserbulk/actions/$dir/lang/$lang/$component.php")) {
include("$CFG->dirroot/$CFG->admin/tool/advuserbulk/actions/$dir/lang/$lang/$component.php");
} elseif (file_exists("$CFG->dirroot/$CFG->admin/tool/advuserbulk/actions/$dir/lang/en/$component.php")) {
include("$CFG->dirroot/$CFG->admin/tool/advuserbulk/actions/$dir/lang/en/$component.php");
} else {
return "[[$identifier]]";
}
$string = $string[$identifier];
if ($a !== NULL) {
if (is_object($a) or is_array($a)) {
$a = (array)$a;
$search = array();
$replace = array();
foreach ($a as $key=>$value) {
if (is_int($key)) {
// we do not support numeric keys - sorry!
continue;
}
$search[] = '{$a->'.$key.'}';
$replace[] = (string)$value;
}
if ($search) {
$string = str_replace($search, $replace, $string);
}
} else {
$string = str_replace('{$a}', (string)$a, $string);
}
}
return $string;
}
?>