diff --git a/README.md b/README.md index 5c0f39b..c0c5613 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Once enabled, the plugin will send an email notification to a configurable list of emails whenever a new user gets registered. ## Configuration -Each journal must be configured individually since the settings are not shared. +Each journal/press must be configured individually since the settings are not shared. ### Recipients The emails must be defined through the plugin settings, the interface supports adding a list of recipients. diff --git a/RegistrationNotificationSettingsForm.inc.php b/RegistrationNotificationSettingsForm.inc.php index a5883b5..83dc96b 100644 --- a/RegistrationNotificationSettingsForm.inc.php +++ b/RegistrationNotificationSettingsForm.inc.php @@ -34,6 +34,11 @@ public function __construct(RegistrationNotificationPlugin $plugin, $contextId) $this->_plugin = $plugin; $this->addCheck(new FormValidatorPost($this)); $this->addCheck(new FormValidatorCSRF($this)); + import('lib.pkp.classes.validation.ValidatorEmail'); + $emailValidator = new ValidatorEmail; + $this->addCheck(new FormValidatorArrayCustom($this, 'email', 'required', 'form.emailRequired', function ($value) use ($emailValidator) { + return $emailValidator->isValid($value); + })); } /** @@ -41,7 +46,8 @@ public function __construct(RegistrationNotificationPlugin $plugin, $contextId) */ public function initData() { $recipientList = $this->_plugin->getSetting($this->_contextId, 'recipientList'); - $this->setData('recipientList', is_array($recipientList) ? $recipientList : []); + $this->setData('email', is_array($recipientList) ? array_keys($recipientList) : []); + $this->setData('name', is_array($recipientList) ? array_values($recipientList) : []); return parent::initData(); } @@ -50,6 +56,17 @@ public function initData() { */ public function readInputData() { $this->readUserVars(array('email', 'name')); + $emails = $this->getData('email'); + $names = $this->getData('name'); + foreach($emails as $i => $email) { + //clean empty entries + if(empty($email) && empty($names[$i])){ + unset($emails[$i]); + unset($names[$i]); + } + } + $this->setData('email', array_values($emails)); + $this->setData('name', array_values($names)); return parent::readInputData(); } @@ -65,15 +82,7 @@ public function fetch($request) { * @copydoc Form::fetch() */ public function execute() { - import('lib.pkp.classes.validation.ValidatorEmail'); - - $emailValidator = new ValidatorEmail; - $data = array_filter( - array_combine($this->getData('email'), $this->getData('name')), - [$emailValidator, 'isValid'], - ARRAY_FILTER_USE_KEY - ); - $this->_plugin->updateSetting($this->_contextId, 'recipientList', $data, 'object'); + $this->_plugin->updateSetting($this->_contextId, 'recipientList', array_combine($this->getData('email'), $this->getData('name')), 'object'); return parent::execute(); } } diff --git a/locale/en_US/emailTemplates.xml b/locale/en_US/emailTemplates.xml index 8dc86c5..800fd8b 100644 --- a/locale/en_US/emailTemplates.xml +++ b/locale/en_US/emailTemplates.xml @@ -20,7 +20,7 @@
Email: {$userEmail}

-This email was generated by Open Journal Systems' Registration Notification plugin.]]> +This email was generated by the Public Knowledge Project's Registration Notification plugin.]]> This email template is used to notify that a new user has been registered. diff --git a/templates/settingsForm.tpl b/templates/settingsForm.tpl index 775e5d3..69ab6b1 100644 --- a/templates/settingsForm.tpl +++ b/templates/settingsForm.tpl @@ -8,21 +8,29 @@ * Registration Notification plugin settings * *} -
-
{translate key="plugins.generic.registrationNotification.description"}
- -

{translate key="navigation.settings"}

-
- {csrf} - {include file="controllers/notification/inPlaceNotification.tpl" notificationId="registrationNotificationSettingsFormNotification"} +
+
{translate key="plugins.generic.registrationNotification.description"}
+ +

{translate key="navigation.settings"}

+ {csrf} + {include file="controllers/notification/inPlaceNotification.tpl" notificationId="registrationNotificationSettingsFormNotification"} - {fbvFormArea id="registrationNotificationSettingsFormArea"} - {foreach from=$recipientList key=email item=name name=email} - {fbvFormSection} - {assign var="index" value=$smarty.foreach.email.index} - {fbvElement type="text" required="required" label="email.email" id="email-`$index`" name="email[]" value=$email inline=true size=$fbvStyles.size.SMALL} - {fbvElement type="text" label="common.name" id="name-`$index`" name="name[]" value=$name inline=true size=$fbvStyles.size.MEDIUM} - {fbvElement type="button" label="common.remove" id="remove-`$index`" inline=true class="default remove-button"} - {/fbvFormSection} - {/foreach} - {fbvFormSection} - {fbvElement type="text" required="required" label="email.email" id="new-email" name="email[]" inline=true size=$fbvStyles.size.SMALL} - {fbvElement type="text" label="common.name" id="new-name" name="name[]" inline=true size=$fbvStyles.size.MEDIUM} - {fbvElement type="button" label="common.more" id="insert" inline=true class="pkp_button_primary default insert-button"} - {/fbvFormSection} - {/fbvFormArea} + {fbvFormArea id="registrationNotificationSettingsFormArea"} + {foreach from=$email key=index item=value} + {fbvFormSection} + {fbvElement type="text" label="email.email" id="email-`$index`" name="email[]" value=$value inline=true size=$fbvStyles.size.SMALL} + {fbvElement type="text" label="common.name" id="name-`$index`" name="name[]" value=$name[$index] inline=true size=$fbvStyles.size.MEDIUM} + {fbvElement type="button" label="common.remove" id="remove-`$index`" inline=true class="default remove-button"} + {/fbvFormSection} + {/foreach} + {fbvFormSection} + {fbvElement type="text" label="email.email" id="new-email" name="email[]" inline=true size=$fbvStyles.size.SMALL} + {fbvElement type="text" label="common.name" id="new-name" name="name[]" inline=true size=$fbvStyles.size.MEDIUM} + {fbvElement type="button" label="common.more" id="insert" inline=true class="pkp_button_primary default insert-button"} + {/fbvFormSection} + {/fbvFormArea} - {fbvFormButtons} -

{translate key="common.requiredField"}

+ {fbvFormButtons} +

{translate key="common.requiredField"}

+
-
diff --git a/version.xml b/version.xml index 9bdd27e..23e5717 100644 --- a/version.xml +++ b/version.xml @@ -13,8 +13,8 @@ registrationNotification plugins.generic - 1.0.0.1 - 2019-01-21 + 1.0.0.2 + 2019-02-24 1 RegistrationNotificationPlugin