From: skodak Date: Wed, 14 Feb 2007 08:03:40 +0000 (+0000) Subject: MDL-7903 Guests can not enter course that allows guests with key reopened: X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=2b91b669dee7a59df9a34baafc043de17af01c1f;p=moodle.git MDL-7903 Guests can not enter course that allows guests with key reopened: * fixed load_guset_role that did not work in course context * fixed typos in get_child_contexts * manual guest enrolment changes --- diff --git a/enrol/manual/enrol.html b/enrol/manual/enrol.html index c1a05fa8ac..6422df421b 100644 --- a/enrol/manual/enrol.html +++ b/enrol/manual/enrol.html @@ -1,12 +1,15 @@ - -

-id&course=".SITEID."\">".fullname($teacher)."."; - } else { - $teachername = get_string('yourteacher', '', $course->teacher); - } - print_string('enrolmentkeyfrom', '', $teachername); +password != '' and !(isguestuser() and !empty($USER->enrolkey[$course->id]))) { // password + + print_box_start('generalbox centerpara'); + echo '

'; + if ($teacher) { + $teachername = "id&course=".SITEID."\">".fullname($teacher)."."; + } else { + $teachername = get_string('yourteacher', '', $course->teacher); + } + print_string('enrolmentkeyfrom', '', $teachername); ?>

@@ -35,26 +38,19 @@ guest and !isguest()) { - print_simple_box_start('center'); -?> -
- - - - - -
- - - -
-
-loginhttps)) { + $loginurl = $CFG->wwwroot .'/login/index.php'; + } else { + $wwwroot = str_replace('http:','https:', $CFG->wwwroot); + $loginurl = $wwwroot .'/login/index.php'; + } + print_single_button($loginurl, null, get_string('login')); + print_box_end(); } ?> diff --git a/enrol/manual/enrol.php b/enrol/manual/enrol.php index 741bdd81bf..c4f7c1df01 100644 --- a/enrol/manual/enrol.php +++ b/enrol/manual/enrol.php @@ -139,7 +139,7 @@ function check_entry($form, $course) { if (($form->password == $course->password) or ($groupid !== false) ) { - if ($USER->username == 'guest') { // only real user guest, do not use this for users with guest role + if (isguestuser()) { // 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()); @@ -271,7 +271,7 @@ function cron() { $strexpirynotify = get_string('expirynotify'); foreach ($courses as $course) { - $a = new object; + $a = new object(); $a->coursename = $course->shortname .'/'. $course->fullname; $a->threshold = $course->expirythreshold / 86400; $a->extendurl = $CFG->wwwroot . '/user/index.php?id=' . $course->id; @@ -299,18 +299,18 @@ function cron() { $teacher = get_admin(); } - $a->studentstr = fullname($user, true); $a->teacherstr = fullname($teacher, true); $strexpirynotifystudentsemail = get_string('expirynotifystudentsemail', '', $a); foreach ($oldenrolments as $user) { /// Email all users about to expire + $a->studentstr = fullname($user, true); if ($user->timeend < ($expiry - 86400)) { $a->past[] = fullname($user) . " <$user->email>"; } else { $a->current[] = fullname($user) . " <$user->email>"; if ($course->notifystudents) { // Send this guy notice - email_to_user($student, $teacher, $SITE->fullname .' '. $strexpirynotify, + email_to_user($user, $teacher, $SITE->fullname .' '. $strexpirynotify, $strexpirynotifystudentsemail); } } diff --git a/lib/accesslib.php b/lib/accesslib.php index 644bbb7be8..26de95fc5b 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -73,6 +73,31 @@ function load_guest_role($context=NULL, $mergewith=NULL) { } } + if ($context->id != $sitecontext->id) { + // first emulate the parent context capabilities merging into expected + $parcontexts = array_reverse(get_parent_contexts($context)); + foreach ($parcontexts as $pcid) { + if ($capabilities = get_records_select('role_capabilities', + "roleid = $guestrole->id + AND contextid = $pcid")) { + + foreach ($capabilities as $capability) { + if ($mergewith === NULL) { + if (!isset($USER->capabilities[$context->id][$capability->capability])) { + $USER->capabilities[$context->id][$capability->capability] = 0; + } + $USER->capabilities[$context->id][$capability->capability] += $capability->permission; + } else { + if (!isset($mergewith[$context->id][$capability->capability])) { + $mergewith[$context->id][$capability->capability] = 0; + } + $mergewith[$context->id][$capability->capability] += $capability->permission; + } + } + } + } + } + $searchcontexts = get_child_contexts($context); array_push($searchcontexts, $context->id); @@ -83,9 +108,15 @@ function load_guest_role($context=NULL, $mergewith=NULL) { foreach ($capabilities as $capability) { if ($mergewith === NULL) { - $USER->capabilities[$scid][$capability->capability] = $capability->permission; + if (!isset($USER->capabilities[$scid][$capability->capability])) { + $USER->capabilities[$scid][$capability->capability] = 0; + } + $USER->capabilities[$scid][$capability->capability] += $capability->permission; } else { - $mergewith[$scid][$capability->capability] = $capability->permission; + if (!isset($mergewith[$scid][$capability->capability])) { + $mergewith[$scid][$capability->capability] = 0; + } + $mergewith[$scid][$capability->capability] += $capability->permission; } } } @@ -2847,12 +2878,12 @@ function get_child_contexts($context) { $page->type = 'course-view'; if ($blocks = blocks_get_by_page_pinned($page)) { foreach ($blocks['l'] as $leftblock) { - if ($child = get_context_instance(CONTEXT_BLOCK, $leftblock->blockid)) { + if ($child = get_context_instance(CONTEXT_BLOCK, $leftblock->id)) { array_push($children, $child->id); } } foreach ($blocks['r'] as $rightblock) { - if ($child = get_context_instance(CONTEXT_BLOCK, $rightblock->blockid)) { + if ($child = get_context_instance(CONTEXT_BLOCK, $rightblock->id)) { array_push($children, $child->id); } } @@ -2866,9 +2897,9 @@ function get_child_contexts($context) { } } // Find all group instances for the course. - if ($groups = get_records('groups', 'courseid', $context->instanceid)) { - foreach ($groups as $group) { - if ($child = get_context_instance(CONTEXT_GROUP, $group->id)) { + if ($groupids = groups_get_groups($context->instanceid)) { + foreach ($groupids as $groupid) { + if ($child = get_context_instance(CONTEXT_GROUP, $groupid)) { array_push($children, $child->id); } }