diff --git a/application/controllers/system/Messages.php b/application/controllers/system/Messages.php index 4c203e478..c61fd5e75 100755 --- a/application/controllers/system/Messages.php +++ b/application/controllers/system/Messages.php @@ -1,34 +1,43 @@ load->library('messaging'); + $this->load->library('MessageLib'); //$this->load->model('person/Person_model'); //$this->load->model('system/Message_model'); } public function index() { - //$messages = $this->Message_model->getMessages(); - $msg = $this->Message_model->load(1); + $this->load->view('system/messages.php'); + } + + public function table() + { + $person_id = $this->input->post('person_id', TRUE); + if ($person_id) + $msg = $this->messagelib->getMessagesByPerson($person_id); + else + $msg = $this->messagelib->getMessagesByUID($this->getUID()); if ($msg->error) show_error($msg->retval); $data = array ( - 'message' => $msg->retval[0] + 'messages' => $msg->retval ); - $v = $this->load->view('message.php', $data); + var_dump ($data); + $this->load->view('system/messagesList.php', $data); } public function view($msg_id) { - $msg = $this->messaging->getMessage($msg_id); + $msg = $this->messagelib->getMessage($msg_id); //var_dump($msg); if ($msg->error) show_error($msg->retval); @@ -57,9 +66,9 @@ class Messages extends FHC_Controller { $body = $this->input->post('body', TRUE); $subject = $this->input->post('subject', TRUE); - if (! $this->messaging->addRecipient(1)) + if (! $this->messagelib->addRecipient(1)) show_error('Error: AddRecipient'); - $msg = $this->messaging->sendMessage(1,$body ,$subject); + $msg = $this->messagelib->sendMessage(1,$body ,$subject); if ($msg->error) show_error($msg->retval); $msg_id = $msg->retval; diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php index f0e224914..4e5f2474d 100644 --- a/application/core/DB_Model.php +++ b/application/core/DB_Model.php @@ -2,11 +2,11 @@ class DB_Model extends FHC_Model { - protected $dbTable; // Name of the DB-Table for CI-Insert, -Update, ... - protected $pk; // Name of the PrimaryKey for DB-Update, Load, ... + protected $dbTable; // Name of the DB-Table for CI-Insert, -Update, ... + protected $pk; // Name of the PrimaryKey for DB-Update, Load, ... protected $hasSequence; // False if this table has a composite primary key that is not using a sequence // True if this table has a primary key that uses a sequence - protected $acl; // Name of the PrimaryKey for DB-Update, Load, ... + protected $acl; // Name of the PrimaryKey for DB-Update, Load, ... function __construct($dbTable = null, $pk = null, $hasSequence = true) { diff --git a/application/core/FHC_Controller.php b/application/core/FHC_Controller.php index 7921455cb..d04ed2a0b 100644 --- a/application/core/FHC_Controller.php +++ b/application/core/FHC_Controller.php @@ -3,19 +3,22 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); class FHC_Controller extends CI_Controller { - public $uid; + protected $_uid; // needs to be changed to protected $_uid - function __construct() + public function __construct() { parent::__construct(); $this->load->library('session'); - //$this->load->helper('language'); + $this->load->helper('fhcauth'); - // look if User is logged in and set uid - if (isset($_SERVER['PHP_AUTH_USER'])) - $this->uid = $_SERVER['PHP_AUTH_USER']; - if (isset($_SESSION['uid'])) - $this->uid = $_SESSION['uid']; - $this->session->set_userdata('uid', 'pam'); + $this->_uid = getAuthUID(); + } + + public function getUID() + { + if (empty($this->_uid)) + return false; + else + return $this->_uid; } } diff --git a/application/core/FHC_Model.php b/application/core/FHC_Model.php index 485678c94..13457057f 100644 --- a/application/core/FHC_Model.php +++ b/application/core/FHC_Model.php @@ -40,6 +40,16 @@ class FHC_Model extends CI_Model { return $this->fhc_db_acl->setUID($uid); } + + /** --------------------------------------------------------------- + * get UID + * + * @return string or (bool)false + */ + public function getUID() + { + return $this->fhc_db_acl->getUID(); + } /** --------------------------------------------------------------- * Success @@ -61,4 +71,4 @@ class FHC_Model extends CI_Model { return error($retval, $message); } -} \ No newline at end of file +} diff --git a/application/helpers/fhcauth_helper.php b/application/helpers/fhcauth_helper.php index 1a904ee55..7a5f782b0 100644 --- a/application/helpers/fhcauth_helper.php +++ b/application/helpers/fhcauth_helper.php @@ -48,4 +48,20 @@ if ( ! function_exists('auth')) return false; } } + + /** + * Look if User is logged in and return uid + * Otherwise return false + * + * @return string or (bool)false + */ + function getAuthUID() + { + // look if User is logged in and return uid + if (isset($_SERVER['PHP_AUTH_USER'])) + return $_SERVER['PHP_AUTH_USER']; + if (isset($_SESSION['uid'])) + return $_SESSION['uid']; + return false; + } } diff --git a/application/libraries/FHC_DB_ACL.php b/application/libraries/FHC_DB_ACL.php index 702b193e7..0c88af34d 100644 --- a/application/libraries/FHC_DB_ACL.php +++ b/application/libraries/FHC_DB_ACL.php @@ -68,4 +68,14 @@ class FHC_DB_ACL { return $this->_uid = $uid; } + + /** --------------------------------------------------------------- + * get UID + * + * @return string or (bool)false + */ + public function getUID() + { + return $this->_uid; + } } diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index fa280938a..2bb04ff2f 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -53,6 +53,40 @@ class MessageLib return $msg; } + /** + * getMessagesByUID() - will return all messages, including the latest status for specified user. It don´t returns Attachments. + * + * @param string $uid REQUIRED + * @return array + */ + function getMessagesByUID($uid, $all = false) + { + if (empty($uid)) + return $this->_error(MSG_ERR_INVALID_MSG_ID); + + $msg = $this->ci->MessageModel->getMessagesByUID($uid, $all); + + // General Error Occurred + return $msg; + } + + /** + * getMessagesByPerson() - will return all messages, including the latest status for specified user. It don´t returns Attachments. + * + * @param bigint $person_id REQUIRED + * @return array + */ + function getMessagesByPerson($person_id, $all = false) + { + if (empty($person_id)) + return $this->_error(MSG_ERR_INVALID_MSG_ID); + + $msg = $this->ci->MessageModel->getMessagesByPerson($person_id, $all); + + // General Error Occurred + return $msg; + } + // ------------------------------------------------------------------------ /** @@ -66,8 +100,7 @@ class MessageLib if (!is_numeric($msg_id)) return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); - $msg = $this->getMessage($msg_id); - return $msg; + return $this->getMessage($msg_id); } // ------------------------------------------------------------------------ diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index 0523789db..4412c4078 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -16,5 +16,86 @@ 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 === $this->getUID()) + { + if (! $this->fhc_db_acl->isBerechtigt('basis/message', 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> system/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).' -> system/message:all', FHC_MODEL_ERROR); + } + + // get Data + $sql = 'SELECT uid, person_id, message_id, subject, priority, relationmessage_id, oe_kurzbz, m.insertamum, anrede, titelpost, titelpre, nachname, vorname, vornamen, +status, statusinfo, s.insertamum AS statusamum +FROM public.tbl_msg_message m +JOIN public.tbl_person USING (person_id) +JOIN public.tbl_benutzer USING (person_id) +LEFT JOIN +( + SELECT message_id, person_id, status, statusinfo, tbl_msg_status.insertamum + FROM public.tbl_msg_status + INNER JOIN + ( + SELECT message_id, person_id, max(insertamum) AS insertamum + FROM public.tbl_msg_status + GROUP BY message_id, person_id + ) status + USING (message_id, person_id) + WHERE tbl_msg_status.insertamum=status.insertamum +) s +USING (message_id, person_id) +WHERE uid = ?'; + if (! $all) + $sql .= ' AND status<2'; + $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); + } + +public function getMessagesByPerson($person_id, $all) + { + // Check wrights + if (! $this->fhc_db_acl->isBerechtigt('basis/message', 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> system/message', FHC_MODEL_ERROR); + + // get Data + $sql = 'SELECT person_id, message_id, subject, priority, relationmessage_id, oe_kurzbz, m.insertamum, anrede, titelpost, titelpre, nachname, vorname, vornamen, +status, statusinfo, s.insertamum AS statusamum +FROM public.tbl_msg_message m +JOIN public.tbl_person USING (person_id) +LEFT JOIN +( + SELECT message_id, person_id, status, statusinfo, tbl_msg_status.insertamum + FROM public.tbl_msg_status + INNER JOIN + ( + SELECT message_id, person_id, max(insertamum) AS insertamum + FROM public.tbl_msg_status + GROUP BY message_id, person_id + ) status + USING (message_id, person_id) + WHERE tbl_msg_status.insertamum=status.insertamum +) s +USING (message_id, person_id) +WHERE person_id = ?'; + if (! $all) + $sql .= ' AND status<2'; + $result = $this->db->query($sql, array($person_id)); + var_dump($result); + if (is_object($result)) + return $this->_success($result->result()); + else + return $this->_error($this->db->error(), FHC_DB_ERROR); + } } -/* end of file Message_model.php */ diff --git a/application/views/system/messages.php b/application/views/system/messages.php index 9e76a00b0..dd194c9f9 100644 --- a/application/views/system/messages.php +++ b/application/views/system/messages.php @@ -1,22 +1,20 @@ - -
| Vorlage | +Bezeichnung | +Anmerkung | MimeType | ++ |
|---|---|---|---|---|
| vorlage_kurzbz; ?> | +bezeichnung; ?> | +anmerkung; ?> | +mimetype; ?> | +View | +