]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10585:
authorthepurpleblob <thepurpleblob>
Wed, 1 Aug 2007 11:52:05 +0000 (11:52 +0000)
committerthepurpleblob <thepurpleblob>
Wed, 1 Aug 2007 11:52:05 +0000 (11:52 +0000)
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 [new file with mode: 0644]
enrol/manual/enrol.html
enrol/manual/enrol.php

diff --git a/enrol/manual/config.html b/enrol/manual/config.html
new file mode 100644 (file)
index 0000000..24898c7
--- /dev/null
@@ -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>
index 78686a31363c4061c2bfc8feef593e19d93aa1cc..93012ea3b55320631bd3e6444fb92c28c763ecdc 100644 (file)
@@ -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>
 
index d1a78d27043222053b787299b099b521aa4ec12d..f708faf11fddd8756d0a26c7242a07d6995acdb6 100644 (file)
@@ -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', '', ':<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