mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
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
This commit is contained in:
parent
40bdeceff8
commit
2b91b669de
@ -1,12 +1,15 @@
|
||||
<?php print_simple_box_start('center'); ?>
|
||||
<p align="center">
|
||||
<?php
|
||||
if ($teacher) {
|
||||
$teachername = "<a href=\"../user/view.php?id=$teacher->id&course=".SITEID."\">".fullname($teacher)."</a>.";
|
||||
} else {
|
||||
$teachername = get_string('yourteacher', '', $course->teacher);
|
||||
}
|
||||
print_string('enrolmentkeyfrom', '', $teachername);
|
||||
<?php
|
||||
|
||||
if ($course->password != '' and !(isguestuser() and !empty($USER->enrolkey[$course->id]))) { // password
|
||||
|
||||
print_box_start('generalbox centerpara');
|
||||
echo '<p align="center">';
|
||||
if ($teacher) {
|
||||
$teachername = "<a href=\"../user/view.php?id=$teacher->id&course=".SITEID."\">".fullname($teacher)."</a>.";
|
||||
} else {
|
||||
$teachername = get_string('yourteacher', '', $course->teacher);
|
||||
}
|
||||
print_string('enrolmentkeyfrom', '', $teachername);
|
||||
?>
|
||||
</p>
|
||||
|
||||
@ -35,26 +38,19 @@
|
||||
</div>
|
||||
|
||||
<?php
|
||||
print_simple_box_end();
|
||||
print_box_end();
|
||||
}
|
||||
|
||||
|
||||
if ($course->guest and !isguest()) {
|
||||
print_simple_box_start('center');
|
||||
?>
|
||||
<form method="post" action="enrol.php">
|
||||
<table align="center" cellpadding="20">
|
||||
<tr>
|
||||
<td><?php print_string('allowguests') ?>: </td>
|
||||
<td>
|
||||
<input name="id" value="<?php p($course->id) ?>" type="hidden">
|
||||
<input name="loginasguest" value="yes" type="hidden" />
|
||||
<input value="<?php print_string('loginguest') ?>" type="submit">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
print_simple_box_end();
|
||||
if (isguestuser()) {
|
||||
print_box_start('centerpara');
|
||||
if (empty($CFG->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();
|
||||
}
|
||||
?>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user