From 6882199d0e524a2242b4498afa4fea370bc9a8b8 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 12 Feb 2020 14:43:11 +0100 Subject: [PATCH] Bugfixes to allow to write to a person or to a prestudent from different GUIs --- .../controllers/system/messages/Messages.php | 24 ++++---- .../system/messages/ViewMessage.php | 4 +- application/models/CL/Messages_model.php | 57 +++++++++++-------- ...htmlError.php => htmlMessageSentError.php} | 2 +- ...Success.php => htmlMessageSentSuccess.php} | 2 +- .../views/system/messages/htmlRead.php | 2 +- .../system/messages/htmlWriteTemplate.php | 4 ++ public/js/messaging/messageWrite.js | 21 ++----- 8 files changed, 62 insertions(+), 54 deletions(-) rename application/views/system/messages/{htmlError.php => htmlMessageSentError.php} (96%) rename application/views/system/messages/{htmlSuccess.php => htmlMessageSentSuccess.php} (95%) diff --git a/application/controllers/system/messages/Messages.php b/application/controllers/system/messages/Messages.php index 0124e704c..7b48b1fcf 100644 --- a/application/controllers/system/messages/Messages.php +++ b/application/controllers/system/messages/Messages.php @@ -56,18 +56,18 @@ class Messages extends Auth_Controller { $subject = $this->input->post('subject'); $body = $this->input->post('body'); - $persons = $this->input->post('persons'); - $prestudenten = $this->input->post('prestudenten'); + $recipients_ids = $this->input->post('recipients_ids'); $relationmessage_id = $this->input->post('relationmessage_id'); + $type = $this->input->post('type'); - $sendImplicitTemplate = $this->CLMessagesModel->sendImplicitTemplate($prestudenten, $subject, $body, $relationmessage_id); + $sendImplicitTemplate = $this->CLMessagesModel->sendImplicitTemplate($type, $recipients_ids, $subject, $body, $relationmessage_id); if (isSuccess($sendImplicitTemplate)) { - $this->load->view('system/messages/htmlSuccess'); + $this->load->view('system/messages/htmlMessageSentSuccess'); } else { - $this->load->view('system/messages/htmlError'); + $this->load->view('system/messages/htmlMessageSentError'); } } @@ -92,17 +92,21 @@ class Messages extends Auth_Controller */ public function parseMessageText() { - $person_id = $this->input->get('person_id'); - $prestudent_id = $this->input->get('prestudent_id'); + $receiver_id = $this->input->get('receiver_id'); $text = $this->input->get('text'); + $type = $this->input->get('type'); - if (!isEmptyString($person_id)) + if ($type == Messages_model::TYPE_PERSONS) { - $this->outputJson($this->CLMessagesModel->parseMessageText($person_id, $text)); + $this->outputJson($this->CLMessagesModel->parseMessageTextPerson($receiver_id, $text)); + } + elseif ($type == Messages_model::TYPE_PRESTUDENTS) + { + $this->outputJson($this->CLMessagesModel->parseMessageTextPrestudent($receiver_id, $text)); } else { - $this->outputJson($this->CLMessagesModel->parseMessageTextPrestudent($prestudent_id, $text)); + $this->outputJsonError('Not a person nor a prestudent was provided'); } } diff --git a/application/controllers/system/messages/ViewMessage.php b/application/controllers/system/messages/ViewMessage.php index 4544ffcc1..ccb9afb33 100644 --- a/application/controllers/system/messages/ViewMessage.php +++ b/application/controllers/system/messages/ViewMessage.php @@ -73,11 +73,11 @@ class ViewMessage extends FHC_Controller $sendReply = $this->CLMessagesModel->sendReply($receiver_id, $subject, $body, $relationmessage_id, $token); if (isSuccess($sendReply)) { - $this->load->view('system/messages/htmlSuccess'); + $this->load->view('system/messages/htmlMessageSentSuccess'); } else { - $this->load->view('system/messages/htmlError'); + $this->load->view('system/messages/htmlMessageSentError'); } } diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index 399a16144..cf5ccd141 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -23,6 +23,10 @@ class Messages_model extends CI_Model const NO_AUTH_UID = 'online'; // hard coded uid if no authentication is performed const ALT_OE = 'infocenter'; // alternative organisation unit when no one is found for a presetudent + // Recipients types + const TYPE_PERSONS = 'persons'; + const TYPE_PRESTUDENTS = 'prestudents'; + /** * Constructor */ @@ -330,14 +334,22 @@ class Messages_model extends CI_Model * Sends a new message or a reply to a message (if $relationmessage_id is given) * using the template stored in the subject and body */ - public function sendImplicitTemplate($persons, $subject, $body, $relationmessage_id = null) + public function sendImplicitTemplate($type, $recipients_ids, $subject, $body, $relationmessage_id = null) { // Retrieves the sender id $sender_id = getAuthPersonId(); if (!is_numeric($sender_id)) show_error('The current logged user person_id is not defined'); + $msgVarsData = error('No persons nor prestudents were provided'); // Retrieves message vars data for the given user/s - $msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($persons); + if ($type == self::TYPE_PERSONS) // if persons were given + { + $msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($recipients_ids); + } + elseif ($type == self::TYPE_PRESTUDENTS) // otherwise prestudents were given + { + $msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($recipients_ids); + } if (isError($msgVarsData)) show_error(getError($msgVarsData)); if (!hasData($msgVarsData)) show_error('No recipients were given'); @@ -361,9 +373,12 @@ class Messages_model extends CI_Model if (isError($message)) return $message; if (!hasData($message)) return error('No messages were saved in database'); - // Write log entry - $personLog = $this->_personLog($sender_id, $msgVarsDataArray['person_id'], getData($message)[0]); - if (isError($personLog)) return $personLog; + // Write log entry only if persons were given + if ($type == self::TYPE_PERSONS) + { + $personLog = $this->_personLog($sender_id, $msgVarsDataArray['person_id'], getData($message)[0]); + if (isError($personLog)) return $personLog; + } } return success('Messages sent successfully'); @@ -515,14 +530,11 @@ class Messages_model extends CI_Model * Parse the given given text using data from the given user * Use the CI parser which performs simple text substitution for pseudo-variable */ - public function parseMessageText($person_id, $text) + public function parseMessageTextPerson($person_id, $text) { $parseMessageText = error('The given person_id is not a valid number'); - if (is_numeric($person_id)) - { - $parseMessageText = $this->MessageModel->getMsgVarsDataByPersonId($person_id); - } + if (is_numeric($person_id)) $parseMessageText = $this->MessageModel->getMsgVarsDataByPersonId($person_id); if (hasData($parseMessageText)) { @@ -545,10 +557,7 @@ class Messages_model extends CI_Model { $parseMessageText = error('The given prestudent_id is not a valid number'); - if (is_numeric($prestudent_id)) - { - $parseMessageText = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); - } + if (is_numeric($prestudent_id)) $parseMessageText = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); if (hasData($parseMessageText)) { @@ -683,27 +692,30 @@ class Messages_model extends CI_Model // - persons: a string that contains HTML input hidden with alla the receivers id (person_id) $recipientsArray = array(); $recipientsList = ''; - $persons = ''; - $prestudenten = ''; + $recipients_ids = ''; + foreach (getData($info) as $receiver) { + $id = 0; $recipient = new stdClass(); $recipient->description = $receiver->Vorname.' '.$receiver->Nachname; + $recipientsList .= $receiver->Vorname.' '.$receiver->Nachname.'; '; // If it is a prestudent then if (isset($receiver->prestudent_id) && is_numeric($receiver->prestudent_id)) { $recipient->id = $receiver->prestudent_id; + $id = $receiver->prestudent_id; } else // otherwise it is a person { $recipient->id = $receiver->person_id; + $id = $receiver->person_id; } + $recipients_ids .= ''."\n"; + $recipientsArray[] = $recipient; - $recipientsList .= $receiver->Vorname.' '.$receiver->Nachname.'; '; - $persons .= ''."\n"; - $prestudenten .= ''."\n"; } // --------------------------------------------------------------------------------------- @@ -738,12 +750,12 @@ class Messages_model extends CI_Model if (isset(getData($info)[0]->prestudent_id) && is_numeric(getData($info)[0]->prestudent_id)) { $variablesResult = $this->messagelib->getMessageVarsPrestudent(); - $type = ''; + $type = ''; } else { $variablesResult = $this->messagelib->getMessageVarsPerson(); - $type = ''; + $type = ''; } if (isError($variablesResult)) show_error(getError($variablesResult)); @@ -780,8 +792,7 @@ class Messages_model extends CI_Model 'organisationUnits' => getData($organisationUnits), 'senderIsAdmin' => getData($senderIsAdmin), 'recipientsArray' => $recipientsArray, - 'persons' => $persons, - 'prestudenten' => $prestudenten, + 'recipients_ids' => $recipients_ids, 'relationmessage_id' => $relationmessage, 'type' => $type ); diff --git a/application/views/system/messages/htmlError.php b/application/views/system/messages/htmlMessageSentError.php similarity index 96% rename from application/views/system/messages/htmlError.php rename to application/views/system/messages/htmlMessageSentError.php index 78ffc7164..90191fcf0 100644 --- a/application/views/system/messages/htmlError.php +++ b/application/views/system/messages/htmlMessageSentError.php @@ -2,7 +2,7 @@ $this->load->view( 'templates/FHC-Header', array( - 'title' => 'Message sent failure', + 'title' => 'Message sent failure - Fehler beim Senden der Nachricht', 'jquery' => true, 'bootstrap' => true, 'fontawesome' => true, diff --git a/application/views/system/messages/htmlSuccess.php b/application/views/system/messages/htmlMessageSentSuccess.php similarity index 95% rename from application/views/system/messages/htmlSuccess.php rename to application/views/system/messages/htmlMessageSentSuccess.php index e421a77e0..48409a5f4 100644 --- a/application/views/system/messages/htmlSuccess.php +++ b/application/views/system/messages/htmlMessageSentSuccess.php @@ -2,7 +2,7 @@ $this->load->view( 'templates/FHC-Header', array( - 'title' => 'Message sent successfully', + 'title' => 'Message sent successfully - Nachricht erfolgreich versandt!', 'jquery' => true, 'bootstrap' => true, 'fontawesome' => true, diff --git a/application/views/system/messages/htmlRead.php b/application/views/system/messages/htmlRead.php index ed184f7c5..985eee326 100644 --- a/application/views/system/messages/htmlRead.php +++ b/application/views/system/messages/htmlRead.php @@ -2,7 +2,7 @@ $this->load->view( 'templates/FHC-Header', array( - 'title' => 'Read a message', + 'title' => 'Read message - Lies die Nachricht', 'jquery' => true, 'bootstrap' => true, 'fontawesome' => true, diff --git a/application/views/system/messages/htmlWriteTemplate.php b/application/views/system/messages/htmlWriteTemplate.php index b4a6af283..77bc168a7 100644 --- a/application/views/system/messages/htmlWriteTemplate.php +++ b/application/views/system/messages/htmlWriteTemplate.php @@ -162,8 +162,12 @@ +<<<<<<< Updated upstream +======= + +>>>>>>> Stashed changes diff --git a/public/js/messaging/messageWrite.js b/public/js/messaging/messageWrite.js index cc9d40730..0676329de 100644 --- a/public/js/messaging/messageWrite.js +++ b/public/js/messaging/messageWrite.js @@ -19,24 +19,13 @@ function tinymcePreviewSetContent() function parseMessageText(receiver_id, text) { - var data = {text: text}; - - if ($("#type").val() == 'persons') - { - data.person_id = receiver_id; - } - else if ($("#type").val() == 'prestudents') - { - data.prestudent_id = receiver_id; - } - else - { - return; - } - FHC_AjaxClient.ajaxCallGet( "system/messages/Messages/parseMessageText", - data, + { + receiver_id: receiver_id, + text: text, + type: $("#type").val() + }, { successCallback: function(data, textStatus, jqXHR) {