From 54ab8769cdb95192112cf97cae8dc3dcf462f161 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Tue, 9 Nov 2010 01:53:28 +0000 Subject: [PATCH] MDL-24955 prevent infinite redirect loop when not enrolled and self enrol not available --- mod/forum/post.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/mod/forum/post.php b/mod/forum/post.php index 98aca112041..6cb638cf5d1 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -111,9 +111,24 @@ if (!empty($forum)) { // User is starting a new discussion in a forum if (! forum_user_can_post_discussion($forum, $groupid, -1, $cm)) { if (!isguestuser()) { if (!is_enrolled($coursecontext)) { - $SESSION->wantsurl = $FULLME; - $SESSION->enrolcancel = $_SERVER['HTTP_REFERER']; - redirect($CFG->wwwroot.'/enrol/index.php?id='.$course->id, get_string('youneedtoenrol')); + //note: this is a bloody hack, make sure there is at least one enrol + // plugin that allows them to self enrol... + $enrolinstances = enrol_get_instances($course->id, true); + + $somethingprobablyusefulforselfenrol = false; + foreach($enrolinstances as $instance) { + if ($instance->enrol === 'self' or $instance->enrol === 'paypal') { + $somethingprobablyusefulforselfenrol = true; + break; + } + } + unset($enrolinstances); + + if ($somethingprobablyusefulforselfenrol) { + $SESSION->wantsurl = $FULLME; + $SESSION->enrolcancel = $_SERVER['HTTP_REFERER']; + redirect($CFG->wwwroot.'/enrol/index.php?id='.$course->id, get_string('youneedtoenrol')); + } } } print_error('nopostforum', 'forum'); @@ -253,7 +268,7 @@ if (!empty($forum)) { // User is starting a new discussion in a forum } $PAGE->set_cm($cm, $course, $forum); - + if (!($forum->type == 'news' && !$post->parent && $discussion->timestart > time())) { if (((time() - $post->created) > $CFG->maxeditingtime) and !has_capability('mod/forum:editanypost', $modcontext)) { -- 2.43.0