weekly release
[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) {
c30bcaae 10 global $SESSION, $DB, $CFG;
cd1edf9e 11
04aec3da 12 list($sqlwhere, $params) = $ufiltering->get_sql_filter("id<>:exguest AND deleted <> 1", array('exguest'=>$CFG->siteguest));
cd1edf9e 13
ca8d6e37 14 if ($rs = $DB->get_recordset_select('user', $sqlwhere, $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname')) {
15 foreach ($rs as $user) {
16 if (!isset($SESSION->bulk_users[$user->id])) {
a5137c50 17 $SESSION->bulk_users[$user->id] = $user->id;
cd1edf9e 18 }
19 }
ca8d6e37 20 $rs->close();
cd1edf9e 21 }
22}
23
24function get_selection_data($ufiltering) {
39bc8cd0 25 global $SESSION, $DB, $CFG;
cd1edf9e 26
27 // get the SQL filter
04aec3da 28 list($sqlwhere, $params) = $ufiltering->get_sql_filter("id<>:exguest AND deleted <> 1", array('exguest'=>$CFG->siteguest));
cd1edf9e 29
04aec3da 30 $total = $DB->count_records_select('user', "id<>:exguest AND deleted <> 1", array('exguest'=>$CFG->siteguest));
624a690b 31 $acount = $DB->count_records_select('user', $sqlwhere, $params);
cd1edf9e 32 $scount = count($SESSION->bulk_users);
33
34 $userlist = array('acount'=>$acount, 'scount'=>$scount, 'ausers'=>false, 'susers'=>false, 'total'=>$total);
ca8d6e37 35 $userlist['ausers'] = $DB->get_records_select_menu('user', $sqlwhere, $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname', 0, MAX_BULK_USERS);
cd1edf9e 36
37 if ($scount) {
38 if ($scount < MAX_BULK_USERS) {
39 $in = implode(',', $SESSION->bulk_users);
40 } else {
a5137c50 41 $bulkusers = array_slice($SESSION->bulk_users, 0, MAX_BULK_USERS, true);
cd1edf9e 42 $in = implode(',', $bulkusers);
43 }
ca8d6e37 44 $userlist['susers'] = $DB->get_records_select_menu('user', "id IN ($in)", null, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
cd1edf9e 45 }
46
47 return $userlist;
48}