From ece06bc462971022917b2b81fbfc5ad7fc622281 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 6 Nov 2019 16:34:20 +0100 Subject: [PATCH] Notice email for all people allowed to receive messages for an organisation unit --- application/libraries/MessageLib.php | 12 +++++++++--- application/models/system/Recipient_model.php | 6 +++--- public/js/messaging/write.js | 10 +++++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 9224996c8..cff457a77 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -528,17 +528,23 @@ class MessageLib if (isError($messageResult)) return $messageResult; // if an error occured then return it if (!hasData($messageResult)) return error('No data found with the given message id'); // if no data found then return an error + // If the message was sent to an organisation unit, then retrives the allowed people to receive the notice email for that organisation unit $messages = getData($messageResult); - if (count($messages) == 1 && $messages[0]->receiver_id == $this->_ci->config->item(self::CFG_SYSTEM_PERSON_ID)) + if (count($messages) == 1 + && $messages[0]->receiver_id == $this->_ci->config->item(self::CFG_SYSTEM_PERSON_ID) + && !isEmptyString($messages[0]->oe_kurzbz)) { - $messages = $this->_ci->RecipientModel->getReceivedMessagesByOE( + $messageResult = $this->_ci->RecipientModel->getMessagesToSentToOE( $messages[0]->oe_kurzbz, $this->_ci->config->item(MessageLib::CFG_OU_RECEIVERS), self::EMAIL_KONTAKT_TYPE ); } - return $this->_sendNotice($messages); + if (isError($messageResult)) return $messageResult; + if (!hasData($messageResult)) return error('It is not possible to retrieve the recipient for this message: '.$message_id); + + return $this->_sendNotice(getData($messageResult)); } /** diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 76a0bf435..4d5e4b986 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -379,9 +379,9 @@ class Recipient_model extends DB_Model } /** - * Gets only the recieved messages from an organisation unit where this person plays a role given by the parameter functions + * Get all the messages to sent to an organisation unit */ - public function getReceivedMessagesByOE($oe_kurzbz, $functions, $kontaktType) + public function getMessagesToSentToOE($oe_kurzbz, $functions, $kontaktType) { // Messages sent to a person that belongs to the recipient organisation unit $sql = 'SELECT mm.message_id, @@ -427,7 +427,7 @@ class Recipient_model extends DB_Model ) mb ON (mb.person_id = mm.person_id) WHERE bf.oe_kurzbz = ? AND mrou.sent IS NULL - AND mrou.sentinfo IS NOT NULL + AND mrou.sentinfo IS NULL GROUP BY mm.message_id, mm.subject, mm.body, diff --git a/public/js/messaging/write.js b/public/js/messaging/write.js index 180a47c36..7be07f28a 100644 --- a/public/js/messaging/write.js +++ b/public/js/messaging/write.js @@ -22,7 +22,15 @@ function sendMessageToOU() }, { successCallback: function(data, textStatus, jqXHR) { - FHC_DialogLib.alertSuccess("Message sent succesfully"); + + if (FHC_AjaxClient.isSuccess(data)) + { + FHC_DialogLib.alertSuccess("Message sent succesfully"); + } + else + { + FHC_DialogLib.alertError("Error"); + } }, errorCallback: function() { FHC_DialogLib.alertError("Error");