From: moodler Date: Tue, 14 Dec 2004 08:12:12 +0000 (+0000) Subject: Allow groups to have enrolment keys in addition to the course enrolment key. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=dad3f933fbe0d809eec874448728bec2e1846918;p=moodle.git Allow groups to have enrolment keys in addition to the course enrolment key. If a user enrols with a group key they will be added to the course and to the group. --- diff --git a/course/group-edit.html b/course/group-edit.html index a3090cece3..8c70eb31a7 100644 --- a/course/group-edit.html +++ b/course/group-edit.html @@ -1,23 +1,24 @@
- + - + - + + + + + + maxbytes, $course->maxbytes); if (!empty($CFG->gdversion) and $maxbytes) { ?> - +

:

:

:

:
+ +
description); - helpbutton("text", get_string("helptext")); if (isset($err["description"])) formerr($err["description"]); ?>

:

:
:

:

: - 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"]); ?> diff --git a/course/group.php b/course/group.php index c204541096..e4b3e30ecf 100644 --- a/course/group.php +++ b/course/group.php @@ -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 { diff --git a/enrol/enrol.class.php b/enrol/enrol.class.php index 79d17d2bcc..bce6934c2d 100644 --- a/enrol/enrol.class.php +++ b/enrol/enrol.class.php @@ -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 *