From 2ef386c34e7cd1352f7cb2df211e438bcc627b40 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 12 Jun 2019 17:27:35 +0200 Subject: [PATCH 01/72] - Changed system/dbupdate_3.3.php to add oe_kurzbz to table public.tbl_msg_recipient and foreign key fk_tbl_msg_recipient_oe_kurzbz - Removed not used constants for messaging from config/constants.php - Renamed config entry assistent_function to ou_receivers and converted from string to array - Moved controllers/MailJob.php to controllers/jobs/MailJob.php - Controller MailJob now extends CLI_Controller - Added new function parseText to helpers/hlp_common_helper.php - Improved code function generateToken in helpers/hlp_common_helper.php - helpers/hlp_sancho_helper.php now uses parseText function from hlp_common_helper - Removed method parseVorlagetext from PhrasesLib.php - PhrasesLib.php now uses parseText function from hlp_common_helper - Removed method parseVorlagetext from VorlageLib - Improved code of controller controllers/system/Messages.php (uses parseText too) - Controller controllers/system/Vorlage.php now uses parseText --- application/config/constants.php | 37 +++--- application/config/message.php | 2 +- .../controllers/{ => jobs}/MailJob.php | 11 +- application/controllers/system/Messages.php | 121 +++++++++--------- application/controllers/system/Vorlage.php | 2 +- application/helpers/hlp_common_helper.php | 73 +++++++---- application/helpers/hlp_sancho_helper.php | 4 +- application/libraries/PhrasesLib.php | 12 +- application/libraries/VorlageLib.php | 14 -- system/dbupdate_3.3.php | 27 +++- 10 files changed, 161 insertions(+), 142 deletions(-) rename application/controllers/{ => jobs}/MailJob.php (68%) diff --git a/application/config/constants.php b/application/config/constants.php index ac2ecc649..e1c5906c3 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -136,26 +136,19 @@ define('MSG_STATUS_READ', 1); define('MSG_STATUS_ARCHIVED', 2); define('MSG_STATUS_DELETED', 3); -// Priority -define('PRIORITY_LOW', 1); -define('PRIORITY_NORMAL', 2); -define('PRIORITY_HIGH', 3); -define('PRIORITY_URGENT', 4); +// Message priorities +define('MSG_PRIORITY_LOW', 1); +define('MSG_PRIORITY_NORMAL', 2); +define('MSG_PRIORITY_HIGH', 3); +define('MSG_PRIORITY_URGENT', 4); -define('MSG_ERR_SUBJECT_EMPTY', 40); -define('MSG_ERR_BODY_EMPTY', 41); -define('MSG_ERR_TEMPLATE_NOT_FOUND', 42); -define('MSG_ERR_DELIVERY_MESSAGE', 43); -define('MSG_ERR_CONTACT_NOT_FOUND', 44); -define('MSG_ERR_OU_CONTACTS_NOT_FOUND', 45); - -define('MSG_ERR_INVALID_USER_ID', 100); -define('MSG_ERR_INVALID_MSG_ID', 101); -define('MSG_ERR_INVALID_THREAD_ID', 102); -define('MSG_ERR_INVALID_STATUS_ID', 103); -define('MSG_ERR_INVALID_SENDER_ID', 104); -define('MSG_ERR_INVALID_RECIPIENTS', 105); -define('MSG_ERR_INVALID_RECEIVER_ID', 106); -define('MSG_ERR_INVALID_OU', 107); -define('MSG_ERR_INVALID_TEMPLATE', 108); -define('MSG_ERR_INVALID_TOKEN', 109); +// Message error status +define('MSG_ERR_INVALID_SUBJECT', 40); +define('MSG_ERR_INVALID_BODY', 41); +define('MSG_ERR_INVALID_TEMPLATE', 42); +define('MSG_ERR_INVALID_MSG_ID', 43); +define('MSG_ERR_INVALID_STATUS_ID', 44); +define('MSG_ERR_INVALID_SENDER', 45); +define('MSG_ERR_INVALID_RECIPIENTS', 46); +define('MSG_ERR_INVALID_OU', 47); +define('MSG_ERR_INVALID_TOKEN', 48); diff --git a/application/config/message.php b/application/config/message.php index 40d15a07e..30444b0ef 100644 --- a/application/config/message.php +++ b/application/config/message.php @@ -12,7 +12,7 @@ $config['message_html_view_url'] = '/ViewMessage/toHTML/'; // Change this to CIS Server (https://cis.example.com/index.ci.php) if you are sending Messages from Vilesci $config['message_server'] = site_url(); -$config['assistent_function'] = 'ass'; +$config['ou_receivers'] = array('ass'); $config['message_redirect_url'] = array(); $config['message_redirect_url']['fallback'] = site_url('ViewMessage/writeReply'); diff --git a/application/controllers/MailJob.php b/application/controllers/jobs/MailJob.php similarity index 68% rename from application/controllers/MailJob.php rename to application/controllers/jobs/MailJob.php index 2f8b5b92d..cb5ffc032 100644 --- a/application/controllers/MailJob.php +++ b/application/controllers/jobs/MailJob.php @@ -14,22 +14,25 @@ if (!defined("BASEPATH")) exit("No direct script access allowed"); -class MailJob extends Auth_Controller +class MailJob extends CLI_Controller { /** * API constructor */ public function __construct() { - // An empty array as parameter will ensure that this controller is ONLY callable from command line - parent::__construct(array()); + parent::__construct(); // Loads MessageLib $this->load->library('MessageLib'); } + /** + * Send all not sent messages + * Parameters are used to overrride messages and mail configuration + */ public function sendMessages($numberToSent = null, $numberPerTimeRange = null, $email_time_range = null, $email_from_system = null) { - $this->messagelib->sendAll($numberToSent, $numberPerTimeRange, $email_time_range, $email_from_system); + $this->messagelib->sendAllNotices($numberToSent, $numberPerTimeRange, $email_time_range, $email_from_system); } } diff --git a/application/controllers/system/Messages.php b/application/controllers/system/Messages.php index ec630da1e..744eb880e 100644 --- a/application/controllers/system/Messages.php +++ b/application/controllers/system/Messages.php @@ -5,7 +5,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); class Messages extends Auth_Controller { /** - * + * MessageLib is loaded by CLMessagesModel */ public function __construct() { @@ -20,9 +20,6 @@ class Messages extends Auth_Controller ) ); - // Loads the message library - $this->load->library('MessageLib'); - // Loads the widget library $this->load->library('WidgetLib'); @@ -38,30 +35,26 @@ class Messages extends Auth_Controller } // ----------------------------------------------------------------------------------------------------------------- - // Public methods + // Public methods - HTML output /** - * Write a new message + * Initialize all the parameters used by view system/messages/messageWrite + * to build a GUI used to write a messate to user/s */ public function write() { - $person_id = $this->input->post('person_id'); - $sender_id = null; + $persons = $this->input->post('person_id'); $authUser = $this->CLMessagesModel->getAuthUser(); - if (isError($authUser)) - { - show_error(getData($authUser)); - } - else - { - $sender_id = getData($authUser)[0]->person_id; - } + if (isError($authUser)) show_error(getData($authUser)); - $msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($person_id); + $sender_id = getData($authUser)[0]->person_id; + + // Retrieves person information + $msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($persons); if (isError($msgVarsData)) show_error(getData($msgVarsData)); - // Retrieves message vars for a person from view view vw_msg_vars_person + // Retrieves message vars from view vw_msg_vars_person $variables = $this->messagelib->getMessageVarsPerson(); if (isError($variables)) show_error(getData($variables)); @@ -73,33 +66,43 @@ class Messages extends Auth_Controller $isAdmin = $this->messagelib->getIsAdmin($sender_id); if (isError($isAdmin)) show_error(getData($isAdmin)); - $data = array ( - 'recipients' => getData($msgVarsData), - 'variables' => getData($variables), - 'oe_kurzbz' => getData($oe_kurzbz), // used to get the templates - 'isAdmin' => getData($isAdmin) + $this->load->view( + 'system/messages/messageWrite', + array ( + 'recipients' => getData($msgVarsData), // recipients data + 'variables' => getData($variables), // message vars + 'oe_kurzbz' => getData($oe_kurzbz), // used to get the templates + 'isAdmin' => getData($isAdmin) // is admin? + ) ); - - $this->load->view('system/messages/messageWrite', $data); } /** - * Send message + * Send a new message or reply to user/s + * If a relationmessage_id this message is a reply to another one */ public function send() { $persons = $this->input->post('persons'); $relationmessage_id = $this->input->post('relationmessage_id'); + // Retrieves message vars data for the fiven user/s $msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($persons); + // Send the message $send = $this->CLMessagesModel->send($msgVarsData, $relationmessage_id); $this->load->view('system/messages/messageSent', array('success' => isSuccess($send))); } + // ----------------------------------------------------------------------------------------------------------------- + // Public methods - JSON output + /** - * Send message, response is in JSON format + * Send a new message + * - The recipients are prestudents + * - An email template with message var may be provided + * - A global organisation unit may be provided, otherwise is used the prestudent one */ public function sendJson() { @@ -120,23 +123,19 @@ class Messages extends Auth_Controller } $send = $this->CLMessagesModel->send($msgVarsData, null, $oe_kurzbz, $vorlage_kurzbz, $msgVars); - if (isError($send)) - { - $this->outputJsonError(getData($send)); - } - else - { - $this->outputJsonSuccess(getData($send)); - } + + $this->outputJson(getData($send)); } /** - * getVorlage + * Returns an object that represent a template store in database + * If no templates are found with the given parameter or the given parameter is an empty string, + * then an error is returned */ public function getVorlage() { $vorlage_kurzbz = $this->input->get('vorlage_kurzbz'); - $result = null; + $result = error('The given vorlage_kurzbz is not valid'); if (!isEmptyString($vorlage_kurzbz)) { @@ -145,10 +144,6 @@ class Messages extends Auth_Controller $result = $this->VorlagestudiengangModel->loadWhere(array('vorlage_kurzbz' => $vorlage_kurzbz)); } - else - { - $result = error('The given vorlage_kurzbz is not valid'); - } if (isError($result) || !hasData($result)) { @@ -161,40 +156,37 @@ class Messages extends Auth_Controller } /** - * parseMessageText + * 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 = $this->input->get('person_id'); $text = $this->input->get('text'); - $parsedText = ''; - $data = null; + $msgVarsData = error('The given person_id is not a valid number'); if (is_numeric($person_id)) { - $data = $this->MessageModel->getMsgVarsDataByPersonId($person_id); + $msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($person_id); + } + + if (isError($msgVarsData) || !hasData($msgVarsData)) + { + $this->outputJsonError(getData($msgVarsData)); } else { - $data = error('The given person_id is not a valid number'); - } - - if (isError($data) || !hasData($data)) - { - $this->outputJsonError(getData($data)); - } - else - { - $parsedText = $this->messagelib->parseMessageText($text, $this->CLMessagesModel->replaceKeys((array)getData($data)[0])); - - $this->outputJsonSuccess($parsedText); + $this->outputJsonSuccess( + parseText( + $text, + $this->CLMessagesModel->replaceKeys((array)getData($msgVarsData)[0]) + ) + ); } } /** * Outputs message data for a message (identified my msg id and receiver id) in JSON format - * @param $msg_id - * @param $receiver_id */ public function getMessageFromIds() { @@ -203,8 +195,13 @@ class Messages extends Auth_Controller $msg = $this->messagelib->getMessage($msg_id, $receiver_id); - $this->output - ->set_content_type('application/json') - ->set_output(json_encode(array(getData($msg)[0]))); + if (isError($msg) || !hasData($msg)) + { + $this->outputJson(array()); + } + else + { + $this->outputJson(array(getData($msg)[0])); + } } } diff --git a/application/controllers/system/Vorlage.php b/application/controllers/system/Vorlage.php index 4712d0e68..22513970e 100644 --- a/application/controllers/system/Vorlage.php +++ b/application/controllers/system/Vorlage.php @@ -269,7 +269,7 @@ class Vorlage extends Auth_Controller show_error($vorlagetext->retval); $data = array( - 'text' => $this->vorlagelib->parseVorlagetext($vorlagetext->retval[0]->text, $jsonDecodedForm) + 'text' => parseText($vorlagetext->retval[0]->text, $jsonDecodedForm) ); $this->load->view('system/vorlage/templatetextPreview', $data); diff --git a/application/helpers/hlp_common_helper.php b/application/helpers/hlp_common_helper.php index bc09cd32c..45a36914c 100644 --- a/application/helpers/hlp_common_helper.php +++ b/application/helpers/hlp_common_helper.php @@ -24,39 +24,54 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); // ------------------------------------------------------------------------ /** - * generateToken() - generates a new token for diffent use - * - reading Messages from external - * - forgotten Password - * - * @return string + * Generates a new token for diffent use cases. Default token length is 64 + * - Reading messages + * - Forgotten password + * - etc + * Returns null on failure */ function generateToken($length = 64) { + $token = null; + $firstGeneratedToken = null; + // For PHP 7 you can use random_bytes() if (function_exists('random_bytes')) { - $token = base64_encode(random_bytes($length)); - //base64 is about 33% longer, so we need to truncate the result - return strtr(substr($token, 0, $length), '+/=', '-_,'); + try + { + $firstGeneratedToken = random_bytes($length); // try to generates cryptographically secure pseudo-random bytes... + } + catch (Exception $e) { $firstGeneratedToken = null; } // if fails $firstGeneratedToken is set to null } - - // for PHP >=5.3 and <7 - if (function_exists('openssl_random_pseudo_bytes')) + // For PHP >= 5.3 and < 7 and openssl is available + elseif (function_exists('openssl_random_pseudo_bytes')) { - $token = base64_encode(openssl_random_pseudo_bytes($length, $strong)); - // is the token strong enough? - if($strong == true) - return strtr(substr($token, 0, $length), '+/=', '-_,'); + $firstGeneratedToken = openssl_random_pseudo_bytes($length, $strong); + // If the token generation ended with errors OR the generated token is NOT strong enough + if ($firstGeneratedToken == false || $strong == false) $firstGeneratedToken = null; // $firstGeneratedToken is set to null } - //fallback to mt_rand if php < 5.3 or no openssl available - $characters = '0123456789'; - $characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/+'; - $charactersLength = strlen($characters)-1; - $token = ''; - //select some random characters - for ($i = 0; $i < $length; $i++) - $token .= $characters[mt_rand(0, $charactersLength)]; + if ($firstGeneratedToken != null) // If everything was fine + { + // base64 is about 33% longer, so we need to truncate the result + $token = strtr(substr(base64_encode($firstGeneratedToken), 0, $length), '+/=', '-_,'); + } + + // Fallback to mt_rand if: + // php < 5.3 + // OR no openssl is available + // OR openssl_random_pseudo_bytes used an algorithm that is cryptographically NOT strong + // OR one of the previous methods failed + if ($token == null) + { + $token = ''; // set $token as an empty string + $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/+'; + $charactersLength = strlen($characters) - 1; + + // Select some random characters + for ($i = 0; $i < $length; $i++) $token .= $characters[mt_rand(0, $charactersLength)]; + } return $token; } @@ -224,3 +239,15 @@ function isDateWorkingDay($date, $days = null) return true; } } + +/** + * Parse the given given text using the given data parameter + * Use the CI parser which performs simple text substitution for pseudo-variable + */ +function parseText($text, $data) +{ + $ci =& get_instance(); // get CI instance + $ci->load->library('parser'); // Loads CI parser library + + return $ci->parser->parse_string($text, $data, true); +} diff --git a/application/helpers/hlp_sancho_helper.php b/application/helpers/hlp_sancho_helper.php index 6f5ef8c24..5d2d9f1f1 100644 --- a/application/helpers/hlp_sancho_helper.php +++ b/application/helpers/hlp_sancho_helper.php @@ -98,9 +98,7 @@ function _parseMailContent($vorlage_kurzbz, $vorlage_data) !isEmptyString($result->retval[0]->text)) { // Parses template text - $parsedText = $ci->vorlagelib->parseVorlagetext($result->retval[0]->text, $vorlage_data); - - return $parsedText; + return parseText($result->retval[0]->text, $vorlage_data); } } } diff --git a/application/libraries/PhrasesLib.php b/application/libraries/PhrasesLib.php index af642fe9e..7d0d6859f 100644 --- a/application/libraries/PhrasesLib.php +++ b/application/libraries/PhrasesLib.php @@ -165,16 +165,6 @@ class PhrasesLib } /** - * parseVorlagetext() - will parse a Vorlagetext. - */ - public function parseVorlagetext($text, $data = array()) - { - if (isEmptyString($text)) return error('Not a valid text'); - - return $this->_ci->parser->parse_string($text, $data, true); - } - - /** * Retrieves a phrases from the the property _phrases with the given parameters * It also replace parameters inside the phrase if they are provided * @param string $category Category name which is used to categorize the phrase. @@ -201,7 +191,7 @@ class PhrasesLib { if (!is_array($parameters)) $parameters = array(); // if params is not an array - return $this->_ci->parser->parse_string($_phrase->text, $parameters, true); // parsing + return parseText($_phrase->text, $parameters); // parsing } } } diff --git a/application/libraries/VorlageLib.php b/application/libraries/VorlageLib.php index d6c9d6a98..9679dff1c 100644 --- a/application/libraries/VorlageLib.php +++ b/application/libraries/VorlageLib.php @@ -188,18 +188,4 @@ class VorlageLib $vorlagetext = $this->ci->VorlageStudiengangModel->update($vorlagestudiengang_id, $data); return $vorlagetext; } - - /** - * parseVorlagetext() - will parse a Vorlagetext. - * - * @param string $text REQUIRED - * @param array $data REQUIRED - * @return string - */ - public function parseVorlagetext($text, $data = array()) - { - if (isEmptyString($text)) return error('Not a valid text'); - - return $this->ci->parser->parse_string($text, $data, true); - } } diff --git a/system/dbupdate_3.3.php b/system/dbupdate_3.3.php index ac5f5fdba..b76d994ee 100644 --- a/system/dbupdate_3.3.php +++ b/system/dbupdate_3.3.php @@ -2938,6 +2938,31 @@ if(!$result = @$db->db_query("SELECT bezeichnung_mehrsprachig FROM bis.tbl_orgfo } } +// Add column oe_kurzbz to public.tbl_msg_recipient +if(!$result = @$db->db_query("SELECT oe_kurzbz FROM public.tbl_msg_recipient LIMIT 1")) +{ + $qry = 'ALTER TABLE public.tbl_msg_recipient ADD COLUMN oe_kurzbz character varying(32);'; + if(!$db->db_query($qry)) + echo 'public.tbl_msg_recipient: '.$db->db_last_error().'
'; + else + echo '
Added column oe_kurzbz to table public.tbl_msg_recipient'; + + // FOREIGN KEY fk_tbl_msg_recipient_oe_kurzbz: public.tbl_msg_recipient.oe_kurzbz references public.tbl_organisationseinheit.oe_kurzbz + if ($result = @$db->db_query("SELECT conname FROM pg_constraint WHERE conname = 'fk_tbl_msg_recipient_oe_kurzbz'")) + { + if ($db->db_num_rows($result) == 0) + { + $qry = "ALTER TABLE public.tbl_msg_recipient ADD CONSTRAINT fk_tbl_msg_recipient_oe_kurzbz FOREIGN KEY (oe_kurzbz) + REFERENCES public.tbl_organisationseinheit(oe_kurzbz) ON UPDATE CASCADE ON DELETE RESTRICT;"; + + if (!$db->db_query($qry)) + echo 'public.tbl_msg_recipient: '.$db->db_last_error().'
'; + else + echo '
public.tbl_msg_recipient: added foreign key on column oe_kurzbz referenced to public.tbl_organisationseinheit(oe_kurzbz)'; + } + } +} + // *** Pruefung und hinzufuegen der neuen Attribute und Tabellen echo '

Pruefe Tabellen und Attribute!

'; @@ -3121,7 +3146,7 @@ $tabellen=array( "public.tbl_mitarbeiter" => array("mitarbeiter_uid","personalnummer","telefonklappe","kurzbz","lektor","fixangestellt","bismelden","stundensatz","ausbildungcode","ort_kurzbz","standort_id","anmerkung","insertamum","insertvon","updateamum","updatevon","ext_id","kleriker"), "public.tbl_msg_attachment" => array("attachment_id","message_id","name","filename"), "public.tbl_msg_message" => array("message_id","person_id","subject","body","priority","relationmessage_id","oe_kurzbz","insertamum","insertvon"), - "public.tbl_msg_recipient" => array("message_id","person_id","token","sent","sentinfo","insertamum","insertvon"), + "public.tbl_msg_recipient" => array("message_id","person_id","token","sent","sentinfo","insertamum","insertvon","oe_kurzbz"), "public.tbl_msg_status" => array("message_id","person_id","status","statusinfo","insertamum","insertvon","updateamum","updatevon"), "public.tbl_notiz" => array("notiz_id","titel","text","verfasser_uid","bearbeiter_uid","start","ende","erledigt","insertamum","insertvon","updateamum","updatevon","ext_id"), "public.tbl_notizzuordnung" => array("notizzuordnung_id","notiz_id","projekt_kurzbz","projektphase_id","projekttask_id","uid","person_id","prestudent_id","bestellung_id","lehreinheit_id","ext_id","anrechnung_id"), From a5b3f0ed88219ea817c8aa496ac334384a810bc9 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 13 Jun 2019 14:09:56 +0200 Subject: [PATCH 02/72] - Moved constants EMAIL_KONTAKT_TYPE and SENT_INFO_NEWLINE from config/constants.php to MessageLib - Added function parseTemplate to helper helpers/hlp_common_helper.php - Changed method getMessages of model models/system/Recipient_model.php - Changed views/templates/mailHTML.php and views/templates/mailTXT.php --- application/config/constants.php | 5 ----- application/helpers/hlp_common_helper.php | 14 +++++++++++++- application/models/system/Recipient_model.php | 16 +++------------- application/views/templates/mailHTML.php | 6 +++--- application/views/templates/mailTXT.php | 8 ++++++-- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/application/config/constants.php b/application/config/constants.php index e1c5906c3..ce917b5a3 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -125,11 +125,6 @@ define('EMAIL_CONFIG_INDEX', 'mail'); | Messaging system constants |-------------------------------------------------------------------------- */ -// Email kontakt type -define('EMAIL_KONTAKT_TYPE', 'email'); -// tbl_msg_recipient->sentInfo separator -define('SENT_INFO_NEWLINE', '\n'); - // Message statuses define('MSG_STATUS_UNREAD', 0); define('MSG_STATUS_READ', 1); diff --git a/application/helpers/hlp_common_helper.php b/application/helpers/hlp_common_helper.php index 45a36914c..025834ed2 100644 --- a/application/helpers/hlp_common_helper.php +++ b/application/helpers/hlp_common_helper.php @@ -241,7 +241,7 @@ function isDateWorkingDay($date, $days = null) } /** - * Parse the given given text using the given data parameter + * Parse the given text using the given data parameter * Use the CI parser which performs simple text substitution for pseudo-variable */ function parseText($text, $data) @@ -251,3 +251,15 @@ function parseText($text, $data) return $ci->parser->parse_string($text, $data, true); } + +/** + * Parse the given template using the given data parameter + * Use the CI parser which performs simple text substitution for pseudo-variable + */ +function parseTemplate($template, $data) +{ + $ci =& get_instance(); // get CI instance + $ci->load->library('parser'); // Loads CI parser library + + return $ci->parser->parse($template, $data, true); +} diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 654a9a883..74a1c3256 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -205,7 +205,7 @@ class Recipient_model extends DB_Model * @param limit specifies the number of messages to get * @param message_id specifies a single message */ - public function getMessages($kontaktType, $sent, $limit = null, $message_id = null) + public function getMessages($kontaktType, $limit = 1, $message_id = null) { $query = 'SELECT mm.message_id, ks.kontakt as sender, @@ -239,17 +239,7 @@ class Recipient_model extends DB_Model $parametersArray = array($kontaktType, $kontaktType); - if (is_null($sent) || $sent == '') - { - $query .= ' WHERE mr.sent IS NULL'; - } - else - { - array_push($parametersArray, $sent); - $query .= ' WHERE mr.sent = ?'; - } - - if (!is_null($message_id)) + if (is_numeric($message_id)) { array_push($parametersArray, $message_id); $query .= ' AND mm.message_id = ?'; @@ -257,7 +247,7 @@ class Recipient_model extends DB_Model $query .= ' ORDER BY mr.insertamum ASC'; - if (!is_null($limit)) + if (is_numeric($limit)) { $query .= ' LIMIT ?'; array_push($parametersArray, $limit); diff --git a/application/views/templates/mailHTML.php b/application/views/templates/mailHTML.php index c2e072f68..32d544c5a 100644 --- a/application/views/templates/mailHTML.php +++ b/application/views/templates/mailHTML.php @@ -1,12 +1,12 @@ - This is not the email template, this is a tribute + Notification of personal message reception
-

Neue Nachricht vorhanden

+

A new message is available

diff --git a/application/views/templates/mailTXT.php b/application/views/templates/mailTXT.php index cd55aeb06..09634e6ae 100644 --- a/application/views/templates/mailTXT.php +++ b/application/views/templates/mailTXT.php @@ -1,3 +1,7 @@ -Follow the following link to read the message. +Notification of personal message reception -{href} \ No newline at end of file +A new message is available + +Click here to view the message + +{href} From 8135c6275e991b34b8cc98a41c355ef600a8affc Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 13 Jun 2019 15:57:45 +0200 Subject: [PATCH 03/72] - Fixed query building in method getMessages of model models/system/Recipient_model.php - Better code in controller api/v1/system/Message.php - Adapted controller api/v1/system/Message.php to use sendMessageUser and sendMessageUserTemplate methods from MessageLib - Adapted model models/CL/Messages_model.php to use sendMessageUser and sendMessageUserTemplate methods from MessageLib - Adapted model models/CL/Messages_model.php to use function parseText - Removed constant MSG_INDX_PREFIX from MessageLib - Added constants to MessageLib: CFG_SYSTEM_PERSON_ID, CFG_SEND_IMMEDIATELY, CFG_MESSAGE_SERVER, CFG_MESSAGE_HTML_VIEW_URL, CFG_OU_RECEIVERS, NOTICE_TEMPLATE_HTML, NOTICE_TEMPLATE_TXT, NOTICE_TEMPLATE_FALLBACK_HTML, NOTICE_TEMPLATE_FALLBACK_TXT, EMAIL_KONTAKT_TYPE and SENT_INFO_NEWLINE - MessageLib does not load anymore library parser - Improved MessageLib code - Added private methodis _sendMessage, _getSender, _getNoticeBody, _getNoticeHTMLBody, _getNoticeTXTBody and _ouExists to MessageLib - Added public methods sendMessageUser, sendMessageUserTemplate and sendMessageOU to MessageLib - Renamed method sendAll to sendAllNotices in MessageLib - Renamed method sendOne to _sendNotice and changed it from public to private - Renamed method _checkReceiverId to _getReceiversByPersonId --- .../controllers/api/v1/system/Message.php | 63 +- application/libraries/MessageLib.php | 1145 ++++++++--------- application/models/CL/Messages_model.php | 39 +- application/models/system/Recipient_model.php | 2 +- 4 files changed, 574 insertions(+), 675 deletions(-) diff --git a/application/controllers/api/v1/system/Message.php b/application/controllers/api/v1/system/Message.php index be87526ed..5c663e832 100644 --- a/application/controllers/api/v1/system/Message.php +++ b/application/controllers/api/v1/system/Message.php @@ -144,26 +144,26 @@ class Message extends APIv1_Controller */ public function postMessage() { - $validation = $this->_validatePostMessage($this->post()); + $postMessage = $this->_validatePostMessage($this->post()); - if (isSuccess($validation)) + if (isSuccess($postMessage)) { - $result = $this->messagelib->sendMessage( - isset($this->post()['person_id']) ? $this->post()['person_id'] : null, - isset($this->post()['receiver_id']) ? $this->post()['receiver_id'] : null, - $this->post()['subject'], - $this->post()['body'], - PRIORITY_NORMAL, - isset($this->post()['relationmessage_id']) ? $this->post()['relationmessage_id'] : null, - isset($this->post()['oe_kurzbz']) ? $this->post()['oe_kurzbz'] : null, // Sender organisation unit - isset($this->post()['multiPartMime']) ? $this->post()['multiPartMime'] : true + $result = $this->messagelib->sendMessageUser( + $this->post()['receiver_id']), // receiverPersonId + $this->post()['subject'], // subject + $this->post()['body'], // body + $this->post()['person_id']) ? $this->post()['person_id'] : null, // sender_id + isset($this->post()['oe_kurzbz']) ? $this->post()['oe_kurzbz'] : null, // senderOU + isset($this->post()['relationmessage_id']) ? $this->post()['relationmessage_id'] : null, // relationmessage_id + MSG_PRIORITY_NORMAL, // priority + isset($this->post()['multiPartMime']) ? $this->post()['multiPartMime'] : true // multiPartMime ); $this->response($result, REST_Controller::HTTP_OK); } else { - $this->response($validation, REST_Controller::HTTP_OK); + $this->response($postMessage, REST_Controller::HTTP_OK); } } @@ -172,26 +172,27 @@ class Message extends APIv1_Controller */ public function postMessageVorlage() { - $validation = $this->_validatePostMessageVorlage($this->post()); + $postMessage = $this->_validatePostMessageVorlage($this->post()); - if (isSuccess($validation)) + if (isSuccess($postMessage)) { - $result = $this->messagelib->sendMessageVorlage( - isset($this->post()['sender_id']) ? $this->post()['sender_id'] : null, - isset($this->post()['receiver_id']) ? $this->post()['receiver_id'] : null, - $this->post()['vorlage_kurzbz'], - isset($this->post()['oe_kurzbz']) ? $this->post()['oe_kurzbz'] : null, // Sender organisation unit - $this->post()['data'], - isset($this->post()['relationmessage_id']) ? $this->post()['relationmessage_id'] : null, - isset($this->post()['orgform_kurzbz']) ? $this->post()['orgform_kurzbz'] : null, - isset($this->post()['multiPartMime']) ? $this->post()['multiPartMime'] : true + $result = $this->messagelib->sendMessageUserTemplate( + isset($this->post()['receiver_id']) ? $this->post()['receiver_id'] : null, // receiversPersonId + $this->post()['vorlage_kurzbz'], // vorlage + $this->post()['data'], // parseData + isset($this->post()['orgform_kurzbz']) ? $this->post()['orgform_kurzbz'] : null, // orgform + isset($this->post()['sender_id']) ? $this->post()['sender_id'] : null, // sender_id + isset($this->post()['oe_kurzbz']) ? $this->post()['oe_kurzbz'] : null, // senderOU + isset($this->post()['relationmessage_id']) ? $this->post()['relationmessage_id'] : null, // relationmessage_id + MSG_PRIORITY_NORMAL, // priority + isset($this->post()['multiPartMime']) ? $this->post()['multiPartMime'] : true // multiPartMime ); $this->response($result, REST_Controller::HTTP_OK); } else { - $this->response($validation, REST_Controller::HTTP_OK); + $this->response($postMessage, REST_Controller::HTTP_OK); } } @@ -220,26 +221,26 @@ class Message extends APIv1_Controller /** * _validatePostMessage */ - private function _validatePostMessage($message = null) + private function _validatePostMessage($post = null) { - if (!isset($message)) + if (!isset($post)) { return error('Parameter is null'); } - if (!isset($message['subject'])) + if (!isset($post['subject'])) { return error('subject is not set'); } - if( !isset($message['body'])) + if (!isset($post['body'])) { return error('body is not set'); } - if (!isset($message['receiver_id']) && !isset($message['oe_kurzbz'])) + if (!isset($post['receiver_id'])) { - return error('If a receiver_id is not given a oe_kurzbz must be specified'); + return error('receiver_id is not set'); } - return success('Input data are valid'); + return success(); } /** diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index feba96473..7911d4b2d 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -7,7 +7,21 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); */ class MessageLib { - const MSG_INDX_PREFIX = 'message_'; + // Config entries + const CFG_SYSTEM_PERSON_ID = 'system_person_id'; + const CFG_SEND_IMMEDIATELY = 'send_immediately'; + const CFG_MESSAGE_SERVER = 'message_server'; + const CFG_MESSAGE_HTML_VIEW_URL = 'message_html_view_url'; + const CFG_OU_RECEIVERS = 'ou_receivers'; + + // Templates names + const NOTICE_TEMPLATE_HTML = 'MessageMailHTML'; + const NOTICE_TEMPLATE_TXT = 'MessageMailTXT'; + const NOTICE_TEMPLATE_FALLBACK_HTML = 'templates/mailHTML'; + const NOTICE_TEMPLATE_FALLBACK_TXT = 'templates/mailTXT'; + + const EMAIL_KONTAKT_TYPE = 'email'; // Email kontakt type + const SENT_INFO_NEWLINE = '\n'; // tbl_msg_recipient->sentInfo separator private $_ci; @@ -22,8 +36,6 @@ class MessageLib // Loads message configuration $this->_ci->config->load('message'); - // CI Parser library - $this->_ci->load->library('parser'); // Loads LogLib $this->_ci->load->library('LogLib'); // Loads VorlageLib @@ -31,352 +43,106 @@ class MessageLib // Loads Mail library $this->_ci->load->library('MailLib'); - // Loading models + // Loads message models $this->_ci->load->model('system/Message_model', 'MessageModel'); $this->_ci->load->model('system/MsgStatus_model', 'MsgStatusModel'); $this->_ci->load->model('system/Recipient_model', 'RecipientModel'); $this->_ci->load->model('system/Attachment_model', 'AttachmentModel'); + + // Loads extra models + $this->_ci->load->model('person/Person_model', 'PersonModel'); + $this->_ci->load->model('system/Benutzerrolle_model', 'BenutzerrolleModel'); + $this->_ci->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel'); + $this->_ci->load->model('organisation/Organisationseinheit_model', 'OrganisationseinheitModel'); } //------------------------------------------------------------------------------------------------------------------ // Public methods /** - * getMessage() - returns the specified received message for a specified person + * Returns the specified message for a specified person */ public function getMessage($msg_id, $person_id) { - if (!is_numeric($msg_id)) - return $this->_error('', MSG_ERR_INVALID_MSG_ID); - if (!is_numeric($person_id)) - return $this->_error('', MSG_ERR_INVALID_RECIPIENTS); + if (!is_numeric($msg_id)) return error('The given message id is not valid', MSG_ERR_INVALID_MSG_ID); + if (!is_numeric($person_id)) return error('The given person id is not valid', MSG_ERR_INVALID_RECIPIENTS); return $this->_ci->RecipientModel->getMessage($msg_id, $person_id); } /** - * getMessagesByUID() - will return all messages, including the latest status for specified user. It don´t returns Attachments. + * Sends a message to persons ($receiversPersonId) */ - public function getMessagesByUID($uid, $oe_kurzbz = null, $all = false) + public function sendMessageUser( + $receiversPersonId, $subject, $body, // Required parameters + $sender_id = null, $senderOU = null, $relationmessage_id = null, $priority = MSG_PRIORITY_NORMAL, $multiPartMime = true + ) { - if (isEmptyString($uid)) - return $this->_error('', MSG_ERR_INVALID_MSG_ID); + // Retrieves receiver id and checks that is valid + $receivers = $this->_getReceiversByPersonId($receiversPersonId); + if (isError($receivers)) return $receivers; - return $this->_ci->RecipientModel->getMessagesByUID($uid, $oe_kurzbz, $all); + // Send the message and return the result + return $this->_sendMessage($receivers, null, $subject, $body, $sender_id, $senderOU, $relationmessage_id, $priority, $multiPartMime); } /** - * getMessagesByPerson() - will return all messages, including the latest status for specified user. It don´t returns Attachments. + * Sends a message to persons ($receiversPersonId) */ - public function getMessagesByPerson($person_id, $oe_kurzbz = null, $all = false) + public function sendMessageUserTemplate( + $receiversPersonId, $vorlage, $parseData, // Required parameters + $orgform = null, $sender_id = null, $senderOU = null, $relationmessage_id = null, $priority = MSG_PRIORITY_NORMAL, $multiPartMime = true + ) { - if (!is_numeric($person_id)) - return $this->_error('', MSG_ERR_INVALID_MSG_ID); - - return $this->_ci->RecipientModel->getMessagesByPerson($person_id, $oe_kurzbz, $all); - } - - /** - * getSentMessagesByPerson() - Get all sent messages from a person identified by person_id - */ - public function getSentMessagesByPerson($person_id, $oe_kurzbz = null, $all = false) - { - if (!is_numeric($person_id)) - return $this->_error('', MSG_ERR_INVALID_MSG_ID); - - return $this->_ci->MessageModel->getMessagesByPerson($person_id, $oe_kurzbz, $all); - } - - /** - * getMessageByToken - */ - public function getMessageByToken($token) - { - if (isEmptyString($token)) - return $this->_error('', MSG_ERR_INVALID_TOKEN); - - $result = $this->_ci->RecipientModel->getMessageByToken($token); - if (hasData($result)) + // Loads template data + $templateResult = $this->_ci->vorlagelib->loadVorlagetext($vorlage, $senderOU, $orgform, getUserLanguage()); + if (hasData($templateResult)) // if a template is found { - // Searches for a status that is different from unread - $found = -1; - for ($i = 0; $i < count($result->retval); $i++) - { - if ($result->retval[$i]->status > MSG_STATUS_UNREAD) - { - $found = $i; - break; - } - } + $template = getData($templateResult)[0]; // template object - // If not found then insert the read status - if ($found == -1) - { - $statusKey = array( - 'message_id' => $result->retval[0]->message_id, - 'person_id' => $result->retval[0]->receiver_id, - 'status' => MSG_STATUS_READ - ); + // Parses template subject + $subject = parseText($template->subject, $parseData); + // Parses template text + $body = parseText($template->text, $parseData); - $resultIns = $this->_ci->MsgStatusModel->insert($statusKey); - // If an error occured while writing on data base, then return it - if (isError($resultIns)) - { - $result = $resultIns; - } - } - } - - return $result; - } - - /** - * getCountUnreadMessages - */ - public function getCountUnreadMessages($person_id, $oe_kurzbz = null) - { - if (!is_numeric($person_id)) - return $this->_error('', MSG_ERR_INVALID_RECIPIENTS); - - return $this->_ci->RecipientModel->getCountUnreadMessages($person_id, $oe_kurzbz); - } - - /** - * updateMessageStatus() - will change status on message for particular user - * NOTE: it performs an insert, NOT an update - */ - public function updateMessageStatus($message_id, $person_id, $status) - { - if (!is_numeric($message_id)) - { - return $this->_error('', MSG_ERR_INVALID_MSG_ID); - } - - if (!is_numeric($person_id)) - { - return $this->_error('', MSG_ERR_INVALID_USER_ID); - } - - // NOTE: Not use empty otherwise if status is 0 it returns an error - if (!isset($status)) - { - return $this->_error('', MSG_ERR_INVALID_STATUS_ID); - } - - // Searches if the status is already present - $result = $this->_ci->MsgStatusModel->load(array($message_id, $person_id, $status)); - if (hasData($result)) - { - // status already present - } - else - { - // Insert the new status - $statusKey = array( - 'message_id' => $message_id, - 'person_id' => $person_id, - 'status' => $status + return $this->sendMessageUser( + $receiversPersonId, $subject, $body, $sender_id, $senderOU, $relationmessage_id, $priority, $multiPartMime ); - - $result = $this->_ci->MsgStatusModel->insert($statusKey); } - - return $result; + elseif (isError($templateResult)) // if an error occured + { + return $templateResult; // return it + } + else // if a template was not found + { + return error('Template was not found', MSG_ERR_INVALID_TEMPLATE); + } } /** - * sendMessage() - sends new internal message. This function will create a new thread + * Sends a message to all the persons that are enabled to read messages for the given organisation unit ($receiversOU) */ - public function sendMessage($sender_id, $receiver_id, $subject, $body, $priority = PRIORITY_NORMAL, $relationmessage_id = null, $oe_kurzbz = null, $multiPartMime = true) + public function sendMessageOU( + $receiversOU, $subject, $body, // Required parameters + $sender_id = null, $senderOU = null, $relationmessage_id = null, $priority = MSG_PRIORITY_NORMAL, $multiPartMime = true + ) { - if (!is_numeric($sender_id)) - { - $sender_id = $this->_ci->config->item('system_person_id'); - } + // If the recipient is an organisation unit that would be possible to send the same message (same message id) + // to the entire organisation unit (one to many functionality) + // In this case the receiver id is a the one present in message configuration + $receivers = success(array($this->_ci->config->item(self::CFG_SYSTEM_PERSON_ID))); - $receivers = $this->_getReceivers($receiver_id, $oe_kurzbz); - - // If everything went ok - if (isSuccess($receivers) && is_array($receivers->retval)) - { - // If no receivers were found for this organization unit - if (count($receivers->retval) == 0) - { - $result = $this->_error($receivers->retval, MSG_ERR_OU_CONTACTS_NOT_FOUND); - } - - // Looping on receivers - for ($i = 0; $i < count($receivers->retval); $i++) - { - $receiver_id = $receivers->retval[$i]->person_id; - - // Checks if the receiver exists - if ($this->_checkReceiverId($receiver_id)) - { - // If the text and the subject of the template are not empty - if (!isEmptyString($subject) && !isEmptyString($body)) - { - $result = $this->_saveMessage($sender_id, $receiver_id, $subject, $body, $relationmessage_id, $oe_kurzbz); - // If no errors were occurred - // Leave the code commented - if (isSuccess($result)) - { - // If the system is configured to send messages immediately - if ($this->_ci->config->item('send_immediately') === true) - { - // Send message by email! - $resultSendEmail = $this->sendOne($result->retval, $subject, $body, $multiPartMime); - } - } - } - else - { - if (isEmptyString($subject)) - { - $result = $this->_error('', MSG_ERR_SUBJECT_EMPTY); - break; - } - elseif (isEmptyString($body)) - { - $result = $this->_error('', MSG_ERR_BODY_EMPTY); - break; - } - } - } - else - { - $result = $this->_error('', MSG_ERR_INVALID_RECEIVER_ID); - break; - } - } - } - // If there was some errors then copy them into the returning variable - else - { - $result = $receivers; - } - - return $result; + // Send the message and return the result + return $this->_sendMessage($receivers, $receiversOU, $subject, $body, $sender_id, $senderOU, $relationmessage_id, $priority, $multiPartMime); } - /** - * Sends new internal message using a template - */ - public function sendMessageVorlage($sender_id, $receiver_id, $vorlage_kurzbz, $oe_kurzbz, $data, $relationmessage_id = null, $orgform_kurzbz = null, $multiPartMime = true) - { - if (!is_numeric($sender_id)) - { - $sender_id = $this->_ci->config->item('system_person_id'); - } - - $receivers = $this->_getReceivers($receiver_id, $oe_kurzbz); - - // If everything went ok - if (isSuccess($receivers) && is_array($receivers->retval)) - { - // If no receivers were found for this organization unit - if (count($receivers->retval) == 0) - { - $result = $this->_error($receivers->retval, MSG_ERR_OU_CONTACTS_NOT_FOUND); - } - else - { - // Load reveiver data to get its relative language - $this->_ci->load->model('person/Person_model', 'PersonModel'); - } - - // Looping on receivers - for ($i = 0; $i < count($receivers->retval); $i++) - { - $receiver_id = $receivers->retval[$i]->person_id; - - // Checks if the receiver exists - $result = $this->_ci->PersonModel->load($receiver_id); - if (hasData($result)) - { - // Retrieves the language of the logged user - $sprache = getUserLanguage(); - - // Loads template data - $result = $this->_ci->vorlagelib->loadVorlagetext($vorlage_kurzbz, $oe_kurzbz, $orgform_kurzbz, $sprache); - if (isSuccess($result)) - { - // If the text and the subject of the template are not empty - if (is_array($result->retval) && count($result->retval) > 0 && - !isEmptyString($result->retval[0]->text) && !isEmptyString($result->retval[0]->subject)) - { - // Parses template text - $parsedText = $this->_ci->vorlagelib->parseVorlagetext($result->retval[0]->text, $data); - // Parses subject - $subject = $this->_ci->vorlagelib->parseVorlagetext($result->retval[0]->subject, $data); - - // Save message - $result = $this->_saveMessage($sender_id, $receiver_id, $subject, $parsedText, $relationmessage_id, $oe_kurzbz); - // If no errors were occurred - if (isSuccess($result)) - { - // If the system is configured to send messages immediately - if ($this->_ci->config->item('send_immediately') === true) - { - // Send message by email! - $resultSendEmail = $this->sendOne($result->retval, $subject, $parsedText, $multiPartMime); - } - } - } - else - { - // Better message error - if (!is_array($result->retval) || (is_array($result->retval) && count($result->retval) == 0)) - { - $result = $this->_error('', MSG_ERR_TEMPLATE_NOT_FOUND); - break; - } - elseif (is_array($result->retval) && count($result->retval) > 0) - { - if (is_null($result->retval[0]->oe_kurzbz)) - { - $result = $this->_error('', MSG_ERR_TEMPLATE_NOT_FOUND); - break; - } - elseif (isEmptyString($result->retval[0]->text)) - { - $result = $this->_error('', MSG_ERR_INVALID_TEMPLATE); - break; - } - elseif (isEmptyString($result->retval[0]->subject)) - { - $result = $this->_error('', MSG_ERR_INVALID_TEMPLATE); - break; - } - } - } - } - else - { - $result = $this->_error($result->retval, EXIT_ERROR); - break; - } - } - else - { - $result = $this->_error('', MSG_ERR_INVALID_RECEIVER_ID); - break; - } - } - } - // If there was some errors then copy them into the returning variable - else - { - $result = $receivers; - } - - return $result; - } + //------------------------------------------------------------------------------------------------------------------ + // Public methods called by a job /** * Gets all the messages from DB and sends them via email */ - public function sendAll($numberToSent = null, $numberPerTimeRange = null, $email_time_range = null, $email_from_system = null) + public function sendAllNotices($numberToSent = null, $numberPerTimeRange = null, $email_time_range = null, $email_from_system = null) { $sent = true; // optimistic expectation @@ -393,8 +159,7 @@ class MessageLib // Gets a number ($this->_ci->maillib->getMaxEmailToSent()) of unsent messages from DB // having EMAIL_KONTAKT_TYPE as relative contact type $result = $this->_ci->RecipientModel->getMessages( - EMAIL_KONTAKT_TYPE, - null, + self::EMAIL_KONTAKT_TYPE, $this->_ci->maillib->getConfigs()->email_number_to_sent ); // Checks if errors were occurred @@ -410,21 +175,20 @@ class MessageLib if ((!is_null($result->retval[$i]->receiver) && $result->retval[$i]->receiver != '') || (!is_null($result->retval[$i]->employeecontact) && $result->retval[$i]->employeecontact != '')) { - $href = $this->_ci->config->item('message_server').$this->_ci->config->item('message_html_view_url').$result->retval[$i]->token; + $href = $this->_ci->config->item(self::CFG_MESSAGE_SERVER).$this->_ci->config->item(self::CFG_MESSAGE_HTML_VIEW_URL).$result->retval[$i]->token; - $vorlage = $this->_ci->vorlagelib->loadVorlagetext('MessageMailHTML'); + $vorlage = $this->_ci->vorlagelib->loadVorlagetext(self::NOTICE_TEMPLATE_HTML); if(hasData($vorlage)) { // Using a template for the html email body - $body = $this->_ci->parser->parse_string( + $body = parseText( $vorlage->retval[0]->text, array( 'href' => $href, 'subject' => $result->retval[$i]->subject, 'body' => $result->retval[$i]->body - ), - true + ) ); } else @@ -445,18 +209,17 @@ class MessageLib $this->_ci->loglib->logError('Error while parsing the mail template'); } - $vorlage = $this->_ci->vorlagelib->loadVorlagetext('MessageMailTXT'); + $vorlage = $this->_ci->vorlagelib->loadVorlagetext(self::NOTICE_TEMPLATE_TXT); if(hasData($vorlage)) { // Using a template for the plain text email body - $altBody = $this->_ci->parser->parse_string( + $altBody = parseText( $vorlage->retval[0]->text, array( 'href' => $href, 'subject' => $result->retval[$i]->subject, 'body' => $result->retval[$i]->body - ), - true + ) ); } else @@ -506,7 +269,7 @@ class MessageLib { $this->_ci->loglib->logError('Error while sending an email'); // Writing errors in tbl_msg_recipient - $sme = $this->setMessageError( + $sme = $this->_setSentError( $result->retval[$i]->message_id, $result->retval[$i]->receiver_id, 'Error while sending an email', @@ -520,7 +283,7 @@ class MessageLib else { // Setting the message as sent in DB - $sent = $this->setMessageSent($result->retval[$i]->message_id, $result->retval[$i]->receiver_id); + $sent = $this->_setSentSuccess($result->retval[$i]->message_id, $result->retval[$i]->receiver_id); // If some errors occurred if (!$sent) { @@ -532,7 +295,7 @@ class MessageLib { $this->_ci->loglib->logError('This person does not have an email account'); // Writing errors in tbl_msg_recipient - $sme = $this->setMessageError( + $sme = $this->_setSentError( $result->retval[$i]->message_id, $result->retval[$i]->receiver_id, 'This person does not have an email account', @@ -561,244 +324,51 @@ class MessageLib return $sent; } - /** - * Gets one message from DB and sends it via email - */ - public function sendOne($message_id, $subject = null, $body = null, $multiPartMime = true) - { - $sent = true; // optimistic expectation - - // Get a specific message from DB having EMAIL_KONTAKT_TYPE as relative contact type - $result = $this->_ci->RecipientModel->getMessages( - EMAIL_KONTAKT_TYPE, - null, - null, - $message_id - ); - - // Checks if errors were occurred - if (isSuccess($result)) - { - // If data are present - if (is_array($result->retval) && count($result->retval) > 0) - { - // If the person has an email account - if ((!is_null($result->retval[0]->receiver) && $result->retval[0]->receiver != '') - || (!is_null($result->retval[0]->employeecontact) && $result->retval[0]->employeecontact != '')) - { - // If it is required use a multi-part message in MIME format - if ($multiPartMime === true) - { - // Using a template for the html email body - $href = $this->_ci->config->item('message_server').$this->_ci->config->item('message_html_view_url').$result->retval[0]->token; - - $vorlage = $this->_ci->vorlagelib->loadVorlagetext('MessageMailHTML'); - if(hasData($vorlage)) - { - $bodyMsg = $this->_ci->parser->parse_string( - $vorlage->retval[0]->text, - array( - 'href' => $href, - 'subject' => $result->retval[0]->subject, - 'body' => $result->retval[0]->body - ), - true - ); - } - else - { - $bodyMsg = $this->_ci->parser->parse( - 'templates/mailHTML', - array( - 'href' => $href, - 'subject' => $result->retval[0]->subject, - 'body' => $result->retval[0]->body - ), - true - ); - } - if (is_null($bodyMsg) || $bodyMsg == '') - { - // $body = $result->retval[0]->body; - $this->_ci->loglib->logError('Error while parsing the html mail template'); - } - - // Using a template for the plain text email body - $vorlage = $this->_ci->vorlagelib->loadVorlagetext('MessageMailTXT'); - if(hasData($vorlage)) - { - $altBody = $this->_ci->parser->parse_string( - $vorlage->retval[0]->text, - array( - 'href' => $href, - 'subject' => $result->retval[0]->subject, - 'body' => $result->retval[0]->body - ), - true - ); - } - else - { - $altBody = $this->_ci->parser->parse( - 'templates/mailTXT', - array( - 'href' => $href, - 'subject' => $result->retval[0]->subject, - 'body' => $result->retval[0]->body - ), - true - ); - } - if (is_null($altBody) || $altBody == '') - { - $this->_ci->loglib->logError('Error while parsing the plain text mail template'); - } - } - else - { - $bodyMsg = $altBody = $body; - } - - // If the sender is not an employee, then system-sender is used if empty - $sender = ''; - if (!is_null($result->retval[0]->senderemployeecontact) && $result->retval[0]->senderemployeecontact != '') - { - $sender = $result->retval[0]->senderemployeecontact.'@'.DOMAIN; - } - - $receiverContact = $result->retval[0]->receiver; - if (!is_null($result->retval[0]->employeecontact) && $result->retval[0]->employeecontact != '') - { - $receiverContact = $result->retval[0]->employeecontact.'@'.DOMAIN; - } - - // Sending email - $sent = $this->_ci->maillib->send( - null, - $receiverContact, - is_null($subject) ? $result->retval[0]->subject : $subject, // if parameter subject is not null, use it! - $bodyMsg, - null, - null, - null, - $altBody - ); - // If errors were occurred while sending the email - if (!$sent) - { - $this->_ci->loglib->logError('Error while sending an email'); - // Writing errors in tbl_msg_recipient - $sme = $this->setMessageError( - $result->retval[0]->message_id, - $result->retval[0]->receiver_id, - 'Error while sending an email', - $result->retval[0]->sentinfo - ); - if (!$sme) - { - $this->_ci->loglib->logError('Error while updating DB'); - } - } - else - { - // Setting the message as sent in DB - $sent = $this->setMessageSent($result->retval[0]->message_id, $result->retval[0]->receiver_id); - // If the email has been sent and the DB updated - if (!$sent) - { - $this->_ci->loglib->logError('Error while updating DB'); - } - } - } - else - { - $this->_ci->loglib->logError('This person does not have an email account'); - // Writing errors in tbl_msg_recipient - $sme = $this->setMessageError( - $result->retval[0]->message_id, - $result->retval[0]->receiver_id, - 'This person does not have an email account', - $result->retval[0]->sentinfo - ); - if (!$sme) - { - $this->_ci->loglib->logError('Error while updating DB'); - } - $sent = true; // Non blocking error - } - } - else - { - $this->_ci->loglib->logInfo('There are no email to be sent'); - $sent = false; - } - } - else - { - $this->_ci->loglib->logError('Something went wrong while getting data from DB'); - $sent = false; - } - - return $sent; - } + //------------------------------------------------------------------------------------------------------------------ + // Public methods used by to build the GUI to write messages to user/s /** - * parseMessageText - */ - public function parseMessageText($text, $data = array()) - { - return $this->_ci->parser->parse_string($text, $data, true); - } - - /** - * Gets data for Person from view vw_msg_vars_person - * @param $person_id + * Retrieves message vars from view vw_msg_vars_person */ public function getMessageVarsPerson() { - $variablesArray = array(); + // Retrieves message vars from view vw_msg_vars_person + $messageVarsPerson = $this->_ci->MessageModel->getMessageVarsPerson(); + if (isSuccess($messageVarsPerson)) // if everything is ok + { + $variablesArray = array(); + $tmpVariablesArray = getData($messageVarsPerson); - $variables = $this->_ci->MessageModel->getMessageVarsPerson(); - if (isError($variables)) - { - return $variables; - } - elseif (hasData($variables)) - { - $tmpVariablesArray = getData($variables); - // Skip person_id + // Starts from 1 to skip the first element which is person_id for ($i = 1; $i < count($tmpVariablesArray); $i++) { $variablesArray['{'.str_replace(' ', '_', strtolower($tmpVariablesArray[$i])).'}'] = $tmpVariablesArray[$i]; } + + return success($variablesArray); } - return success($variablesArray); + return $messageVarsPerson; // otherwise returns the error } /** - * A person may belongs to more organisation units + * Retrieves organisation units for each role that a user plays inside that organisation unit */ public function getOeKurzbz($sender_id) { - $oe_kurzbz = array(); - - $this->_ci->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel'); - + // Retrieves organisation units for a user from database $benutzer = $this->_ci->BenutzerfunktionModel->getByPersonId($sender_id); - if (isError($benutzer)) - { - return $benutzer; - } - elseif (hasData($benutzer)) + if (isSuccess($benutzer)) // if everything is ok { - foreach (getData($benutzer) as $val) - { - $oe_kurzbz[] = $val->oe_kurzbz; - } + $ouArray = array(); + + // Copies organisation units in $ouArray array + foreach (getData($benutzer) as $val) $ouArray[] = $val->oe_kurzbz; + + return success($ouArray); } - return success($oe_kurzbz); + return $benutzer; // otherwise returns the error } /** @@ -806,55 +376,172 @@ class MessageLib */ public function getIsAdmin($sender_id) { - $this->_ci->load->model('system/Benutzerrolle_model', 'BenutzerrolleModel'); - return $this->_ci->BenutzerrolleModel->isAdminByPersonId($sender_id); } + //------------------------------------------------------------------------------------------------------------------ + // Public methods used by REST API + + /** + * Return all messages, including the latest status for specified user. It don´t returns Attachments. + * The sender organisation unit may be specified to filter messages + */ + public function getMessagesByUID($uid, $senderOU = null, $all = false) + { + if (isEmptyString($uid)) return error('The given message id is not valid', MSG_ERR_INVALID_MSG_ID); + + return $this->_ci->RecipientModel->getMessagesByUID($uid, $senderOU, $all); + } + + /** + * Return all messages, including the latest status for specified user. It does not return attachments + * The sender organisation unit may be specified to filter messages + */ + public function getMessagesByPerson($person_id, $senderOU = null, $all = false) + { + if (!is_numeric($person_id)) return error('The given message id is not valid', MSG_ERR_INVALID_MSG_ID); + + return $this->_ci->RecipientModel->getMessagesByPerson($person_id, $senderOU, $all); + } + + /** + * Get all sent messages from a person identified by person_id + * The sender organisation unit may be specified to filter messages + */ + public function getSentMessagesByPerson($person_id, $senderOU = null, $all = false) + { + if (!is_numeric($person_id)) return error('The given message id is not valid', MSG_ERR_INVALID_MSG_ID); + + return $this->_ci->MessageModel->getMessagesByPerson($person_id, $senderOU, $all); + } + + /** + * Retrieves a message by its token + * If a message is found with the given token then this message is set as read + */ + public function getMessageByToken($token) + { + if (isEmptyString($token)) return error('The given token is not valid', MSG_ERR_INVALID_TOKEN); + + $result = $this->_ci->RecipientModel->getMessageByToken($token); + if (hasData($result)) + { + // Searches for a status that is NOT unread + $found = false; + + foreach (getData($result) as $message) + { + if ($message->status > MSG_STATUS_UNREAD) + { + $found = true; + break; + } + } + + // If NOT found then insert the read status + if (!$found) + { + $statusData = array( + 'message_id' => getData($result)[0]->message_id, + 'person_id' => getData($result)[0]->receiver_id, + 'status' => MSG_STATUS_READ + ); + + $resultIns = $this->_ci->MsgStatusModel->insert($statusData); + // If an error occured while writing on data base, then return it + if (isError($resultIns)) $result = $resultIns; + } + } + + return $result; + } + + /** + * Counts the unread messages for the given user + * The sender organisation unit may be specified to filter messages + */ + public function getCountUnreadMessages($person_id, $senderOU = null) + { + if (!is_numeric($person_id)) return error('The given person id is not valid', MSG_ERR_INVALID_RECIPIENTS); + + return $this->_ci->RecipientModel->getCountUnreadMessages($person_id, $senderOU); + } + + /** + * Change the message status of the given message specified by message_id and person_id, using the given status + * NOTE: it performs an insert NOT an update + */ + public function updateMessageStatus($message_id, $person_id, $status) + { + if (!is_numeric($message_id)) return error('The given message id is not valid', MSG_ERR_INVALID_MSG_ID); + if (!is_numeric($person_id)) return error('The given person id is not valid', MSG_ERR_INVALID_RECIPIENTS); + if (!is_numeric($status)) return error('The given status is not valid', MSG_ERR_INVALID_STATUS_ID); + + $this->_ci->MsgStatusModel->resetQuery(); // Reset an eventually already buit query + + // Searches if the status is already present + $result = $this->_ci->MsgStatusModel->load(array($message_id, $person_id, $status)); + if (!hasData($result)) // if not found + { + // Insert the new status + $statusKey = array( + 'message_id' => $message_id, + 'person_id' => $person_id, + 'status' => $status + ); + $result = $this->_ci->MsgStatusModel->insert($statusKey); + } + + return $result; + } + //------------------------------------------------------------------------------------------------------------------ // Private methods /** - * Update the table tbl_msg_recipient + * */ - private function _updateMessageRecipient($message_id, $receiver_id, $parameters) + private function _getSender($sender_id) { - $updated = false; - - // Updates table tbl_msg_recipient - $resultUpdate = $this->_ci->RecipientModel->update(array($receiver_id, $message_id), $parameters); - // Checks if errors were occurred - if (isSuccess($resultUpdate) && is_array($resultUpdate->retval)) + // By default the sender is defined in message configuration + $sender = success($this->_ci->config->item(self::CFG_SYSTEM_PERSON_ID)); + if ($sender_id != null) // if it was given as parameter { - $updated = true; + if (is_numeric($sender_id)) // if it valid -> it is a number + { + $sender = success($sender_id); // return it as a success object + } + else + { + // Otherwise returns an error + $sender = error('The given sender is not valid', MSG_ERR_INVALID_SENDER); + } } - return $updated; + return $sender; } /** - * Changes the status of the message from unsent to sent + * Checks if the given receiver ids belong to persons in database */ - private function setMessageSent($message_id, $receiver_id) + private function _getReceiversByPersonId($receiver_id) { - $parameters = array('sent' => 'NOW()', 'sentinfo' => null); + // Reset an eventually already buit query + $this->_ci->PersonModel->resetQuery(); - return $this->_updateMessageRecipient($message_id, $receiver_id, $parameters); - } + // Get only this columns + $this->_ci->PersonModel->addSelect('person_id'); - /** - * Sets the sentInfo with the error - */ - private function setMessageError($message_id, $receiver_id, $sentInfo, $prevSentInfo = null) - { - if (!is_null($prevSentInfo) && $prevSentInfo != '') + // Loads from database the person by its person_id + $personResult = $this->_ci->PersonModel->load($receiver_id); + if (hasData($personResult)) // if data are retrieved { - $sentInfo = $prevSentInfo.SENT_INFO_NEWLINE.$sentInfo; + return $personResult; // return them + } + else // otherwise an error occurred (blocking error or data not found) + { + return error('The given person id is not valid', MSG_ERR_INVALID_RECIPIENTS); } - - $parameters = array('sent' => null, 'sentinfo' => $sentInfo); - - return $this->_updateMessageRecipient($message_id, $receiver_id, $parameters); } /** @@ -869,92 +556,49 @@ class MessageLib // Get all the valid receivers id using the oe_kurzbz $receivers = $this->_ci->BenutzerfunktionModel->loadWhere( 'oe_kurzbz = '.$this->_ci->db->escape($oe_kurzbz). - ' AND funktion_kurzbz = '.$this->_ci->db->escape($this->_ci->config->item('assistent_function')). + ' AND funktion_kurzbz = '.$this->_ci->db->escape($this->_ci->config->item(self::CFG_OU_RECEIVERS)). ' AND (NOW() BETWEEN COALESCE(datum_von, NOW()) AND COALESCE(datum_bis, NOW()))' ); - return $receivers; } /** - * Gets the receivers id + * Save a new message in DB */ - private function _getReceivers($receiver_id, $oe_kurzbz = null) + private function _saveMessage($sender_id, $senderOU, $receiver_id, $receiverOU, $subject, $body, $priority, $relationmessage_id) { - $receivers = null; - - // If no receiver_id is given... - if (is_null($receiver_id)) - { - // ...a oe_kurzbz must be specified - if (is_null($oe_kurzbz)) - { - $receivers = $this->_error('', MSG_ERR_INVALID_OU); - } - else - { - $receivers = $this->_getReceiversByOekurzbz($oe_kurzbz); - } - } - // Else if the receiver id is given - else - { - $receivers = $this->_success(array(new stdClass())); - $receivers->retval[0]->person_id = $receiver_id; - } - - return $receivers; - } - - /** - * Checks if the given receiver id is a valid person - */ - private function _checkReceiverId($receiver_id) - { - // Load Person_model - $this->_ci->load->model('person/Person_model', 'PersonModel'); - $result = $this->_ci->PersonModel->load($receiver_id); - if (hasData($result)) - { - return true; - } - - return false; - } - - /** - * Save a message in DB - **/ - private function _saveMessage($sender_id, $receiver_id, $subject, $body, $relationmessage_id, $oe_kurzbz) - { - // Starts db transaction + // Starts database transaction $this->_ci->db->trans_start(false); - // Save Message - $msgData = array( + // Store message information in tbl_msg_message + $messageData = array( 'person_id' => $sender_id, 'subject' => $subject, 'body' => $body, - 'priority' => PRIORITY_NORMAL, + 'priority' => $priority, 'relationmessage_id' => $relationmessage_id, - 'oe_kurzbz' => $oe_kurzbz + 'oe_kurzbz' => $senderOU ); - $result = $this->_ci->MessageModel->insert($msgData); + + $result = $this->_ci->MessageModel->insert($messageData); if (isSuccess($result)) { - // Link the message with the receiver - $msg_id = $result->retval; + $messageId = getData($result); // Gets the message id generated by database + + // Store message information in tbl_msg_recipient $recipientData = array( 'person_id' => $receiver_id, - 'message_id' => $msg_id, - 'token' => generateToken() + 'message_id' => $messageId, + 'token' => generateToken(), + 'oe_kurzbz' => $receiverOU ); + $result = $this->_ci->RecipientModel->insert($recipientData); if (isSuccess($result)) { - // Save message status + // Store message information in tbl_msg_status $statusData = array( - 'message_id' => $msg_id, + 'message_id' => $messageId, 'person_id' => $receiver_id, 'status' => MSG_STATUS_UNREAD ); @@ -962,35 +606,262 @@ class MessageLib } } - $this->_ci->db->trans_complete(); + $this->_ci->db->trans_complete(); // Ends database transaction + // If the transaction failed... if ($this->_ci->db->trans_status() === false || isError($result)) { - $this->_ci->db->trans_rollback(); - $result = $this->_error('An error occurred while saving a message', EXIT_ERROR); + $this->_ci->db->trans_rollback(); // ...then rollback } - else + else // otherwise commit... { $this->_ci->db->trans_commit(); - $result = $this->_success($msg_id); + $result = success($messageId); // ...and returns the message id } return $result; } /** - * Wrapper for function error + * Set the message as sent successfully by setting columns 'sent' and 'sentinfo' of table tbl_msg_recipient + * sent column is set with date of delivery + * sentinfo is set to null */ - private function _error($retval, $code) + private function _setSentSuccess($message_id, $receiver_id) { - return error($retval, $code); + return $this->_ci->RecipientModel->update(array($receiver_id, $message_id), array('sent' => 'NOW()', 'sentinfo' => null)); } /** - * Wrapper for function success + * Set the message as sent with error by setting columns 'sent' and 'sentinfo' of table tbl_msg_recipient + * Stores the type of error in 'sentinfo' column keeping en eventual previous error + * sent column is set to null */ - private function _success($retval, $code = null) + private function _setSentError($message_id, $receiver_id, $sentInfo, $prevSentInfo) { - return success($retval, $code); + if (!isEmptyString($prevSentInfo)) + { + $sentInfo .= self::SENT_INFO_NEWLINE.$prevSentInfo; + } + + return $this->_ci->RecipientModel->update(array($receiver_id, $message_id), array('sent' => null, 'sentinfo' => $sentInfo)); + } + + /** + * Returns the notice body. Tries to use the template present in database and then falling back + * on the one present in filesystem. If both fail then an error is returned + */ + private function _getNoticeBody($viewMessageLink, $subject, $body, $dbTemplateName, $fsTemplateName) + { + $noticeBody = null; + + $vorlageResult = $this->_ci->vorlagelib->loadVorlagetext($dbTemplateName); + + if (isError($vorlageResult)) return $vorlageResult; + + if (hasData($vorlageResult)) + { + $vorlage = getData($vorlageResult)[0]; + + $noticeBody = parseText( + $vorlage->text, + array( + 'href' => $viewMessageLink, + 'subject' => $subject, + 'body' => $body + ) + ); + } + else + { + $noticeBody = parseTemplate( + $fsTemplateName, + array( + 'href' => $viewMessageLink, + 'subject' => $subject, + 'body' => $body + ) + ); + } + + if (isEmptyString($noticeBody)) return error('An error occurred while generating the notice body'); + + return success($noticeBody); + } + + /** + * Returns the notice HTML body try to using the template present in database and then falling back + * on the one present in filesystem. If both fail then an error is returned + */ + private function _getNoticeHTMLBody($viewMessageLink, $subject, $body) + { + return $this->_getNoticeBody($viewMessageLink, $subject, $body, self::NOTICE_TEMPLATE_HTML, self::NOTICE_TEMPLATE_FALLBACK_HTML); + } + + /** + * Returns the notice TXT body try to using the template present in database and then falling back + * on the one present in filesystem. If both fail then an error is returned + */ + private function _getNoticeTXTBody($viewMessageLink, $subject, $body) + { + return $this->_getNoticeBody($viewMessageLink, $subject, $body, self::NOTICE_TEMPLATE_TXT, self::NOTICE_TEMPLATE_FALLBACK_TXT); + } + + /** + * Sends a notice email that notices to a user about a new received message + */ + private function _sendNotice($message_id) + { + // Get the message and related data (sender, recipient, etc...) + $messageResult = $this->_ci->RecipientModel->getMessages( + self::EMAIL_KONTAKT_TYPE, + 1, + $message_id + ); + + 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 + + $messageData = getData($messageResult)[0]; // Message data from database + + // Checks if this person has a valid email address where to send the notice email + if (isEmptyString($messageData->receiver) && isEmptyString($messageData->employeecontact)) + { + // Set in database why this email is NOT going to be send + $sse = $this->_setSentError( + $message_id, + $messageData->receiver_id, + 'This person does not have an email account', + $messageData->sentinfo + ); + + // If database error occurred then return it, otherwise return a logic error + return isError($sse) ? $sse : error('This person does not have an email account'); + } + + // Create a link to the controller to view the message using a token + $viewMessageLink = $this->_ci->config->item(self::CFG_MESSAGE_SERVER). + $this->_ci->config->item(self::CFG_MESSAGE_HTML_VIEW_URL). + $messageData->token; + + // Generates notice email body in HTML and plain text version. + // If an error occured during the generation then the error itself is returned + $noticeHTMLBody = $this->_getNoticeHTMLBody($viewMessageLink, $messageData->subject, $messageData->body); + if (isError($noticeHTMLBody)) return $noticeHTMLBody; + $noticeTXTBody = $this->_getNoticeTXTBody($viewMessageLink, $messageData->subject, $messageData->body); + if (isError($noticeTXTBody)) return $noticeTXTBody; + + // If an employeecontact contact is present then use it, otherwise use the personal contacts + $receiverContact = $messageData->receiver; + if (!isEmptyString($messageData->employeecontact)) $receiverContact = $messageData->employeecontact.'@'.DOMAIN; + + // Sending email + $sent = $this->_ci->maillib->send( + null, + $receiverContact, + $messageData->subject, + getData($noticeHTMLBody), + null, + null, + null, + getData($noticeTXTBody) + ); + + // If errors occurred while sending the email + if (!$sent) + { + // Set in database why this email is NOT going to be send + $sse = $this->_setSentError( + $message_id, + $messageData->receiver_id, + 'An error occurred while sending the email', + $messageData->sentinfo + ); + + // If database error occurred then return it, otherwise return a logic error + return isError($sse) ? $sse : error('An error occurred while sending the email'); + } + else // success! + { + // Set in database that the notice email was succesfully sent + $sss = $this->_setSentSuccess($message_id, $messageData->receiver_id); + if (isError($sss)) return $sss; // If database error occurred then return it + } + + return success('Notice email sent successfully'); + } + + /** + * Sends new message core method, may be wrapped by other methods. + */ + private function _sendMessage( + $receivers, $receiversOU, $subject, $body, $sender_id, $senderOU, $relationmessage_id, $priority, $multiPartMime + ) + { + // Checks if sender is fine + $sender = $this->_getSender($sender_id); + if (!hasData($sender)) return $sender; + // Checks if the sender and receiver organisation unit are valid + if (($receiversOU != null && !$this->_ouExists($receiversOU)) || ($senderOU != null && !$this->_ouExists($senderOU))) + { + return error('The given organisation unit is not valid', MSG_ERR_INVALID_OU); + } + // Checks subjects + if (isEmptyString($subject)) return error('The given subject is an empty string', MSG_ERR_INVALID_SUBJECT); + // Checks body + if (isEmptyString($body)) return error('The given body is an empty string', MSG_ERR_INVALID_BODY); + + $savedMessages = array(); // This array contains all the message ids of the saved messages + + // Looping on receivers + foreach (getData($receivers) as $receiver) + { + // Save message in database + $saveMessageResult = $this->_saveMessage( + getData($sender), $senderOU, $receiver->person_id, $receiversOU, $subject, $body, $priority, $relationmessage_id + ); + if (isSuccess($saveMessageResult)) // If successfully saved + { + // If the system is configured to send messages immediately + if ($this->_ci->config->item(self::CFG_SEND_IMMEDIATELY) === true) + { + $savedMessages[] = getData($saveMessageResult); // store the message id of the saved message + } + } + else + { + return $saveMessageResult; // If an error occured while saving + } + } + + // If the system is configured to send messages immediately + if ($this->_ci->config->item(self::CFG_SEND_IMMEDIATELY) === true) + { + // Looping through saved messages ids + foreach ($savedMessages as $message_id) + { + // Send message notice via email! + $sendNotice = $this->_sendNotice($message_id); + // If an error occurred then return it + if (isError($sendNotice)) return $sendNotice; + } + } + + return success('Message sent successfully'); + } + + /** + * Checks if the given organisation unit exists in database + */ + private function _ouExists($ou) + { + // Reset an eventually already buit query + $this->_ci->OrganisationseinheitModel->resetQuery(); + // Get only this columns + $this->_ci->OrganisationseinheitModel->addSelect('oe_kurzbz'); + // Retrieves the given organisation unit from database + $ouResults = $this->_ci->OrganisationseinheitModel->loadWhere(array('oe_kurzbz' => $ou)); + + return hasData($ouResults); } } diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index 5f3f40e6d..c17d608c7 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -38,19 +38,29 @@ class Messages_model extends CI_Model $sender_id = getData($authUser)[0]->person_id; + // Send message(s) if (hasData($msgVarsData)) { for ($i = 0; $i < count(getData($msgVarsData)); $i++) { - $parsedText = ""; + $parsedText = ''; $msgVarsDataArray = $this->replaceKeys((array)getData($msgVarsData)[$i]); // replaces array keys // Send without vorlage if (isEmptyString($vorlage_kurzbz)) { - $parsedText = $this->messagelib->parseMessageText($body, $msgVarsDataArray); - $msg = $this->messagelib->sendMessage($sender_id, $msgVarsDataArray['person_id'], $subject, $parsedText, PRIORITY_NORMAL, $relationmessage_id, $oe_kurzbz); + $parsedText = parseText($body, $msgVarsDataArray); + + $msg = $this->messagelib->sendMessageUser( + $msgVarsDataArray['person_id'], // receiverPersonId + $subject, // subject + $parsedText, // body + $sender_id, // sender_id + $oe_kurzbz, // senderOU + $relationmessage_id, // relationmessage_id + MSG_PRIORITY_NORMAL // priority + ); } // Send with vorlage else @@ -63,7 +73,15 @@ class Messages_model extends CI_Model $msgVarsDataArray[$key] = $msgvar; } } - $msg = $this->messagelib->sendMessageVorlage($sender_id, $msgVarsDataArray['person_id'], $vorlage_kurzbz, $oe_kurzbz, $msgVarsDataArray); + + $msg = $this->messagelib->sendMessageUserTemplate( + $msgVarsDataArray['person_id'], // receiversPersonId + $vorlage_kurzbz, // vorlage + $msgVarsDataArray, // parseData + null, // orgform + $sender_id, // sender_id + $oe_kurzbz // senderOU + ); } if (isError($msg)) return $msg; @@ -95,7 +113,7 @@ class Messages_model extends CI_Model } /** - * Send a reply + * Send a reply to a message accessed using a token */ public function sendReply($subject, $body, $persons, $relationmessage_id, $token) { @@ -116,7 +134,16 @@ class Messages_model extends CI_Model { $dataArray = (array)getData($data)[$i]; - $msg = $this->messagelib->sendMessage($sender_id, $dataArray['person_id'], $subject, $body, PRIORITY_NORMAL, $relationmessage_id, null); + $msg = $this->messagelib->sendMessageUser( + $dataArray['person_id'], // receiverPersonId + $subject, // subject + $body, // body + $sender_id, // sender_id + null, // senderOU + $relationmessage_id, // relationmessage_id + MSG_PRIORITY_NORMAL // priority + ); + if (isError($msg)) return $msg; // Logs person data diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 74a1c3256..49fc21fc4 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -242,7 +242,7 @@ class Recipient_model extends DB_Model if (is_numeric($message_id)) { array_push($parametersArray, $message_id); - $query .= ' AND mm.message_id = ?'; + $query .= ' WHERE mm.message_id = ?'; } $query .= ' ORDER BY mr.insertamum ASC'; From 0ef94aacdad9545edc20a160d36d70753e8852f4 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 13 Jun 2019 18:23:24 +0200 Subject: [PATCH 04/72] - Fixed query method getMessages in model models/system/Recipient_model.php - Changed interface method sendMessages of job jobs/MailJob.php - Added function terminateWithError to helper helpers/hlp_common_helper.php - Changed method overrideConfigs of library MailLib - Removed method getConfigs from library MailLib - Added public method getEmailNumberToSent to library MailLib - Changed method sendAllNotices of library MessageLib - Renamed private method _sendNotice to _sendOneNotice in library MessageLib - Added new private methods _loadDbNoticeEmailTemplate, _loadFsNoticeEmailTemplate and _sendNotice to library MessageLib - Changed method _getNoticeBody in library MessageLib - Removed methods _getNoticeHTMLBody and _getNoticeTXTBody from in library MessageLib --- application/controllers/jobs/MailJob.php | 4 +- application/helpers/hlp_common_helper.php | 22 + application/libraries/MailLib.php | 47 +- application/libraries/MessageLib.php | 444 ++++++------------ application/models/system/Recipient_model.php | 11 +- 5 files changed, 202 insertions(+), 326 deletions(-) diff --git a/application/controllers/jobs/MailJob.php b/application/controllers/jobs/MailJob.php index cb5ffc032..721db0068 100644 --- a/application/controllers/jobs/MailJob.php +++ b/application/controllers/jobs/MailJob.php @@ -31,8 +31,8 @@ class MailJob extends CLI_Controller * Send all not sent messages * Parameters are used to overrride messages and mail configuration */ - public function sendMessages($numberToSent = null, $numberPerTimeRange = null, $email_time_range = null, $email_from_system = null) + public function sendMessages($numberToSent = null, $numberPerTimeRange = null, $emailTimeRange = null, $emailFromSystem = null) { - $this->messagelib->sendAllNotices($numberToSent, $numberPerTimeRange, $email_time_range, $email_from_system); + $this->messagelib->sendAllNotices($numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem); } } diff --git a/application/helpers/hlp_common_helper.php b/application/helpers/hlp_common_helper.php index 025834ed2..dbd8eb905 100644 --- a/application/helpers/hlp_common_helper.php +++ b/application/helpers/hlp_common_helper.php @@ -263,3 +263,25 @@ function parseTemplate($template, $data) return $ci->parser->parse($template, $data, true); } + +/** + * Terminate immediately the execution of the current script. + * If message parameter is given then: + * - logs the given message in CI logs + * - prints the given message to standard output + * Otherwise terminate with the generic error + */ +function terminateWithError($message = null) +{ + if (!isEmptyString($message)) + { + $ci =& get_instance(); // get CI instance + $ci->load->library('LogLib'); // Loads LogLib + + $ci->loglib->logError($message); + + exit($message); + } + + exit(EXIT_ERROR); +} diff --git a/application/libraries/MailLib.php b/application/libraries/MailLib.php index 6d0a48f73..e9e571f6c 100644 --- a/application/libraries/MailLib.php +++ b/application/libraries/MailLib.php @@ -110,43 +110,34 @@ class MailLib } /** - * To ovveride the configurations + * Overrides configuration parameters + * If the given parameters are not null or empty strings then they are used to override + * the following properties of this object: + * - email_number_to_sent + * - email_number_per_time_range + * - email_time_range + * - email_from_system */ - public function overrideConfigs($cfg) + public function overrideConfigs($numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem) { - if (!is_null($cfg)) + if (is_numeric($numberToSent)) $this->email_number_to_sent = $numberToSent; + + if (is_numeric($numberPerTimeRange)) $this->email_number_per_time_range = $numberPerTimeRange; + + if (is_numeric($emailTimeRange)) $this->email_time_range = $emailTimeRange; + + if (!isEmptyString($emailFromSystem) && filter_var($emailFromSystem, FILTER_VALIDATE_EMAIL)) { - if (isset($cfg->email_number_to_sent) && is_numeric($cfg->email_number_to_sent)) - { - $this->email_number_to_sent = $cfg->email_number_to_sent; - } - if (isset($cfg->email_number_per_time_range) && is_numeric($cfg->email_number_per_time_range)) - { - $this->email_number_per_time_range = $cfg->email_number_per_time_range; - } - if (isset($cfg->email_time_range) && is_numeric($cfg->email_time_range)) - { - $this->email_time_range = $cfg->email_time_range; - } - if (isset($cfg->email_from_system) && filter_var($cfg->email_from_system, FILTER_VALIDATE_EMAIL)) - { - $this->email_from_system = $cfg->email_from_system; - } + $this->email_from_system = $emailFromSystem; } } /** - * Returns the current configuration + * Returns value of property email_number_to_sent */ - public function getConfigs() + public function getEmailNumberToSent() { - $cfg = new stdClass(); - $cfg->email_number_to_sent = $this->email_number_to_sent; - $cfg->email_number_per_time_range = $this->email_number_per_time_range; - $cfg->email_time_range = $this->email_time_range; - $cfg->email_from_system = $this->email_from_system; - - return $cfg; + return $this->email_number_to_sent; } /** diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 7911d4b2d..c3c1169d4 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -36,8 +36,6 @@ class MessageLib // Loads message configuration $this->_ci->config->load('message'); - // Loads LogLib - $this->_ci->load->library('LogLib'); // Loads VorlageLib $this->_ci->load->library('VorlageLib'); // Loads Mail library @@ -140,188 +138,27 @@ class MessageLib // Public methods called by a job /** - * Gets all the messages from DB and sends them via email + * Gets all NOT sent messages from DB and sends for each of them the notice email + * Does not return anything, it logs info and errors on CI logs and in tbl_msg_recipient table + * Wrapper for _sendNotice. */ - public function sendAllNotices($numberToSent = null, $numberPerTimeRange = null, $email_time_range = null, $email_from_system = null) + public function sendAllNotices($numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem) { - $sent = true; // optimistic expectation + // Overrides MailLib configs with the given parameters + $this->_ci->maillib->overrideConfigs($numberToSent, $numberPerTimeRange, $emailTimeRange, $emailFromSystem); - // Gets standard configs - $cfg = $this->_ci->maillib->getConfigs(); - $cfg->email_number_to_sent = $numberToSent; - $cfg->email_number_per_time_range = $numberPerTimeRange; - $cfg->email_time_range = $email_time_range; - $cfg->email_from_system = $email_from_system; - - // Overrides configs with the parameters - $this->_ci->maillib->overrideConfigs($cfg); - - // Gets a number ($this->_ci->maillib->getMaxEmailToSent()) of unsent messages from DB - // having EMAIL_KONTAKT_TYPE as relative contact type - $result = $this->_ci->RecipientModel->getMessages( + // Retrieves a certain amount of NOT sent messages, the amount is given by maillib->email_number_to_sent + $messagesResult = $this->_ci->RecipientModel->getMessages( self::EMAIL_KONTAKT_TYPE, - $this->_ci->maillib->getConfigs()->email_number_to_sent + null, + $this->_ci->maillib->getEmailNumberToSent() ); - // Checks if errors were occurred - if (isSuccess($result)) - { - // If data are present - if (is_array($result->retval) && count($result->retval) > 0) - { - // Iterating through the result set, if no errors occurred in the previous iteration - for ($i = 0; $i < count($result->retval) && $sent; $i++) - { - // If the person has an email account - if ((!is_null($result->retval[$i]->receiver) && $result->retval[$i]->receiver != '') - || (!is_null($result->retval[$i]->employeecontact) && $result->retval[$i]->employeecontact != '')) - { - $href = $this->_ci->config->item(self::CFG_MESSAGE_SERVER).$this->_ci->config->item(self::CFG_MESSAGE_HTML_VIEW_URL).$result->retval[$i]->token; - $vorlage = $this->_ci->vorlagelib->loadVorlagetext(self::NOTICE_TEMPLATE_HTML); + if (isError($messagesResult)) terminateWithError(getData($messagesResult)); // If an error occurred then log it and terminate - if(hasData($vorlage)) - { - // Using a template for the html email body - $body = parseText( - $vorlage->retval[0]->text, - array( - 'href' => $href, - 'subject' => $result->retval[$i]->subject, - 'body' => $result->retval[$i]->body - ) - ); - } - else - { - // Using a template for the html email body - $body = $this->_ci->parser->parse( - 'templates/mailHTML', - array( - 'href' => $href, - 'subject' => $result->retval[$i]->subject, - 'body' => $result->retval[$i]->body - ), - true - ); - } - if (is_null($body) || $body == '') - { - $this->_ci->loglib->logError('Error while parsing the mail template'); - } + $sendNotice = $this->_sendNotice(getData($messagesResult)); - $vorlage = $this->_ci->vorlagelib->loadVorlagetext(self::NOTICE_TEMPLATE_TXT); - if(hasData($vorlage)) - { - // Using a template for the plain text email body - $altBody = parseText( - $vorlage->retval[0]->text, - array( - 'href' => $href, - 'subject' => $result->retval[$i]->subject, - 'body' => $result->retval[$i]->body - ) - ); - } - else - { - // Using a template for the plain text email body - $altBody = $this->_ci->parser->parse( - 'templates/mailTXT', - array( - 'href' => $href, - 'subject' => $result->retval[$i]->subject, - 'body' => $result->retval[$i]->body - ), - true - ); - } - if (is_null($altBody) || $altBody == '') - { - $this->_ci->loglib->logError('Error while parsing the mail template'); - } - - // If the sender is not an employee, then system-sender is used if empty - $sender = ''; - if (!is_null($result->retval[0]->senderemployeecontact) && $result->retval[0]->senderemployeecontact != '') - { - $sender = $result->retval[0]->senderemployeecontact.'@'.DOMAIN; - } - - $receiverContact = $result->retval[$i]->receiver; - if (!is_null($result->retval[$i]->employeecontact) && $result->retval[$i]->employeecontact != '') - { - $receiverContact = $result->retval[$i]->employeecontact.'@'.DOMAIN; - } - - // Sending email - $sent = $this->_ci->maillib->send( - $sender, - $receiverContact, - $result->retval[$i]->subject, - $body, - null, - null, - null, - $altBody - ); - // If errors were occurred while sending the email - if (!$sent) - { - $this->_ci->loglib->logError('Error while sending an email'); - // Writing errors in tbl_msg_recipient - $sme = $this->_setSentError( - $result->retval[$i]->message_id, - $result->retval[$i]->receiver_id, - 'Error while sending an email', - $result->retval[$i]->sentinfo - ); - if (!$sme) - { - $this->_ci->loglib->logError('Error while updating DB'); - } - } - else - { - // Setting the message as sent in DB - $sent = $this->_setSentSuccess($result->retval[$i]->message_id, $result->retval[$i]->receiver_id); - // If some errors occurred - if (!$sent) - { - $this->_ci->loglib->logError('Error while updating DB'); - } - } - } - else - { - $this->_ci->loglib->logError('This person does not have an email account'); - // Writing errors in tbl_msg_recipient - $sme = $this->_setSentError( - $result->retval[$i]->message_id, - $result->retval[$i]->receiver_id, - 'This person does not have an email account', - $result->retval[$i]->sentinfo - ); - if (!$sme) - { - $this->_ci->loglib->logError('Error while updating DB'); - } - $sent = true; // Non blocking error - } - } - } - else - { - $this->_ci->loglib->logInfo('There are no email to be sent'); - $sent = false; - } - } - else - { - $this->_ci->loglib->logError('Something went wrong while getting data from DB'); - $sent = false; - } - - return $sent; + if (isError($sendNotice)) terminateWithError(getData($sendNotice)); // If an error occurred then log it and terminate } //------------------------------------------------------------------------------------------------------------------ @@ -423,13 +260,13 @@ class MessageLib { if (isEmptyString($token)) return error('The given token is not valid', MSG_ERR_INVALID_TOKEN); - $result = $this->_ci->RecipientModel->getMessageByToken($token); - if (hasData($result)) + $messageTokenResult = $this->_ci->RecipientModel->getMessageByToken($token); + if (hasData($messageTokenResult)) { // Searches for a status that is NOT unread $found = false; - foreach (getData($result) as $message) + foreach (getData($messageTokenResult) as $message) { if ($message->status > MSG_STATUS_UNREAD) { @@ -442,18 +279,18 @@ class MessageLib if (!$found) { $statusData = array( - 'message_id' => getData($result)[0]->message_id, - 'person_id' => getData($result)[0]->receiver_id, + 'message_id' => getData($messageTokenResult)[0]->message_id, + 'person_id' => getData($messageTokenResult)[0]->receiver_id, 'status' => MSG_STATUS_READ ); - $resultIns = $this->_ci->MsgStatusModel->insert($statusData); + $messageTokenResultIns = $this->_ci->MsgStatusModel->insert($statusData); // If an error occured while writing on data base, then return it - if (isError($resultIns)) $result = $resultIns; + if (isError($messageTokenResultIns)) $messageTokenResult = $messageTokenResultIns; } } - return $result; + return $messageTokenResult; } /** @@ -480,8 +317,8 @@ class MessageLib $this->_ci->MsgStatusModel->resetQuery(); // Reset an eventually already buit query // Searches if the status is already present - $result = $this->_ci->MsgStatusModel->load(array($message_id, $person_id, $status)); - if (!hasData($result)) // if not found + $updMessageStatusResult = $this->_ci->MsgStatusModel->load(array($message_id, $person_id, $status)); + if (!hasData($updMessageStatusResult)) // if not found { // Insert the new status $statusKey = array( @@ -489,10 +326,10 @@ class MessageLib 'person_id' => $person_id, 'status' => $status ); - $result = $this->_ci->MsgStatusModel->insert($statusKey); + $updMessageStatusResult = $this->_ci->MsgStatusModel->insert($statusKey); } - return $result; + return $updMessageStatusResult; } //------------------------------------------------------------------------------------------------------------------ @@ -580,10 +417,10 @@ class MessageLib 'oe_kurzbz' => $senderOU ); - $result = $this->_ci->MessageModel->insert($messageData); - if (isSuccess($result)) + $saveMessageResult = $this->_ci->MessageModel->insert($messageData); + if (isSuccess($saveMessageResult)) { - $messageId = getData($result); // Gets the message id generated by database + $messageId = getData($saveMessageResult); // Gets the message id generated by database // Store message information in tbl_msg_recipient $recipientData = array( @@ -593,8 +430,8 @@ class MessageLib 'oe_kurzbz' => $receiverOU ); - $result = $this->_ci->RecipientModel->insert($recipientData); - if (isSuccess($result)) + $saveMessageResult = $this->_ci->RecipientModel->insert($recipientData); + if (isSuccess($saveMessageResult)) { // Store message information in tbl_msg_status $statusData = array( @@ -602,24 +439,24 @@ class MessageLib 'person_id' => $receiver_id, 'status' => MSG_STATUS_UNREAD ); - $result = $this->_ci->MsgStatusModel->insert($statusData); + $saveMessageResult = $this->_ci->MsgStatusModel->insert($statusData); } } $this->_ci->db->trans_complete(); // Ends database transaction // If the transaction failed... - if ($this->_ci->db->trans_status() === false || isError($result)) + if ($this->_ci->db->trans_status() === false || isError($saveMessageResult)) { $this->_ci->db->trans_rollback(); // ...then rollback } else // otherwise commit... { $this->_ci->db->trans_commit(); - $result = success($messageId); // ...and returns the message id + $saveMessageResult = success($messageId); // ...and returns the message id } - return $result; + return $saveMessageResult; } /** @@ -651,20 +488,14 @@ class MessageLib * Returns the notice body. Tries to use the template present in database and then falling back * on the one present in filesystem. If both fail then an error is returned */ - private function _getNoticeBody($viewMessageLink, $subject, $body, $dbTemplateName, $fsTemplateName) + private function _getNoticeBody($dbEmailNoticeTemplate, $fsEmailNoticeTemplate, $viewMessageLink, $subject, $body) { - $noticeBody = null; + $noticeBody = null; // pessimistic expectation - $vorlageResult = $this->_ci->vorlagelib->loadVorlagetext($dbTemplateName); - - if (isError($vorlageResult)) return $vorlageResult; - - if (hasData($vorlageResult)) + if (!isEmptyString($dbEmailNoticeTemplate)) { - $vorlage = getData($vorlageResult)[0]; - $noticeBody = parseText( - $vorlage->text, + $dbEmailNoticeTemplate, array( 'href' => $viewMessageLink, 'subject' => $subject, @@ -674,8 +505,8 @@ class MessageLib } else { - $noticeBody = parseTemplate( - $fsTemplateName, + $noticeBody = parseText( + $fsEmailNoticeTemplate, array( 'href' => $viewMessageLink, 'subject' => $subject, @@ -689,106 +520,111 @@ class MessageLib return success($noticeBody); } - /** - * Returns the notice HTML body try to using the template present in database and then falling back - * on the one present in filesystem. If both fail then an error is returned - */ - private function _getNoticeHTMLBody($viewMessageLink, $subject, $body) - { - return $this->_getNoticeBody($viewMessageLink, $subject, $body, self::NOTICE_TEMPLATE_HTML, self::NOTICE_TEMPLATE_FALLBACK_HTML); - } - - /** - * Returns the notice TXT body try to using the template present in database and then falling back - * on the one present in filesystem. If both fail then an error is returned - */ - private function _getNoticeTXTBody($viewMessageLink, $subject, $body) - { - return $this->_getNoticeBody($viewMessageLink, $subject, $body, self::NOTICE_TEMPLATE_TXT, self::NOTICE_TEMPLATE_FALLBACK_TXT); - } - /** * Sends a notice email that notices to a user about a new received message + * It gets just one message. Wrapper for _sendNotice. */ - private function _sendNotice($message_id) + private function _sendOneNotice($message_id) { // Get the message and related data (sender, recipient, etc...) $messageResult = $this->_ci->RecipientModel->getMessages( self::EMAIL_KONTAKT_TYPE, - 1, $message_id ); 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 - $messageData = getData($messageResult)[0]; // Message data from database + return $this->_sendNotice(getData($messageResult)); + } - // Checks if this person has a valid email address where to send the notice email - if (isEmptyString($messageData->receiver) && isEmptyString($messageData->employeecontact)) + /** + * Core method to send one or more email notices for one or more messages + */ + private function _sendNotice($messagesResult) + { + // Prefix for all links that will be subsequently generated + $prefixLink = $this->_ci->config->item(self::CFG_MESSAGE_SERVER).$this->_ci->config->item(self::CFG_MESSAGE_HTML_VIEW_URL); + + // Loads all the needed templates for HTML and plain text. Main templates from database, fallback templates from file system + $dbEmailNoticeTemplateHTML = $this->_loadDbNoticeEmailTemplate(self::NOTICE_TEMPLATE_HTML); + $dbEmailNoticeTemplateTXT = $this->_loadDbNoticeEmailTemplate(self::NOTICE_TEMPLATE_TXT); + $fsEmailNoticeTemplateHTML = $this->_loadFsNoticeEmailTemplate(self::NOTICE_TEMPLATE_FALLBACK_HTML); + $fsEmailNoticeTemplateTXT = $this->_loadFsNoticeEmailTemplate(self::NOTICE_TEMPLATE_FALLBACK_TXT); + + // Loops through all the messages to be sent + foreach ($messagesResult as $messageData) { - // Set in database why this email is NOT going to be send - $sse = $this->_setSentError( - $message_id, - $messageData->receiver_id, - 'This person does not have an email account', - $messageData->sentinfo + // Checks if this person has a valid email address where to send the notice email + if (isEmptyString($messageData->receiver) && isEmptyString($messageData->employeecontact)) + { + // Set in database why this email is NOT going to be send + $sse = $this->_setSentError( + $messageData->message_id, + $messageData->receiver_id, + 'This person does not have an email account', + $messageData->sentinfo + ); + + // If database error occurred then return it + if (isError($sse)) return $sse; + + continue; // Skip the rest, continue with the next one + } + + // Create a link to the controller to view the message using a token + $viewMessageLink = $prefixLink.$messageData->token; + + // Generates notice email body in HTML and plain text version. + // If an error occured during the generation then the error itself is returned + $noticeHTMLBody = $this->_getNoticeBody( + $dbEmailNoticeTemplateHTML, $fsEmailNoticeTemplateHTML, $viewMessageLink, $messageData->subject, $messageData->body + ); + if (isError($noticeHTMLBody)) return $noticeHTMLBody; + $noticeTXTBody = $this->_getNoticeBody( + $dbEmailNoticeTemplateTXT, $fsEmailNoticeTemplateTXT, $viewMessageLink, $messageData->subject, $messageData->body + ); + if (isError($noticeTXTBody)) return $noticeTXTBody; + + // If an employeecontact contact is present then use it, otherwise use the personal contacts + $receiverContact = $messageData->receiver; + if (!isEmptyString($messageData->employeecontact)) $receiverContact = $messageData->employeecontact.'@'.DOMAIN; + + // Sending email + $sent = $this->_ci->maillib->send( + null, + $receiverContact, + $messageData->subject, + getData($noticeHTMLBody), + null, + null, + null, + getData($noticeTXTBody) ); - // If database error occurred then return it, otherwise return a logic error - return isError($sse) ? $sse : error('This person does not have an email account'); + // If errors occurred while sending the email + if (!$sent) + { + // Set in database why this email is NOT going to be send + $sse = $this->_setSentError( + $messageData->message_id, + $messageData->receiver_id, + 'An error occurred while sending the email', + $messageData->sentinfo + ); + + // If database error occurred then return it, otherwise return a logic error + return isError($sse) ? $sse : error('An error occurred while sending the email'); + } + else // success! + { + // Set in database that the notice email was succesfully sent + $sss = $this->_setSentSuccess($messageData->message_id, $messageData->receiver_id); + if (isError($sss)) return $sss; // If database error occurred then return it + } } - // Create a link to the controller to view the message using a token - $viewMessageLink = $this->_ci->config->item(self::CFG_MESSAGE_SERVER). - $this->_ci->config->item(self::CFG_MESSAGE_HTML_VIEW_URL). - $messageData->token; - - // Generates notice email body in HTML and plain text version. - // If an error occured during the generation then the error itself is returned - $noticeHTMLBody = $this->_getNoticeHTMLBody($viewMessageLink, $messageData->subject, $messageData->body); - if (isError($noticeHTMLBody)) return $noticeHTMLBody; - $noticeTXTBody = $this->_getNoticeTXTBody($viewMessageLink, $messageData->subject, $messageData->body); - if (isError($noticeTXTBody)) return $noticeTXTBody; - - // If an employeecontact contact is present then use it, otherwise use the personal contacts - $receiverContact = $messageData->receiver; - if (!isEmptyString($messageData->employeecontact)) $receiverContact = $messageData->employeecontact.'@'.DOMAIN; - - // Sending email - $sent = $this->_ci->maillib->send( - null, - $receiverContact, - $messageData->subject, - getData($noticeHTMLBody), - null, - null, - null, - getData($noticeTXTBody) - ); - - // If errors occurred while sending the email - if (!$sent) - { - // Set in database why this email is NOT going to be send - $sse = $this->_setSentError( - $message_id, - $messageData->receiver_id, - 'An error occurred while sending the email', - $messageData->sentinfo - ); - - // If database error occurred then return it, otherwise return a logic error - return isError($sse) ? $sse : error('An error occurred while sending the email'); - } - else // success! - { - // Set in database that the notice email was succesfully sent - $sss = $this->_setSentSuccess($message_id, $messageData->receiver_id); - if (isError($sss)) return $sss; // If database error occurred then return it - } - - return success('Notice email sent successfully'); + return success('Notice emails sent successfully'); } /** @@ -841,7 +677,7 @@ class MessageLib foreach ($savedMessages as $message_id) { // Send message notice via email! - $sendNotice = $this->_sendNotice($message_id); + $sendNotice = $this->_sendOneNotice($message_id); // If an error occurred then return it if (isError($sendNotice)) return $sendNotice; } @@ -864,4 +700,30 @@ class MessageLib return hasData($ouResults); } + + /** + * Loads a the specified template from database + * Returns null if not found or on failure + */ + private function _loadDbNoticeEmailTemplate($dbTemplateName) + { + $emailNoticeTemplate = null; + + $vorlageResult = $this->_ci->vorlagelib->loadVorlagetext($dbTemplateName); + + if (hasData($vorlageResult)) + { + $emailNoticeTemplate = getData($vorlageResult)[0]->text; + } + + return $emailNoticeTemplate; + } + + /** + * Loads a the specified template from database + */ + private function _loadFsNoticeEmailTemplate($fsTemplateName) + { + return $this->_ci->load->view($fsTemplateName, null, true); + } } diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 49fc21fc4..3a30bba1f 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -205,7 +205,7 @@ class Recipient_model extends DB_Model * @param limit specifies the number of messages to get * @param message_id specifies a single message */ - public function getMessages($kontaktType, $limit = 1, $message_id = null) + public function getMessages($kontaktType, $message_id = null, $limit = 1) { $query = 'SELECT mm.message_id, ks.kontakt as sender, @@ -219,10 +219,10 @@ class Recipient_model extends DB_Model mr.sentinfo FROM public.tbl_msg_recipient mr INNER JOIN public.tbl_msg_message mm USING (message_id) LEFT JOIN ( - SELECT person_id, kontakt FROM public.tbl_kontakt WHERE kontakttyp = ? + SELECT person_id, kontakt FROM public.tbl_kontakt WHERE zustellung = true AND kontakttyp = ? ) ks ON (ks.person_id = mm.person_id) LEFT JOIN ( - SELECT person_id, kontakt FROM public.tbl_kontakt WHERE kontakttyp = ? + SELECT person_id, kontakt FROM public.tbl_kontakt WHERE zustellung = true AND kontakttyp = ? ) kr ON (kr.person_id = mr.person_id) LEFT JOIN ( SELECT b.person_id, @@ -235,14 +235,15 @@ class Recipient_model extends DB_Model m.mitarbeiter_uid FROM public.tbl_benutzer b INNER JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid) WHERE b.aktiv = TRUE - ) ms ON (ms.person_id = mm.person_id)'; + ) ms ON (ms.person_id = mm.person_id) + WHERE mr.sent IS NULL'; $parametersArray = array($kontaktType, $kontaktType); if (is_numeric($message_id)) { array_push($parametersArray, $message_id); - $query .= ' WHERE mm.message_id = ?'; + $query .= ' AND mm.message_id = ?'; } $query .= ' ORDER BY mr.insertamum ASC'; From 5bda5eb966a21ac612e9b6716c297bde5532d629 Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 14 Jun 2019 15:40:15 +0200 Subject: [PATCH 05/72] - Moved view system/messages/messageList.php -> system/infocenter/messageList.php - Moved js public/js/messaging/messageList.js -> public/js/infocenter/messageList.js - Updated includes in controller system/infocenter/InfoCenter.php and view system/infocenter/infocenterDetails.php --- application/controllers/system/Messages.php | 63 ++++++++++--------- .../system/infocenter/InfoCenter.php | 2 +- .../system/infocenter/infocenterDetails.php | 4 +- .../{messages => infocenter}/messageList.php | 0 .../{messaging => infocenter}/messageList.js | 0 5 files changed, 36 insertions(+), 33 deletions(-) rename application/views/system/{messages => infocenter}/messageList.php (100%) rename public/js/{messaging => infocenter}/messageList.js (100%) diff --git a/application/controllers/system/Messages.php b/application/controllers/system/Messages.php index 744eb880e..a7709a702 100644 --- a/application/controllers/system/Messages.php +++ b/application/controllers/system/Messages.php @@ -96,36 +96,7 @@ class Messages extends Auth_Controller } // ----------------------------------------------------------------------------------------------------------------- - // Public methods - JSON output - - /** - * Send a new message - * - The recipients are prestudents - * - An email template with message var may be provided - * - A global organisation unit may be provided, otherwise is used the prestudent one - */ - public function sendJson() - { - $prestudents = $this->input->post('prestudents'); - $vorlage_kurzbz = $this->input->post('vorlage_kurzbz'); - $oe_kurzbz = $this->input->post('oe_kurzbz'); - $msgVars = $this->input->post('msgvars'); - - $msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudents); - - $this->load->model('crm/Prestudent_model', 'PrestudentModel'); - $prestudentsData = $this->PrestudentModel->getOrganisationunits($prestudents); - - // Adds the organisation unit to each prestudent - if (isEmptyString($oe_kurzbz) && hasData($msgVarsData) && hasData($prestudentsData)) - { - $this->CLMessagesModel->addOeToPrestudents($msgVarsData, $prestudentsData); - } - - $send = $this->CLMessagesModel->send($msgVarsData, null, $oe_kurzbz, $vorlage_kurzbz, $msgVars); - - $this->outputJson(getData($send)); - } + // Public methods - JSON output - called by this controller and FASMessages (view system/messages/messageWrite) /** * Returns an object that represent a template store in database @@ -185,6 +156,9 @@ class Messages extends Auth_Controller } } + // ----------------------------------------------------------------------------------------------------------------- + // Public methods - JSON output - called by infocenter + /** * Outputs message data for a message (identified my msg id and receiver id) in JSON format */ @@ -204,4 +178,33 @@ class Messages extends Auth_Controller $this->outputJson(array(getData($msg)[0])); } } + + /** + * Send a new message + * - The recipients are prestudents + * - An email template with message var may be provided + * - A global organisation unit may be provided, otherwise is used the prestudent one + */ + public function sendJson() + { + $prestudents = $this->input->post('prestudents'); + $vorlage_kurzbz = $this->input->post('vorlage_kurzbz'); + $oe_kurzbz = $this->input->post('oe_kurzbz'); + $msgVars = $this->input->post('msgvars'); + + $msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudents); + + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + $prestudentsData = $this->PrestudentModel->getOrganisationunits($prestudents); + + // Adds the organisation unit to each prestudent + if (isEmptyString($oe_kurzbz) && hasData($msgVarsData) && hasData($prestudentsData)) + { + $this->CLMessagesModel->addOeToPrestudents($msgVarsData, $prestudentsData); + } + + $send = $this->CLMessagesModel->send($msgVarsData, null, $oe_kurzbz, $vorlage_kurzbz, $msgVars); + + $this->outputJson(getData($send)); + } } diff --git a/application/controllers/system/infocenter/InfoCenter.php b/application/controllers/system/infocenter/InfoCenter.php index d59c058cf..b83d6e48b 100644 --- a/application/controllers/system/infocenter/InfoCenter.php +++ b/application/controllers/system/infocenter/InfoCenter.php @@ -646,7 +646,7 @@ class InfoCenter extends Auth_Controller public function reloadMessages($person_id) { $messages = $this->MessageModel->getMessagesOfPerson($person_id, 1); - $this->load->view('system/messages/messageList.php', array('messages' => $messages->retval)); + $this->load->view('system/infocenter/messageList.php', array('messages' => $messages->retval)); } /** diff --git a/application/views/system/infocenter/infocenterDetails.php b/application/views/system/infocenter/infocenterDetails.php index 9e708d076..86493134c 100644 --- a/application/views/system/infocenter/infocenterDetails.php +++ b/application/views/system/infocenter/infocenterDetails.php @@ -22,7 +22,7 @@ 'customJSs' => array( 'public/js/bootstrapper.js', 'public/js/tablesort/tablesort.js', - 'public/js/messaging/messageList.js', + 'public/js/infocenter/messageList.js', 'public/js/infocenter/infocenterDetails.js' ), 'phrases' => array( @@ -147,7 +147,7 @@
load->view('system/messages/messageList.php', $messages); + $this->load->view('system/infocenter/messageList.php', $messages); ?>
diff --git a/application/views/system/messages/messageList.php b/application/views/system/infocenter/messageList.php similarity index 100% rename from application/views/system/messages/messageList.php rename to application/views/system/infocenter/messageList.php diff --git a/public/js/messaging/messageList.js b/public/js/infocenter/messageList.js similarity index 100% rename from public/js/messaging/messageList.js rename to public/js/infocenter/messageList.js From f6e0f58b3dbe9031d2520fbb1c350c1ff7bf0be3 Mon Sep 17 00:00:00 2001 From: Paolo Date: Tue, 18 Jun 2019 18:25:26 +0200 Subject: [PATCH 06/72] - Renamed view system/messages/messageSent.php to system/messages/htmlSuccess.php - Added new view system/messages/htmlError.php - Renamed view system/messages/messageWrite.php to system/messages/htmlWriteTemplate.php - Added new widget views: widgets/Dropdown_widget.php and widgets/MultipleDropdown_widget.php - Added new CSS public/css/Widgets.css - Controller system/FASMessages: - Renamed method write to writeTemplate and method writeReply to writeReplyTemplate - Removed all the private methods and moved all the logic to model CL/Messages_model - Methods writeTemplate and writeReplyTemplate do not need anymore the sender id as parameter - Controller system/Messages: - Renamed method write to writeTemplate - Renamed method send to sendImplicitTemplate - Renamed method sendJson to sendExplicitTemplateJson - Moved all the logic to model CL/Messages_model - Adapted php and JS code to use these new methods names and interfaces - Removed public method getIsAdmin from MessageLib - Method _sendMessage of MessageLib now returns the saved message ids - Added new package olifolkerd/tabulator to composer - Added new parameter widgets to view templates/FHC-Header.php - Added new HTML widget widgets/Dropdown_widget and widgets/MultipleDropdown_widget - Added constants REPLY_SUBJECT_PREFIX and REPLY_BODY_PREFIX to model CL/Messages_model - Added new public methods prepareHtmlWriteTemplatePersons, prepareHtmlWriteTemplatePrestudents, sendImplicitTemplate, sendExplicitTemplate, getVorlage, parseMessageText and getMessageFromIds to model CL/Messages_model - Added new private methods _getAuthUser, _lowerReplaceSpaceArrayKeys, _addOeToPrestudents, _personLog and _prepareHtmlWriteTemplate to model CL/Messages_model --- .../controllers/system/FASMessages.php | 177 +------- application/controllers/system/Messages.php | 147 ++----- application/libraries/MessageLib.php | 18 +- application/models/CL/Messages_model.php | 409 ++++++++++++++---- .../views/system/infocenter/stammdaten.php | 2 +- .../views/system/messages/htmlError.php | 82 ++++ .../{messageSent.php => htmlSuccess.php} | 12 +- .../system/messages/htmlWriteTemplate.php | 167 +++++++ .../views/system/messages/messageWrite.php | 183 -------- application/views/templates/FHC-Header.php | 4 + application/views/widgets/dropdown.php | 6 +- application/widgets/Dropdown_widget.php | 19 + .../widgets/MultipleDropdown_widget.php | 20 + application/widgets/html/DropdownWidget.php | 42 +- composer.json | 13 + composer.lock | 49 ++- content/fasoverlay.js.php | 2 +- content/messages.js.php | 4 +- public/css/Widgets.css | 46 ++ public/css/messaging/messageWrite.css | 7 +- public/js/infocenter/infocenterDetails.js | 2 +- .../js/infocenter/infocenterPersonDataset.js | 2 +- public/js/messaging/messageWrite.js | 2 +- 23 files changed, 802 insertions(+), 613 deletions(-) create mode 100644 application/views/system/messages/htmlError.php rename application/views/system/messages/{messageSent.php => htmlSuccess.php} (95%) create mode 100644 application/views/system/messages/htmlWriteTemplate.php delete mode 100644 application/views/system/messages/messageWrite.php create mode 100644 application/widgets/Dropdown_widget.php create mode 100644 application/widgets/MultipleDropdown_widget.php create mode 100644 public/css/Widgets.css diff --git a/application/controllers/system/FASMessages.php b/application/controllers/system/FASMessages.php index 6928a919d..55d1da25f 100644 --- a/application/controllers/system/FASMessages.php +++ b/application/controllers/system/FASMessages.php @@ -11,17 +11,15 @@ class FASMessages extends Auth_Controller { parent::__construct( array( - 'write' => 'basis/message:rw', - 'writeReply' => 'basis/message:rw' + 'writeTemplate' => 'basis/message:rw', + 'writeReplyTemplate' => 'basis/message:rw' ) ); - // Loads the message library - $this->load->library('MessageLib'); - - // Loads the widget library - $this->load->library('WidgetLib'); + // Loads model CLMessagesModel which contains the GUI logic + $this->load->model('CL/Messages_model', 'CLMessagesModel'); + // Phrases used in loaded views $this->loadPhrases( array( 'global', @@ -30,162 +28,33 @@ class FASMessages extends Auth_Controller ); } - // ----------------------------------------------------------------------------------------------------------------- - // Public methods - /** - * Write a new message + * Writes a new message to a prestudent using templates */ - public function write($sender_id) + public function writeTemplate() { - $prestudent_id = $this->input->post('prestudent_id'); // recipients prestudend_id(s) + $prestudents = $this->input->post('prestudent_id'); // recipients prestudend_id(s) - if (!is_numeric($sender_id)) - { - show_error('The current logged user person_id is not defined'); - } - - $msgVarsData = $this->_getMsgVarsData($prestudent_id); - - // Retrieves message vars for a person from view view vw_msg_vars_person - $variablesArray = $this->_getMessageVarsPerson(); - - // Organisation units used to get the templates - $oe_kurzbz = $this->_getOeKurzbz($sender_id); - - // Admin or commoner? - $isAdmin = $this->_getIsAdmin($sender_id); - - $data = array( - 'recipients' => getData($msgVarsData), - 'variables' => $variablesArray, - 'oe_kurzbz' => $oe_kurzbz, // used to get the templates - 'isAdmin' => $isAdmin - ); - - $this->load->view('system/messages/messageWrite', $data); + // Loads the view to write a new message with a template + $this->load->view( + 'system/messages/htmlWriteTemplate', + $this->CLMessagesModel->prepareHtmlWriteTemplatePrestudents($prestudents) + ); } /** - * Write a reply + * Writes a reply to a message identified by parameters $message_id and $recipient_id + * The recipient is a prestudent + * Uses templates */ - public function writeReply($sender_id, $msg_id, $receiver_id) + public function writeReplyTemplate($message_id, $recipient_id) { - $prestudent_id = $this->input->post('prestudent_id'); // recipients prestudend_id(s) + $prestudents = $this->input->post('prestudent_id'); // recipients prestudend_id(s) - if (!is_numeric($sender_id)) - { - show_error('The current logged user person_id is not defined'); - } - - if (!is_numeric($msg_id)) - { - show_error('The msg_id must be a number'); - } - - if (!is_numeric($receiver_id)) - { - show_error('The receiver_id must be a number'); - } - - $msg = $this->_getMessage($msg_id, $receiver_id); - - $msgVarsData = $this->_getMsgVarsData($prestudent_id); - - // Retrieves message vars for a person from view view vw_msg_vars_person - $variablesArray = $this->_getMessageVarsPerson(); - - // Organisation units used to get the templates - $oe_kurzbz = $this->_getOeKurzbz($sender_id); - - // Admin or commoner? - $isAdmin = $this->_getIsAdmin($sender_id); - - $data = array( - 'recipients' => getData($msgVarsData), - 'message' => $msg, - 'variables' => $variablesArray, - 'oe_kurzbz' => $oe_kurzbz, // used to get the templates - 'isAdmin' => $isAdmin - ); - - $this->load->view('system/messages/messageWrite', $data); + // Loads the view to write a new message with a template + $this->load->view( + 'system/messages/htmlWriteTemplate', + $this->CLMessagesModel->prepareHtmlWriteTemplatePrestudents($prestudents, $message_id, $recipient_id) + ); } - - // ----------------------------------------------------------------------------------------------------------------- - // Private methods - - /** - * - */ - private function _getMessage($msg_id, $receiver_id) - { - $msg = $this->messagelib->getMessage($msg_id, $receiver_id); - if (isError($msg)) - { - show_error(getData($msg)); - } - elseif (!hasData($msg)) - { - show_error('The selected message does not exist'); - } - else - { - $msg = getData($msg)[0]; - } - - return $msg; - } - - /** - * Retrieves message vars from view vw_msg_vars - */ - private function _getMsgVarsData($prestudent_id) - { - $this->load->model('system/Message_model', 'MessageModel'); - $msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); - - if (isError($msgVarsData)) - { - show_error(getData($msgVarsData)); - } - - return $msgVarsData; - } - - /** - * Wrapper method to call messagelib->getMessageVarsPerson - */ - private function _getMessageVarsPerson() - { - $variables = $this->messagelib->getMessageVarsPerson(); - - if (isError($variables)) show_error(getData($variables)); - - return getData($variables); - } - - /** - * Wrapper method to call messagelib->getOeKurzbz - */ - private function _getOeKurzbz($sender_id) - { - $oe_kurzbz = $this->messagelib->getOeKurzbz($sender_id); - - if (isError($oe_kurzbz)) show_error(getData($oe_kurzbz)); - - return getData($oe_kurzbz); - } - - /** - * Wrapper method to call messagelib->getIsAdmin - */ - private function _getIsAdmin($sender_id) - { - $isAdmin = $this->messagelib->getIsAdmin($sender_id); - - if (isError($isAdmin)) show_error(getData($isAdmin)); - - return getData($isAdmin); - } } diff --git a/application/controllers/system/Messages.php b/application/controllers/system/Messages.php index a7709a702..20fed38ad 100644 --- a/application/controllers/system/Messages.php +++ b/application/controllers/system/Messages.php @@ -4,28 +4,23 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); class Messages extends Auth_Controller { - /** - * MessageLib is loaded by CLMessagesModel - */ public function __construct() { parent::__construct( array( - 'write' => array('basis/message:rw', 'infocenter:rw'), - 'send' => array('basis/message:rw', 'infocenter:rw'), - 'sendJson' => array('basis/message:rw', 'infocenter:rw'), + 'writeTemplate' => array('basis/message:rw', 'infocenter:rw'), + 'sendImplicitTemplate' => array('basis/message:rw', 'infocenter:rw'), + 'sendExplicitTemplateJson' => array('basis/message:rw', 'infocenter:rw'), 'getVorlage' => array('basis/message:r', 'infocenter:r'), 'parseMessageText' => array('basis/message:r', 'infocenter:r'), 'getMessageFromIds' => array('basis/message:r', 'infocenter:r') ) ); - // Loads the widget library - $this->load->library('WidgetLib'); - - $this->load->model('system/Message_model', 'MessageModel'); + // Loads model CLMessagesModel which contains the GUI logic $this->load->model('CL/Messages_model', 'CLMessagesModel'); + // Phrases used in loaded views $this->loadPhrases( array( 'global', @@ -38,65 +33,45 @@ class Messages extends Auth_Controller // Public methods - HTML output /** - * Initialize all the parameters used by view system/messages/messageWrite - * to build a GUI used to write a messate to user/s + * Initialize all the parameters used by view system/messages/htmlWriteTemplate + * to build a GUI used to write a messate to user/s using a template */ - public function write() + public function writeTemplate() { $persons = $this->input->post('person_id'); - $authUser = $this->CLMessagesModel->getAuthUser(); - if (isError($authUser)) show_error(getData($authUser)); - - $sender_id = getData($authUser)[0]->person_id; - - // Retrieves person information - $msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($persons); - if (isError($msgVarsData)) show_error(getData($msgVarsData)); - - // Retrieves message vars from view vw_msg_vars_person - $variables = $this->messagelib->getMessageVarsPerson(); - if (isError($variables)) show_error(getData($variables)); - - // Organisation units used to get the templates - $oe_kurzbz = $this->messagelib->getOeKurzbz($sender_id); - if (isError($oe_kurzbz)) show_error(getData($oe_kurzbz)); - - // Admin or commoner? - $isAdmin = $this->messagelib->getIsAdmin($sender_id); - if (isError($isAdmin)) show_error(getData($isAdmin)); - + // Loads the view to write a new message with a template $this->load->view( - 'system/messages/messageWrite', - array ( - 'recipients' => getData($msgVarsData), // recipients data - 'variables' => getData($variables), // message vars - 'oe_kurzbz' => getData($oe_kurzbz), // used to get the templates - 'isAdmin' => getData($isAdmin) // is admin? - ) + 'system/messages/htmlWriteTemplate', + $this->CLMessagesModel->prepareHtmlWriteTemplatePersons($persons) ); } /** * Send a new message or reply to user/s * If a relationmessage_id this message is a reply to another one + * Body is a template and will be parsed using information present in persons parameter */ - public function send() + public function sendImplicitTemplate() { + $subject = $this->input->post('subject'); + $body = $this->input->post('body'); $persons = $this->input->post('persons'); $relationmessage_id = $this->input->post('relationmessage_id'); - // Retrieves message vars data for the fiven user/s - $msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($persons); - - // Send the message - $send = $this->CLMessagesModel->send($msgVarsData, $relationmessage_id); - - $this->load->view('system/messages/messageSent', array('success' => isSuccess($send))); + $sendImplicitTemplate = $this->CLMessagesModel->sendImplicitTemplate($persons, $subject, $body, $relationmessage_id); + if (isSuccess($sendImplicitTemplate)) + { + $this->load->view('system/messages/htmlSuccess'); + } + else + { + $this->load->view('system/messages/htmlError'); + } } // ----------------------------------------------------------------------------------------------------------------- - // Public methods - JSON output - called by this controller and FASMessages (view system/messages/messageWrite) + // Public methods - JSON output - called by this controller and FASMessages (view system/messages/htmlWriteTemplate) /** * Returns an object that represent a template store in database @@ -106,24 +81,8 @@ class Messages extends Auth_Controller public function getVorlage() { $vorlage_kurzbz = $this->input->get('vorlage_kurzbz'); - $result = error('The given vorlage_kurzbz is not valid'); - if (!isEmptyString($vorlage_kurzbz)) - { - $this->load->model('system/Vorlagestudiengang_model', 'VorlagestudiengangModel'); - $this->VorlagestudiengangModel->addOrder('version','DESC'); - - $result = $this->VorlagestudiengangModel->loadWhere(array('vorlage_kurzbz' => $vorlage_kurzbz)); - } - - if (isError($result) || !hasData($result)) - { - $this->outputJsonError(getData($result)); - } - else - { - $this->outputJsonSuccess(getData($result)); - } + $this->outputJson($this->CLMessagesModel->getVorlage($vorlage_kurzbz)); } /** @@ -134,26 +93,8 @@ class Messages extends Auth_Controller { $person_id = $this->input->get('person_id'); $text = $this->input->get('text'); - $msgVarsData = error('The given person_id is not a valid number'); - if (is_numeric($person_id)) - { - $msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($person_id); - } - - if (isError($msgVarsData) || !hasData($msgVarsData)) - { - $this->outputJsonError(getData($msgVarsData)); - } - else - { - $this->outputJsonSuccess( - parseText( - $text, - $this->CLMessagesModel->replaceKeys((array)getData($msgVarsData)[0]) - ) - ); - } + $this->outputJson($this->CLMessagesModel->parseMessageText($person_id, $text)); } // ----------------------------------------------------------------------------------------------------------------- @@ -164,19 +105,10 @@ class Messages extends Auth_Controller */ public function getMessageFromIds() { - $msg_id = $this->input->get('msg_id'); + $message_id = $this->input->get('msg_id'); $receiver_id = $this->input->get('receiver_id'); - $msg = $this->messagelib->getMessage($msg_id, $receiver_id); - - if (isError($msg) || !hasData($msg)) - { - $this->outputJson(array()); - } - else - { - $this->outputJson(array(getData($msg)[0])); - } + $this->outputJson($this->CLMessagesModel->getMessageFromIds($message_id, $receiver_id)); } /** @@ -184,27 +116,16 @@ class Messages extends Auth_Controller * - The recipients are prestudents * - An email template with message var may be provided * - A global organisation unit may be provided, otherwise is used the prestudent one + * - A template is explicitly specified */ - public function sendJson() + public function sendExplicitTemplateJson() { $prestudents = $this->input->post('prestudents'); - $vorlage_kurzbz = $this->input->post('vorlage_kurzbz'); $oe_kurzbz = $this->input->post('oe_kurzbz'); + $vorlage_kurzbz = $this->input->post('vorlage_kurzbz'); $msgVars = $this->input->post('msgvars'); - $msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudents); - - $this->load->model('crm/Prestudent_model', 'PrestudentModel'); - $prestudentsData = $this->PrestudentModel->getOrganisationunits($prestudents); - - // Adds the organisation unit to each prestudent - if (isEmptyString($oe_kurzbz) && hasData($msgVarsData) && hasData($prestudentsData)) - { - $this->CLMessagesModel->addOeToPrestudents($msgVarsData, $prestudentsData); - } - - $send = $this->CLMessagesModel->send($msgVarsData, null, $oe_kurzbz, $vorlage_kurzbz, $msgVars); - - $this->outputJson(getData($send)); + $sendExplicitTemplate = $this->CLMessagesModel->sendExplicitTemplate($prestudents, $oe_kurzbz, $vorlage_kurzbz, $msgVars); + $this->outputJson(getData($sendExplicitTemplate)); } } diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index c3c1169d4..7bf6b7518 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -49,7 +49,6 @@ class MessageLib // Loads extra models $this->_ci->load->model('person/Person_model', 'PersonModel'); - $this->_ci->load->model('system/Benutzerrolle_model', 'BenutzerrolleModel'); $this->_ci->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel'); $this->_ci->load->model('organisation/Organisationseinheit_model', 'OrganisationseinheitModel'); } @@ -208,14 +207,6 @@ class MessageLib return $benutzer; // otherwise returns the error } - /** - * Admin or commoner? - */ - public function getIsAdmin($sender_id) - { - return $this->_ci->BenutzerrolleModel->isAdminByPersonId($sender_id); - } - //------------------------------------------------------------------------------------------------------------------ // Public methods used by REST API @@ -629,6 +620,7 @@ class MessageLib /** * Sends new message core method, may be wrapped by other methods. + * If success then returns an array of successfully saved message ids */ private function _sendMessage( $receivers, $receiversOU, $subject, $body, $sender_id, $senderOU, $relationmessage_id, $priority, $multiPartMime @@ -658,11 +650,7 @@ class MessageLib ); if (isSuccess($saveMessageResult)) // If successfully saved { - // If the system is configured to send messages immediately - if ($this->_ci->config->item(self::CFG_SEND_IMMEDIATELY) === true) - { - $savedMessages[] = getData($saveMessageResult); // store the message id of the saved message - } + $savedMessages[] = getData($saveMessageResult); // store the message id of the saved message } else { @@ -683,7 +671,7 @@ class MessageLib } } - return success('Message sent successfully'); + return success($savedMessages); } /** diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index c17d608c7..05eaa8b16 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -1,11 +1,15 @@
-------------------------------------------------------------------------------'; + /** * Constructor */ @@ -14,102 +18,143 @@ class Messages_model extends CI_Model parent::__construct(); // Loads the message library - $this->load->library('MessageLib'); - + $this->load->library('MessageLib'); // MessageModel loaded here! // Loads the person log library $this->load->library('PersonLogLib'); + // Loads the widget library + $this->load->library('WidgetLib'); + // Loads model MessageToken_model $this->load->model('system/MessageToken_model', 'MessageTokenModel'); + + // Loads model Benutzerrolle_model + $this->load->model('system/Benutzerrolle_model', 'BenutzerrolleModel'); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * Prepares data for the view system/messages/htmlWriteTemplate using person ids as main parameter + * Wrap method to _prepareHtmlWriteTemplate + */ + public function prepareHtmlWriteTemplatePersons($persons, $message_id = null, $recipient_id = null) + { + // Retrieves persons information + $msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($persons); + + return $this->_prepareHtmlWriteTemplate($msgVarsData, $message_id, $recipient_id); } /** - * Executes message sending - * @param $sender_id - * @return array wether execution was successfull - error or success + * Prepares data for the view system/messages/htmlWriteTemplate using prestudent ids as main parameter + * Wrap method to _prepareHtmlWriteTemplate */ - public function send($msgVarsData, $relationmessage_id = null, $oe_kurzbz = null, $vorlage_kurzbz = null, $msgVars = null) + public function prepareHtmlWriteTemplatePrestudents($prestudents, $message_id = null, $recipient_id = null) { - $subject = $this->input->post('subject'); - $body = $this->input->post('body'); + // Retrieves prestudents information + $msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudents); - $authUser = $this->getAuthUser(); + return $this->_prepareHtmlWriteTemplate($msgVarsData, $message_id, $recipient_id); + } - if (isError($authUser)) return $authUser; + /** + * 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) + { + // Retrieves the sender id + $authUser = $this->_getAuthUser(); + if (isError($authUser)) show_error(getData($authUser)); + if (!hasData($authUser)) show_error('The current logged user person_id is not defined'); $sender_id = getData($authUser)[0]->person_id; + // Retrieves message vars data for the given user/s + $msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($persons); + if (isError($msgVarsData)) show_error(getData($msgVarsData)); + if (!hasData($msgVarsData)) show_error('No recipients were given'); - // Send message(s) - if (hasData($msgVarsData)) + foreach (getData($msgVarsData) as $receiver) { - for ($i = 0; $i < count(getData($msgVarsData)); $i++) - { - $parsedText = ''; - $msgVarsDataArray = $this->replaceKeys((array)getData($msgVarsData)[$i]); // replaces array keys + $msgVarsDataArray = $this->_lowerReplaceSpaceArrayKeys((array)$receiver); // replaces array keys - // Send without vorlage - if (isEmptyString($vorlage_kurzbz)) - { - $parsedText = parseText($body, $msgVarsDataArray); + $parsedSubject = parseText($subject, $msgVarsDataArray); + $parsedBody = parseText($body, $msgVarsDataArray); - $msg = $this->messagelib->sendMessageUser( - $msgVarsDataArray['person_id'], // receiverPersonId - $subject, // subject - $parsedText, // body - $sender_id, // sender_id - $oe_kurzbz, // senderOU - $relationmessage_id, // relationmessage_id - MSG_PRIORITY_NORMAL // priority - ); - } - // Send with vorlage - else - { - if (is_array($msgVars)) - { - // Additional message variables - foreach ($msgVars as $key => $msgvar) - { - $msgVarsDataArray[$key] = $msgvar; - } - } + $message = $this->messagelib->sendMessageUser( + $msgVarsDataArray['person_id'], // receiverPersonId + $parsedSubject, // subject + $parsedBody, // body + $sender_id, // sender_id + null, // senderOU + $relationmessage_id, // relationmessage_id + MSG_PRIORITY_NORMAL // priority + ); - $msg = $this->messagelib->sendMessageUserTemplate( - $msgVarsDataArray['person_id'], // receiversPersonId - $vorlage_kurzbz, // vorlage - $msgVarsDataArray, // parseData - null, // orgform - $sender_id, // sender_id - $oe_kurzbz // senderOU - ); - } + if (isError($message)) return $message; + if (!hasData($message)) return error('No messages were saved in database'); - if (isError($msg)) return $msg; - - // Write log entry - $personLog = $this->personloglib->log( - $msgVarsDataArray['person_id'], - 'Action', - array( - 'name' => 'Message sent', - 'message' => 'Message sent from person '.$sender_id.' to '.$msgVarsDataArray['person_id'].', messageid '.getData($msg), - 'success' => 'true' - ), - 'kommunikation', - 'core', - null, - getAuthUID() - ); - - if (isError($personLog)) return $personLog; - } - - return success('Messages sent successfully'); + // Write log entry + $personLog = $this->_personLog($sender_id, $msgVarsDataArray['person_id'], getData($message)[0]); + if (isError($personLog)) return $personLog; } - else + + return success('Messages sent successfully'); + } + + /** + * Sends a new message using the given template and information present in parameter prestudents + * Extra variables can be added using parameter $msgVars + */ + public function sendExplicitTemplate($prestudents, $oe_kurzbz, $vorlage_kurzbz, $msgVars) + { + // Retrieves the sender id + $authUser = $this->_getAuthUser(); + if (isError($authUser)) show_error(getData($authUser)); + if (!hasData($authUser)) show_error('The current logged user person_id is not defined'); + + $sender_id = getData($authUser)[0]->person_id; + + // Retrieves message vars data for the given user/s + $msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudents); + if (isError($msgVarsData)) show_error(getData($msgVarsData)); + if (!hasData($msgVarsData)) show_error('No recipients were given'); + + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + $prestudentsData = $this->PrestudentModel->getOrganisationunits($prestudents); + + // Adds the organisation unit to each prestudent + if (isEmptyString($oe_kurzbz) && hasData($msgVarsData) && hasData($prestudentsData)) { - return $msgVarsData; + $this->CLMessagesModel->_addOeToPrestudents($msgVarsData, $prestudentsData); } + + foreach (getData($msgVarsData) as $receiver) + { + $msgVarsDataArray = $this->_lowerReplaceSpaceArrayKeys((array)$receiver); // replaces array keys + + // Additional message variables + if (is_array($msgVars)) $msgVarsDataArray = array_merge($msgVarsDataArray, $msgVars); + + $message = $this->messagelib->sendMessageUserTemplate( + $msgVarsDataArray['person_id'], // receiversPersonId + $vorlage_kurzbz, // vorlage + $msgVarsDataArray, // parseData + null, // orgform + $sender_id, // sender_id + $oe_kurzbz // senderOU + ); + + if (isError($message)) return $message; + + // Write log entry + $personLog = $this->_personLog($sender_id, $msgVarsDataArray['person_id'], getData($message)[0]); + if (isError($personLog)) return $personLog; + } + + return success('Messages sent successfully'); } /** @@ -171,29 +216,98 @@ class Messages_model extends CI_Model return success('Reply sent'); } - /** - * - */ - public function getAuthUser() - { - $sender_id = null; + //------------------------------------------------------------------------------------------------------------------ + // Public methods called by controller system/Messages + /** + * Returns an object that represent a template store in database + * If no templates are found with the given parameter or the given parameter is an empty string, + * then an error is returned + */ + public function getVorlage($vorlage_kurzbz) + { + $getVorlage = error('The given vorlage_kurzbz is not valid'); + + if (!isEmptyString($vorlage_kurzbz)) + { + $this->load->model('system/Vorlagestudiengang_model', 'VorlagestudiengangModel'); + $this->VorlagestudiengangModel->addOrder('version','DESC'); + + $getVorlage = $this->VorlagestudiengangModel->loadWhere(array('vorlage_kurzbz' => $vorlage_kurzbz)); + } + + return $getVorlage; + } + + /** + * 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) + { + $parseMessageText = error('The given person_id is not a valid number'); + + if (is_numeric($person_id)) + { + $parseMessageText = $this->MessageModel->getMsgVarsDataByPersonId($person_id); + } + + if (hasData($parseMessageText)) + { + $parseMessageText = success( + parseText( + $text, + $this->_lowerReplaceSpaceArrayKeys((array)getData($parseMessageText)[0]) + ) + ); + } + + return $parseMessageText; + } + + /** + * Outputs message data for a message (identified my msg id and receiver id) in JSON format + */ + public function getMessageFromIds($message_id, $receiver_id) + { + $getMessageFromIds = error('The given message id or receiver id are not valid'); + + if (is_numeric($message_id) && is_numeric($receiver_id)) + { + $getMessageFromIds = $this->messagelib->getMessage($message_id, $receiver_id); + } + + if (isError($getMessageFromIds) || !hasData($getMessageFromIds)) + { + return array(); + } + else + { + return array(getData($getMessageFromIds)[0]); + } + } + + //------------------------------------------------------------------------------------------------------------------ + // Private methods + + /** + * Returns the current authenticated person object + */ + private function _getAuthUser() + { $this->load->model('person/Person_model', 'PersonModel'); $authUser = $this->PersonModel->getByUid(getAuthUID()); - if (!hasData($authUser)) $authUser = error('The current logged user person_id is not defined'); - return $authUser; } /** - * + * Replaces data array keys to a lowercase string with underscores instead of spaces */ - public function replaceKeys($data) + private function _lowerReplaceSpaceArrayKeys($data) { $tmpData = array(); - // Replaces data array keys to a lowercase without spaces string foreach ($data as $key => $val) { $tmpData[str_replace(' ', '_', strtolower($key))] = $val; @@ -203,9 +317,9 @@ class Messages_model extends CI_Model } /** - * + * Add organisation unit to an array of prestudents (objects) */ - public function addOeToPrestudents(&$msgVarsData, $prestudentsData) + private function _addOeToPrestudents(&$msgVarsData, $prestudentsData) { for ($i = 0; $i < count(getData($msgVarsData)); $i++) { @@ -219,4 +333,127 @@ class Messages_model extends CI_Model } } } + + /** + * Perform a person log after a message is sent + */ + private function _personLog($sender_id, $receiver_id, $message_id) + { + $_personLog = $this->personloglib->log( + $receiver_id, + 'Action', + array( + 'name' => 'Message sent', + 'message' => 'Message sent from person '.$sender_id.' to '.$receiver_id.', message id: '.$message_id, + 'success' => 'true' + ), + 'kommunikation', + 'core', + null, + getAuthUID() + ); + + return $_personLog; + } + + /** + * Prepares data for the view system/messages/htmlWriteTemplate using the given parameters + */ + private function _prepareHtmlWriteTemplate($info, $message_id, $recipient_id) + { + // Checks that info parameter is valid + if (isError($info)) show_error(getData($info)); + if (!hasData($info)) show_error('No recipients were given'); + + // If the message id and recipient id are given, then both they must be valid numbers + if ((is_numeric($message_id) && !is_numeric($recipient_id)) + || (!is_numeric($message_id) && is_numeric($recipient_id))) + { + show_error('If given, message id and recipient id both must be valid numbers'); + } + + // --------------------------------------------------------------------------------------- + // Retrieves the recipients information and builds: + // - recipientsArray: an array that contains objects with id (person_id) and description (Vorname + Nachname) of recipient + // - recipientsList: a string that contains all the recipients descriptions (Vorname + Nachname) separated by ; + // - persons: a string that contains HTML input hidden with alla the receivers id (person_id) + $recipientsArray = array(); + $recipientsList = ''; + $persons = ''; + foreach (getData($info) as $receiver) + { + $recipient = new stdClass(); + $recipient->id = $receiver->person_id; + $recipient->description = $receiver->Vorname.' '.$receiver->Nachname; + + $recipientsArray[] = $recipient; + $recipientsList .= $receiver->Vorname.' '.$receiver->Nachname.'; '; + $persons .= ''."\n"; + } + + // --------------------------------------------------------------------------------------- + // Retrieves the message to reply to, if it is specified by parameters $message_id and $recipient_id + $replySubject = ''; // message reply subject + $replyBody = ''; // message reply body + $relationmessage = ''; // input hidden that contains the message id to be replied to + // If both are given and they are valid + if (is_numeric($message_id) && is_numeric($recipient_id)) + { + // Retrieves a received message from tbl_msg_recipient + $messageResult = $this->messagelib->getMessage($message_id, $recipient_id); + if (isError($messageResult)) show_error(getData($messageResult)); + if (!hasData($messageResult)) show_error('The selected message does not exist'); + + $message = getData($messageResult)[0]; + + $replySubject = self::REPLY_SUBJECT_PREFIX.$message->subject; + $replyBody = self::REPLY_BODY_PREFIX.$message->body; + $relationmessage = ''; + } + + // --------------------------------------------------------------------------------------- + // Retrieves message vars from database view vw_msg_vars_person + $variablesResult = $this->messagelib->getMessageVarsPerson(); + if (isError($variablesResult)) show_error(getData($variablesResult)); + + // Then builds an array that contains objects with id (person_id) and description (Vorname + Nachname) of recipient + $variables = array(); + foreach (getData($variablesResult) as $id => $description) + { + $tmpVar = new stdClass(); + $tmpVar->id = $id; + $tmpVar->description = $description; + + $variables[] = $tmpVar; + } + + // --------------------------------------------------------------------------------------- + // Retrieves the sender id + $authUser = $this->_getAuthUser(); + if (isError($authUser)) show_error(getData($authUser)); + if (!hasData($authUser)) show_error('The current logged user person_id is not defined'); + + $sender_id = getData($authUser)[0]->person_id; + + // --------------------------------------------------------------------------------------- + // Organisation units and a boolean (true if the sender is administrator) are used to get the templates + $organisationUnits = $this->messagelib->getOeKurzbz($sender_id); + if (isError($organisationUnits)) show_error(getData($organisationUnits)); + $senderIsAdmin = $this->BenutzerrolleModel->isAdminByPersonId($sender_id); + if (isError($senderIsAdmin)) show_error(getData($senderIsAdmin)); + + // --------------------------------------------------------------------------------------- + // Returns data as an array + return array ( + 'recipientsList' => $recipientsList, + 'subject' => $replySubject, + 'body' => $replyBody, + 'variables' => $variables, + 'organisationUnits' => getData($organisationUnits), + 'senderIsAdmin' => getData($senderIsAdmin), + 'recipientsArray' => $recipientsArray, + 'persons' => $persons, + 'relationmessage_id' => $relationmessage + ); + } } diff --git a/application/views/system/infocenter/stammdaten.php b/application/views/system/infocenter/stammdaten.php index 2b481692e..ebd812c6a 100644 --- a/application/views/system/infocenter/stammdaten.php +++ b/application/views/system/infocenter/stammdaten.php @@ -113,7 +113,7 @@
-
+  p->t('ui','nachrichtSenden'); ?> diff --git a/application/views/system/messages/htmlError.php b/application/views/system/messages/htmlError.php new file mode 100644 index 000000000..7e029b50c --- /dev/null +++ b/application/views/system/messages/htmlError.php @@ -0,0 +1,82 @@ +load->view( + 'templates/FHC-Header', + array( + 'title' => 'Message sent failure', + 'jquery' => true, + 'bootstrap' => true, + 'fontawesome' => true, + 'sbadmintemplate' => true, + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageSent.css') + ) + ); +?> + + + + + +load->view("templates/FHC-Footer"); ?> diff --git a/application/views/system/messages/messageSent.php b/application/views/system/messages/htmlSuccess.php similarity index 95% rename from application/views/system/messages/messageSent.php rename to application/views/system/messages/htmlSuccess.php index 674ccd5a0..0260c9d16 100644 --- a/application/views/system/messages/messageSent.php +++ b/application/views/system/messages/htmlSuccess.php @@ -2,7 +2,7 @@ $this->load->view( 'templates/FHC-Header', array( - 'title' => 'MessageSent', + 'title' => 'Message sent successfully', 'jquery' => true, 'bootstrap' => true, 'fontawesome' => true, @@ -17,11 +17,6 @@
- -
@@ -79,11 +74,6 @@
- - -
diff --git a/application/views/system/messages/htmlWriteTemplate.php b/application/views/system/messages/htmlWriteTemplate.php new file mode 100644 index 000000000..8ce4d670a --- /dev/null +++ b/application/views/system/messages/htmlWriteTemplate.php @@ -0,0 +1,167 @@ +load->view( + 'templates/FHC-Header', + array( + 'title' => 'Write a message', + 'jquery' => true, + 'jqueryui' => true, + 'bootstrap' => true, + 'ajaxlib' => true, + 'fontawesome' => true, + 'tinymce' => true, + 'sbadmintemplate' => true, + 'widgets' => true, + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageWrite.css'), + 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/messageWrite.js') + ) + ); +?> + + + + +load->view("templates/FHC-Footer"); ?> diff --git a/application/views/system/messages/messageWrite.php b/application/views/system/messages/messageWrite.php deleted file mode 100644 index 93caaf861..000000000 --- a/application/views/system/messages/messageWrite.php +++ /dev/null @@ -1,183 +0,0 @@ -load->view( - 'templates/FHC-Header', - array( - 'title' => 'Write a message', - 'jquery' => true, - 'jqueryui' => true, - 'bootstrap' => true, - 'ajaxlib' => true, - 'fontawesome' => true, - 'tinymce' => true, - 'sbadmintemplate' => true, - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageWrite.css'), - 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/messageWrite.js') - ) -); -?> - -
-
-
-
-
- -
-
-
-
-
-
- -
-
- 1 && $i % 10 == 0) - { - echo '
'; - } - echo $receiver->Vorname." ".$receiver->Nachname."; "; - } - ?> -
-
-
-
-
-
- -
  - subject; - } - ?> -
- -
-
-
-
-
-
- - body; - } - ?> - -
- -
-
- - -
-
- -
-
-
-
- widgetlib->widget( - 'Vorlage_widget', - array('oe_kurzbz' => $oe_kurzbz, 'isAdmin' => $isAdmin), - array('name' => 'vorlage', 'id' => 'vorlageDnD') - ); - ?> -
-
- -
-
- 0) - { - ?> -
-
-
- -
-
-
-
-
-
- - -   - Refresh -
-
-
- -
-
-
- -
- - - person_id.'">'."\n"; - } - ?> - - - - - -
-
-
-
- - -load->view("templates/FHC-Footer"); ?> diff --git a/application/views/templates/FHC-Header.php b/application/views/templates/FHC-Header.php index 43112dd7b..6b9afd6b9 100644 --- a/application/views/templates/FHC-Header.php +++ b/application/views/templates/FHC-Header.php @@ -30,6 +30,7 @@ $sbadmintemplate = isset($sbadmintemplate) ? $sbadmintemplate : false; $tablesorter = isset($tablesorter) ? $tablesorter : false; $tinymce = isset($tinymce) ? $tinymce : false; + $widgets = isset($widgets) ? $widgets : false; ?> @@ -94,6 +95,9 @@ // NavigationWidget CSS if ($navigationwidget === true) generateCSSsInclude('public/css/NavigationWidget.css'); + // HTML Widget CSS + if ($widgets === true) generateCSSsInclude('public/css/Widgets.css'); + // Eventually required CSS generateCSSsInclude($customCSSs); // Eventually required CSS diff --git a/application/views/widgets/dropdown.php b/application/views/widgets/dropdown.php index c1bdbf5c8..3db602755 100644 --- a/application/views/widgets/dropdown.php +++ b/application/views/widgets/dropdown.php @@ -37,11 +37,11 @@
- \ No newline at end of file + diff --git a/application/widgets/Dropdown_widget.php b/application/widgets/Dropdown_widget.php new file mode 100644 index 000000000..91e41e3ad --- /dev/null +++ b/application/widgets/Dropdown_widget.php @@ -0,0 +1,19 @@ +setElementsArray( + $elements, + true, + $emptyElement, + 'No data present' + ); + + $this->loadDropDownView($widgetData); + } +} diff --git a/application/widgets/MultipleDropdown_widget.php b/application/widgets/MultipleDropdown_widget.php new file mode 100644 index 000000000..a13f62492 --- /dev/null +++ b/application/widgets/MultipleDropdown_widget.php @@ -0,0 +1,20 @@ +setElementsArray( + $elements, + false, + '', + 'No data present' + ); + + $this->setMultiple(); + + $this->loadDropDownView($widgetData); + } +} diff --git a/application/widgets/html/DropdownWidget.php b/application/widgets/html/DropdownWidget.php index ca3e30163..5c28e5a9f 100644 --- a/application/widgets/html/DropdownWidget.php +++ b/application/widgets/html/DropdownWidget.php @@ -17,32 +17,32 @@ class DropdownWidget extends HTMLWidget const SELECTED_ELEMENT = 'selectedElement'; // Default HTML value const HTML_DEFAULT_VALUE = 'null'; - + const SIZE = 'size'; // size of the dropdown const MULTIPLE = 'multiple'; // multiple attribute - + // Alias of $this->_args[HTMLWidget::HTML_ARG_NAME] for a better code readability protected $htmlParameters; - + /** - * + * */ public function __construct($name, $args = array(), $htmlArgs = array()) { parent::__construct($name, $args, $htmlArgs); - + // If the selectd element is not set then set it to HTML_DEFAULT_VALUE if (!isset($this->_args[DropdownWidget::SELECTED_ELEMENT])) { $this->_args[DropdownWidget::SELECTED_ELEMENT] = DropdownWidget::HTML_DEFAULT_VALUE; } - + $this->htmlParameters =& $this->_args[HTMLWidget::HTML_ARG_NAME]; // Reference for a better code readability - + // By default is not a multiple dropdown unset($this->htmlParameters[DropdownWidget::MULTIPLE]); } - + /** * Set this dropdown as multiple: * - Setting the multiple attribute @@ -53,23 +53,23 @@ class DropdownWidget extends HTMLWidget $this->htmlParameters[DropdownWidget::MULTIPLE] = DropdownWidget::MULTIPLE; $this->htmlParameters[HTMLWidget::HTML_NAME] .= '[]'; } - + /** * Checks if this object is a multiple dropdown */ public function isMultipleDropdown() { $isMultipleDropdown = false; - + if (isset($this->htmlParameters[DropdownWidget::MULTIPLE]) && $this->htmlParameters[DropdownWidget::MULTIPLE] == DropdownWidget::MULTIPLE) { $isMultipleDropdown = true; } - + return $isMultipleDropdown; } - + /** * Add the correct select to the model used to load a list of elemets for this dropdown * @param model $model the model used to load elements @@ -88,7 +88,7 @@ class DropdownWidget extends HTMLWidget ) ); } - + /** * Set the array used to populate the dropdown * @param array $elements list used to populate this dropdown @@ -102,7 +102,7 @@ class DropdownWidget extends HTMLWidget ) { $tmpElements = array(); - + if (isError($elements)) { if (is_object($elements) && isset($elements->retval)) @@ -133,11 +133,11 @@ class DropdownWidget extends HTMLWidget { $tmpElements = $elements->retval; } - + $this->_args[DropdownWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME] = $tmpElements; } } - + /** * Adds an element to the beginning of the array */ @@ -146,17 +146,17 @@ class DropdownWidget extends HTMLWidget $element = new stdClass(); $element->{DropdownWidget::ID_FIELD} = $id; $element->{DropdownWidget::DESCRIPTION_FIELD} = $stdDescription; - + if (!hasData($elements)) { $element->{DropdownWidget::DESCRIPTION_FIELD} = $noDataDescription; } - + array_unshift($elements->retval, $element); - + return $elements->retval; } - + /** * Loads the dropdown view with all the elements to be displayed */ @@ -164,4 +164,4 @@ class DropdownWidget extends HTMLWidget { $this->view('widgets/dropdown', $this->_args); } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index d763dc5ad..c6816e075 100644 --- a/composer.json +++ b/composer.json @@ -173,6 +173,17 @@ } } }, + { + "type": "package", + "package": { + "name": "olifolkerd/tabulator", + "version": "4.2.7", + "dist": { + "url": "https://github.com/olifolkerd/tabulator/archive/4.2.7.zip", + "type": "zip" + } + } + }, { "type": "package", "package": { @@ -260,6 +271,8 @@ "netcarver/textile": "^3.5", "nicolaskruchten/pivottable": "^2.15.0", + "olifolkerd/tabulator": "4.2.7", + "phpseclib/phpseclib": "^2.0", "rmariuzzo/jquery-checkboxes": "1.0.7", diff --git a/composer.lock b/composer.lock index 8fc88ce07..f328832e6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "ddbbad487c655512e6983408339cb85f", - "content-hash": "b5902c71fe21cd14397101dba5a3080c", + "hash": "df6059a4bee974ecf5447aad8a8b1e15", + "content-hash": "2111c73853dbc47938c3f31dbc349883", "packages": [ { "name": "BlackrockDigital/startbootstrap-sb-admin-2", @@ -1198,16 +1198,16 @@ }, { "name": "netcarver/textile", - "version": "v3.7.1", + "version": "v3.7.2", "source": { "type": "git", "url": "https://github.com/textile/php-textile.git", - "reference": "377933125dd30d708804c545bf33da87a3c1b0f4" + "reference": "c24d68d9f4d099f9c2434e71024f2a6140dc1594" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/textile/php-textile/zipball/377933125dd30d708804c545bf33da87a3c1b0f4", - "reference": "377933125dd30d708804c545bf33da87a3c1b0f4", + "url": "https://api.github.com/repos/textile/php-textile/zipball/c24d68d9f4d099f9c2434e71024f2a6140dc1594", + "reference": "c24d68d9f4d099f9c2434e71024f2a6140dc1594", "shasum": "" }, "require": { @@ -1247,7 +1247,7 @@ "plaintext", "textile" ], - "time": "2019-01-26 17:03:58" + "time": "2019-06-08 17:57:17" }, { "name": "nicolaskruchten/pivottable", @@ -1260,18 +1260,29 @@ }, "type": "library" }, + { + "name": "olifolkerd/tabulator", + "version": "4.2.7", + "dist": { + "type": "zip", + "url": "https://github.com/olifolkerd/tabulator/archive/4.2.7.zip", + "reference": null, + "shasum": null + }, + "type": "library" + }, { "name": "phpseclib/phpseclib", - "version": "2.0.15", + "version": "2.0.18", "source": { "type": "git", "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "11cf67cf78dc4acb18dc9149a57be4aee5036ce0" + "reference": "60519001db8d791215a822efd366d24cafee9e63" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/11cf67cf78dc4acb18dc9149a57be4aee5036ce0", - "reference": "11cf67cf78dc4acb18dc9149a57be4aee5036ce0", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/60519001db8d791215a822efd366d24cafee9e63", + "reference": "60519001db8d791215a822efd366d24cafee9e63", "shasum": "" }, "require": { @@ -1350,7 +1361,7 @@ "x.509", "x509" ], - "time": "2019-03-10 16:53:45" + "time": "2019-06-13 06:15:54" }, { "name": "psr/log", @@ -2180,16 +2191,16 @@ }, { "name": "twig/twig", - "version": "v1.41.0", + "version": "v1.42.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "575cd5028362da591facde1ef5d7b94553c375c9" + "reference": "671347603760a88b1e7288aaa9378f33687d7edf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/575cd5028362da591facde1ef5d7b94553c375c9", - "reference": "575cd5028362da591facde1ef5d7b94553c375c9", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/671347603760a88b1e7288aaa9378f33687d7edf", + "reference": "671347603760a88b1e7288aaa9378f33687d7edf", "shasum": "" }, "require": { @@ -2199,12 +2210,12 @@ "require-dev": { "psr/container": "^1.0", "symfony/debug": "^2.7", - "symfony/phpunit-bridge": "^3.4.19|^4.1.8" + "symfony/phpunit-bridge": "^3.4.19|^4.1.8|^5.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.41-dev" + "dev-master": "1.42-dev" } }, "autoload": { @@ -2242,7 +2253,7 @@ "keywords": [ "templating" ], - "time": "2019-05-14 11:59:08" + "time": "2019-06-04 11:31:08" }, { "name": "zetacomponents/base", diff --git a/content/fasoverlay.js.php b/content/fasoverlay.js.php index 0c80221e9..3089b6032 100644 --- a/content/fasoverlay.js.php +++ b/content/fasoverlay.js.php @@ -1250,7 +1250,7 @@ function MessageNew() { var prestudentIdArray = getMultipleTreeCellText(tree, 'student-treecol-prestudent_id'); - var action = 'index.ci.php/system/FASMessages/write/' + person_id; ?>; + var action = 'index.ci.php/system/FASMessages/writeTemplate/' + person_id; ?>; openWindowPostArray(action, 'prestudent_id', prestudentIdArray); } diff --git a/content/messages.js.php b/content/messages.js.php index fae1db4ba..4094cddb8 100644 --- a/content/messages.js.php +++ b/content/messages.js.php @@ -104,7 +104,7 @@ function MessagesNewMessage() { var prestudentIdArray = getMultipleTreeCellText(tree, 'student-treecol-prestudent_id'); - var action = 'index.ci.php/system/FASMessages/write/' + MessageSenderPersonID; + var action = 'index.ci.php/system/FASMessages/writeTemplate'; openWindowPostArray(action, 'prestudent_id', prestudentIdArray); } @@ -128,7 +128,7 @@ function MessagesSendAnswer() var RecipientID = getTreeCellText(messagesTree, 'messages-tree-recipient_id', messagesTree.currentIndex); var prestudentIdArray = new Array(getTreeCellText(studentsTree, 'student-treecol-prestudent_id', studentsTree.currentIndex)); - var action = 'index.ci.php/system/FASMessages/writeReply/' + MessageSenderPersonID + '/' + MessageId + '/' + RecipientID; + var action = 'index.ci.php/system/FASMessages/writeReplyTemplate/' + MessageId + '/' + RecipientID; openWindowPostArray(action, 'prestudent_id', prestudentIdArray); } diff --git a/public/css/Widgets.css b/public/css/Widgets.css new file mode 100644 index 000000000..ef98856ea --- /dev/null +++ b/public/css/Widgets.css @@ -0,0 +1,46 @@ +.div-table { + display: table; +} + +.div-row { + display: table-row; +} + +.div-cell { + display: table-cell; +} + +.div-cell-label { + display: table-cell; +} + +label[required-field=true]::after { + content: "*"; +} + +.div-cell-data { + display: table-cell; +} + +.halign-right { + text-align: right; + margin-left: auto; + margin-right: 0; +} + +.valign-middle { + vertical-align: middle; +} + +.valign-top { + vertical-align: top; + padding-top: 1px; +} + +.width-150px { + width: 150px; +} + +.width-30px { + width: 30px; +} diff --git a/public/css/messaging/messageWrite.css b/public/css/messaging/messageWrite.css index 91b20729f..3b5e1fd0e 100644 --- a/public/css/messaging/messageWrite.css +++ b/public/css/messaging/messageWrite.css @@ -21,4 +21,9 @@ input[type=text] { #sendButton { width: 120px; -} \ No newline at end of file +} + +/* Overwrites the Widget.css class */ +div .width-150px { + width: 200px; +} diff --git a/public/js/infocenter/infocenterDetails.js b/public/js/infocenter/infocenterDetails.js index a43b36df8..3edb9d42d 100644 --- a/public/js/infocenter/infocenterDetails.js +++ b/public/js/infocenter/infocenterDetails.js @@ -629,7 +629,7 @@ var InfocenterDetails = { sendFreigabeMessage: function(prestudentid, vorlage_kurzbz, msgvars) { FHC_AjaxClient.ajaxCallPost( - 'system/Messages/sendJson', + 'system/Messages/sendExplicitTemplateJson', { "prestudents": prestudentid, "vorlage_kurzbz": vorlage_kurzbz, diff --git a/public/js/infocenter/infocenterPersonDataset.js b/public/js/infocenter/infocenterPersonDataset.js index dc6af2284..c5ea99dfc 100644 --- a/public/js/infocenter/infocenterPersonDataset.js +++ b/public/js/infocenter/infocenterPersonDataset.js @@ -26,7 +26,7 @@ var InfocenterPersonDataset = { appendTableActionsHtml: function() { var currurl = window.location.href; - var url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + "/system/Messages/write"; + var url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + "/system/Messages/writeTemplate"; var formHtml = '
'; $("#datasetActionsTop").before(formHtml); diff --git a/public/js/messaging/messageWrite.js b/public/js/messaging/messageWrite.js index 9894573ee..c496b269d 100644 --- a/public/js/messaging/messageWrite.js +++ b/public/js/messaging/messageWrite.js @@ -1,5 +1,5 @@ /** - * JS used by view system/messages/messageWrite + * JS used by view system/messages/htmlWriteTemplate */ function tinymcePreviewSetContent() From 99570978c3676346d42b6becc7a87396a9bd86b6 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 19 Jun 2019 14:51:54 +0200 Subject: [PATCH 07/72] - Renamed view system/messages/messageHTML to system/messages/htmlRead - Renamed view system/messages/messageWriteReply to system/messages/htmlWriteReply - Removed views system/messages/messageReplySent and system/messages/messageForm - Moved logic from controller ViewMessage to model CL/Messages_model - Added new constants CFG_REDIRECT_VIEW_MESSAGE_URL to MessageLib - Removed public method getPersonData from model system/MessageToken_model - Changed query in method system/Recipient_model->getMessage to include column tbl_msg_recipient.sent - Added new public method prepareHtmlRead to model CL/Messages_model - Changed constant REPLY_BODY_FORMAT of model CL/Messages_model - Added new constant NO_AUTH_UID to model CL/Messages_model - Added new public method prepareHtmlWriteReply to model CL/Messages_model - Changed public method sendReply of model CL/Messages_model - Added new private method _getReplyBody to model CL/Messages_model - Changed method _personLog of model CL/Messages_model to manage not authenticated users --- application/controllers/ViewMessage.php | 107 ++-------- application/libraries/MessageLib.php | 1 + application/models/CL/Messages_model.php | 183 +++++++++++++----- .../models/system/MessageToken_model.php | 65 +------ application/models/system/Recipient_model.php | 3 +- .../{messageHTML.php => htmlRead.php} | 23 ++- .../views/system/messages/htmlWriteReply.php | 73 +++++++ .../views/system/messages/messageForm.php | 81 -------- .../system/messages/messageReplySent.php | 103 ---------- .../system/messages/messageWriteReply.php | 63 ------ 10 files changed, 242 insertions(+), 460 deletions(-) rename application/views/system/messages/{messageHTML.php => htmlRead.php} (87%) create mode 100644 application/views/system/messages/htmlWriteReply.php delete mode 100644 application/views/system/messages/messageForm.php delete mode 100644 application/views/system/messages/messageReplySent.php delete mode 100644 application/views/system/messages/messageWriteReply.php diff --git a/application/controllers/ViewMessage.php b/application/controllers/ViewMessage.php index 3c22c8977..9c6fc4c4e 100644 --- a/application/controllers/ViewMessage.php +++ b/application/controllers/ViewMessage.php @@ -16,14 +16,10 @@ if (!defined('BASEPATH')) exit('No direct script access allowed'); /** * Handles sending messages with token - * NOTE: in this controller is not possible to include/call everything - * that automatically call the authentication system, like the most of models or libraries + * NOTE: it extends FHC_Controller instead of Auth_Controller because authentication is not needed */ class ViewMessage extends FHC_Controller { - /** - * API constructor - */ public function __construct() { parent::__construct(); @@ -32,121 +28,48 @@ class ViewMessage extends FHC_Controller $this->config->load('message'); // Load model MessageToken_model, not calling the authentication system - $this->load->model('system/MessageToken_model', 'MessageTokenModel'); $this->load->model('CL/Messages_model', 'CLMessagesModel'); } /** - * Using the MessageTokenModel instead of MessageLib to allow - * viewing the message without prompting the login + * Display a message in read mode only using the specified token */ public function toHTML($token) { - $msg = $this->MessageTokenModel->getMessageByToken($token); - - if ($msg->error) - { - show_error(getData($msg)); - } - - if (is_array(getData($msg)) && count(getData($msg)) > 0) - { - $setReadMessageStatusByToken = $this->MessageTokenModel->setReadMessageStatusByToken($token); - - if (isError($setReadMessageStatusByToken)) - { - show_error($msg->$setReadMessageStatusByToken); - } - - $sender_id = getData($msg)[0]->sender_id; - $receiver_id = getData($msg)[0]->receiver_id; - $sender = $this->MessageTokenModel->getSenderData($sender_id); - - // To decide how to change the redirection - $isEmployee = $this->MessageTokenModel->isEmployee($receiver_id); - if (!is_bool($isEmployee) && isError($isEmployee)) - { - show_error($isEmployee); - } - - if($this->config->item('redirect_view_message_url') != '') - $href = $this->config->item('message_server').$this->config->item('redirect_view_message_url').$token; - else - $href = ''; - - $data = array ( - 'sender_id' => $sender_id, - 'sender' => getData($sender)[0], - 'message' => getData($msg)[0], - 'isEmployee' => $isEmployee, - 'href' => $href - ); - - $this->load->view('system/messages/messageHTML.php', $data); - } + // Loads the view to read a received message using its token as identifier + $this->load->view('system/messages/htmlRead', $this->CLMessagesModel->prepareHtmlRead($token)); } /** - * write the reply + * Write a reply message to a received one using its token as identifier */ public function writeReply() { - $token = $this->input->get('token'); + $token = $this->input->get('token'); // gets received message token - if (isEmptyString($token)) - { - show_error('No token supplied'); - } - - $msg = null; - - // Get message data if possible - $msg = $this->MessageTokenModel->getMessageByToken($token); - if (!hasData($msg)) - { - show_error('No message found'); - } - - $msg = getData($msg)[0]; - - // Get variables - $receiverData = $this->MessageTokenModel->getPersonData($msg->sender_id); - if (!hasData($receiverData)) - { - show_error('No sender found'); - } - - $data = array ( - 'receivers' => getData($receiverData), - 'message' => $msg, - 'token' => $token - ); - - $this->load->view('system/messages/messageWriteReply', $data); + // Loads the view to write a reply message + $this->load->view('system/messages/htmlWriteReply', $this->CLMessagesModel->prepareHtmlWriteReply($token)); } /** - * Send a reply + * Send a reply message (no templates are used) */ public function sendReply() { $subject = $this->input->post('subject'); $body = $this->input->post('body'); - $persons = $this->input->post('persons'); + $receiver_id = $this->input->post('receiver_id'); $relationmessage_id = $this->input->post('relationmessage_id'); $token = $this->input->post('token'); - if (!isset($relationmessage_id) || $relationmessage_id == '' || !isset($token) || $token == '') + $sendReply = $this->CLMessagesModel->sendReply($receiver_id, $subject, $body, $relationmessage_id, $token); + if (isSuccess($sendReply)) { - show_error('Error while sending reply'); + $this->load->view('system/messages/htmlSuccess'); } - - $sendReply = $this->CLMessagesModel->sendReply($subject, $body, $persons, $relationmessage_id, $token); - if (isError($sendReply)) + else { - show_error(getData($sendReply)); + $this->load->view('system/messages/htmlError'); } - - $this->load->view('system/messages/messageReplySent'); } } diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 7bf6b7518..206aeed87 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -13,6 +13,7 @@ class MessageLib const CFG_MESSAGE_SERVER = 'message_server'; const CFG_MESSAGE_HTML_VIEW_URL = 'message_html_view_url'; const CFG_OU_RECEIVERS = 'ou_receivers'; + const CFG_REDIRECT_VIEW_MESSAGE_URL = 'redirect_view_message_url'; // Templates names const NOTICE_TEMPLATE_HTML = 'MessageMailHTML'; diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index 05eaa8b16..33bc90e80 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -8,7 +8,9 @@ class Messages_model extends CI_Model { const REPLY_SUBJECT_PREFIX = 'Re: '; - const REPLY_BODY_PREFIX = '

-------------------------------------------------------------------------------'; + const REPLY_BODY_FORMAT = '

On %s %s %s wrote:
%s
'; + + const NO_AUTH_UID = 'online'; // hard coded uid if no authentication is performed /** * Constructor @@ -34,6 +36,87 @@ class Messages_model extends CI_Model //------------------------------------------------------------------------------------------------------------------ // Public methods + /** + * Prepares data for the view system/messages/htmlRead using a token that identifies a single message + */ + public function prepareHtmlRead($token) + { + if (isEmptyString($token)) show_error('The given token is not valid'); + + // Retrieves message using the given token + $messageResult = $this->MessageTokenModel->getMessageByToken($token); + if (isError($messageResult)) show_error(getData($messageResult)); + if (!hasData($messageResult)) show_error('No message found with the given token'); + + $message = getData($messageResult)[0]; // Found message data + + // Set message as read + $srmsbtResult = $this->MessageTokenModel->setReadMessageStatusByToken($token); + if (isError($srmsbtResult)) show_error(getData($srmsbtResult)); + + // Retrieves message sender information + $senderResult = $this->MessageTokenModel->getSenderData($message->sender_id); + if (isError($senderResult)) show_error(getData($senderResult)); + if (!hasData($senderResult)) show_error('No sender information found'); + + $sender = getData($senderResult)[0]; // Found sender data + + // Check if the receiver is an employee + $isEmployee = false; // not by default + $isEmployeeResult = $this->MessageTokenModel->isEmployee($message->receiver_id); + if (isError($isEmployeeResult)) show_error(getData($isEmployeeResult)); + if (hasData($isEmployeeResult)) $isEmployee = true; + + // If the sender is an employee and are present configurations to reply + $hrefReply = ''; + if ($isEmployee && !isEmptyString($this->config->item(MessageLib::CFG_REDIRECT_VIEW_MESSAGE_URL))) + { + $hrefReply = $this->config->item(MessageLib::CFG_MESSAGE_SERVER). + $this->config->item(MessageLib::CFG_REDIRECT_VIEW_MESSAGE_URL). + $token; + } + + return array ( + 'sender' => $sender, + 'message' => $message, + 'hrefReply' => $hrefReply + ); + } + + /** + * Prepares data for the view system/messages/htmlWriteReply using a token that identifies a single message + */ + public function prepareHtmlWriteReply($token) + { + if (isEmptyString($token)) show_error('The given token is not valid'); + + // Retrieves message using the given token + $messageResult = $this->MessageTokenModel->getMessageByToken($token); + if (isError($messageResult)) show_error(getData($messageResult)); + if (!hasData($messageResult)) show_error('No message found with the given token'); + + $message = getData($messageResult)[0]; // Found message data + + // Retrieves message sender information + $senderResult = $this->MessageTokenModel->getSenderData($message->sender_id); + if (isError($senderResult)) show_error(getData($senderResult)); + if (!hasData($senderResult)) show_error('No sender information found'); + + $sender = getData($senderResult)[0]; // Found sender data + + $replySubject = self::REPLY_SUBJECT_PREFIX.$message->subject; + $replyBody = $this->_getReplyBody($message->body, $sender->vorname, $sender->nachname, $message->sent); + + return array ( + 'receiver' => $sender->vorname.' '.$sender->nachname, // yep! the sender of the sent message is the receiver of the reply message + 'subject' => $replySubject, + 'body' => $replyBody, + 'receiver_id' => $message->sender_id, + 'relationmessage_id' => $message->message_id, + 'token' => $token + ); + } + /** * Prepares data for the view system/messages/htmlWriteTemplate using person ids as main parameter * Wrap method to _prepareHtmlWriteTemplate @@ -158,62 +241,45 @@ class Messages_model extends CI_Model } /** - * Send a reply to a message accessed using a token + * Send a reply to a single recipient for a message identified by a token (no templates are used) */ - public function sendReply($subject, $body, $persons, $relationmessage_id, $token) + public function sendReply($receiver_id, $subject, $body, $relationmessage_id, $token) { - $relationmsg = $this->MessageTokenModel->getMessageByToken($token); - if (!hasData($relationmsg) || $relationmessage_id !== getData($relationmsg)[0]->message_id) + // Retrieves message sender information + $senderResult = $this->MessageTokenModel->getSenderData($receiver_id); + if (isError($senderResult)) show_error(getData($senderResult)); + if (!hasData($senderResult)) show_error('No sender information found'); + + $sender = getData($senderResult)[0]; // Found sender data + + $messageResult = $this->MessageTokenModel->getMessageByToken($token); + if (isError($messageResult)) show_error(getData($messageResult)); + // Security check! It is possible to reply only to a received message!! + if (!hasData($messageResult) || $relationmessage_id != getData($messageResult)[0]->message_id) { - show_error('Error while sending reply'); + show_error('An error occurred while sending your message, please contact the site administrator'); } - // Get sender (receiver of previous msg) - $sender_id = getData($relationmsg)[0]->receiver_id; + $sender_id = getData($messageResult)[0]->receiver_id; - // Get message data of persons - $data = $this->MessageTokenModel->getPersonData($persons); - if (hasData($data)) - { - for ($i = 0; $i < count(getData($data)); $i++) - { - $dataArray = (array)getData($data)[$i]; + $message = $this->messagelib->sendMessageUser( + $receiver_id, // receiverPersonId + $subject, // subject + $body, // body + $sender_id, // sender_id, the receiver of the previous message is the sender of the current one + null, // senderOU + $relationmessage_id, // relationmessage_id + MSG_PRIORITY_NORMAL // priority + ); - $msg = $this->messagelib->sendMessageUser( - $dataArray['person_id'], // receiverPersonId - $subject, // subject - $body, // body - $sender_id, // sender_id - null, // senderOU - $relationmessage_id, // relationmessage_id - MSG_PRIORITY_NORMAL // priority - ); + if (isError($message)) return $message; + if (!hasData($message)) return error('No messages were saved in database'); - if (isError($msg)) return $msg; + // Write log entry + $personLog = $this->_personLog($sender_id, $receiver_id, getData($message)[0]); + if (isError($personLog)) return $personLog; - // Logs person data - $personLog = $this->personloglib->log( - $sender_id, - 'Action', - array( - 'name' => 'Message sent', - 'message' => 'Message sent from person '.$sender_id.' to '.$dataArray['person_id'].', messageid '.getData($msg), - 'success' => 'true' - ), - 'kommunikation', - 'core', - null, - 'online' - ); - - // Unpark bewerber after he sends message - $personLog = $this->personloglib->unPark($sender_id); - - if (isError($personLog)) return $personLog; - } - } - - return success('Reply sent'); + return success('Messages sent successfully'); } //------------------------------------------------------------------------------------------------------------------ @@ -339,7 +405,11 @@ class Messages_model extends CI_Model */ private function _personLog($sender_id, $receiver_id, $message_id) { - $_personLog = $this->personloglib->log( + // In case the message is accessed via ViewMessage controller -> no authentication + // If no authentication is performed then use a hard coded uid + $loggedUserUID = function_exists('getAuthUID') ? getAuthUID() : self::NO_AUTH_UID; + + return $this->personloglib->log( $receiver_id, 'Action', array( @@ -350,10 +420,19 @@ class Messages_model extends CI_Model 'kommunikation', 'core', null, - getAuthUID() + $loggedUserUID ); + } - return $_personLog; + /** + * + */ + private function _getReplyBody($body, $receiverName, $receiverSurname, $sentDate) + { + return sprintf( + self::REPLY_BODY_FORMAT, + date_format(date_create($sentDate), 'd.m.Y H:i'), $receiverName, $receiverSurname, $body + ); } /** @@ -407,7 +486,7 @@ class Messages_model extends CI_Model $message = getData($messageResult)[0]; $replySubject = self::REPLY_SUBJECT_PREFIX.$message->subject; - $replyBody = self::REPLY_BODY_PREFIX.$message->body; + $replyBody = $this->_getReplyBody($message->body, $receiver->Vorname, $receiver->Nachname, $message->sent); $relationmessage = ''; } diff --git a/application/models/system/MessageToken_model.php b/application/models/system/MessageToken_model.php index 2398bf57a..bdb6136ac 100644 --- a/application/models/system/MessageToken_model.php +++ b/application/models/system/MessageToken_model.php @@ -152,45 +152,7 @@ class MessageToken_model extends DB_Model LEFT JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid) WHERE p.person_id = ?'; - $result = $this->db->query($sql, array($person_id)); - - // If no errors occurred - if ($result) - { - return success($result->result()); - } - else - { - return error($this->db->error()); - } - } - - /** - * Get data of a person - */ - public function getPersonData($person_id) - { - $sql = 'SELECT person_id, - vorname as "Vorname", - nachname as "Nachname", - anrede as "Anrede", - titelpost as "TitelPost", - titelpre as "TitelPre", - vornamen as "Vornamen" - FROM public.tbl_person - WHERE person_id %s ?'; - - $result = $this->db->query(sprintf($sql, is_array($person_id) ? 'IN' : '='), array($person_id)); - - // If no errors occurred - if ($result) - { - return success($result->result()); - } - else - { - return error($this->db->error()); - } + return $this->execQuery($sql, array($person_id)); } /** @@ -205,30 +167,7 @@ class MessageToken_model extends DB_Model WHERE p.person_id = ? AND b.aktiv = TRUE'; - $result = $this->db->query($sql, array($person_id)); - - // If no errors occurred - if ($result) - { - // If data are present - if (is_array($result->result()) && count($result->result()) > 0) - { - $personresults = $result->result(); - $person = $personresults[0]; - - // If it is an employee - if ($person->mitarbeiter_uid != null) - { - return true; - } - } - - return false; - } - else - { - return error($this->db->error()); - } + return $this->execQuery($sql, array($person_id)); } /** diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 3a30bba1f..65812580e 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -25,7 +25,8 @@ class Recipient_model extends DB_Model ks.kontakt, p.nachname, p.vorname, - b.uid + b.uid, + mr.sent FROM public.tbl_msg_recipient mr INNER JOIN public.tbl_msg_message mm USING (message_id) INNER JOIN public.tbl_person p ON (mm.person_id = p.person_id) LEFT JOIN public.tbl_benutzer b ON (mr.person_id = b.person_id) diff --git a/application/views/system/messages/messageHTML.php b/application/views/system/messages/htmlRead.php similarity index 87% rename from application/views/system/messages/messageHTML.php rename to application/views/system/messages/htmlRead.php index 0ae6c3866..97751f96f 100644 --- a/application/views/system/messages/messageHTML.php +++ b/application/views/system/messages/htmlRead.php @@ -1,4 +1,4 @@ - load->view( 'templates/FHC-Header', array( @@ -10,7 +10,7 @@ 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageReply.css') ) ); - ?> +?>
@@ -24,7 +24,9 @@
+ subject; ?> +
@@ -33,7 +35,9 @@ From: @@ -41,7 +45,9 @@ Subject: @@ -49,7 +55,9 @@ Message:
+ vorname.' '.$sender->nachname; ?> +
+ subject; ?> +
+ body; ?> +
@@ -57,11 +65,15 @@ @@ -72,4 +84,5 @@
- load->view("templates/FHC-Footer"); ?> \ No newline at end of file + +load->view("templates/FHC-Footer"); ?> diff --git a/application/views/system/messages/htmlWriteReply.php b/application/views/system/messages/htmlWriteReply.php new file mode 100644 index 000000000..fe8145613 --- /dev/null +++ b/application/views/system/messages/htmlWriteReply.php @@ -0,0 +1,73 @@ +load->view( + 'templates/FHC-Header', + array( + 'title' => 'MessageReply', + 'jquery' => true, + 'bootstrap' => true, + 'fontawesome' => true, + 'tinymce' => true, + 'sbadmintemplate' => true, + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageWrite.css'), + 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/messageWriteReply.js') + ) + ); +?> + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+ + + +
+
+
+
+
+
+ +
+   +
+ +
+
+
+
+
+
+ + +
+
+
+
+
+ +
+
+ + + + + +
+
+
+
+ + +load->view("templates/FHC-Footer"); ?> diff --git a/application/views/system/messages/messageForm.php b/application/views/system/messages/messageForm.php deleted file mode 100644 index d1436a492..000000000 --- a/application/views/system/messages/messageForm.php +++ /dev/null @@ -1,81 +0,0 @@ -
-
-
- -
-
- 1 && $i % 10 == 0) - { - echo '
'; - } - echo $receiver->Vorname." ".$receiver->Nachname."; "; - } - ?> -
-
-
-
-
-
- -
  - subject; - } - ?> -
- -
-
-
-
-
-
- -

On '.date_format(date_create($message->sent), 'd.m.Y H:i').' '.$receivers[0]->Vorname.' '.$receivers[0]->Nachname.' wrote:'.'
'; - $body .= '
'; - $body .= $message->body.'
'; - } - ?> - -
- -
-
- - -
-
- -
-
-
-
- -
-
\ No newline at end of file diff --git a/application/views/system/messages/messageReplySent.php b/application/views/system/messages/messageReplySent.php deleted file mode 100644 index 88fc945b0..000000000 --- a/application/views/system/messages/messageReplySent.php +++ /dev/null @@ -1,103 +0,0 @@ -load->view( - 'templates/FHC-Header', - array( - 'title' => 'MessageSent', - 'jquery' => true, - 'bootstrap' => true, - 'fontawesome' => true, - 'sbadmintemplate' => true, - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageSent.css') - ) - ); -?> - - -
-
-
- -
- -
- -
- -
- -
- -
- -
-
-
-
-
-
- Message sent successfully! -
-
- Nachricht erfolgreich versandt! -
-
-
-
-
-
- - Thank you for your message. - - - We will get back to you shortly. - -
-
- - Herzlichen Dank für Ihre Nachricht. - - - Wir werden uns schnellstmöglich um Ihr Anliegen kümmern. - -
-
- -
- -
-
- You can safely close this window. -
-
- Sie können dieses Fenster schließen. -
-
-
-
-
- Your InfoCenter@FHTW Team -
-
- Ihr InfoCenter@FHTW Team -
-
-
-
-
-
-
-

- Fachhochschule Technikum Wien | University of Applied Sciences Technikum Wien -
Hoechstaedtplatz 6, 1200 Wien, AUSTRIA -
www.technikum-wien.at -

-
-
-
-
-
-
-
- - -load->view("templates/FHC-Footer"); ?> diff --git a/application/views/system/messages/messageWriteReply.php b/application/views/system/messages/messageWriteReply.php deleted file mode 100644 index 344871b2d..000000000 --- a/application/views/system/messages/messageWriteReply.php +++ /dev/null @@ -1,63 +0,0 @@ -load->view( - 'templates/FHC-Header', - array( - 'title' => 'MessageReply', - 'jquery' => true, - 'bootstrap' => true, - 'fontawesome' => true, - 'tinymce' => true, - 'sbadmintemplate' => true, - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageWrite.css'), - 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/messageWriteReply.js') - ) -); -?> - - -
-
-
-
-
- -
-
-
- load->view('system/messages/messageForm.php'); - - for ($i = 0; $i < count($receivers); $i++) - { - $receiver = $receivers[$i]; - $receiverid = $receiver->person_id; - $fieldname = 'persons[]'; - - echo ''."\n"; - } - ?> - - - - - - - -
-
-
-
- - -load->view("templates/FHC-Footer"); ?> From b364cfae06348790fec1e7b84fd3ba8917e0b65a Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 19 Jun 2019 15:29:17 +0200 Subject: [PATCH 08/72] - Moved controllers FASMessages and Messages to system/messages/ - Adapted code to use the new path --- application/controllers/system/{ => messages}/FASMessages.php | 0 application/controllers/system/{ => messages}/Messages.php | 0 application/models/CL/Messages_model.php | 2 +- application/views/system/infocenter/stammdaten.php | 2 +- application/views/system/messages/htmlWriteTemplate.php | 2 +- content/fasoverlay.js.php | 2 +- content/messages.js.php | 4 ++-- public/js/infocenter/infocenterDetails.js | 2 +- public/js/infocenter/infocenterPersonDataset.js | 2 +- public/js/infocenter/messageList.js | 2 +- public/js/messaging/messageWrite.js | 4 ++-- 11 files changed, 11 insertions(+), 11 deletions(-) rename application/controllers/system/{ => messages}/FASMessages.php (100%) rename application/controllers/system/{ => messages}/Messages.php (100%) diff --git a/application/controllers/system/FASMessages.php b/application/controllers/system/messages/FASMessages.php similarity index 100% rename from application/controllers/system/FASMessages.php rename to application/controllers/system/messages/FASMessages.php diff --git a/application/controllers/system/Messages.php b/application/controllers/system/messages/Messages.php similarity index 100% rename from application/controllers/system/Messages.php rename to application/controllers/system/messages/Messages.php diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index 33bc90e80..302e51340 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -283,7 +283,7 @@ class Messages_model extends CI_Model } //------------------------------------------------------------------------------------------------------------------ - // Public methods called by controller system/Messages + // Public methods called by controller system/messages/Messages /** * Returns an object that represent a template store in database diff --git a/application/views/system/infocenter/stammdaten.php b/application/views/system/infocenter/stammdaten.php index ebd812c6a..a80439bfe 100644 --- a/application/views/system/infocenter/stammdaten.php +++ b/application/views/system/infocenter/stammdaten.php @@ -113,7 +113,7 @@ - +
diff --git a/content/fasoverlay.js.php b/content/fasoverlay.js.php index 3089b6032..2fafb5ea8 100644 --- a/content/fasoverlay.js.php +++ b/content/fasoverlay.js.php @@ -1250,7 +1250,7 @@ function MessageNew() { var prestudentIdArray = getMultipleTreeCellText(tree, 'student-treecol-prestudent_id'); - var action = 'index.ci.php/system/FASMessages/writeTemplate/' + person_id; ?>; + var action = 'index.ci.php/system/messages/FASMessages/writeTemplate/' + person_id; ?>; openWindowPostArray(action, 'prestudent_id', prestudentIdArray); } diff --git a/content/messages.js.php b/content/messages.js.php index 4094cddb8..3e72748ec 100644 --- a/content/messages.js.php +++ b/content/messages.js.php @@ -104,7 +104,7 @@ function MessagesNewMessage() { var prestudentIdArray = getMultipleTreeCellText(tree, 'student-treecol-prestudent_id'); - var action = 'index.ci.php/system/FASMessages/writeTemplate'; + var action = 'index.ci.php/system/messages/FASMessages/writeTemplate'; openWindowPostArray(action, 'prestudent_id', prestudentIdArray); } @@ -128,7 +128,7 @@ function MessagesSendAnswer() var RecipientID = getTreeCellText(messagesTree, 'messages-tree-recipient_id', messagesTree.currentIndex); var prestudentIdArray = new Array(getTreeCellText(studentsTree, 'student-treecol-prestudent_id', studentsTree.currentIndex)); - var action = 'index.ci.php/system/FASMessages/writeReplyTemplate/' + MessageId + '/' + RecipientID; + var action = 'index.ci.php/system/messages/FASMessages/writeReplyTemplate/' + MessageId + '/' + RecipientID; openWindowPostArray(action, 'prestudent_id', prestudentIdArray); } diff --git a/public/js/infocenter/infocenterDetails.js b/public/js/infocenter/infocenterDetails.js index 3edb9d42d..60da695d2 100644 --- a/public/js/infocenter/infocenterDetails.js +++ b/public/js/infocenter/infocenterDetails.js @@ -629,7 +629,7 @@ var InfocenterDetails = { sendFreigabeMessage: function(prestudentid, vorlage_kurzbz, msgvars) { FHC_AjaxClient.ajaxCallPost( - 'system/Messages/sendExplicitTemplateJson', + 'system/messages/Messages/sendExplicitTemplateJson', { "prestudents": prestudentid, "vorlage_kurzbz": vorlage_kurzbz, diff --git a/public/js/infocenter/infocenterPersonDataset.js b/public/js/infocenter/infocenterPersonDataset.js index c5ea99dfc..07163ccee 100644 --- a/public/js/infocenter/infocenterPersonDataset.js +++ b/public/js/infocenter/infocenterPersonDataset.js @@ -26,7 +26,7 @@ var InfocenterPersonDataset = { appendTableActionsHtml: function() { var currurl = window.location.href; - var url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + "/system/Messages/writeTemplate"; + var url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + "/system/messages/Messages/writeTemplate"; var formHtml = ''; $("#datasetActionsTop").before(formHtml); diff --git a/public/js/infocenter/messageList.js b/public/js/infocenter/messageList.js index 85d5ad603..6146c7639 100644 --- a/public/js/infocenter/messageList.js +++ b/public/js/infocenter/messageList.js @@ -54,7 +54,7 @@ var MessageList = { var recid = id.substr(id.indexOf('_') + 1); FHC_AjaxClient.ajaxCallGet( - 'system/Messages/getMessageFromIds', + 'system/messages/Messages/getMessageFromIds', { "msg_id": msgid, "receiver_id": recid diff --git a/public/js/messaging/messageWrite.js b/public/js/messaging/messageWrite.js index c496b269d..4146b7008 100644 --- a/public/js/messaging/messageWrite.js +++ b/public/js/messaging/messageWrite.js @@ -20,7 +20,7 @@ function tinymcePreviewSetContent() function parseMessageText(receiver_id, text) { FHC_AjaxClient.ajaxCallGet( - "system/Messages/parseMessageText", + "system/messages/Messages/parseMessageText", { person_id: receiver_id, text: text @@ -111,7 +111,7 @@ $(document).ready(function () if (vorlage_kurzbz != '') { FHC_AjaxClient.ajaxCallGet( - "system/Messages/getVorlage", + "system/messages/Messages/getVorlage", { vorlage_kurzbz: vorlage_kurzbz }, From 1cb9c28f7dfecb35559635188372df7234824879 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 19 Jun 2019 17:53:51 +0200 Subject: [PATCH 09/72] - Added new controller system/messages/MessageClient used to read and write messages using a new GUI based on ajax and tabulator - system/messages/MessageClient currently has only two methods: read and listMessages - Added new view system/messages/ajaxRead.php used for the GUI to read messages - Added new parameters to templates/FHC-Header: tabulator and momentjs - Added new packages to composer: tabulator and momentjs --- .../system/messages/MessageClient.php | 39 +++++++++++++++++++ .../controllers/system/messages/Messages.php | 6 +-- .../views/system/messages/ajaxRead.php | 20 ++++++++++ .../views/system/messages/htmlRead.php | 2 +- .../views/system/messages/htmlWriteReply.php | 2 +- .../system/messages/htmlWriteTemplate.php | 2 +- application/views/templates/FHC-Header.php | 30 ++++++++------ composer.json | 12 ++++++ composer.lock | 25 ++++++++---- 9 files changed, 114 insertions(+), 24 deletions(-) create mode 100644 application/controllers/system/messages/MessageClient.php create mode 100644 application/views/system/messages/ajaxRead.php diff --git a/application/controllers/system/messages/MessageClient.php b/application/controllers/system/messages/MessageClient.php new file mode 100644 index 000000000..3000e6b91 --- /dev/null +++ b/application/controllers/system/messages/MessageClient.php @@ -0,0 +1,39 @@ + array('basis/message:r'), + 'listMessages' => array('basis/message:r') + ) + ); + + // Loads model CLMessagesModel which contains the GUI logic + $this->load->model('CL/Messages_model', 'CLMessagesModel'); + } + + /** + * Starts the GUI used to read all the personal messages + */ + public function read() + { + // Loads the view to read messages + $this->load->view('system/messages/ajaxRead'); + } + + /** + * Returns JSON that that contains all the received messages by the currently logged user + * This JSON structure is nested data used by tabulator + */ + public function listMessages() + { + $jsonNestedData = $this->CLMessagesModel->prepareAjaxRead(); + + $this->outputJson($jsonNestedData); + } +} diff --git a/application/controllers/system/messages/Messages.php b/application/controllers/system/messages/Messages.php index 20fed38ad..869caec39 100644 --- a/application/controllers/system/messages/Messages.php +++ b/application/controllers/system/messages/Messages.php @@ -30,7 +30,7 @@ class Messages extends Auth_Controller } // ----------------------------------------------------------------------------------------------------------------- - // Public methods - HTML output + // Methods with HTML output /** * Initialize all the parameters used by view system/messages/htmlWriteTemplate @@ -71,7 +71,7 @@ class Messages extends Auth_Controller } // ----------------------------------------------------------------------------------------------------------------- - // Public methods - JSON output - called by this controller and FASMessages (view system/messages/htmlWriteTemplate) + // Methods with JSON output called by this controller and FASMessages (view system/messages/htmlWriteTemplate) /** * Returns an object that represent a template store in database @@ -98,7 +98,7 @@ class Messages extends Auth_Controller } // ----------------------------------------------------------------------------------------------------------------- - // Public methods - JSON output - called by infocenter + // Methods with JSON output called by infocenter /** * Outputs message data for a message (identified my msg id and receiver id) in JSON format diff --git a/application/views/system/messages/ajaxRead.php b/application/views/system/messages/ajaxRead.php new file mode 100644 index 000000000..97f16ce3b --- /dev/null +++ b/application/views/system/messages/ajaxRead.php @@ -0,0 +1,20 @@ +load->view( + 'templates/FHC-Header', + array( + 'title' => 'Read personal messages', + 'jquery' => true, + 'bootstrap' => true, + 'momentjs' => true, + 'tabulator' => true, + 'ajaxlib' => true, + 'customJSs' => array('public/js/messaging/messageClient.js') + ) + ); +?> + +
+
+ + +load->view("templates/FHC-Footer"); ?> diff --git a/application/views/system/messages/htmlRead.php b/application/views/system/messages/htmlRead.php index 97751f96f..01a5421ac 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' => 'MessageSent', + 'title' => 'Read a message', 'jquery' => true, 'bootstrap' => true, 'fontawesome' => true, diff --git a/application/views/system/messages/htmlWriteReply.php b/application/views/system/messages/htmlWriteReply.php index fe8145613..b9932148b 100644 --- a/application/views/system/messages/htmlWriteReply.php +++ b/application/views/system/messages/htmlWriteReply.php @@ -2,7 +2,7 @@ $this->load->view( 'templates/FHC-Header', array( - 'title' => 'MessageReply', + 'title' => 'Reply to a message', 'jquery' => true, 'bootstrap' => true, 'fontawesome' => true, diff --git a/application/views/system/messages/htmlWriteTemplate.php b/application/views/system/messages/htmlWriteTemplate.php index f46138e28..7132cfb36 100644 --- a/application/views/system/messages/htmlWriteTemplate.php +++ b/application/views/system/messages/htmlWriteTemplate.php @@ -2,7 +2,7 @@ $this->load->view( 'templates/FHC-Header', array( - 'title' => 'Write a message', + 'title' => 'Write a new message or reply using templates', 'jquery' => true, 'jqueryui' => true, 'bootstrap' => true, diff --git a/application/views/templates/FHC-Header.php b/application/views/templates/FHC-Header.php index 6b9afd6b9..7b75e2ad7 100644 --- a/application/views/templates/FHC-Header.php +++ b/application/views/templates/FHC-Header.php @@ -25,10 +25,12 @@ $jqueryui = isset($jqueryui) ? $jqueryui : false; $jquerycheckboxes = isset($jquerycheckboxes) ? $jquerycheckboxes : false; $jquerytreetable = isset($jquerytreetable) ? $jquerytreetable : false; + $momentjs = isset($momentjs) ? $momentjs : false; $navigationwidget = isset($navigationwidget) ? $navigationwidget : false; $pivotui = isset($pivotui) ? $pivotui : false; $sbadmintemplate = isset($sbadmintemplate) ? $sbadmintemplate : false; $tablesorter = isset($tablesorter) ? $tablesorter : false; + $tabulator = isset($tabulator) ? $tabulator : false; $tinymce = isset($tinymce) ? $tinymce : false; $widgets = isset($widgets) ? $widgets : false; ?> @@ -61,10 +63,7 @@ if ($fontawesome === true) generateCSSsInclude('vendor/components/font-awesome/css/font-awesome.min.css'); // PivotUI CSS - if ($pivotui === true) - { - generateCSSsInclude('vendor/nicolaskruchten/pivottable/dist/pivot.min.css'); - } + if ($pivotui === true) generateCSSsInclude('vendor/nicolaskruchten/pivottable/dist/pivot.min.css'); // SB Admin 2 template CSS if ($sbadmintemplate === true) @@ -80,6 +79,9 @@ generateCSSsInclude('vendor/mottie/tablesorter/dist/css/jquery.tablesorter.pager.min.css'); } + // Tabulator CSS + if ($tabulator === true) generateCSSsInclude('vendor/olifolkerd/tabulator/dist/css/bootstrap/tabulator_bootstrap.min.css'); + // -------------------------------------------------------------------------------------------------------- // From public folder @@ -101,6 +103,7 @@ // Eventually required CSS generateCSSsInclude($customCSSs); // Eventually required CSS + // -------------------------------------------------------------------------------------------------------- // Javascripts @@ -126,10 +129,7 @@ } // jQuery checkboxes - if ($jquerycheckboxes === true) - { - generateJSsInclude('vendor/rmariuzzo/jquery-checkboxes/dist/jquery.checkboxes-1.0.7.min.js'); - } + if ($jquerycheckboxes === true) generateJSsInclude('vendor/rmariuzzo/jquery-checkboxes/dist/jquery.checkboxes-1.0.7.min.js'); // Bootstrap JS if ($bootstrap === true) generateJSsInclude('vendor/twbs/bootstrap/dist/js/bootstrap.min.js'); @@ -138,12 +138,17 @@ // NOTE: keep it after jQuery includes if ($jquerytreetable === true) generateJSsInclude('vendor/ludo/jquery-treetable/jquery.treetable.js'); - // PivotUI CSS - if ($pivotui === true) + // MomentJS + if ($momentjs === true) { - generateJSsInclude('vendor/nicolaskruchten/pivottable/dist/pivot.min.js'); + generateJSsInclude('vendor/moment/momentjs/min/moment.min.js'); + generateJSsInclude('vendor/moment/momentjs/locale/de-at.js'); + generateJSsInclude('vendor/moment/momentjs/locale/en-ie.js'); } + // PivotUI JS + if ($pivotui === true) generateJSsInclude('vendor/nicolaskruchten/pivottable/dist/pivot.min.js'); + // Table sorter JS if ($tablesorter === true) { @@ -152,6 +157,9 @@ generateJSsInclude('vendor/mottie/tablesorter/dist/js/extras/jquery.tablesorter.pager.min.js'); } + // Tabulator JS + if ($tabulator === true) generateJSsInclude('vendor/olifolkerd/tabulator/dist/js/tabulator.min.js'); + // Tinymce JS if ($tinymce === true) generateJSsInclude('vendor/tinymce/tinymce/tinymce.min.js'); diff --git a/composer.json b/composer.json index c6816e075..5003468c2 100644 --- a/composer.json +++ b/composer.json @@ -162,6 +162,17 @@ } } }, + { + "type": "package", + "package": { + "name": "moment/momentjs", + "version": "2.24.0", + "dist": { + "url": "https://github.com/moment/moment/archive/2.24.0.zip", + "type": "zip" + } + } + }, { "type": "package", "package": { @@ -263,6 +274,7 @@ "ludo/jquery-treetable": "^3.2", + "moment/momentjs": "2.24.0", "michelf/php-markdown": "1.5.0", "ml/json-ld": "1.*", "mottie/tablesorter": "^2.29", diff --git a/composer.lock b/composer.lock index f328832e6..85e506cc4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "df6059a4bee974ecf5447aad8a8b1e15", - "content-hash": "2111c73853dbc47938c3f31dbc349883", + "hash": "e3de1eee238160400fb63f68735b4144", + "content-hash": "5b71e8a3c356d52e43d788eb6f018151", "packages": [ { "name": "BlackrockDigital/startbootstrap-sb-admin-2", @@ -1095,6 +1095,17 @@ ], "time": "2018-11-18 20:26:18" }, + { + "name": "moment/momentjs", + "version": "2.24.0", + "dist": { + "type": "zip", + "url": "https://github.com/moment/moment/archive/2.24.0.zip", + "reference": null, + "shasum": null + }, + "type": "library" + }, { "name": "mottie/tablesorter", "version": "v2.31.1", @@ -2191,16 +2202,16 @@ }, { "name": "twig/twig", - "version": "v1.42.1", + "version": "v1.42.2", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "671347603760a88b1e7288aaa9378f33687d7edf" + "reference": "21707d6ebd05476854805e4f91b836531941bcd4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/671347603760a88b1e7288aaa9378f33687d7edf", - "reference": "671347603760a88b1e7288aaa9378f33687d7edf", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/21707d6ebd05476854805e4f91b836531941bcd4", + "reference": "21707d6ebd05476854805e4f91b836531941bcd4", "shasum": "" }, "require": { @@ -2253,7 +2264,7 @@ "keywords": [ "templating" ], - "time": "2019-06-04 11:31:08" + "time": "2019-06-18 15:35:16" }, { "name": "zetacomponents/base", From 27ccd086ac18e59513dd91cd713a56203d3ffd5d Mon Sep 17 00:00:00 2001 From: Paolo Date: Mon, 24 Jun 2019 17:32:31 +0200 Subject: [PATCH 10/72] - Added new functions getAuthFirstname and getAuthSurname to helper hlp_authentication_helper - Added methods getReceivedMessages and getSentMessages to model system/Recipient_model.php - Added jqueryui and dialoglib to view system/messages/ajaxRead - Added method prepareAjaxRead to model CL/Messages_model - Removed private method _getAuthUser from model CL/Messages_model - Adapted code in model CL/Messages_model to use functions isLogged and getAuthPersonId --- .../helpers/hlp_authentication_helper.php | 29 +++++- application/models/CL/Messages_model.php | 95 +++++++++++++------ application/models/system/Recipient_model.php | 59 ++++++++++++ .../views/system/messages/ajaxRead.php | 2 + public/js/messaging/messageClient.js | 53 +++++++++++ 5 files changed, 210 insertions(+), 28 deletions(-) create mode 100644 public/js/messaging/messageClient.js diff --git a/application/helpers/hlp_authentication_helper.php b/application/helpers/hlp_authentication_helper.php index 740823ff9..459c7fb80 100644 --- a/application/helpers/hlp_authentication_helper.php +++ b/application/helpers/hlp_authentication_helper.php @@ -20,7 +20,6 @@ function getAuthPersonId() return isLogged() ? ($ci->authlib->getAuthObj())->{AuthLib::AO_PERSON_ID} : null; } - /** * If the user is NOT logged then a null value is returned. * If the user is alredy logged, then it is possible to access to the authentication object @@ -34,3 +33,31 @@ function getAuthUID() return isLogged() ? ($ci->authlib->getAuthObj())->{AuthLib::AO_USERNAME} : null; } + +/** + * If the user is NOT logged then a null value is returned. + * If the user is alredy logged, then it is possible to access to the authentication object + * that contains the firstname of the logged user + * NOTE: if the user is logged with a "foreign" method (ex. Bewerbungstool), + * then it is possible that the firstname is null! + */ +function getAuthFirstname() +{ + $ci =& get_instance(); // get CI instance + + return isLogged() ? ($ci->authlib->getAuthObj())->{AuthLib::AO_NAME} : null; +} + +/** + * If the user is NOT logged then a null value is returned. + * If the user is alredy logged, then it is possible to access to the authentication object + * that contains the surname of the logged user + * NOTE: if the user is logged with a "foreign" method (ex. Bewerbungstool), + * then it is possible that the surname is null! + */ +function getAuthSurname() +{ + $ci =& get_instance(); // get CI instance + + return isLogged() ? ($ci->authlib->getAuthObj())->{AuthLib::AO_SURNAME} : null; +} diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index 302e51340..21cba1d68 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -36,6 +36,67 @@ class Messages_model extends CI_Model //------------------------------------------------------------------------------------------------------------------ // Public methods + /** + * + */ + public function prepareAjaxRead() + { + $jsonNestedData = error('Something did not go as it should'); + + $loggedUserName = getAuthFirstname().' '.getAuthSurname(); + + if (isEmptyString($loggedUserName)) $loggedUserName = 'Me'; + + $receivedMessagesResult = $this->RecipientModel->getReceivedMessages(getAuthPersonId()); + if (isError($receivedMessagesResult)) return $receivedMessagesResult; + + $sentMessagesResult = $this->RecipientModel->getSentMessages(getAuthPersonId()); + if (isError($sentMessagesResult)) return $sentMessagesResult; + + if (hasData($receivedMessagesResult)) + { + $jsonArray = array(); + + foreach (getData($receivedMessagesResult) as $receivedMessage) + { + $jsonRecord = new stdClass(); + $jsonRecord->subject = $receivedMessage->subject; + $jsonRecord->from = $receivedMessage->vorname.' '.$receivedMessage->nachname; + $sentDate = new DateTime($receivedMessage->sent); + $jsonRecord->sent = $sentDate->format('d/m/Y H:i:s'); + $jsonRecord->status = $receivedMessage->status; + + if (hasData($sentMessagesResult)) + { + $jsonChildrenArray = array(); + + foreach (getData($sentMessagesResult) as $sentMessage) + { + if ($receivedMessage->relationmessage_id == $sentMessage->message_id) + { + $jsonChildrenRecord = new stdClass(); + $jsonChildrenRecord->subject = $sentMessage->subject; + $jsonChildrenRecord->from = $loggedUserName; + $sentDate = new DateTime($sentMessage->sent); + $jsonChildrenRecord->sent = $sentDate->format('d/m/Y H:i:s'); + $jsonChildrenRecord->status = $sentMessage->status; + + $jsonChildrenArray[] = $jsonChildrenRecord; + } + } + + if (!isEmptyArray($jsonChildrenArray)) $jsonRecord->_children = $jsonChildrenArray; + } + + $jsonArray[] = $jsonRecord; + } + + $jsonNestedData = success(json_encode($jsonArray)); + } + + return $jsonNestedData; + } + /** * Prepares data for the view system/messages/htmlRead using a token that identifies a single message */ @@ -148,11 +209,8 @@ class Messages_model extends CI_Model public function sendImplicitTemplate($persons, $subject, $body, $relationmessage_id = null) { // Retrieves the sender id - $authUser = $this->_getAuthUser(); - if (isError($authUser)) show_error(getData($authUser)); - if (!hasData($authUser)) show_error('The current logged user person_id is not defined'); - - $sender_id = getData($authUser)[0]->person_id; + $sender_id = getAuthPersonId(); + if (!is_numeric($sender_id)) show_error('The current logged user person_id is not defined'); // Retrieves message vars data for the given user/s $msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($persons); @@ -194,11 +252,8 @@ class Messages_model extends CI_Model public function sendExplicitTemplate($prestudents, $oe_kurzbz, $vorlage_kurzbz, $msgVars) { // Retrieves the sender id - $authUser = $this->_getAuthUser(); - if (isError($authUser)) show_error(getData($authUser)); - if (!hasData($authUser)) show_error('The current logged user person_id is not defined'); - - $sender_id = getData($authUser)[0]->person_id; + $sender_id = getAuthPersonId(); + if (!is_numeric($sender_id)) show_error('The current logged user person_id is not defined'); // Retrieves message vars data for the given user/s $msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudents); @@ -356,17 +411,6 @@ class Messages_model extends CI_Model //------------------------------------------------------------------------------------------------------------------ // Private methods - /** - * Returns the current authenticated person object - */ - private function _getAuthUser() - { - $this->load->model('person/Person_model', 'PersonModel'); - $authUser = $this->PersonModel->getByUid(getAuthUID()); - - return $authUser; - } - /** * Replaces data array keys to a lowercase string with underscores instead of spaces */ @@ -407,7 +451,7 @@ class Messages_model extends CI_Model { // In case the message is accessed via ViewMessage controller -> no authentication // If no authentication is performed then use a hard coded uid - $loggedUserUID = function_exists('getAuthUID') ? getAuthUID() : self::NO_AUTH_UID; + $loggedUserUID = isLogged() ? getAuthUID() : self::NO_AUTH_UID; return $this->personloglib->log( $receiver_id, @@ -508,11 +552,8 @@ class Messages_model extends CI_Model // --------------------------------------------------------------------------------------- // Retrieves the sender id - $authUser = $this->_getAuthUser(); - if (isError($authUser)) show_error(getData($authUser)); - if (!hasData($authUser)) show_error('The current logged user person_id is not defined'); - - $sender_id = getData($authUser)[0]->person_id; + $sender_id = getAuthPersonId(); + if (!is_numeric($sender_id)) show_error('The current logged user person_id is not defined'); // --------------------------------------------------------------------------------------- // Organisation units and a boolean (true if the sender is administrator) are used to get the templates diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 65812580e..8d1162de5 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -299,4 +299,63 @@ class Recipient_model extends DB_Model return $this->execQuery($sql, $parametersArray); } + + /** + * + */ + public function getReceivedMessages($person_id) + { + $sql = 'SELECT mr.message_id, + mm.relationmessage_id, + mm.subject, + mm.body, + mr.sent, + p.vorname, + p.nachname, + MAX(ms.status) AS status + FROM public.tbl_msg_recipient mr + JOIN public.tbl_msg_message mm ON (mm.message_id = mr.message_id) + JOIN public.tbl_msg_status ms ON (ms.message_id = mr.message_id AND ms.person_id = mr.person_id) + JOIN public.tbl_person p ON (p.person_id = mm.person_id) + WHERE mr.person_id = ? + AND mr.sent IS NOT NULL + AND mr.sentinfo IS NULL + GROUP BY mr.message_id, + mm.relationmessage_id, + mm.subject, + mm.body, + mr.sent, + p.vorname, + p.nachname + ORDER BY mr.sent DESC'; + + return $this->execQuery($sql, array($person_id)); + } + + /** + * + */ + public function getSentMessages($person_id) + { + $sql = 'SELECT mm.message_id, + mm.relationmessage_id, + mm.subject, + mm.body, + mr.sent, + MAX(ms.status) AS status + FROM public.tbl_msg_message mm + JOIN public.tbl_msg_recipient mr ON (mr.message_id = mm.message_id) + JOIN public.tbl_msg_status ms ON (ms.message_id = mm.message_id AND mr.person_id = mr.person_id) + WHERE mm.person_id = ? + AND mr.sent IS NOT NULL + AND mr.sentinfo IS NULL + GROUP BY mm.message_id, + mm.relationmessage_id, + mm.subject, + mm.body, + mr.sent + ORDER BY mr.sent DESC'; + + return $this->execQuery($sql, array($person_id)); + } } diff --git a/application/views/system/messages/ajaxRead.php b/application/views/system/messages/ajaxRead.php index 97f16ce3b..e3ff133f0 100644 --- a/application/views/system/messages/ajaxRead.php +++ b/application/views/system/messages/ajaxRead.php @@ -4,10 +4,12 @@ array( 'title' => 'Read personal messages', 'jquery' => true, + 'jqueryui' => true, 'bootstrap' => true, 'momentjs' => true, 'tabulator' => true, 'ajaxlib' => true, + 'dialoglib' => true, 'customJSs' => array('public/js/messaging/messageClient.js') ) ); diff --git a/public/js/messaging/messageClient.js b/public/js/messaging/messageClient.js new file mode 100644 index 000000000..850777ea9 --- /dev/null +++ b/public/js/messaging/messageClient.js @@ -0,0 +1,53 @@ +/** + * + */ +$(document).ready(function () { + + FHC_AjaxClient.ajaxCallGet( + FHC_JS_DATA_STORAGE_OBJECT.called_path + '/listMessages', + null, + { + successCallback: function(data, textStatus, jqXHR) { + + if (FHC_AjaxClient.hasData(data)) + { + try + { + var jsonMessageLst = JSON.parse(FHC_AjaxClient.getData(data)); + + console.log(jsonMessageLst); + + var tableMessageLst = new Tabulator("#lstMessagesPanel", { + height: "400px", + data: jsonMessageLst, + dataTree: true, + dataTreeStartExpanded: true, + dataTreeElementColumn: "subject", + columns: [ + {title: "Subject", field: "subject", width: 700, responsive: 0}, + {title: "From", field: "from", width: 400}, + {title: "Date", field: "sent", sorter: "datetime", width: 150} + ], + rowClick: function(e, row) { + // TODO + } + }); + } + catch (syntaxError) + { + FHC_DialogLib.alertError("An error occurred while retrieving message, contact the website administrator"); + } + } + else + { + FHC_DialogLib.alertWarning("No message currently available"); + } + }, + errorCallback: function() { + + }, + veilTimeout: 300 + } + ); + +}); From 34dc82766acd3f28fb0e5cd77f6e5c306d7889cf Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 28 Jun 2019 19:01:25 +0200 Subject: [PATCH 11/72] - Renamed public/js/messaging/messageClient.js to public/js/messaging/read.js - Added new JS public/js/messaging/write.js used in view application/views/system/messages/ajaxWrite.php - Added new public method write, listReceivedMessages, listSentMessages and sendMessageToOU to controller system/messages/MessageClient.php - Removed private method _getReceiversByOekurzbz from MessageLib - Fixed method sendMessageOU of MessageLib - Added new public method prepareAjaxWrite to model CL/Messages_model - Fixed method prepareAjaxReadReceived of model CL/Messages_model - Added new public method prepareAjaxReadSent to model CL/Messages_model - Changed method CL/Messages_model->_personLog interface - Added new public method getOrganisationunitsByPersonId to crm/Prestudent_model - Added new public method getReceivedMessages to model system/Recipient_model - Changed getReceivedMessages method of model system/Recipient_model - Changed view system/messages/ajaxRead.php - Added new view system/messages/ajaxWrite.php --- .../system/messages/MessageClient.php | 43 +++++- application/libraries/MessageLib.php | 22 +-- application/models/CL/Messages_model.php | 131 ++++++++++++++---- application/models/crm/Prestudent_model.php | 16 +++ application/models/system/Recipient_model.php | 40 +++++- .../views/system/messages/ajaxRead.php | 15 +- .../views/system/messages/ajaxWrite.php | 71 ++++++++++ public/js/messaging/messageClient.js | 53 ------- public/js/messaging/messageWrite.js | 10 +- public/js/messaging/read.js | 116 ++++++++++++++++ public/js/messaging/write.js | 52 +++++++ 11 files changed, 449 insertions(+), 120 deletions(-) create mode 100644 application/views/system/messages/ajaxWrite.php delete mode 100644 public/js/messaging/messageClient.js create mode 100644 public/js/messaging/read.js create mode 100644 public/js/messaging/write.js diff --git a/application/controllers/system/messages/MessageClient.php b/application/controllers/system/messages/MessageClient.php index 3000e6b91..1062202c1 100644 --- a/application/controllers/system/messages/MessageClient.php +++ b/application/controllers/system/messages/MessageClient.php @@ -8,8 +8,11 @@ class MessageClient extends Auth_Controller { parent::__construct( array( - 'read' => array('basis/message:r'), - 'listMessages' => array('basis/message:r') + 'read' => array('basis/person:r'), + 'write' => array('basis/person:r'), + 'listReceivedMessages' => array('basis/person:r'), + 'listSentMessages' => array('basis/person:r'), + 'sendMessageToOU' => array('basis/person:r') ) ); @@ -27,13 +30,39 @@ class MessageClient extends Auth_Controller } /** - * Returns JSON that that contains all the received messages by the currently logged user - * This JSON structure is nested data used by tabulator + * Starts the GUI used to write a personal message to an organisation unit */ - public function listMessages() + public function write() { - $jsonNestedData = $this->CLMessagesModel->prepareAjaxRead(); + // Loads the view to write a message + $this->load->view('system/messages/ajaxWrite', $this->CLMessagesModel->prepareAjaxWrite()); + } - $this->outputJson($jsonNestedData); + /** + * Returns JSON that that contains all the received messages by the currently logged user + */ + public function listReceivedMessages() + { + $this->outputJson($this->CLMessagesModel->prepareAjaxReadReceived()); + } + + /** + * Returns JSON that that contains all the sent messages by the currently logged user + */ + public function listSentMessages() + { + $this->outputJson($this->CLMessagesModel->prepareAjaxReadSent()); + } + + /** + * + */ + public function sendMessageToOU() + { + $receiverOU = $this->input->post('receiverOU'); + $subject = $this->input->post('subject'); + $body = $this->input->post('body'); + + $this->outputJson($this->CLMessagesModel->sendToOrganisationUnit($receiverOU, $subject, $body)); } } diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 206aeed87..18b958e14 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -128,7 +128,9 @@ class MessageLib // If the recipient is an organisation unit that would be possible to send the same message (same message id) // to the entire organisation unit (one to many functionality) // In this case the receiver id is a the one present in message configuration - $receivers = success(array($this->_ci->config->item(self::CFG_SYSTEM_PERSON_ID))); + $receiver = new stdClass(); + $receiver->person_id = $this->_ci->config->item(self::CFG_SYSTEM_PERSON_ID); + $receivers = success(array($receiver)); // Send the message and return the result return $this->_sendMessage($receivers, $receiversOU, $subject, $body, $sender_id, $senderOU, $relationmessage_id, $priority, $multiPartMime); @@ -373,24 +375,6 @@ class MessageLib } } - /** - * Gets the receivers id that are enabled to read messages for that oe_kurzbz - */ - private function _getReceiversByOekurzbz($oe_kurzbz) - { - // Load Benutzerfunktion_model - $this->_ci->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel'); - // Join with table public.tbl_benutzer on field uid - $this->_ci->BenutzerfunktionModel->addJoin('public.tbl_benutzer', 'uid'); - // Get all the valid receivers id using the oe_kurzbz - $receivers = $this->_ci->BenutzerfunktionModel->loadWhere( - 'oe_kurzbz = '.$this->_ci->db->escape($oe_kurzbz). - ' AND funktion_kurzbz = '.$this->_ci->db->escape($this->_ci->config->item(self::CFG_OU_RECEIVERS)). - ' AND (NOW() BETWEEN COALESCE(datum_von, NOW()) AND COALESCE(datum_bis, NOW()))' - ); - return $receivers; - } - /** * Save a new message in DB */ diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index 21cba1d68..5810487a9 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -28,9 +28,10 @@ class Messages_model extends CI_Model // Loads model MessageToken_model $this->load->model('system/MessageToken_model', 'MessageTokenModel'); - // Loads model Benutzerrolle_model $this->load->model('system/Benutzerrolle_model', 'BenutzerrolleModel'); + // Loads model Prestudent_model + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); } //------------------------------------------------------------------------------------------------------------------ @@ -39,20 +40,42 @@ class Messages_model extends CI_Model /** * */ - public function prepareAjaxRead() + public function prepareAjaxWrite() { - $jsonNestedData = error('Something did not go as it should'); + $ouResult = $this->PrestudentModel->getOrganisationunitsByPersonId(getAuthPersonId()); + + if (isError($ouResult)) show_error('An error occurred while loading this page, please contact the site administrator'); + + $ouOptions = ''; + + if (hasData($ouResult)) + { + foreach (getData($ouResult) as $ou) + { + $ouOptions .= sprintf("\n".'', $ou->oe_kurzbz, $ou->bezeichnung); + } + } + + return array('organisationUnitOptions' => $ouOptions); + } + + /** + * + */ + public function prepareAjaxReadReceived() + { + $jsonResult = error('Something did not go as it should'); $loggedUserName = getAuthFirstname().' '.getAuthSurname(); if (isEmptyString($loggedUserName)) $loggedUserName = 'Me'; - $receivedMessagesResult = $this->RecipientModel->getReceivedMessages(getAuthPersonId()); + $receivedMessagesResult = $this->RecipientModel->getReceivedMessages( + getAuthPersonId(), + $this->config->item(MessageLib::CFG_OU_RECEIVERS) + ); if (isError($receivedMessagesResult)) return $receivedMessagesResult; - $sentMessagesResult = $this->RecipientModel->getSentMessages(getAuthPersonId()); - if (isError($sentMessagesResult)) return $sentMessagesResult; - if (hasData($receivedMessagesResult)) { $jsonArray = array(); @@ -60,41 +83,59 @@ class Messages_model extends CI_Model foreach (getData($receivedMessagesResult) as $receivedMessage) { $jsonRecord = new stdClass(); + $jsonRecord->message_id = $receivedMessage->message_id; $jsonRecord->subject = $receivedMessage->subject; + $jsonRecord->body = $receivedMessage->body; $jsonRecord->from = $receivedMessage->vorname.' '.$receivedMessage->nachname; $sentDate = new DateTime($receivedMessage->sent); $jsonRecord->sent = $sentDate->format('d/m/Y H:i:s'); $jsonRecord->status = $receivedMessage->status; - if (hasData($sentMessagesResult)) - { - $jsonChildrenArray = array(); + $jsonArray[] = $jsonRecord; + } - foreach (getData($sentMessagesResult) as $sentMessage) - { - if ($receivedMessage->relationmessage_id == $sentMessage->message_id) - { - $jsonChildrenRecord = new stdClass(); - $jsonChildrenRecord->subject = $sentMessage->subject; - $jsonChildrenRecord->from = $loggedUserName; - $sentDate = new DateTime($sentMessage->sent); - $jsonChildrenRecord->sent = $sentDate->format('d/m/Y H:i:s'); - $jsonChildrenRecord->status = $sentMessage->status; + $jsonResult = success(json_encode($jsonArray)); + } - $jsonChildrenArray[] = $jsonChildrenRecord; - } - } + return $jsonResult; + } - if (!isEmptyArray($jsonChildrenArray)) $jsonRecord->_children = $jsonChildrenArray; - } + /** + * + */ + public function prepareAjaxReadSent() + { + $jsonResult = error('Something did not go as it should'); + + $loggedUserName = getAuthFirstname().' '.getAuthSurname(); + + if (isEmptyString($loggedUserName)) $loggedUserName = 'Me'; + + $sentMessagesResult = $this->RecipientModel->getSentMessages(getAuthPersonId()); + if (isError($sentMessagesResult)) return $sentMessagesResult; + + if (hasData($sentMessagesResult)) + { + $jsonArray = array(); + + foreach (getData($sentMessagesResult) as $sentMessage) + { + $jsonRecord = new stdClass(); + $jsonRecord->message_id = $sentMessage->message_id; + $jsonRecord->subject = $sentMessage->subject; + $jsonRecord->body = $sentMessage->body; + $jsonRecord->from = $sentMessage->vorname.' '.$sentMessage->nachname; + $sentDate = new DateTime($sentMessage->sent); + $jsonRecord->sent = $sentDate->format('d/m/Y H:i:s'); + $jsonRecord->status = $sentMessage->status; $jsonArray[] = $jsonRecord; } - $jsonNestedData = success(json_encode($jsonArray)); + $jsonResult = success(json_encode($jsonArray)); } - return $jsonNestedData; + return $jsonResult; } /** @@ -260,7 +301,6 @@ class Messages_model extends CI_Model if (isError($msgVarsData)) show_error(getData($msgVarsData)); if (!hasData($msgVarsData)) show_error('No recipients were given'); - $this->load->model('crm/Prestudent_model', 'PrestudentModel'); $prestudentsData = $this->PrestudentModel->getOrganisationunits($prestudents); // Adds the organisation unit to each prestudent @@ -337,6 +377,34 @@ class Messages_model extends CI_Model return success('Messages sent successfully'); } + /** + * Send a message to an organisation unit + */ + public function sendToOrganisationUnit($receiverOU, $subject, $body) + { + if (isEmptyString($receiverOU)) return error('Not a valid organisation unit'); + if (isEmptyString($subject)) return error('Subject is an empty string'); + if (isEmptyString($body)) return error('Body is an empty string'); + + $sender_id = getAuthPersonId(); + + $message = $this->messagelib->sendMessageOU( + $receiverOU, // receiverPersonId + $subject, // subject + $body, // body + $sender_id // sender_id + ); + + if (isError($message)) return $message; + if (!hasData($message)) return error('No messages were saved in database'); + + // Write log entry + $personLog = $this->_personLog($sender_id, $this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID), getData($message)[0], $receiverOU); + if (isError($personLog)) return $personLog; + + return success('Messages sent successfully'); + } + //------------------------------------------------------------------------------------------------------------------ // Public methods called by controller system/messages/Messages @@ -447,18 +515,21 @@ class Messages_model extends CI_Model /** * Perform a person log after a message is sent */ - private function _personLog($sender_id, $receiver_id, $message_id) + private function _personLog($sender_id, $receiver_id, $message_id, $receiverOU = null) { // In case the message is accessed via ViewMessage controller -> no authentication // If no authentication is performed then use a hard coded uid $loggedUserUID = isLogged() ? getAuthUID() : self::NO_AUTH_UID; + $message = 'Message sent from person '.$sender_id.' to '.$receiver_id.', message id: '.$message_id; + if (!isEmptyString($receiverOU)) $message .= ', receiverOU: '.$receiverOU; + return $this->personloglib->log( $receiver_id, 'Action', array( 'name' => 'Message sent', - 'message' => 'Message sent from person '.$sender_id.' to '.$receiver_id.', message id: '.$message_id, + 'message' => $message, 'success' => 'true' ), 'kommunikation', diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index ffc6afb0e..b4c756e52 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -523,4 +523,20 @@ class Prestudent_model extends DB_Model } } } + + /** + * Get organisation units for all the prestudents of a person + */ + public function getOrganisationunitsByPersonId($person_id) + { + $query = 'SELECT o.oe_kurzbz, o.bezeichnung + FROM public.tbl_prestudent p + JOIN public.tbl_studiengang s USING(studiengang_kz) + JOIN public.tbl_organisationseinheit o USING(oe_kurzbz) + WHERE p.person_id = ? + GROUP BY o.oe_kurzbz, o.bezeichnung + ORDER BY o.bezeichnung'; + + return $this->execQuery($query, array($person_id)); + } } diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 8d1162de5..39961cdbf 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -303,13 +303,13 @@ class Recipient_model extends DB_Model /** * */ - public function getReceivedMessages($person_id) + public function getReceivedMessages($person_id, $functions) { $sql = 'SELECT mr.message_id, mm.relationmessage_id, mm.subject, mm.body, - mr.sent, + mr.sent AS sent, p.vorname, p.nachname, MAX(ms.status) AS status @@ -327,9 +327,34 @@ class Recipient_model extends DB_Model mr.sent, p.vorname, p.nachname - ORDER BY mr.sent DESC'; + UNION + SELECT mrou.message_id, + mm.relationmessage_id, + mm.subject, + mm.body, + mrou.sent AS sent, + p.vorname, + p.nachname, + MAX(ms.status) AS status + FROM public.tbl_person p + JOIN public.tbl_benutzer b ON (b.person_id = p.person_id) + JOIN (SELECT uid, oe_kurzbz FROM public.tbl_benutzerfunktion WHERE funktion_kurzbz IN ?) bf ON (bf.uid = b.uid) + JOIN public.tbl_msg_recipient mrou ON (mrou.oe_kurzbz = bf.oe_kurzbz) + JOIN public.tbl_msg_message mm ON (mm.message_id = mrou.message_id) + JOIN public.tbl_msg_status ms ON (ms.message_id = mrou.message_id AND ms.person_id = mrou.person_id) + WHERE p.person_id = ? + AND mrou.sent IS NOT NULL + AND mrou.sentinfo IS NULL + GROUP BY mrou.message_id, + mm.relationmessage_id, + mm.subject, + mm.body, + mrou.sent, + p.vorname, + p.nachname + ORDER BY sent DESC'; - return $this->execQuery($sql, array($person_id)); + return $this->execQuery($sql, array($person_id, $functions, $person_id)); } /** @@ -342,10 +367,13 @@ class Recipient_model extends DB_Model mm.subject, mm.body, mr.sent, + p.vorname, + p.nachname, MAX(ms.status) AS status FROM public.tbl_msg_message mm JOIN public.tbl_msg_recipient mr ON (mr.message_id = mm.message_id) JOIN public.tbl_msg_status ms ON (ms.message_id = mm.message_id AND mr.person_id = mr.person_id) + JOIN public.tbl_person p ON (p.person_id = mr.person_id) WHERE mm.person_id = ? AND mr.sent IS NOT NULL AND mr.sentinfo IS NULL @@ -353,7 +381,9 @@ class Recipient_model extends DB_Model mm.relationmessage_id, mm.subject, mm.body, - mr.sent + mr.sent, + p.vorname, + p.nachname ORDER BY mr.sent DESC'; return $this->execQuery($sql, array($person_id)); diff --git a/application/views/system/messages/ajaxRead.php b/application/views/system/messages/ajaxRead.php index e3ff133f0..b8d2ea4a6 100644 --- a/application/views/system/messages/ajaxRead.php +++ b/application/views/system/messages/ajaxRead.php @@ -6,15 +6,28 @@ 'jquery' => true, 'jqueryui' => true, 'bootstrap' => true, + 'fontawesome' => true, + 'sbadmintemplate' => true, 'momentjs' => true, 'tabulator' => true, 'ajaxlib' => true, 'dialoglib' => true, - 'customJSs' => array('public/js/messaging/messageClient.js') + 'tinymce' => true, + 'customJSs' => array('public/js/messaging/read.js') ) ); ?> +
+
+ + +
+
diff --git a/application/views/system/messages/ajaxWrite.php b/application/views/system/messages/ajaxWrite.php new file mode 100644 index 000000000..a21a724b2 --- /dev/null +++ b/application/views/system/messages/ajaxWrite.php @@ -0,0 +1,71 @@ +load->view( + 'templates/FHC-Header', + array( + 'title' => 'Write a new message', + 'jquery' => true, + 'jqueryui' => true, + 'bootstrap' => true, + 'fontawesome' => true, + 'sbadmintemplate' => true, + 'ajaxlib' => true, + 'dialoglib' => true, + 'tinymce' => true, + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageWrite.css'), + 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/write.js') + ) + ); +?> + +
+
+
+
+
+ +
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+   +
+ +
+
+
+
+
+
+ + +
+
+
+
+
+ +
+
+
+
+
+ + +load->view("templates/FHC-Footer"); ?> diff --git a/public/js/messaging/messageClient.js b/public/js/messaging/messageClient.js deleted file mode 100644 index 850777ea9..000000000 --- a/public/js/messaging/messageClient.js +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - */ -$(document).ready(function () { - - FHC_AjaxClient.ajaxCallGet( - FHC_JS_DATA_STORAGE_OBJECT.called_path + '/listMessages', - null, - { - successCallback: function(data, textStatus, jqXHR) { - - if (FHC_AjaxClient.hasData(data)) - { - try - { - var jsonMessageLst = JSON.parse(FHC_AjaxClient.getData(data)); - - console.log(jsonMessageLst); - - var tableMessageLst = new Tabulator("#lstMessagesPanel", { - height: "400px", - data: jsonMessageLst, - dataTree: true, - dataTreeStartExpanded: true, - dataTreeElementColumn: "subject", - columns: [ - {title: "Subject", field: "subject", width: 700, responsive: 0}, - {title: "From", field: "from", width: 400}, - {title: "Date", field: "sent", sorter: "datetime", width: 150} - ], - rowClick: function(e, row) { - // TODO - } - }); - } - catch (syntaxError) - { - FHC_DialogLib.alertError("An error occurred while retrieving message, contact the website administrator"); - } - } - else - { - FHC_DialogLib.alertWarning("No message currently available"); - } - }, - errorCallback: function() { - - }, - veilTimeout: 300 - } - ); - -}); diff --git a/public/js/messaging/messageWrite.js b/public/js/messaging/messageWrite.js index 4146b7008..08a3b46a0 100644 --- a/public/js/messaging/messageWrite.js +++ b/public/js/messaging/messageWrite.js @@ -1,6 +1,6 @@ -/** - * JS used by view system/messages/htmlWriteTemplate - */ +// ******************************************************** +// JS used by view system/messages/htmlWriteTemplate +// ******************************************************** function tinymcePreviewSetContent() { @@ -52,12 +52,12 @@ $(document).ready(function () }); tinymce.init({ + selector: "#tinymcePreview", + plugins: "autoresize", menubar: false, toolbar: false, statusbar: false, readonly: 1, - selector: "#tinymcePreview", - plugins: "autoresize", autoresize_min_height: 150, autoresize_bottom_margin: 10 }); diff --git a/public/js/messaging/read.js b/public/js/messaging/read.js new file mode 100644 index 000000000..c4a27edc6 --- /dev/null +++ b/public/js/messaging/read.js @@ -0,0 +1,116 @@ +// *********************************************************************** +// List all personal messages, used by view system/messages/ajaxRead +// *********************************************************************** + +// +var tableMessageLst; + +/** + * + */ +function genericError() +{ + FHC_DialogLib.alertError("An error occurred while retrieving message, contact the website administrator"); +} + +/** + * + */ +function getReceivedMessages() +{ + _getMessages(FHC_JS_DATA_STORAGE_OBJECT.called_path + '/listReceivedMessages'); +} + +/** + * + */ +function getSentMessages() +{ + _getMessages(FHC_JS_DATA_STORAGE_OBJECT.called_path + '/listSentMessages'); +} + +/** + * + */ +function _getMessages(getMessagesURL) +{ + FHC_AjaxClient.ajaxCallGet( + getMessagesURL, + null, + { + successCallback: function(data, textStatus, jqXHR) { + + if (FHC_AjaxClient.hasData(data)) + { + try + { + tableMessageLst.replaceData(JSON.parse(FHC_AjaxClient.getData(data))); + } + catch (syntaxError) + { + genericError(); + } + } + }, + errorCallback: genericError, + veilTimeout: 300 + } + ); +} + +/** + * + */ +function changeTinyMCE(e, row) +{ + tinyMCE.get("readMessagePanel").setContent(row._row.data.body); +} + +/** + * + */ +function toggleMessages() +{ + // + if ($(this)[0].className.search('active') == -1) + { + $(this)[0].id == 'r' ? getReceivedMessages() : getSentMessages(); + } +} + +/** + * + */ +$(document).ready(function () { + + // + tinymce.init({ + selector: "#readMessagePanel", + plugins: "autoresize", + menubar: false, + toolbar: false, + statusbar: false, + readonly: 1, + autoresize_min_height: 200, + autoresize_bottom_margin: 0 + }); + + // + tableMessageLst = new Tabulator("#lstMessagesPanel", { + height: "400px", + pagination: "local", + columns: [ + {title: "Subject", field: "subject", width: 700, responsive: 0}, + {title: "From", field: "from", width: 400}, + {title: "Date", field: "sent", sorter: "datetime", width: 150} + ], + rowClick: changeTinyMCE + }); + + // + $('.toggleMessages .btn').click(toggleMessages); + + // + getReceivedMessages(); + +}); diff --git a/public/js/messaging/write.js b/public/js/messaging/write.js new file mode 100644 index 000000000..180a47c36 --- /dev/null +++ b/public/js/messaging/write.js @@ -0,0 +1,52 @@ +// **************************************************************************************** +// Write a message to an organisation unit, used by view system/messages/ajaxWrite +// **************************************************************************************** + +/** + * + */ +function sendMessageToOU() +{ + if ($('#organisationUnit').val() == 0) + { + FHC_DialogLib.alertWarning("Not valid organisation unit"); + } + else + { + FHC_AjaxClient.ajaxCallPost( + FHC_JS_DATA_STORAGE_OBJECT.called_path + '/sendMessageToOU', + { + receiverOU: $('#organisationUnit').val(), + subject: $('#subject').val(), + body: tinyMCE.get("body").getContent() + }, + { + successCallback: function(data, textStatus, jqXHR) { + FHC_DialogLib.alertSuccess("Message sent succesfully"); + }, + errorCallback: function() { + FHC_DialogLib.alertError("Error"); + }, + veilTimeout: 300 + } + ); + } +} + +/** + * + */ +$(document).ready(function () { + + // + tinymce.init({ + selector: "#body", + plugins: "autoresize", + autoresize_min_height: 150, + autoresize_max_height: 600, + autoresize_bottom_margin: 10 + }); + + $('#sendButton').click(sendMessageToOU); + +}); From 99e541d5065fd3623fe5cc4261e827f1725b2d69 Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 28 Jun 2019 19:18:18 +0200 Subject: [PATCH 12/72] Fixed receiver/sender retrieved from database --- application/models/CL/Messages_model.php | 2 +- application/models/system/Recipient_model.php | 11 ++++++----- public/js/messaging/read.js | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index 5810487a9..37b244038 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -124,7 +124,7 @@ class Messages_model extends CI_Model $jsonRecord->message_id = $sentMessage->message_id; $jsonRecord->subject = $sentMessage->subject; $jsonRecord->body = $sentMessage->body; - $jsonRecord->from = $sentMessage->vorname.' '.$sentMessage->nachname; + $jsonRecord->to = $sentMessage->vorname.' '.$sentMessage->nachname; $sentDate = new DateTime($sentMessage->sent); $jsonRecord->sent = $sentDate->format('d/m/Y H:i:s'); $jsonRecord->status = $sentMessage->status; diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 39961cdbf..8a3ee1aa6 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -316,7 +316,7 @@ class Recipient_model extends DB_Model FROM public.tbl_msg_recipient mr JOIN public.tbl_msg_message mm ON (mm.message_id = mr.message_id) JOIN public.tbl_msg_status ms ON (ms.message_id = mr.message_id AND ms.person_id = mr.person_id) - JOIN public.tbl_person p ON (p.person_id = mm.person_id) + JOIN public.tbl_person p ON (p.person_id = mr.person_id) WHERE mr.person_id = ? AND mr.sent IS NOT NULL AND mr.sentinfo IS NULL @@ -333,8 +333,8 @@ class Recipient_model extends DB_Model mm.subject, mm.body, mrou.sent AS sent, - p.vorname, - p.nachname, + pr.vorname, + pr.nachname, MAX(ms.status) AS status FROM public.tbl_person p JOIN public.tbl_benutzer b ON (b.person_id = p.person_id) @@ -342,6 +342,7 @@ class Recipient_model extends DB_Model JOIN public.tbl_msg_recipient mrou ON (mrou.oe_kurzbz = bf.oe_kurzbz) JOIN public.tbl_msg_message mm ON (mm.message_id = mrou.message_id) JOIN public.tbl_msg_status ms ON (ms.message_id = mrou.message_id AND ms.person_id = mrou.person_id) + JOIN public.tbl_person pr ON (pr.person_id = mrou.person_id) WHERE p.person_id = ? AND mrou.sent IS NOT NULL AND mrou.sentinfo IS NULL @@ -350,8 +351,8 @@ class Recipient_model extends DB_Model mm.subject, mm.body, mrou.sent, - p.vorname, - p.nachname + pr.vorname, + pr.nachname ORDER BY sent DESC'; return $this->execQuery($sql, array($person_id, $functions, $person_id)); diff --git a/public/js/messaging/read.js b/public/js/messaging/read.js index c4a27edc6..348e6b3ed 100644 --- a/public/js/messaging/read.js +++ b/public/js/messaging/read.js @@ -102,6 +102,7 @@ $(document).ready(function () { columns: [ {title: "Subject", field: "subject", width: 700, responsive: 0}, {title: "From", field: "from", width: 400}, + {title: "To", field: "to", width: 400}, {title: "Date", field: "sent", sorter: "datetime", width: 150} ], rowClick: changeTinyMCE From c62b4dc018fb62ced6370187d7d7ce28eae71ceb Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 4 Jul 2019 11:15:07 +0200 Subject: [PATCH 13/72] - Added new public method setMessageRead to system/messages/MessageClient - system/Recipient_model methods getReceivedMessages and getSentMessages now retrieve person_id from tbl_msg_status - Added new public method setMessageRead to CL/Messages_model - Improved code in public/js/messaging/read.js --- .../system/messages/MessageClient.php | 16 ++- application/models/CL/Messages_model.php | 79 ++++++++--- application/models/system/Recipient_model.php | 27 ++-- public/js/messaging/read.js | 128 +++++++++++++----- 4 files changed, 183 insertions(+), 67 deletions(-) diff --git a/application/controllers/system/messages/MessageClient.php b/application/controllers/system/messages/MessageClient.php index 1062202c1..4cc4c9f2a 100644 --- a/application/controllers/system/messages/MessageClient.php +++ b/application/controllers/system/messages/MessageClient.php @@ -12,7 +12,8 @@ class MessageClient extends Auth_Controller 'write' => array('basis/person:r'), 'listReceivedMessages' => array('basis/person:r'), 'listSentMessages' => array('basis/person:r'), - 'sendMessageToOU' => array('basis/person:r') + 'sendMessageToOU' => array('basis/person:r'), + 'setMessageRead' => array('basis/person:r') ) ); @@ -55,7 +56,7 @@ class MessageClient extends Auth_Controller } /** - * + * Sends a message to an organisation unit */ public function sendMessageToOU() { @@ -65,4 +66,15 @@ class MessageClient extends Auth_Controller $this->outputJson($this->CLMessagesModel->sendToOrganisationUnit($receiverOU, $subject, $body)); } + + /** + * Set a message as read + */ + public function setMessageRead() + { + $message_id = $this->input->post('message_id'); + $statusPersonId = $this->input->post('statusPersonId'); + + $this->outputJson($this->CLMessagesModel->setMessageRead($message_id, $statusPersonId)); + } } diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index 37b244038..e907022aa 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -2,13 +2,23 @@ /** * Messages GUI logic - * This model extends CI_Model because here is just implemented logic - * It does not represent a resource (ex. like models that extend DB_Model) + * - This model extends CI_Model because here is just implemented logic + * - It does not represent a resource (ex. like models that extend DB_Model) */ class Messages_model extends CI_Model { - const REPLY_SUBJECT_PREFIX = 'Re: '; - const REPLY_BODY_FORMAT = '

On %s %s %s wrote:
%s
'; + const REPLY_SUBJECT_PREFIX = 'Re: '; // reply subject prefix + // To quote a reply body message + const REPLY_BODY_FORMAT = '
+
+
+ + On %s %s %s wrote: + +
+
+ %s +
'; const NO_AUTH_UID = 'online'; // hard coded uid if no authentication is performed @@ -38,7 +48,28 @@ class Messages_model extends CI_Model // Public methods /** - * + * Set a message as read by its id ($message_id + $person_id) + */ + public function setMessageRead($message_id, $person_id) + { + // Checks parameters + if (!is_numeric($message_id) || !is_numeric($person_id)) return error('Invalid setMessageRead parameters'); + + // Loads needed models + $this->load->model('system/MsgStatus_model', 'MsgStatusModel'); + + // Set date used to insert + $statusData = array( + 'message_id' => $message_id, + 'person_id' => $person_id, + 'status' => MSG_STATUS_READ + ); + + return $this->MsgStatusModel->insert($statusData); // insert and return result + } + + /** + * Prepares data for the view system/messages/ajaxWrite */ public function prepareAjaxWrite() { @@ -60,26 +91,31 @@ class Messages_model extends CI_Model } /** - * + * Prepares data for the view system/messages/ajaxRead + * If everything is fine returns a list of received messages (objects) */ public function prepareAjaxReadReceived() { - $jsonResult = error('Something did not go as it should'); - + // Name and surname of the logged user $loggedUserName = getAuthFirstname().' '.getAuthSurname(); + // If empty then use a hard coded one if (isEmptyString($loggedUserName)) $loggedUserName = 'Me'; + // Retrieves received messages for the logged user and its organisation units $receivedMessagesResult = $this->RecipientModel->getReceivedMessages( getAuthPersonId(), $this->config->item(MessageLib::CFG_OU_RECEIVERS) ); + // If an error occurred return it if (isError($receivedMessagesResult)) return $receivedMessagesResult; + // If data were found if (hasData($receivedMessagesResult)) { - $jsonArray = array(); + $jsonArray = array(); // array that contains all the received messages + // Collect'em all in the array $jsonArray foreach (getData($receivedMessagesResult) as $receivedMessage) { $jsonRecord = new stdClass(); @@ -90,34 +126,38 @@ class Messages_model extends CI_Model $sentDate = new DateTime($receivedMessage->sent); $jsonRecord->sent = $sentDate->format('d/m/Y H:i:s'); $jsonRecord->status = $receivedMessage->status; + $jsonRecord->statusPersonId = $receivedMessage->statuspersonid; $jsonArray[] = $jsonRecord; } - $jsonResult = success(json_encode($jsonArray)); + return success(json_encode($jsonArray)); // return as an json encoded string } - return $jsonResult; + return success('No messages were found'); // NOT a blocking error } /** - * + * Prepares data for the view system/messages/ajaxRead + * If everything is fine returns a list of sent messages (objects) */ public function prepareAjaxReadSent() { - $jsonResult = error('Something did not go as it should'); - + // Name and surname of the logged user $loggedUserName = getAuthFirstname().' '.getAuthSurname(); + // If empty then use a hard coded one if (isEmptyString($loggedUserName)) $loggedUserName = 'Me'; + // Retrieves sent messages from the logged user $sentMessagesResult = $this->RecipientModel->getSentMessages(getAuthPersonId()); - if (isError($sentMessagesResult)) return $sentMessagesResult; + if (isError($sentMessagesResult)) return $sentMessagesResult; // If an error occurred return it if (hasData($sentMessagesResult)) { - $jsonArray = array(); + $jsonArray = array();// array that contains all the sent messages + // Collect'em all in the array $jsonArray foreach (getData($sentMessagesResult) as $sentMessage) { $jsonRecord = new stdClass(); @@ -128,14 +168,15 @@ class Messages_model extends CI_Model $sentDate = new DateTime($sentMessage->sent); $jsonRecord->sent = $sentDate->format('d/m/Y H:i:s'); $jsonRecord->status = $sentMessage->status; + $jsonRecord->statusPersonId = $sentMessage->statuspersonid; $jsonArray[] = $jsonRecord; } - $jsonResult = success(json_encode($jsonArray)); + return success(json_encode($jsonArray)); // return as an json encoded string } - return $jsonResult; + return success('No messages were found'); // NOT a blocking error } /** @@ -540,7 +581,7 @@ class Messages_model extends CI_Model } /** - * + * Quotes the previous message body */ private function _getReplyBody($body, $receiverName, $receiverSurname, $sentDate) { diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 8a3ee1aa6..46cf0e36f 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -301,18 +301,21 @@ class Recipient_model extends DB_Model } /** - * + * - Gets the directly recieved messages using the given person id + * - Gets the recieved messages from an organisation unit where this person plays a role given by the parameter functions */ public function getReceivedMessages($person_id, $functions) { - $sql = 'SELECT mr.message_id, + $sql = '-- Messages sent directly to the person + SELECT mr.message_id, mm.relationmessage_id, mm.subject, mm.body, mr.sent AS sent, p.vorname, p.nachname, - MAX(ms.status) AS status + MAX(ms.status) AS status, + ms.person_id AS statusPersonId FROM public.tbl_msg_recipient mr JOIN public.tbl_msg_message mm ON (mm.message_id = mr.message_id) JOIN public.tbl_msg_status ms ON (ms.message_id = mr.message_id AND ms.person_id = mr.person_id) @@ -326,8 +329,10 @@ class Recipient_model extends DB_Model mm.body, mr.sent, p.vorname, - p.nachname + p.nachname, + ms.person_id UNION + -- Messages sent to a person that belongs to the recipient organisation unit SELECT mrou.message_id, mm.relationmessage_id, mm.subject, @@ -335,7 +340,8 @@ class Recipient_model extends DB_Model mrou.sent AS sent, pr.vorname, pr.nachname, - MAX(ms.status) AS status + MAX(ms.status) AS status, + ms.person_id AS statusPersonId FROM public.tbl_person p JOIN public.tbl_benutzer b ON (b.person_id = p.person_id) JOIN (SELECT uid, oe_kurzbz FROM public.tbl_benutzerfunktion WHERE funktion_kurzbz IN ?) bf ON (bf.uid = b.uid) @@ -352,14 +358,15 @@ class Recipient_model extends DB_Model mm.body, mrou.sent, pr.vorname, - pr.nachname + pr.nachname, + ms.person_id ORDER BY sent DESC'; return $this->execQuery($sql, array($person_id, $functions, $person_id)); } /** - * + * Gets all the sent message by the given person */ public function getSentMessages($person_id) { @@ -370,7 +377,8 @@ class Recipient_model extends DB_Model mr.sent, p.vorname, p.nachname, - MAX(ms.status) AS status + MAX(ms.status) AS status, + ms.person_id AS statusPersonId FROM public.tbl_msg_message mm JOIN public.tbl_msg_recipient mr ON (mr.message_id = mm.message_id) JOIN public.tbl_msg_status ms ON (ms.message_id = mm.message_id AND mr.person_id = mr.person_id) @@ -384,7 +392,8 @@ class Recipient_model extends DB_Model mm.body, mr.sent, p.vorname, - p.nachname + p.nachname, + ms.person_id ORDER BY mr.sent DESC'; return $this->execQuery($sql, array($person_id)); diff --git a/public/js/messaging/read.js b/public/js/messaging/read.js index 348e6b3ed..99426bffa 100644 --- a/public/js/messaging/read.js +++ b/public/js/messaging/read.js @@ -2,35 +2,108 @@ // List all personal messages, used by view system/messages/ajaxRead // *********************************************************************** -// +// Global variable that contains tha tabulator instance var tableMessageLst; /** - * + * Use DialogLib to display a Generic error */ -function genericError() +function readMessagesGenericError() { FHC_DialogLib.alertError("An error occurred while retrieving message, contact the website administrator"); } /** - * + * Gets all the received messages */ function getReceivedMessages() { - _getMessages(FHC_JS_DATA_STORAGE_OBJECT.called_path + '/listReceivedMessages'); + _getMessages(FHC_JS_DATA_STORAGE_OBJECT.called_path + "/listReceivedMessages"); } /** - * + * Gets all the sent messages */ function getSentMessages() { - _getMessages(FHC_JS_DATA_STORAGE_OBJECT.called_path + '/listSentMessages'); + _getMessages(FHC_JS_DATA_STORAGE_OBJECT.called_path + "/listSentMessages"); } /** - * + * Change the TinyMCE content + */ +function changeTinyMCE(row) +{ + tinyMCE.get("readMessagePanel").setContent(row.getData().body); +} + +/** + * Called on Tabulator row click event + * - If a clicked message is unread thes is set as read + * - Change the TinyMCE content with the clicked message body + */ +function rowClick(e, row) +{ + // If the message is unread + if (row.getData().status == "0") + { + FHC_AjaxClient.ajaxCallPost( + FHC_JS_DATA_STORAGE_OBJECT.called_path + "/setMessageRead", + { + message_id: row.getData().message_id, + statusPersonId: row.getData().statusPersonId + }, + { + successCallback: function(data, textStatus, jqXHR) { + + if (FHC_AjaxClient.isSuccess(data)) + { + rowFormatter(row, "normal"); + } + else + { + readMessagesGenericError(); + } + }, + errorCallback: readMessagesGenericError, + veilTimeout: 300 + } + ); + } + + changeTinyMCE(row); // Change TinyMCE content +} + +/** + * Radio button click event to switch between received and sent messages + */ +function toggleMessages() +{ + // + if ($(this)[0].className.search("active") == -1) + { + $(this)[0].id == "r" ? getReceivedMessages() : getSentMessages(); + } +} + +/** + * Formats tabulator rows + */ +function rowFormatter(row, fontWeight = 700) +{ + if (row.getData().status == "0") + { + var cells = row.getElement().childNodes; + + for (var i = 0; i < cells.length; i++) + { + cells[i].style.fontWeight = fontWeight; + } + } +} + +/** + * Get received/sent messages and change tabulator content */ function _getMessages(getMessagesURL) { @@ -48,42 +121,22 @@ function _getMessages(getMessagesURL) } catch (syntaxError) { - genericError(); + readMessagesGenericError(); } } }, - errorCallback: genericError, + errorCallback: readMessagesGenericError, veilTimeout: 300 } ); } /** - * - */ -function changeTinyMCE(e, row) -{ - tinyMCE.get("readMessagePanel").setContent(row._row.data.body); -} - -/** - * - */ -function toggleMessages() -{ - // - if ($(this)[0].className.search('active') == -1) - { - $(this)[0].id == 'r' ? getReceivedMessages() : getSentMessages(); - } -} - -/** - * + * Start! */ $(document).ready(function () { - // + // TinyMCE initialization tinymce.init({ selector: "#readMessagePanel", plugins: "autoresize", @@ -95,7 +148,7 @@ $(document).ready(function () { autoresize_bottom_margin: 0 }); - // + // Tabulator initialization tableMessageLst = new Tabulator("#lstMessagesPanel", { height: "400px", pagination: "local", @@ -105,13 +158,14 @@ $(document).ready(function () { {title: "To", field: "to", width: 400}, {title: "Date", field: "sent", sorter: "datetime", width: 150} ], - rowClick: changeTinyMCE + rowClick: rowClick, + rowFormatter: rowFormatter }); - // - $('.toggleMessages .btn').click(toggleMessages); + // Bind radio buttons click event with toggleMessages function + $(".toggleMessages .btn").click(toggleMessages); - // + // First retrieve the received message and populate the tabulator getReceivedMessages(); }); From 18ea98416f683e5291e10bd50d95a458aae8e083 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 4 Jul 2019 15:11:58 +0200 Subject: [PATCH 14/72] From/To toggle tabulator columns --- public/js/messaging/read.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/public/js/messaging/read.js b/public/js/messaging/read.js index 99426bffa..e1fe784d0 100644 --- a/public/js/messaging/read.js +++ b/public/js/messaging/read.js @@ -18,6 +18,9 @@ function readMessagesGenericError() */ function getReceivedMessages() { + tableMessageLst.hideColumn("to"); + tableMessageLst.showColumn("from"); + _getMessages(FHC_JS_DATA_STORAGE_OBJECT.called_path + "/listReceivedMessages"); } @@ -26,6 +29,9 @@ function getReceivedMessages() */ function getSentMessages() { + tableMessageLst.hideColumn("from"); + tableMessageLst.showColumn("to"); + _getMessages(FHC_JS_DATA_STORAGE_OBJECT.called_path + "/listSentMessages"); } @@ -154,8 +160,8 @@ $(document).ready(function () { pagination: "local", columns: [ {title: "Subject", field: "subject", width: 700, responsive: 0}, - {title: "From", field: "from", width: 400}, - {title: "To", field: "to", width: 400}, + {title: "From", field: "from", width: 400, visible: false}, + {title: "To", field: "to", width: 400, visible: false}, {title: "Date", field: "sent", sorter: "datetime", width: 150} ], rowClick: rowClick, From 48bcc77c975ec19ddc7c0ca8bfe4f6fa4b886735 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 4 Jul 2019 17:18:01 +0200 Subject: [PATCH 15/72] - Added CSS public/css/Tabulator.css and public/css/TinyMCE.css - Added these new CSS to views/templates/FHC-Header.php - Unified messages CSS in public/css/messaging/message.css - Messages Inbox/Outbox GUI beautified --- .../views/system/messages/ajaxRead.php | 19 +- .../views/system/messages/ajaxWrite.php | 2 +- .../views/system/messages/htmlError.php | 2 +- .../views/system/messages/htmlRead.php | 2 +- .../views/system/messages/htmlSuccess.php | 2 +- .../views/system/messages/htmlWriteReply.php | 2 +- .../system/messages/htmlWriteTemplate.php | 2 +- application/views/templates/FHC-Header.php | 9 +- public/css/Tabulator.css | 14 ++ public/css/TinyMCE.css | 7 + public/css/messaging/message.css | 191 ++++++++++++++++++ public/css/messaging/messageReply.css | 17 -- public/css/messaging/messageSent.css | 25 --- public/css/messaging/messageWrite.css | 29 --- public/js/messaging/read.js | 20 +- 15 files changed, 245 insertions(+), 98 deletions(-) create mode 100644 public/css/Tabulator.css create mode 100644 public/css/TinyMCE.css create mode 100644 public/css/messaging/message.css delete mode 100644 public/css/messaging/messageReply.css delete mode 100644 public/css/messaging/messageSent.css delete mode 100644 public/css/messaging/messageWrite.css diff --git a/application/views/system/messages/ajaxRead.php b/application/views/system/messages/ajaxRead.php index b8d2ea4a6..f5a733c74 100644 --- a/application/views/system/messages/ajaxRead.php +++ b/application/views/system/messages/ajaxRead.php @@ -13,21 +13,20 @@ 'ajaxlib' => true, 'dialoglib' => true, 'tinymce' => true, - 'customJSs' => array('public/js/messaging/read.js') + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), + 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/read.js') ) ); ?> -
-
- - +
+
+ + + +
-
+
diff --git a/application/views/system/messages/ajaxWrite.php b/application/views/system/messages/ajaxWrite.php index a21a724b2..88767628c 100644 --- a/application/views/system/messages/ajaxWrite.php +++ b/application/views/system/messages/ajaxWrite.php @@ -11,7 +11,7 @@ 'ajaxlib' => true, 'dialoglib' => true, 'tinymce' => true, - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageWrite.css'), + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/write.js') ) ); diff --git a/application/views/system/messages/htmlError.php b/application/views/system/messages/htmlError.php index 7e029b50c..78ffc7164 100644 --- a/application/views/system/messages/htmlError.php +++ b/application/views/system/messages/htmlError.php @@ -7,7 +7,7 @@ 'bootstrap' => true, 'fontawesome' => true, 'sbadmintemplate' => true, - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageSent.css') + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css') ) ); ?> diff --git a/application/views/system/messages/htmlRead.php b/application/views/system/messages/htmlRead.php index 01a5421ac..390e84ccc 100644 --- a/application/views/system/messages/htmlRead.php +++ b/application/views/system/messages/htmlRead.php @@ -7,7 +7,7 @@ 'bootstrap' => true, 'fontawesome' => true, 'sbadmintemplate' => true, - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageReply.css') + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css') ) ); ?> diff --git a/application/views/system/messages/htmlSuccess.php b/application/views/system/messages/htmlSuccess.php index 0260c9d16..e421a77e0 100644 --- a/application/views/system/messages/htmlSuccess.php +++ b/application/views/system/messages/htmlSuccess.php @@ -7,7 +7,7 @@ 'bootstrap' => true, 'fontawesome' => true, 'sbadmintemplate' => true, - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageSent.css') + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css') ) ); ?> diff --git a/application/views/system/messages/htmlWriteReply.php b/application/views/system/messages/htmlWriteReply.php index b9932148b..dde6cf17a 100644 --- a/application/views/system/messages/htmlWriteReply.php +++ b/application/views/system/messages/htmlWriteReply.php @@ -8,7 +8,7 @@ 'fontawesome' => true, 'tinymce' => true, 'sbadmintemplate' => true, - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageWrite.css'), + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/messageWriteReply.js') ) ); diff --git a/application/views/system/messages/htmlWriteTemplate.php b/application/views/system/messages/htmlWriteTemplate.php index 7132cfb36..9d087f2ca 100644 --- a/application/views/system/messages/htmlWriteTemplate.php +++ b/application/views/system/messages/htmlWriteTemplate.php @@ -11,7 +11,7 @@ 'tinymce' => true, 'sbadmintemplate' => true, 'widgets' => true, - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageWrite.css'), + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/messageWrite.js') ) ); diff --git a/application/views/templates/FHC-Header.php b/application/views/templates/FHC-Header.php index 7b75e2ad7..2d6a92ace 100644 --- a/application/views/templates/FHC-Header.php +++ b/application/views/templates/FHC-Header.php @@ -80,7 +80,14 @@ } // Tabulator CSS - if ($tabulator === true) generateCSSsInclude('vendor/olifolkerd/tabulator/dist/css/bootstrap/tabulator_bootstrap.min.css'); + if ($tabulator === true) + { + generateCSSsInclude('vendor/olifolkerd/tabulator/dist/css/bootstrap/tabulator_bootstrap.min.css'); + generateCSSsInclude('public/css/Tabulator.css'); + } + + // Tinymce CSS + if ($tinymce === true) generateCSSsInclude('public/css/TinyMCE.css'); // -------------------------------------------------------------------------------------------------------- // From public folder diff --git a/public/css/Tabulator.css b/public/css/Tabulator.css new file mode 100644 index 000000000..359f29e72 --- /dev/null +++ b/public/css/Tabulator.css @@ -0,0 +1,14 @@ +.tabulator-col { + font-size: 14px; +} + +.tabulator-page { + color: black; + opacity: 1 !important; + padding: 2px 7px !important; + border: 0px !important; +} + +.tabulator-page.active { + color: #337ab7 !important; +} diff --git a/public/css/TinyMCE.css b/public/css/TinyMCE.css new file mode 100644 index 000000000..a6d956b48 --- /dev/null +++ b/public/css/TinyMCE.css @@ -0,0 +1,7 @@ +.mce-tinymce .mce-container .mce-panel { + border-width: 0px; +} + +.mce-panel { + border-width: 0px !important; +} diff --git a/public/css/messaging/message.css b/public/css/messaging/message.css new file mode 100644 index 000000000..5d62a5e6a --- /dev/null +++ b/public/css/messaging/message.css @@ -0,0 +1,191 @@ +/* Smaller subject field */ +input[type=text] { + height: 28px; + padding: 0; +} + +.msgfield label { + margin-bottom: 0 !important; + margin-top: 3px; +} + +@media screen and (min-width: 1200px) { + .col-lg-1.msgfieldcol-left { + width: 13%; + } + + .col-lg-11.msgfieldcol-right { + width: 87%; + } +} + +#sendButton { + width: 120px; +} + +/* Overwrites the Widget.css class */ +div .width-150px { + width: 200px; +} + +.panel-heading { + font-size: 16px; +} + +.signatureblock { + color: grey; +} + +.signatureblocklink { + color: grey; +} + +.signatureblocklink:hover { + color: #337ab7; +} + +.rwd-line { + display: block; +} + +@media screen and (min-width: 1831px) { + .rwd-line { + display: inline; + } +} + +.panel-heading { + font-size: 16px; +} + +@media screen and (min-width: 1500px) { + #msgtable { + width: 70%; + } +} + +#msgtable td { + border: none !important; +} + +#replybutton { + width: 120px; +} + +/* STYLE THE HTML ELEMENTS (INCLUDES RESETS FOR THE DEFAULT FIELDSET AND LEGEND STYLES) */ +fieldset { + margin: 0; + padding: 2rem; + box-sizing: border-box; + display: block; + border: none; + border: solid 1px #CCC; + min-width: 0; + background-color: #FFF; +} +fieldset legend { + margin: 0 0 1.5rem; + padding: 0; + width: 100%; + float: left; + display: table; + font-size: 1.5rem; + line-height: 140%; + font-weight: 600; + color: #333; +} +fieldset legend + * { + clear: both; +} +body:not(:-moz-handler-blocked) fieldset { + display: table-cell; +} + +/* TOGGLE STYLING */ +.toggle { + margin: 0 0 1.5rem; + box-sizing: border-box; + font-size: 0; + display: flex; + flex-flow: row nowrap; + justify-content: flex-start; + align-items: stretch; +} +.toggle input { + width: 0; + height: 0; + position: absolute; + left: -9999px; +} +.toggle input + label { + margin: 0; + padding: .75rem 2rem; + box-sizing: border-box; + position: relative; + display: inline-block; + border: solid 1px #DDD; + background-color: #FFF; + font-size: 14px; + line-height: 140%; + font-weight: 600; + text-align: center; + box-shadow: 0 0 0 rgba(255, 255, 255, 0); + transition: border-color .15s ease-out, color .25s ease-out, background-color .15s ease-out, box-shadow .15s ease-out; + cursor: pointer; +} +.toggle input + label:first-of-type { + border-radius: 6px 0 0 6px; + border-right: none; +} +.toggle input + label:last-of-type { + border-radius: 0 6px 6px 0; + border-left: none; +} +.toggle input:hover + label { + border-color: #213140; +} +.toggle input:checked + label { + background-color: #337ab7; + color: #FFF; + box-shadow: 0 0 10px rgba(102, 179, 251, 0.5); + border-color: #337ab7; + z-index: 1; +} +.toggle input:focus + label { + outline: dotted 1px #CCC; + outline-offset: .45rem; +} +@media (max-width: 800px) { + .toggle input + label { + padding: .75rem .25rem; + flex: 0 0 50%; + display: flex; + justify-content: center; + align-items: center; + } +} + +/* STYLING FOR THE STATUS HELPER TEXT FOR THE DEMO */ +.status { + margin: 0; + font-size: 1rem; + font-weight: 400; +} +.status span { + font-weight: 600; + color: #B6985A; +} +.status span:first-of-type { + display: inline; +} +.status span:last-of-type { + display: none; +} +@media (max-width: 800px) { + .status span:first-of-type { + display: none; + } + .status span:last-of-type { + display: inline; + } +} diff --git a/public/css/messaging/messageReply.css b/public/css/messaging/messageReply.css deleted file mode 100644 index 17f978ecc..000000000 --- a/public/css/messaging/messageReply.css +++ /dev/null @@ -1,17 +0,0 @@ -.panel-heading { - font-size: 16px; -} - -@media screen and (min-width: 1500px) { - #msgtable { - width: 70%; - } -} - -#msgtable td { - border: none !important; -} - -#replybutton { - width: 120px; -} diff --git a/public/css/messaging/messageSent.css b/public/css/messaging/messageSent.css deleted file mode 100644 index 96403d797..000000000 --- a/public/css/messaging/messageSent.css +++ /dev/null @@ -1,25 +0,0 @@ -.panel-heading { - font-size: 16px; -} - -.signatureblock { - color: grey; -} - -.signatureblocklink { - color: grey; -} - -.signatureblocklink:hover { - color: #337ab7; -} - -.rwd-line { - display: block; -} - -@media screen and (min-width: 1831px) { - .rwd-line { - display: inline; - } -} diff --git a/public/css/messaging/messageWrite.css b/public/css/messaging/messageWrite.css deleted file mode 100644 index 3b5e1fd0e..000000000 --- a/public/css/messaging/messageWrite.css +++ /dev/null @@ -1,29 +0,0 @@ -/*smaller subject field*/ -input[type=text] { - height: 28px; - padding: 0; -} - -.msgfield label { - margin-bottom: 0 !important; - margin-top: 3px; -} - -@media screen and (min-width: 1200px) { - .col-lg-1.msgfieldcol-left { - width: 13%; - } - - .col-lg-11.msgfieldcol-right { - width: 87%; - } -} - -#sendButton { - width: 120px; -} - -/* Overwrites the Widget.css class */ -div .width-150px { - width: 200px; -} diff --git a/public/js/messaging/read.js b/public/js/messaging/read.js index e1fe784d0..edafe7483 100644 --- a/public/js/messaging/read.js +++ b/public/js/messaging/read.js @@ -85,11 +85,9 @@ function rowClick(e, row) */ function toggleMessages() { - // - if ($(this)[0].className.search("active") == -1) - { - $(this)[0].id == "r" ? getReceivedMessages() : getSentMessages(); - } + $(this)[0].id == "received" ? getReceivedMessages() : getSentMessages(); + + tableMessageLst.redraw(); // redraw table after its content is changed } /** @@ -158,18 +156,20 @@ $(document).ready(function () { tableMessageLst = new Tabulator("#lstMessagesPanel", { height: "400px", pagination: "local", + layout: "fitColumns", + layoutColumnsOnNewData: true, columns: [ - {title: "Subject", field: "subject", width: 700, responsive: 0}, - {title: "From", field: "from", width: 400, visible: false}, - {title: "To", field: "to", width: 400, visible: false}, - {title: "Date", field: "sent", sorter: "datetime", width: 150} + {title: "Subject", field: "subject", responsive: 0}, + {title: "From", field: "from", visible: false}, + {title: "To", field: "to", visible: false}, + {title: "Date", field: "sent", sorter: "datetime"} ], rowClick: rowClick, rowFormatter: rowFormatter }); // Bind radio buttons click event with toggleMessages function - $(".toggleMessages .btn").click(toggleMessages); + $("#toggleMessages input").click(toggleMessages); // First retrieve the received message and populate the tabulator getReceivedMessages(); From c30135f197c2bc3363d8ecbf6c3c48a27ca0eafe Mon Sep 17 00:00:00 2001 From: Paolo Date: Tue, 17 Sep 2019 10:38:25 +0200 Subject: [PATCH 16/72] Now MessageClient extends FHC_Controller and then starts the authentication --- .../system/messages/MessageClient.php | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/application/controllers/system/messages/MessageClient.php b/application/controllers/system/messages/MessageClient.php index 4cc4c9f2a..f7bc760ad 100644 --- a/application/controllers/system/messages/MessageClient.php +++ b/application/controllers/system/messages/MessageClient.php @@ -2,20 +2,19 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); -class MessageClient extends Auth_Controller +/** + * NOTE: MessageClient extends FHC_Controller and NOT Auth_Controller to be able to use + * the authentication system without the need to load the permissions system + */ +class MessageClient extends FHC_Controller { public function __construct() { - parent::__construct( - array( - 'read' => array('basis/person:r'), - 'write' => array('basis/person:r'), - 'listReceivedMessages' => array('basis/person:r'), - 'listSentMessages' => array('basis/person:r'), - 'sendMessageToOU' => array('basis/person:r'), - 'setMessageRead' => array('basis/person:r') - ) - ); + parent::__construct(); + + // Loads authentication library and starts authentication + // NOTE: it is loaded here because the controller extends FHC_Controller and NOT Auth_Controller + $this->load->library('AuthLib'); // Loads model CLMessagesModel which contains the GUI logic $this->load->model('CL/Messages_model', 'CLMessagesModel'); From 509fdef03b565bcb3ed744b10276743cd85d2be8 Mon Sep 17 00:00:00 2001 From: Paolo Date: Tue, 15 Oct 2019 11:54:01 +0200 Subject: [PATCH 17/72] - Removed tabulator local pagination for messages list - Removed error messages when the messages list is empty --- public/js/messaging/read.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/public/js/messaging/read.js b/public/js/messaging/read.js index edafe7483..c3b117636 100644 --- a/public/js/messaging/read.js +++ b/public/js/messaging/read.js @@ -119,13 +119,18 @@ function _getMessages(getMessagesURL) if (FHC_AjaxClient.hasData(data)) { - try + var messages = FHC_AjaxClient.getData(data); + + if ($.isArray(messages)) { - tableMessageLst.replaceData(JSON.parse(FHC_AjaxClient.getData(data))); - } - catch (syntaxError) - { - readMessagesGenericError(); + try + { + tableMessageLst.replaceData(JSON.parse()); + } + catch (syntaxError) + { + readMessagesGenericError(); + } } } }, @@ -155,7 +160,6 @@ $(document).ready(function () { // Tabulator initialization tableMessageLst = new Tabulator("#lstMessagesPanel", { height: "400px", - pagination: "local", layout: "fitColumns", layoutColumnsOnNewData: true, columns: [ From d40fd6391a1c876bca5cfbaee42be569587b9816 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 30 Oct 2019 18:30:16 +0100 Subject: [PATCH 18/72] Added some phrases for the messaging system, english only --- system/phrasesupdate.php | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index 4f5145034..a2ff737c2 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -3450,6 +3450,66 @@ $phrases = array( 'insertvon' => 'system' ) ) + ), + array( + 'app' => 'core', + 'category' => 'global', + 'phrase' => 'write', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => '', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Write', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'global', + 'phrase' => 'received', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => '', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Received', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'global', + 'phrase' => 'reply', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => '', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Reply', + 'description' => '', + 'insertvon' => 'system' + ) + ) ) ); From 6594a5288bfb38bfff2ca7a089b490b71ef03327 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 30 Oct 2019 18:30:50 +0100 Subject: [PATCH 19/72] Better CSS for messaging system pages --- public/css/messaging/message.css | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/public/css/messaging/message.css b/public/css/messaging/message.css index 5d62a5e6a..f5440b892 100644 --- a/public/css/messaging/message.css +++ b/public/css/messaging/message.css @@ -83,6 +83,7 @@ fieldset { min-width: 0; background-color: #FFF; } + fieldset legend { margin: 0 0 1.5rem; padding: 0; @@ -94,9 +95,11 @@ fieldset legend { font-weight: 600; color: #333; } + fieldset legend + * { clear: both; } + body:not(:-moz-handler-blocked) fieldset { display: table-cell; } @@ -106,17 +109,18 @@ body:not(:-moz-handler-blocked) fieldset { margin: 0 0 1.5rem; box-sizing: border-box; font-size: 0; - display: flex; flex-flow: row nowrap; justify-content: flex-start; align-items: stretch; } + .toggle input { width: 0; height: 0; position: absolute; left: -9999px; } + .toggle input + label { margin: 0; padding: .75rem 2rem; @@ -133,17 +137,21 @@ body:not(:-moz-handler-blocked) fieldset { transition: border-color .15s ease-out, color .25s ease-out, background-color .15s ease-out, box-shadow .15s ease-out; cursor: pointer; } + .toggle input + label:first-of-type { border-radius: 6px 0 0 6px; border-right: none; } + .toggle input + label:last-of-type { border-radius: 0 6px 6px 0; border-left: none; } + .toggle input:hover + label { border-color: #213140; } + .toggle input:checked + label { background-color: #337ab7; color: #FFF; @@ -151,15 +159,16 @@ body:not(:-moz-handler-blocked) fieldset { border-color: #337ab7; z-index: 1; } + .toggle input:focus + label { outline: dotted 1px #CCC; outline-offset: .45rem; } + @media (max-width: 800px) { .toggle input + label { padding: .75rem .25rem; flex: 0 0 50%; - display: flex; justify-content: center; align-items: center; } @@ -171,16 +180,20 @@ body:not(:-moz-handler-blocked) fieldset { font-size: 1rem; font-weight: 400; } + .status span { font-weight: 600; color: #B6985A; } + .status span:first-of-type { display: inline; } + .status span:last-of-type { display: none; } + @media (max-width: 800px) { .status span:first-of-type { display: none; @@ -189,3 +202,9 @@ body:not(:-moz-handler-blocked) fieldset { display: inline; } } + + +.buttonsSpacer { + display: inline-block; + width: 30px; +} From 36e5009d68b0731a7d35e5e260b55e055f997287 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 30 Oct 2019 18:31:21 +0100 Subject: [PATCH 20/72] Fixed problems with DialogLib --- public/js/DialogLib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/DialogLib.js b/public/js/DialogLib.js index 05558844a..3b472cd6a 100644 --- a/public/js/DialogLib.js +++ b/public/js/DialogLib.js @@ -74,7 +74,7 @@ var FHC_DialogLib = { buttons: [{ text: "Ok", click: function() { - $(this).dialog("close"); + $("#fhc-dialoglib-dialog").remove(); } }] }); From 2a4360862af77f03d59069f9041001184971fa5e Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 30 Oct 2019 18:35:46 +0100 Subject: [PATCH 21/72] =?UTF-8?q?-=20Reply=20Button=20in=20Inbox/outbox=20?= =?UTF-8?q?Page=20-=20Write=20new=20message=20Button=20with=20Layer/Popup?= =?UTF-8?q?=20-=20Degree=20Programs=20drop=20down=20displays=20longer=20na?= =?UTF-8?q?me=20(if=20prestudent=20best=C3=A4tigt=20(alias=20interessent?= =?UTF-8?q?=20with=20bestaetigtam=20!=3D=20null=20)=20receiver->=20dp,=20o?= =?UTF-8?q?therwise=20->=20infocenter)=20-=20SQL=20to=20get=20OU=20recipie?= =?UTF-8?q?nt=20doesn't=20use=20beginn=20/=20End=20of=20function=20-=20Alw?= =?UTF-8?q?ays=20set=20insertvon=20in=20tbl=5Fmsg=5Fstatus=20-=20Add=20Mul?= =?UTF-8?q?tilanguage=20Support=20for=20Message=20Page=20(not=20completed?= =?UTF-8?q?=20yet)=20-=20If=20in=20sent=20mode=20do=20not=20set=20messages?= =?UTF-8?q?=20as=20read=20-=20Error=20message=20when=20there=20are=20no=20?= =?UTF-8?q?Messages=20available=20shouldnt=20be=20displayed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/messages/MessageClient.php | 33 ++++++ application/libraries/MessageLib.php | 35 +++++- application/models/CL/Messages_model.php | 71 +++++++++--- application/models/crm/Prestudent_model.php | 18 ++- application/models/system/Recipient_model.php | 109 ++++++++++++++++-- .../views/system/messages/ajaxRead.php | 90 +++++++++------ .../views/system/messages/ajaxWriteReply.php | 80 +++++++++++++ public/js/messaging/read.js | 88 ++++++++++++-- public/js/messaging/writeReply.js | 48 ++++++++ 9 files changed, 494 insertions(+), 78 deletions(-) create mode 100644 application/views/system/messages/ajaxWriteReply.php create mode 100644 public/js/messaging/writeReply.js diff --git a/application/controllers/system/messages/MessageClient.php b/application/controllers/system/messages/MessageClient.php index f7bc760ad..a0cc5c518 100644 --- a/application/controllers/system/messages/MessageClient.php +++ b/application/controllers/system/messages/MessageClient.php @@ -18,6 +18,14 @@ class MessageClient extends FHC_Controller // Loads model CLMessagesModel which contains the GUI logic $this->load->model('CL/Messages_model', 'CLMessagesModel'); + + // Phrases used in loaded views + $this->loadPhrases( + array( + 'global', + 'ui' + ) + ); } /** @@ -38,6 +46,17 @@ class MessageClient extends FHC_Controller $this->load->view('system/messages/ajaxWrite', $this->CLMessagesModel->prepareAjaxWrite()); } + /** + * Starts the GUI used to reply to a received personal message + */ + public function writeReply() + { + $token = $this->input->get('token'); + + // Loads the view to reply to a message + $this->load->view('system/messages/ajaxWriteReply', $this->CLMessagesModel->prepareAjaxWriteReply($token)); + } + /** * Returns JSON that that contains all the received messages by the currently logged user */ @@ -66,6 +85,20 @@ class MessageClient extends FHC_Controller $this->outputJson($this->CLMessagesModel->sendToOrganisationUnit($receiverOU, $subject, $body)); } + /** + * Sends a message to an organisation unit + */ + public function sendMessageReply() + { + $receiver_id = $this->input->post('receiver_id'); + $relationmessage_id = $this->input->post('relationmessage_id'); + $token = $this->input->post('token'); + $subject = $this->input->post('subject'); + $body = $this->input->post('body'); + + $this->outputJson($this->CLMessagesModel->sendReply($receiver_id, $subject, $body, $relationmessage_id, $token)); + } + /** * Set a message as read */ diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 18b958e14..9224996c8 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -272,10 +272,17 @@ class MessageLib // If NOT found then insert the read status if (!$found) { + $uid = null; + if (!isEmptyString($messageTokenResult[0]->uid)) + { + $uid = $messageTokenResult[0]->uid; + } + $statusData = array( 'message_id' => getData($messageTokenResult)[0]->message_id, 'person_id' => getData($messageTokenResult)[0]->receiver_id, - 'status' => MSG_STATUS_READ + 'status' => MSG_STATUS_READ, + 'insertvon' => $uid ); $messageTokenResultIns = $this->_ci->MsgStatusModel->insert($statusData); @@ -383,6 +390,15 @@ class MessageLib // Starts database transaction $this->_ci->db->trans_start(false); + $this->_ci->load->model('person/Benutzer_model', 'BenutzerModel'); + + $uid = null; + $benutzerDB = $this->_ci->BenutzerModel->loadWhere(array('person_id' => $sender_id)); + if (hasData($benutzerDB)) + { + $uid = getData($benutzerDB)[0]->uid; + } + // Store message information in tbl_msg_message $messageData = array( 'person_id' => $sender_id, @@ -413,7 +429,8 @@ class MessageLib $statusData = array( 'message_id' => $messageId, 'person_id' => $receiver_id, - 'status' => MSG_STATUS_UNREAD + 'status' => MSG_STATUS_UNREAD, + 'insertvon' => $uid ); $saveMessageResult = $this->_ci->MsgStatusModel->insert($statusData); } @@ -511,7 +528,17 @@ 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 - return $this->_sendNotice(getData($messageResult)); + $messages = getData($messageResult); + if (count($messages) == 1 && $messages[0]->receiver_id == $this->_ci->config->item(self::CFG_SYSTEM_PERSON_ID)) + { + $messages = $this->_ci->RecipientModel->getReceivedMessagesByOE( + $messages[0]->oe_kurzbz, + $this->_ci->config->item(MessageLib::CFG_OU_RECEIVERS), + self::EMAIL_KONTAKT_TYPE + ); + } + + return $this->_sendNotice($messages); } /** @@ -614,11 +641,13 @@ class MessageLib // Checks if sender is fine $sender = $this->_getSender($sender_id); if (!hasData($sender)) return $sender; + // Checks if the sender and receiver organisation unit are valid if (($receiversOU != null && !$this->_ouExists($receiversOU)) || ($senderOU != null && !$this->_ouExists($senderOU))) { return error('The given organisation unit is not valid', MSG_ERR_INVALID_OU); } + // Checks subjects if (isEmptyString($subject)) return error('The given subject is an empty string', MSG_ERR_INVALID_SUBJECT); // Checks body diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index e907022aa..7673a6d71 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -62,7 +62,8 @@ class Messages_model extends CI_Model $statusData = array( 'message_id' => $message_id, 'person_id' => $person_id, - 'status' => MSG_STATUS_READ + 'status' => MSG_STATUS_READ, + 'insertvon' => getAuthUID() ); return $this->MsgStatusModel->insert($statusData); // insert and return result @@ -83,25 +84,61 @@ class Messages_model extends CI_Model { foreach (getData($ouResult) as $ou) { - $ouOptions .= sprintf("\n".'', $ou->oe_kurzbz, $ou->bezeichnung); + $ouOptions .= sprintf( + "\n".'', + is_numeric($ou->prestudent_id) ? $ou->oe_kurzbz : 'infocenter', + $ou->bezeichnung + ); } } return array('organisationUnitOptions' => $ouOptions); } + /** + * Prepares data for the view system/messages/ajaxWriteReply + */ + public function prepareAjaxWriteReply($token) + { + if (isEmptyString($token)) show_error('The given token is not valid'); + + // Retrieves message using the given token + $messageResult = $this->MessageTokenModel->getMessageByToken($token); + if (isError($messageResult)) show_error('An error occurred while loading this page, please contact the site administrator'); + + if (hasData($messageResult)) + { + $message = getData($messageResult)[0]; // Found message data + + // Retrieves message sender information + $senderResult = $this->MessageTokenModel->getSenderData($message->sender_id); + if (isError($senderResult)) show_error('An error occurred while loading this page, please contact the site administrator'); + + if (hasData($senderResult)) + { + $sender = getData($senderResult)[0]; // Found sender data + + $replySubject = self::REPLY_SUBJECT_PREFIX.$message->subject; + $replyBody = $this->_getReplyBody($message->body, $sender->vorname, $sender->nachname, $message->sent); + + return array ( + 'receiver' => $sender->vorname.' '.$sender->nachname, // yep! the sender of the sent message is the receiver of the reply message + 'subject' => $replySubject, + 'body' => $replyBody, + 'receiver_id' => $message->sender_id, + 'relationmessage_id' => $message->message_id, + 'token' => $token + ); + } + } + } + /** * Prepares data for the view system/messages/ajaxRead * If everything is fine returns a list of received messages (objects) */ public function prepareAjaxReadReceived() { - // Name and surname of the logged user - $loggedUserName = getAuthFirstname().' '.getAuthSurname(); - - // If empty then use a hard coded one - if (isEmptyString($loggedUserName)) $loggedUserName = 'Me'; - // Retrieves received messages for the logged user and its organisation units $receivedMessagesResult = $this->RecipientModel->getReceivedMessages( getAuthPersonId(), @@ -127,6 +164,7 @@ class Messages_model extends CI_Model $jsonRecord->sent = $sentDate->format('d/m/Y H:i:s'); $jsonRecord->status = $receivedMessage->status; $jsonRecord->statusPersonId = $receivedMessage->statuspersonid; + $jsonRecord->token = $receivedMessage->token; $jsonArray[] = $jsonRecord; } @@ -143,12 +181,6 @@ class Messages_model extends CI_Model */ public function prepareAjaxReadSent() { - // Name and surname of the logged user - $loggedUserName = getAuthFirstname().' '.getAuthSurname(); - - // If empty then use a hard coded one - if (isEmptyString($loggedUserName)) $loggedUserName = 'Me'; - // Retrieves sent messages from the logged user $sentMessagesResult = $this->RecipientModel->getSentMessages(getAuthPersonId()); if (isError($sentMessagesResult)) return $sentMessagesResult; // If an error occurred return it @@ -164,11 +196,20 @@ class Messages_model extends CI_Model $jsonRecord->message_id = $sentMessage->message_id; $jsonRecord->subject = $sentMessage->subject; $jsonRecord->body = $sentMessage->body; - $jsonRecord->to = $sentMessage->vorname.' '.$sentMessage->nachname; $sentDate = new DateTime($sentMessage->sent); $jsonRecord->sent = $sentDate->format('d/m/Y H:i:s'); $jsonRecord->status = $sentMessage->status; $jsonRecord->statusPersonId = $sentMessage->statuspersonid; + $jsonRecord->token = $sentMessage->token; + + if ($sentMessage->person_id == $this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID)) + { + $jsonRecord->to = $sentMessage->sg; + } + else + { + $jsonRecord->to = $sentMessage->vorname.' '.$sentMessage->nachname; + } $jsonArray[] = $jsonRecord; } diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index b4c756e52..b1ae9b8e9 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -529,13 +529,23 @@ class Prestudent_model extends DB_Model */ public function getOrganisationunitsByPersonId($person_id) { - $query = 'SELECT o.oe_kurzbz, o.bezeichnung + $query = 'SELECT o.oe_kurzbz, + sg.bezeichnung, + ps.prestudent_id FROM public.tbl_prestudent p - JOIN public.tbl_studiengang s USING(studiengang_kz) + JOIN public.tbl_studiengang sg USING(studiengang_kz) JOIN public.tbl_organisationseinheit o USING(oe_kurzbz) + LEFT JOIN ( + SELECT prestudent_id + FROM public.tbl_prestudentstatus + WHERE bestaetigtam IS NOT NULL + AND status_kurzbz = \'Interessent\' + ) ps USING(prestudent_id) WHERE p.person_id = ? - GROUP BY o.oe_kurzbz, o.bezeichnung - ORDER BY o.bezeichnung'; + GROUP BY o.oe_kurzbz, + sg.bezeichnung, + ps.prestudent_id + ORDER BY sg.bezeichnung'; return $this->execQuery($query, array($person_id)); } diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 46cf0e36f..76a0bf435 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -57,11 +57,13 @@ class Recipient_model extends DB_Model m.oe_kurzbz, s.status, s.statusinfo, - s.insertamum as statusamum + s.insertamum as statusamum, + b.uid FROM public.tbl_msg_recipient r JOIN public.tbl_msg_message m USING (message_id) JOIN ( SELECT * FROM public.tbl_msg_status WHERE status < ? ORDER BY insertamum DESC, status DESC - ) s ON (r.message_id = s.message_id AND r.person_id = s.person_id) + ) s ON (r.message_id = s.message_id AND r.person_id = s.person_id), + LEFT JOIN public.tbl_benutzer b USING(person_id) WHERE r.token = ? LIMIT 1'; @@ -217,7 +219,8 @@ class Recipient_model extends DB_Model mr.token, mm.subject, mm.body, - mr.sentinfo + mr.sentinfo, + mr.oe_kurzbz FROM public.tbl_msg_recipient mr INNER JOIN public.tbl_msg_message mm USING (message_id) LEFT JOIN ( SELECT person_id, kontakt FROM public.tbl_kontakt WHERE zustellung = true AND kontakttyp = ? @@ -315,11 +318,12 @@ class Recipient_model extends DB_Model p.vorname, p.nachname, MAX(ms.status) AS status, - ms.person_id AS statusPersonId + ms.person_id AS statusPersonId, + mr.token FROM public.tbl_msg_recipient mr JOIN public.tbl_msg_message mm ON (mm.message_id = mr.message_id) JOIN public.tbl_msg_status ms ON (ms.message_id = mr.message_id AND ms.person_id = mr.person_id) - JOIN public.tbl_person p ON (p.person_id = mr.person_id) + JOIN public.tbl_person p ON (p.person_id = mm.person_id) WHERE mr.person_id = ? AND mr.sent IS NOT NULL AND mr.sentinfo IS NULL @@ -330,7 +334,8 @@ class Recipient_model extends DB_Model mr.sent, p.vorname, p.nachname, - ms.person_id + ms.person_id, + mr.token UNION -- Messages sent to a person that belongs to the recipient organisation unit SELECT mrou.message_id, @@ -341,14 +346,21 @@ class Recipient_model extends DB_Model pr.vorname, pr.nachname, MAX(ms.status) AS status, - ms.person_id AS statusPersonId + ms.person_id AS statusPersonId, + mrou.token FROM public.tbl_person p JOIN public.tbl_benutzer b ON (b.person_id = p.person_id) - JOIN (SELECT uid, oe_kurzbz FROM public.tbl_benutzerfunktion WHERE funktion_kurzbz IN ?) bf ON (bf.uid = b.uid) + JOIN ( + SELECT uid, oe_kurzbz + FROM public.tbl_benutzerfunktion + WHERE (datum_von IS NULL OR datum_von <= NOW()) + AND (datum_bis IS NULL OR datum_bis >= NOW()) + AND funktion_kurzbz IN ? + ) bf ON (bf.uid = b.uid) JOIN public.tbl_msg_recipient mrou ON (mrou.oe_kurzbz = bf.oe_kurzbz) JOIN public.tbl_msg_message mm ON (mm.message_id = mrou.message_id) JOIN public.tbl_msg_status ms ON (ms.message_id = mrou.message_id AND ms.person_id = mrou.person_id) - JOIN public.tbl_person pr ON (pr.person_id = mrou.person_id) + JOIN public.tbl_person pr ON (pr.person_id = mm.person_id) WHERE p.person_id = ? AND mrou.sent IS NOT NULL AND mrou.sentinfo IS NULL @@ -359,12 +371,78 @@ class Recipient_model extends DB_Model mrou.sent, pr.vorname, pr.nachname, - ms.person_id + ms.person_id, + mrou.token ORDER BY sent DESC'; return $this->execQuery($sql, array($person_id, $functions, $person_id)); } + /** + * Gets only the recieved messages from an organisation unit where this person plays a role given by the parameter functions + */ + public function getReceivedMessagesByOE($oe_kurzbz, $functions, $kontaktType) + { + // Messages sent to a person that belongs to the recipient organisation unit + $sql = 'SELECT mm.message_id, + mm.subject, + mm.body, + mrou.person_id as receiver_id, + mrou.sentinfo, + mrou.token, + mrou.oe_kurzbz, + ks.kontakt as sender, + kr.kontakt as receiver, + mu.mitarbeiter_uid as employeeContact, + mb.mitarbeiter_uid as senderemployeeContact + FROM public.tbl_benutzer b + JOIN ( + SELECT uid, oe_kurzbz + FROM public.tbl_benutzerfunktion + WHERE (datum_von IS NULL OR datum_von <= NOW()) + AND (datum_bis IS NULL OR datum_bis >= NOW()) + AND funktion_kurzbz IN ? + ) bf ON (bf.uid = b.uid) + JOIN public.tbl_msg_recipient mrou ON (mrou.oe_kurzbz = bf.oe_kurzbz) + JOIN public.tbl_msg_message mm ON (mm.message_id = mrou.message_id) + JOIN public.tbl_msg_status ms ON (ms.message_id = mrou.message_id AND ms.person_id = mrou.person_id) + JOIN public.tbl_person pr ON (pr.person_id = mm.person_id) + LEFT JOIN ( + SELECT person_id, kontakt FROM public.tbl_kontakt WHERE zustellung = true AND kontakttyp = ? + ) ks ON (ks.person_id = mm.person_id) + LEFT JOIN ( + SELECT person_id, kontakt FROM public.tbl_kontakt WHERE zustellung = true AND kontakttyp = ? + ) kr ON (kr.person_id = mrou.person_id) + LEFT JOIN ( + SELECT b.person_id, + m.mitarbeiter_uid + FROM public.tbl_benutzer b INNER JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid) + WHERE b.aktiv = TRUE + ) mu ON (mu.person_id = mrou.person_id) + LEFT JOIN ( + SELECT b.person_id, + m.mitarbeiter_uid + FROM public.tbl_benutzer b INNER JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid) + WHERE b.aktiv = TRUE + ) mb ON (mb.person_id = mm.person_id) + WHERE bf.oe_kurzbz = ? + AND mrou.sent IS NULL + AND mrou.sentinfo IS NOT NULL + GROUP BY mm.message_id, + mm.subject, + mm.body, + mrou.person_id, + mrou.sentinfo, + mrou.token, + mrou.oe_kurzbz, + ks.kontakt, + kr.kontakt, + mu.mitarbeiter_uid, + mb.mitarbeiter_uid'; + + return $this->execQuery($sql, array($functions, $kontaktType, $kontaktType, $oe_kurzbz)); + } + /** * Gets all the sent message by the given person */ @@ -375,14 +453,18 @@ class Recipient_model extends DB_Model mm.subject, mm.body, mr.sent, + p.person_id, p.vorname, p.nachname, MAX(ms.status) AS status, - ms.person_id AS statusPersonId + ms.person_id AS statusPersonId, + sg.bezeichnung AS sg, + mr.token FROM public.tbl_msg_message mm JOIN public.tbl_msg_recipient mr ON (mr.message_id = mm.message_id) JOIN public.tbl_msg_status ms ON (ms.message_id = mm.message_id AND mr.person_id = mr.person_id) JOIN public.tbl_person p ON (p.person_id = mr.person_id) + LEFT JOIN public.tbl_studiengang sg ON (sg.oe_kurzbz = mr.oe_kurzbz) WHERE mm.person_id = ? AND mr.sent IS NOT NULL AND mr.sentinfo IS NULL @@ -391,9 +473,12 @@ class Recipient_model extends DB_Model mm.subject, mm.body, mr.sent, + p.person_id, p.vorname, p.nachname, - ms.person_id + ms.person_id, + sg.bezeichnung, + mr.token ORDER BY mr.sent DESC'; return $this->execQuery($sql, array($person_id)); diff --git a/application/views/system/messages/ajaxRead.php b/application/views/system/messages/ajaxRead.php index f5a733c74..1e4dbd187 100644 --- a/application/views/system/messages/ajaxRead.php +++ b/application/views/system/messages/ajaxRead.php @@ -1,34 +1,56 @@ -load->view( - 'templates/FHC-Header', - array( - 'title' => 'Read personal messages', - 'jquery' => true, - 'jqueryui' => true, - 'bootstrap' => true, - 'fontawesome' => true, - 'sbadmintemplate' => true, - 'momentjs' => true, - 'tabulator' => true, - 'ajaxlib' => true, - 'dialoglib' => true, - 'tinymce' => true, - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), - 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/read.js') - ) - ); -?> - -
-
- - - - -
-
-
-
- - -load->view("templates/FHC-Footer"); ?> +load->view( + 'templates/FHC-Header', + array( + 'title' => 'Read personal messages', + 'jquery' => true, + 'jqueryui' => true, + 'bootstrap' => true, + 'fontawesome' => true, + 'sbadmintemplate' => true, + 'momentjs' => true, + 'tabulator' => true, + 'ajaxlib' => true, + 'dialoglib' => true, + 'tinymce' => true, + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), + 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/read.js') + ) + ); +?> + + +
+ + + + + + + + + + + + + + + + + + + +
+ + +
+ +
+ + + +load->view("templates/FHC-Footer"); ?> diff --git a/application/views/system/messages/ajaxWriteReply.php b/application/views/system/messages/ajaxWriteReply.php new file mode 100644 index 000000000..25602271c --- /dev/null +++ b/application/views/system/messages/ajaxWriteReply.php @@ -0,0 +1,80 @@ +load->view( + 'templates/FHC-Header', + array( + 'title' => 'Reply to a message', + 'jquery' => true, + 'jqueryui' => true, + 'bootstrap' => true, + 'fontawesome' => true, + 'sbadmintemplate' => true, + 'ajaxlib' => true, + 'dialoglib' => true, + 'tinymce' => true, + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), + 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/writeReply.js') + ) + ); +?> + +
+
+
+
+
+ +
+
+
+
+
+ +
+
+ + + +
+
+
+
+
+
+ +
+   +
+ + + +
+
+
+
+
+
+ + +
+
+
+
+
+ + + + + + +
+
+
+
+
+ + +load->view("templates/FHC-Footer"); ?> diff --git a/public/js/messaging/read.js b/public/js/messaging/read.js index c3b117636..cc463b3f7 100644 --- a/public/js/messaging/read.js +++ b/public/js/messaging/read.js @@ -4,6 +4,7 @@ // Global variable that contains tha tabulator instance var tableMessageLst; +var selectedToggleMessage = "received"; /** * Use DialogLib to display a Generic error @@ -40,7 +41,14 @@ function getSentMessages() */ function changeTinyMCE(row) { - tinyMCE.get("readMessagePanel").setContent(row.getData().body); + if (row == null) + { + tinyMCE.get("readMessagePanel").setContent(''); + } + else + { + tinyMCE.get("readMessagePanel").setContent(row.getData().body); + } } /** @@ -50,8 +58,8 @@ function changeTinyMCE(row) */ function rowClick(e, row) { - // If the message is unread - if (row.getData().status == "0") + // If in received mode and the message is not unread + if (selectedToggleMessage == "received" && row.getData().status == "0") { FHC_AjaxClient.ajaxCallPost( FHC_JS_DATA_STORAGE_OBJECT.called_path + "/setMessageRead", @@ -64,7 +72,8 @@ function rowClick(e, row) if (FHC_AjaxClient.isSuccess(data)) { - rowFormatter(row, "normal"); + rowFormatter(row, "normal"); // format row + row.getData().status = "1"; // update status to read } else { @@ -77,6 +86,12 @@ function rowClick(e, row) ); } + // If NOT in send mode + if (selectedToggleMessage == "received") + { + $("#replyMessage").show(); + } + changeTinyMCE(row); // Change TinyMCE content } @@ -85,8 +100,19 @@ function rowClick(e, row) */ function toggleMessages() { - $(this)[0].id == "received" ? getReceivedMessages() : getSentMessages(); + if ($(this)[0].id == "received") + { + selectedToggleMessage = "received"; + getReceivedMessages(); + } + else + { + selectedToggleMessage = "send"; + $("#replyMessage").hide(); + getSentMessages(); + } + changeTinyMCE(null); // clean tinymce tableMessageLst.redraw(); // redraw table after its content is changed } @@ -119,13 +145,19 @@ function _getMessages(getMessagesURL) if (FHC_AjaxClient.hasData(data)) { - var messages = FHC_AjaxClient.getData(data); + var messages = null; + + try + { + messages = JSON.parse(FHC_AjaxClient.getData(data)); + } + catch (syntaxError) {} if ($.isArray(messages)) { try { - tableMessageLst.replaceData(JSON.parse()); + tableMessageLst.replaceData(messages); } catch (syntaxError) { @@ -141,10 +173,39 @@ function _getMessages(getMessagesURL) } /** - * Start! + * Open new tab/window to write a new message + */ +function writeNewMessage() +{ + window.open("write", "_blank"); +} + +/** + * Open new tab/window to reply to a received message + */ +function replyMessage() +{ + var selectedMessages = tableMessageLst.getSelectedData(); + + if ($.isArray(selectedMessages)) + { + var selectedMessage = selectedMessages[0]; + + window.open("writeReply?token=" + selectedMessage.token, "_blank"); + } + else // + { + FHC_DialogLib.alertInfo("Please select a message"); + } +} + +/** + * Start me up! */ $(document).ready(function () { + $("#replyMessage").hide(); + // TinyMCE initialization tinymce.init({ selector: "#readMessagePanel", @@ -153,14 +214,15 @@ $(document).ready(function () { toolbar: false, statusbar: false, readonly: 1, - autoresize_min_height: 200, + autoresize_min_height: 300, autoresize_bottom_margin: 0 }); // Tabulator initialization tableMessageLst = new Tabulator("#lstMessagesPanel", { - height: "400px", + height: "270px", layout: "fitColumns", + selectable: 1, layoutColumnsOnNewData: true, columns: [ {title: "Subject", field: "subject", responsive: 0}, @@ -175,6 +237,12 @@ $(document).ready(function () { // Bind radio buttons click event with toggleMessages function $("#toggleMessages input").click(toggleMessages); + // Bind write a new message button + $("#writeMessage").click(writeNewMessage); + + // Bind reply to a message button + $("#replyMessage").click(replyMessage); + // First retrieve the received message and populate the tabulator getReceivedMessages(); diff --git a/public/js/messaging/writeReply.js b/public/js/messaging/writeReply.js new file mode 100644 index 000000000..aeb13dc2c --- /dev/null +++ b/public/js/messaging/writeReply.js @@ -0,0 +1,48 @@ +// **************************************************************************************** +// Write a reply to a received message, used by view system/messages/ajaxWriteReply +// **************************************************************************************** + +/** + * + */ +function sendReply() +{ + FHC_AjaxClient.ajaxCallPost( + FHC_JS_DATA_STORAGE_OBJECT.called_path + '/sendMessageReply', + { + receiver_id: $('#receiver_id').val(), + relationmessage_id: $('#relationmessage_id').val(), + token: $('#token').val(), + subject: $('#subject').html(), + body: tinyMCE.get("body").getContent() + }, + { + successCallback: function(data, textStatus, jqXHR) { + + FHC_DialogLib.alertSuccess("Message sent succesfully"); + }, + errorCallback: function() { + FHC_DialogLib.alertError("Error"); + }, + veilTimeout: 300 + } + ); +} + +/** + * + */ +$(document).ready(function () { + + // + tinymce.init({ + selector: "#body", + plugins: "autoresize", + autoresize_min_height: 150, + autoresize_max_height: 600, + autoresize_bottom_margin: 10 + }); + + $('#sendButton').click(sendReply); + +}); From ece06bc462971022917b2b81fbfc5ad7fc622281 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 6 Nov 2019 16:34:20 +0100 Subject: [PATCH 22/72] 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"); From 565cf93f5d1f8177245cd8078c7c7be25cb30ec3 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 14 Nov 2019 13:49:31 +0100 Subject: [PATCH 23/72] - Messages GUI multilingual - Tabulator refresh fixed --- application/views/system/messages/ajaxRead.php | 1 + application/views/system/messages/ajaxWrite.php | 13 ++++++++----- .../views/system/messages/ajaxWriteReply.php | 11 ++++++----- .../views/system/messages/htmlWriteTemplate.php | 1 + public/js/messaging/messageWrite.js | 4 ++-- public/js/messaging/messageWriteReply.js | 2 +- public/js/messaging/read.js | 6 ++++-- public/js/messaging/write.js | 8 ++++---- 8 files changed, 27 insertions(+), 19 deletions(-) diff --git a/application/views/system/messages/ajaxRead.php b/application/views/system/messages/ajaxRead.php index 1e4dbd187..2ff1f6cbb 100644 --- a/application/views/system/messages/ajaxRead.php +++ b/application/views/system/messages/ajaxRead.php @@ -13,6 +13,7 @@ 'ajaxlib' => true, 'dialoglib' => true, 'tinymce' => true, + 'phrases' => array('global', 'ui'), 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/read.js') ) diff --git a/application/views/system/messages/ajaxWrite.php b/application/views/system/messages/ajaxWrite.php index 88767628c..6080f3eef 100644 --- a/application/views/system/messages/ajaxWrite.php +++ b/application/views/system/messages/ajaxWrite.php @@ -11,6 +11,7 @@ 'ajaxlib' => true, 'dialoglib' => true, 'tinymce' => true, + 'phrases' => array('global', 'ui'), 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/write.js') ) @@ -22,13 +23,13 @@
- +
- +

- +
diff --git a/application/views/system/messages/ajaxWriteReply.php b/application/views/system/messages/ajaxWriteReply.php index 25602271c..36d999fc0 100644 --- a/application/views/system/messages/ajaxWriteReply.php +++ b/application/views/system/messages/ajaxWriteReply.php @@ -11,6 +11,7 @@ 'ajaxlib' => true, 'dialoglib' => true, 'tinymce' => true, + 'phrases' => array('global', 'ui'), 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/writeReply.js') ) @@ -22,13 +23,13 @@
- +
- +
@@ -40,7 +41,7 @@
- +
 
@@ -53,7 +54,7 @@
- + + +
+ +
+ p->t('ui', 'altRecipientNote'); ?> +

diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index f0c66b758..e4ea4aacb 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -4174,6 +4174,26 @@ When on hold, the date is only a reminder.', 'insertvon' => 'system' ) ) + ), + array( + 'app' => 'core', + 'category' => 'ui', + 'phrase' => 'altRecipientNote', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => '* This is a notice to notice you that you have been noticed DE', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => '* This is a notice to notice you that you have been noticed', + 'description' => '', + 'insertvon' => 'system' + ) + ) ) ); From 53ac4d11ba33eb31c5350d3b50a545cce15eebe6 Mon Sep 17 00:00:00 2001 From: Paolo Date: Tue, 4 Feb 2020 14:42:53 +0100 Subject: [PATCH 40/72] Do not retrieve the degree program name from studiengang table but directly from the organization unit table in student sent messages page and student write to organisation unit page --- application/models/CL/Messages_model.php | 4 ++-- application/models/crm/Prestudent_model.php | 7 ++++--- application/models/system/Recipient_model.php | 15 +++++---------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index 84f4e59aa..87eff0f99 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -183,7 +183,7 @@ class Messages_model extends CI_Model public function prepareAjaxReadSent() { // Retrieves sent messages from the logged user - $sentMessagesResult = $this->RecipientModel->getSentMessages(getAuthPersonId(), self::ALT_OE); + $sentMessagesResult = $this->RecipientModel->getSentMessages(getAuthPersonId()); if (isError($sentMessagesResult)) return $sentMessagesResult; // If an error occurred return it if (hasData($sentMessagesResult)) @@ -205,7 +205,7 @@ class Messages_model extends CI_Model if ($sentMessage->person_id == $this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID)) { - $jsonRecord->to = $sentMessage->sg; + $jsonRecord->to = $sentMessage->oe; } else { diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index 5b74ed5e4..94d77f8d3 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -524,11 +524,12 @@ class Prestudent_model extends DB_Model /** * Get organisation units for all the prestudents of a person + * TODO */ public function getOrganisationunitsByPersonId($person_id) { $query = 'SELECT o.oe_kurzbz, - sg.bezeichnung, + o.bezeichnung, ps.prestudent_id FROM public.tbl_prestudent p JOIN public.tbl_studiengang sg USING(studiengang_kz) @@ -541,9 +542,9 @@ class Prestudent_model extends DB_Model ) ps USING(prestudent_id) WHERE p.person_id = ? GROUP BY o.oe_kurzbz, - sg.bezeichnung, + o.bezeichnung, ps.prestudent_id - ORDER BY sg.bezeichnung'; + ORDER BY o.bezeichnung'; return $this->execQuery($query, array($person_id)); } diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 8f5dfa397..c2acd2d56 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -446,7 +446,7 @@ class Recipient_model extends DB_Model /** * Gets all the sent message by the given person */ - public function getSentMessages($person_id, $altOe = '') + public function getSentMessages($person_id) { $sql = 'SELECT mm.message_id, mm.relationmessage_id, @@ -458,18 +458,13 @@ class Recipient_model extends DB_Model p.nachname, MAX(ms.status) AS status, ms.person_id AS statusPersonId, - sg.bezeichnung AS sg, + oe.bezeichnung AS oe, mr.token FROM public.tbl_msg_message mm JOIN public.tbl_msg_recipient mr ON (mr.message_id = mm.message_id) JOIN public.tbl_msg_status ms ON (ms.message_id = mm.message_id AND mr.person_id = mr.person_id) JOIN public.tbl_person p ON (p.person_id = mr.person_id) - LEFT JOIN ( - SELECT oe_kurzbz, bezeichnung - FROM public.tbl_studiengang - UNION - SELECT ?, ? - ) sg ON (sg.oe_kurzbz = mr.oe_kurzbz) + JOIN public.tbl_organisationseinheit oe ON (oe.oe_kurzbz = mr.oe_kurzbz) WHERE mm.person_id = ? AND mr.sent IS NOT NULL AND mr.sentinfo IS NULL @@ -482,10 +477,10 @@ class Recipient_model extends DB_Model p.vorname, p.nachname, ms.person_id, - sg.bezeichnung, + oe.bezeichnung, mr.token ORDER BY mr.sent DESC'; - return $this->execQuery($sql, array($altOe, ucfirst($altOe), $person_id)); + return $this->execQuery($sql, array($person_id)); } } From 749e9be64d0d996642c6e8fce6756ed412f247c5 Mon Sep 17 00:00:00 2001 From: Paolo Date: Tue, 4 Feb 2020 17:02:25 +0100 Subject: [PATCH 41/72] Messaging system: student writes new message: separate logic for master and bachelor --- application/models/crm/Prestudent_model.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index 94d77f8d3..b40897d82 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -524,26 +524,30 @@ class Prestudent_model extends DB_Model /** * Get organisation units for all the prestudents of a person - * TODO */ public function getOrganisationunitsByPersonId($person_id) { $query = 'SELECT o.oe_kurzbz, o.bezeichnung, - ps.prestudent_id + (CASE + WHEN sg.typ = \'b\' THEN ps.prestudent_id + WHEN sg.typ = \'m\' THEN p.prestudent_id + ELSE NULL + END) AS prestudent_id FROM public.tbl_prestudent p JOIN public.tbl_studiengang sg USING(studiengang_kz) JOIN public.tbl_organisationseinheit o USING(oe_kurzbz) LEFT JOIN ( SELECT prestudent_id FROM public.tbl_prestudentstatus - WHERE bestaetigtam IS NOT NULL - AND status_kurzbz = \'Interessent\' + WHERE status_kurzbz = \'Bewerber\' ) ps USING(prestudent_id) WHERE p.person_id = ? GROUP BY o.oe_kurzbz, o.bezeichnung, - ps.prestudent_id + sg.typ, + ps.prestudent_id, + p.prestudent_id ORDER BY o.bezeichnung'; return $this->execQuery($query, array($person_id)); From a5ad57ceeefa9b5825646848783229643d3ca400 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 4 Feb 2020 17:53:32 +0100 Subject: [PATCH 42/72] =?UTF-8?q?testtool/admin/edit=5Fgebiet.php:=20Offse?= =?UTF-8?q?tpunkte=20k=C3=B6nnen=20nun=20=C3=BCber=20admin=20GUI=20eingetr?= =?UTF-8?q?agen=20werden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cis/testtool/admin/edit_gebiet.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cis/testtool/admin/edit_gebiet.php b/cis/testtool/admin/edit_gebiet.php index afe81dae7..474546d4a 100644 --- a/cis/testtool/admin/edit_gebiet.php +++ b/cis/testtool/admin/edit_gebiet.php @@ -186,6 +186,7 @@ if (isset($_POST['speichern'])) $gebiet->zufallvorschlag = isset($_POST['zufallvorschlag']); $gebiet->levelgleichverteilung = isset($_POST['levelgleichverteilung']); $gebiet->maxpunkte = $_POST['maxpunkte']; + $gebiet->offsetpunkte = $_POST['offsetpunkte']; $gebiet->maxfragen = $_POST['maxfragen']; $gebiet->level_start = $_POST['level_start']; $gebiet->level_sprung_auf = $_POST['level_sprung_auf']; @@ -257,6 +258,8 @@ if ($gebiet_id != '') $hinweis = ''; echo 'Maximale Punkteanzahl'.$hinweis.''; echo ''; + echo 'Offsetpunkte (minimale Punkteanzahl)'; + echo ''; echo 'Maximale Fragenanzahl'; echo ''; echo 'Antworten pro Zeile'; From e724f7159fe4f2a017ea7fd0c8b8af66ec9de297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Fri, 7 Feb 2020 11:31:08 +0100 Subject: [PATCH 43/72] Datentyp der Offsetpunkte auf Numeric korrigiert --- system/dbupdate_3.3.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/dbupdate_3.3.php b/system/dbupdate_3.3.php index af529bab4..703e40857 100644 --- a/system/dbupdate_3.3.php +++ b/system/dbupdate_3.3.php @@ -3452,7 +3452,7 @@ if(!$result = @$db->db_query("SELECT 1 FROM fue.tbl_projekttyp LIMIT 1")) // Add column offset to testtool.tbl_gebiet if(!$result = @$db->db_query("SELECT offsetpunkte FROM testtool.tbl_gebiet LIMIT 1")) { - $qry = "ALTER TABLE testtool.tbl_gebiet ADD COLUMN offsetpunkte smallint"; + $qry = "ALTER TABLE testtool.tbl_gebiet ADD COLUMN offsetpunkte numeric(8,4)"; if(!$db->db_query($qry)) echo 'testtool.tbl_gebiet: '.$db->db_last_error().'
'; From d5e8d33adcc3b0447cd65f90a819cfdd84a62e1d Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 11 Feb 2020 10:28:43 +0100 Subject: [PATCH 44/72] public.vw_msg_vars: added orgform_kurzbz for tbl_bankverbindung --- system/dbupdate_3.3.php | 107 +++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 44 deletions(-) diff --git a/system/dbupdate_3.3.php b/system/dbupdate_3.3.php index 7721fefa4..a7d4011cc 100644 --- a/system/dbupdate_3.3.php +++ b/system/dbupdate_3.3.php @@ -3449,6 +3449,18 @@ if(!$result = @$db->db_query("SELECT 1 FROM fue.tbl_projekttyp LIMIT 1")) echo '
fue.tbl_projekttyp hinzugefuegt.'; } +// Add column orgform_kurzbz to tbl_bankverbindung +if(!$result = @$db->db_query("SELECT orgform_kurzbz FROM public.tbl_bankverbindung LIMIT 1")) +{ + $qry = "ALTER TABLE public.tbl_bankverbindung ADD COLUMN orgform_kurzbz varchar(3); + ALTER TABLE public.tbl_bankverbindung ADD CONSTRAINT fk_bankverbindung_orgform FOREIGN KEY (orgform_kurzbz) REFERENCES bis.tbl_orgform (orgform_kurzbz) ON DELETE RESTRICT ON UPDATE CASCADE;"; + + if(!$db->db_query($qry)) + echo 'public.tbl_bankverbindung: '.$db->db_last_error().'
'; + else + echo '
public.tbl_bankverbindung: Spalte orgform_kurzbz hinzugefuegt'; +} + // iban und bic zu vw_msg_vars hinzufügen if(!$result = @$db->db_query('SELECT "IBAN Studiengang", "BIC Studiengang" FROM public.vw_msg_vars LIMIT 1')) { @@ -3469,53 +3481,60 @@ if(!$result = @$db->db_query('SELECT "IBAN Studiengang", "BIC Studiengang" FROM s.bezeichnung AS "Studiengang DE", s.english AS "Studiengang EN", st.bezeichnung AS "Typ", - orgform_kurzbz AS "Orgform", + last_prestudent_status.orgform_kurzbz AS "Orgform", p.zugangscode AS "Zugangscode", bk.iban AS "IBAN Studiengang", bk.bic AS "BIC Studiengang" FROM public.tbl_person p - LEFT JOIN ( - SELECT person_id, - kontakt - FROM public.tbl_kontakt - WHERE zustellung = TRUE - AND kontakttyp = \'email\' - ORDER BY kontakt_id DESC - ) ke USING(person_id) - LEFT JOIN ( - SELECT person_id, - kontakt - FROM public.tbl_kontakt - WHERE zustellung = TRUE - AND kontakttyp IN (\'telefon\', \'mobil\') - ORDER BY kontakt_id DESC - ) kt USING(person_id) - LEFT JOIN ( - SELECT person_id, - strasse, - ort, - plz, - gemeinde, - langtext - FROM public.tbl_adresse - LEFT JOIN bis.tbl_nation ON(bis.tbl_nation.nation_code = public.tbl_adresse.nation) - WHERE public.tbl_adresse.heimatadresse = TRUE - ORDER BY adresse_id DESC - ) a USING(person_id) - LEFT JOIN public.tbl_prestudent pr USING(person_id) - INNER JOIN public.tbl_studiengang s USING(studiengang_kz) - INNER JOIN public.tbl_studiengangstyp st USING(typ) - LEFT JOIN ( SELECT DISTINCT ON (prestudent_id) - tbl_prestudent.prestudent_id, - tbl_bankverbindung.iban, - tbl_bankverbindung.bic, - tbl_studiengang.oe_kurzbz - FROM public.tbl_bankverbindung - JOIN public.tbl_studiengang USING(oe_kurzbz) - JOIN public.tbl_prestudent USING (studiengang_kz) - ORDER BY prestudent_id, tbl_bankverbindung.insertamum DESC, iban) bk USING (prestudent_id) - WHERE p.aktiv = TRUE - ORDER BY p.person_id ASC, pr.prestudent_id ASC + LEFT JOIN ( + SELECT person_id, + kontakt + FROM public.tbl_kontakt + WHERE zustellung = TRUE + AND kontakttyp = \'email\' + ORDER BY kontakt_id DESC + ) ke USING(person_id) + LEFT JOIN ( + SELECT person_id, + kontakt + FROM public.tbl_kontakt + WHERE zustellung = TRUE + AND kontakttyp IN (\'telefon\', \'mobil\') + ORDER BY kontakt_id DESC + ) kt USING(person_id) + LEFT JOIN ( + SELECT person_id, + strasse, + ort, + plz, + gemeinde, + langtext + FROM public.tbl_adresse + LEFT JOIN bis.tbl_nation ON(bis.tbl_nation.nation_code = public.tbl_adresse.nation) + WHERE public.tbl_adresse.heimatadresse = TRUE + ORDER BY adresse_id DESC + ) a USING(person_id) + LEFT JOIN public.tbl_prestudent pr USING(person_id) + INNER JOIN public.tbl_studiengang s USING(studiengang_kz) + INNER JOIN public.tbl_studiengangstyp st USING(typ) + LEFT JOIN ( + SELECT DISTINCT ON (ps.prestudent_id) tbl_studienplan.orgform_kurzbz, ps.prestudent_id + FROM public.tbl_prestudent ps + JOIN public.tbl_prestudentstatus ON ps.prestudent_id = tbl_prestudentstatus.prestudent_id + JOIN lehre.tbl_studienplan USING(studienplan_id) + ORDER BY ps.prestudent_id DESC, + tbl_prestudentstatus.datum DESC, + tbl_prestudentstatus.insertamum DESC, + tbl_prestudentstatus.ext_id DESC + ) last_prestudent_status ON pr.prestudent_id = last_prestudent_status.prestudent_id + LEFT JOIN ( + SELECT DISTINCT ON (oe_kurzbz, orgform_kurzbz) oe_kurzbz, orgform_kurzbz, iban, bic + FROM tbl_bankverbindung + WHERE oe_kurzbz IS NOT NULL + ORDER BY oe_kurzbz, orgform_kurzbz, tbl_bankverbindung.insertamum DESC,tbl_bankverbindung.iban + )bk ON s.oe_kurzbz = bk.oe_kurzbz AND (last_prestudent_status.orgform_kurzbz = bk.orgform_kurzbz OR bk.orgform_kurzbz IS NULL) + WHERE p.aktiv = TRUE + ORDER BY p.person_id ASC, pr.prestudent_id ASC );'; if(!$db->db_query($qry)) @@ -3682,7 +3701,7 @@ $tabellen=array( "public.tbl_aufnahmeschluessel" => array("aufnahmeschluessel"), "public.tbl_aufnahmetermin" => array("aufnahmetermin_id","aufnahmetermintyp_kurzbz","prestudent_id","termin","teilgenommen","bewertung","protokoll","insertamum","insertvon","updateamum","updatevon","ext_id"), "public.tbl_aufnahmetermintyp" => array("aufnahmetermintyp_kurzbz","bezeichnung"), - "public.tbl_bankverbindung" => array("bankverbindung_id","person_id","name","anschrift","bic","blz","iban","kontonr","typ","verrechnung","updateamum","updatevon","insertamum","insertvon","ext_id","oe_kurzbz"), + "public.tbl_bankverbindung" => array("bankverbindung_id","person_id","name","anschrift","bic","blz","iban","kontonr","typ","verrechnung","updateamum","updatevon","insertamum","insertvon","ext_id","oe_kurzbz", "orgform_kurzbz"), "public.tbl_benutzer" => array("uid","person_id","aktiv","alias","insertamum","insertvon","updateamum","updatevon","ext_id","updateaktivvon","updateaktivam","aktivierungscode"), "public.tbl_benutzerfunktion" => array("benutzerfunktion_id","fachbereich_kurzbz","uid","oe_kurzbz","funktion_kurzbz","semester", "datum_von","datum_bis", "updateamum","updatevon","insertamum","insertvon","ext_id","bezeichnung","wochenstunden"), "public.tbl_benutzergruppe" => array("uid","gruppe_kurzbz","studiensemester_kurzbz","updateamum","updatevon","insertamum","insertvon","ext_id"), From a63f6bd256ac422d26a46bcb0dac6969d8544eae Mon Sep 17 00:00:00 2001 From: raab Date: Tue, 11 Feb 2020 15:25:17 +0100 Subject: [PATCH 45/72] Filter InfoCenterNotSentApplicationAll Spalten getauscht --- system/filtersupdate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/filtersupdate.php b/system/filtersupdate.php index 42ac64571..d05a39aab 100644 --- a/system/filtersupdate.php +++ b/system/filtersupdate.php @@ -106,8 +106,8 @@ $filters = array( {"name": "Nachname"}, {"name": "Nation"}, {"name": "LastAction"}, - {"name": "User/Operator"}, {"name": "LastActionType"}, + {"name": "User/Operator"}, {"name": "LockUser"}, {"name": "StgNichtAbgeschickt"}, {"name": "StgAbgeschickt"}, From c7b33fe160b67202d359f1b400238da918c8c291 Mon Sep 17 00:00:00 2001 From: Paolo Date: Tue, 11 Feb 2020 16:04:08 +0100 Subject: [PATCH 46/72] Bugfix: FAS write page person id and prestudent id are swapped --- application/models/CL/Messages_model.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index 87eff0f99..3c8217e73 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -687,9 +687,18 @@ class Messages_model extends CI_Model foreach (getData($info) as $receiver) { $recipient = new stdClass(); - $recipient->id = $receiver->person_id; $recipient->description = $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; + } + else // otherwise it is a person + { + $recipient->id = $receiver->person_id; + } + $recipientsArray[] = $recipient; $recipientsList .= $receiver->Vorname.' '.$receiver->Nachname.'; '; $persons .= ''."\n"; @@ -723,7 +732,7 @@ class Messages_model extends CI_Model // If data contains a prestudent id // NOTE: // - info is checked at the beginning of this method so it is safe to use getData($info)[0] - // - the provided data inside info are all persons or prestudents, so it is safe to check only the first one + // - the provided data inside info are all persons or all prestudents, so it is safe to check only the first one if (isset(getData($info)[0]->prestudent_id) && is_numeric(getData($info)[0]->prestudent_id)) { $variablesResult = $this->messagelib->getMessageVarsPrestudent(); From 1b9693e316656d06a3a6032fedcfd8768dca646d Mon Sep 17 00:00:00 2001 From: Paolo Date: Tue, 11 Feb 2020 16:10:39 +0100 Subject: [PATCH 47/72] Bugfix: Infocenter write page person id and prestudent id are swapped --- public/js/messaging/messageWrite.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/public/js/messaging/messageWrite.js b/public/js/messaging/messageWrite.js index 04a262cbc..cc9d40730 100644 --- a/public/js/messaging/messageWrite.js +++ b/public/js/messaging/messageWrite.js @@ -21,14 +21,18 @@ function parseMessageText(receiver_id, text) { var data = {text: text}; - if ($("#type").val() == 'person_id') + if ($("#type").val() == 'persons') { data.person_id = receiver_id; } - else + else if ($("#type").val() == 'prestudents') { data.prestudent_id = receiver_id; } + else + { + return; + } FHC_AjaxClient.ajaxCallGet( "system/messages/Messages/parseMessageText", From 16cb4a0d4ca4175b7d80a8011f706a78fa9f59b6 Mon Sep 17 00:00:00 2001 From: Paolo Date: Tue, 11 Feb 2020 16:49:25 +0100 Subject: [PATCH 48/72] - Replace "This is a notice to notice you that you have been noticed..." with: EN: "This message will be delivered to the Infocenter of UAS Technikum Wien" DE: "Diese Nachricht wird an das Infocenter der FHTW zugestellt " - Bugfix: fixed phrases in system/messages/MessageClient/write --- application/views/system/messages/ajaxWrite.php | 10 +++++----- system/phrasesupdate.php | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/application/views/system/messages/ajaxWrite.php b/application/views/system/messages/ajaxWrite.php index df6c1bfcb..5a0a3f7b9 100644 --- a/application/views/system/messages/ajaxWrite.php +++ b/application/views/system/messages/ajaxWrite.php @@ -23,13 +23,13 @@
- +
- +

@@ -68,7 +68,7 @@
diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index d53d87dbb..3766f976d 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -4383,13 +4383,13 @@ When on hold, the date is only a reminder.', 'phrases' => array( array( 'sprache' => 'German', - 'text' => '* This is a notice to notice you that you have been noticed DE', + 'text' => '* Diese Nachricht wird an das Infocenter der FHTW zugestellt', 'description' => '', 'insertvon' => 'system' ), array( 'sprache' => 'English', - 'text' => '* This is a notice to notice you that you have been noticed', + 'text' => '* This message will be delivered to the Infocenter of UAS Technikum Wien', 'description' => '', 'insertvon' => 'system' ) From 98918bc3362c269a596bfaa8e20577370f523628 Mon Sep 17 00:00:00 2001 From: Paolo Date: Tue, 11 Feb 2020 18:05:26 +0100 Subject: [PATCH 49/72] - Bugfix: fixed phrases in views/system/messages/* - Added new phrases where missing or hard coded - Fixed windowz new lines in /application/* --- .../controllers/api/v1/person/Person.php | 534 +++++++++--------- application/views/crm/statusEdit.php | 178 +++--- application/views/crm/statusgrund.php | 64 +-- application/views/crm/statusgrundEdit.php | 214 +++---- application/views/crm/statusgrundNew.php | 132 ++--- application/views/system/fas_udf.php | 300 +++++----- application/views/system/infocenter/logs.php | 36 +- .../views/system/infocenter/messageList.php | 74 +-- .../views/system/infocenter/notizen.php | 38 +- .../views/system/messages/ajaxRead.php | 6 +- .../views/system/messages/ajaxWrite.php | 180 +++--- .../views/system/messages/ajaxWriteReply.php | 182 +++--- .../views/system/messages/htmlRead.php | 192 ++++--- .../views/system/messages/htmlWriteReply.php | 30 +- .../system/messages/htmlWriteTemplate.php | 20 +- application/views/system/phrases/phrases.php | 40 +- .../views/system/phrases/phrasesEdit.php | 34 +- .../system/phrases/phrasesinhaltList.php | 108 ++-- .../views/system/vorlage/templates.php | 40 +- .../system/vorlage/templatetextPreview.php | 4 +- application/views/templates/vilesci.php | 82 +-- application/widgets/Dropdown_widget.php | 38 +- .../widgets/MultipleDropdown_widget.php | 40 +- application/widgets/Nation_widget.php | 42 +- application/widgets/Zgv_widget.php | 42 +- 25 files changed, 1368 insertions(+), 1282 deletions(-) diff --git a/application/controllers/api/v1/person/Person.php b/application/controllers/api/v1/person/Person.php index c8c95ae06..ca8a66bea 100644 --- a/application/controllers/api/v1/person/Person.php +++ b/application/controllers/api/v1/person/Person.php @@ -1,267 +1,267 @@ - 'basis/person:rw', 'CheckBewerbung' => 'basis/person:r')); - // Load model PersonModel - $this->load->model('person/person_model', 'PersonModel'); - } - - /** - * @return void - */ - public function getPerson() - { - $person_id = $this->get('person_id'); - $code = $this->get('code'); - $email = $this->get('email'); - - if (isset($code) || isset($email) || isset($person_id)) - { - if (isset($code) && isset($email)) - { - $result = $this->PersonModel->getPersonKontaktByZugangscode($code, $email); - } - else - { - $parametersArray = array(); - - if (isset($code)) - { - $parametersArray['zugangscode'] = $code; - } - else - { - $parametersArray['person_id'] = $person_id; - } - - $result = $this->PersonModel->loadWhere($parametersArray); - } - - $this->response($result, REST_Controller::HTTP_OK); - } - else - { - $this->response(); - } - } - - /** - * @return void - */ - public function getCheckBewerbung() - { - $email = $this->get('email'); - $studiensemester_kurzbz = $this->get('studiensemester_kurzbz'); - - if (isset($email)) - { - $result = $this->PersonModel->checkBewerbung($email, $studiensemester_kurzbz); - - $this->response($result, REST_Controller::HTTP_OK); - } - else - { - $this->response(); - } - } - - /** - * @return void - */ - public function postPerson() - { - $person = $this->post(); - $validation = $this->_validate($person); - - if (isSuccess($validation)) - { - if(isset($person['person_id']) && !(is_null($person['person_id'])) && ($person['person_id'] != '')) - { - $result = $this->PersonModel->updatePerson($person); - } - else - { - $result = $this->PersonModel->insert($person); - } - - $this->response($result, REST_Controller::HTTP_OK); - } - else - { - $this->response($validation, REST_Controller::HTTP_OK); - } - } - - private function _validate($person) - { - // If $person is consistent - if (!isset($person) || (isset($person) && !is_array($person))) - { - return error('Any parameters posted'); - } - - // Trim all the values - foreach($person as $key => $value) - { - if (gettype($value) == 'string') - { - $person[$key] = trim($value); - } - } - - if (isset($person['sprache']) && mb_strlen($person['sprache']) > 16) - { - return error('Sprache darf nicht laenger als 16 Zeichen sein'); - } - if (isset($person['anrede']) && mb_strlen($person['anrede']) > 16) - { - return error('Anrede darf nicht laenger als 16 Zeichen sein'); - } - if (isset($person['titelpost']) && mb_strlen($person['titelpost']) > 32) - { - return error('Titelpost darf nicht laenger als 32 Zeichen sein'); - } - if (isset($person['titelpre']) && mb_strlen($person['titelpre']) > 64) - { - return error('Titelpre darf nicht laenger als 64 Zeichen sein'); - } - if (isset($person['nachname']) && mb_strlen($person['nachname']) > 64) - { - return error('Nachname darf nicht laenger als 64 Zeichen sein'); - } - if (isset($person['nachname']) && ($person['nachname'] == '' || is_null($person['nachname']))) - { - return error('Nachname muss eingegeben werden'); - } - if (isset($person['vorname']) && mb_strlen($person['vorname']) > 32) - { - return error('Vorname darf nicht laenger als 32 Zeichen sein'); - } - if (isset($person['vornamen']) && mb_strlen($person['vornamen']) > 128) - { - return error('Vornamen darf nicht laenger als 128 Zeichen sein'); - } - if (isset($person['gebort']) && mb_strlen($person['gebort']) > 128) - { - return error('Geburtsort darf nicht laenger als 128 Zeichen sein'); - } - if (isset($person['homepage']) && mb_strlen($person['homepage']) > 256) - { - return error('Homepage darf nicht laenger als 256 Zeichen sein'); - } - if (isset($person['matr_nr']) && mb_strlen($person['matr_nr']) > 32) - { - return error('Matrikelnummer darf nicht laenger als 32 Zeichen sein'); - } - if (isset($person['ersatzkennzeichen']) && mb_strlen($person['ersatzkennzeichen']) > 10) - { - return error('Ersatzkennzeichen darf nicht laenger als 10 Zeichen sein'); - } - if (isset($person['familienstand']) && mb_strlen($person['familienstand']) > 1) - { - return error('Familienstand ist ungueltig'); - } - if (isset($person['anzahlkinder']) && $person['anzahlkinder'] != '' && !is_numeric($person['anzahlkinder'])) - { - return error('Anzahl der Kinder ist ungueltig'); - } - if (!isset($person['aktiv']) || (isset($person['aktiv']) && $person['aktiv'] !== true && $person['aktiv'] !== false)) - { - return error('Aktiv ist ungueltig'); - } - if (!isset($person['person_id']) && isset($person['insertvon']) && mb_strlen($person['insertvon']) > 32) - { - return error('Insertvon darf nicht laenger als 32 Zeichen sein'); - } - if (isset($person['updatevon']) && mb_strlen($person['updatevon']) > 32) - { - return error('Updatevon darf nicht laenger als 32 Zeichen sein'); - } - if (isset($person['geburtsnation']) && mb_strlen($person['geburtsnation']) > 3) - { - return error('Geburtsnation darf nicht laenger als 3 Zeichen sein'); - } - if (isset($person['staatsbuergerschaft']) && mb_strlen($person['staatsbuergerschaft']) > 3) - { - return error('Staatsbuergerschaft darf nicht laenger als 3 Zeichen sein'); - } - if (!isset($person['geschlecht']) || (isset($person['geschlecht']) && mb_strlen($person['geschlecht']) > 1)) - { - return error('Geschlecht darf nicht laenger als 1 Zeichen sein'); - } - if (isset($person['geschlecht']) && $person['geschlecht'] != 'm' && $person['geschlecht'] != 'w' && $person['geschlecht'] != 'u') - { - return error('Geschlecht muss w, m oder u sein!'); - } - - if (isset($person['svnr'])) - { - if ($person['svnr'] != '' && mb_strlen($person['svnr']) != 16 - && mb_strlen($person['svnr']) != 12 && mb_strlen($person['svnr']) != 10) - { - return error('SVNR muss 10, 12 oder 16 Zeichen lang sein'); - } - if (mb_strlen($person['svnr']) == 10 || mb_strlen($person['svnr']) == 12) - { - //SVNR mit Pruefziffer pruefen - //Die 4. Stelle in der SVNR ist die Pruefziffer - //(Summe von (gewichtung[i]*svnr[i])) modulo 11 ergibt diese Pruefziffer - //Falls nicht, ist die SVNR ungueltig - $gewichtung = array(3, 7, 9, 0, 5, 8, 4, 2, 1, 6); - $erg = 0; - $tmpSvnr = substr($person['svnr'], 0, 10); - //Quersumme bilden - for ($i = 0; $i < 10; $i++) - { - $erg += $gewichtung[$i] * $tmpSvnr{$i}; - } - - if ($tmpSvnr{3} != ($erg % 11)) //Vergleichen der Pruefziffer mit Quersumme Modulo 11 - { - return error('SVNR ist ungueltig'); - } - - if (mb_strlen($person['svnr']) == 12) - { - $last = substr($person['svnr'], 10, 12); - if ($last{0} != 'v' || !is_numeric($last{1})) - { - return error('SVNR ist ungueltig'); - } - } - } - - //Pruefen ob das Geburtsdatum mit der SVNR uebereinstimmt. - if (isset($person['gebdatum']) && $person['svnr'] != '' && $person['gebdatum'] != '') - { - if (!mb_ereg('([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})', $person['gebdatum']) - && !mb_ereg('([0-9]{4})-([0-9]{2})-([0-9]{2})', $person['gebdatum'])) - { - return error('Format des Geburtsdatums ist ungueltig'); - } - } - } - - return success('Input data are valid'); - } -} + 'basis/person:rw', 'CheckBewerbung' => 'basis/person:r')); + // Load model PersonModel + $this->load->model('person/person_model', 'PersonModel'); + } + + /** + * @return void + */ + public function getPerson() + { + $person_id = $this->get('person_id'); + $code = $this->get('code'); + $email = $this->get('email'); + + if (isset($code) || isset($email) || isset($person_id)) + { + if (isset($code) && isset($email)) + { + $result = $this->PersonModel->getPersonKontaktByZugangscode($code, $email); + } + else + { + $parametersArray = array(); + + if (isset($code)) + { + $parametersArray['zugangscode'] = $code; + } + else + { + $parametersArray['person_id'] = $person_id; + } + + $result = $this->PersonModel->loadWhere($parametersArray); + } + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + + /** + * @return void + */ + public function getCheckBewerbung() + { + $email = $this->get('email'); + $studiensemester_kurzbz = $this->get('studiensemester_kurzbz'); + + if (isset($email)) + { + $result = $this->PersonModel->checkBewerbung($email, $studiensemester_kurzbz); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + + /** + * @return void + */ + public function postPerson() + { + $person = $this->post(); + $validation = $this->_validate($person); + + if (isSuccess($validation)) + { + if(isset($person['person_id']) && !(is_null($person['person_id'])) && ($person['person_id'] != '')) + { + $result = $this->PersonModel->updatePerson($person); + } + else + { + $result = $this->PersonModel->insert($person); + } + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response($validation, REST_Controller::HTTP_OK); + } + } + + private function _validate($person) + { + // If $person is consistent + if (!isset($person) || (isset($person) && !is_array($person))) + { + return error('Any parameters posted'); + } + + // Trim all the values + foreach($person as $key => $value) + { + if (gettype($value) == 'string') + { + $person[$key] = trim($value); + } + } + + if (isset($person['sprache']) && mb_strlen($person['sprache']) > 16) + { + return error('Sprache darf nicht laenger als 16 Zeichen sein'); + } + if (isset($person['anrede']) && mb_strlen($person['anrede']) > 16) + { + return error('Anrede darf nicht laenger als 16 Zeichen sein'); + } + if (isset($person['titelpost']) && mb_strlen($person['titelpost']) > 32) + { + return error('Titelpost darf nicht laenger als 32 Zeichen sein'); + } + if (isset($person['titelpre']) && mb_strlen($person['titelpre']) > 64) + { + return error('Titelpre darf nicht laenger als 64 Zeichen sein'); + } + if (isset($person['nachname']) && mb_strlen($person['nachname']) > 64) + { + return error('Nachname darf nicht laenger als 64 Zeichen sein'); + } + if (isset($person['nachname']) && ($person['nachname'] == '' || is_null($person['nachname']))) + { + return error('Nachname muss eingegeben werden'); + } + if (isset($person['vorname']) && mb_strlen($person['vorname']) > 32) + { + return error('Vorname darf nicht laenger als 32 Zeichen sein'); + } + if (isset($person['vornamen']) && mb_strlen($person['vornamen']) > 128) + { + return error('Vornamen darf nicht laenger als 128 Zeichen sein'); + } + if (isset($person['gebort']) && mb_strlen($person['gebort']) > 128) + { + return error('Geburtsort darf nicht laenger als 128 Zeichen sein'); + } + if (isset($person['homepage']) && mb_strlen($person['homepage']) > 256) + { + return error('Homepage darf nicht laenger als 256 Zeichen sein'); + } + if (isset($person['matr_nr']) && mb_strlen($person['matr_nr']) > 32) + { + return error('Matrikelnummer darf nicht laenger als 32 Zeichen sein'); + } + if (isset($person['ersatzkennzeichen']) && mb_strlen($person['ersatzkennzeichen']) > 10) + { + return error('Ersatzkennzeichen darf nicht laenger als 10 Zeichen sein'); + } + if (isset($person['familienstand']) && mb_strlen($person['familienstand']) > 1) + { + return error('Familienstand ist ungueltig'); + } + if (isset($person['anzahlkinder']) && $person['anzahlkinder'] != '' && !is_numeric($person['anzahlkinder'])) + { + return error('Anzahl der Kinder ist ungueltig'); + } + if (!isset($person['aktiv']) || (isset($person['aktiv']) && $person['aktiv'] !== true && $person['aktiv'] !== false)) + { + return error('Aktiv ist ungueltig'); + } + if (!isset($person['person_id']) && isset($person['insertvon']) && mb_strlen($person['insertvon']) > 32) + { + return error('Insertvon darf nicht laenger als 32 Zeichen sein'); + } + if (isset($person['updatevon']) && mb_strlen($person['updatevon']) > 32) + { + return error('Updatevon darf nicht laenger als 32 Zeichen sein'); + } + if (isset($person['geburtsnation']) && mb_strlen($person['geburtsnation']) > 3) + { + return error('Geburtsnation darf nicht laenger als 3 Zeichen sein'); + } + if (isset($person['staatsbuergerschaft']) && mb_strlen($person['staatsbuergerschaft']) > 3) + { + return error('Staatsbuergerschaft darf nicht laenger als 3 Zeichen sein'); + } + if (!isset($person['geschlecht']) || (isset($person['geschlecht']) && mb_strlen($person['geschlecht']) > 1)) + { + return error('Geschlecht darf nicht laenger als 1 Zeichen sein'); + } + if (isset($person['geschlecht']) && $person['geschlecht'] != 'm' && $person['geschlecht'] != 'w' && $person['geschlecht'] != 'u') + { + return error('Geschlecht muss w, m oder u sein!'); + } + + if (isset($person['svnr'])) + { + if ($person['svnr'] != '' && mb_strlen($person['svnr']) != 16 + && mb_strlen($person['svnr']) != 12 && mb_strlen($person['svnr']) != 10) + { + return error('SVNR muss 10, 12 oder 16 Zeichen lang sein'); + } + if (mb_strlen($person['svnr']) == 10 || mb_strlen($person['svnr']) == 12) + { + //SVNR mit Pruefziffer pruefen + //Die 4. Stelle in der SVNR ist die Pruefziffer + //(Summe von (gewichtung[i]*svnr[i])) modulo 11 ergibt diese Pruefziffer + //Falls nicht, ist die SVNR ungueltig + $gewichtung = array(3, 7, 9, 0, 5, 8, 4, 2, 1, 6); + $erg = 0; + $tmpSvnr = substr($person['svnr'], 0, 10); + //Quersumme bilden + for ($i = 0; $i < 10; $i++) + { + $erg += $gewichtung[$i] * $tmpSvnr{$i}; + } + + if ($tmpSvnr{3} != ($erg % 11)) //Vergleichen der Pruefziffer mit Quersumme Modulo 11 + { + return error('SVNR ist ungueltig'); + } + + if (mb_strlen($person['svnr']) == 12) + { + $last = substr($person['svnr'], 10, 12); + if ($last{0} != 'v' || !is_numeric($last{1})) + { + return error('SVNR ist ungueltig'); + } + } + } + + //Pruefen ob das Geburtsdatum mit der SVNR uebereinstimmt. + if (isset($person['gebdatum']) && $person['svnr'] != '' && $person['gebdatum'] != '') + { + if (!mb_ereg('([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})', $person['gebdatum']) + && !mb_ereg('([0-9]{4})-([0-9]{2})-([0-9]{2})', $person['gebdatum'])) + { + return error('Format des Geburtsdatums ist ungueltig'); + } + } + } + + return success('Input data are valid'); + } +} diff --git a/application/views/crm/statusEdit.php b/application/views/crm/statusEdit.php index 5fee3ee92..5f0353acf 100644 --- a/application/views/crm/statusEdit.php +++ b/application/views/crm/statusEdit.php @@ -1,89 +1,89 @@ -load->view('templates/header', array('title' => 'StatusEdit')); - - $s = $status; -?> - -
-
-

Status: status_kurzbz; ?>

-
- - - - - - - - - - - - - - - - - - - - - - -
- beschreibung:

-
-
-   -
- Anmerkung:

-
-
-   -
- Bezeichnung mehrsprachig:

- - - - - sprache; ?>:
- bezeichnung_mehrsprachig[$i])) - { - $val = ''; - } - else - { - $val = $s->bezeichnung_mehrsprachig[$i]; - } - $i++; - ?> -
- - -
-   -
- -
- -
-
-
- - - - - - - +load->view('templates/header', array('title' => 'StatusEdit')); + + $s = $status; +?> + +
+
+

Status: status_kurzbz; ?>

+
+ + + + + + + + + + + + + + + + + + + + + + +
+ beschreibung:

+
+
+   +
+ Anmerkung:

+
+
+   +
+ Bezeichnung mehrsprachig:

+ + + + + sprache; ?>:
+ bezeichnung_mehrsprachig[$i])) + { + $val = ''; + } + else + { + $val = $s->bezeichnung_mehrsprachig[$i]; + } + $i++; + ?> +
+ + +
+   +
+ +
+ +
+
+
+ + + + + + + diff --git a/application/views/crm/statusgrund.php b/application/views/crm/statusgrund.php index e79fa5d05..d4a31aa53 100644 --- a/application/views/crm/statusgrund.php +++ b/application/views/crm/statusgrund.php @@ -1,32 +1,32 @@ - - - - - VileSci - Statusgrund - - - - - - - <body bgcolor="#FFFFFF"> - This application works only with a frames-enabled browser.<br /> - </body> - - - - - <body bgcolor="#FFFFFF"> - This application works only with a frames-enabled browser.<br /> - </body> - - - - <body bgcolor="#FFFFFF"> - This application works only with a frames-enabled browser.<br /> - </body> - - - - - + + + + + VileSci - Statusgrund + + + + + + + <body bgcolor="#FFFFFF"> + This application works only with a frames-enabled browser.<br /> + </body> + + + + + <body bgcolor="#FFFFFF"> + This application works only with a frames-enabled browser.<br /> + </body> + + + + <body bgcolor="#FFFFFF"> + This application works only with a frames-enabled browser.<br /> + </body> + + + + + diff --git a/application/views/crm/statusgrundEdit.php b/application/views/crm/statusgrundEdit.php index ddbd1ff0a..9fa91b6d5 100644 --- a/application/views/crm/statusgrundEdit.php +++ b/application/views/crm/statusgrundEdit.php @@ -1,107 +1,107 @@ -load->view('templates/header', array('title' => 'StatusgrundEdit')); - - $sg = $statusgrund; -?> - -
-
-

Statusgrund: status_kurzbz; ?>

-
"> - - - - - - - - - - - - - - - - - - - - - - - -
- Bezeichnung mehrsprachig:

- - - sprache; ?>:
- bezeichnung_mehrsprachig[$i])) - { - $val = ""; - } - else - { - $val = $sg->bezeichnung_mehrsprachig[$i]; - } - $i++; - ?> -
- - -
-   -
- Beschreibung:

- - - sprache; ?>:
- beschreibung[$i])) - { - $val = ""; - } - else - { - $val = $sg->beschreibung[$i]; - } - $i++; - ?> -
- -
-   -
- Aktiv: - - aktiv) && $sg->aktiv === true ? "checked" : ""; ?> /> -
-   -
- -
- " /> -
-
-
- - - - - - - +load->view('templates/header', array('title' => 'StatusgrundEdit')); + + $sg = $statusgrund; +?> + +
+
+

Statusgrund: status_kurzbz; ?>

+
"> + + + + + + + + + + + + + + + + + + + + + + + +
+ Bezeichnung mehrsprachig:

+ + + sprache; ?>:
+ bezeichnung_mehrsprachig[$i])) + { + $val = ""; + } + else + { + $val = $sg->bezeichnung_mehrsprachig[$i]; + } + $i++; + ?> +
+ + +
+   +
+ Beschreibung:

+ + + sprache; ?>:
+ beschreibung[$i])) + { + $val = ""; + } + else + { + $val = $sg->beschreibung[$i]; + } + $i++; + ?> +
+ +
+   +
+ Aktiv: + + aktiv) && $sg->aktiv === true ? "checked" : ""; ?> /> +
+   +
+ +
+ " /> +
+
+
+ + + + + + + diff --git a/application/views/crm/statusgrundNew.php b/application/views/crm/statusgrundNew.php index bd2ebe7d7..ffcd18429 100644 --- a/application/views/crm/statusgrundNew.php +++ b/application/views/crm/statusgrundNew.php @@ -1,66 +1,66 @@ -load->view('templates/header', array('title' => 'StatusgrundNew')); -?> - -
-
-

Neuer Statusgrund

-
"> - - - - - - - - - - - - - - - - - - - - - - - -
- Bezeichnung mehrsprachig:

- - - sprache; ?>:
-
- - -
-   -
- Beschreibung:

- - - sprache; ?>:
-
- -
-   -
- Aktiv: - - -
-   -
- -
- -
-
-
- - - +load->view('templates/header', array('title' => 'StatusgrundNew')); +?> + +
+
+

Neuer Statusgrund

+
"> + + + + + + + + + + + + + + + + + + + + + + + +
+ Bezeichnung mehrsprachig:

+ + + sprache; ?>:
+
+ + +
+   +
+ Beschreibung:

+ + + sprache; ?>:
+
+ +
+   +
+ Aktiv: + + +
+   +
+ +
+ +
+
+
+ + + diff --git a/application/views/system/fas_udf.php b/application/views/system/fas_udf.php index d4a01b9e9..3efc61abc 100644 --- a/application/views/system/fas_udf.php +++ b/application/views/system/fas_udf.php @@ -1,150 +1,150 @@ -load->view("templates/header", array("title" => "UDF", "widgetsCSS" => true)); ?> - - - - -
- Saved! -
- -
- -
- Error while saving! -
-
-
-retval; - if(is_array($errors)) - { - foreach ($errors as $error) - { - foreach ($error as $fieldError) - { - echo $fieldError->code . ': ' . $fieldError->retval . '
'; - } - } - } - else - echo $result->retval; -?> -
- -
-
-
- -
- -
-
-
- Zusatzfelder -
-
-
-
-   -
-
-
- -
- udflib->UDFWidget( - array( - UDFLib::SCHEMA_ARG_NAME => 'public', - UDFLib::TABLE_ARG_NAME => 'tbl_person', - UDFLib::UDFS_ARG_NAME => $personUdfs - ) - ); - ?> -
-
-   -
- - -
- udflib->UDFWidget( - array( - UDFLib::SCHEMA_ARG_NAME => 'public', - UDFLib::TABLE_ARG_NAME => 'tbl_prestudent', - UDFLib::UDFS_ARG_NAME => $prestudentUdfs - ) - ); - ?> -
- -
-
-
-   -
-
-
- -
-   -
-
-   -
- -
- -
-
-
- - - - - - - - -
- - - -load->view("templates/footer"); ?> +load->view("templates/header", array("title" => "UDF", "widgetsCSS" => true)); ?> + + + + +
+ Saved! +
+ +
+ +
+ Error while saving! +
+
+
+retval; + if(is_array($errors)) + { + foreach ($errors as $error) + { + foreach ($error as $fieldError) + { + echo $fieldError->code . ': ' . $fieldError->retval . '
'; + } + } + } + else + echo $result->retval; +?> +
+ +
+
+
+ +
+ +
+
+
+ Zusatzfelder +
+
+
+
+   +
+
+
+ +
+ udflib->UDFWidget( + array( + UDFLib::SCHEMA_ARG_NAME => 'public', + UDFLib::TABLE_ARG_NAME => 'tbl_person', + UDFLib::UDFS_ARG_NAME => $personUdfs + ) + ); + ?> +
+
+   +
+ + +
+ udflib->UDFWidget( + array( + UDFLib::SCHEMA_ARG_NAME => 'public', + UDFLib::TABLE_ARG_NAME => 'tbl_prestudent', + UDFLib::UDFS_ARG_NAME => $prestudentUdfs + ) + ); + ?> +
+ +
+
+
+   +
+
+
+ +
+   +
+
+   +
+ +
+ +
+
+
+ + + + + + + + +
+ + + +load->view("templates/footer"); ?> diff --git a/application/views/system/infocenter/logs.php b/application/views/system/infocenter/logs.php index de97d5055..8005bf4f7 100644 --- a/application/views/system/infocenter/logs.php +++ b/application/views/system/infocenter/logs.php @@ -1,19 +1,19 @@ - - - - - - - - - - - - - - - - - +
p->t('global', 'datum')) ?>p->t('global', 'aktivitaet')) ?>User
zeitpunkt), 'd.m.Y H:i:s') ?>logdata->name) ? $log->logdata->name : '' ?>insertvon ?>
+ + + + + + + + + + + + + + + +
p->t('global', 'datum')) ?>p->t('global', 'aktivitaet')) ?>User
zeitpunkt), 'd.m.Y H:i:s') ?>logdata->name) ? $log->logdata->name : '' ?>insertvon ?>
\ No newline at end of file diff --git a/application/views/system/infocenter/messageList.php b/application/views/system/infocenter/messageList.php index d666e32fe..18b859314 100644 --- a/application/views/system/infocenter/messageList.php +++ b/application/views/system/infocenter/messageList.php @@ -1,37 +1,37 @@ - 0; -$widthColumn = $msgExists === true ? 8 : 12; -?> -
- - - - - - - - - - - - - - - - - - - - - -
p->t('global','gesendetAm')) ?>p->t('global','sender')) ?>p->t('global','empfaenger')) ?>p->t('global','betreff')) ?>p->t('global','gelesenAm')) ?>
insertamum) ? date_format(date_create($message->insertamum), 'd.m.Y H:i:s') : '' ?>sevorname.' '.$message->senachname ?>revorname.' '.$message->renachname ?>subject ?>statusamum) ? date_format(date_create($message->statusamum), 'd.m.Y H:i:s') : '' ?>
-
- -
-
-
-
- -
-
- + 0; +$widthColumn = $msgExists === true ? 8 : 12; +?> +
+ + + + + + + + + + + + + + + + + + + + + +
p->t('global','gesendetAm')) ?>p->t('global','sender')) ?>p->t('global','empfaenger')) ?>p->t('global','betreff')) ?>p->t('global','gelesenAm')) ?>
insertamum) ? date_format(date_create($message->insertamum), 'd.m.Y H:i:s') : '' ?>sevorname.' '.$message->senachname ?>revorname.' '.$message->renachname ?>subject ?>statusamum) ? date_format(date_create($message->statusamum), 'd.m.Y H:i:s') : '' ?>
+
+ +
+
+
+
+ +
+
+ diff --git a/application/views/system/infocenter/notizen.php b/application/views/system/infocenter/notizen.php index 13f7bb6e1..b28f7939a 100644 --- a/application/views/system/infocenter/notizen.php +++ b/application/views/system/infocenter/notizen.php @@ -1,20 +1,20 @@ - - - - - - - - - - - - - - - - - - +
p->t('global', 'datum')) ?>p->t('global', 'notiz')) ?>User
insertamum), 'd.m.Y H:i:s') ?>titel) ?>verfasser_uid ?>
+ + + + + + + + + + + + + + + + +
p->t('global', 'datum')) ?>p->t('global', 'notiz')) ?>User
insertamum), 'd.m.Y H:i:s') ?>titel) ?>verfasser_uid ?>
\ No newline at end of file diff --git a/application/views/system/messages/ajaxRead.php b/application/views/system/messages/ajaxRead.php index 2ff1f6cbb..1ed1b7f40 100644 --- a/application/views/system/messages/ajaxRead.php +++ b/application/views/system/messages/ajaxRead.php @@ -27,12 +27,16 @@ @@ -40,7 +44,7 @@ - + diff --git a/application/views/system/messages/ajaxWrite.php b/application/views/system/messages/ajaxWrite.php index 5a0a3f7b9..fe9b9e897 100644 --- a/application/views/system/messages/ajaxWrite.php +++ b/application/views/system/messages/ajaxWrite.php @@ -1,80 +1,100 @@ -load->view( - 'templates/FHC-Header', - array( - 'title' => 'Write a new message', - 'jquery' => true, - 'jqueryui' => true, - 'bootstrap' => true, - 'fontawesome' => true, - 'sbadmintemplate' => true, - 'ajaxlib' => true, - 'dialoglib' => true, - 'tinymce' => true, - 'phrases' => array('global', 'ui'), - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), - 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/write.js') - ) - ); -?> - -
-
-
-
-
- -
-
-
-
-
- -
-
- -
-
-
-
-
-
- -
-   -
- -
-
-
-
-
-
- - - -
- -
- p->t('ui', 'altRecipientNote'); ?> -
-
-
-
-
-
- -
-
-
-
-
- - -load->view("templates/FHC-Footer"); ?> +load->view( + 'templates/FHC-Header', + array( + 'title' => 'Write a new message', + 'jquery' => true, + 'jqueryui' => true, + 'bootstrap' => true, + 'fontawesome' => true, + 'sbadmintemplate' => true, + 'ajaxlib' => true, + 'dialoglib' => true, + 'tinymce' => true, + 'phrases' => array('global', 'ui'), + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), + 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/write.js') + ) + ); +?> + +
+
+
+
+
+ +
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+   +
+ +
+
+
+
+
+
+ + + +
+ +
+ + p->t('ui', 'altRecipientNote'); ?> + +
+
+
+
+
+
+ +
+
+
+
+
+ + +load->view("templates/FHC-Footer"); ?> diff --git a/application/views/system/messages/ajaxWriteReply.php b/application/views/system/messages/ajaxWriteReply.php index 36d999fc0..2fdaea907 100644 --- a/application/views/system/messages/ajaxWriteReply.php +++ b/application/views/system/messages/ajaxWriteReply.php @@ -1,81 +1,101 @@ -load->view( - 'templates/FHC-Header', - array( - 'title' => 'Reply to a message', - 'jquery' => true, - 'jqueryui' => true, - 'bootstrap' => true, - 'fontawesome' => true, - 'sbadmintemplate' => true, - 'ajaxlib' => true, - 'dialoglib' => true, - 'tinymce' => true, - 'phrases' => array('global', 'ui'), - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), - 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/writeReply.js') - ) - ); -?> - -
-
-
-
-
- -
-
-
-
-
- -
-
- - - -
-
-
-
-
-
- -
-   -
- - - -
-
-
-
-
-
- - -
-
-
-
-
- - - - - - -
-
-
-
-
- - -load->view("templates/FHC-Footer"); ?> +load->view( + 'templates/FHC-Header', + array( + 'title' => 'Reply to a message', + 'jquery' => true, + 'jqueryui' => true, + 'bootstrap' => true, + 'fontawesome' => true, + 'sbadmintemplate' => true, + 'ajaxlib' => true, + 'dialoglib' => true, + 'tinymce' => true, + 'phrases' => array('global', 'ui'), + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), + 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/writeReply.js') + ) + ); +?> + +
+
+
+
+
+ +
+
+
+
+
+ +
+
+ + + +
+
+
+
+
+
+ +
+   +
+ + + +
+
+
+
+
+
+ + +
+
+
+
+
+ + + + + + +
+
+
+
+
+ + +load->view("templates/FHC-Footer"); ?> diff --git a/application/views/system/messages/htmlRead.php b/application/views/system/messages/htmlRead.php index 390e84ccc..ed184f7c5 100644 --- a/application/views/system/messages/htmlRead.php +++ b/application/views/system/messages/htmlRead.php @@ -1,88 +1,104 @@ -load->view( - 'templates/FHC-Header', - array( - 'title' => 'Read a message', - 'jquery' => true, - 'bootstrap' => true, - 'fontawesome' => true, - 'sbadmintemplate' => true, - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css') - ) - ); -?> - -
-
-
-
-
- -
-
-
-
-
-
- - subject; ?> - -
-
- - - - - - - - - - - - - -
- From: - - - vorname.' '.$sender->nachname; ?> - -
- Subject: - - - subject; ?> - -
- Message: - - - body; ?> - -
-
- -
-
-
-
-
-
- - -load->view("templates/FHC-Footer"); ?> +load->view( + 'templates/FHC-Header', + array( + 'title' => 'Read a message', + 'jquery' => true, + 'bootstrap' => true, + 'fontawesome' => true, + 'sbadmintemplate' => true, + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css') + ) + ); +?> + +
+
+
+
+
+ +
+
+
+
+
+
+ + subject; ?> + +
+
+ + + + + + + + + + + + + +
+ + + p->t('ui', 'from')); ?>: + + + + + vorname.' '.$sender->nachname; ?> + +
+ + + p->t('global', 'betreff')); ?>: + + + + + subject; ?> + +
+ + + p->t('global', 'nachricht')); ?>: + + + + + body; ?> + +
+
+ +
+
+
+
+
+
+ + +load->view("templates/FHC-Footer"); ?> diff --git a/application/views/system/messages/htmlWriteReply.php b/application/views/system/messages/htmlWriteReply.php index 8e1ef7d7f..fa3390bfa 100644 --- a/application/views/system/messages/htmlWriteReply.php +++ b/application/views/system/messages/htmlWriteReply.php @@ -19,14 +19,22 @@
- +
- +
@@ -38,7 +46,11 @@
- +
 
@@ -49,14 +61,22 @@
- +

- +
diff --git a/application/views/system/messages/htmlWriteTemplate.php b/application/views/system/messages/htmlWriteTemplate.php index 5309e0cb5..d26ec534c 100644 --- a/application/views/system/messages/htmlWriteTemplate.php +++ b/application/views/system/messages/htmlWriteTemplate.php @@ -36,7 +36,7 @@
@@ -50,7 +50,7 @@
@@ -65,7 +65,7 @@
+<<<<<<< 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) { From 937db42e1187ca1e91e0d5c4999e4d3f6a4a7ff4 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 12 Feb 2020 16:14:50 +0100 Subject: [PATCH 55/72] - Allow to change the subject in all reply pages - Remove tabs and/or blanks from subject when replying --- application/views/system/messages/ajaxWriteReply.php | 4 ++-- application/views/system/messages/htmlRead.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/application/views/system/messages/ajaxWriteReply.php b/application/views/system/messages/ajaxWriteReply.php index 2fdaea907..a43131d1d 100644 --- a/application/views/system/messages/ajaxWriteReply.php +++ b/application/views/system/messages/ajaxWriteReply.php @@ -56,9 +56,9 @@
  -
+
- +
diff --git a/application/views/system/messages/htmlRead.php b/application/views/system/messages/htmlRead.php index 985eee326..5413af9f4 100644 --- a/application/views/system/messages/htmlRead.php +++ b/application/views/system/messages/htmlRead.php @@ -85,7 +85,7 @@ From c54579ef7de80e0ab64a5ce78f474b36567ef582 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 12 Feb 2020 16:39:00 +0100 Subject: [PATCH 56/72] /system/messages/MessageClient/read sent messages: read them all --- application/models/system/Recipient_model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index c2acd2d56..8e2e46513 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -464,7 +464,7 @@ class Recipient_model extends DB_Model JOIN public.tbl_msg_recipient mr ON (mr.message_id = mm.message_id) JOIN public.tbl_msg_status ms ON (ms.message_id = mm.message_id AND mr.person_id = mr.person_id) JOIN public.tbl_person p ON (p.person_id = mr.person_id) - JOIN public.tbl_organisationseinheit oe ON (oe.oe_kurzbz = mr.oe_kurzbz) + LEFT JOIN public.tbl_organisationseinheit oe ON (oe.oe_kurzbz = mr.oe_kurzbz) WHERE mm.person_id = ? AND mr.sent IS NOT NULL AND mr.sentinfo IS NULL From a4bfdfb4a0e590ffdbb9c48b3acc5b26245984b0 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 13 Feb 2020 12:49:57 +0100 Subject: [PATCH 57/72] Fixed merge with stashed files in system/messages/htmlWriteTemplate.php --- application/views/system/messages/htmlWriteTemplate.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/application/views/system/messages/htmlWriteTemplate.php b/application/views/system/messages/htmlWriteTemplate.php index 77bc168a7..64a8c8236 100644 --- a/application/views/system/messages/htmlWriteTemplate.php +++ b/application/views/system/messages/htmlWriteTemplate.php @@ -162,12 +162,7 @@
-<<<<<<< Updated upstream - - -======= ->>>>>>> Stashed changes From 21da8dfb51e94004dbecc04153658c3b1efd06aa Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 13 Feb 2020 18:49:01 +0100 Subject: [PATCH 58/72] - Added offsetpunkte Berechnung for Suggestions on admin/edit_gebiet page - offsetpunkte are validated before saving --- cis/testtool/admin/edit_gebiet.php | 8 +- include/gebiet.class.php | 135 ++++++++++++++++++++++++++++- 2 files changed, 141 insertions(+), 2 deletions(-) diff --git a/cis/testtool/admin/edit_gebiet.php b/cis/testtool/admin/edit_gebiet.php index 474546d4a..80a205574 100644 --- a/cis/testtool/admin/edit_gebiet.php +++ b/cis/testtool/admin/edit_gebiet.php @@ -258,7 +258,13 @@ if ($gebiet_id != '') $hinweis = ''; echo 'Maximale Punkteanzahl'.$hinweis.''; echo ''; - echo 'Offsetpunkte (minimale Punkteanzahl)'; + // empfohlene offsetpunkte berechnen und anzeigen + $offsetpunkte = $gebiet->berechneOffsetpunkte($gebiet_id); + if ($gebiet->offsetpunkte != $offsetpunkte) + $hinweis = ' empfohlene Offsetpunkteanzahl: '.round($offsetpunkte).(round($offsetpunkte) != $offsetpunkte?' ('.$offsetpunkte.' gerundet)':'').''; + else + $hinweis = ''; + echo 'Offsetpunkte (minimale Punkteanzahl)'.$hinweis.''; echo ''; echo 'Maximale Fragenanzahl'; echo ''; diff --git a/include/gebiet.class.php b/include/gebiet.class.php index a83c3319c..0268944cc 100644 --- a/include/gebiet.class.php +++ b/include/gebiet.class.php @@ -171,6 +171,11 @@ class gebiet extends basis_db $this->errormsg = 'Maxpunkte muss eine gueltige Zahl sein'; return false; } + if(!is_numeric($this->offsetpunkte) && $this->offsetpunkte!='') + { + $this->errormsg = 'Offsetpunkte muss eine gueltige Zahl sein'; + return false; + } if(!is_numeric($this->antwortenprozeile) || $this->antwortenprozeile<=0) { $this->errormsg = 'AntortenProZeile muss eine gueltige Zahl und groesser als 0 sein'; @@ -571,7 +576,8 @@ class gebiet extends basis_db ( SELECT level, frage_id, sum(punkte) as punkte FROM testtool.tbl_frage JOIN testtool.tbl_vorschlag USING(frage_id) - WHERE gebiet_id=".$this->db_add_param($gebiet_id, FHC_INTEGER)." AND punkte>0 AND level>=".$this->db_add_param($this->level_start)." AND NOT demo + WHERE gebiet_id=".$this->db_add_param($gebiet_id, FHC_INTEGER)." AND punkte>0 + AND level>=".$this->db_add_param($this->level_start)." AND NOT demo GROUP BY level, frage_id ) as a GROUP by level, punkte ORDER BY level"; @@ -616,6 +622,133 @@ class gebiet extends basis_db } } + /** + * Berechnet die offsetpunkte fuer das Gebiet + * + * @param $gebiet_id + */ + public function berechneOffsetpunkte($gebiet_id) + { + if(!$this->load($gebiet_id)) + return false; + + $qry = " + WITH fragen AS ( + SELECT tbl_frage.frage_id, tbl_frage.gebiet_id, tbl_frage.level, punkte + FROM testtool.tbl_frage + JOIN testtool.tbl_vorschlag USING (frage_id) + WHERE tbl_vorschlag.aktiv + AND tbl_vorschlag.punkte < 0 + AND tbl_frage.demo = false + AND tbl_frage.aktiv + ), + fragenanzahl AS ( + SELECT gebiet_id, level, levelgleichverteilung, + CASE WHEN levelgleichverteilung + THEN + ROUND(COALESCE(maxfragen + * ((SELECT count(*) FROM testtool.tbl_frage f WHERE f.level = tbl_frage.level AND f.gebiet_id = tbl_frage.gebiet_id)::decimal) + / (SELECT count(*) FROM testtool.tbl_frage f WHERE f.gebiet_id = tbl_frage.gebiet_id)::decimal + , (SELECT count(*) FROM testtool.tbl_frage f WHERE f.level = tbl_frage.level AND f.gebiet_id = tbl_frage.gebiet_id) + )) + ELSE + COALESCE(maxfragen, count(*)) + END + AS anzahl + FROM testtool.tbl_frage + JOIN testtool.tbl_gebiet USING (gebiet_id) + WHERE tbl_frage.aktiv + AND tbl_frage.demo = false + GROUP BY gebiet_id, level, levelgleichverteilung, maxfragen + ) + SELECT + tbl_gebiet.gebiet_id, tbl_gebiet.bezeichnung, + tbl_gebiet.multipleresponse, + tbl_gebiet.maxpunkte, tbl_gebiet.maxfragen, + tbl_gebiet.levelgleichverteilung, + tbl_gebiet.level_start, + ( + CASE WHEN tbl_gebiet.levelgleichverteilung THEN + (CASE WHEN tbl_gebiet.multipleresponse=false THEN + (SELECT sum(frprolevel) FROM + ( + SELECT fragen.level, (min(punkte) + * (SELECT anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = fragen.gebiet_id and fragenanzahl.level = fragen.level LIMIT 1)) AS frprolevel + FROM fragen + WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id + GROUP BY fragen.gebiet_id, level + ) pkteprolevel) + ELSE + (SELECT sum(frprolevel) FROM + ( + SELECT fragen.level, (sum(punkte) + * (SELECT anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = fragen.gebiet_id and fragenanzahl.level = fragen.level LIMIT 1)) AS frprolevel + FROM fragen + WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id + AND frage_id = (SELECT min(frage_id) FROM fragen fr WHERE fr.gebiet_id = fragen.gebiet_id AND fr.level = fragen.level) + GROUP BY fragen.gebiet_id, level + ) pkteprolevel) + END) *(-1) + WHEN tbl_gebiet.level_start IS NOT NULL THEN + (CASE WHEN tbl_gebiet.multipleresponse=false THEN + ( + SELECT min(punkte) + FROM fragen + WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id + AND fragen.level = tbl_gebiet.level_start + ) * (SELECT fragenanzahl.anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = tbl_gebiet.gebiet_id AND fragenanzahl.level = tbl_gebiet.level_start LIMIT 1) + ELSE + (SELECT sum(punkte) + FROM fragen + WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id + AND frage_id = (SELECT min(frage_id) FROM fragen WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id) + AND fragen.level = tbl_gebiet.level_start + )* (SELECT fragenanzahl.anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = tbl_gebiet.gebiet_id AND fragenanzahl.level = tbl_gebiet.level_start LIMIT 1) + END) *(-1) + ELSE + (CASE WHEN tbl_gebiet.multipleresponse=false THEN + ( + SELECT min(punkte) + FROM fragen + WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id + ) * (SELECT fragenanzahl.anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = tbl_gebiet.gebiet_id LIMIT 1) + ELSE + (SELECT sum(punkte) + FROM fragen + WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id + AND frage_id = (SELECT min(frage_id) FROM fragen WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id) + )* (SELECT fragenanzahl.anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = tbl_gebiet.gebiet_id LIMIT 1) + END) *(-1) + + END) AS offsetpunkte + FROM + testtool.tbl_gebiet + WHERE + EXISTS( + SELECT 1 FROM fragen WHERE fragen.gebiet_id=tbl_gebiet.gebiet_id + ) + AND gebiet_id = ".$this->db_add_param($gebiet_id, FHC_INTEGER)." + "; + + if($this->db_query($qry)) + { + if($row = $this->db_fetch_object()) + { + return $row->offsetpunkte; + } + else + { + $this->errormsg = 'Fehler beim Ermitteln der Offsetpunkte'; + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Ermitteln der Offsetpunkte'; + return false; + } + } + /** * Prueft ob das Gebiet bereits gestartet wurde. Wahlweise pruefling_id oder prestudent_id * From b60e7ed43927332c4cf307696691a452a1c291e0 Mon Sep 17 00:00:00 2001 From: Manfred Kindl Date: Thu, 13 Feb 2020 19:08:37 +0100 Subject: [PATCH 59/72] =?UTF-8?q?Option=20zur=20Ausgabe=20der=20Fragen=20o?= =?UTF-8?q?hne=20L=C3=B6sungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cis/testtool/admin/uebersichtFragen.php | 35 +++++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/cis/testtool/admin/uebersichtFragen.php b/cis/testtool/admin/uebersichtFragen.php index 71d154a1b..50963a337 100644 --- a/cis/testtool/admin/uebersichtFragen.php +++ b/cis/testtool/admin/uebersichtFragen.php @@ -35,7 +35,7 @@ if (!$db = new basis_db()) Testool Fragen Übersicht - + isBerechtigt('basis/testtool', null, 's')) $gebiet = new gebiet(); $gebiet->getAll(); $sprache = (isset($_REQUEST['Sprache'])?$_REQUEST['Sprache']:'German'); -$Auswahlgebiet = (isset($_REQUEST['AuswahlGebiet'])?$_REQUEST['AuswahlGebiet']:''); +$Auswahlgebiet = (isset($_REQUEST['AuswahlGebiet'])?$_REQUEST['AuswahlGebiet']:''); +$loesungen = (isset($_REQUEST['loesungen']) && $_REQUEST['loesungen'] != '' ? true:false); echo ' @@ -76,6 +77,13 @@ else echo' + + + + +
+Mit Lösungen +

'; @@ -208,8 +216,17 @@ if(isset($_REQUEST['AuswahlGebiet'])) $vorschlag = new vorschlag(); $vorschlag->loadVorschlagSprache($vor->vorschlag_id, $sprache); - if($vorschlag->bild =='') - echo ''.$vor->punkte.' '.$vorschlag->text.''; + if($vorschlag->bild == '') + { + if ($loesungen) + { + echo ''.$vor->nummer.''.$vor->punkte.' '.$vorschlag->text.''; + } + else + { + echo ''.$vor->nummer.' '.$vorschlag->text.''; + } + } if($vorschlag->bild!='') { // zeilenumbruch nach 4 bilder @@ -217,7 +234,15 @@ if(isset($_REQUEST['AuswahlGebiet'])) echo ""; echo ""; echo "
"; - echo "
".$vor->punkte.""; + if ($loesungen) + { + echo "
".$vor->punkte.""; + } + else + { + echo ""; + } + $anzahlBild++; } if($vorschlag->audio!='') From 1ac14fca24de1a9c55aec14c3d586e41d02a3d51 Mon Sep 17 00:00:00 2001 From: Nikolaus Krondraf Date: Fri, 14 Feb 2020 07:33:28 +0100 Subject: [PATCH 60/72] =?UTF-8?q?Pr=C3=BCfungstermine=20werden=20nicht=20m?= =?UTF-8?q?ehr=20doppelt=20angezeigt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cis/private/lehre/pruefung/pruefung.js.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cis/private/lehre/pruefung/pruefung.js.php b/cis/private/lehre/pruefung/pruefung.js.php index b207c94e5..aafcf9710 100644 --- a/cis/private/lehre/pruefung/pruefung.js.php +++ b/cis/private/lehre/pruefung/pruefung.js.php @@ -337,10 +337,10 @@ function writePruefungsTable(e, data, anmeldung) { var row = ""; var teilnehmer = ""; - var button = ""; row += ""+e.organisationseinheit+""+e.lehrveranstaltung[0].bezeichnung+"
("+e.lehrveranstaltung[0].lehrform_kurzbz+", "+e.lehrveranstaltung[0].ects+" ECTS, "+e.pruefung.mitarbeiter_uid+")"; e.pruefung.termine.forEach(function(d){ - var storno = false; + var button = ""; + var storno = false; var anmeldung_id = null; data.result.anmeldungen.forEach(function(anmeldung){ if((anmeldung.pruefungstermin_id === d.pruefungstermin_id) && (anmeldung.lehrveranstaltung_id === e.lehrveranstaltung[0].lehrveranstaltung_id)) From c81a25988e30affe25bb3950b716a030a1c97a15 Mon Sep 17 00:00:00 2001 From: Manfred Kindl Date: Fri, 14 Feb 2020 15:31:20 +0100 Subject: [PATCH 61/72] Historie-Feld nebeneinander --- content/student/studentdetailoverlay.xul.php | 326 ++++++++++--------- 1 file changed, 164 insertions(+), 162 deletions(-) diff --git a/content/student/studentdetailoverlay.xul.php b/content/student/studentdetailoverlay.xul.php index aabe442d4..0a014b20a 100644 --- a/content/student/studentdetailoverlay.xul.php +++ b/content/student/studentdetailoverlay.xul.php @@ -504,170 +504,172 @@ echo '';
diff --git a/public/js/messaging/writeReply.js b/public/js/messaging/writeReply.js index aeb13dc2c..c78748889 100644 --- a/public/js/messaging/writeReply.js +++ b/public/js/messaging/writeReply.js @@ -13,7 +13,7 @@ function sendReply() receiver_id: $('#receiver_id').val(), relationmessage_id: $('#relationmessage_id').val(), token: $('#token').val(), - subject: $('#subject').html(), + subject: $('#subject').val(), body: tinyMCE.get("body").getContent() }, { From a063a73c412f234d8f265e7015440770cceb745d Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 17 Feb 2020 19:26:55 +0100 Subject: [PATCH 64/72] reihungst admin edit_gebiet.php: checking that there are same negativpoints for one gebiet and one level before showing offsetpunkte suggestion for RT gebiete --- cis/testtool/admin/edit_gebiet.php | 14 ++++--- include/gebiet.class.php | 59 ++++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 13 deletions(-) diff --git a/cis/testtool/admin/edit_gebiet.php b/cis/testtool/admin/edit_gebiet.php index 80a205574..5610679b4 100644 --- a/cis/testtool/admin/edit_gebiet.php +++ b/cis/testtool/admin/edit_gebiet.php @@ -259,12 +259,16 @@ if ($gebiet_id != '') echo 'Maximale Punkteanzahl'.$hinweis.''; echo ''; // empfohlene offsetpunkte berechnen und anzeigen + $offsethinweis = ''; $offsetpunkte = $gebiet->berechneOffsetpunkte($gebiet_id); - if ($gebiet->offsetpunkte != $offsetpunkte) - $hinweis = ' empfohlene Offsetpunkteanzahl: '.round($offsetpunkte).(round($offsetpunkte) != $offsetpunkte?' ('.$offsetpunkte.' gerundet)':'').''; - else - $hinweis = ''; - echo 'Offsetpunkte (minimale Punkteanzahl)'.$hinweis.''; + if ($offsetpunkte) + { + $offsetwarnung = strlen($gebiet->errormsg) > 0 ? ' (HINWEIS: '.$gebiet->errormsg.')' : ''; + + if ($gebiet->offsetpunkte != $offsetpunkte) + $offsethinweis = ' empfohlene Offsetpunkteanzahl: '.round($offsetpunkte).(round($offsetpunkte) != $offsetpunkte ? ' ('.$offsetpunkte.' gerundet)' : '').$offsetwarnung.''; + } + echo 'Offsetpunkte (minimale Punkteanzahl)'.$offsethinweis.''; echo ''; echo 'Maximale Fragenanzahl'; echo ''; diff --git a/include/gebiet.class.php b/include/gebiet.class.php index 0268944cc..dbdd50b3d 100644 --- a/include/gebiet.class.php +++ b/include/gebiet.class.php @@ -632,6 +632,49 @@ class gebiet extends basis_db if(!$this->load($gebiet_id)) return false; + $checkqry = "SELECT COUNT (uniquepoints) AS count_uniquepoints + FROM ( + SELECT gebiet_id, + level, + count(DISTINCT punkte), + CASE WHEN count(DISTINCT punkte) > 1 THEN FALSE ELSE TRUE END AS uniquepoints + FROM ( + SELECT tbl_frage.gebiet_id, + tbl_frage.level, + CASE WHEN multipleresponse THEN sum(punkte) ELSE min(punkte) END AS punkte + FROM testtool.tbl_frage + JOIN testtool.tbl_vorschlag USING (frage_id) + JOIN testtool.tbl_gebiet USING (gebiet_id) + WHERE tbl_vorschlag.aktiv + AND tbl_vorschlag.punkte < 0 + AND tbl_frage.demo = false + AND tbl_frage.aktiv + AND gebiet_id = ".$this->db_add_param($gebiet_id, FHC_INTEGER)." + GROUP BY tbl_frage.gebiet_id, multipleresponse, tbl_frage.level, tbl_frage.frage_id + ) p + GROUP BY gebiet_id, level + ) pu + WHERE uniquepoints = FALSE"; + + if($this->db_query($checkqry)) + { + if($row = $this->db_fetch_object()) + { + if (!is_numeric($row->count_uniquepoints) || $row->count_uniquepoints > 0) + $this->errormsg = 'Negativpunkte sind nicht für alle Fragen gleich hoch!'; + } + else + { + $this->errormsg = 'Fehler beim Prüfen der Offsetpunkte'; + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Prüfen der Offsetpunkte'; + return false; + } + $qry = " WITH fragen AS ( SELECT tbl_frage.frage_id, tbl_frage.gebiet_id, tbl_frage.level, punkte @@ -688,7 +731,7 @@ class gebiet extends basis_db AND frage_id = (SELECT min(frage_id) FROM fragen fr WHERE fr.gebiet_id = fragen.gebiet_id AND fr.level = fragen.level) GROUP BY fragen.gebiet_id, level ) pkteprolevel) - END) *(-1) + END) WHEN tbl_gebiet.level_start IS NOT NULL THEN (CASE WHEN tbl_gebiet.multipleresponse=false THEN ( @@ -696,31 +739,31 @@ class gebiet extends basis_db FROM fragen WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id AND fragen.level = tbl_gebiet.level_start - ) * (SELECT fragenanzahl.anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = tbl_gebiet.gebiet_id AND fragenanzahl.level = tbl_gebiet.level_start LIMIT 1) + ) * (SELECT anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = tbl_gebiet.gebiet_id AND fragenanzahl.level = tbl_gebiet.level_start LIMIT 1) ELSE (SELECT sum(punkte) FROM fragen WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id AND frage_id = (SELECT min(frage_id) FROM fragen WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id) AND fragen.level = tbl_gebiet.level_start - )* (SELECT fragenanzahl.anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = tbl_gebiet.gebiet_id AND fragenanzahl.level = tbl_gebiet.level_start LIMIT 1) - END) *(-1) + )* (SELECT anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = tbl_gebiet.gebiet_id AND fragenanzahl.level = tbl_gebiet.level_start LIMIT 1) + END) ELSE (CASE WHEN tbl_gebiet.multipleresponse=false THEN ( SELECT min(punkte) FROM fragen WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id - ) * (SELECT fragenanzahl.anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = tbl_gebiet.gebiet_id LIMIT 1) + ) * (SELECT anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = tbl_gebiet.gebiet_id LIMIT 1) ELSE (SELECT sum(punkte) FROM fragen WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id AND frage_id = (SELECT min(frage_id) FROM fragen WHERE fragen.gebiet_id = tbl_gebiet.gebiet_id) - )* (SELECT fragenanzahl.anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = tbl_gebiet.gebiet_id LIMIT 1) - END) *(-1) + )* (SELECT anzahl FROM fragenanzahl WHERE fragenanzahl.gebiet_id = tbl_gebiet.gebiet_id LIMIT 1) + END) - END) AS offsetpunkte + END) * (-1) AS offsetpunkte FROM testtool.tbl_gebiet WHERE From 0db611ed270d2128cc80b37f0707a8cdf8dc2dd5 Mon Sep 17 00:00:00 2001 From: Paolo Date: Tue, 18 Feb 2020 15:19:58 +0100 Subject: [PATCH 65/72] - Added new config entry in mail config file called enable_debug - If enable_debug is true then info about the mail are logged into the CI error logs - Fixed queries to get sent and received messages with Recipient_model, now messages for which a notice email was not sent are retrieved and messages are sorted by insertamum - CL/Messages_model: - Before setting a message as read check if a record is already present - If the recipient is a prestudent then in table tbl_msg_message oe_kurzbz is set with the ou of the prestudent - The sender id (person_id) now is get from the currently logged user also when replying - MessageLib->_sendNoticeEmails checks that the message was sent only from FAS (NOT from infocenter) --- application/config/mail.php | 3 + application/libraries/MailLib.php | 50 ++++++++++----- application/libraries/MessageLib.php | 7 ++- application/models/CL/Messages_model.php | 61 +++++++++++++++---- application/models/system/Recipient_model.php | 22 +++---- 5 files changed, 100 insertions(+), 43 deletions(-) diff --git a/application/config/mail.php b/application/config/mail.php index 2163bc122..9d577720d 100644 --- a/application/config/mail.php +++ b/application/config/mail.php @@ -29,3 +29,6 @@ $config['wrapchars'] = 76; // Character count to wrap at. $config['mailtype'] = 'html'; // html or text $config['priority'] = 3; // Email Priority. 1 = highest. 5 = lowest. 3 = normal $config['validate'] = false; // If true then the email address will be validated + +// If enabled will be logged info about emails in Codeigniter error logs +$config['enable_debug'] = false; diff --git a/application/libraries/MailLib.php b/application/libraries/MailLib.php index e9e571f6c..dbbc22f08 100644 --- a/application/libraries/MailLib.php +++ b/application/libraries/MailLib.php @@ -7,6 +7,8 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); */ class MailLib { + const ENABLE_DEBUG = 'enable_debug'; + private $sended; // Sended email counter // Properties for storing the configuration @@ -15,6 +17,8 @@ class MailLib private $email_time_range; private $email_from_system; + private $_ci; // Codeigniter instance + /** * Class constructor */ @@ -24,16 +28,16 @@ class MailLib $this->sended = 0; // Get CI instance - $this->ci =& get_instance(); + $this->_ci =& get_instance(); // The second parameter is used to avoiding name collisions in the config array - $this->ci->config->load('mail', true); + $this->_ci->config->load('mail', true); // CI Email library - $this->ci->load->library('email'); + $this->_ci->load->library('email'); // Initializing email library with the loaded configurations - $this->ci->email->initialize($this->ci->config->config['mail']); + $this->_ci->email->initialize($this->_ci->config->config['mail']); // Set the configuration properties with the standard configuration values $this->email_number_to_sent = $this->getEmailCfgItem('email_number_to_sent'); @@ -48,6 +52,22 @@ class MailLib */ public function send($from, $to, $subject, $message, $alias = '', $cc = null, $bcc = null, $altMessage = '', $bulk = false, $autogenerated = false) { + // If it is configured then log mail info into the CI error logs + if ($this->getEmailCfgItem(self::ENABLE_DEBUG) === true) + { + $this->_ci->load->library('LogLib'); // Loads logging library + + // Log them all! + $this->_ci->loglib->logError('From: '.$from); + $this->_ci->loglib->logError('To: '.$to); + $this->_ci->loglib->logError('Subject: '.$subject); + $this->_ci->loglib->logError('Message: '.$message); + $this->_ci->loglib->logError('Alias: '.$alias); + $this->_ci->loglib->logError('CC: '.$cc); + $this->_ci->loglib->logError('BCC: '.$bcc); + $this->_ci->loglib->logError('Alternative message: '.$altMessage); + } + // If from is not specified then use the standard one if (is_null($from) || $from == '') { @@ -67,7 +87,7 @@ class MailLib } } - $this->ci->email->from($from, $alias); + $this->_ci->email->from($from, $alias); // Check if the email address of the debug recipient is a valid one $recipient = $to; @@ -83,20 +103,20 @@ class MailLib $recipientBCC = MAIL_DEBUG; } - $this->ci->email->to($recipient); - if (!is_null($recipientCC)) $this->ci->email->cc($recipientCC); - if (!is_null($recipientBCC)) $this->ci->email->bcc($recipientBCC); - $this->ci->email->subject($subject); - $this->ci->email->message($message); - if (!isEmptyString($altMessage)) $this->ci->email->set_alt_message($altMessage); + $this->_ci->email->to($recipient); + if (!is_null($recipientCC)) $this->_ci->email->cc($recipientCC); + if (!is_null($recipientBCC)) $this->_ci->email->bcc($recipientBCC); + $this->_ci->email->subject($subject); + $this->_ci->email->message($message); + if (!isEmptyString($altMessage)) $this->_ci->email->set_alt_message($altMessage); if($bulk) - $this->ci->email->set_header('Precedence', 'bulk'); + $this->_ci->email->set_header('Precedence', 'bulk'); if($autogenerated) - $this->ci->email->set_header('Auto-Submitted', 'auto-generated'); + $this->_ci->email->set_header('Auto-Submitted', 'auto-generated'); // Avoid printing on standard output ugly error messages - $result = @$this->ci->email->send(); + $result = @$this->_ci->email->send(); // If the email was succesfully sended then increment the counter // and checks if it has to wait until the sending of the next @@ -171,6 +191,6 @@ class MailLib */ private function getEmailCfgItem($itemName) { - return $this->ci->config->item($itemName, EMAIL_CONFIG_INDEX); + return $this->_ci->config->item($itemName, EMAIL_CONFIG_INDEX); } } diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 240055978..3a8f133cf 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -575,8 +575,9 @@ class MessageLib // Use the degree program email if (hasData($studiengangResult)) $message->receiverContact = getData($studiengangResult)[0]->email; } - // If message was sent from FAS - elseif (!isEmptyString($message->sender_ou)) + // If message was sent from FAS and NOT from infocenter + elseif (!isEmptyString($message->sender_ou) + && !array_search($message->sender_ou, $this->_ci->config->item(self::CFG_OU_RECEIVERS_NO_NOTICE))) { // If the recipient organisation unit is NOT in the list of organisation units that sent only to private emails if (array_search($message->receiver_ou, $this->_ci->config->item(self::CFG_OU_RECEIVERS_PRIVATE)) === false) @@ -592,7 +593,7 @@ class MessageLib } // Otherwise try with the private email - if ($message->receiverContact == null) + if (isEmptyString($message->receiverContact)) { $privateEmailResult = $this->_getPrivateEmail($message->receiver_id); if (isError($privateEmailResult)) return $privateEmailResult; // if an error occured then return it diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index e2c5c34c2..a841e266a 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -62,15 +62,31 @@ class Messages_model extends CI_Model // Loads needed models $this->load->model('system/MsgStatus_model', 'MsgStatusModel'); - // Set date used to insert - $statusData = array( - 'message_id' => $message_id, - 'person_id' => $person_id, - 'status' => MSG_STATUS_READ, - 'insertvon' => getAuthUID() + $statuResult = $this->MsgStatusModel->loadWhere( + array( + 'message_id' => $message_id, + 'person_id' => $person_id, + 'status' => MSG_STATUS_READ + ) ); - return $this->MsgStatusModel->insert($statusData); // insert and return result + if (isError($statuResult)) return $statuResult; + if (!hasData($statuResult)) + { + // Set date used to insert + return $this->MsgStatusModel->insert( + array( + 'message_id' => $message_id, + 'person_id' => $person_id, + 'status' => MSG_STATUS_READ, + 'insertvon' => getAuthUID() + ) + ); // insert and return result + } + else + { + return success('Already set as read'); + } } /** @@ -348,23 +364,43 @@ class Messages_model extends CI_Model elseif ($type == self::TYPE_PRESTUDENTS) // otherwise prestudents were given { $msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($recipients_ids); + + // Retrieve organisation unit for the recipients + $organisationUnitsResult = $this->PrestudentModel->getOrganisationunits($recipients_ids); + if (isError($organisationUnitsResult)) return $organisationUnitsResult; + if (hasData($organisationUnitsResult)) $senderOUArray = getData($organisationUnitsResult); } if (isError($msgVarsData)) show_error(getError($msgVarsData)); if (!hasData($msgVarsData)) show_error('No recipients were given'); + $senderOU = null; // sender organisation unit only for presetudents + $receiversCounter = 0; // a counter + + // Looping on receivers data foreach (getData($msgVarsData) as $receiver) { $msgVarsDataArray = $this->_lowerReplaceSpaceArrayKeys((array)$receiver); // replaces array keys - $parsedSubject = parseText($subject, $msgVarsDataArray); $parsedBody = parseText($body, $msgVarsDataArray); + // If exist an organisation unit for this prestudent and it is valid + if (isset($senderOUArray[$receiversCounter]) + && isset($senderOUArray[$receiversCounter]->oe_kurzbz) + && !isEmptyString($senderOUArray[$receiversCounter]->oe_kurzbz)) + { + $senderOU = $senderOUArray[$receiversCounter]->oe_kurzbz; + } + else + { + $senderOU = null; + } + $message = $this->messagelib->sendMessageUser( $msgVarsDataArray['person_id'], // receiverPersonId $parsedSubject, // subject $parsedBody, // body $sender_id, // sender_id - null, // senderOU + $senderOU, // senderOU $relationmessage_id, // relationmessage_id MSG_PRIORITY_NORMAL // priority ); @@ -378,6 +414,8 @@ class Messages_model extends CI_Model $personLog = $this->_personLog($sender_id, $msgVarsDataArray['person_id'], getData($message)[0]); if (isError($personLog)) return $personLog; } + + $receiversCounter++; // increment the counter } return success('Messages sent successfully'); @@ -452,7 +490,8 @@ class Messages_model extends CI_Model show_error('An error occurred while sending your message, please contact the site administrator'); } - $sender_id = getData($messageResult)[0]->receiver_id; + $sender_id = getAuthPersonId(); + if (!is_numeric($sender_id)) return error('The current logged user person_id is not defined'); $message = $this->messagelib->sendMessageUser( $receiver_id, // receiverPersonId @@ -484,6 +523,7 @@ class Messages_model extends CI_Model if (isEmptyString($body)) return error('Body is an empty string'); $sender_id = getAuthPersonId(); + if (!is_numeric($sender_id)) return error('The current logged user person_id is not defined'); $message = $this->messagelib->sendMessageOU( $receiverOU, // receiverPersonId @@ -672,7 +712,6 @@ class Messages_model extends CI_Model */ private function _prepareHtmlWriteTemplate($info, $message_id, $recipient_id) { - // Checks that info parameter is valid if (isError($info)) show_error(getError($info)); if (!hasData($info)) show_error('No recipients were given'); diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index bc7ab246f..cea11a7a7 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -314,7 +314,7 @@ class Recipient_model extends DB_Model mm.relationmessage_id, mm.subject, mm.body, - mr.sent AS sent, + mm.insertamum AS sent, p.vorname, p.nachname, MAX(ms.status) AS status, @@ -325,13 +325,11 @@ class Recipient_model extends DB_Model JOIN public.tbl_msg_status ms ON (ms.message_id = mr.message_id AND ms.person_id = mr.person_id) JOIN public.tbl_person p ON (p.person_id = mm.person_id) WHERE mr.person_id = ? - AND mr.sent IS NOT NULL - AND mr.sentinfo IS NULL GROUP BY mr.message_id, mm.relationmessage_id, mm.subject, mm.body, - mr.sent, + mm.insertamum, p.vorname, p.nachname, ms.person_id, @@ -342,7 +340,7 @@ class Recipient_model extends DB_Model mm.relationmessage_id, mm.subject, mm.body, - mrou.sent AS sent, + mm.insertamum AS sent, pr.vorname, pr.nachname, MAX(ms.status) AS status, @@ -362,13 +360,11 @@ class Recipient_model extends DB_Model JOIN public.tbl_msg_status ms ON (ms.message_id = mrou.message_id AND ms.person_id = mrou.person_id) JOIN public.tbl_person pr ON (pr.person_id = mm.person_id) WHERE p.person_id = ? - AND mrou.sent IS NOT NULL - AND mrou.sentinfo IS NULL GROUP BY mrou.message_id, mm.relationmessage_id, mm.subject, mm.body, - mrou.sent, + mm.insertamum, pr.vorname, pr.nachname, ms.person_id, @@ -387,7 +383,7 @@ class Recipient_model extends DB_Model mm.relationmessage_id, mm.subject, mm.body, - mr.sent, + mm.insertamum AS sent, p.person_id, p.vorname, p.nachname, @@ -397,24 +393,22 @@ class Recipient_model extends DB_Model mr.token FROM public.tbl_msg_message mm JOIN public.tbl_msg_recipient mr ON (mr.message_id = mm.message_id) - JOIN public.tbl_msg_status ms ON (ms.message_id = mm.message_id AND mr.person_id = mr.person_id) + JOIN public.tbl_msg_status ms ON (ms.message_id = mm.message_id AND ms.person_id = mr.person_id) JOIN public.tbl_person p ON (p.person_id = mr.person_id) LEFT JOIN public.tbl_organisationseinheit oe ON (oe.oe_kurzbz = mr.oe_kurzbz) WHERE mm.person_id = ? - AND mr.sent IS NOT NULL - AND mr.sentinfo IS NULL GROUP BY mm.message_id, mm.relationmessage_id, mm.subject, mm.body, - mr.sent, + mm.insertamum, p.person_id, p.vorname, p.nachname, ms.person_id, oe.bezeichnung, mr.token - ORDER BY mr.sent DESC'; + ORDER BY sent DESC'; return $this->execQuery($sql, array($person_id)); } From d74a516202a776cbc0752810f6ca54dd835ec1e6 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 18 Feb 2020 17:33:44 +0100 Subject: [PATCH 66/72] - testtool edit_gebiet.php: hinweis for suggestion offsetpunkteanzahl is always shown --- cis/testtool/admin/edit_gebiet.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cis/testtool/admin/edit_gebiet.php b/cis/testtool/admin/edit_gebiet.php index 5610679b4..68c502577 100644 --- a/cis/testtool/admin/edit_gebiet.php +++ b/cis/testtool/admin/edit_gebiet.php @@ -265,8 +265,8 @@ if ($gebiet_id != '') { $offsetwarnung = strlen($gebiet->errormsg) > 0 ? ' (HINWEIS: '.$gebiet->errormsg.')' : ''; - if ($gebiet->offsetpunkte != $offsetpunkte) - $offsethinweis = ' empfohlene Offsetpunkteanzahl: '.round($offsetpunkte).(round($offsetpunkte) != $offsetpunkte ? ' ('.$offsetpunkte.' gerundet)' : '').$offsetwarnung.''; + $offsethinweis = ' empfohlene Offsetpunkteanzahl: '.round($offsetpunkte).(round($offsetpunkte) != $offsetpunkte ? ' ('.$offsetpunkte.' gerundet)' : '').''; + $offsethinweis .= ''.$offsetwarnung.''; } echo 'Offsetpunkte (minimale Punkteanzahl)'.$offsethinweis.''; echo ''; From 0b3d5e19a37fcde97901874a7d3436648c993f72 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 20 Feb 2020 14:39:37 +0100 Subject: [PATCH 67/72] CL/Messages_model->sendReply now uses as sender id the logged user person id or the previous message recipient id --- application/models/CL/Messages_model.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index a841e266a..dd9655131 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -472,6 +472,7 @@ class Messages_model extends CI_Model /** * Send a reply to a single recipient for a message identified by a token (no templates are used) + * NOTE: this method could be also called from not authenticated controllers */ public function sendReply($receiver_id, $subject, $body, $relationmessage_id, $token) { @@ -490,8 +491,9 @@ class Messages_model extends CI_Model show_error('An error occurred while sending your message, please contact the site administrator'); } - $sender_id = getAuthPersonId(); - if (!is_numeric($sender_id)) return error('The current logged user person_id is not defined'); + // If the user is logged then use its person id as sender id, otherwise get the receiver id of the previous message + $sender_id = isLogged() ? getAuthPersonId() : getData($messageResult)[0]->receiver_id; + if (!is_numeric($sender_id)) return error('The sender id is not valid'); $message = $this->messagelib->sendMessageUser( $receiver_id, // receiverPersonId From 1ac1c118d530efb7e28729297a31aa2f154b6c2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Thu, 20 Feb 2020 15:53:43 +0100 Subject: [PATCH 68/72] Fixed Message Reply --- application/models/CL/Messages_model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index dd9655131..de6ec5a10 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -271,9 +271,9 @@ class Messages_model extends CI_Model if (isError($isEmployeeResult)) show_error(getError($isEmployeeResult)); if (hasData($isEmployeeResult)) $isEmployee = true; - // If the sender is an employee and are present configurations to reply + // If the sender is not an employee and are present configurations to reply $hrefReply = ''; - if ($isEmployee && !isEmptyString($this->config->item(MessageLib::CFG_REDIRECT_VIEW_MESSAGE_URL))) + if (!$isEmployee && !isEmptyString($this->config->item(MessageLib::CFG_REDIRECT_VIEW_MESSAGE_URL))) { $hrefReply = $this->config->item(MessageLib::CFG_MESSAGE_SERVER). $this->config->item(MessageLib::CFG_REDIRECT_VIEW_MESSAGE_URL). From 9a9b847138ba5c32842ae43b4775adc731c41775 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 20 Feb 2020 16:21:31 +0100 Subject: [PATCH 69/72] Fixed Tabulator include in FHC-Header --- application/views/templates/FHC-Header.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/application/views/templates/FHC-Header.php b/application/views/templates/FHC-Header.php index c569d2389..5eec10f43 100644 --- a/application/views/templates/FHC-Header.php +++ b/application/views/templates/FHC-Header.php @@ -182,7 +182,11 @@ } // Tabulator JS - if ($tabulator === true) generateJSsInclude('vendor/olifolkerd/tabulator/dist/js/tabulator.min.js'); + if ($tabulator === true) + { + generateJSsInclude('vendor/olifolkerd/tabulator/dist/js/tabulator.min.js'); + generateJSsInclude('vendor/olifolkerd/tabulator/dist/js/jquery_wrapper.min.js'); + } // Tinymce JS if ($tinymce === true) generateJSsInclude('vendor/tinymce/tinymce/tinymce.min.js'); From fc9ae760b5a7849c2287d2678eca3140cd2ca209 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 20 Feb 2020 17:07:57 +0100 Subject: [PATCH 70/72] public.vw_msg_vars: added variables semester, Studiengangsassistenz, relative Prio --- system/dbupdate_3.3.php | 174 ++++++++++++++++++++++++++-------------- 1 file changed, 116 insertions(+), 58 deletions(-) diff --git a/system/dbupdate_3.3.php b/system/dbupdate_3.3.php index a7d4011cc..de3df43c0 100644 --- a/system/dbupdate_3.3.php +++ b/system/dbupdate_3.3.php @@ -3462,77 +3462,135 @@ if(!$result = @$db->db_query("SELECT orgform_kurzbz FROM public.tbl_bankverbindu } // iban und bic zu vw_msg_vars hinzufügen -if(!$result = @$db->db_query('SELECT "IBAN Studiengang", "BIC Studiengang" FROM public.vw_msg_vars LIMIT 1')) +if(!$result = @$db->db_query('SELECT "IBAN Studiengang", "BIC Studiengang", "Studiengangskennzahl", "Einstiegssemester", "Einstiegsstudiensemester", "Vorname Studiengangsassistenz", "Nachname Studiengangsassistenz", "Durchwahl Studiengangsassistenz", "Relative Priorität" FROM public.vw_msg_vars LIMIT 1')) { $qry = ' CREATE OR REPLACE VIEW public.vw_msg_vars AS ( SELECT DISTINCT ON(p.person_id, pr.prestudent_id) p.person_id, - pr.prestudent_id AS prestudent_id, - p.nachname AS "Nachname", - p.vorname AS "Vorname", - p.anrede AS "Anrede", - a.strasse AS "Strasse", - a.ort AS "Ort", - a.plz AS "PLZ", - a.gemeinde AS "Gemeinde", - a.langtext AS "Nation", - ke.kontakt AS "Email", - kt.kontakt AS "Telefon", - s.bezeichnung AS "Studiengang DE", - s.english AS "Studiengang EN", - st.bezeichnung AS "Typ", - last_prestudent_status.orgform_kurzbz AS "Orgform", - p.zugangscode AS "Zugangscode", - bk.iban AS "IBAN Studiengang", - bk.bic AS "BIC Studiengang" - FROM public.tbl_person p - LEFT JOIN ( - SELECT person_id, - kontakt - FROM public.tbl_kontakt - WHERE zustellung = TRUE - AND kontakttyp = \'email\' - ORDER BY kontakt_id DESC - ) ke USING(person_id) - LEFT JOIN ( - SELECT person_id, - kontakt - FROM public.tbl_kontakt - WHERE zustellung = TRUE - AND kontakttyp IN (\'telefon\', \'mobil\') - ORDER BY kontakt_id DESC - ) kt USING(person_id) - LEFT JOIN ( - SELECT person_id, - strasse, - ort, - plz, - gemeinde, - langtext - FROM public.tbl_adresse + pr.prestudent_id AS prestudent_id, + p.nachname AS "Nachname", + p.vorname AS "Vorname", + p.anrede AS "Anrede", + a.strasse AS "Strasse", + a.ort AS "Ort", + a.plz AS "PLZ", + a.gemeinde AS "Gemeinde", + a.langtext AS "Nation", + ke.kontakt AS "Email", + kt.kontakt AS "Telefon", + s.bezeichnung AS "Studiengang DE", + s.english AS "Studiengang EN", + st.bezeichnung AS "Typ", + last_prestudent_status.orgform_kurzbz AS "Orgform", + p.zugangscode AS "Zugangscode", + bk.iban AS "IBAN Studiengang", + bk.bic AS "BIC Studiengang", + s.studiengang_kz AS "Studiengangskennzahl", + first_prestudent_status.ausbildungssemester AS "Einstiegssemester", + first_prestudent_status.studiensemester AS "Einstiegsstudiensemester", + ass.vorname AS "Vorname Studiengangsassistenz", + ass.nachname AS "Nachname Studiengangsassistenz", + ass.telefonklappe AS "Durchwahl Studiengangsassistenz", + (SELECT count(*) + FROM ( + SELECT pss.prestudent_id, pss.person_id, priorisierung, + ( + SELECT status_kurzbz + FROM public.tbl_prestudentstatus + WHERE prestudent_id = pss.prestudent_id + ORDER BY datum DESC, + tbl_prestudentstatus.insertamum DESC LIMIT 1 + ) AS laststatus + FROM public.tbl_prestudent pss + JOIN public.tbl_prestudentstatus USING (prestudent_id) + WHERE person_id = ( + SELECT person_id + FROM public.tbl_prestudent + WHERE prestudent_id = pr.prestudent_id + ) + AND studiensemester_kurzbz = ( + SELECT studiensemester_kurzbz + FROM public.tbl_prestudentstatus + WHERE prestudent_id = pr.prestudent_id + AND status_kurzbz = \'Interessent\' LIMIT 1 + ) + AND status_kurzbz = \'Interessent\' + ) prest + WHERE laststatus NOT IN (\'Abbrecher\', \'Abgewiesener\', \'Absolvent\') + AND priorisierung <= pr.priorisierung) AS "Relative Priorität" + FROM public.tbl_person p + LEFT JOIN ( + SELECT person_id, + kontakt + FROM public.tbl_kontakt + WHERE zustellung = TRUE + AND kontakttyp = \'email\' + ORDER BY kontakt_id DESC + ) ke USING(person_id) + LEFT JOIN ( + SELECT person_id, + kontakt + FROM public.tbl_kontakt + WHERE zustellung = TRUE + AND kontakttyp IN (\'telefon\', \'mobil\') + ORDER BY kontakt_id DESC + ) kt USING(person_id) + LEFT JOIN ( + SELECT person_id, + strasse, + ort, + plz, + gemeinde, + langtext + FROM public.tbl_adresse LEFT JOIN bis.tbl_nation ON(bis.tbl_nation.nation_code = public.tbl_adresse.nation) - WHERE public.tbl_adresse.heimatadresse = TRUE - ORDER BY adresse_id DESC - ) a USING(person_id) + WHERE public.tbl_adresse.heimatadresse = TRUE + ORDER BY adresse_id DESC + ) a USING(person_id) LEFT JOIN public.tbl_prestudent pr USING(person_id) INNER JOIN public.tbl_studiengang s USING(studiengang_kz) INNER JOIN public.tbl_studiengangstyp st USING(typ) LEFT JOIN ( - SELECT DISTINCT ON (ps.prestudent_id) tbl_studienplan.orgform_kurzbz, ps.prestudent_id - FROM public.tbl_prestudent ps - JOIN public.tbl_prestudentstatus ON ps.prestudent_id = tbl_prestudentstatus.prestudent_id - JOIN lehre.tbl_studienplan USING(studienplan_id) - ORDER BY ps.prestudent_id DESC, - tbl_prestudentstatus.datum DESC, - tbl_prestudentstatus.insertamum DESC, - tbl_prestudentstatus.ext_id DESC - ) last_prestudent_status ON pr.prestudent_id = last_prestudent_status.prestudent_id + SELECT DISTINCT ON (ps.prestudent_id) ps.prestudent_id, tbl_studienplan.orgform_kurzbz + FROM public.tbl_prestudent ps + JOIN public.tbl_prestudentstatus ON ps.prestudent_id = tbl_prestudentstatus.prestudent_id + JOIN lehre.tbl_studienplan USING(studienplan_id) + ORDER BY ps.prestudent_id DESC, + tbl_prestudentstatus.datum DESC, + tbl_prestudentstatus.insertamum DESC, + tbl_prestudentstatus.ext_id DESC + ) last_prestudent_status ON pr.prestudent_id = last_prestudent_status.prestudent_id LEFT JOIN ( + SELECT DISTINCT ON (ps.prestudent_id) ps.prestudent_id, tbl_prestudentstatus.ausbildungssemester, + studiensemester_kurzbz, tbl_studiensemester.bezeichnung AS studiensemester, + tbl_studienordnung.studiengang_kz + FROM public.tbl_prestudent ps + JOIN public.tbl_prestudentstatus ON ps.prestudent_id = tbl_prestudentstatus.prestudent_id + JOIN public.tbl_studiensemester USING (studiensemester_kurzbz) + JOIN lehre.tbl_studienplan USING(studienplan_id) + JOIN lehre.tbl_studienordnung USING (studienordnung_id) + WHERE tbl_prestudentstatus.status_kurzbz = \'Interessent\' + ORDER BY ps.prestudent_id ASC, + tbl_prestudentstatus.datum ASC, + tbl_prestudentstatus.insertamum ASC, + tbl_prestudentstatus.ext_id ASC + ) first_prestudent_status ON pr.prestudent_id = first_prestudent_status.prestudent_id + LEFT JOIN ( + SELECT DISTINCT ON (tbl_benutzerfunktion.oe_kurzbz) vorname, nachname, oe_kurzbz, telefonklappe + FROM public.tbl_benutzerfunktion + JOIN public.tbl_benutzer USING (uid) + JOIN public.tbl_person USING (person_id) + JOIN public.tbl_mitarbeiter on tbl_benutzer.uid = tbl_mitarbeiter.mitarbeiter_uid + WHERE tbl_benutzerfunktion.funktion_kurzbz = \'ass\' + AND NOW() BETWEEN COALESCE(datum_von, NOW()) AND COALESCE(datum_bis, NOW()) + ORDER BY tbl_benutzerfunktion.oe_kurzbz, tbl_benutzerfunktion.insertamum DESC NULLS LAST, datum_von DESC NULLS LAST + ) ass ON s.oe_kurzbz = ass.oe_kurzbz + LEFT JOIN ( SELECT DISTINCT ON (oe_kurzbz, orgform_kurzbz) oe_kurzbz, orgform_kurzbz, iban, bic FROM tbl_bankverbindung WHERE oe_kurzbz IS NOT NULL ORDER BY oe_kurzbz, orgform_kurzbz, tbl_bankverbindung.insertamum DESC,tbl_bankverbindung.iban - )bk ON s.oe_kurzbz = bk.oe_kurzbz AND (last_prestudent_status.orgform_kurzbz = bk.orgform_kurzbz OR bk.orgform_kurzbz IS NULL) + )bk ON s.oe_kurzbz = bk.oe_kurzbz AND (last_prestudent_status.orgform_kurzbz = bk.orgform_kurzbz OR bk.orgform_kurzbz IS NULL) WHERE p.aktiv = TRUE ORDER BY p.person_id ASC, pr.prestudent_id ASC );'; @@ -3540,7 +3598,7 @@ if(!$result = @$db->db_query('SELECT "IBAN Studiengang", "BIC Studiengang" FROM if(!$db->db_query($qry)) echo 'public.vw_msg_vars: '.$db->db_last_error().'
'; else - echo '
public.vw_msg_vars iban und bic added'; + echo '
public.vw_msg_vars IBAN Studiengang, BIC Studiengang, Studiengangskennzahl, Einstiegssemester, Einstiegsstudiensemester, Vorname Studiengangsassistenz, Nachname Studiengangsassistenz, Durchwahl Studiengangsassistenz, Relative Priorität added'; } // *** Pruefung und hinzufuegen der neuen Attribute und Tabellen From 7043422fe9c96d7a443bb4bb75dd4eac6ef86d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Thu, 20 Feb 2020 18:11:37 +0100 Subject: [PATCH 71/72] Zahlenformat bei Lehrauftragsexport korrigiert --- content/statistik/lehrauftragsliste_mail.xls.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/statistik/lehrauftragsliste_mail.xls.php b/content/statistik/lehrauftragsliste_mail.xls.php index 6c701c4f5..853be72fe 100644 --- a/content/statistik/lehrauftragsliste_mail.xls.php +++ b/content/statistik/lehrauftragsliste_mail.xls.php @@ -125,15 +125,15 @@ $format_colored =& $workbook->addFormat(); $format_colored->setFgColor(10); $format_number_colored =& $workbook->addFormat(); -$format_number_colored->setNumFormat('0, 0.00'); +$format_number_colored->setNumFormat('0,0.00'); //$format_number_colored->setNumFormat('0.00'); $format_number_colored->setFgColor(10); $format_number =& $workbook->addFormat(); -$format_number->setNumFormat('0, 0.00'); +$format_number->setNumFormat('0,0.00'); $format_number_bold =& $workbook->addFormat(); -$format_number_bold->setNumFormat('0, 0.00'); +$format_number_bold->setNumFormat('0,0.00'); //$format_number_bold->setNumFormat('0.00'); $format_number_bold->setBold(); From f1cf82c107267f606e61599dac64cd28a9a30211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Thu, 20 Feb 2020 18:48:15 +0100 Subject: [PATCH 72/72] =?UTF-8?q?Spalte=20Alias=20hinzugef=C3=BCgt,=20Spal?= =?UTF-8?q?te=20Prio=20umbenannt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/dbupdate_3.3.php | 107 ++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/system/dbupdate_3.3.php b/system/dbupdate_3.3.php index de3df43c0..a3965780a 100644 --- a/system/dbupdate_3.3.php +++ b/system/dbupdate_3.3.php @@ -3462,62 +3462,63 @@ if(!$result = @$db->db_query("SELECT orgform_kurzbz FROM public.tbl_bankverbindu } // iban und bic zu vw_msg_vars hinzufügen -if(!$result = @$db->db_query('SELECT "IBAN Studiengang", "BIC Studiengang", "Studiengangskennzahl", "Einstiegssemester", "Einstiegsstudiensemester", "Vorname Studiengangsassistenz", "Nachname Studiengangsassistenz", "Durchwahl Studiengangsassistenz", "Relative Priorität" FROM public.vw_msg_vars LIMIT 1')) +if(!$result = @$db->db_query('SELECT "IBAN Studiengang", "BIC Studiengang", "Studiengangskennzahl", "Einstiegssemester", "Einstiegsstudiensemester", "Vorname Studiengangsassistenz", "Nachname Studiengangsassistenz", "Durchwahl Studiengangsassistenz", "Relative Prio" FROM public.vw_msg_vars LIMIT 1')) { $qry = ' CREATE OR REPLACE VIEW public.vw_msg_vars AS ( SELECT DISTINCT ON(p.person_id, pr.prestudent_id) p.person_id, - pr.prestudent_id AS prestudent_id, - p.nachname AS "Nachname", - p.vorname AS "Vorname", - p.anrede AS "Anrede", - a.strasse AS "Strasse", - a.ort AS "Ort", - a.plz AS "PLZ", - a.gemeinde AS "Gemeinde", - a.langtext AS "Nation", - ke.kontakt AS "Email", - kt.kontakt AS "Telefon", - s.bezeichnung AS "Studiengang DE", - s.english AS "Studiengang EN", - st.bezeichnung AS "Typ", - last_prestudent_status.orgform_kurzbz AS "Orgform", - p.zugangscode AS "Zugangscode", - bk.iban AS "IBAN Studiengang", - bk.bic AS "BIC Studiengang", - s.studiengang_kz AS "Studiengangskennzahl", - first_prestudent_status.ausbildungssemester AS "Einstiegssemester", - first_prestudent_status.studiensemester AS "Einstiegsstudiensemester", - ass.vorname AS "Vorname Studiengangsassistenz", - ass.nachname AS "Nachname Studiengangsassistenz", - ass.telefonklappe AS "Durchwahl Studiengangsassistenz", - (SELECT count(*) - FROM ( - SELECT pss.prestudent_id, pss.person_id, priorisierung, - ( - SELECT status_kurzbz - FROM public.tbl_prestudentstatus - WHERE prestudent_id = pss.prestudent_id - ORDER BY datum DESC, - tbl_prestudentstatus.insertamum DESC LIMIT 1 - ) AS laststatus - FROM public.tbl_prestudent pss - JOIN public.tbl_prestudentstatus USING (prestudent_id) - WHERE person_id = ( - SELECT person_id - FROM public.tbl_prestudent - WHERE prestudent_id = pr.prestudent_id - ) - AND studiensemester_kurzbz = ( - SELECT studiensemester_kurzbz - FROM public.tbl_prestudentstatus - WHERE prestudent_id = pr.prestudent_id - AND status_kurzbz = \'Interessent\' LIMIT 1 - ) - AND status_kurzbz = \'Interessent\' - ) prest - WHERE laststatus NOT IN (\'Abbrecher\', \'Abgewiesener\', \'Absolvent\') - AND priorisierung <= pr.priorisierung) AS "Relative Priorität" + pr.prestudent_id AS prestudent_id, + p.nachname AS "Nachname", + p.vorname AS "Vorname", + p.anrede AS "Anrede", + a.strasse AS "Strasse", + a.ort AS "Ort", + a.plz AS "PLZ", + a.gemeinde AS "Gemeinde", + a.langtext AS "Nation", + ke.kontakt AS "Email", + kt.kontakt AS "Telefon", + s.bezeichnung AS "Studiengang DE", + s.english AS "Studiengang EN", + st.bezeichnung AS "Typ", + last_prestudent_status.orgform_kurzbz AS "Orgform", + p.zugangscode AS "Zugangscode", + bk.iban AS "IBAN Studiengang", + bk.bic AS "BIC Studiengang", + s.studiengang_kz AS "Studiengangskennzahl", + first_prestudent_status.ausbildungssemester AS "Einstiegssemester", + first_prestudent_status.studiensemester AS "Einstiegsstudiensemester", + ass.vorname AS "Vorname Studiengangsassistenz", + ass.nachname AS "Nachname Studiengangsassistenz", + ass.telefonklappe AS "Durchwahl Studiengangsassistenz", + ass.alias AS "Alias Studiengangsassistenz", + (SELECT count(*) + FROM ( + SELECT pss.prestudent_id, pss.person_id, priorisierung, + ( + SELECT status_kurzbz + FROM public.tbl_prestudentstatus + WHERE prestudent_id = pss.prestudent_id + ORDER BY datum DESC, + tbl_prestudentstatus.insertamum DESC LIMIT 1 + ) AS laststatus + FROM public.tbl_prestudent pss + JOIN public.tbl_prestudentstatus USING (prestudent_id) + WHERE person_id = ( + SELECT person_id + FROM public.tbl_prestudent + WHERE prestudent_id = pr.prestudent_id + ) + AND studiensemester_kurzbz = ( + SELECT studiensemester_kurzbz + FROM public.tbl_prestudentstatus + WHERE prestudent_id = pr.prestudent_id + AND status_kurzbz = \'Interessent\' LIMIT 1 + ) + AND status_kurzbz = \'Interessent\' + ) prest + WHERE laststatus NOT IN (\'Abbrecher\', \'Abgewiesener\', \'Absolvent\') + AND priorisierung <= pr.priorisierung) AS "Relative Prio" FROM public.tbl_person p LEFT JOIN ( SELECT person_id, @@ -3576,7 +3577,7 @@ if(!$result = @$db->db_query('SELECT "IBAN Studiengang", "BIC Studiengang", "Stu tbl_prestudentstatus.ext_id ASC ) first_prestudent_status ON pr.prestudent_id = first_prestudent_status.prestudent_id LEFT JOIN ( - SELECT DISTINCT ON (tbl_benutzerfunktion.oe_kurzbz) vorname, nachname, oe_kurzbz, telefonklappe + SELECT DISTINCT ON (tbl_benutzerfunktion.oe_kurzbz) vorname, nachname, oe_kurzbz, telefonklappe, alias FROM public.tbl_benutzerfunktion JOIN public.tbl_benutzer USING (uid) JOIN public.tbl_person USING (person_id)