Skip to content

Commit

Permalink
MDL-10585:
Browse files Browse the repository at this point in the history
MDL-10584:
Present more factually correct message when a guest attempts to enrol.
Provide a mechanism for specifying which role in a course holds the
enrolment key.
  • Loading branch information
thepurpleblob committed Aug 1, 2007
1 parent 5ceecda commit a871e63
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 14 deletions.
21 changes: 21 additions & 0 deletions enrol/manual/config.html
@@ -0,0 +1,21 @@
<table cellspacing="0" cellpadding="5" border="0" class="boxaligncenter">

<tr valign="top">
<td align="right">enrol_manual_keyholderrole:</td>
<td>
<?php
$roles = get_all_roles();
$rolenames = array();
foreach ($roles as $id=>$role) {
$rolenames[$id]=$role->name;
}
choose_from_menu($rolenames, 'enrol_manual_keyholderrole', $frm->enrol_manual_keyholderrole);
?>
</td>
<td>
<?php print_string("keyholderrole", "enrol_manual") ?>
</td>
</tr>


</table>
9 changes: 2 additions & 7 deletions enrol/manual/enrol.html
@@ -1,15 +1,10 @@
<?php

if ($course->password != '' and !(isguestuser() and !empty($USER->enrolkey[$course->id]))) { // password

print_box_start('generalbox centerpara');
echo '<p align="center">';
if (!empty($teacher)) {
$teachername = "<a href=\"../user/view.php?id=$teacher->id&course=".SITEID."\">".fullname($teacher)."</a>.";
} else {
$teachername = get_string('defaultcourseteacher'); //get_string('yourteacher', '', $course->teacher);
}
print_string('enrolmentkeyfrom', '', $teachername);

$this->print_enrolmentkeyfrom( $course );
?>
</p>

Expand Down
70 changes: 63 additions & 7 deletions enrol/manual/enrol.php
Expand Up @@ -96,11 +96,8 @@ function print_entry($course) {
}
}

if ($teachers = get_users_by_capability(get_context_instance(CONTEXT_COURSE, $course->id), 'moodle/course:update',
'u.*,ra.hidden', 'r.sortorder ASC',
0, 1, '', '', false, true)) {
$teacher = array_shift($teachers);
}
// if we get here we are going to display the form asking for the enrolment key
// and (hopefully) provide information about who to ask for it.
if (!isset($password)) {
$password = '';
}
Expand Down Expand Up @@ -199,10 +196,16 @@ function check_group_entry ($courseid, $password) {
* This function is called from admin/enrol.php, and outputs a
* full page with a form for defining the current enrolment plugin.
*
* @param page an object containing all the data for this page
* @param frm an object containing all the data for this page
*/
function config_form($page) {
function config_form($frm) {
global $CFG;

if (!isset( $frm->enrol_manual_keyholderrole )) {
$frm->enrol_manual_keyholderrole = '';
}

include ("$CFG->dirroot/enrol/manual/config.html");
}


Expand Down Expand Up @@ -370,6 +373,59 @@ function get_access_icons($course) {
return $str;
}

/**
* Prints the message telling you were to get the enrolment key
* appropriate for the prevailing circumstances
* A bit clunky because I didn't want to change the standard strings
*/
function print_enrolmentkeyfrom($course) {
global $CFG;
global $USER;

$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
$guest = has_capability('moodle/legacy:guest', $context, $USER->id, false);

// if a keyholder role is defined we list teachers in that role (if any exist)
$contactslisted = false;
if (!empty($CFG->enrol_manual_keyholderrole)) {
if ($contacts = get_role_users($CFG->enrol_manual_keyholderrole, get_context_instance(CONTEXT_COURSE, $course->id), true )) {
// guest user has a slightly different message
if ($guest) {
print_string('enrolmentkeyfromguest', '', ':<br />' );
}
else {
print_string('enrolmentkeyfrom', '', ':<br />');
}
foreach ($contacts as $contact) {
$contactname = "<a href=\"../user/view.php?id=$contact->id&course=".SITEID."\">".fullname($contact)."</a>.";
echo "$contactname<br />";
}
$contactslisted = true;
}
}

// if no keyholder role is defined OR nobody is in that role we do this the 'old' way
// (show the first person with update rights)
if (!$contactslisted) {
if ($teachers = get_users_by_capability(get_context_instance(CONTEXT_COURSE, $course->id), 'moodle/course:update',
'u.*,ra.hidden', 'r.sortorder ASC', 0, 1, '', '', false, true)) {
$teacher = array_shift($teachers);
}
if (!empty($teacher)) {
$teachername = "<a href=\"../user/view.php?id=$teacher->id&course=".SITEID."\">".fullname($teacher)."</a>.";
} else {
$teachername = strtolower( get_string('defaultcourseteacher') ); //get_string('yourteacher', '', $course->teacher);
}

// guest user has a slightly different message
if ($guest) {
print_string('enrolmentkeyfromguest', '', $teachername );
}
else {
print_string('enrolmentkeyfrom', '', $teachername);
}
}
}

} /// end of class

Expand Down

0 comments on commit a871e63

Please sign in to comment.