Merge after last Commit

This commit is contained in:
cris-technikum
2018-02-28 14:39:33 +01:00
parent dc3d71fdfb
commit db14c86a77
57 changed files with 3338 additions and 1704 deletions
+251 -182
View File
@@ -15,7 +15,7 @@ class MessageLib
public function __construct()
{
// Get code igniter instance
$this->ci =& get_instance();
$this->ci =& get_instance();
// Loads message configuration
$this->ci->config->load('message');
@@ -41,70 +41,70 @@ class MessageLib
$this->ci->load->helper('message');
// Loads phrases
$this->ci->lang->load('message');
}
$this->ci->lang->load('message');
}
/**
* getMessage() - returns the specified received message for a specified person
*/
public function getMessage($msg_id, $person_id)
{
if (empty($msg_id))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
/**
* getMessage() - returns the specified received message for a specified person
*/
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);
return $this->_error('', MSG_ERR_INVALID_RECIPIENTS);
$msg = $this->ci->RecipientModel->getMessage($msg_id, $person_id);
return $msg;
}
return $msg;
}
/**
* getMessagesByUID() - will return all messages, including the latest status for specified user. It don´t returns Attachments.
*/
public function getMessagesByUID($uid, $oe_kurzbz = null, $all = false)
{
if (empty($uid))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
* getMessagesByUID() - will return all messages, including the latest status for specified user. It don´t returns Attachments.
*/
public function getMessagesByUID($uid, $oe_kurzbz = null, $all = false)
{
if (empty($uid))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
$msg = $this->ci->RecipientModel->getMessagesByUID($uid, $oe_kurzbz, $all);
return $msg;
}
return $msg;
}
/**
* getMessagesByPerson() - will return all messages, including the latest status for specified user. It don´t returns Attachments.
*/
public function getMessagesByPerson($person_id, $oe_kurzbz = null, $all = false)
{
if (empty($person_id))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
* getMessagesByPerson() - will return all messages, including the latest status for specified user. It don´t returns Attachments.
*/
public function getMessagesByPerson($person_id, $oe_kurzbz = null, $all = false)
{
if (empty($person_id))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
$msg = $this->ci->RecipientModel->getMessagesByPerson($person_id, $oe_kurzbz, $all);
return $msg;
}
return $msg;
}
/**
* getSentMessagesByPerson() - Get all sent messages from a person identified by person_id
*/
public function getSentMessagesByPerson($person_id, $oe_kurzbz = null, $all = false)
{
if (empty($person_id))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
* getSentMessagesByPerson() - Get all sent messages from a person identified by person_id
*/
public function getSentMessagesByPerson($person_id, $oe_kurzbz = null, $all = false)
{
if (empty($person_id))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
$msg = $this->ci->MessageModel->getMessagesByPerson($person_id, $oe_kurzbz, $all);
return $msg;
}
return $msg;
}
/**
* getMessageByToken
*/
public function getMessageByToken($token)
{
if (empty($token))
return $this->_error('', MSG_ERR_INVALID_TOKEN);
* getMessageByToken
*/
public function getMessageByToken($token)
{
if (empty($token))
return $this->_error('', MSG_ERR_INVALID_TOKEN);
$result = $this->ci->RecipientModel->getMessageByToken($token);
if (hasData($result))
@@ -138,43 +138,43 @@ class MessageLib
}
}
return $result;
}
return $result;
}
/**
* getCountUnreadMessages
*/
public function getCountUnreadMessages($person_id, $oe_kurzbz = null)
{
if (!is_numeric($person_id))
return $this->_error('', MSG_ERR_INVALID_RECIPIENTS);
/**
* getCountUnreadMessages
*/
public function getCountUnreadMessages($person_id, $oe_kurzbz = null)
{
if (!is_numeric($person_id))
return $this->_error('', MSG_ERR_INVALID_RECIPIENTS);
$msg = $this->ci->RecipientModel->getCountUnreadMessages($person_id, $oe_kurzbz);
return $msg;
}
return $msg;
}
/**
* updateMessageStatus() - will change status on message for particular user
/**
* updateMessageStatus() - will change status on message for particular user
* NOTE: it performs an insert, NOT an update
*/
public function updateMessageStatus($message_id, $person_id, $status)
{
if (empty($message_id))
{
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
}
*/
public function updateMessageStatus($message_id, $person_id, $status)
{
if (empty($message_id))
{
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
}
if (empty($person_id))
{
return $this->_error('', MSG_ERR_INVALID_USER_ID);
}
if (empty($person_id))
{
return $this->_error('', MSG_ERR_INVALID_USER_ID);
}
// NOTE: Not use empty otherwise if status is 0 it returns an error
if (!isset($status))
{
return $this->_error('', MSG_ERR_INVALID_STATUS_ID);
}
if (!isset($status))
{
return $this->_error('', MSG_ERR_INVALID_STATUS_ID);
}
// Searches if the status is already present
$result = $this->ci->MsgStatusModel->load(array($message_id, $person_id, $status));
@@ -195,17 +195,17 @@ class MessageLib
}
return $result;
}
}
/**
* sendMessage() - sends new internal message. This function will create a new thread
*/
public function sendMessage($sender_id, $receiver_id, $subject, $body, $priority = PRIORITY_NORMAL, $relationmessage_id = null, $oe_kurzbz = null, $multiPartMime = true)
{
if (!is_numeric($sender_id))
{
/**
* sendMessage() - sends new internal message. This function will create a new thread
*/
public function sendMessage($sender_id, $receiver_id, $subject, $body, $priority = PRIORITY_NORMAL, $relationmessage_id = null, $oe_kurzbz = null, $multiPartMime = true)
{
if (!is_numeric($sender_id))
{
$sender_id = $this->ci->config->item('system_person_id');
}
}
$receivers = $this->_getReceivers($receiver_id, $oe_kurzbz);
@@ -270,17 +270,17 @@ class MessageLib
}
return $result;
}
}
/**
* sendMessageVorlage() - sends new internal message using a template
*/
public function sendMessageVorlage($sender_id, $receiver_id, $vorlage_kurzbz, $oe_kurzbz, $data, $relationmessage_id = null, $orgform_kurzbz = null, $multiPartMime = true)
{
if (!is_numeric($sender_id))
{
* sendMessageVorlage() - sends new internal message using a template
*/
public function sendMessageVorlage($sender_id, $receiver_id, $vorlage_kurzbz, $oe_kurzbz, $data, $relationmessage_id = null, $orgform_kurzbz = null, $multiPartMime = true)
{
if (!is_numeric($sender_id))
{
$sender_id = $this->ci->config->item('system_person_id');
}
}
$receivers = $this->_getReceivers($receiver_id, $oe_kurzbz);
@@ -387,7 +387,7 @@ class MessageLib
}
return $result;
}
}
/**
* Gets all the messages from DB and sends them via email
@@ -426,54 +426,90 @@ class MessageLib
if ((!is_null($result->retval[$i]->receiver) && $result->retval[$i]->receiver != '')
|| (!is_null($result->retval[$i]->employeecontact) && $result->retval[$i]->employeecontact != ''))
{
$href = $this->ci->config->item('message_server').$this->ci->config->item('message_html_view_url').$result->retval[0]->token;
// Using a template for the html email body
$body = $this->ci->parser->parse(
'templates/mailHTML',
array(
'href' => $href,
'subject' => $result->retval[0]->subject,
'body' => $result->retval[0]->body
),
true
);
$href = $this->ci->config->item('message_server').$this->ci->config->item('message_html_view_url').$result->retval[$i]->token;
$vorlage = $this->ci->vorlagelib->loadVorlagetext('MessageMailHTML');
if(hasData($vorlage))
{
// Using a template for the html email body
$body = $this->ci->parser->parse_string(
$vorlage->retval[0]->text,
array(
'href' => $href,
'subject' => $result->retval[$i]->subject,
'body' => $result->retval[$i]->body
),
true
);
}
else
{
// Using a template for the html email body
$body = $this->ci->parser->parse(
'templates/mailHTML',
array(
'href' => $href,
'subject' => $result->retval[$i]->subject,
'body' => $result->retval[$i]->body
),
true
);
}
if (is_null($body) || $body == '')
{
$this->ci->loglib->logError('Error while parsing the mail template');
}
// Using a template for the plain text email body
$altBody = $this->ci->parser->parse(
'templates/mailTXT',
array(
'href' => $href,
'subject' => $result->retval[0]->subject,
'body' => $result->retval[0]->body
),
true
);
$vorlage = $this->ci->vorlagelib->loadVorlagetext('MessageMailTXT');
if(hasData($vorlage))
{
// Using a template for the plain text email body
$altBody = $this->ci->parser->parse_string(
$vorlage->retval[0]->text,
array(
'href' => $href,
'subject' => $result->retval[$i]->subject,
'body' => $result->retval[$i]->body
),
true
);
}
else
{
// Using a template for the plain text email body
$altBody = $this->ci->parser->parse(
'templates/mailTXT',
array(
'href' => $href,
'subject' => $result->retval[$i]->subject,
'body' => $result->retval[$i]->body
),
true
);
}
if (is_null($altBody) || $altBody == '')
{
$this->ci->loglib->logError('Error while parsing the mail template');
}
// If the sender kontakt does not exist, then system-sender is used if empty
// If the sender is not an employee, then system-sender is used if empty
$sender = '';
if (!is_null($result->retval[0]->sender) && $result->retval[0]->sender != '')
if (!is_null($result->retval[0]->senderemployeecontact) && $result->retval[0]->senderemployeecontact != '')
{
$sender = $result->retval[0]->sender;
$sender = $result->retval[0]->senderemployeecontact.'@'.DOMAIN;
}
$receiverContanct = $result->retval[$i]->receiver;
$receiverContact = $result->retval[$i]->receiver;
if (!is_null($result->retval[$i]->employeecontact) && $result->retval[$i]->employeecontact != '')
{
$receiverContanct = $result->retval[$i]->employeecontact.'@'.DOMAIN;
$receiverContact = $result->retval[$i]->employeecontact.'@'.DOMAIN;
}
// Sending email
$sent = $this->ci->maillib->send(
$sender,
$receiverContanct,
$receiverContact,
$result->retval[$i]->subject,
$body,
null,
@@ -571,15 +607,32 @@ class MessageLib
{
// Using a template for the html email body
$href = $this->ci->config->item('message_server').$this->ci->config->item('message_html_view_url').$result->retval[0]->token;
$bodyMsg = $this->ci->parser->parse(
'templates/mailHTML',
array(
'href' => $href,
'subject' => $result->retval[0]->subject,
'body' => $result->retval[0]->body
),
true
);
$vorlage = $this->ci->vorlagelib->loadVorlagetext('MessageMailHTML');
if(hasData($vorlage))
{
$bodyMsg = $this->ci->parser->parse_string(
$vorlage->retval[0]->text,
array(
'href' => $href,
'subject' => $result->retval[0]->subject,
'body' => $result->retval[0]->body
),
true
);
}
else
{
$bodyMsg = $this->ci->parser->parse(
'templates/mailHTML',
array(
'href' => $href,
'subject' => $result->retval[0]->subject,
'body' => $result->retval[0]->body
),
true
);
}
if (is_null($bodyMsg) || $bodyMsg == '')
{
// $body = $result->retval[0]->body;
@@ -587,15 +640,31 @@ class MessageLib
}
// Using a template for the plain text email body
$altBody = $this->ci->parser->parse(
'templates/mailTXT',
array(
'href' => $href,
'subject' => $result->retval[0]->subject,
'body' => $result->retval[0]->body
),
true
);
$vorlage = $this->ci->vorlagelib->loadVorlagetext('MessageMailTXT');
if(hasData($vorlage))
{
$altBody = $this->ci->parser->parse_string(
$vorlage->retval[0]->text,
array(
'href' => $href,
'subject' => $result->retval[0]->subject,
'body' => $result->retval[0]->body
),
true
);
}
else
{
$altBody = $this->ci->parser->parse(
'templates/mailTXT',
array(
'href' => $href,
'subject' => $result->retval[0]->subject,
'body' => $result->retval[0]->body
),
true
);
}
if (is_null($altBody) || $altBody == '')
{
$this->ci->loglib->logError('Error while parsing the plain text mail template');
@@ -606,23 +675,23 @@ class MessageLib
$bodyMsg = $altBody = $body;
}
// If the sender kontakt does not exist, then system-sender is used if empty
// If the sender is not an employee, then system-sender is used if empty
$sender = '';
if (!is_null($result->retval[0]->sender) && $result->retval[0]->sender != '')
if (!is_null($result->retval[0]->senderemployeecontact) && $result->retval[0]->senderemployeecontact != '')
{
$sender = $result->retval[0]->sender;
$sender = $result->retval[0]->senderemployeecontact.'@'.DOMAIN;
}
$receiverContanct = $result->retval[0]->receiver;
$receiverContact = $result->retval[0]->receiver;
if (!is_null($result->retval[0]->employeecontact) && $result->retval[0]->employeecontact != '')
{
$receiverContanct = $result->retval[0]->employeecontact.'@'.DOMAIN;
$receiverContact = $result->retval[0]->employeecontact.'@'.DOMAIN;
}
// Sending email
$sent = $this->ci->maillib->send(
$sender,
$receiverContanct,
$receiverContact,
is_null($subject) ? $result->retval[0]->subject : $subject, // if parameter subject is not null, use it!
$bodyMsg,
null,
@@ -689,8 +758,8 @@ class MessageLib
return $sent;
}
// ------------------------------------------------------------------------
// Private methods
// ------------------------------------------------------------------------
// Private methods
/**
* Update the table tbl_msg_recipient
@@ -736,29 +805,29 @@ class MessageLib
}
/**
* Gets the receivers id that are enabled to read messages for that oe_kurzbz
*/
private function _getReceiversByOekurzbz($oe_kurzbz)
{
* Gets the receivers id that are enabled to read messages for that oe_kurzbz
*/
private function _getReceiversByOekurzbz($oe_kurzbz)
{
// Load Benutzerfunktion_model
$this->ci->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel');
// Join with table public.tbl_benutzer on field uid
$this->ci->BenutzerfunktionModel->addJoin('public.tbl_benutzer', 'uid');
// Get all the valid receivers id using the oe_kurzbz
$receivers = $this->ci->BenutzerfunktionModel->loadWhere(
'oe_kurzbz = \''.$oe_kurzbz.'\''.
' AND funktion_kurzbz = \''.$this->ci->config->item('assistent_function').'\''.
'oe_kurzbz = '.$this->ci->db->escape($oe_kurzbz).
' AND funktion_kurzbz = '.$this->ci->db->escape($this->ci->config->item('assistent_function')).
' AND (NOW() BETWEEN COALESCE(datum_von, NOW()) AND COALESCE(datum_bis, NOW()))'
);
return $receivers;
}
}
/**
* Gets the receivers id
*/
private function _getReceivers($receiver_id, $oe_kurzbz = null)
{
/**
* Gets the receivers id
*/
private function _getReceivers($receiver_id, $oe_kurzbz = null)
{
$receivers = null;
// If no receiver_id is given...
@@ -782,13 +851,13 @@ class MessageLib
}
return $receivers;
}
}
/**
* Checks if the given receiver id is a valid person
*/
private function _checkReceiverId($receiver_id)
{
/**
* Checks if the given receiver id is a valid person
*/
private function _checkReceiverId($receiver_id)
{
// Load Person_model
$this->ci->load->model('person/Person_model', 'PersonModel');
$result = $this->ci->PersonModel->load($receiver_id);
@@ -798,13 +867,13 @@ class MessageLib
}
return false;
}
}
/**
* Save a message in DB
**/
private function _saveMessage($sender_id, $receiver_id, $subject, $body, $relationmessage_id, $oe_kurzbz)
{
/**
* Save a message in DB
**/
private function _saveMessage($sender_id, $receiver_id, $subject, $body, $relationmessage_id, $oe_kurzbz)
{
// Starts db transaction
$this->ci->db->trans_start(false);
@@ -854,27 +923,27 @@ class MessageLib
}
return $result;
}
}
/**
* Wrapper for function error
*/
private function _error($retval = '', $code = null)
{
/**
* Wrapper for function error
*/
private function _error($retval = '', $code = null)
{
return error($retval, $code, MessageLib::MSG_INDX_PREFIX);
}
}
/**
* Wrapper for function success
*/
private function _success($retval = '', $code = null)
{
/**
* Wrapper for function success
*/
private function _success($retval = '', $code = null)
{
return success($retval, $code, MessageLib::MSG_INDX_PREFIX);
}
}
/**
*
*/
/**
*
*/
public function parseMessageText($text, $data = array())
{
return $this->ci->parser->parse_string($text, $data, true);