diff --git a/user/index.php b/user/index.php index f0bc5ff9dab..9abdc74dd2e 100644 --- a/user/index.php +++ b/user/index.php @@ -337,7 +337,20 @@ {$CFG->prefix}role_assignments r on u.id=r.userid LEFT OUTER JOIN {$CFG->prefix}user_lastaccess ul on (r.userid=ul.userid and ul.courseid = $course->id)"; - $hiddensql = has_capability('moodle/role:viewhiddenassigns', $context)? '':' AND r.hidden = 0 '; + $hiddensql = has_capability('moodle/role:viewhiddenassigns', $context)? '':' AND r.hidden = 0 '; + + // excluse users with these admin role assignments + if ($doanythingroles) { + $adminroles = 'AND r.id NOT IN ('; + + foreach ($doanythingroles as $aroleid=>$role) { + $adminroles .= "$aroleid,"; + } + $adminroles = rtrim($adminroles,","); + $adminroles .= ')'; + } else { + $adminroles = ''; + } // join on 2 conditions // otherwise we run into the problem of having records in ul table, but not relevant course @@ -345,7 +358,8 @@ $where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts) AND u.deleted = 0 $selectrole AND (ul.courseid = $course->id OR ul.courseid IS NULL) - AND u.username <> 'guest' + AND u.username != 'guest' + $adminroles $hiddensql "; $where .= get_lastaccess_sql($accesssince);