### Eclipse Workspace Patch 1.0
#P moodle
Index: course/enrol.php
===================================================================
RCS file: /cvsroot/moodle/moodle/course/enrol.php,v
retrieving revision 1.47
diff -u -r1.47 enrol.php
--- course/enrol.php	23 Nov 2006 20:16:36 -0000	1.47
+++ course/enrol.php	14 Dec 2006 23:22:05 -0000
@@ -8,12 +8,15 @@
     require_once("$CFG->dirroot/enrol/enrol.class.php");
 
     $id           = required_param('id', PARAM_INT);
-    $loginasguest = optional_param('loginasguest', 0, PARAM_BOOL);
+    $loginasguest = optional_param('loginasguest', 0, PARAM_BOOL); // hmm, is this still needed?
 
-    require_login();
-
-    if ($USER->username == 'guest') {                      // Guests can't enrol in anything!
-        redirect($CFG->wwwroot.'/login/index.php');
+    if (!isloggedin()) {
+        $wwwroot = $CFG->wwwroot;
+        if (!empty($CFG->loginhttps)) {
+            $wwwroot = str_replace('http:','https:', $wwwroot);
+        }
+        // do not use require_login here because we are usually comming from it
+        redirect($wwwroot.'/login/index.php');
     }
 
     if (! $course = get_record('course', 'id', $id) ) {
@@ -34,7 +37,7 @@
 /// thus got to this script by mistake.  This might occur if enrolments 
 /// changed during this session or something
 
-    if (has_capability('moodle/course:view', $context) and !has_capability('moodle/legacy:guest', $context)) {
+    if (has_capability('moodle/course:view', $context) and !has_capability('moodle/legacy:guest', $context, NULL, false)) {
         if ($SESSION->wantsurl) {
             $destination = $SESSION->wantsurl;
             unset($SESSION->wantsurl);
Index: enrol/authorize/enrol.php
===================================================================
RCS file: /cvsroot/moodle/moodle/enrol/authorize/enrol.php,v
retrieving revision 1.127
diff -u -r1.127 enrol.php
--- enrol/authorize/enrol.php	29 Nov 2006 11:05:56 -0000	1.127
+++ enrol/authorize/enrol.php	14 Dec 2006 23:22:06 -0000
@@ -64,7 +64,7 @@
         }
 
         print_simple_box_start('center', '80%');
-        if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), $USER->id, false)) {
+        if ($USER->username == 'guest') { // only real guest user, not for users with guest role
             $curcost = get_course_cost($course);
             echo '<div align="center">';
             echo '<p>'.get_string('paymentrequired').'</p>';
Index: enrol/manual/enrol.php
===================================================================
RCS file: /cvsroot/moodle/moodle/enrol/manual/enrol.php,v
retrieving revision 1.12
diff -u -r1.12 enrol.php
--- enrol/manual/enrol.php	23 Oct 2006 06:38:15 -0000	1.12
+++ enrol/manual/enrol.php	14 Dec 2006 23:22:06 -0000
@@ -137,11 +137,9 @@
 
     $groupid = $this->check_group_entry($course->id, $form->password);
 
-    $context = get_context_instance(CONTEXT_COURSE, $course->id);
-
     if (($form->password == $course->password) or ($groupid !== false) ) {
 
-        if (has_capability('moodle/legacy:guest', $context, $USER->id, false)) {
+        if ($USER->username == 'guest') { // only real user guest, do not use this for users with guest role
             $USER->enrolkey[$course->id] = true;
             add_to_log($course->id, 'course', 'guest', 'view.php?id='.$course->id, getremoteaddr());
 
