Search moodle.org's
Developer Documentation

   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          $columnicon = ' <img src="'.$OUTPUT->pix_url('t/'.($dir == 'asc' ? 'down' : 'up' )).'f" alt="" />';
  61      }
  62      $table->head[] = '<a href="user_bulk_display.php?sort='.$column.'&amp;dir='.$columndir.'">'.$strtitle.'</a>'.$columnicon;
  63      $table->align[] = 'left';
  64  }
  65  
  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
  74      );
  75  }
  76  
  77  echo $OUTPUT->heading("$usercount / $usertotal ".get_string('users'));
  78  echo html_writer::table($table);
  79  
  80  echo $OUTPUT->continue_button($return);
  81  
  82  echo $OUTPUT->footer();

Search This Site: