From 4d3145f3d34e069349d4e76c7f99c4e49a56d2d5 Mon Sep 17 00:00:00 2001 From: thepurpleblob Date: Wed, 1 Aug 2007 11:52:05 +0000 Subject: [PATCH] MDL-10585: 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. Merged from STABLE_18 --- enrol/manual/config.html | 21 ++++++++++++ enrol/manual/enrol.html | 9 ++--- enrol/manual/enrol.php | 73 +++++++++++++++++++++++++++++++++++----- 3 files changed, 87 insertions(+), 16 deletions(-) create mode 100644 enrol/manual/config.html diff --git a/enrol/manual/config.html b/enrol/manual/config.html new file mode 100644 index 0000000000..24898c7b7e --- /dev/null +++ b/enrol/manual/config.html @@ -0,0 +1,21 @@ + + + + + + + + + +
enrol_manual_keyholderrole: + $role) { + $rolenames[$id]=$role->name; + } + choose_from_menu($rolenames, 'enrol_manual_keyholderrole', $frm->enrol_manual_keyholderrole); + ?> + + +
diff --git a/enrol/manual/enrol.html b/enrol/manual/enrol.html index 78686a3136..93012ea3b5 100644 --- a/enrol/manual/enrol.html +++ b/enrol/manual/enrol.html @@ -1,15 +1,10 @@ password != '' and !(isguestuser() and !empty($USER->enrolkey[$course->id]))) { // password - print_box_start('generalbox centerpara'); echo '

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

diff --git a/enrol/manual/enrol.php b/enrol/manual/enrol.php index d1a78d2704..f708faf11f 100644 --- a/enrol/manual/enrol.php +++ b/enrol/manual/enrol.php @@ -95,13 +95,9 @@ function print_entry($course) { redirect($destination); } } - - 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 = ''; } @@ -200,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"); } @@ -346,6 +348,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', '', ':
' ); + } + else { + print_string('enrolmentkeyfrom', '', ':
'); + } + foreach ($contacts as $contact) { + $contactname = "id&course=".SITEID."\">".fullname($contact)."."; + echo "$contactname
"; + } + $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 = "id&course=".SITEID."\">".fullname($teacher)."."; + } 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 -- 2.39.5