From 0244caaa70750c657e70fa15b55be563b4cf6a9b Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 17 Jan 2020 15:39:34 +0100 Subject: [PATCH] - Moved core from Redirect controller to ViewMessage controller - Dropped Redirect controller - Adapted configs and paths because of these changes --- application/config/message.php | 4 +- .../controllers/system/messages/Redirect.php | 80 ------------------- .../system/messages/ViewMessage.php | 51 ++++++++++++ .../views/system/messages/htmlWriteReply.php | 2 +- 4 files changed, 54 insertions(+), 83 deletions(-) delete mode 100644 application/controllers/system/messages/Redirect.php diff --git a/application/config/message.php b/application/config/message.php index 065cb1b66..b13fbe8b9 100644 --- a/application/config/message.php +++ b/application/config/message.php @@ -7,7 +7,7 @@ $config['send_immediately'] = false; $config['msg_delivery'] = true; // Default true $config['system_person_id'] = 1; // Dummy sender, used for sending messages from the system -$config['redirect_view_message_url'] = '/system/messages/Redirect/redirectByToken/'; +$config['redirect_view_message_url'] = '/system/messages/ViewMessage/redirectByToken/'; $config['message_html_view_url'] = '/system/messages/ViewMessage/toHTML/'; // Change this to CIS Server (https://cis.example.com/index.ci.php) if you are sending Messages from Vilesci @@ -15,6 +15,6 @@ $config['message_server'] = site_url(); $config['ou_receivers'] = array('ass'); $config['message_redirect_url'] = array(); -$config['message_redirect_url']['fallback'] = site_url('system/messagesViewMessage/writeReply'); +$config['message_redirect_url']['fallback'] = site_url('system/messages/ViewMessage/writeReply'); // $config['message_redirect_url']['OE_ROOT_1'] = 'https:///addons/aufnahme/OE_ROOT/cis/index.php'; // $config['message_redirect_url']['OE_ROOT_2'] = 'https:///'; diff --git a/application/controllers/system/messages/Redirect.php b/application/controllers/system/messages/Redirect.php deleted file mode 100644 index 855a6fd84..000000000 --- a/application/controllers/system/messages/Redirect.php +++ /dev/null @@ -1,80 +0,0 @@ -load->model('system/MessageToken_model', 'MessageTokenModel'); - } - - /** - * With the given token redirects the user to reply page configured in the config/message.php file - */ - public function redirectByToken($token) - { - // Retrieves the single message data using the given token - $msg = $this->MessageTokenModel->getMessageByToken($token); - // If it is an error or it does not contain data show an error - if (!hasData($msg)) show_error('MSG-ERR-0001: An error occurred while redirecting, please contact the administrator'); - // else - $oe_kurzbz = getData($msg)[0]->oe_kurzbz; - - $organisationRoot = null; // by default is null - - // If an organisation unit is present in the message tries to retrieve the root organisation unit - // from the one found in the message - if (!isEmptyString($oe_kurzbz)) - { - // Retrieves the root organisation unit from the one found in the message - $getOERoot = $this->MessageTokenModel->getOERoot($oe_kurzbz); - // If it is an error or it does not contain data show an error - if (!hasData($getOERoot)) show_error('MSG-ERR-0002: An error occurred while redirecting, please contact the administrator'); - // else - $organisationRoot = getData($getOERoot)[0]->oe_kurzbz; - } - - // Retrieves the possible redirecting URLs array from configs - $messageRedirectUrls = $this->config->item('message_redirect_url'); - // If it is not a valid array then show an error - if (isEmptyArray($messageRedirectUrls)) show_error('MSG-ERR-0003: An error occurred while redirecting, please contact the administrator'); - - // If this organisation unit root is not configured as an entry in the possible redirecting URLs array, - // then tries to use the default one... - if (!isset($messageRedirectUrls[$organisationRoot])) - { - $organisationRoot = 'fallback'; - - // ...if even the default one is not present show an error - if (!isset($messageRedirectUrls[$organisationRoot])) - { - show_error('MSG-ERR-0004: An error occurred while redirecting, please contact the administrator'); - } - } - - // Finally if everything was right then the user can be redirected - redirect($messageRedirectUrls[$organisationRoot] . '?token=' . $token); - } -} diff --git a/application/controllers/system/messages/ViewMessage.php b/application/controllers/system/messages/ViewMessage.php index 9c6fc4c4e..72216aa3a 100644 --- a/application/controllers/system/messages/ViewMessage.php +++ b/application/controllers/system/messages/ViewMessage.php @@ -72,4 +72,55 @@ class ViewMessage extends FHC_Controller $this->load->view('system/messages/htmlError'); } } + + /** + * With the given token redirects the user to reply page configured in the config/message.php file + */ + public function redirectByToken($token) + { + // Loads model MessageTokenModel + $this->load->model('system/MessageToken_model', 'MessageTokenModel'); + + // Retrieves the single message data using the given token + $msg = $this->MessageTokenModel->getMessageByToken($token); + // If it is an error or it does not contain data show an error + if (!hasData($msg)) show_error('MSG-ERR-0001: An error occurred while redirecting, please contact the administrator'); + // else + $oe_kurzbz = getData($msg)[0]->oe_kurzbz; + + $organisationRoot = null; // by default is null + + // If an organisation unit is present in the message tries to retrieve the root organisation unit + // from the one found in the message + if (!isEmptyString($oe_kurzbz)) + { + // Retrieves the root organisation unit from the one found in the message + $getOERoot = $this->MessageTokenModel->getOERoot($oe_kurzbz); + // If it is an error or it does not contain data show an error + if (!hasData($getOERoot)) show_error('MSG-ERR-0002: An error occurred while redirecting, please contact the administrator'); + // else + $organisationRoot = getData($getOERoot)[0]->oe_kurzbz; + } + + // Retrieves the possible redirecting URLs array from configs + $messageRedirectUrls = $this->config->item('message_redirect_url'); + // If it is not a valid array then show an error + if (isEmptyArray($messageRedirectUrls)) show_error('MSG-ERR-0003: An error occurred while redirecting, please contact the administrator'); + + // If this organisation unit root is not configured as an entry in the possible redirecting URLs array, + // then tries to use the default one... + if (!isset($messageRedirectUrls[$organisationRoot])) + { + $organisationRoot = 'fallback'; + + // ...if even the default one is not present show an error + if (!isset($messageRedirectUrls[$organisationRoot])) + { + show_error('MSG-ERR-0004: An error occurred while redirecting, please contact the administrator'); + } + } + + // Finally if everything was right then the user can be redirected + redirect($messageRedirectUrls[$organisationRoot] . '?token=' . $token); + } } diff --git a/application/views/system/messages/htmlWriteReply.php b/application/views/system/messages/htmlWriteReply.php index dde6cf17a..8e1ef7d7f 100644 --- a/application/views/system/messages/htmlWriteReply.php +++ b/application/views/system/messages/htmlWriteReply.php @@ -22,7 +22,7 @@ -
+