From 71483894b2d10506fabd6052e817080100e3c24f Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 2 Nov 2006 08:12:54 +0000 Subject: [PATCH] Petr's patch for MDL-7327 to modify require_capability login a bit (merged from stable) --- lib/accesslib.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index c440feda78..06d309dd77 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -227,21 +227,30 @@ function get_parent_cats($context, $type) { * @param string $stringfile - which stringfile to get it from */ function require_capability($capability, $context=NULL, $userid=NULL, $doanything=true, - $errormessage="nopermissions", $stringfile='') { + $errormessage='nopermissions', $stringfile='') { - global $USER; + global $USER, $CFG; -/// If the current user is not logged in, then make sure they are +/// If the current user is not logged in, then make sure they are (if needed) if (empty($userid) and empty($USER->capabilities)) { if ($context && ($context->contextlevel == CONTEXT_COURSE)) { require_login($context->instanceid); } else if ($context && ($context->contextlevel == CONTEXT_MODULE)) { if ($cm = get_record('course_modules','id',$context->instanceid)) { - require_login($cm->course, true, $cm); + if (!$course = get_record('course', 'id', $cm->course)) { + error('Incorrect course.'); + } + require_course_login($course, true, $cm); + } else { require_login(); } + } else if ($context && ($context->contextlevel == CONTEXT_SYSTEM)) { + if (!empty($CFG->forcelogin)) { + require_login(); + } + } else { require_login(); } -- 2.39.5