Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   1  <?php
   2  
   3  require_once('../../config.php');
   4  require_once($CFG->libdir.'/adminlib.php');
   5  
   6  $sort = optional_param('sort', 'fullname', PARAM_ALPHA);
   7  $dir  = optional_param('dir', 'asc', PARAM_ALPHA);
   8  
   9  admin_externalpage_setup('userbulk');
  10  
  11  $return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
  12  
  13  if (empty($SESSION->bulk_users)) {
  14      redirect($return);
  15  }
  16  
  17  $users = $SESSION->bulk_users;
  18  $usertotal = get_users(false);
  19  $usercount = count($users);
  20  
  21  $strnever = get_string('never');
  22  
  23  echo $OUTPUT->header();
  24  
  25  $countries = get_string_manager()->get_list_of_countries(true);
  26  
  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;
  35  }
  36  unset($countries);
  37  
  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);
  45      }
  46      return $dir == 'desc' ? -$rez : $rez;
  47  }
  48  usort($users, 'sort_compare');
  49  
  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          $icon = 't/down';
  61          $iconstr = $columndir;
  62          if ($dir != 'asc') {
  63              $icon = 't/up';
  64          }
  65          $columnicon = ' ' . $OUTPUT->pix_icon($icon, get_string($iconstr));
  66      }
  67      $table->head[] = '<a href="user_bulk_display.php?sort='.$column.'&amp;dir='.$columndir.'">'.$strtitle.'</a>'.$columnicon;
  68      $table->align[] = 'left';
  69  }
  70  
  71  foreach($users as $user) {
  72      $table->data[] = array (
  73          '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.SITEID.'">'.$user->fullname.'</a>',
  74  //        $user->username,
  75          s($user->email),
  76          $user->city,
  77          $user->country,
  78          $user->lastaccess ? format_time(time() - $user->lastaccess) : $strnever
  79      );
  80  }
  81  
  82  echo $OUTPUT->heading("$usercount / $usertotal ".get_string('users'));
  83  echo html_writer::table($table);
  84  
  85  echo $OUTPUT->continue_button($return);
  86  
  87  echo $OUTPUT->footer();