diff --git a/enrol/self/db/install.php b/enrol/self/db/install.php index 1a8a57d1b4c..7eb22ba894c 100644 --- a/enrol/self/db/install.php +++ b/enrol/self/db/install.php @@ -30,7 +30,8 @@ function xmldb_enrol_self_install() { // migrate welcome message if (isset($CFG->sendcoursewelcomemessage)) { - set_config('sendcoursewelcomemessage', $CFG->sendcoursewelcomemessage, 'enrol_self'); + set_config('sendcoursewelcomemessage', $CFG->sendcoursewelcomemessage, 'enrol_self'); // new course default + $DB->set_field('enrol', 'customint4', $CFG->sendcoursewelcomemessage, array('enrol'=>'self')); // each instance has different setting now unset_config('sendcoursewelcomemessage'); } diff --git a/enrol/self/edit.php b/enrol/self/edit.php index 564480361c3..b57aead8f2b 100644 --- a/enrol/self/edit.php +++ b/enrol/self/edit.php @@ -71,6 +71,8 @@ if ($mform->is_cancelled()) { $instance->customint1 = $data->customint1; $instance->customint2 = $data->customint2; $instance->customint3 = $data->customint3; + $instance->customint4 = $data->customint4; + $instance->customtext1 = $data->customtext1; $instance->roleid = $data->roleid; $instance->enrolperiod = $data->enrolperiod; $instance->enrolstartdate = $data->enrolstartdate; @@ -79,7 +81,8 @@ if ($mform->is_cancelled()) { $DB->update_record('enrol', $instance); } else { - $fields = array('status'=>$data->status, 'name'=>$data->name, 'password'=>$data->password, 'customint1'=>$data->customint1, 'customint2'=>$data->customint2, 'customint3'=>$data->customint3, + $fields = array('status'=>$data->status, 'name'=>$data->name, 'password'=>$data->password, 'customint1'=>$data->customint1, 'customint2'=>$data->customint2, + 'customint3'=>$data->customint3, 'customint4'=>$data->customint4, 'customtext1'=>$data->customtext1, 'roleid'=>$data->roleid, 'enrolperiod'=>$data->enrolperiod, 'enrolstartdate'=>$data->enrolstartdate, 'enrolenddate'=>$data->enrolenddate); $plugin->add_instance($course, $fields); } diff --git a/enrol/self/edit_form.php b/enrol/self/edit_form.php index aadf70ddd4f..307b50b09ef 100644 --- a/enrol/self/edit_form.php +++ b/enrol/self/edit_form.php @@ -97,6 +97,12 @@ class enrol_self_edit_form extends moodleform { $mform->addHelpButton('customint3', 'maxenrolled', 'enrol_self'); $mform->setType('customint3', PARAM_INT); + $mform->addElement('advcheckbox', 'customint4', get_string('sendcoursewelcomemessage', 'enrol_self')); + $mform->setDefault('customint4', $plugin->get_config('sendcoursewelcomemessage')); + $mform->addHelpButton('customint4', 'sendcoursewelcomemessage', 'enrol_self'); + + $mform->addElement('textarea', 'customtext1', get_string('customwelcomemessage', 'enrol_self'), array('cols'=>'60', 'rows'=>'8')); + $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid'); diff --git a/enrol/self/lang/en/enrol_self.php b/enrol/self/lang/en/enrol_self.php index 9f06ca4f248..c2ed728199e 100644 --- a/enrol/self/lang/en/enrol_self.php +++ b/enrol/self/lang/en/enrol_self.php @@ -24,6 +24,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['customwelcomemessage'] = 'Custom welcome message'; $string['defaultrole'] = 'Default role assignment'; $string['defaultrole_desc'] = 'Select role which should be assigned to users during self enrolment'; $string['enrolenddate'] = 'End date'; @@ -61,7 +62,7 @@ $string['self:manage'] = 'Manage enrolled users'; $string['self:unenrol'] = 'Unenrol users from course'; $string['self:unenrolself'] = 'Unenrol self from the course'; $string['sendcoursewelcomemessage'] = 'Send course welcome message'; -$string['sendcoursewelcomemessage_desc'] = 'If enabled, users receive a welcome message via email when they self-enrol in a course.'; +$string['sendcoursewelcomemessage_help'] = 'If enabled, users receive a welcome message via email when they self-enrol in a course.'; $string['showhint'] = 'Show hint'; $string['showhint_desc'] = 'Show first letter of the guest access key.'; $string['status'] = 'Allow self enrolments'; diff --git a/enrol/self/lib.php b/enrol/self/lib.php index 832a06218d9..a5a12e55006 100644 --- a/enrol/self/lib.php +++ b/enrol/self/lib.php @@ -204,7 +204,7 @@ class enrol_self_plugin extends enrol_plugin { } } // send welcome - if ($this->get_config('sendcoursewelcomemessage')) { + if ($instance->customint4) { $this->email_welcome_message($instance, $USER); } } @@ -228,6 +228,7 @@ class enrol_self_plugin extends enrol_plugin { $fields = array('customint1' => $this->get_config('groupkey'), 'customint2' => $this->get_config('longtimenosee'), 'customint3' => $this->get_config('maxenrolled'), + 'customint4' => $this->get_config('sendcoursewelcomemessage'), 'enrolperiod' => $this->get_config('enrolperiod', 0), 'status' => $this->get_config('status'), 'roleid' => $this->get_config('roleid', 0)); @@ -251,20 +252,22 @@ class enrol_self_plugin extends enrol_plugin { $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST); - if (!empty($instance->customtext1)) { - //note: there is no gui for this yet, do we really need it? - $message = formaat_string($instance->customtext1); + $a = new object(); + $a->coursename = format_string($course->fullname); + $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id"; + + if (trim($instance->customtext1) !== '') { + $message = $instance->customtext1; + $message = str_replace('{$a->coursename}', $a->coursename, $message); + $message = str_replace('{$a->profileurl}', $a->profileurl, $message); } else { - $a = new object(); - $a->coursename = format_string($course->fullname); - $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id"; - $message = get_string("welcometocoursetext", 'enrol_self', $a); + $message = get_string('welcometocoursetext', 'enrol_self', $a); } $subject = get_string('welcometocourse', 'enrol_self', format_string($course->fullname)); $context = get_context_instance(CONTEXT_COURSE, $course->id); - $rusers = null; + $rusers = array(); if (!empty($CFG->coursecontact)) { $croles = explode(',', $CFG->coursecontact); $rusers = get_role_users($croles, $context, true, '', 'r.sortorder ASC, u.lastname ASC'); diff --git a/enrol/self/settings.php b/enrol/self/settings.php index 5a0b35991d7..adfa89b3325 100644 --- a/enrol/self/settings.php +++ b/enrol/self/settings.php @@ -40,10 +40,6 @@ if ($ADMIN->fulltree) { $settings->add(new admin_setting_configcheckbox('enrol_self/showhint', get_string('showhint', 'enrol_self'), get_string('showhint_desc', 'enrol_self'), 0)); - $settings->add(new admin_setting_configcheckbox('enrol_self/sendcoursewelcomemessage', - get_string('sendcoursewelcomemessage', 'enrol_self'), get_string('sendcoursewelcomemessage_desc', 'enrol_self'), 1)); - - //--- enrol instance defaults ---------------------------------------------------------------------------- $settings->add(new admin_setting_heading('enrol_self_defaults', get_string('enrolinstancedefaults', 'admin'), get_string('enrolinstancedefaults_desc', 'admin'))); @@ -90,4 +86,7 @@ if ($ADMIN->fulltree) { $settings->add(new admin_setting_configtext('enrol_self/maxenrolled', get_string('maxenrolled', 'enrol_self'), get_string('maxenrolled_help', 'enrol_self'), 0, PARAM_INT)); + + $settings->add(new admin_setting_configcheckbox('enrol_self/sendcoursewelcomemessage', + get_string('sendcoursewelcomemessage', 'enrol_self'), get_string('sendcoursewelcomemessage_desc', 'enrol_self'), 1)); } diff --git a/enrol/self/version.php b/enrol/self/version.php index dd73667e0dd..e0178ca3371 100644 --- a/enrol/self/version.php +++ b/enrol/self/version.php @@ -26,5 +26,5 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2010090500; +$plugin->version = 2010090501; $plugin->cron = 180; \ No newline at end of file