MDL-47919 tool_monitor: adjustments to behat tests
[moodle.git] / admin / user / user_bulk_display.php
blob44259dfd079649e1d89409a7801baafa394826a0
1 <?php
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 $return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
13 if (empty($SESSION->bulk_users)) {
14 redirect($return);
17 $users = $SESSION->bulk_users;
18 $usertotal = get_users(false);
19 $usercount = count($users);
21 $strnever = get_string('never');
23 echo $OUTPUT->header();
25 $countries = get_string_manager()->get_list_of_countries(true);
27 $namefields = get_all_user_name_fields(true);
28 foreach ($users as $key => $id) {
29 $user = $DB->get_record('user', array('id'=>$id), 'id, ' . $namefields . ', username, email, country, lastaccess, city');
30 $user->fullname = fullname($user, true);
31 $user->country = @$countries[$user->country];
32 unset($user->firstname);
33 unset($user->lastname);
34 $users[$key] = $user;
36 unset($countries);
38 // Need to sort by date
39 function sort_compare($a, $b) {
40 global $sort, $dir;
41 if($sort == 'lastaccess') {
42 $rez = $b->lastaccess - $a->lastaccess;
43 } else {
44 $rez = strcasecmp(@$a->$sort, @$b->$sort);
46 return $dir == 'desc' ? -$rez : $rez;
48 usort($users, 'sort_compare');
50 $table = new html_table();
51 $table->width = "95%";
52 $columns = array('fullname', /*'username', */'email', 'city', 'country', 'lastaccess');
53 foreach ($columns as $column) {
54 $strtitle = get_string($column);
55 if ($sort != $column) {
56 $columnicon = '';
57 $columndir = 'asc';
58 } else {
59 $columndir = $dir == 'asc' ? 'desc' : 'asc';
60 $columnicon = ' <img src="'.$OUTPUT->pix_url('t/'.($dir == 'asc' ? 'down' : 'up' )).'f" alt="" />';
62 $table->head[] = '<a href="user_bulk_display.php?sort='.$column.'&amp;dir='.$columndir.'">'.$strtitle.'</a>'.$columnicon;
63 $table->align[] = 'left';
66 foreach($users as $user) {
67 $table->data[] = array (
68 '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.SITEID.'">'.$user->fullname.'</a>',
69 // $user->username,
70 $user->email,
71 $user->city,
72 $user->country,
73 $user->lastaccess ? format_time(time() - $user->lastaccess) : $strnever
77 echo $OUTPUT->heading("$usercount / $usertotal ".get_string('users'));
78 echo html_writer::table($table);
80 echo $OUTPUT->continue_button($return);
82 echo $OUTPUT->footer();