diff --git a/application/controllers/system/Messages.php b/application/controllers/system/Messages.php index 191af6623..37ed57323 100755 --- a/application/controllers/system/Messages.php +++ b/application/controllers/system/Messages.php @@ -1,110 +1,118 @@ load->library('MessageLib'); - $this->load->model('person/Person_model', 'PersonModel'); + $this->load->library("MessageLib"); + $this->load->model("person/Person_model", "PersonModel"); } - public function index($person_id = null) + public function index() { - $data = array('person_id' => $person_id); - $this->load->view('system/messages.php', $data); + $this->load->view("system/messages.php", array("person_id" => $this->getPersonId())); } - public function inbox($person_id = null) + public function inbox($person_id) { - if (empty($person_id)) - $person_id = $this->input->post('person_id', TRUE); - if (empty($person_id)) - $msg = $this->messagelib->getMessagesByUID(getAuthUID()); - else - $msg = $this->messagelib->getMessagesByPerson($person_id); + $msg = $this->messagelib->getMessagesByPerson($person_id); if ($msg->error) - show_error($msg->retval); - - $data = array - ( - 'uid' => getAuthUID(), - 'messages' => $msg->retval - ); - if (!empty($person_id)) { - $person = $this->PersonModel->load($person_id); - $data['person'] = $person->retval[0]; + show_error($msg->retval); } - // var_dump ($data); - $this->load->view('system/messagesInbox.php', $data); + + $person = $this->PersonModel->load($person_id); + if ($person->error) + { + show_error($person->retval); + } + + $data = array ( + "messages" => $msg->retval, + "person" => $person->retval[0] + ); + + $this->load->view("system/messagesInbox.php", $data); } - public function outbox($person_id = null) + public function outbox($person_id) { - if (empty($person_id)) - $person_id = $this->input->post('person_id', TRUE); - if (empty($person_id)) - $msg = $this->messagelib->getMessagesByUID(getAuthUID()); - else - $msg = $this->messagelib->getMessagesByPerson($person_id); + $msg = $this->messagelib->getMessagesByPerson($person_id); if ($msg->error) - show_error($msg->retval); - - $data = array - ( - 'uid' => getAuthUID(), - 'messages' => $msg->retval - ); - if (!empty($person_id)) { - $person = $this->PersonModel->load($person_id); - $data['person'] = $person->retval[0]; + show_error($msg->retval); } - //var_dump ($data); - $this->load->view('system/messagesOutbox.php', $data); + + $person = $this->PersonModel->load($person_id); + if ($person->error) + { + show_error($person->retval); + } + + $data = array ( + "messages" => $msg->retval, + "person" => $person->retval[0] + ); + + $this->load->view("system/messagesOutbox.php", $data); } - public function view($msg_id) + public function view($msg_id, $person_id) { - $msg = $this->messagelib->getMessage($msg_id); - //var_dump($msg); + $msg = $this->messagelib->getMessage($msg_id, $person_id); if ($msg->error) + { show_error($msg->retval); - if (count($msg->retval) != 1) - show_error('Nachricht nicht vorhanden! ID: '.$msg_id); - - $data = array - ( - 'message' => $msg->retval[0] - ); - //var_dump($data['message']); - $v = $this->load->view('system/messageView', $data); + } + + $v = $this->load->view("system/messageView", array("message" => $msg->retval[0])); } public function write($vorlage_kurzbz = null) { $data = array ( - 'subject' => 'TestSubject', - 'body' => 'TestDevelopmentBodyText' + "subject" => "TestSubject", + "body" => "TestDevelopmentBodyText" ); - $v = $this->load->view('system/messageWrite', $data); + $v = $this->load->view("system/messageWrite", $data); } public function send() { - $body = $this->input->post('body', TRUE); - $subject = $this->input->post('subject', TRUE); + $body = $this->input->post("body", TRUE); + $subject = $this->input->post("subject", TRUE); if (! $this->messagelib->addRecipient(1)) - show_error('Error: AddRecipient'); + show_error("Error: AddRecipient"); $msg = $this->messagelib->sendMessage(1,$body ,$subject); if ($msg->error) show_error($msg->retval); $msg_id = $msg->retval; - redirect('/system/Message/view/'.$msg_id); + redirect("/system/Message/view/".$msg_id); + } + + private function getPersonId() + { + $person_id = null; + + if ($this->input->get("person_id") !== null) + { + $person_id = $this->input->get("person_id"); + } + else if ($this->input->post("person_id") !== null) + { + $person_id = $this->input->get("person_id"); + } + + if (!is_numeric($person_id)) + { + show_error("Person_id is not numeric"); + } + + return $person_id; } } diff --git a/application/core/VileSci_Controller.php b/application/core/VileSci_Controller.php index f3dcd1aee..4eaa733a1 100644 --- a/application/core/VileSci_Controller.php +++ b/application/core/VileSci_Controller.php @@ -1,13 +1,11 @@ getUID() && strncmp(uri_string(), 'system/Login', 11) !== 0) - redirect(site_url('system/Login/'.uri_string()));*/ } - } diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 3e239b1a5..c382c1d77 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -35,6 +35,26 @@ class MessageLib //$this->ci->load->helper('language'); $this->ci->lang->load("message"); } + + /** + * getMessage() - returns the spicified message for a specified person + * + * @param string $msg_id REQUIRED + * @param string $person_id REQUIRED + * @return object + */ + public function getMessage($msg_id, $person_id) + { + if (empty($msg_id)) + return $this->_error(MSG_ERR_INVALID_MSG_ID); + 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)); + + return $msg; + } /** * getMessagesByUID() - will return all messages, including the latest status for specified user. It don´t returns Attachments. @@ -63,8 +83,8 @@ class MessageLib if (empty($person_id)) return $this->_error(MSG_ERR_INVALID_MSG_ID); - $msg = $this->ci->MessageModel->getMessagesByPerson($person_id, $all); - + $msg = $this->ci->MessageModel->getMessagesByPerson($person_id, $all); + return $msg; } diff --git a/application/migrations/008_message.php b/application/migrations/008_message.php index 5f3e65f33..3d102aa6b 100644 --- a/application/migrations/008_message.php +++ b/application/migrations/008_message.php @@ -100,11 +100,11 @@ class Migration_Message extends MigrationLib // Create table public.tbl_msg_recipient $fields = array( - "person_id" => array( + "message_id" => array( "type" => "bigint", "null" => false ), - "message_id" => array( + "person_id" => array( "type" => "bigint", "null" => false ), @@ -291,4 +291,4 @@ class Migration_Message extends MigrationLib $this->endDown(); } -} \ No newline at end of file +} diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index 966927d34..8bb73108b 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -84,9 +84,16 @@ class Message_model extends DB_Model 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 @@ -154,4 +161,4 @@ class Message_model extends DB_Model else return $this->_error($this->db->error(), FHC_DB_ERROR); } -} \ No newline at end of file +} diff --git a/application/views/system/messageView.php b/application/views/system/messageView.php index e6275752f..37bdc1341 100644 --- a/application/views/system/messageView.php +++ b/application/views/system/messageView.php @@ -1,14 +1,14 @@ +
| MessageID | -Sender | -Erstellt | -Priorität | -Status | -StatusInfo | -OE | -Relation | -- |
|---|---|---|---|---|---|---|---|---|
| message_id; ?> | -titelpost.' '.$m->vorname.' '.$m->nachname.' '.$m->titelpre; ?> | -insertamum; ?> | -priority; ?> | -status; ?> | -statusinfo; ?> | -oe_kurzbz; ?> | -relationmessage_id; ?> | -View | -