From 63f475cd2744b35d37c9bab4c13da34935928870 Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 17 Jan 2020 15:02:42 +0100 Subject: [PATCH] - Moved controllers Redirect and ViewMessage to system/messages/ - Changed config entries in message.php - Changed Redirect controller to improve code and logic --- application/config/message.php | 9 +- application/controllers/Redirect.php | 87 ------------------- .../controllers/system/messages/Redirect.php | 80 +++++++++++++++++ .../{ => system/messages}/ViewMessage.php | 0 4 files changed, 85 insertions(+), 91 deletions(-) delete mode 100644 application/controllers/Redirect.php create mode 100644 application/controllers/system/messages/Redirect.php rename application/controllers/{ => system/messages}/ViewMessage.php (100%) diff --git a/application/config/message.php b/application/config/message.php index 30444b0ef..065cb1b66 100644 --- a/application/config/message.php +++ b/application/config/message.php @@ -7,13 +7,14 @@ $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'] = '/Redirect/redirectByToken/'; -$config['message_html_view_url'] = '/ViewMessage/toHTML/'; +$config['redirect_view_message_url'] = '/system/messages/Redirect/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 $config['message_server'] = site_url(); $config['ou_receivers'] = array('ass'); $config['message_redirect_url'] = array(); -$config['message_redirect_url']['fallback'] = site_url('ViewMessage/writeReply'); -// $config['message_redirect_url']['OE_ROOT'] = 'https://SERVER-NAME/addons/aufnahme/OE_ROOT/cis/index.php'; +$config['message_redirect_url']['fallback'] = site_url('system/messagesViewMessage/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/Redirect.php b/application/controllers/Redirect.php deleted file mode 100644 index 8a107b4b3..000000000 --- a/application/controllers/Redirect.php +++ /dev/null @@ -1,87 +0,0 @@ -load->model('system/MessageToken_model', 'MessageTokenModel'); - } - - /** - * redirectByToken - * - * - Loads the message using a token - * - Loads the root of the organisation unit tree using the oe_kurzbz present in the message - * - Redirect to the aufnahme related to the found organisation unit - */ - public function redirectByToken($token) - { - $msg = $this->MessageTokenModel->getMessageByToken($token); - if (isError($msg)) - { - show_error(getError($msg)); - } - - $oe_kurzbz = null; - if (hasData($msg)) $oe_kurzbz = getData($msg)[0]->oe_kurzbz; - - if ($oe_kurzbz != null && $oe_kurzbz != '') - { - $organisationRoot = null; - - $getOERoot = $this->MessageTokenModel->getOERoot($oe_kurzbz); - if (isSuccess($getOERoot)) // If no errors occurred - { - $organisationRoot = getData($getOERoot); - } - else - { - show_error('No organisation unit present in the message'); - } - - $addonAufnahmeUrls = $this->config->item('message_redirect_url'); - if(!isset($addonAufnahmeUrls[$organisationRoot])) - $organisationRoot = 'fallback'; - - if (isset($token) - && hasData($msg) - && is_array($addonAufnahmeUrls) - && $organisationRoot != null - && isset($addonAufnahmeUrls[$organisationRoot])) - { - redirect($addonAufnahmeUrls[$organisationRoot] . '?token=' . $token); - } - } - else - { - $addonAufnahmeUrls = $this->config->item('message_redirect_url'); - if (isset($token) - && hasData($msg) - && is_array($addonAufnahmeUrls) - && isset($addonAufnahmeUrls['fallback'])) - { - redirect($addonAufnahmeUrls['fallback'] . '?token=' . $token); - } - } - } -} diff --git a/application/controllers/system/messages/Redirect.php b/application/controllers/system/messages/Redirect.php new file mode 100644 index 000000000..855a6fd84 --- /dev/null +++ b/application/controllers/system/messages/Redirect.php @@ -0,0 +1,80 @@ +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/ViewMessage.php b/application/controllers/system/messages/ViewMessage.php similarity index 100% rename from application/controllers/ViewMessage.php rename to application/controllers/system/messages/ViewMessage.php