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
)) {
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
);
38 // Need to sort by date
39 function sort_compare($a, $b) {
41 if($sort == 'lastaccess') {
42 $rez = $b->lastaccess
- $a->lastaccess
;
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) {
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.'&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
.'&course='.SITEID
.'">'.$user->fullname
.'</a>',
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();