mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 16:32:20 +00:00
- Added field status in the primary key array of model MsgStatus_model
- Changes in the logic of the messaging system, now every message status is a new entry in the table tbl_msg_status
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
<?php
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
if (! defined("BASEPATH")) exit("No direct script access allowed");
|
||||
|
||||
/**
|
||||
* Name: Messaging Library for FH-Complete
|
||||
*
|
||||
*
|
||||
*/
|
||||
class MessageLib
|
||||
{
|
||||
@@ -24,24 +23,24 @@ class MessageLib
|
||||
// CI Parser library
|
||||
$this->ci->load->library("parser");
|
||||
// Loads LogLib
|
||||
$this->ci->load->library('LogLib');
|
||||
$this->ci->load->library("LogLib");
|
||||
// Loads VorlageLib
|
||||
$this->ci->load->library('VorlageLib');
|
||||
$this->ci->load->library("VorlageLib");
|
||||
|
||||
// Initializing email library with the loaded configurations
|
||||
$this->ci->email->initialize($this->ci->config->config["mail"]);
|
||||
|
||||
// Loading models
|
||||
$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->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");
|
||||
|
||||
// Loads fhc helper
|
||||
$this->ci->load->helper('fhc');
|
||||
$this->ci->load->helper("fhc");
|
||||
|
||||
//$this->ci->load->helper('language');
|
||||
$this->ci->lang->load('message');
|
||||
$this->ci->lang->load("message");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -52,19 +51,22 @@ class MessageLib
|
||||
* @param integer $msg_id REQUIRED
|
||||
* @return array
|
||||
*/
|
||||
function getMessage($msg_id)
|
||||
public 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));
|
||||
$this->ci->MessageModel->addJoin("public.tbl_person", "person_id");
|
||||
$msg = $this->ci->MessageModel->loadWhere(array("message_id" => $msg_id));
|
||||
|
||||
// Sorts the statuses by the insert date, so the first in the array is the most updated
|
||||
$this->ci->MsgStatusModel->addOrder("insertamum", "DESC");
|
||||
$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));
|
||||
|
||||
$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));
|
||||
$attm = $this->ci->AttachmentModel->loadWhere(array("message_id" => $msg_id));
|
||||
$msg->retval[0]->attm = $attm->retval;
|
||||
|
||||
return $msg;
|
||||
@@ -76,7 +78,7 @@ class MessageLib
|
||||
* @param string $uid REQUIRED
|
||||
* @return array
|
||||
*/
|
||||
function getMessagesByUID($uid, $all = false)
|
||||
public function getMessagesByUID($uid, $all = false)
|
||||
{
|
||||
if (empty($uid))
|
||||
return $this->_error(MSG_ERR_INVALID_MSG_ID);
|
||||
@@ -92,7 +94,7 @@ class MessageLib
|
||||
* @param bigint $person_id REQUIRED
|
||||
* @return array
|
||||
*/
|
||||
function getMessagesByPerson($person_id, $all = false)
|
||||
public function getMessagesByPerson($person_id, $all = false)
|
||||
{
|
||||
if (empty($person_id))
|
||||
return $this->_error(MSG_ERR_INVALID_MSG_ID);
|
||||
@@ -110,7 +112,7 @@ class MessageLib
|
||||
* @param integer $msg_id REQUIRED
|
||||
* @return array
|
||||
*/
|
||||
function getSubMessages($msg_id)
|
||||
public function getSubMessages($msg_id)
|
||||
{
|
||||
if (!is_numeric($msg_id))
|
||||
return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID);
|
||||
@@ -124,7 +126,7 @@ class MessageLib
|
||||
* @param token string
|
||||
* @return array
|
||||
*/
|
||||
function getMessagesByToken($token)
|
||||
public function getMessagesByToken($token)
|
||||
{
|
||||
if (empty($token))
|
||||
return $this->_error(MSG_ERR_INVALID_MSG_ID);
|
||||
@@ -132,31 +134,33 @@ class MessageLib
|
||||
$result = $this->ci->MessageModel->getMessagesByToken($token);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0)
|
||||
{
|
||||
if ($result->retval[0]->status == MSG_STATUS_UNREAD)
|
||||
// Searches for a status that is different from unread
|
||||
$found = -1;
|
||||
for ($i = 0; $i < count($result->retval); $i++)
|
||||
{
|
||||
if ($result->retval[$i]->status > MSG_STATUS_UNREAD)
|
||||
{
|
||||
$found = $i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If not found then insert the read status
|
||||
if ($found == -1)
|
||||
{
|
||||
$statusKey = array(
|
||||
'message_id' => $result->retval[0]->message_id,
|
||||
'person_id' => $result->retval[0]->receiver_id,
|
||||
'status' => MSG_STATUS_UNREAD
|
||||
"message_id" => $result->retval[0]->message_id,
|
||||
"person_id" => $result->retval[0]->receiver_id,
|
||||
"status" => MSG_STATUS_READ
|
||||
);
|
||||
$resTmp = $this->ci->MsgStatusModel->update($statusKey, array('status' => MSG_STATUS_READ));
|
||||
if (!is_object($resTmp) || (is_object($resTmp) && $resTmp->error != EXIT_SUCCESS))
|
||||
{
|
||||
$result = $resTmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->retval[0]->status = MSG_STATUS_READ;
|
||||
}
|
||||
|
||||
$result = $this->ci->MsgStatusModel->insert($statusKey);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -167,7 +171,7 @@ class MessageLib
|
||||
* @param integer $status_id REQUIRED - should come from config/message.php list of constants
|
||||
* @return array
|
||||
*/
|
||||
function updateMessageStatus($message_id, $person_id, $status)
|
||||
public function updateMessageStatus($message_id, $person_id, $status)
|
||||
{
|
||||
if (empty($message_id))
|
||||
{
|
||||
@@ -185,10 +189,23 @@ class MessageLib
|
||||
return $this->_invalid_id(MSG_ERR_INVALID_STATUS_ID);
|
||||
}
|
||||
|
||||
$result = $this->ci->MsgStatusModel->update(
|
||||
array('message_id' => $message_id, 'person_id' => $person_id),
|
||||
array('status' => $status)
|
||||
);
|
||||
// Searches if the status is already present
|
||||
$result = $this->ci->MsgStatusModel->load(array($message_id, $person_id, $status));
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0)
|
||||
{
|
||||
// status already present
|
||||
}
|
||||
else
|
||||
{
|
||||
// Insert the new status
|
||||
$statusKey = array(
|
||||
"message_id" => $message_id,
|
||||
"person_id" => $person_id,
|
||||
"status" => $status
|
||||
);
|
||||
|
||||
$result = $this->ci->MsgStatusModel->insert($statusKey);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -202,7 +219,7 @@ class MessageLib
|
||||
* @param integer $user_id REQUIRED
|
||||
* @return array
|
||||
*/
|
||||
function addRecipient($person_id)
|
||||
public function addRecipient($person_id)
|
||||
{
|
||||
if (!is_numeric($person_id))
|
||||
return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID);
|
||||
@@ -212,8 +229,6 @@ class MessageLib
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -226,7 +241,7 @@ class MessageLib
|
||||
* @param integer $priority
|
||||
* @return array
|
||||
*/
|
||||
function sendMessage($sender_id, $subject = '', $body = '', $priority = PRIORITY_NORMAL, $relationmessage_id = null, $oe_kurzbz = null)
|
||||
public 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);
|
||||
@@ -235,12 +250,12 @@ class MessageLib
|
||||
$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
|
||||
"person_id" => $sender_id,
|
||||
"subject" => $subject,
|
||||
"body" => $body,
|
||||
"priority" => $priority,
|
||||
"relationmessage_id" => $relationmessage_id,
|
||||
"oe_kurzbz" => $oe_kurzbz
|
||||
);
|
||||
|
||||
$result = $this->ci->MessageModel->insert($data);
|
||||
@@ -251,9 +266,9 @@ class MessageLib
|
||||
*/
|
||||
$msg_id = $result->retval;
|
||||
$statusData = array(
|
||||
'message_id' => $msg_id,
|
||||
'person_id' => $sender_id,
|
||||
'status' => MSG_STATUS_UNREAD
|
||||
"message_id" => $msg_id,
|
||||
"person_id" => $sender_id,
|
||||
"status" => MSG_STATUS_UNREAD
|
||||
);
|
||||
$result = $this->ci->MsgStatusModel->insert($statusData);
|
||||
}
|
||||
@@ -282,13 +297,13 @@ class MessageLib
|
||||
* @param integer $priority
|
||||
* @return array
|
||||
*/
|
||||
function sendMessageVorlage($sender_id, $receiver_id, $vorlage_kurzbz, $oe_kurzbz, $data, $relationmessage_id = null, $orgform_kurzbz = null)
|
||||
public function sendMessageVorlage($sender_id, $receiver_id, $vorlage_kurzbz, $oe_kurzbz, $data, $relationmessage_id = null, $orgform_kurzbz = null)
|
||||
{
|
||||
if (!is_numeric($sender_id) || !is_numeric($receiver_id))
|
||||
return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID);
|
||||
|
||||
// Load reveiver data to get its relative language
|
||||
$this->ci->load->model('person/Person_model', 'PersonModel');
|
||||
$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)
|
||||
{
|
||||
@@ -314,12 +329,12 @@ class MessageLib
|
||||
$this->ci->db->trans_start(false);
|
||||
// Save Message
|
||||
$msgData = array(
|
||||
'person_id' => $sender_id,
|
||||
'subject' => $result->retval[0]->subject,
|
||||
'body' => $parsedText,
|
||||
'priority' => PRIORITY_NORMAL,
|
||||
'relationmessage_id' => $relationmessage_id,
|
||||
'oe_kurzbz' => $oe_kurzbz
|
||||
"person_id" => $sender_id,
|
||||
"subject" => $result->retval[0]->subject,
|
||||
"body" => $parsedText,
|
||||
"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)
|
||||
@@ -327,18 +342,18 @@ class MessageLib
|
||||
// Link the message with the receiver
|
||||
$msg_id = $result->retval;
|
||||
$recipientData = array(
|
||||
'person_id' => $receiver_id,
|
||||
'message_id' => $msg_id,
|
||||
'token' => generateToken()
|
||||
"person_id" => $receiver_id,
|
||||
"message_id" => $msg_id,
|
||||
"token" => generateToken()
|
||||
);
|
||||
$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
|
||||
"message_id" => $msg_id,
|
||||
"person_id" => $receiver_id,
|
||||
"status" => MSG_STATUS_UNREAD
|
||||
);
|
||||
$result = $this->ci->MsgStatusModel->insert($statusData);
|
||||
}
|
||||
@@ -362,21 +377,21 @@ class MessageLib
|
||||
// Better message error
|
||||
if (!is_array($result->retval) || (is_array($result->retval) && count($result->retval) == 0))
|
||||
{
|
||||
$result = $this->_error('Vorlage not found', EXIT_ERROR);
|
||||
$result = $this->_error("Vorlage not found", EXIT_ERROR);
|
||||
}
|
||||
else if (is_array($result->retval) && count($result->retval) > 0)
|
||||
{
|
||||
if (is_null($result->retval[0]->oe_kurzbz))
|
||||
{
|
||||
$result = $this->_error('Vorlage not found', EXIT_ERROR);
|
||||
$result = $this->_error("Vorlage not found", EXIT_ERROR);
|
||||
}
|
||||
else if (empty($result->retval[0]->text))
|
||||
{
|
||||
$result = $this->_error('Vorlage has an empty text', EXIT_ERROR);
|
||||
$result = $this->_error("Vorlage has an empty text", EXIT_ERROR);
|
||||
}
|
||||
else if (empty($result->retval[0]->subject))
|
||||
{
|
||||
$result = $this->_error('Vorlage has an empty subject', EXIT_ERROR);
|
||||
$result = $this->_error("Vorlage has an empty subject", EXIT_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -389,123 +404,6 @@ class MessageLib
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// 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)
|
||||
{
|
||||
$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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an item from the email configuration array
|
||||
*/
|
||||
private function getEmailCfgItem($itemName)
|
||||
{
|
||||
return $this->ci->config->item($itemName, EMAIL_CONFIG_INDEX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a single email
|
||||
*/
|
||||
private function sendOne($from, $to, $subject, $message, $alias = "", $cc = null, $bcc = null)
|
||||
{
|
||||
$this->ci->email->from($from, $alias);
|
||||
$this->ci->email->to($to);
|
||||
if (!is_null($cc)) $this->ci->email->cc($cc);
|
||||
if (!is_null($bcc)) $this->ci->email->bcc($bcc);
|
||||
$this->ci->email->subject($subject);
|
||||
$this->ci->email->message($message);
|
||||
|
||||
// Avoid printing on standard output ugly error messages
|
||||
return @$this->ci->email->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the table tbl_message_recipient
|
||||
*/
|
||||
private function _updateMessageRecipient($message_id, $receiver_id, $parameters)
|
||||
{
|
||||
$updated = false;
|
||||
|
||||
// Changes the status of the message from unread to read
|
||||
$resultUpdate = $this->ci->RecipientModel->update(array($receiver_id, $message_id), $parameters);
|
||||
// Checks if errors were occurred
|
||||
if (is_object($resultUpdate) && $resultUpdate->error == EXIT_SUCCESS && is_array($resultUpdate->retval))
|
||||
{
|
||||
$updated = true;
|
||||
}
|
||||
|
||||
return $updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the status of the message from unsent to sent
|
||||
*/
|
||||
private function setMessageSent($message_id, $receiver_id)
|
||||
{
|
||||
$parameters = array("sent" => "NOW()", "sentinfo" => null);
|
||||
|
||||
return $this->_updateMessageRecipient($message_id, $receiver_id, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sentInfo with the error
|
||||
*/
|
||||
private function setMessageError($message_id, $receiver_id, $sentInfo, $prevSentInfo = null)
|
||||
{
|
||||
if (!is_null($prevSentInfo) && $prevSentInfo != "")
|
||||
{
|
||||
$sentInfo = $prevSentInfo . SENT_INFO_NEWLINE . $sentInfo;
|
||||
}
|
||||
|
||||
$parameters = array("sent" => null, "sentinfo" => $sentInfo);
|
||||
|
||||
return $this->_updateMessageRecipient($message_id, $receiver_id, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the messages from DB and sends them via email
|
||||
@@ -631,4 +529,120 @@ class MessageLib
|
||||
|
||||
return $sent;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// 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)
|
||||
{
|
||||
$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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an item from the email configuration array
|
||||
*/
|
||||
private function getEmailCfgItem($itemName)
|
||||
{
|
||||
return $this->ci->config->item($itemName, EMAIL_CONFIG_INDEX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a single email
|
||||
*/
|
||||
private function sendOne($from, $to, $subject, $message, $alias = "", $cc = null, $bcc = null)
|
||||
{
|
||||
$this->ci->email->from($from, $alias);
|
||||
$this->ci->email->to($to);
|
||||
if (!is_null($cc)) $this->ci->email->cc($cc);
|
||||
if (!is_null($bcc)) $this->ci->email->bcc($bcc);
|
||||
$this->ci->email->subject($subject);
|
||||
$this->ci->email->message($message);
|
||||
|
||||
// Avoid printing on standard output ugly error messages
|
||||
return @$this->ci->email->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the table tbl_message_recipient
|
||||
*/
|
||||
private function _updateMessageRecipient($message_id, $receiver_id, $parameters)
|
||||
{
|
||||
$updated = false;
|
||||
|
||||
// Changes the status of the message from unread to read
|
||||
$resultUpdate = $this->ci->RecipientModel->update(array($receiver_id, $message_id), $parameters);
|
||||
// Checks if errors were occurred
|
||||
if (is_object($resultUpdate) && $resultUpdate->error == EXIT_SUCCESS && is_array($resultUpdate->retval))
|
||||
{
|
||||
$updated = true;
|
||||
}
|
||||
|
||||
return $updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the status of the message from unsent to sent
|
||||
*/
|
||||
private function setMessageSent($message_id, $receiver_id)
|
||||
{
|
||||
$parameters = array("sent" => "NOW()", "sentinfo" => null);
|
||||
|
||||
return $this->_updateMessageRecipient($message_id, $receiver_id, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sentInfo with the error
|
||||
*/
|
||||
private function setMessageError($message_id, $receiver_id, $sentInfo, $prevSentInfo = null)
|
||||
{
|
||||
if (!is_null($prevSentInfo) && $prevSentInfo != "")
|
||||
{
|
||||
$sentInfo = $prevSentInfo . SENT_INFO_NEWLINE . $sentInfo;
|
||||
}
|
||||
|
||||
$parameters = array("sent" => null, "sentinfo" => $sentInfo);
|
||||
|
||||
return $this->_updateMessageRecipient($message_id, $receiver_id, $parameters);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
if ( ! defined("BASEPATH")) exit("No direct script access allowed");
|
||||
|
||||
class Message_model extends DB_Model
|
||||
{
|
||||
@@ -10,8 +10,8 @@ class Message_model extends DB_Model
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable = 'public.tbl_msg_message';
|
||||
$this->pk = 'message_id';
|
||||
$this->dbTable = "public.tbl_msg_message";
|
||||
$this->pk = "message_id";
|
||||
}
|
||||
|
||||
public function getMessagesByUID($uid, $all)
|
||||
@@ -21,50 +21,46 @@ class Message_model extends DB_Model
|
||||
// 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 (! $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);
|
||||
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 uid,
|
||||
person_id,
|
||||
message_id,
|
||||
subject,
|
||||
body,
|
||||
priority,
|
||||
relationmessage_id,
|
||||
oe_kurzbz,
|
||||
$sql = "SELECT b.uid,
|
||||
m.person_id,
|
||||
m.message_id,
|
||||
m.subject,
|
||||
m.body,
|
||||
m.priority,
|
||||
m.relationmessage_id,
|
||||
m.oe_kurzbz,
|
||||
m.insertamum,
|
||||
anrede,
|
||||
titelpost,
|
||||
titelpre,
|
||||
nachname,
|
||||
vorname,
|
||||
vornamen,
|
||||
status,
|
||||
statusinfo,
|
||||
p.anrede,
|
||||
p.titelpost,
|
||||
p.titelpre,
|
||||
p.nachname,
|
||||
p.vorname,
|
||||
p.vornamen,
|
||||
s.status,
|
||||
s.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 OUTER 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 = ?';
|
||||
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)';
|
||||
$sql .= " AND (status < 3 OR status IS NULL)";
|
||||
|
||||
$result = $this->db->query($sql, array($uid));
|
||||
if (is_object($result))
|
||||
return $this->_success($result->result());
|
||||
@@ -75,16 +71,16 @@ class Message_model extends DB_Model
|
||||
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);
|
||||
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,
|
||||
$sql = "SELECT r.message_id,
|
||||
m.person_id,
|
||||
m.subject,
|
||||
m.body,
|
||||
@@ -93,11 +89,13 @@ class Message_model extends DB_Model
|
||||
m.oe_kurzbz,
|
||||
s.status,
|
||||
s.statusinfo,
|
||||
s.updateamum
|
||||
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 public.tbl_msg_status s USING (message_id)
|
||||
WHERE r.person_id = ?';
|
||||
JOIN (
|
||||
SELECT * FROM public.tbl_msg_status ORDER BY insertamum DESC LIMIT 1
|
||||
) s ON (m.message_id = s.message_id AND r.person_id = s.person_id)
|
||||
WHERE r.person_id = ?";
|
||||
|
||||
$result = $this->db->query($sql, array($person_id));
|
||||
if (is_object($result))
|
||||
@@ -109,14 +107,14 @@ class Message_model extends DB_Model
|
||||
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);
|
||||
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,
|
||||
$sql = "SELECT r.message_id,
|
||||
r.person_id as receiver_id,
|
||||
m.person_id as sender_id,
|
||||
m.subject,
|
||||
@@ -126,11 +124,12 @@ class Message_model extends DB_Model
|
||||
m.oe_kurzbz,
|
||||
s.status,
|
||||
s.statusinfo,
|
||||
s.updateamum
|
||||
s.insertamum
|
||||
FROM public.tbl_msg_recipient r JOIN public.tbl_msg_message m USING (message_id)
|
||||
JOIN public.tbl_msg_status s USING (message_id)
|
||||
JOIN public.tbl_msg_status s ON (r.message_id = s.message_id AND r.person_id = s.person_id)
|
||||
WHERE r.token = ?
|
||||
AND status < ?';
|
||||
AND status < ?
|
||||
ORDER BY s.insertamum DESC";
|
||||
|
||||
$result = $this->db->query($sql, array($token, MSG_STATUS_DELETED));
|
||||
if (is_object($result))
|
||||
|
||||
@@ -11,7 +11,7 @@ class MsgStatus_model extends DB_Model
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable = "public.tbl_msg_status";
|
||||
$this->pk = array("message_id", "person_id");
|
||||
$this->pk = array("message_id", "person_id", "status");
|
||||
$this->hasSequence = false;
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class Recipient_model extends DB_Model
|
||||
*/
|
||||
public function getMessages($kontaktType, $sent, $limit = null)
|
||||
{
|
||||
// Check wrights
|
||||
// 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"))
|
||||
@@ -67,8 +67,6 @@ class Recipient_model extends DB_Model
|
||||
array_push($parametersArray, $limit);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Get data of the messages to sent
|
||||
$result = $this->db->query($query, $parametersArray);
|
||||
if (is_object($result))
|
||||
|
||||
Reference in New Issue
Block a user