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