]> git.mjollnir.org Git - moodle.git/commitdiff
Allow groups to have enrolment keys in addition to the course enrolment key.
authormoodler <moodler>
Tue, 14 Dec 2004 08:12:12 +0000 (08:12 +0000)
committermoodler <moodler>
Tue, 14 Dec 2004 08:12:12 +0000 (08:12 +0000)
If a user enrols with a group key they will be added to the course and to
the group.

course/group-edit.html
course/group.php
enrol/enrol.class.php

index a3090cece339966e9930db67afd1df6ebd1712e3..8c70eb31a7122d6fb853370f7d1c43e605c665dd 100644 (file)
@@ -1,23 +1,24 @@
 <form method="post" enctype="multipart/form-data" action="group.php">
 <table cellpadding="9" cellspacing="0" align="center">
 <tr valign="top">
-    <td align="right"><p><?php print_string("name") ?>:</td>
+    <td align="right"><?php print_string("name") ?>:</td>
     <td><input type="text" name="name" size="30" value="<?php p($group->name) ?>" />
     <?php if (isset($err["name"])) formerr($err["name"]); ?>
     </td>
 </tr>
 <tr valign="top">
-    <td align="right"><p><?php print_string("description") ?>:</td>
+    <td align="right"><?php print_string("description") ?>:<br />
+        <?php helpbutton("text", get_string("helptext")) ?>
+    </td>
     <td><?php 
         print_textarea($usehtmleditor, 10, 50, 660, 200, "description", $group->description);
-        helpbutton("text", get_string("helptext"));
         if (isset($err["description"])) formerr($err["description"]); 
     ?>
     </td>
 </tr>
 
 <tr valign="top">
-    <td align="right"><p><?php print_string("hidepicture") ?>:</td>
+    <td align="right"><?php print_string("hidepicture") ?>:</td>
     <td><?php 
         $options = NULL;
         $options[0] = get_string("no");
     </td>
 </tr>
 
+<tr valign="top">
+    <td align="right"><?print_string('enrolmentkey') ?>:</td>
+    <td><input type="text" name="password" size="25" value="<?php echo $group->password ?>" alt="<?print_string('enrolmentkey') ?>" /></td>
+</tr>
+
 <?php 
     $maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes);
     if (!empty($CFG->gdversion) and $maxbytes) {  
 ?>
 <tr valign="top">
-    <td align="right"><p><?php print_string("newpicture") ?>:</td>
+    <td align="right"><?php print_string("newpicture") ?>:</td>
     <td>
-    <?php helpbutton("picture", get_string("helppicture"));
+    <?php
        require_once($CFG->dirroot.'/lib/uploadlib.php');
        upload_print_form_fragment(1,array('imagefile'),null,false,null,0,0,false);
+       helpbutton("picture", get_string("helppicture"));
        print_string("maxsize", "", display_size($maxbytes)); 
        if (isset($err["imagefile"])) formerr($err["imagefile"]);
     ?>
index c2045410966bf7c9de01d3adfc1bc4316f3b20f3..e4b3e30ecff753e1129e104cabeee3befcef3280 100644 (file)
@@ -74,6 +74,7 @@
             $group->name        = $form->name;
             $group->description = $form->description;
             $group->hidepicture = $form->hidepicture;
+            $group->password    = $form->password;
             if (!update_record("groups", $group)) {
                 notify("A strange error occurred while trying to save ");
             } else {
index 79d17d2bcc0d26ebcd42ba7906bb0d720663826d..bce6934c2db6d80d6d91322503ee7fea701ccda3 100644 (file)
@@ -203,7 +203,8 @@ function print_entry($course) {
 function check_entry($form, $course) {
     global $CFG, $USER, $SESSION, $THEME;
 
-    if ($form->password == $course->password) {
+    $groupid = $this->check_group_entry($course->id, $form->password);
+    if (($form->password == $course->password) or ($groupid !== false) ) {
 
         if (isguest()) {
         
@@ -221,6 +222,10 @@ function check_entry($form, $course) {
             if (! enrol_student($USER->id, $course->id, $timestart, $timeend)) {
                 error("An error occurred while trying to enrol you.");
             }
+
+            if (($groupid !== false ) and (!add_user_to_group($groupid, $USER->id)) ) {
+                error("An error occurred while trying to add you to a group");
+            }
             
             $subject = get_string("welcometocourse", "", $course->fullname);
             $a->coursename = $course->fullname;
@@ -253,6 +258,25 @@ function check_entry($form, $course) {
 }
 
 
+/**
+* Check if the given enrolment key matches a group enrolment key for the given course
+*
+* Check if the given enrolment key matches a group enrolment key for the given course
+*
+* @param    courseid  the current course id
+* @param    password  the submitted enrolment key
+*/
+function check_group_entry ($courseid, $password) {
+    $ingroup = false;
+    if ( ($groups = get_groups($courseid)) !== false ) {
+        foreach ($groups as $group) 
+            if ( !empty($group->password) and ($password == $group->password) )
+                $ingroup = $group->id;
+    }
+    return $ingroup;
+}
+
+
 /**
 * Prints a form for configuring the current enrolment plugin
 *