diff --git a/application/config/fhcomplete.php b/application/config/fhcomplete.php index 0f7f1e94a..427270550 100644 --- a/application/config/fhcomplete.php +++ b/application/config/fhcomplete.php @@ -5,4 +5,5 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); $config['fhc_version'] = '3.3'; $config['addons_aufnahme_url'] = array(); +$config['addons_aufnahme_url']['fallback'] = 'https://localhost/fhcomplete/index.ci.php/ViewMessage/writeReply/'; $config['addons_aufnahme_url']['OE_ROOT'] = 'https://SERVER-NAME/addons/aufnahme/OE_ROOT/cis/index.php'; diff --git a/application/controllers/Redirect.php b/application/controllers/Redirect.php index c3ba110ca..6f3d457a8 100644 --- a/application/controllers/Redirect.php +++ b/application/controllers/Redirect.php @@ -75,5 +75,16 @@ class Redirect extends CI_Controller redirect($addonAufnahmeUrls[$organisationRoot] . '?token=' . $token); } } + else + { + $addonAufnahmeUrls = $this->config->item('addons_aufnahme_url'); + if (isset($token) + && hasData($msg) + && is_array($addonAufnahmeUrls) + && isset($addonAufnahmeUrls['fallback'])) + { + redirect($addonAufnahmeUrls['fallback'] . '?token=' . $token); + } + } } } diff --git a/application/controllers/ViewMessage.php b/application/controllers/ViewMessage.php index 48c0a09f1..1d510d9a3 100644 --- a/application/controllers/ViewMessage.php +++ b/application/controllers/ViewMessage.php @@ -15,6 +15,7 @@ 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 */ @@ -83,4 +84,130 @@ class ViewMessage extends CI_Controller $this->load->view('system/messageHTML.php', $data); } } + + /** + * write the reply + */ + public function writeReply() + { + $token = $this->input->get('token'); + + if (empty($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 = $msg->retval[0]; + + // Get variables + $receiverData = $this->MessageTokenModel->getPersonData($msg->sender_id); + + if (!hasData($receiverData)) + { + show_error('no sender found'); + } + + $data = array ( + 'receivers' => $receiverData->retval, + 'message' => $msg, + 'token' => $token + ); + + $v = $this->load->view('system/messageWriteReply', $data); + } + + /** + * send reply + */ + public function sendReply() + { + $this->load->model('system/Message_model', 'MessageModel'); + $this->load->library('MessageLib'); + + $error = false; + + $subject = $this->input->post('subject'); + $body = $this->input->post('body'); + $persons = $this->input->post('persons'); + $relationmessage_id = $this->input->post('relationmessage_id'); + $token = $this->input->post('token'); + + if (!isset($relationmessage_id) || $relationmessage_id == '' || !isset($token) || $token == '') + { + show_error('Error while sending reply'); + $error = true; + } + + $relationmsg = $this->MessageTokenModel->getMessageByToken($token); + + // check if correct message + if (!hasData($relationmsg) || $relationmessage_id !== $relationmsg->retval[0]->message_id) + { + show_error('Error while sending reply'); + $error = true; + } + + // get sender (receiver of previous msg) + $sender_id = $relationmsg->retval[0]->receiver_id; + + // get message data of persons + $data = $this->MessageTokenModel->getPersonData($persons); + + // send message(s) + if (hasData($data)) + { + for ($i = 0; $i < count($data->retval); $i++) + { + $dataArray = (array)$data->retval[$i]; + + $msg = $this->messagelib->sendMessage($sender_id, $dataArray['person_id'], $subject, $body, PRIORITY_NORMAL, $relationmessage_id, null); + if ($msg->error) + { + show_error($msg->retval); + $error = true; + break; + } + + // Loads the person log library + $this->load->library('PersonLogLib'); + + // Write log entry for sender + $logtype_kurzbz = 'Action'; + $logdata = array( + 'name' => 'Message sent', + 'message' => 'Message sent from person '.$sender_id.' to '.$dataArray['person_id'].', messageid '.$msg->retval, + 'success' => 'true' + ); + $taetigkeit_kurzbz = 'kommunikation'; + $app = 'core'; + $oe_kurzbz = null; + $insertvon = 'online'; + + $this->personloglib->log( + $sender_id, + $logtype_kurzbz, + $logdata, + $taetigkeit_kurzbz, + $app, + $oe_kurzbz, + $insertvon + ); + } + } + + if (!$error) + { + echo "Messages sent successfully"; + } + } } diff --git a/application/controllers/system/Messages.php b/application/controllers/system/Messages.php index 8af20368c..ace825832 100644 --- a/application/controllers/system/Messages.php +++ b/application/controllers/system/Messages.php @@ -185,9 +185,9 @@ class Messages extends FHC_Controller { $user_person = $this->PersonModel->getByUid($this->uid); - if (isError($user_person)) + if (!hasData($user_person)) { - show_error($user_person->retval); + show_error('no sender'); } $sender_id = $user_person->retval[0]->person_id; } diff --git a/application/models/system/MessageToken_model.php b/application/models/system/MessageToken_model.php index fb7f81a0a..1f847a36f 100644 --- a/application/models/system/MessageToken_model.php +++ b/application/models/system/MessageToken_model.php @@ -31,6 +31,7 @@ class MessageToken_model extends CI_Model $sql = 'SELECT r.message_id, m.person_id as sender_id, r.person_id as receiver_id, + r.sent, m.subject, m.body, m.insertamum, @@ -174,6 +175,34 @@ class MessageToken_model extends CI_Model } } + /** + * 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()); + } + } + /** * */ diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 7289c3055..654a9a883 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -48,6 +48,7 @@ class Recipient_model extends DB_Model $sql = 'SELECT r.message_id, m.person_id as sender_id, r.person_id as receiver_id, + r.sent, m.subject, m.body, m.insertamum, diff --git a/application/views/system/messageForm.php b/application/views/system/messageForm.php new file mode 100644 index 000000000..8e48e082b --- /dev/null +++ b/application/views/system/messageForm.php @@ -0,0 +1,81 @@ +
+
+
+ +
+
+ 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/messageHTML.php b/application/views/system/messageHTML.php index 6a1d509ba..b99389188 100644 --- a/application/views/system/messageHTML.php +++ b/application/views/system/messageHTML.php @@ -42,6 +42,8 @@ if ($isEmployee === false && $href != '') { ?> +   +   Reply diff --git a/application/views/system/messageWrite.php b/application/views/system/messageWrite.php index 3f9ed5254..89c408687 100644 --- a/application/views/system/messageWrite.php +++ b/application/views/system/messageWrite.php @@ -8,24 +8,14 @@ $this->load->view( 'fontawesome' => true, 'tinymce' => true, 'sbadmintemplate' => true, - 'customCSSs' => 'public/css/sbadmin2/admintemplate_contentonly.css', - 'customJSs' => 'public/js/bootstrapper.js' + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messageWrite.css'), + 'customJSs' => array('public/js/bootstrapper.js') ) ); ?> -
@@ -36,78 +26,7 @@ $href = str_replace("/system/Messages/write", "/system/Messages/send", $_SERVER[
-
-
-
- -
-
- 1 && $i % 10 == 0) - { - echo '
'; - } - echo $receiver->Vorname." ".$receiver->Nachname."; "; - } - ?> -
-
-
-
-
-
- -
  - subject; - } - ?> -
- -
-
-
-
-
-
- - body; - } - ?> - -
- -
-
- - -
-
- -
+ load->view('system/messageForm.php'); ?>
@@ -119,9 +38,6 @@ $href = str_replace("/system/Messages/write", "/system/Messages/send", $_SERVER[ ); ?>
-
- -
0): ?>
@@ -196,18 +112,25 @@ $href = str_replace("/system/Messages/write", "/system/Messages/send", $_SERVER[ + + + +load->view("templates/FHC-Footer"); ?> diff --git a/public/css/messageWrite.css b/public/css/messageWrite.css new file mode 100644 index 000000000..d929f656c --- /dev/null +++ b/public/css/messageWrite.css @@ -0,0 +1,10 @@ +/*smaller subject field*/ +input[type=text] { + height: 28px; + padding: 0px; +} + +.msgfield label { + margin-bottom: 0px !important; + margin-top: 3px; +} \ No newline at end of file