MDL-23927 do not use = 'guest' because we have CFG->siteguest AND it matches any...
[moodle.git] / admin / user / lib.php
CommitLineData
244bb396 1<?php
cd1edf9e 2
3require_once($CFG->dirroot.'/user/filters/lib.php');
4
5if (!defined('MAX_BULK_USERS')) {
6 define('MAX_BULK_USERS', 2000);
7}
8
9function add_selection_all($ufiltering) {
ca8d6e37 10 global $SESSION, $DB;
cd1edf9e 11
9e492db0 12 $guest = get_complete_user_data('username', 'guest');
ca8d6e37 13 list($sqlwhere, $params) = $ufiltering->get_sql_filter("id<>:exguest AND deleted <> 1", array('exguest'=>$guest->id));
cd1edf9e 14
ca8d6e37 15 if ($rs = $DB->get_recordset_select('user', $sqlwhere, $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname')) {
16 foreach ($rs as $user) {
17 if (!isset($SESSION->bulk_users[$user->id])) {
a5137c50 18 $SESSION->bulk_users[$user->id] = $user->id;
cd1edf9e 19 }
20 }
ca8d6e37 21 $rs->close();
cd1edf9e 22 }
23}
24
25function get_selection_data($ufiltering) {
624a690b 26 global $SESSION, $DB;
cd1edf9e 27
28 // get the SQL filter
9e492db0 29 $guest = get_complete_user_data('username', 'guest');
624a690b 30 list($sqlwhere, $params) = $ufiltering->get_sql_filter("id<>:exguest AND deleted <> 1", array('exguest'=>$guest->id));
cd1edf9e 31
624a690b 32 $total = $DB->count_records_select('user', "id<>:exguest AND deleted <> 1", array('exguest'=>$guest->id));
33 $acount = $DB->count_records_select('user', $sqlwhere, $params);
cd1edf9e 34 $scount = count($SESSION->bulk_users);
35
36 $userlist = array('acount'=>$acount, 'scount'=>$scount, 'ausers'=>false, 'susers'=>false, 'total'=>$total);
ca8d6e37 37 $userlist['ausers'] = $DB->get_records_select_menu('user', $sqlwhere, $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname', 0, MAX_BULK_USERS);
cd1edf9e 38
39 if ($scount) {
40 if ($scount < MAX_BULK_USERS) {
41 $in = implode(',', $SESSION->bulk_users);
42 } else {
a5137c50 43 $bulkusers = array_slice($SESSION->bulk_users, 0, MAX_BULK_USERS, true);
cd1edf9e 44 $in = implode(',', $bulkusers);
45 }
ca8d6e37 46 $userlist['susers'] = $DB->get_records_select_menu('user', "id IN ($in)", null, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
cd1edf9e 47 }
48
49 return $userlist;
50}