forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_bulk_display.php
88 lines (72 loc) · 2.55 KB
/
user_bulk_display.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
<?php
require_once('../../config.php');
require_once($CFG->libdir.'/adminlib.php');
$sort = optional_param('sort', 'fullname', PARAM_ALPHA);
$dir = optional_param('dir', 'asc', PARAM_ALPHA);
admin_externalpage_setup('userbulk');
$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
if (empty($SESSION->bulk_users)) {
redirect($return);
}
$users = $SESSION->bulk_users;
$usertotal = get_users(false);
$usercount = count($users);
$strnever = get_string('never');
echo $OUTPUT->header();
$countries = get_string_manager()->get_list_of_countries(true);
$userfieldsapi = \core_user\fields::for_name();
$namefields = $userfieldsapi->get_sql('', false, '', '', false)->selects;
foreach ($users as $key => $id) {
$user = $DB->get_record('user', array('id'=>$id), 'id, ' . $namefields . ', username, email, country, lastaccess, city');
$user->fullname = fullname($user, true);
$user->country = @$countries[$user->country];
unset($user->firstname);
unset($user->lastname);
$users[$key] = $user;
}
unset($countries);
// Need to sort by date
function sort_compare($a, $b) {
global $sort, $dir;
if($sort == 'lastaccess') {
$rez = $b->lastaccess - $a->lastaccess;
} else {
$rez = strcasecmp(@$a->$sort, @$b->$sort);
}
return $dir == 'desc' ? -$rez : $rez;
}
usort($users, 'sort_compare');
$table = new html_table();
$table->width = "95%";
$columns = array('fullname', /*'username', */'email', 'city', 'country', 'lastaccess');
foreach ($columns as $column) {
$strtitle = get_string($column);
if ($sort != $column) {
$columnicon = '';
$columndir = 'asc';
} else {
$columndir = $dir == 'asc' ? 'desc' : 'asc';
$icon = 't/down';
$iconstr = $columndir;
if ($dir != 'asc') {
$icon = 't/up';
}
$columnicon = ' ' . $OUTPUT->pix_icon($icon, get_string($iconstr));
}
$table->head[] = '<a href="user_bulk_display.php?sort='.$column.'&dir='.$columndir.'">'.$strtitle.'</a>'.$columnicon;
$table->align[] = 'left';
}
foreach($users as $user) {
$table->data[] = array (
'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.SITEID.'">'.$user->fullname.'</a>',
// $user->username,
s($user->email),
$user->city,
$user->country,
$user->lastaccess ? format_time(time() - $user->lastaccess) : $strnever
);
}
echo $OUTPUT->heading("$usercount / $usertotal ".get_string('users'));
echo html_writer::table($table);
echo $OUTPUT->continue_button($return);
echo $OUTPUT->footer();