]> git.mjollnir.org Git - moodle.git/commitdiff
According to the final comments in SC#65:
authordefacer <defacer>
Sun, 23 Jan 2005 21:38:01 +0000 (21:38 +0000)
committerdefacer <defacer>
Sun, 23 Jan 2005 21:38:01 +0000 (21:38 +0000)
Made isteacher() require that the first parameter (course id) be
specified and non-empty. If it is empty, [i.e., 0, which was used to
simulate what has now become isteacherinanycourse()], then the return
value IS correct but a warning is printed on screen. This should allow
us to track down any such calls in legacy modules without breaking Moodle.

The correct way to check for teacher status in ANY course is now to
call isteacherinanycourse().

blocks/participants/block_participants.php
lib/datalib.php
lib/moodlelib.php
mod/quiz/preview.php
mod/quiz/quizfile.php
user/index.php
user/view.php

index bc2e4aaa5ac92580edff72d15fb7a703744a2f8b..476a09f87b380551e6e8687df9f602a885e1cfb1 100644 (file)
@@ -28,7 +28,7 @@ class block_participants extends block_base {
 
         $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="" />';
         }
index c3c88e0ec8bbc3366f7476d36759a53c8bac7a9e..bcea6cc210c89f9fee89826907141397dae54538 100644 (file)
@@ -2765,7 +2765,7 @@ function count_login_failures($mode, $username, $lastlogin) {
             $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;
         }
index 675e2c0e2d10dba1c54e7cc469f507ca4ecb6490..cbdf458cac50d849a1e52afad168dbc2d6c9733c 100644 (file)
@@ -1079,20 +1079,25 @@ function isadmin($userid=0) {
 /**
  * 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]);
@@ -1103,11 +1108,27 @@ function isteacher($courseid=0, $userid=0, $includeadmin=true) {
         $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);
 }
 
 /**
index 292a874a97335323ee5d3fa685520c1f82bbaafe..af3bf42b7516d230dac0e78f9aaa542aeb728bde 100644 (file)
@@ -47,7 +47,7 @@ $qtype = $question->qtype;
 
 require_login();
 
-if (!isteacher()) {
+if (!isteacherinanycourse()) {
     error('This page is for teachers only');
 }
 
index f38c0f437489071e20a14b137efdb12e43923708..a1ab10de663631c923b8d3e21433debcfe067d3d 100644 (file)
     /////////////////////////////////////
     // 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 {
index dc26787a75368857a087301dbbca50b22eaab888..77629e442e677b5b2e7c0663e1aaa142ed1b78e2 100644 (file)
@@ -28,7 +28,7 @@
         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'));
         }
     }
index 7e2fff741dbac336f625725730a7d3655019cae9..633ef04cfb0bb7bed2363fd490a87251f1a45678 100644 (file)
@@ -69,7 +69,7 @@
     }
 
     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, "&nbsp;", navmenu($course));