From: toyomoyo <toyomoyo>
Date: Wed, 7 Mar 2007 06:22:58 +0000 (+0000)
Subject: do not force parents to enrol
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7034b46c8a27c3a5f9e5ce24952b0dac8fc43b9a;p=moodle.git

do not force parents to enrol
---

diff --git a/mod/forum/user.php b/mod/forum/user.php
index 4fb6749302..98b728dcf1 100644
--- a/mod/forum/user.php
+++ b/mod/forum/user.php
@@ -25,9 +25,12 @@
     }
 
     $syscontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
-
-    require_course_login($course);
-
+    $usercontext   = get_context_instance(CONTEXT_USER, $id);
+    
+    // do not force parents to enrol
+    if (!get_record('role_assignments', 'userid', $USER->id, 'contextid', $usercontext->id)) {
+        require_course_login($course);
+    }
 
     add_to_log($course->id, "forum", "user report", "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode", "$user->id"); 
 
diff --git a/user/view.php b/user/view.php
index 101c2b990c..9ee7053a12 100644
--- a/user/view.php
+++ b/user/view.php
@@ -29,10 +29,6 @@
        $currentuser = ($user->id == $USER->id);
     }
 
-    if (!empty($CFG->forcelogin) || $course->id != SITEID) {
-        require_login($course->id);
-    }
-
     if ($course->id == SITEID) {
         $coursecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);   // SYSTEM context
     } else {
@@ -40,8 +36,17 @@
     }
     $usercontext   = get_context_instance(CONTEXT_USER, $user->id);       // User context
     
+    if (!empty($CFG->forcelogin) || $course->id != SITEID) {
+        // do not force parents to enrol
+        if (!get_record('role_assignments', 'userid', $USER->id, 'contextid', $usercontext->id)) {
+            require_login($course->id);
+        }
+    }
+    
     // make sure user can view this student's profile
-    if ($USER->id != $user->id && !has_capability('moodle/user:viewdetails', $coursecontext) && !has_capability('moodle/user:viewdetails', $usercontext)) {
+    if ($USER->id != $user->id && 
+        (!has_capability('moodle/user:viewdetails', $coursecontext) && !has_capability('moodle/user:viewdetails', $usercontext))
+        && !has_capability('moodle/user:viewdetails', $usercontext)) {
         error('You can not view the profile of this user');
     }
 
@@ -132,7 +137,7 @@
 
 
     if (($course->id != SITEID) and ! isguest() ) {   // Need to have access to a course to see that info
-        if (!has_capability('moodle/course:view', $coursecontext)) {
+        if (!has_capability('moodle/course:view', $coursecontext, $user->id)) {
             print_heading(get_string('notenrolled', '', $fullname));
             print_footer($course);
             die;