diff --git a/user/index.php b/user/index.php index 9accbcaac3e..3a74657d953 100644 --- a/user/index.php +++ b/user/index.php @@ -158,23 +158,21 @@ /// If there are multiple Roles in the course, then show a drop down menu for switching - if ($roles = get_roles_used_in_context($context)) { + $rolenames = array(); - $rolenames = array(); + if ($roles = get_roles_used_in_context($context)) { foreach ($roles as $role) { $rolenames[$role->id] = $role->name; } - if (empty($roleid)) { - $roleid = array_shift(array_keys($rolenames)); // get first element + if (!empty($roleid)) { + echo '
'; } - - echo ''; } @@ -316,59 +314,57 @@ function checkchecked(form) { echo ''; } - $guest = get_guest(); - $exceptions[] = $guest->id; + /// Define a table showing a list of users in the current role. - - $tablecolumns = array('picture', 'fullname'); - $tableheaders = array('', get_string('fullname')); - if (!isset($hiddenfields['city'])) { - $tablecolumns[] = 'city'; - $tableheaders[] = get_string('city'); - } - if (!isset($hiddenfields['country'])) { - $tablecolumns[] = 'country'; - $tableheaders[] = get_string('country'); - } - if (!isset($hiddenfields['lastaccess'])) { - $tablecolumns[] = 'lastaccess'; - $tableheaders[] = get_string('lastaccess'); - } - - if ($course->enrolperiod) { - $tablecolumns[] = 'timeend'; - $tableheaders[] = get_string('enrolmentend'); - } - - if ($isteacher) { - $tablecolumns[] = ''; - $tableheaders[] = get_string('select'); - } - - $table = new flexible_table('user-index-students-'.$course->id); - - $table->define_columns($tablecolumns); - $table->define_headers($tableheaders); - $table->define_baseurl($baseurl); - - $table->sortable(true, 'lastaccess', SORT_DESC); - - $table->set_attribute('cellspacing', '0'); - $table->set_attribute('id', 'students'); - $table->set_attribute('class', 'generaltable generalbox'); - - $table->set_control_variables(array( - TABLE_VAR_SORT => 'ssort', - TABLE_VAR_HIDE => 'shide', - TABLE_VAR_SHOW => 'sshow', - TABLE_VAR_IFIRST => 'sifirst', - TABLE_VAR_ILAST => 'silast', - TABLE_VAR_PAGE => 'spage' - )); - $table->setup(); - if ($roleid) { + $tablecolumns = array('picture', 'fullname'); + $tableheaders = array('', get_string('fullname')); + if (!isset($hiddenfields['city'])) { + $tablecolumns[] = 'city'; + $tableheaders[] = get_string('city'); + } + if (!isset($hiddenfields['country'])) { + $tablecolumns[] = 'country'; + $tableheaders[] = get_string('country'); + } + if (!isset($hiddenfields['lastaccess'])) { + $tablecolumns[] = 'lastaccess'; + $tableheaders[] = get_string('lastaccess'); + } + + if ($course->enrolperiod) { + $tablecolumns[] = 'timeend'; + $tableheaders[] = get_string('enrolmentend'); + } + + if ($isteacher) { + $tablecolumns[] = ''; + $tableheaders[] = get_string('select'); + } + + $table = new flexible_table('user-index-students-'.$course->id); + + $table->define_columns($tablecolumns); + $table->define_headers($tableheaders); + $table->define_baseurl($baseurl); + + $table->sortable(true, 'lastaccess', SORT_DESC); + + $table->set_attribute('cellspacing', '0'); + $table->set_attribute('id', 'students'); + $table->set_attribute('class', 'generaltable generalbox'); + + $table->set_control_variables(array( + TABLE_VAR_SORT => 'ssort', + TABLE_VAR_HIDE => 'shide', + TABLE_VAR_SHOW => 'sshow', + TABLE_VAR_IFIRST => 'sifirst', + TABLE_VAR_ILAST => 'silast', + TABLE_VAR_PAGE => 'spage' + )); + $table->setup(); + // we are looking for all users with this role assigned in this context or higher if ($usercontexts = get_parent_contexts($context)) { @@ -386,7 +382,8 @@ function checkchecked(form) { $where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts) AND u.deleted = 0 AND r.roleid = $roleid - AND (ul.courseid = $course->id OR ul.courseid IS NULL)"; + AND (ul.courseid = $course->id OR ul.courseid IS NULL) + AND u.username <> 'guest' "; $where .= get_lastaccess_sql($accesssince); $wheresearch = ''; @@ -405,6 +402,9 @@ function checkchecked(form) { } if ($course->id == SITEID) { + $guest = get_guest(); + $exceptions[] = $guest->id; + $where .= ' AND u.id NOT IN ('.implode(',', $exceptions).')'; } @@ -431,9 +431,9 @@ function checkchecked(form) { error('That role does not exist'); } - $a->count = $totalcount; - $a->items = $currentrole->name; - echo '