diff --git a/application/controllers/api/v1/system/Message.php b/application/controllers/api/v1/system/Message.php index 1bcb8f96b..32f888eee 100644 --- a/application/controllers/api/v1/system/Message.php +++ b/application/controllers/api/v1/system/Message.php @@ -75,7 +75,7 @@ class Message extends APIv1_Controller if (isset($token)) { - $result = $this->messagelib->getMessagesByToken($token); + $result = $this->messagelib->getMessageByToken($token); $this->response($result, REST_Controller::HTTP_OK); } @@ -96,6 +96,7 @@ class Message extends APIv1_Controller { $result = $this->messagelib->sendMessage( $this->post()['person_id'], + $this->post()['receiver_id'], $this->post()['subject'], $this->post()['body'], PRIORITY_NORMAL, @@ -215,4 +216,4 @@ class Message extends APIv1_Controller return $this->_success('Input data are valid'); } -} \ No newline at end of file +} diff --git a/application/controllers/api/v1/system/message_old.php b/application/controllers/api/v1/system/message_old.php deleted file mode 100644 index 05f0f5555..000000000 --- a/application/controllers/api/v1/system/message_old.php +++ /dev/null @@ -1,78 +0,0 @@ -load->model('system/message_old_model', 'message_oldModel'); - - - } - - /** - * @return void - */ - public function getmessage_old() - { - $message_oldID = $this->get('message_old_id'); - - if (isset($message_oldID)) - { - $result = $this->message_oldModel->load($message_oldID); - - $this->response($result, REST_Controller::HTTP_OK); - } - else - { - $this->response(); - } - } - - /** - * @return void - */ - public function postmessage_old() - { - if ($this->_validate($this->post())) - { - if (isset($this->post()['message_old_id'])) - { - $result = $this->message_oldModel->update($this->post()['message_old_id'], $this->post()); - } - else - { - $result = $this->message_oldModel->insert($this->post()); - } - - $this->response($result, REST_Controller::HTTP_OK); - } - else - { - $this->response(); - } - } - - private function _validate($message_old = NULL) - { - return true; - } -} \ No newline at end of file diff --git a/application/controllers/system/Messages.php b/application/controllers/system/Messages.php index 37ed57323..fdce0082a 100755 --- a/application/controllers/system/Messages.php +++ b/application/controllers/system/Messages.php @@ -40,7 +40,7 @@ class Messages extends VileSci_Controller public function outbox($person_id) { - $msg = $this->messagelib->getMessagesByPerson($person_id); + $msg = $this->messagelib->getSentMessagesByPerson($person_id); if ($msg->error) { show_error($msg->retval); @@ -71,28 +71,36 @@ class Messages extends VileSci_Controller $v = $this->load->view("system/messageView", array("message" => $msg->retval[0])); } - public function write($vorlage_kurzbz = null) + public function write($msg_id, $person_id) { - $data = array - ( - "subject" => "TestSubject", - "body" => "TestDevelopmentBodyText" - ); - $v = $this->load->view("system/messageWrite", $data); + $msg = $this->messagelib->getMessage($msg_id, $person_id); + if ($msg->error) + { + show_error($msg->retval); + } + + $v = $this->load->view("system/messageWrite", array("message" => $msg->retval[0])); } - public function send() + public function send($msg_id, $person_id) { - $body = $this->input->post("body", TRUE); - $subject = $this->input->post("subject", TRUE); - if (! $this->messagelib->addRecipient(1)) - show_error("Error: AddRecipient"); - $msg = $this->messagelib->sendMessage(1,$body ,$subject); + $subject = $this->input->post("subject"); + $body = $this->input->post("body"); + + $this->load->model("system/Message_model", "MessageModel"); + $originMsg = $this->MessageModel->load($msg_id); + if ($originMsg->error) + { + show_error($originMsg->retval); + } + + $msg = $this->messagelib->sendMessage($person_id, $originMsg->retval[0]->person_id, $subject, $body, PRIORITY_NORMAL, $msg_id); if ($msg->error) + { show_error($msg->retval); - $msg_id = $msg->retval; - - redirect("/system/Message/view/".$msg_id); + } + + redirect("/system/Messages/view/" . $msg->retval . "/" . $originMsg->retval[0]->person_id); } private function getPersonId() diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index c382c1d77..f0ed4e87a 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -37,7 +37,7 @@ class MessageLib } /** - * getMessage() - returns the spicified message for a specified person + * getMessage() - returns the spicified received message for a specified person * * @param string $msg_id REQUIRED * @param string $person_id REQUIRED @@ -50,12 +50,11 @@ class MessageLib if (empty($person_id)) return $this->_error(MSG_ERR_INVALID_RECIPIENTS); - $this->ci->RecipientModel->addJoin("public.tbl_msg_message m", "message_id"); - $msg = $this->ci->RecipientModel->loadWhere(array("message_id" => $msg_id, "public.tbl_msg_recipient.person_id" => $person_id)); + $msg = $this->ci->RecipientModel->getMessage($msg_id, $person_id); return $msg; } - + /** * getMessagesByUID() - will return all messages, including the latest status for specified user. It don“t returns Attachments. * @@ -67,7 +66,7 @@ class MessageLib if (empty($uid)) return $this->_error(MSG_ERR_INVALID_MSG_ID); - $msg = $this->ci->MessageModel->getMessagesByUID($uid, $all); + $msg = $this->ci->RecipientModel->getMessagesByUID($uid, $all); return $msg; } @@ -83,23 +82,39 @@ class MessageLib if (empty($person_id)) return $this->_error(MSG_ERR_INVALID_MSG_ID); + $msg = $this->ci->RecipientModel->getMessagesByPerson($person_id, $all); + + return $msg; + } + + /** + * getSentMessagesByPerson() - Get all sent messages from a person identified by person_id + * + * @param bigint $person_id REQUIRED + * @return array + */ + public function getSentMessagesByPerson($person_id, $all = false) + { + if (empty($person_id)) + return $this->_error(MSG_ERR_INVALID_MSG_ID); + $msg = $this->ci->MessageModel->getMessagesByPerson($person_id, $all); return $msg; } /** - * getMessagesByToken + * getMessageByToken * * @param token string * @return array */ - public function getMessagesByToken($token) + public function getMessageByToken($token) { if (empty($token)) return $this->_error(MSG_ERR_INVALID_MSG_ID); - $result = $this->ci->MessageModel->getMessagesByToken($token); + $result = $this->ci->RecipientModel->getMessageByToken($token); if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0) { // Searches for a status that is different from unread @@ -179,61 +194,94 @@ class MessageLib /** * sendMessage() - sends new internal message. This function will create a new thread * - * @param integer $sender_id REQUIRED - * @param mixed $recipients REQUIRED - a single integer or an array of integers, representing user_ids - * @param string $subject - * @param string $body - * @param integer $priority - * @return array */ - public function sendMessage($sender_id, $subject = "", $body = "", $priority = PRIORITY_NORMAL, $relationmessage_id = null, $oe_kurzbz = null) + public function sendMessage($sender_id, $receiver_id, $subject, $body, $priority = PRIORITY_NORMAL, $relationmessage_id = null, $oe_kurzbz = null) { - if (!is_numeric($sender_id)) + if (!is_numeric($sender_id) || !is_numeric($receiver_id)) return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); - // Start sending Message - $this->ci->db->trans_start(false); - //save Message - $data = array( - "person_id" => $sender_id, - "subject" => $subject, - "body" => $body, - "priority" => $priority, - "relationmessage_id" => $relationmessage_id, - "oe_kurzbz" => $oe_kurzbz - ); - - $result = $this->ci->MessageModel->insert($data); - if (is_object($result) && $result->error == EXIT_SUCCESS) + // Checks if the receiver exists + $this->ci->load->model("person/Person_model", "PersonModel"); + $result = $this->ci->PersonModel->load($receiver_id); + if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0) { - /** - * @TODO: sender_id must be a receiver_id - */ - $msg_id = $result->retval; - $statusData = array( - "message_id" => $msg_id, - "person_id" => $sender_id, - "status" => MSG_STATUS_UNREAD - ); - $result = $this->ci->MsgStatusModel->insert($statusData); - } - - $this->ci->db->trans_complete(); - - if ($this->ci->db->trans_status() === false || (is_object($result) && $result->error != EXIT_SUCCESS)) - { - $this->ci->db->trans_rollback(); - return $this->_error($result->msg, EXIT_ERROR); + // If the text and the subject of the template are not empty + if (!empty($subject) && !empty($body)) + { + $this->ci->db->trans_start(false); + // Save Message + $msgData = array( + "person_id" => $sender_id, + "subject" => $subject, + "body" => $body, + "priority" => PRIORITY_NORMAL, + "relationmessage_id" => $relationmessage_id, + "oe_kurzbz" => $oe_kurzbz + ); + $result = $this->ci->MessageModel->insert($msgData); + if (is_object($result) && $result->error == EXIT_SUCCESS) + { + // Link the message with the receiver + $msg_id = $result->retval; + $recipientData = array( + "person_id" => $receiver_id, + "message_id" => $msg_id + ); + $result = $this->ci->RecipientModel->insert($recipientData); + if (is_object($result) && $result->error == EXIT_SUCCESS) + { + // Save message status + $statusData = array( + "message_id" => $msg_id, + "person_id" => $receiver_id, + "status" => MSG_STATUS_UNREAD + ); + $result = $this->ci->MsgStatusModel->insert($statusData); + + // If no errors were occurred + /** + * TODO: different config item??? + */ + /*if (is_object($result) && $result->error == EXIT_SUCCESS) + { + // If the system is configured to send messages immediately + if ($this->ci->config->item("send_immediately") === true) + { + // Send message by email! + $resultSendEmail = $this->sendOne($msg_id, $subject, $parsedText); + } + }*/ + } + } + + $this->ci->db->trans_complete(); + + if ($this->ci->db->trans_status() === false || (is_object($result) && $result->error != EXIT_SUCCESS)) + { + $this->ci->db->trans_rollback(); + return $this->_error($result->msg, EXIT_ERROR); + } + else + { + $this->ci->db->trans_commit(); + return $this->_success($msg_id); + } + } + else + { + $result = $this->_error("Subject or body empty", EXIT_ERROR); + } } else { - $this->ci->db->trans_commit(); - return $this->_success($msg_id); + $result = $this->_error("Receiver not present", EXIT_ERROR); } + + return $result; } /** - * sendMessage() - sends new internal message. This function will create a new thread + * sendMessageVorlage() - sends new internal message using a template * * @param integer $sender_id REQUIRED * @param mixed $recipients REQUIRED - a single integer or an array of integers, representing user_ids @@ -484,7 +532,7 @@ class MessageLib } /** - * One messages from DB and sends it via email + * Gets one message from DB and sends it via email */ public function sendOne($message_id, $subject = null, $body = null) { diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index 8bb73108b..8f6240e5c 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -14,60 +14,9 @@ class Message_model extends DB_Model $this->pk = "message_id"; } - public function getMessagesByUID($uid, $all) - { - // Check wrights - // @ToDo: Define the special wright for reading own messages "basis/message:own" - // if same user - if ($uid === getAuthUID()) - { - if (! $this->fhc_db_acl->isBerechtigt("basis/message", "s")) - return $this->_error(lang("fhc_".FHC_NORIGHT)." -> basis/message", FHC_MODEL_ERROR); - } - // if different user, for reading messages from other users - else - { - if (! $this->fhc_db_acl->isBerechtigt("basis/message", "s")) - return $this->_error(lang("fhc_".FHC_NORIGHT)." -> basis/message:all", FHC_MODEL_ERROR); - } - - // get Data - $sql = "SELECT b.uid, - m.person_id, - m.message_id, - m.subject, - m.body, - m.priority, - m.relationmessage_id, - m.oe_kurzbz, - m.insertamum, - p.anrede, - p.titelpost, - p.titelpre, - p.nachname, - p.vorname, - p.vornamen, - s.status, - s.statusinfo, - s.insertamum AS statusamum - FROM public.tbl_msg_recipient r JOIN public.tbl_msg_message m USING (message_id) - JOIN public.tbl_person p ON (r.person_id = p.person_id) - JOIN public.tbl_benutzer b ON (r.person_id = b.person_id) - JOIN ( - SELECT * FROM public.tbl_msg_status ORDER BY insertamum DESC LIMIT 1 - ) s ON (r.message_id = s.message_id AND r.person_id = s.person_id) - WHERE b.uid = ?"; - - if (! $all) - $sql .= " AND (status < 3 OR status IS NULL)"; - - $result = $this->db->query($sql, array($uid)); - if (is_object($result)) - return $this->_success($result->result()); - else - return $this->_error($this->db->error(), FHC_DB_ERROR); - } - + /** + * Get all sent messages from a person identified by person_id + */ public function getMessagesByPerson($person_id, $all) { // Check wrights @@ -80,7 +29,7 @@ class Message_model extends DB_Model if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_status"), "s")) return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_status"), FHC_MODEL_ERROR); - $sql = "SELECT r.message_id, + $sql = "SELECT m.message_id, m.person_id, m.subject, m.body, @@ -99,13 +48,13 @@ class Message_model extends DB_Model s.insertamum AS statusamum FROM public.tbl_msg_recipient r JOIN public.tbl_msg_message m USING (message_id) JOIN public.tbl_person p ON (p.person_id = m.person_id) - JOIN ( + LEFT JOIN ( SELECT message_id, person_id, status, statusinfo, insertamum FROM public.tbl_msg_status %s ORDER BY insertamum DESC ) s ON (m.message_id = s.message_id AND r.person_id = s.person_id) - WHERE r.person_id = ?"; + WHERE m.person_id = ?"; $parametersArray = array($person_id); @@ -115,8 +64,7 @@ class Message_model extends DB_Model } else { - array_push($parametersArray, $person_id, $person_id); - $sql = sprintf($sql, "WHERE person_id = ? AND message_id NOT IN (SELECT message_id FROM public.tbl_msg_status WHERE status >= 3 AND person_id = ?)"); + $sql = sprintf($sql, "WHERE status >= 3"); } $result = $this->db->query($sql, $parametersArray); @@ -125,40 +73,4 @@ class Message_model extends DB_Model else return $this->_error($this->db->error(), FHC_DB_ERROR); } - - public function getMessagesByToken($token) - { - // Check wrights - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_recipient"), "s")) - return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_recipient"), FHC_MODEL_ERROR); - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_message"), "s")) - return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_message"), FHC_MODEL_ERROR); - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_status"), "s")) - return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_status"), FHC_MODEL_ERROR); - - $sql = "SELECT r.message_id, - r.person_id as receiver_id, - m.person_id as sender_id, - m.subject, - m.body, - m.insertamum, - m.relationmessage_id, - m.oe_kurzbz, - s.status, - s.statusinfo, - s.insertamum as statusamum - FROM public.tbl_msg_recipient r JOIN public.tbl_msg_message m USING (message_id) - JOIN ( - SELECT * FROM public.tbl_msg_status ORDER BY insertamum DESC LIMIT 1 - ) s ON (r.message_id = s.message_id AND r.person_id = s.person_id) - WHERE r.token = ? - AND status < ? - ORDER BY s.insertamum DESC"; - - $result = $this->db->query($sql, array($token, MSG_STATUS_DELETED)); - if (is_object($result)) - return $this->_success($result->result()); - else - return $this->_error($this->db->error(), FHC_DB_ERROR); - } } diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 136156cde..282b7aa42 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -1,18 +1,216 @@ dbTable = 'public.tbl_msg_recipient'; - $this->pk = array('person_id', 'message_id'); + $this->dbTable = "public.tbl_msg_recipient"; + $this->pk = array("person_id", "message_id"); $this->hasSequence = false; } + /** + * Get data for a received message + */ + public function getMessage($message_id, $person_id) + { + // Check rights + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_recipient"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_recipient"), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_message"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_message"), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_person"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_person"), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_kontakt"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_kontakt"), FHC_MODEL_ERROR); + + $query = "SELECT mr.message_id, + mr.person_id, + mm.subject, + mm.body, + ks.kontakt, + p.nachname, + p.vorname, + b.uid + FROM public.tbl_msg_recipient mr INNER JOIN public.tbl_msg_message mm USING (message_id) + INNER JOIN public.tbl_person p ON (mr.person_id = p.person_id) + LEFT JOIN public.tbl_benutzer b ON (mr.person_id = b.person_id) + LEFT JOIN ( + SELECT person_id, kontakt FROM public.tbl_kontakt WHERE kontakttyp = 'email' + ) ks ON (ks.person_id = mr.person_id) + WHERE mr.message_id = ? AND mr.person_id = ?"; + + $parametersArray = array($message_id, $person_id); + + // Get data of the messages to sent + $result = $this->db->query($query, $parametersArray); + if (is_object($result)) + return $this->_success($result->result()); + else + return $this->_error($this->db->error(), FHC_DB_ERROR); + } + + /** + * Get a received message identified by token + */ + public function getMessageByToken($token) + { + // Check wrights + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_recipient"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_recipient"), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_message"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_message"), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_status"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_status"), FHC_MODEL_ERROR); + + $sql = "SELECT r.message_id, + r.person_id as receiver_id, + m.person_id as sender_id, + m.subject, + m.body, + m.insertamum, + m.relationmessage_id, + m.oe_kurzbz, + s.status, + s.statusinfo, + s.insertamum as statusamum + FROM public.tbl_msg_recipient r JOIN public.tbl_msg_message m USING (message_id) + JOIN ( + SELECT * FROM public.tbl_msg_status ORDER BY insertamum DESC LIMIT 1 + ) s ON (r.message_id = s.message_id AND r.person_id = s.person_id) + WHERE r.token = ? + AND status < ? + ORDER BY s.insertamum DESC"; + + $result = $this->db->query($sql, array($token, MSG_STATUS_DELETED)); + if (is_object($result)) + return $this->_success($result->result()); + else + return $this->_error($this->db->error(), FHC_DB_ERROR); + } + + /** + * Get all received messages for a person identified by person_id + */ + public function getMessagesByPerson($person_id, $all) + { + // Check wrights + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_recipient"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_recipient"), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_message"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_message"), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_person"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_person"), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_status"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_status"), FHC_MODEL_ERROR); + + $sql = "SELECT r.message_id, + m.person_id, + m.subject, + m.body, + m.priority, + m.insertamum, + m.relationmessage_id, + m.oe_kurzbz, + p.anrede, + p.titelpost, + p.titelpre, + p.nachname, + p.vorname, + p.vornamen, + s.status, + s.statusinfo, + s.insertamum AS statusamum + FROM public.tbl_msg_recipient r JOIN public.tbl_msg_message m USING (message_id) + JOIN public.tbl_person p ON (p.person_id = m.person_id) + JOIN ( + SELECT message_id, person_id, status, statusinfo, insertamum + FROM public.tbl_msg_status + %s + ORDER BY insertamum DESC + ) s ON (m.message_id = s.message_id AND r.person_id = s.person_id) + WHERE r.person_id = ?"; + + $parametersArray = array($person_id); + + if ($all == "true") + { + $sql = sprintf($sql, ""); + } + else + { + array_push($parametersArray, $person_id, $person_id); + $sql = sprintf($sql, "WHERE person_id = ? AND message_id NOT IN (SELECT message_id FROM public.tbl_msg_status WHERE status >= 3 AND person_id = ?)"); + } + + $result = $this->db->query($sql, $parametersArray); + if (is_object($result)) + return $this->_success($result->result()); + else + return $this->_error($this->db->error(), FHC_DB_ERROR); + } + + /** + * Get all received messages for a person identified by uid + */ + public function getMessagesByUID($uid, $all) + { + // Check wrights + // @ToDo: Define the special wright for reading own messages "basis/message:own" + // if same user + if ($uid === getAuthUID()) + { + if (! $this->fhc_db_acl->isBerechtigt("basis/message", "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> basis/message", FHC_MODEL_ERROR); + } + // if different user, for reading messages from other users + else + { + if (! $this->fhc_db_acl->isBerechtigt("basis/message", "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> basis/message:all", FHC_MODEL_ERROR); + } + + // get Data + $sql = "SELECT b.uid, + m.person_id, + m.message_id, + m.subject, + m.body, + m.priority, + m.relationmessage_id, + m.oe_kurzbz, + m.insertamum, + p.anrede, + p.titelpost, + p.titelpre, + p.nachname, + p.vorname, + p.vornamen, + s.status, + s.statusinfo, + s.insertamum AS statusamum + FROM public.tbl_msg_recipient r JOIN public.tbl_msg_message m USING (message_id) + JOIN public.tbl_person p ON (r.person_id = p.person_id) + JOIN public.tbl_benutzer b ON (r.person_id = b.person_id) + JOIN ( + SELECT * FROM public.tbl_msg_status ORDER BY insertamum DESC LIMIT 1 + ) s ON (r.message_id = s.message_id AND r.person_id = s.person_id) + WHERE b.uid = ?"; + + if (! $all) + $sql .= " AND (status < 3 OR status IS NULL)"; + + $result = $this->db->query($sql, array($uid)); + if (is_object($result)) + return $this->_success($result->result()); + else + return $this->_error($this->db->error(), FHC_DB_ERROR); + } + /** * getMessages * diff --git a/application/views/system/messageView.php b/application/views/system/messageView.php index 37bdc1341..ae1f9b74e 100644 --- a/application/views/system/messageView.php +++ b/application/views/system/messageView.php @@ -1,14 +1,34 @@ +load->view('templates/header'); ?> + -