diff --git a/edit.php b/edit.php index aab3b4c..5ec3bcd 100644 --- a/edit.php +++ b/edit.php @@ -105,6 +105,9 @@ $instance->customint5 = 0; } + $instance->customsubject1 = $data->customsubject1; + $instance->customsubject2 = $data->customsubject2; + $instance->customsubject3 = $data->customsubject3; $instance->customtext1 = $data->customtext1['text']; $instance->customtext2 = $data->customtext2['text']; $instance->customtext3 = $data->customtext3['text']; @@ -126,6 +129,9 @@ 'customint3' => $data->customint3, 'customint4' => $data->customint4, 'customint5' => $data->customint5, + 'customsubject1' => $data->customsubject1, + 'customsubject2' => $data->customsubject2, + 'customsubject3' => $data->customsubject3, 'customtext1' => $data->customtext1['text'], 'customtext2' => $data->customtext2['text'], 'customtext3' => $data->customtext3['text'], diff --git a/lang/en/enrol_notificationeabc.php b/lang/en/enrol_notificationeabc.php index e8e0d2c..25bf203 100644 --- a/lang/en/enrol_notificationeabc.php +++ b/lang/en/enrol_notificationeabc.php @@ -26,6 +26,8 @@ */ $string['filelockedmail'] = 'You has been enroled in {$a->fullname} ({$a->url})'; +$string['enrolsubject'] = 'Custom Subject'; +$string['enrolsubject_help'] = 'Personalize the email subject for enrol notifications'; $string['location'] = 'Message'; $string['messageprovider:notificationeabc_enrolment'] = 'Enrol notification messages'; $string['notificationeabc:manage'] = 'Manage notificationeabc'; @@ -58,6 +60,8 @@ $string['activeunenrolalert_help'] = 'Active unenrol alert'; $string['activarglobalunenrolalert'] = 'Active global'; $string['activarglobalunenrolalert_help'] = 'Active enrol notifications for all site'; +$string['unenrolsubject'] = 'Custom Subject'; +$string['unenrolsubject_help'] = 'Personalize the email subject for unenrol notifications'; $string['unenrolmessage'] = 'Custom Message'; $string['unenrolmessage_help'] = 'Personalize the message that users will come to be unenrolled. This field accepts the following markers which then will be replaced by the corresponding values ​​dynamically
@@ -73,6 +77,8 @@
 $string['activeenrolupdatedalert_help'] = 'Active update enrol notifications';
 $string['activarglobalenrolupdated'] = 'Active global';
 $string['activarglobalenrolupdated_help'] = 'Active enrol updated notifications for all site';
+$string['updatedenrolsubject'] = 'Custom Subject';
+$string['updatedenrolsubject_help'] = 'Personalize the email subject for update enrol notifications';
 $string['updatedenrolmessage'] = 'Custom message';
 $string['updatedenrolmessage_help'] = 'Personalize the message that users will come to be updated. This field accepts the following markers which then will be replaced by the corresponding values ​​dynamically
 
diff --git a/lib.php b/lib.php
index f8bb742..ef3243c 100644
--- a/lib.php
+++ b/lib.php
@@ -66,6 +66,9 @@ public function enviarmail(stdClass $user, stdClass $course, $type) {
         $plainmensajeunenrol = strip_tags($mensajeunenrol);
         $mensajeupdateenrol = $this->get_config('updatedenrolmessage');
         $plainmensajeupdateenrol = strip_tags($mensajeupdateenrol);
+        $enrolsubject = $this->get_config('enrolsubject');
+        $unenrolsubject = $this->get_config('unenrolsubject');
+        $updatedenrolmessage = $this->get_config('updatedenrolmessage');
 
         switch ((int)$type) {
             case 1:
@@ -83,6 +86,12 @@ public function enviarmail(stdClass $user, stdClass $course, $type) {
                 } else {
                     $mensaje = get_string("filelockedmail", "enrol_notificationeabc", $course);
                 }
+                
+                if (!empty($enrolsubject)) {
+                    $emailsubject = $this->process_subject($enrolsubject, $user, $course);
+                } else {
+                    $emailsubject = $this->process_subject(get_string('subject', 'enrol_notificationeabc'), $user, $course);
+                }
                 break;
             case 2:
 
@@ -99,6 +108,12 @@ public function enviarmail(stdClass $user, stdClass $course, $type) {
                 } else {
                     $mensaje = get_string("unenrolmessagedefault", "enrol_notificationeabc", $course);
                 }
+                
+                if (!empty($unenrolsubject)) {
+                    $emailsubject = $this->process_subject($unenrolsubject, $user, $course);
+                } else {
+                    $emailsubject = $this->process_subject(get_string('subject', 'enrol_notificationeabc'), $user, $course);
+                }
                 break;
             case 3:
 
@@ -115,6 +130,12 @@ public function enviarmail(stdClass $user, stdClass $course, $type) {
                 } else {
                     $mensaje = get_string("updatedenrolmessagedefault", "enrol_notificationeabc", $course);
                 }
+                
+                if (!empty($updatedenrolsubject)) {
+                    $emailsubject = $this->process_subject($updatedenrolsubject, $user, $course);
+                } else {
+                    $emailsubject = $this->process_subject(get_string('subject', 'enrol_notificationeabc'), $user, $course);
+                }
                 break;
 
             default:
@@ -146,7 +167,7 @@ public function enviarmail(stdClass $user, stdClass $course, $type) {
         $eventdata->name = 'notificationeabc_enrolment';
         $eventdata->userfrom = $sender;
         $eventdata->userto = $user->id;
-        $eventdata->subject = get_string('subject', 'enrol_notificationeabc');
+        $eventdata->subject = $emailsubject;
         $eventdata->fullmessage = '';
         $eventdata->fullmessageformat = FORMAT_HTML;
         $eventdata->fullmessagehtml = $mensaje;
@@ -163,7 +184,7 @@ public function enviarmail(stdClass $user, stdClass $course, $type) {
         }
     } // End of function.
 
-    // Procesa el mensaje para aceptar marcadores.
+    // Common function to process placeholders in content
     /**
      * Proccess message method
      * @param String $mensaje el mensaje en bruto
@@ -171,11 +192,11 @@ public function enviarmail(stdClass $user, stdClass $course, $type) {
      * @param stdClass $course instancia curso
      * @return String el mensaje procesado
      */
-    public function process_mensaje($mensaje, stdClass $user, stdClass $course) {
+    public function process_placeholders($mensaje, stdClass $user, stdClass $course) {
         global $CFG;
         $m = $mensaje;
         $url = new moodle_url($CFG->wwwroot . '/course/view.php', array('id' => $course->id));
-        $m = str_replace('{COURSENAME}', $course->fullname, $m);
+        $m = str_replace('{COURSENAME}', format_string($course->fullname), $m);
         $m = str_replace('{USERNAME}', $user->username, $m);
         $m = str_replace('{NOMBRE}', $user->firstname, $m);
         $m = str_replace('{APELLIDO}', $user->lastname, $m);
@@ -183,6 +204,39 @@ public function process_mensaje($mensaje, stdClass $user, stdClass $course) {
         return $m;
     }
 
+    // Procesa el mensaje para aceptar marcadores.
+    /**
+     * Proccess message method
+     * @param String $mensaje el mensaje en bruto
+     * @param stdClass $user instancia usuario
+     * @param stdClass $course instancia curso
+     * @return String el mensaje procesado
+     */
+    public function process_mensaje($mensaje, stdClass $user, stdClass $course) {
+        global $CFG;
+        $m = $mensaje;
+        $m = $this->process_placeholders($m, $user, $course);
+        $m = format_text($m);
+        return $m;
+    }
+
+
+    // Process email subject
+    /**
+     * Proccess message method
+     * @param String $mensaje el mensaje en bruto
+     * @param stdClass $user instancia usuario
+     * @param stdClass $course instancia curso
+     * @return String el mensaje procesado
+     */
+    public function process_subject($mensaje, stdClass $user, stdClass $course) {
+        global $CFG;
+        $m = $mensaje;
+        $m = $this->process_placeholders($m, $user, $course);
+        $m = format_string($m);
+        return $m;
+    }
+
 
     /**
      * Returns link to page which may be used to add new instance of enrolment plugin in course.
@@ -219,6 +273,9 @@ public function get_instance_defaults() {
         $fields['customint5'] = $this->get_config('activeenrolupdatedalert');
         $fields['customchar1'] = $this->get_config('emailsender');
         $fields['customchar2'] = $this->get_config('namesender');
+        $fields['customsubject1'] = $this->get_config('enrolsubject');
+        $fields['customsubject2'] = $this->get_config('unenrolsubject');
+        $fields['customsubject3'] = $this->get_config('updatedenrolsubject');
 
         return $fields;
     }
diff --git a/settings.php b/settings.php
index d7d0666..983a182 100644
--- a/settings.php
+++ b/settings.php
@@ -52,6 +52,12 @@
         get_string('pluginname_desc', 'enrol_notificationeabc'),
         '')
     );
+    $settings->add(new admin_setting_configtext(
+        'enrol_notificationeabc/enrolsubject',
+        get_string('enrolsubject', 'enrol_notificationeabc'),
+        get_string('enrolsubject_help', 'enrol_notificationeabc'),
+        get_string('subject', 'enrol_notificationeabc'))
+    );
     $settings->add(new admin_setting_confightmleditor(
         'enrol_notificationeabc/location',
         get_string('location', 'enrol_notificationeabc'),
@@ -73,6 +79,12 @@
         get_string('activarglobalunenrolalert_help', 'enrol_notificationeabc'),
         '')
     );
+    $settings->add(new admin_setting_configtext(
+        'enrol_notificationeabc/unenrolsubject',
+        get_string('unenrolsubject', 'enrol_notificationeabc'),
+        get_string('unenrolsubject_help', 'enrol_notificationeabc'),
+        get_string('subject', 'enrol_notificationeabc'))
+    );
     $settings->add(new admin_setting_confightmleditor(
         'enrol_notificationeabc/unenrolmessage',
         get_string('unenrolmessage', 'enrol_notificationeabc'),
@@ -94,6 +106,12 @@
         get_string('activarglobalenrolupdated_help', 'enrol_notificationeabc'),
         '')
     );
+    $settings->add(new admin_setting_configtext(
+        'enrol_notificationeabc/updatedenrolsubject',
+        get_string('updatedenrolsubject', 'enrol_notificationeabc'),
+        get_string('updatedenrolsubject_help', 'enrol_notificationeabc'),
+        get_string('subject', 'enrol_notificationeabc'))
+    );
     $settings->add(new admin_setting_confightmleditor(
         'enrol_notificationeabc/updatedenrolmessage',
         get_string('updatedenrolmessage', 'enrol_notificationeabc'),