$course = get_record('course', 'id', $this->instance->pageid);
- if ($this->instance->pageid != SITEID || $CFG->showsiteparticipantslist > 1 || ($CFG->showsiteparticipantslist == 1 && isteacher()) || isteacher(SITEID)) {
+ if ($this->instance->pageid != SITEID || $CFG->showsiteparticipantslist > 1 || ($CFG->showsiteparticipantslist == 1 && isteacherinanycourse()) || isteacher(SITEID)) {
$this->content->items[]='<a title="'.get_string('listofallpeople').'" href="'.$CFG->wwwroot.'/user/index.php?id='.$this->instance->pageid.'">'.get_string('participants').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/users.gif" height="16" width="16" alt="" />';
}
$count->accounts = count_records_select('log', $select, 'COUNT(DISTINCT info)');
return $count;
}
- } else if ($mode == 'everybody' or ($mode == 'teacher' and isteacher())) {
+ } else if ($mode == 'everybody' or ($mode == 'teacher' and isteacherinanycourse())) {
if ($count->attempts = count_records_select('log', $select .' AND info = \''. $username .'\'')) {
return $count;
}
/**
* Determines if a user is a teacher or an admin
*
- * @uses $USER
+ * @uses $USER
* @param int $courseid The id of the course that is being viewed, if any
* @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
* @param boolean $includeadmin If true this function will return true when it encounters an admin user.
* @return boolean
* @todo Finish documenting this function
*/
-function isteacher($courseid=0, $userid=0, $includeadmin=true) {
+function isteacher($courseid, $userid=0, $includeadmin=true) {
global $USER;
if ($includeadmin and isadmin($userid)) { // admins can do anything the teacher can
return true;
}
+ if (empty($courseid)) {
+ notify('isteacher() should not be used without a valid course id as argument');
+ return isteacherinanycourse($userid, $includeadmin);
+ }
+
if (!$userid) {
if ($courseid) {
return !empty($USER->teacher[$courseid]);
$userid = $USER->id;
}
- if (!$courseid) {
- return record_exists('user_teachers', 'userid', $userid);
+ return record_exists('user_teachers', 'userid', $userid, 'course', $courseid);
+}
+
+/**
+ * Determines if a user is a teacher in any course, or an admin
+ *
+ * @uses $USER
+ * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
+ * @param boolean $includeadmin If true this function will return true when it encounters an admin user.
+ * @return boolean
+ * @todo Finish documenting this function
+ */
+function isteacherinanycourse($userid = 0, $includeadmin = true) {
+ if(empty($userid)) {
+ if(empty($USER) || empty($USER->id)) {
+ return false;
+ }
+ $userid = $USER->id;
}
- return record_exists('user_teachers', 'userid', $userid, 'course', $courseid);
+ return record_exists('user_teachers', 'userid', $userid);
}
/**
require_login();
-if (!isteacher()) {
+if (!isteacherinanycourse()) {
error('This page is for teachers only');
}
/////////////////////////////////////
// Check access
/////////////////////////////////////
- if ($quizid == 0) { // teache doing preview during quiz creation
+ if ($quizid == 0) { // teacher doing preview during quiz creation
if ($questioncategory->publish) {
require_login();
- if (!isteacher()) {
+ if (!isteacherinanycourse()) {
error('No valid arguments supplied');
}
} else {
if (!$CFG->showsiteparticipantslist and !isteacher(SITEID)) {
notice(get_string('sitepartlist0'));
}
- if ($CFG->showsiteparticipantslist < 2 and !isteacher()) {
+ if ($CFG->showsiteparticipantslist < 2 and !isteacherinanycourse()) {
notice(get_string('sitepartlist1'));
}
}
}
if (!$course->category and !$currentuser) { // To reduce possibility of "browsing" userbase at site level
- if (!isteacher() and !isteacher(0, $user->id) ) { // Teachers can browse and be browsed at site level
+ if (!isteacherinanycourse() and !isteacherinanycourse($user->id) ) { // Teachers can browse and be browsed at site level
print_header("$personalprofile: ", "$personalprofile: ",
"<a href=\"index.php?id=$course->id\">$participants</a>",
"", "", true, " ", navmenu($course));