diff --git a/application/config/autoload.php b/application/config/autoload.php index 6bbcbf33b..c40606b70 100755 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -60,7 +60,7 @@ $autoload['packages'] = array(); */ //$autoload['libraries'] = array(); -$autoload['libraries'] = array('Session', 'FHC_Auth'); +$autoload['libraries'] = array('Session', 'FHC_Auth', 'TemplateLib'); /* | ------------------------------------------------------------------- diff --git a/application/controllers/system/Messages.php b/application/controllers/system/Messages.php new file mode 100755 index 000000000..4c203e478 --- /dev/null +++ b/application/controllers/system/Messages.php @@ -0,0 +1,69 @@ +load->library('messaging'); + //$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); + if ($msg->error) + show_error($msg->retval); + + $data = array + ( + 'message' => $msg->retval[0] + ); + $v = $this->load->view('message.php', $data); + } + + public function view($msg_id) + { + $msg = $this->messaging->getMessage($msg_id); + //var_dump($msg); + 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); + } + + public function write($vorlage_kurzbz = null) + { + $data = array + ( + 'subject' => 'TestSubject', + 'body' => 'TestDevelopmentBodyText' + ); + $v = $this->load->view('system/messageWrite', $data); + } + + public function send() + { + $body = $this->input->post('body', TRUE); + $subject = $this->input->post('subject', TRUE); + if (! $this->messaging->addRecipient(1)) + show_error('Error: AddRecipient'); + $msg = $this->messaging->sendMessage(1,$body ,$subject); + if ($msg->error) + show_error($msg->retval); + $msg_id = $msg->retval; + + redirect('/system/Message/view/'.$msg_id); + } +} diff --git a/application/controllers/system/Templates.php b/application/controllers/system/Templates.php new file mode 100755 index 000000000..8914763b0 --- /dev/null +++ b/application/controllers/system/Templates.php @@ -0,0 +1,80 @@ +load->library('VorlageLib'); + } + + public function index() + { + $this->load->view('system/templates.php'); + } + + public function table() + { + $mimetype = $this->input->post('mimetype', TRUE); + if (is_null($mimetype)) + $mimetype = 'text/html'; + if ($mimetype == '') + $mimetype = null; + $vorlage = $this->vorlagelib->getVorlageByMimetype($mimetype); + if ($vorlage->error) + show_error($vorlage->retval); + //var_dump($vorlage); + + $data = array + ( + 'mimetype' => $mimetype, + 'vorlage' => $vorlage->retval + ); + $v = $this->load->view('system/templatesList.php', $data); + } + + public function edit($vorlage_kurzbz = null) + { + if (empty($vorlage_kurzbz)) + exit; + $vorlage = $this->vorlagelib->getVorlage($vorlage_kurzbz); + //var_dump($vorlage); + if ($vorlage->error) + show_error($vorlage->retval); + if (count($vorlage->retval) != 1) + show_error('Nachricht nicht vorhanden! ID: '.$vorlage_kurzbz); + + $data = array + ( + 'vorlage' => $vorlage->retval[0] + ); + //var_dump($data['message']); + $v = $this->load->view('system/templatesEdit', $data); + } + + public function write($vorlage_kurzbz = null) + { + $data = array + ( + 'subject' => 'TestSubject', + 'body' => 'TestDevelopmentBodyText' + ); + $v = $this->load->view('system/messageWrite', $data); + } + + public function save() + { + $vorlage_kurzbz = $this->input->post('vorlage_kurzbz', TRUE); + $data['bezeichnung'] = $this->input->post('bezeichnung', TRUE); + $data['anmerkung'] = $this->input->post('anmerkung', TRUE); + $data['mimetype'] = $this->input->post('mimetype', TRUE); + $vorlage = $this->vorlagelib->saveVorlage($vorlage_kurzbz, $data); + if ($vorlage->error) + show_error($vorlage->retval); + $vorlage_kurzbz = $vorlage->retval; + + redirect('/system/Templates/edit/'.$vorlage_kurzbz); + } +} diff --git a/application/core/FHC_Controller.php b/application/core/FHC_Controller.php index ad29804c6..7921455cb 100644 --- a/application/core/FHC_Controller.php +++ b/application/core/FHC_Controller.php @@ -8,7 +8,6 @@ class FHC_Controller extends CI_Controller function __construct() { parent::__construct(); - $this->load->library('template'); $this->load->library('session'); //$this->load->helper('language'); diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php new file mode 100644 index 000000000..fa280938a --- /dev/null +++ b/application/libraries/MessageLib.php @@ -0,0 +1,311 @@ +ci =& get_instance(); + //$this->ci->load->model('person/Person_model', 'PersonModel'); + $this->ci->load->model('system/Message_model', 'MessageModel'); + $this->ci->load->model('system/MsgStatus_model', 'MsgStatusModel'); + $this->ci->load->model('system/Recipient_model', 'RecipientModel'); + $this->ci->load->model('system/Attachment_model', 'AttachmentModel'); + $this->ci->load->helper('language'); + $this->ci->lang->load('message'); + } + + // ------------------------------------------------------------------------ + + /** + * get_message() - will return a single message, including the status for specified user. + * + * @param integer $msg_id REQUIRED + * @return array + */ + function getMessage($msg_id) + { + if (!is_numeric($msg_id)) + return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); + + $this->ci->MessageModel->addJoin('public.tbl_person', 'person_id'); + $msg = $this->ci->MessageModel->loadWhere(array('message_id' => $msg_id)); + //$msg = $this->ci->MessageModel->getMessage($msg_id); + $stat = $this->ci->MsgStatusModel->loadWhere(array('message_id' => $msg_id)); + $msg->retval[0]->stat = $stat->retval; + $recp = $this->ci->RecipientModel->loadWhere(array('message_id' => $msg_id)); + $msg->retval[0]->recp = $recp->retval; + $attm = $this->ci->AttachmentModel->loadWhere(array('message_id' => $msg_id)); + $msg->retval[0]->attm = $attm->retval; + + + // General Error Occurred + return $msg; + } + + // ------------------------------------------------------------------------ + + /** + * getSubMessages() - will return all Messages subordinated from a specified message. + * + * @param integer $msg_id REQUIRED + * @return array + */ + function getSubMessages($msg_id) + { + if (!is_numeric($msg_id)) + return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); + + $msg = $this->getMessage($msg_id); + return $msg; + } + + // ------------------------------------------------------------------------ + + + // ------------------------------------------------------------------------ + + /** + * updateMessageStatus() - will change status on message for particular user + * + * @param integer $msg_id REQUIRED + * @param integer $user_id REQUIRED + * @param integer $status_id REQUIRED - should come from config/message.php list of constants + * @return array + */ + function updateMessageStatus($msg_id, $user_id, $status_id ) + { + if (empty($msg_id)) + { + return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); + } + + if (empty($user_id)) + { + return $this->_invalid_id(MSG_ERR_INVALID_USER_ID); + } + + if (empty($status_id)) + { + return $this->_invalid_id(MSG_ERR_INVALID_STATUS_ID); + } + + if ($this->ci->message_model->update_message_status($msg_id, $user_id, $status_id)) + { + return $this->_success(NULL, MSG_STATUS_UPDATE); + } + + // General Error Occurred + return $this->_general_error(); + + } + + // ------------------------------------------------------------------------ + + /** + * add_participant() - adds user to existing thread + * + * @param integer $thread_id REQUIRED + * @param integer $user_id REQUIRED + * @return array + */ + function addRecipient($person_id) + { + if (!is_numeric($person_id)) + return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); + + $this->recipients[] = $person_id; + + return true; + } + + + + // ------------------------------------------------------------------------ + + /** + * 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 + */ + function sendMessage($sender_id, $subject = '', $body = '', $priority = PRIORITY_NORMAL, $relationmessage_id = null, $oe_kurzbz = null) + { + if (!is_numeric($sender_id)) + return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); + + if (empty($this->recipients)) + return $this->_error('No Recipients! Use addRecipient()', MSG_ERR_INVALID_RECIPIENTS); + + // 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); + if (! $msg = $this->ci->MessageModel->insert($data)) + return $this->_error($msg->msg.$msg->retval, MSG_ERR_GENERAL); + $msg_id = $msg->retval; + $this->ci->db->trans_complete(); + if ($this->ci->db->trans_status() === FALSE) + { + // generate an error... or use the log_message() function to log your error + // General Error Occurred + return $this->_error(); + } + else + return $this->_success($msg_id); + + } + + // ------------------------------------------------------------------------ + + /** + * reply_to_message() - replies to internal message. This function will NOT create a new thread or participant list + * + * @param integer $msg_id REQUIRED + * @param integer $sender_id REQUIRED + * @param string $subject + * @param string $body + * @param integer $priority + * @return array + */ + function reply_to_message($msg_id, $sender_id, $subject = '', $body = '', $priority = PRIORITY_NORMAL) + { + if (empty($sender_id)) + { + return $this->_invalid_id(MSG_ERR_INVALID_SENDER_ID); + } + + if (empty($msg_id)) + { + return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); + } + + if ($new_msg_id = $this->ci->message_model->reply_to_message($msg_id, $sender_id, $body, $priority)) + { + return $this->_success($new_msg_id, MSG_MESSAGE_SENT); + } + + // General Error Occurred + return $this->_general_error(); + } + + // ------------------------------------------------------------------------ + + /** + * get_participant_list() - returns list of participants on given thread. If sender_id set, sender_id will be left off list + * + * @param integer $thread_id REQUIRED + * @param integer $sender_id REQUIRED + * @return array + */ + function get_participant_list($thread_id, $sender_id = 0) + { + if (empty($thread_id)) + { + return $this->_invalid_id(MSG_ERR_INVALID_THREAD_ID); + } + + if ($participants = $this->ci->message_model-> get_participant_list($thread_id, $sender_id)) + { + return $this->_success($participants); + } + + // General Error Occurred + return $this->_general_error(); + } + + // ------------------------------------------------------------------------ + + /** + * get_msg_count() - returns integer with count of message for user, by status. defaults to new messages + * + * @param integer $user_id REQUIRED + * @param integer $status_id OPTIONAL - defaults to "Unread" + * @return array + */ + function get_msg_count($user_id, $status_id = MSG_STATUS_UNREAD) + { + if (empty($user_id)) + { + return $this->_invalid_id(MSG_ERR_INVALID_USER_ID); + } + + if (is_numeric($message = $this->ci->message_model->get_msg_count($user_id, $status_id))) + { + return $this->_success($message); + } + + // General Error Occurred + return $this->_general_error(); + } + + // ------------------------------------------------------------------------ + // Private Functions from here out! + // ------------------------------------------------------------------------ + + /** --------------------------------------------------------------- + * Success + * + * @param mixed $retval + * @return array + */ + protected function _success($retval, $message = MSG_SUCCESS) + { + $return = new stdClass(); + $return->error = EXIT_SUCCESS; + $return->Code = $message; + $return->msg = lang('message_' . $message); + $return->retval = $retval; + return $return; + } + + /** --------------------------------------------------------------- + * General Error + * + * @return array + */ + protected function _error($retval = '', $message = MSG_ERROR_GENERAL) + { + $return = new stdClass(); + $return->error = EXIT_ERROR; + $return->Code = $message; + $return->msg = lang('message_' . $message); + $return->retval = $retval; + return $return; + } + /** + * Invalid ID + * + * @param integer config.php error code numbers + * @return array + */ + private function _invalid_id($error = '') + { + return array( + 'err' => 1, + 'code' => $error, + 'msg' => lang('message_'.$error) + ); + } +} diff --git a/application/libraries/PermissionLib.php b/application/libraries/PermissionLib.php new file mode 100644 index 000000000..faa6dde26 --- /dev/null +++ b/application/libraries/PermissionLib.php @@ -0,0 +1,78 @@ +_uid = $param['uid']; + } + + function isBerechtigt($berechtigung_kurzbz, $art=null, $oe_kurzbz=null, $kostenstelle_id=null) + { + $this->bb->getBerechtigungen($this->_uid); + return $this->bb->isBerechtigt($berechtigung_kurzbz, $oe_kurzbz=null, $art=null, $kostenstelle_id=null); + } + + function getPermissions($uid) + { + } + + function isEntitled($berechtigung_kurzbz, $oe_kurzbz=null, $art=null, $kostenstelle_id=null) + { + } + + /** --------------------------------------------------------------- + * Set UID + * + * @param string $uid + * @return bool + */ + public function setUID($uid) + { + return $this->_uid = $uid; + } +} diff --git a/application/libraries/Rdf.php b/application/libraries/RdfLib.php similarity index 92% rename from application/libraries/Rdf.php rename to application/libraries/RdfLib.php index 76e200fc3..f45411e88 100644 --- a/application/libraries/Rdf.php +++ b/application/libraries/RdfLib.php @@ -11,7 +11,7 @@ */ require_once APPPATH."../vendor/easyrdf/easyrdf/lib/EasyRdf.php"; -class Rdf +class RdfLib { diff --git a/application/libraries/Template.php b/application/libraries/TemplateLib.php similarity index 96% rename from application/libraries/Template.php rename to application/libraries/TemplateLib.php index 3f90cef91..6cc001f1f 100644 --- a/application/libraries/Template.php +++ b/application/libraries/TemplateLib.php @@ -27,7 +27,7 @@ if (!defined("BASEPATH")) exit("No direct script access allowed"); -class Template +class TemplateLib { /* default values */ diff --git a/application/libraries/VorlageLib.php b/application/libraries/VorlageLib.php new file mode 100644 index 000000000..463e2bdf5 --- /dev/null +++ b/application/libraries/VorlageLib.php @@ -0,0 +1,95 @@ +ci =& get_instance(); + $this->ci->load->model('system/Vorlage_model', 'VorlageModel'); + $this->ci->load->helper('language'); + $this->ci->lang->load('message'); + } + + /** + * getVorlage() - will load a spezific Template + * + * @param integer $vorlage_kurzbz REQUIRED + * @return struct + */ + function getVorlage($vorlage_kurzbz) + { + if (empty($vorlage_kurzbz)) + return $this->_error(MSG_ERR_INVALID_MSG_ID); + + $vorlage = $this->ci->VorlageModel->load($vorlage_kurzbz); + return $vorlage; + } + + /** + * getSubMessages() - will return all Messages subordinated from a specified message. + * + * @param integer $msg_id REQUIRED + * @return array + */ + function getVorlageByMimetype($mimetype = null) + { + $vorlage = $this->ci->VorlageModel->loadWhere(array('mimetype' => $mimetype)); + return $vorlage; + } + + /** + * saveVorlage() - will save a spezific Template. + * + * @param array $data REQUIRED + * @return array + */ + function saveVorlage($vorlage_kurzbz, $data) + { + if (empty($data)) + return $this->_error(MSG_ERR_INVALID_MSG_ID); + + $vorlage = $this->ci->VorlageModel->update($vorlage_kurzbz, $data); + return $vorlage; + } + /** --------------------------------------------------------------- + * Success + * + * @param mixed $retval + * @return array + */ + protected function _success($retval, $message = MSG_SUCCESS) + { + $return = new stdClass(); + $return->error = EXIT_SUCCESS; + $return->Code = $message; + $return->msg = lang('message_' . $message); + $return->retval = $retval; + return $return; + } + + /** --------------------------------------------------------------- + * General Error + * + * @return array + */ + protected function _error($retval = '', $message = MSG_ERROR_GENERAL) + { + $return = new stdClass(); + $return->error = EXIT_ERROR; + $return->Code = $message; + $return->msg = lang('message_' . $message); + $return->retval = $retval; + return $return; + } +} diff --git a/application/models/system/Attachment_model.php b/application/models/system/Attachment_model.php new file mode 100644 index 000000000..50f7c6ab4 --- /dev/null +++ b/application/models/system/Attachment_model.php @@ -0,0 +1,16 @@ +dbTable = 'public.tbl_msg_attachment'; + $this->pk = 'attachment_id'; + } +} diff --git a/application/models/system/MsgStatus_model.php b/application/models/system/MsgStatus_model.php new file mode 100644 index 000000000..f717efe05 --- /dev/null +++ b/application/models/system/MsgStatus_model.php @@ -0,0 +1,18 @@ +dbTable = 'public.tbl_msg_status'; + $this->pk = array('message_id', 'person_id'); + $this->hasSequence = false; + } +} + diff --git a/application/views/system/messageView.php b/application/views/system/messageView.php new file mode 100644 index 000000000..8932c4fde --- /dev/null +++ b/application/views/system/messageView.php @@ -0,0 +1,14 @@ + +