Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   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  $PAGE->set_primary_active_tab('siteadminnode');
  24  $PAGE->set_secondary_active_tab('users');
  25  
  26  echo $OUTPUT->header();
  27  
  28  $countries = get_string_manager()->get_list_of_countries(true);
  29  
  30  $userfieldsapi = \core_user\fields::for_name();
  31  $namefields = $userfieldsapi->get_sql('', false, '', '', false)->selects;
  32  foreach ($users as $key => $id) {
  33      $user = $DB->get_record('user', array('id'=>$id), 'id, ' . $namefields . ', username, email, country, lastaccess, city');
  34      $user->fullname = fullname($user, true);
  35      $user->country = @$countries[$user->country];
  36      unset($user->firstname);
  37      unset($user->lastname);
  38      $users[$key] = $user;
  39  }
  40  unset($countries);
  41  
  42  // Need to sort by date
  43  function sort_compare($a, $b) {
  44      global $sort, $dir;
  45      if($sort == 'lastaccess') {
  46          $rez = $b->lastaccess - $a->lastaccess;
  47      } else {
  48          $rez = strcasecmp(@$a->$sort, @$b->$sort);
  49      }
  50      return $dir == 'desc' ? -$rez : $rez;
  51  }
  52  usort($users, 'sort_compare');
  53  
  54  $table = new html_table();
  55  $table->width = "95%";
  56  $columns = array('fullname', /*'username', */'email', 'city', 'country', 'lastaccess');
  57  foreach ($columns as $column) {
  58      $strtitle = get_string($column);
  59      if ($sort != $column) {
  60          $columnicon = '';
  61          $columndir = 'asc';
  62      } else {
  63          $columndir = $dir == 'asc' ? 'desc' : 'asc';
  64          $icon = 't/down';
  65          $iconstr = $columndir;
  66          if ($dir != 'asc') {
  67              $icon = 't/up';
  68          }
  69          $columnicon = ' ' . $OUTPUT->pix_icon($icon, get_string($iconstr));
  70      }
  71      $table->head[] = '<a href="user_bulk_display.php?sort='.$column.'&amp;dir='.$columndir.'">'.$strtitle.'</a>'.$columnicon;
  72      $table->align[] = 'left';
  73  }
  74  
  75  foreach($users as $user) {
  76      $table->data[] = array (
  77          '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.SITEID.'">'.$user->fullname.'</a>',
  78  //        $user->username,
  79          s($user->email),
  80          $user->city,
  81          $user->country,
  82          $user->lastaccess ? format_time(time() - $user->lastaccess) : $strnever
  83      );
  84  }
  85  
  86  echo $OUTPUT->heading("$usercount / $usertotal ".get_string('users'));
  87  echo html_writer::table($table);
  88  
  89  echo $OUTPUT->continue_button($return);
  90  
  91  echo $OUTPUT->footer();