MDL-12101 cleanup/fixing/refactoring of user bulk operation and admin user browsing
[moodle.git] / admin / user / lib.php
CommitLineData
cd1edf9e 1<?php //$Id$
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;
11
12 $guest = get_guest();
13 $sqlwhere = $ufiltering->get_sql_filter("id<>{$guest->id} AND deleted <> 1");
14
15 if ($rs = get_recordset_select('user', $sqlwhere, 'fullname', 'id,'.sql_fullname().' AS fullname')) {
16 while ($user = rs_fetch_next_record($rs)) {
17 if (!in_array($user->id, $SESSION->bulk_users)) {
18 $SESSION->bulk_users[] = $user->id;
19 }
20 }
21 rs_close($rs);
22 }
23}
24
25function get_selection_data($ufiltering) {
26 global $SESSION;
27
28 // get the SQL filter
29 $guest = get_guest();
30 $sqlwhere = $ufiltering->get_sql_filter("id<>{$guest->id} AND deleted <> 1");
31
32 $total = count_records_select('user', "id<>{$guest->id} AND deleted <> 1");
33 $acount = count_records_select('user', $sqlwhere);
34 $scount = count($SESSION->bulk_users);
35
36 $userlist = array('acount'=>$acount, 'scount'=>$scount, 'ausers'=>false, 'susers'=>false, 'total'=>$total);
37 $userlist['ausers'] = get_records_select_menu('user', $sqlwhere, 'fullname', 'id,'.sql_fullname().' AS fullname', 0, MAX_BULK_USERS);
38
39 if ($scount) {
40 if ($scount < MAX_BULK_USERS) {
41 $in = implode(',', $SESSION->bulk_users);
42 } else {
43 $bulkusers = array_slice($SESSION->bulk_users, 0, MAX_BULK_USERS);
44 $in = implode(',', $bulkusers);
45 }
46 $userlist['susers'] = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname');
47 }
48
49 return $userlist;
50}
51
52
53?>