[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/user/ -> index.php (source)

   1  <?PHP // $Id: index.php,v 1.194.2.16 2008/05/28 14:52:15 mchurch Exp $
   2  
   3  //  Lists all the users within a given course
   4  
   5      require_once ('../config.php');
   6      require_once($CFG->libdir.'/tablelib.php');
   7  
   8      define('USER_SMALL_CLASS', 20);   // Below this is considered small
   9      define('USER_LARGE_CLASS', 200);  // Above this is considered large
  10      define('DEFAULT_PAGE_SIZE', 20);
  11      define('SHOW_ALL_PAGE_SIZE', 5000);
  12  
  13      $page         = optional_param('page', 0, PARAM_INT);                     // which page to show
  14      $perpage      = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT);  // how many per page
  15      $mode         = optional_param('mode', NULL);                             // '0' for less details, '1' for more
  16      $accesssince  = optional_param('accesssince',0,PARAM_INT);                // filter by last access. -1 = never
  17      $search       = optional_param('search','',PARAM_CLEAN);
  18      $roleid       = optional_param('roleid', 0, PARAM_INT);                   // optional roleid, -1 means all site users on frontpage
  19  
  20      $contextid    = optional_param('contextid', 0, PARAM_INT);                // one of this or
  21      $courseid     = optional_param('id', 0, PARAM_INT);                       // this are required
  22  
  23      if ($contextid) {
  24          if (! $context = get_context_instance_by_id($contextid)) {
  25              error("Context ID is incorrect");
  26          }
  27          if (! $course = get_record('course', 'id', $context->instanceid)) {
  28              error("Course ID is incorrect");
  29          }
  30      } else {
  31          if (! $course = get_record('course', 'id', $courseid)) {
  32              error("Course ID is incorrect");
  33          }
  34          if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) {
  35              error("Context ID is incorrect");
  36          }
  37      }
  38      // not needed anymore
  39      unset($contextid);
  40      unset($courseid);
  41  
  42      require_login($course);
  43  
  44      $sitecontext = get_context_instance(CONTEXT_SYSTEM);
  45      $frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID);
  46  
  47      if ($context->id != $frontpagectx->id) {
  48          require_capability('moodle/course:viewparticipants', $context);
  49      } else {
  50          require_capability('moodle/site:viewparticipants', $sitecontext);
  51          // override the default on frontpage
  52          $roleid = optional_param('roleid', -1, PARAM_INT);
  53      }
  54  
  55      /// front page course is different
  56      $rolenames = array();
  57      $avoidroles = array();
  58  
  59      if ($roles = get_roles_used_in_context($context, true)) {
  60          // We should ONLY allow roles with moodle/course:view because otherwise we get little niggly issues
  61          // like MDL-8093
  62          // We should further exclude "admin" users (those with "doanything" at site level) because
  63          // Otherwise they appear in every participant list
  64  
  65          $canviewroles    = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context);
  66          $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext);
  67  
  68          if ($context->id == $frontpagectx->id) {
  69              //we want admins listed on frontpage too
  70              foreach ($doanythingroles as $dar) {
  71                  $canviewroles[$dar->id] = $dar;
  72              }
  73              $doanythingroles = array();
  74          }
  75  
  76          foreach ($roles as $role) {
  77              if (!isset($canviewroles[$role->id])) {   // Avoid this role (eg course creator)
  78                  $avoidroles[] = $role->id;
  79                  unset($roles[$role->id]);
  80                  continue;
  81              }
  82              if (isset($doanythingroles[$role->id])) {   // Avoid this role (ie admin)
  83                  $avoidroles[] = $role->id;
  84                  unset($roles[$role->id]);
  85                  continue;
  86              }
  87              $rolenames[$role->id] = strip_tags(role_get_name($role, $context));   // Used in menus etc later on
  88          }
  89      }
  90  
  91      if ($context->id == $frontpagectx->id and $CFG->defaultfrontpageroleid) {
  92          // default frontpage role is assigned to all site users
  93          unset($rolenames[$CFG->defaultfrontpageroleid]);
  94      }
  95  
  96      // no roles to display yet?
  97      // frontpage course is an exception, on the front page course we should display all users
  98      if (empty($rolenames) && $context->id != $frontpagectx->id) {
  99          if (has_capability('moodle/role:assign', $context)) {
 100              redirect($CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id);
 101          } else {
 102              error ('No participants found for this course');
 103          }
 104      }
 105  
 106      add_to_log($course->id, 'user', 'view all', 'index.php?id='.$course->id, '');
 107  
 108      $bulkoperations = has_capability('moodle/course:bulkmessaging', $context);
 109  
 110      $countries = get_list_of_countries();
 111  
 112      $strnever = get_string('never');
 113  
 114      $datestring->year  = get_string('year');
 115      $datestring->years = get_string('years');
 116      $datestring->day   = get_string('day');
 117      $datestring->days  = get_string('days');
 118      $datestring->hour  = get_string('hour');
 119      $datestring->hours = get_string('hours');
 120      $datestring->min   = get_string('min');
 121      $datestring->mins  = get_string('mins');
 122      $datestring->sec   = get_string('sec');
 123      $datestring->secs  = get_string('secs');
 124  
 125      if ($mode !== NULL) {
 126          $SESSION->userindexmode = $fullmode = ($mode == 1);
 127      } else if (isset($SESSION->userindexmode)) {
 128          $fullmode = $SESSION->userindexmode;
 129      } else {
 130          $fullmode = false;
 131      }
 132  
 133  /// Check to see if groups are being used in this course
 134  /// and if so, set $currentgroup to reflect the current group
 135  
 136      $groupmode    = groups_get_course_groupmode($course);   // Groups are being used
 137      $currentgroup = groups_get_course_group($course, true);
 138  
 139      if (!$currentgroup) {      // To make some other functions work better later
 140          $currentgroup  = NULL;
 141      }
 142  
 143      $isseparategroups = ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce and
 144                           !has_capability('moodle/site:accessallgroups', $context));
 145  
 146      if ($isseparategroups and (!$currentgroup) ) {
 147          $navlinks = array();
 148          $navlinks[] = array('name' => get_string('participants'), 'link' => null, 'type' => 'misc');
 149          $navigation = build_navigation($navlinks);
 150  
 151          print_header("$course->shortname: ".get_string('participants'), $course->fullname, $navigation, "", "", true, "&nbsp;", navmenu($course));
 152          print_heading(get_string("notingroup"));
 153          print_footer($course);
 154          exit;
 155      }
 156  
 157      // Should use this variable so that we don't break stuff every time a variable is added or changed.
 158      $baseurl = $CFG->wwwroot.'/user/index.php?contextid='.$context->id.'&amp;roleid='.$roleid.'&amp;id='.$course->id.'&amp;perpage='.$perpage.'&amp;accesssince='.$accesssince.'&amp;search='.s($search);
 159  
 160  /// Print headers
 161  
 162      $navlinks = array();
 163      $navlinks[] = array('name' => get_string('participants'), 'link' => null, 'type' => 'misc');
 164      $navigation = build_navigation($navlinks);
 165  
 166      print_header("$course->shortname: ".get_string('participants'), $course->fullname, $navigation, "", "", true, "&nbsp;", navmenu($course));
 167  
 168  /// setting up tags
 169      if ($course->id == SITEID) {
 170          $filtertype = 'site';
 171      } else if ($course->id && !$currentgroup) {
 172          $filtertype = 'course';
 173          $filterselect = $course->id;
 174      } else {
 175          $filtertype = 'group';
 176          $filterselect = $currentgroup;
 177      }
 178      $currenttab = 'participants';
 179      $user = $USER;
 180  
 181      require_once($CFG->dirroot .'/user/tabs.php');
 182  
 183  
 184  /// Get the hidden field list
 185      if (has_capability('moodle/course:viewhiddenuserfields', $context)) {
 186          $hiddenfields = array();  // teachers and admins are allowed to see everything
 187      } else {
 188          $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
 189      }
 190  
 191  
 192  /// Print settings and things in a table across the top
 193  
 194      echo '<table class="controls" cellspacing="0"><tr>';
 195  
 196  /// Print my course menus
 197      if ($mycourses = get_my_courses($USER->id)) {
 198          echo '<td class="left">';
 199          $courselist = array();
 200          foreach ($mycourses as $mycourse) {
 201              $courselist[$mycourse->id] = format_string($mycourse->shortname);
 202          }
 203          if (has_capability('moodle/site:viewparticipants', $sitecontext)) {
 204              unset($courselist[SITEID]);
 205              $courselist = array(SITEID => format_string($SITE->shortname)) + $courselist;
 206          }
 207          popup_form($CFG->wwwroot.'/user/index.php?roleid='.$roleid.'&amp;sifirst=&amp;silast=&amp;id=',
 208                     $courselist, 'courseform', $course->id, '', '', '', false, 'self', get_string('mycourses'));
 209          echo '</td>';
 210      }
 211  
 212      echo '<td class="left">';
 213      groups_print_course_menu($course, $baseurl);
 214      echo '</td>';
 215  
 216      // get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
 217      // we need to make it diferently for normal courses and site course
 218      if ($context->id != $frontpagectx->id) {
 219          $minlastaccess = get_field_sql('SELECT min(timeaccess)
 220                                            FROM '.$CFG->prefix.'user_lastaccess
 221                                           WHERE courseid = '.$course->id.'
 222                                             AND timeaccess != 0');
 223          $lastaccess0exists = record_exists('user_lastaccess', 'courseid', $course->id, 'timeaccess', 0);
 224      } else {
 225          $minlastaccess = get_field_sql('SELECT min(lastaccess)
 226                                            FROM '.$CFG->prefix.'user
 227                                           WHERE lastaccess != 0');
 228          $lastaccess0exists = record_exists('user','lastaccess',0);
 229      }
 230  
 231      $now = usergetmidnight(time());
 232      $timeaccess = array();
 233  
 234      // makes sense for this to go first.
 235      $timeoptions[0] = get_string('selectperiod');
 236  
 237      // days
 238      for ($i = 1; $i < 7; $i++) {
 239          if (strtotime('-'.$i.' days',$now) >= $minlastaccess) {
 240              $timeoptions[strtotime('-'.$i.' days',$now)] = get_string('numdays','moodle',$i);
 241          }
 242      }
 243      // weeks
 244      for ($i = 1; $i < 10; $i++) {
 245          if (strtotime('-'.$i.' weeks',$now) >= $minlastaccess) {
 246              $timeoptions[strtotime('-'.$i.' weeks',$now)] = get_string('numweeks','moodle',$i);
 247          }
 248      }
 249      // months
 250      for ($i = 2; $i < 12; $i++) {
 251          if (strtotime('-'.$i.' months',$now) >= $minlastaccess) {
 252              $timeoptions[strtotime('-'.$i.' months',$now)] = get_string('nummonths','moodle',$i);
 253          }
 254      }
 255      // try a year
 256      if (strtotime('-1 year',$now) >= $minlastaccess) {
 257          $timeoptions[strtotime('-1 year',$now)] = get_string('lastyear');
 258      }
 259  
 260      if (!empty($lastaccess0exists)) {
 261          $timeoptions[-1] = get_string('never');
 262      }
 263  
 264      if (count($timeoptions) > 1) {
 265          echo '<td class="left">';
 266          $baseurl = preg_replace('/&amp;accesssince='.$accesssince.'/','',$baseurl);
 267          popup_form($baseurl.'&amp;accesssince=',$timeoptions,'timeoptions',$accesssince, '', '', '', false, 'self', get_string('usersnoaccesssince'));
 268          echo '</td>';
 269      }
 270  
 271  
 272      echo '<td class="right">';
 273      $formatmenu = array( '0' => get_string('detailedless'),
 274                           '1' => get_string('detailedmore'));
 275      popup_form($baseurl.'&amp;mode=', $formatmenu, 'formatmenu', $fullmode, '', '', '', false, 'self', get_string('userlist'));
 276      echo '</td></tr></table>';
 277  
 278      if ($currentgroup and (!$isseparategroups or has_capability('moodle/site:accessallgroups', $context))) {    /// Display info about the group
 279          if ($group = groups_get_group($currentgroup)) {
 280              if (!empty($group->description) or (!empty($group->picture) and empty($group->hidepicture))) {
 281                  echo '<table class="groupinfobox"><tr><td class="left side picture">';
 282                  print_group_picture($group, $course->id, true, false, false);
 283                  echo '</td><td class="content">';
 284                  echo '<h3>'.$group->name;
 285                  if (has_capability('moodle/course:managegroups', $context)) {
 286                      echo '&nbsp;<a title="'.get_string('editgroupprofile').'" href="'.$CFG->wwwroot.'/group/group.php?id='.$group->id.'&amp;courseid='.$group->courseid.'">';
 287                      echo '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.get_string('editgroupprofile').'" />';
 288                      echo '</a>';
 289                  }
 290                  echo '</h3>';
 291                  echo format_text($group->description);
 292                  echo '</td></tr></table>';
 293              }
 294          }
 295      }
 296  
 297      /// Define a table showing a list of users in the current role selection
 298  
 299      $tablecolumns = array('userpic', 'fullname');
 300      $tableheaders = array(get_string('userpic'), get_string('fullname'));
 301      if (!isset($hiddenfields['city'])) {
 302          $tablecolumns[] = 'city';
 303          $tableheaders[] = get_string('city');
 304      }
 305      if (!isset($hiddenfields['country'])) {
 306          $tablecolumns[] = 'country';
 307          $tableheaders[] = get_string('country');
 308      }
 309      if (!isset($hiddenfields['lastaccess'])) {
 310          $tablecolumns[] = 'lastaccess';
 311          $tableheaders[] = get_string('lastaccess');
 312      }
 313  
 314      if ($course->enrolperiod) {
 315          $tablecolumns[] = 'timeend';
 316          $tableheaders[] = get_string('enrolmentend');
 317      }
 318  
 319      if ($bulkoperations) {
 320          $tablecolumns[] = '';
 321          $tableheaders[] = get_string('select');
 322      }
 323  
 324      $table = new flexible_table('user-index-participants-'.$course->id);
 325  
 326      $table->define_columns($tablecolumns);
 327      $table->define_headers($tableheaders);
 328      $table->define_baseurl($baseurl);
 329  
 330      $table->sortable(true, 'lastaccess', SORT_DESC);
 331  
 332      $table->set_attribute('cellspacing', '0');
 333      $table->set_attribute('id', 'participants');
 334      $table->set_attribute('class', 'generaltable generalbox');
 335  
 336      $table->set_control_variables(array(
 337                  TABLE_VAR_SORT    => 'ssort',
 338                  TABLE_VAR_HIDE    => 'shide',
 339                  TABLE_VAR_SHOW    => 'sshow',
 340                  TABLE_VAR_IFIRST  => 'sifirst',
 341                  TABLE_VAR_ILAST   => 'silast',
 342                  TABLE_VAR_PAGE    => 'spage'
 343                  ));
 344      $table->setup();
 345  
 346  
 347      // we are looking for all users with this role assigned in this context or higher
 348      if ($usercontexts = get_parent_contexts($context)) {
 349          $listofcontexts = '('.implode(',', $usercontexts).')';
 350      } else {
 351          $listofcontexts = '('.$sitecontext->id.')'; // must be site
 352      }
 353      if ($roleid > 0) {
 354          $selectrole = " AND r.roleid = $roleid ";
 355      } else {
 356          $selectrole = " ";
 357      }
 358  
 359      if ($context->id != $frontpagectx->id) {
 360          $select = 'SELECT DISTINCT u.id, u.username, u.firstname, u.lastname,
 361                        u.email, u.city, u.country, u.picture,
 362                        u.lang, u.timezone, u.emailstop, u.maildisplay, u.imagealt,
 363                        COALESCE(ul.timeaccess, 0) AS lastaccess,
 364                        r.hidden,
 365                        ctx.id AS ctxid, ctx.path AS ctxpath,
 366                        ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel ';
 367          $select .= $course->enrolperiod?', r.timeend ':'';
 368      } else {
 369          if ($roleid >= 0) {
 370              $select = 'SELECT u.id, u.username, u.firstname, u.lastname,
 371                            u.email, u.city, u.country, u.picture,
 372                            u.lang, u.timezone, u.emailstop, u.maildisplay, u.imagealt,
 373                            u.lastaccess, r.hidden,
 374                            ctx.id AS ctxid, ctx.path AS ctxpath,
 375                            ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel ';
 376          } else {
 377              $select = 'SELECT u.id, u.username, u.firstname, u.lastname,
 378                            u.email, u.city, u.country, u.picture,
 379                            u.lang, u.timezone, u.emailstop, u.maildisplay, u.imagealt,
 380                            u.lastaccess,
 381                            ctx.id AS ctxid, ctx.path AS ctxpath,
 382                            ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel ';
 383          }
 384      }
 385  
 386      if ($context->id != $frontpagectx->id or $roleid >= 0) {
 387          $from   = "FROM {$CFG->prefix}user u
 388                  LEFT OUTER JOIN {$CFG->prefix}context ctx
 389                      ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.")
 390                  JOIN {$CFG->prefix}role_assignments r
 391                      ON u.id=r.userid
 392                  LEFT OUTER JOIN {$CFG->prefix}user_lastaccess ul
 393                      ON (r.userid=ul.userid and ul.courseid = $course->id) ";
 394      } else {
 395          // on frontpage and we want all registered users
 396          $from = "FROM {$CFG->prefix}user u
 397                  LEFT OUTER JOIN {$CFG->prefix}context ctx
 398                      ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.") ";
 399      }
 400  
 401      $hiddensql = has_capability('moodle/role:viewhiddenassigns', $context)? '':' AND r.hidden = 0 ';
 402  
 403      // exclude users with roles we are avoiding
 404      if ($avoidroles) {
 405          $adminroles = 'AND r.roleid NOT IN (';
 406          $adminroles .= implode(',', $avoidroles);
 407          $adminroles .= ')';
 408      } else {
 409          $adminroles = '';
 410      }
 411  
 412      // join on 2 conditions
 413      // otherwise we run into the problem of having records in ul table, but not relevant course
 414      // and user record is not pulled out
 415  
 416      if ($context->id != $frontpagectx->id) {
 417          $where  = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts)
 418              AND u.deleted = 0 $selectrole
 419              AND (ul.courseid = $course->id OR ul.courseid IS NULL)
 420              AND u.username != 'guest'
 421              $adminroles
 422              $hiddensql ";
 423              $where .= get_course_lastaccess_sql($accesssince);
 424      } else {
 425          if ($roleid >= 0) {
 426              $where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts)
 427                  AND u.deleted = 0 $selectrole
 428                  AND u.username != 'guest'";
 429                  $where .= get_user_lastaccess_sql($accesssince);
 430          } else {
 431              $where = "WHERE u.deleted = 0
 432                  AND u.username != 'guest'";
 433                  $where .= get_user_lastaccess_sql($accesssince);
 434          }
 435      }
 436      $wheresearch = '';
 437  
 438      if (!empty($search)) {
 439          $LIKE = sql_ilike();
 440          $fullname  = sql_fullname('u.firstname','u.lastname');
 441          $wheresearch .= ' AND ('. $fullname .' '. $LIKE .'\'%'. $search .'%\' OR email '. $LIKE .'\'%'. $search .'%\' OR idnumber '.$LIKE.' \'%'.$search.'%\') ';
 442  
 443      }
 444  
 445      if ($currentgroup) {    // Displaying a group by choice
 446          // FIX: TODO: This will not work if $currentgroup == 0, i.e. "those not in a group"
 447          $from  .= 'LEFT JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid ';
 448          $where .= ' AND gm.groupid = '.$currentgroup;
 449      }
 450  
 451      $totalcount = count_records_sql('SELECT COUNT(distinct u.id) '.$from.$where);   // Each user could have > 1 role
 452  
 453      if ($table->get_sql_where()) {
 454          $where .= ' AND '.$table->get_sql_where();
 455      }
 456  
 457      /// Always add r.hidden to sort in order to guarantee hiddens to "win"
 458      /// in the resolution of duplicates later - MDL-13935
 459      /// Only exception is frontpage that doesn't have such r.hidden info
 460      /// because it retrieves ALL users (without role checking) - MDL-14034
 461      if ($table->get_sql_sort()) {
 462          $sort = ' ORDER BY '.$table->get_sql_sort();
 463          if ($context->id != $frontpagectx->id or $roleid >= 0) {
 464              $sort .= ', r.hidden DESC';
 465          }
 466      } else {
 467          $sort = '';
 468          if ($context->id != $frontpagectx->id or $roleid >= 0) {
 469              $sort .= ' ORDER BY r.hidden DESC';
 470          }
 471      }
 472  
 473      $matchcount = count_records_sql('SELECT COUNT(distinct u.id) '.$from.$where.$wheresearch);
 474  
 475      $table->initialbars(true);
 476      $table->pagesize($perpage, $matchcount);
 477  
 478      $userlist = get_recordset_sql($select.$from.$where.$wheresearch.$sort,
 479              $table->get_page_start(),  $table->get_page_size());
 480  
 481      if ($context->id == $frontpagectx->id) {
 482          $strallsiteusers = get_string('allsiteusers', 'role');
 483          if ($CFG->defaultfrontpageroleid) {
 484              if ($fprole = get_record('role', 'id', $CFG->defaultfrontpageroleid)) {
 485                  $fprole = role_get_name($fprole, $frontpagectx);
 486                  $strallsiteusers = "$strallsiteusers ($fprole)";
 487              }
 488          }
 489          $rolenames = array(-1 => $strallsiteusers) + $rolenames;
 490      }
 491  
 492      /// If there are multiple Roles in the course, then show a drop down menu for switching
 493      if (count($rolenames) > 1) {
 494          echo '<div class="rolesform">';
 495          echo '<label for="rolesform_jump">'.get_string('currentrole', 'role').'&nbsp;</label>';
 496          if ($context->id != $frontpagectx->id) {
 497              $rolenames = array(0 => get_string('all')) + $rolenames;
 498          } else {
 499              if (!$CFG->defaultfrontpageroleid) {
 500                  // we do not want "All users with role" - we already have all users in defualt frontpage role option
 501                  $rolenames = array(0 => get_string('userswithrole', 'role')) + $rolenames;
 502              }
 503          }
 504          popup_form("$CFG->wwwroot/user/index.php?contextid=$context->id&amp;sifirst=&amp;silast=&amp;roleid=", $rolenames,
 505                     'rolesform', $roleid, '');
 506          echo '</div>';
 507  
 508      } else if (count($rolenames) == 1) {
 509          // when all users with the same role - print its name
 510          echo '<div class="rolesform">';
 511          echo get_string('role').': ';
 512          $rolename = reset($rolenames);
 513          echo $rolename;
 514          echo '</div>';
 515      }
 516  
 517      if ($roleid > 0) {
 518          if (!$currentrole = get_record('role','id',$roleid)) {
 519              error('That role does not exist');
 520          }
 521          $a->number = $totalcount;
 522          // MDL-12217, use course specific rolename
 523          if (isset($rolenames[$currentrole->id])){
 524              $a->role = $rolenames[$currentrole->id];
 525          }else{
 526              $a->role = $currentrole->name;//safety net
 527          }
 528          $heading = format_string(get_string('xuserswiththerole', 'role', $a));
 529  
 530          if ($currentgroup and $group) {
 531              $a->group = $group->name;
 532              $heading .= ' ' . format_string(get_string('ingroup', 'role', $a));
 533          }
 534  
 535          if ($accesssince) {
 536              $a->timeperiod = $timeoptions[$accesssince];
 537              $heading .= ' ' . format_string(get_string('inactiveformorethan', 'role', $a));
 538          }
 539  
 540          $heading .= ": $a->number";
 541          if (user_can_assign($context, $roleid)) {
 542              $heading .= ' <a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?roleid='.$roleid.'&amp;contextid='.$context->id.'">';
 543              $heading .= '<img src="'.$CFG->pixpath.'/i/edit.gif" class="icon" alt="" /></a>';
 544          }
 545          print_heading($heading, 'center', 3);
 546      } else {
 547          if ($course->id != SITEID && has_capability('moodle/role:assign', $context)) {
 548              $editlink  = ' <a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">';
 549              $editlink .= '<img src="'.$CFG->pixpath.'/i/edit.gif" class="icon" alt="" /></a>';
 550          } else {
 551              $editlink = '';
 552          }
 553          if ($course->id == SITEID and $roleid < 0) {
 554              $strallparticipants = get_string('allsiteusers', 'role');
 555          } else {
 556              $strallparticipants = get_string('allparticipants');
 557          }
 558          if ($matchcount < $totalcount) {
 559              print_heading($strallparticipants.': '.$matchcount.'/'.$totalcount . $editlink, '', 3);
 560          } else {
 561              print_heading($strallparticipants.': '.$matchcount . $editlink, '', 3);
 562          }
 563      }
 564  
 565  
 566      if ($bulkoperations) {
 567          echo '
 568          <script type="text/javascript">
 569          //<![CDATA[
 570          function checksubmit(form) {
 571              var destination = form.formaction.options[form.formaction.selectedIndex].value;
 572              if (destination == "" || !checkchecked(form)) {
 573                  form.formaction.selectedIndex = 0;
 574                  return false;
 575              } else {
 576                  return true;
 577              }
 578          }
 579  
 580          function checkchecked(form) {
 581              var inputs = document.getElementsByTagName(\'INPUT\');
 582              var checked = false;
 583              inputs = filterByParent(inputs, function() {return form;});
 584              for(var i = 0; i < inputs.length; ++i) {
 585                  if (inputs[i].type == \'checkbox\' && inputs[i].checked) {
 586                      checked = true;
 587                  }
 588              }
 589              return checked;
 590          }
 591          //]]>
 592          </script>
 593              ';
 594          echo '<form action="action_redir.php" method="post" id="participantsform" onsubmit="return checksubmit(this);">';
 595          echo '<div>';
 596          echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
 597          echo '<input type="hidden" name="returnto" value="'.s(me()).'" />';
 598      }
 599  
 600      if ($CFG->longtimenosee > 0 && $CFG->longtimenosee < 1000 && $totalcount > 0) {
 601          echo '<p id="longtimenosee">('.get_string('unusedaccounts', '', $CFG->longtimenosee).')</p>';
 602      }
 603  
 604      if ($fullmode) {    // Print simple listing
 605          if ($totalcount < 1) {
 606              print_heading(get_string('nothingtodisplay'));
 607          } else {
 608              if ($totalcount > $perpage) {
 609  
 610                  $firstinitial = $table->get_initial_first();
 611                  $lastinitial  = $table->get_initial_last();
 612                  $strall = get_string('all');
 613                  $alpha  = explode(',', get_string('alphabet'));
 614  
 615                  // Bar of first initials
 616  
 617                  echo '<div class="initialbar firstinitial">'.get_string('firstname').' : ';
 618                  if(!empty($firstinitial)) {
 619                      echo '<a href="'.$baseurl.'&amp;sifirst=">'.$strall.'</a>';
 620                  } else {
 621                      echo '<strong>'.$strall.'</strong>';
 622                  }
 623                  foreach ($alpha as $letter) {
 624                      if ($letter == $firstinitial) {
 625                          echo ' <strong>'.$letter.'</strong>';
 626                      } else {
 627                          echo ' <a href="'.$baseurl.'&amp;sifirst='.$letter.'">'.$letter.'</a>';
 628                      }
 629                  }
 630                  echo '</div>';
 631  
 632                  // Bar of last initials
 633  
 634                  echo '<div class="initialbar lastinitial">'.get_string('lastname').' : ';
 635                  if(!empty($lastinitial)) {
 636                      echo '<a href="'.$baseurl.'&amp;silast=">'.$strall.'</a>';
 637                  } else {
 638                      echo '<strong>'.$strall.'</strong>';
 639                  }
 640                  foreach ($alpha as $letter) {
 641                      if ($letter == $lastinitial) {
 642                          echo ' <strong>'.$letter.'</strong>';
 643                      } else {
 644                          echo ' <a href="'.$baseurl.'&amp;silast='.$letter.'">'.$letter.'</a>';
 645                      }
 646                  }
 647                  echo '</div>';
 648  
 649                  print_paging_bar($matchcount, intval($table->get_page_start() / $perpage), $perpage, $baseurl.'&amp;', 'spage');
 650              }
 651  
 652              if ($matchcount > 0) {
 653                  $usersprinted = array();
 654                  while ($user = rs_fetch_next_record($userlist)) {
 655                      if (in_array($user->id, $usersprinted)) { /// Prevent duplicates by r.hidden - MDL-13935
 656                          continue;
 657                      }
 658                      $usersprinted[] = $user->id; /// Add new user to the array of users printed
 659  
 660                      $user = make_context_subobj($user);
 661                      print_user($user, $course, $bulkoperations);
 662                  }
 663  
 664              } else {
 665                  print_heading(get_string('nothingtodisplay'));
 666              }
 667          }
 668  
 669      } else {
 670          $countrysort = (strpos($sort, 'country') !== false);
 671          $timeformat = get_string('strftimedate');
 672  
 673  
 674          if ($userlist)  {
 675              $usersprinted = array();
 676              while ($user = rs_fetch_next_record($userlist)) {
 677                  if (in_array($user->id, $usersprinted)) { /// Prevent duplicates by r.hidden - MDL-13935
 678                      continue;
 679                  }
 680                  $usersprinted[] = $user->id; /// Add new user to the array of users printed
 681  
 682                  $user = make_context_subobj($user);
 683                  if ( !empty($user->hidden) ) {
 684                  // if the assignment is hidden, display icon
 685                      $hidden = " <img src=\"{$CFG->pixpath}/t/show.gif\" title=\"".get_string('userhashiddenassignments', 'role')."\" alt=\"".get_string('hiddenassign')."\" class=\"hide-show-image\"/>";
 686                  } else {
 687                      $hidden = '';
 688                  }
 689  
 690                  if ($user->lastaccess) {
 691                      $lastaccess = format_time(time() - $user->lastaccess, $datestring);
 692                  } else {
 693                      $lastaccess = $strnever;
 694                  }
 695  
 696                  if (empty($user->country)) {
 697                      $country = '';
 698  
 699                  } else {
 700                      if($countrysort) {
 701                          $country = '('.$user->country.') '.$countries[$user->country];
 702                      }
 703                      else {
 704                          $country = $countries[$user->country];
 705                      }
 706                  }
 707  
 708                  if (!isset($user->context)) {
 709                      $usercontext = get_context_instance(CONTEXT_USER, $user->id);
 710                  } else {
 711                      $usercontext = $user->context;
 712                  }
 713  
 714                  if ($piclink = ($USER->id == $user->id || has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext))) {
 715                      $profilelink = '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id.'">'.fullname($user).'</a></strong>';
 716                  } else {
 717                      $profilelink = '<strong>'.fullname($user).'</strong>';
 718                  }
 719  
 720                  $data = array (
 721                          print_user_picture($user, $course->id, $user->picture, false, true, $piclink),
 722                          $profilelink . $hidden);
 723  
 724                  if (!isset($hiddenfields['city'])) {
 725                      $data[] = $user->city;
 726                  }
 727                  if (!isset($hiddenfields['country'])) {
 728                      $data[] = $country;
 729                  }
 730                  if (!isset($hiddenfields['lastaccess'])) {
 731                      $data[] = $lastaccess;
 732                  }
 733                  if ($course->enrolperiod) {
 734                      if ($user->timeend) {
 735                          $data[] = userdate($user->timeend, $timeformat);
 736                      } else {
 737                          $data[] = get_string('unlimited');
 738                      }
 739                  }
 740                  if ($bulkoperations) {
 741                      $data[] = '<input type="checkbox" name="user'.$user->id.'" />';
 742                  }
 743                  $table->add_data($data);
 744  
 745              }
 746          }
 747  
 748          $table->print_html();
 749  
 750      }
 751  
 752      if ($bulkoperations) {
 753          echo '<br /><div class="buttons">';
 754          echo '<input type="button" onclick="checkall()" value="'.get_string('selectall').'" /> ';
 755          echo '<input type="button" onclick="checknone()" value="'.get_string('deselectall').'" /> ';
 756          $displaylist = array();
 757          $displaylist['messageselect.php'] = get_string('messageselectadd');
 758          if (has_capability('moodle/notes:manage', $context) && $context->id != $frontpagectx->id) {
 759              $displaylist['addnote.php'] = get_string('addnewnote', 'notes');
 760              $displaylist['groupaddnote.php'] = get_string('groupaddnewnote', 'notes');
 761          }
 762  
 763          if ($context->id != $frontpagectx->id) {
 764              $displaylist['extendenrol.php'] = get_string('extendenrol');
 765              $displaylist['groupextendenrol.php'] = get_string('groupextendenrol');
 766          }
 767  
 768          helpbutton("participantswithselectedusers", get_string("withselectedusers"));
 769          choose_from_menu ($displaylist, "formaction", "", get_string("withselectedusers"), "if(checksubmit(this.form))this.form.submit();", "");
 770          echo '<input type="hidden" name="id" value="'.$course->id.'" />';
 771          echo '<div id="noscriptparticipantsform" style="display: inline;">';
 772          echo '<input type="submit" value="'.get_string('ok').'" /></div>';
 773          echo '<script type="text/javascript">'.
 774                 "\n//<![CDATA[\n".
 775                 'document.getElementById("noscriptparticipantsform").style.display = "none";'.
 776                 "\n//]]>\n".'</script>';
 777          echo '</div>';
 778          echo '</div>';
 779          echo '</form>';
 780  
 781      }
 782  
 783      if ($bulkoperations && $totalcount > ($perpage*3)) {
 784          echo '<form action="index.php"><div><input type="hidden" name="id" value="'.$course->id.'" />'.get_string('search').':&nbsp;'."\n";
 785          echo '<input type="text" name="search" value="'.s($search).'" />&nbsp;<input type="submit" value="'.get_string('search').'" /></div></form>'."\n";
 786      }
 787  
 788      $perpageurl = preg_replace('/&amp;perpage=\d*/','', $baseurl);
 789      if ($perpage == SHOW_ALL_PAGE_SIZE) {
 790          echo '<div id="showall"><a href="'.$perpageurl.'&amp;perpage='.DEFAULT_PAGE_SIZE.'">'.get_string('showperpage', '', DEFAULT_PAGE_SIZE).'</a></div>';
 791  
 792      } else if ($matchcount > 0 && $perpage < $matchcount) {
 793          echo '<div id="showall"><a href="'.$perpageurl.'&amp;perpage='.SHOW_ALL_PAGE_SIZE.'">'.get_string('showall', '', $matchcount).'</a></div>';
 794      }
 795  
 796      print_footer($course);
 797  
 798      if ($userlist) {
 799          rs_close($userlist);
 800      }
 801  
 802  
 803  function get_course_lastaccess_sql($accesssince='') {
 804      if (empty($accesssince)) {
 805          return '';
 806      }
 807      if ($accesssince == -1) { // never
 808          return ' AND ul.timeaccess = 0';
 809      } else {
 810          return ' AND ul.timeaccess != 0 AND ul.timeaccess < '.$accesssince;
 811      }
 812  }
 813  
 814  function get_user_lastaccess_sql($accesssince='') {
 815      if (empty($accesssince)) {
 816          return '';
 817      }
 818      if ($accesssince == -1) { // never
 819          return ' AND u.lastaccess = 0';
 820      } else {
 821          return ' AND u.lastaccess != 0 AND u.lastaccess < '.$accesssince;
 822      }
 823  }
 824  
 825  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7