3 require_once('../../config.php');
4 require_once($CFG->libdir
.'/adminlib.php');
6 $sort = optional_param('sort', 'fullname', PARAM_ALPHA
);
7 $dir = optional_param('dir', 'asc', PARAM_ALPHA
);
9 admin_externalpage_setup('userbulk');
11 $returnurl = optional_param('returnurl', '', PARAM_LOCALURL
);
12 $return = new moodle_url($returnurl ?
: '/admin/user/user_bulk.php');
14 if (empty($SESSION->bulk_users
)) {
18 $users = $SESSION->bulk_users
;
19 $usertotal = get_users(false);
20 $usercount = count($users);
22 $strnever = get_string('never');
24 $PAGE->set_primary_active_tab('siteadminnode');
25 $PAGE->set_secondary_active_tab('users');
27 echo $OUTPUT->header();
29 $countries = get_string_manager()->get_list_of_countries(true);
31 $userfieldsapi = \core_user\fields
::for_name();
32 $namefields = $userfieldsapi->get_sql('', false, '', '', false)->selects
;
33 foreach ($users as $key => $id) {
34 $user = $DB->get_record('user', array('id'=>$id), 'id, ' . $namefields . ', username, email, country, lastaccess, city');
35 $user->fullname
= fullname($user, true);
36 $user->country
= @$countries[$user->country
];
37 unset($user->firstname
);
38 unset($user->lastname
);
43 // Need to sort by date
44 function sort_compare($a, $b) {
46 if($sort == 'lastaccess') {
47 $rez = $b->lastaccess
- $a->lastaccess
;
49 $rez = strcasecmp(@$a->$sort, @$b->$sort);
51 return $dir == 'desc' ?
-$rez : $rez;
53 usort($users, 'sort_compare');
55 $table = new html_table();
56 $table->width
= "95%";
57 $columns = array('fullname', /*'username', */'email', 'city', 'country', 'lastaccess');
58 foreach ($columns as $column) {
59 $strtitle = get_string($column);
60 if ($sort != $column) {
64 $columndir = $dir == 'asc' ?
'desc' : 'asc';
66 $iconstr = $columndir;
70 $columnicon = ' ' . $OUTPUT->pix_icon($icon, get_string($iconstr));
72 $table->head
[] = '<a href="user_bulk_display.php?sort='.$column.'&dir='.$columndir.'">'.$strtitle.'</a>'.$columnicon;
73 $table->align
[] = 'left';
76 foreach($users as $user) {
77 $table->data
[] = array (
78 '<a href="'.$CFG->wwwroot
.'/user/view.php?id='.$user->id
.'&course='.SITEID
.'">'.$user->fullname
.'</a>',
83 $user->lastaccess ?
format_time(time() - $user->lastaccess
) : $strnever
87 echo $OUTPUT->heading("$usercount / $usertotal ".get_string('users'));
88 echo html_writer
::table($table);
90 echo $OUTPUT->continue_button($return);
92 echo $OUTPUT->footer();