- Added new method writeReply to FASMessages

- Moved logic from Messages and MessageLib to MessageLib\
- Better code in views/system/messageWrite.php
- Adapted content/messages.js.php to use writeReply
This commit is contained in:
Paolo
2019-02-01 12:04:20 +01:00
parent 306da46c80
commit 2bf2cac383
4 changed files with 518 additions and 431 deletions
+102 -64
View File
@@ -11,7 +11,8 @@ class FASMessages extends Auth_Controller
{
parent::__construct(
array(
'write' => 'basis/message:rw'
'write' => 'basis/message:rw',
'writeReply' => 'basis/message:rw'
)
);
@@ -21,9 +22,6 @@ class FASMessages extends Auth_Controller
// Loads the widget library
$this->load->library('WidgetLib');
$this->load->model('system/Message_model', 'MessageModel');
$this->load->model('person/Person_model', 'PersonModel');
$this->loadPhrases(
array(
'global',
@@ -32,86 +30,126 @@ class FASMessages extends Auth_Controller
);
}
// -----------------------------------------------------------------------------------------------------------------
// Public methods
/**
* Write
* Write a new message
*/
public function write($sender_id = null, $msg_id = null, $receiver_id = null)
public function write($sender_id)
{
$prestudent_id = $this->input->post('prestudent_id');
$oe_kurzbz = array(); // a person may belongs to more organisation units
$msg = null;
$prestudent_id = $this->input->post('prestudent_id'); // recipients prestudend_id(s)
if (!is_numeric($sender_id))
{
$personByUID = $this->PersonModel->getByUid(getAuthUID());
if (isError($personByUID) || !hasData($personByUID))
{
show_error($personByUID->retval);
}
else
{
$sender_id = $personByUID->retval[0]->person_id;
}
show_error('The current logged user person_id is not defined');
}
// Get message data if possible
if (is_numeric($msg_id) && is_numeric($receiver_id))
{
$msg = $this->messagelib->getMessage($msg_id, $receiver_id);
if (isError($msg) || !hasData($msg))
{
show_error($msg->retval);
}
else
{
$msg = $msg->retval[0];
}
}
// Retrieves message vars from view vw_msg_vars
$msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id);
if (isError($msgVarsData))
{
show_error($msgVarsData->retval);
}
$msgVarsData = $this->_getMsgVarsData($prestudent_id);
// Retrieves message vars for a person from view view vw_msg_vars_person
$variablesArray = $this->messagelib->getMessageVarsPerson();
// Organisation units used to get the templates
$this->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel');
$benutzerResult = $this->BenutzerfunktionModel->getByPersonId($sender_id);
if (isError($benutzerResult))
{
show_error($benutzerResult->retval);
}
elseif (hasData($benutzerResult))
{
foreach ($benutzerResult->retval as $val)
{
$oe_kurzbz[] = $val->oe_kurzbz;
}
}
$oe_kurzbz = $this->messagelib->getOeKurzbz($sender_id);
// Admin or commoner?
$this->load->model('system/Benutzerrolle_model', 'BenutzerrolleModel');
$isAdmin = $this->BenutzerrolleModel->isAdminByPersonId($sender_id);
if (isError($isAdmin))
{
show_error($isAdmin->retval);
}
$isAdmin = $this->messagelib->getIsAdmin($sender_id);
$data = array (
'sender_id' => $sender_id,
'receivers' => $msgVarsData->retval,
'message' => $msg,
$data = array(
'recipients' => $msgVarsData->retval,
'variables' => $variablesArray,
'oe_kurzbz' => $oe_kurzbz, // used to get the templates
'isAdmin' => $isAdmin->retval,
'personOnly' => false // indicates if sent only to persons
'isAdmin' => $isAdmin
);
$this->load->view('system/messageWrite', $data);
}
/**
* Write a reply
*/
public function writeReply($sender_id, $msg_id, $receiver_id)
{
$prestudent_id = $this->input->post('prestudent_id'); // recipients prestudend_id(s)
if (!is_numeric($sender_id))
{
show_error('The current logged user person_id is not defined');
}
if (!is_numeric($msg_id))
{
show_error('The msg_id must be a number');
}
if (!is_numeric($receiver_id))
{
show_error('The receiver_id must be a number');
}
$msg = $this->_getMessage($msg_id, $receiver_id);
$msgVarsData = $this->_getMsgVarsData($prestudent_id);
// Retrieves message vars for a person from view view vw_msg_vars_person
$variablesArray = $this->messagelib->getMessageVarsPerson();
// Organisation units used to get the templates
$oe_kurzbz = $this->messagelib->getOeKurzbz($sender_id);
// Admin or commoner?
$isAdmin = $this->messagelib->getIsAdmin($sender_id);
$data = array(
'recipients' => $msgVarsData->retval,
'message' => $msg,
'variables' => $variablesArray,
'oe_kurzbz' => $oe_kurzbz, // used to get the templates
'isAdmin' => $isAdmin
);
$this->load->view('system/messageWrite', $data);
}
// -----------------------------------------------------------------------------------------------------------------
// Private methods
/**
*
*/
private function _getMessage($msg_id, $receiver_id)
{
$msg = $this->messagelib->getMessage($msg_id, $receiver_id);
if (isError($msg))
{
show_error($msg->retval);
}
elseif (!hasData($msg))
{
show_error('The selected message does not exist');
}
else
{
$msg = $msg->retval[0];
}
return $msg;
}
/**
* Retrieves message vars from view vw_msg_vars
*/
private function _getMsgVarsData($prestudent_id)
{
$this->load->model('system/Message_model', 'MessageModel');
$msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id);
if (isError($msgVarsData))
{
show_error($msgVarsData->retval);
}
return $msgVarsData;
}
}
+129 -87
View File
@@ -9,34 +9,36 @@ class MessageLib
{
const MSG_INDX_PREFIX = 'message_';
private $_ci;
/**
* Constructor
*/
public function __construct()
{
// Get code igniter instance
$this->ci =& get_instance();
$this->_ci =& get_instance();
// Loads message configuration
$this->ci->config->load('message');
$this->_ci->config->load('message');
// CI Parser library
$this->ci->load->library('parser');
$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');
// Loads Mail library
$this->ci->load->library('MailLib');
$this->_ci->load->library('MailLib');
// 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 phrases
$this->ci->lang->load('message');
$this->_ci->lang->load('message');
}
//------------------------------------------------------------------------------------------------------------------
@@ -52,7 +54,7 @@ class MessageLib
if (!is_numeric($person_id))
return $this->_error('', MSG_ERR_INVALID_RECIPIENTS);
$msg = $this->ci->RecipientModel->getMessage($msg_id, $person_id);
$msg = $this->_ci->RecipientModel->getMessage($msg_id, $person_id);
return $msg;
}
@@ -65,7 +67,7 @@ class MessageLib
if (isEmptyString($uid))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
$msg = $this->ci->RecipientModel->getMessagesByUID($uid, $oe_kurzbz, $all);
$msg = $this->_ci->RecipientModel->getMessagesByUID($uid, $oe_kurzbz, $all);
return $msg;
}
@@ -78,7 +80,7 @@ class MessageLib
if (!is_numeric($person_id))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
$msg = $this->ci->RecipientModel->getMessagesByPerson($person_id, $oe_kurzbz, $all);
$msg = $this->_ci->RecipientModel->getMessagesByPerson($person_id, $oe_kurzbz, $all);
return $msg;
}
@@ -91,7 +93,7 @@ class MessageLib
if (!is_numeric($person_id))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
$msg = $this->ci->MessageModel->getMessagesByPerson($person_id, $oe_kurzbz, $all);
$msg = $this->_ci->MessageModel->getMessagesByPerson($person_id, $oe_kurzbz, $all);
return $msg;
}
@@ -104,7 +106,7 @@ class MessageLib
if (isEmptyString($token))
return $this->_error('', MSG_ERR_INVALID_TOKEN);
$result = $this->ci->RecipientModel->getMessageByToken($token);
$result = $this->_ci->RecipientModel->getMessageByToken($token);
if (hasData($result))
{
// Searches for a status that is different from unread
@@ -127,7 +129,7 @@ class MessageLib
'status' => MSG_STATUS_READ
);
$resultIns = $this->ci->MsgStatusModel->insert($statusKey);
$resultIns = $this->_ci->MsgStatusModel->insert($statusKey);
// If an error occured while writing on data base, then return it
if (isError($resultIns))
{
@@ -147,7 +149,7 @@ class MessageLib
if (!is_numeric($person_id))
return $this->_error('', MSG_ERR_INVALID_RECIPIENTS);
$msg = $this->ci->RecipientModel->getCountUnreadMessages($person_id, $oe_kurzbz);
$msg = $this->_ci->RecipientModel->getCountUnreadMessages($person_id, $oe_kurzbz);
return $msg;
}
@@ -175,7 +177,7 @@ class MessageLib
}
// Searches if the status is already present
$result = $this->ci->MsgStatusModel->load(array($message_id, $person_id, $status));
$result = $this->_ci->MsgStatusModel->load(array($message_id, $person_id, $status));
if (hasData($result))
{
// status already present
@@ -189,7 +191,7 @@ class MessageLib
'status' => $status
);
$result = $this->ci->MsgStatusModel->insert($statusKey);
$result = $this->_ci->MsgStatusModel->insert($statusKey);
}
return $result;
@@ -202,7 +204,7 @@ class MessageLib
{
if (!is_numeric($sender_id))
{
$sender_id = $this->ci->config->item('system_person_id');
$sender_id = $this->_ci->config->item('system_person_id');
}
$receivers = $this->_getReceivers($receiver_id, $oe_kurzbz);
@@ -233,7 +235,7 @@ class MessageLib
if (isSuccess($result))
{
// If the system is configured to send messages immediately
if ($this->ci->config->item('send_immediately') === true)
if ($this->_ci->config->item('send_immediately') === true)
{
// Send message by email!
$resultSendEmail = $this->sendOne($result->retval, $subject, $body, $multiPartMime);
@@ -277,7 +279,7 @@ class MessageLib
{
if (!is_numeric($sender_id))
{
$sender_id = $this->ci->config->item('system_person_id');
$sender_id = $this->_ci->config->item('system_person_id');
}
$receivers = $this->_getReceivers($receiver_id, $oe_kurzbz);
@@ -293,7 +295,7 @@ class MessageLib
else
{
// Load reveiver data to get its relative language
$this->ci->load->model('person/Person_model', 'PersonModel');
$this->_ci->load->model('person/Person_model', 'PersonModel');
}
// Looping on receivers
@@ -302,14 +304,14 @@ class MessageLib
$receiver_id = $receivers->retval[$i]->person_id;
// Checks if the receiver exists
$result = $this->ci->PersonModel->load($receiver_id);
$result = $this->_ci->PersonModel->load($receiver_id);
if (hasData($result))
{
// Retrives the language of the logged user
$sprache = getUserLanguage();
// Loads template data
$result = $this->ci->vorlagelib->loadVorlagetext($vorlage_kurzbz, $oe_kurzbz, $orgform_kurzbz, $sprache);
$result = $this->_ci->vorlagelib->loadVorlagetext($vorlage_kurzbz, $oe_kurzbz, $orgform_kurzbz, $sprache);
if (isSuccess($result))
{
// If the text and the subject of the template are not empty
@@ -317,9 +319,9 @@ class MessageLib
!isEmptyString($result->retval[0]->text) && !isEmptyString($result->retval[0]->subject))
{
// Parses template text
$parsedText = $this->ci->vorlagelib->parseVorlagetext($result->retval[0]->text, $data);
$parsedText = $this->_ci->vorlagelib->parseVorlagetext($result->retval[0]->text, $data);
// Parses subject
$subject = $this->ci->vorlagelib->parseVorlagetext($result->retval[0]->subject, $data);
$subject = $this->_ci->vorlagelib->parseVorlagetext($result->retval[0]->subject, $data);
// Save message
$result = $this->_saveMessage($sender_id, $receiver_id, $subject, $parsedText, $relationmessage_id, $oe_kurzbz);
@@ -327,7 +329,7 @@ class MessageLib
if (isSuccess($result))
{
// If the system is configured to send messages immediately
if ($this->ci->config->item('send_immediately') === true)
if ($this->_ci->config->item('send_immediately') === true)
{
// Send message by email!
$resultSendEmail = $this->sendOne($result->retval, $subject, $parsedText, $multiPartMime);
@@ -392,21 +394,21 @@ class MessageLib
$sent = true; // optimistic expectation
// Gets standard configs
$cfg = $this->ci->maillib->getConfigs();
$cfg = $this->_ci->maillib->getConfigs();
$cfg->email_number_to_sent = $numberToSent;
$cfg->email_number_per_time_range = $numberPerTimeRange;
$cfg->email_time_range = $email_time_range;
$cfg->email_from_system = $email_from_system;
// Overrides configs with the parameters
$this->ci->maillib->overrideConfigs($cfg);
$this->_ci->maillib->overrideConfigs($cfg);
// Gets a number ($this->ci->maillib->getMaxEmailToSent()) of unsent messages from DB
// Gets a number ($this->_ci->maillib->getMaxEmailToSent()) of unsent messages from DB
// having EMAIL_KONTAKT_TYPE as relative contact type
$result = $this->ci->RecipientModel->getMessages(
$result = $this->_ci->RecipientModel->getMessages(
EMAIL_KONTAKT_TYPE,
null,
$this->ci->maillib->getConfigs()->email_number_to_sent
$this->_ci->maillib->getConfigs()->email_number_to_sent
);
// Checks if errors were occurred
if (isSuccess($result))
@@ -421,14 +423,14 @@ 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[$i]->token;
$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');
$vorlage = $this->_ci->vorlagelib->loadVorlagetext('MessageMailHTML');
if(hasData($vorlage))
{
// Using a template for the html email body
$body = $this->ci->parser->parse_string(
$body = $this->_ci->parser->parse_string(
$vorlage->retval[0]->text,
array(
'href' => $href,
@@ -441,7 +443,7 @@ class MessageLib
else
{
// Using a template for the html email body
$body = $this->ci->parser->parse(
$body = $this->_ci->parser->parse(
'templates/mailHTML',
array(
'href' => $href,
@@ -453,14 +455,14 @@ class MessageLib
}
if (is_null($body) || $body == '')
{
$this->ci->loglib->logError('Error while parsing the mail template');
$this->_ci->loglib->logError('Error while parsing the mail template');
}
$vorlage = $this->ci->vorlagelib->loadVorlagetext('MessageMailTXT');
$vorlage = $this->_ci->vorlagelib->loadVorlagetext('MessageMailTXT');
if(hasData($vorlage))
{
// Using a template for the plain text email body
$altBody = $this->ci->parser->parse_string(
$altBody = $this->_ci->parser->parse_string(
$vorlage->retval[0]->text,
array(
'href' => $href,
@@ -473,7 +475,7 @@ class MessageLib
else
{
// Using a template for the plain text email body
$altBody = $this->ci->parser->parse(
$altBody = $this->_ci->parser->parse(
'templates/mailTXT',
array(
'href' => $href,
@@ -485,7 +487,7 @@ class MessageLib
}
if (is_null($altBody) || $altBody == '')
{
$this->ci->loglib->logError('Error while parsing the mail template');
$this->_ci->loglib->logError('Error while parsing the mail template');
}
// If the sender is not an employee, then system-sender is used if empty
@@ -502,7 +504,7 @@ class MessageLib
}
// Sending email
$sent = $this->ci->maillib->send(
$sent = $this->_ci->maillib->send(
$sender,
$receiverContact,
$result->retval[$i]->subject,
@@ -515,7 +517,7 @@ class MessageLib
// If errors were occurred while sending the email
if (!$sent)
{
$this->ci->loglib->logError('Error while sending an email');
$this->_ci->loglib->logError('Error while sending an email');
// Writing errors in tbl_msg_recipient
$sme = $this->setMessageError(
$result->retval[$i]->message_id,
@@ -525,7 +527,7 @@ class MessageLib
);
if (!$sme)
{
$this->ci->loglib->logError('Error while updating DB');
$this->_ci->loglib->logError('Error while updating DB');
}
}
else
@@ -535,13 +537,13 @@ class MessageLib
// If some errors occurred
if (!$sent)
{
$this->ci->loglib->logError('Error while updating DB');
$this->_ci->loglib->logError('Error while updating DB');
}
}
}
else
{
$this->ci->loglib->logError('This person does not have an email account');
$this->_ci->loglib->logError('This person does not have an email account');
// Writing errors in tbl_msg_recipient
$sme = $this->setMessageError(
$result->retval[$i]->message_id,
@@ -551,7 +553,7 @@ class MessageLib
);
if (!$sme)
{
$this->ci->loglib->logError('Error while updating DB');
$this->_ci->loglib->logError('Error while updating DB');
}
$sent = true; // Non blocking error
}
@@ -559,13 +561,13 @@ class MessageLib
}
else
{
$this->ci->loglib->logInfo('There are no email to be sent');
$this->_ci->loglib->logInfo('There are no email to be sent');
$sent = false;
}
}
else
{
$this->ci->loglib->logError('Something went wrong while getting data from DB');
$this->_ci->loglib->logError('Something went wrong while getting data from DB');
$sent = false;
}
@@ -580,7 +582,7 @@ class MessageLib
$sent = true; // optimistic expectation
// Get a specific message from DB having EMAIL_KONTAKT_TYPE as relative contact type
$result = $this->ci->RecipientModel->getMessages(
$result = $this->_ci->RecipientModel->getMessages(
EMAIL_KONTAKT_TYPE,
null,
null,
@@ -601,12 +603,12 @@ class MessageLib
if ($multiPartMime === true)
{
// 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;
$href = $this->_ci->config->item('message_server').$this->_ci->config->item('message_html_view_url').$result->retval[0]->token;
$vorlage = $this->ci->vorlagelib->loadVorlagetext('MessageMailHTML');
$vorlage = $this->_ci->vorlagelib->loadVorlagetext('MessageMailHTML');
if(hasData($vorlage))
{
$bodyMsg = $this->ci->parser->parse_string(
$bodyMsg = $this->_ci->parser->parse_string(
$vorlage->retval[0]->text,
array(
'href' => $href,
@@ -618,7 +620,7 @@ class MessageLib
}
else
{
$bodyMsg = $this->ci->parser->parse(
$bodyMsg = $this->_ci->parser->parse(
'templates/mailHTML',
array(
'href' => $href,
@@ -631,14 +633,14 @@ class MessageLib
if (is_null($bodyMsg) || $bodyMsg == '')
{
// $body = $result->retval[0]->body;
$this->ci->loglib->logError('Error while parsing the html mail template');
$this->_ci->loglib->logError('Error while parsing the html mail template');
}
// Using a template for the plain text email body
$vorlage = $this->ci->vorlagelib->loadVorlagetext('MessageMailTXT');
$vorlage = $this->_ci->vorlagelib->loadVorlagetext('MessageMailTXT');
if(hasData($vorlage))
{
$altBody = $this->ci->parser->parse_string(
$altBody = $this->_ci->parser->parse_string(
$vorlage->retval[0]->text,
array(
'href' => $href,
@@ -650,7 +652,7 @@ class MessageLib
}
else
{
$altBody = $this->ci->parser->parse(
$altBody = $this->_ci->parser->parse(
'templates/mailTXT',
array(
'href' => $href,
@@ -662,7 +664,7 @@ class MessageLib
}
if (is_null($altBody) || $altBody == '')
{
$this->ci->loglib->logError('Error while parsing the plain text mail template');
$this->_ci->loglib->logError('Error while parsing the plain text mail template');
}
}
else
@@ -684,7 +686,7 @@ class MessageLib
}
// Sending email
$sent = $this->ci->maillib->send(
$sent = $this->_ci->maillib->send(
null,
$receiverContact,
is_null($subject) ? $result->retval[0]->subject : $subject, // if parameter subject is not null, use it!
@@ -697,7 +699,7 @@ class MessageLib
// If errors were occurred while sending the email
if (!$sent)
{
$this->ci->loglib->logError('Error while sending an email');
$this->_ci->loglib->logError('Error while sending an email');
// Writing errors in tbl_msg_recipient
$sme = $this->setMessageError(
$result->retval[0]->message_id,
@@ -707,7 +709,7 @@ class MessageLib
);
if (!$sme)
{
$this->ci->loglib->logError('Error while updating DB');
$this->_ci->loglib->logError('Error while updating DB');
}
}
else
@@ -717,13 +719,13 @@ class MessageLib
// If the email has been sent and the DB updated
if (!$sent)
{
$this->ci->loglib->logError('Error while updating DB');
$this->_ci->loglib->logError('Error while updating DB');
}
}
}
else
{
$this->ci->loglib->logError('This person does not have an email account');
$this->_ci->loglib->logError('This person does not have an email account');
// Writing errors in tbl_msg_recipient
$sme = $this->setMessageError(
$result->retval[0]->message_id,
@@ -733,20 +735,20 @@ class MessageLib
);
if (!$sme)
{
$this->ci->loglib->logError('Error while updating DB');
$this->_ci->loglib->logError('Error while updating DB');
}
$sent = true; // Non blocking error
}
}
else
{
$this->ci->loglib->logInfo('There are no email to be sent');
$this->_ci->loglib->logInfo('There are no email to be sent');
$sent = false;
}
}
else
{
$this->ci->loglib->logError('Something went wrong while getting data from DB');
$this->_ci->loglib->logError('Something went wrong while getting data from DB');
$sent = false;
}
@@ -758,7 +760,7 @@ class MessageLib
*/
public function parseMessageText($text, $data = array())
{
return $this->ci->parser->parse_string($text, $data, true);
return $this->_ci->parser->parse_string($text, $data, true);
}
/**
@@ -768,7 +770,7 @@ class MessageLib
public function getMessageVarsPerson()
{
$variablesArray = array();
$variables = $this->ci->MessageModel->getMessageVarsPerson();
$variables = $this->_ci->MessageModel->getMessageVarsPerson();
if (hasData($variables))
{
@@ -783,6 +785,46 @@ class MessageLib
return $variablesArray;
}
/**
* A person may belongs to more organisation units
*/
public function getOeKurzbz($sender_id)
{
$oe_kurzbz = array();
$this->_ci->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel');
$benutzerResult = $this->_ci->BenutzerfunktionModel->getByPersonId($sender_id);
if (isError($benutzerResult))
{
show_error($benutzerResult->retval);
}
elseif (hasData($benutzerResult))
{
foreach ($benutzerResult->retval as $val)
{
$oe_kurzbz[] = $val->oe_kurzbz;
}
}
return $oe_kurzbz;
}
/**
* Admin or commoner?
*/
public function getIsAdmin($sender_id)
{
$this->_ci->load->model('system/Benutzerrolle_model', 'BenutzerrolleModel');
$isAdmin = $this->_ci->BenutzerrolleModel->isAdminByPersonId($sender_id);
if (isError($isAdmin))
{
show_error($isAdmin->retval);
}
return $isAdmin->retval;
}
//------------------------------------------------------------------------------------------------------------------
// Private methods
@@ -794,7 +836,7 @@ class MessageLib
$updated = false;
// Updates table tbl_msg_recipient
$resultUpdate = $this->ci->RecipientModel->update(array($receiver_id, $message_id), $parameters);
$resultUpdate = $this->_ci->RecipientModel->update(array($receiver_id, $message_id), $parameters);
// Checks if errors were occurred
if (isSuccess($resultUpdate) && is_array($resultUpdate->retval))
{
@@ -835,13 +877,13 @@ class MessageLib
private function _getReceiversByOekurzbz($oe_kurzbz)
{
// Load Benutzerfunktion_model
$this->ci->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel');
$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');
$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 = '.$this->ci->db->escape($oe_kurzbz).
' AND funktion_kurzbz = '.$this->ci->db->escape($this->ci->config->item('assistent_function')).
$receivers = $this->_ci->BenutzerfunktionModel->loadWhere(
'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()))'
);
@@ -884,8 +926,8 @@ class MessageLib
private function _checkReceiverId($receiver_id)
{
// Load Person_model
$this->ci->load->model('person/Person_model', 'PersonModel');
$result = $this->ci->PersonModel->load($receiver_id);
$this->_ci->load->model('person/Person_model', 'PersonModel');
$result = $this->_ci->PersonModel->load($receiver_id);
if (hasData($result))
{
return true;
@@ -900,7 +942,7 @@ class MessageLib
private function _saveMessage($sender_id, $receiver_id, $subject, $body, $relationmessage_id, $oe_kurzbz)
{
// Starts db transaction
$this->ci->db->trans_start(false);
$this->_ci->db->trans_start(false);
// Save Message
$msgData = array(
@@ -911,7 +953,7 @@ class MessageLib
'relationmessage_id' => $relationmessage_id,
'oe_kurzbz' => $oe_kurzbz
);
$result = $this->ci->MessageModel->insert($msgData);
$result = $this->_ci->MessageModel->insert($msgData);
if (isSuccess($result))
{
// Link the message with the receiver
@@ -921,7 +963,7 @@ class MessageLib
'message_id' => $msg_id,
'token' => generateToken()
);
$result = $this->ci->RecipientModel->insert($recipientData);
$result = $this->_ci->RecipientModel->insert($recipientData);
if (isSuccess($result))
{
// Save message status
@@ -930,20 +972,20 @@ class MessageLib
'person_id' => $receiver_id,
'status' => MSG_STATUS_UNREAD
);
$result = $this->ci->MsgStatusModel->insert($statusData);
$result = $this->_ci->MsgStatusModel->insert($statusData);
}
}
$this->ci->db->trans_complete();
$this->_ci->db->trans_complete();
if ($this->ci->db->trans_status() === false || isError($result))
if ($this->_ci->db->trans_status() === false || isError($result))
{
$this->ci->db->trans_rollback();
$this->_ci->db->trans_rollback();
$result = $this->_error($result->msg, EXIT_ERROR);
}
else
{
$this->ci->db->trans_commit();
$this->_ci->db->trans_commit();
$result = $this->_success($msg_id);
}
+96 -89
View File
@@ -19,27 +19,27 @@ $this->load->view(
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h3 class="page-header"><?php echo ucfirst($this->p->t('ui', 'nachrichtSenden')) ?></h3>
<h3 class="page-header"><?php echo ucfirst($this->p->t('ui', 'nachrichtSenden')); ?></h3>
</div>
</div>
<form id="sendForm" method="post" action="<?php echo site_url('/system/Messages/send'); ?>">
<div class="row">
<div class="form-group">
<div class="col-lg-1 msgfieldcol-left">
<label><?php echo ucfirst($this->p->t('global', 'empfaenger')) . ':'?></label>
<label><?php echo ucfirst($this->p->t('global', 'empfaenger')).':'; ?></label>
</div>
<div class="col-lg-11 msgfieldcol-right">
<?php
for ($i = 0; $i < count($receivers); $i++)
{
$receiver = $receivers[$i];
// Every 10 recipients a new line
if ($i > 1 && $i % 10 == 0)
for ($i = 0; $i < count($recipients); $i++)
{
echo '<br>';
$receiver = $recipients[$i];
// Every 10 recipients a new line
if ($i > 1 && $i % 10 == 0)
{
echo '<br>';
}
echo $receiver->Vorname." ".$receiver->Nachname."; ";
}
echo $receiver->Vorname." ".$receiver->Nachname."; ";
}
?>
</div>
</div>
@@ -47,123 +47,130 @@ $this->load->view(
<div class="row">
<div class="form-group">
<div class="col-lg-1 msgfield msgfieldcol-left">
<label><?php echo ucfirst($this->p->t('global', 'betreff')) . ':'?></label>
<label><?php echo ucfirst($this->p->t('global', 'betreff')).':'; ?></label>
</div>&nbsp;
<?php
$subject = '';
if (isset($message))
{
$subject = 'Re: '.$message->subject;
}
$subject = '';
if (isset($message))
{
$subject = 'Re: '.$message->subject;
}
?>
<div class="col-lg-7">
<input id="subject" class="form-control" type="text" value="<?php echo $subject; ?>"
name="subject">
<input id="subject" class="form-control" type="text" value="<?php echo $subject; ?>" name="subject">
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-10">
<label><?php echo ucfirst($this->p->t('global', 'nachricht')) . ':'?></label>
<label><?php echo ucfirst($this->p->t('global', 'nachricht')).':'; ?></label>
<?php
$body = '';
if (isset($message))
{
$body = $message->body;
}
$body = '';
if (isset($message))
{
$body = $message->body;
}
?>
<textarea id="bodyTextArea" name="body"><?php echo $body; ?></textarea>
</div>
<?php
if (isset($variables)):
?>
<div class="col-lg-2">
<div class="form-group">
<label><?php echo ucfirst($this->p->t('ui', 'felder')) . ':'?></label>
<select id="variables" class="form-control" size="14" multiple="multiple">
<?php
foreach ($variables as $key => $val)
{
?>
<option value="<?php echo $key; ?>"><?php echo $val; ?></option>
if (isset($variables))
{
?>
<div class="col-lg-2">
<div class="form-group">
<label><?php echo ucfirst($this->p->t('ui', 'felder')).':'; ?></label>
<select id="variables" class="form-control" size="14" multiple="multiple">
<?php
}
?>
</select>
foreach ($variables as $key => $val)
{
?>
<option value="<?php echo $key; ?>"><?php echo $val; ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<?php endif; ?>
<?php
}
?>
</div>
<br>
<div class="row">
<div class="col-xs-3">
<?php
echo $this->widgetlib->widget(
'Vorlage_widget',
array('oe_kurzbz' => $oe_kurzbz, 'isAdmin' => $isAdmin),
array('name' => 'vorlage', 'id' => 'vorlageDnD')
);
echo $this->widgetlib->widget(
'Vorlage_widget',
array('oe_kurzbz' => $oe_kurzbz, 'isAdmin' => $isAdmin),
array('name' => 'vorlage', 'id' => 'vorlageDnD')
);
?>
</div>
<div class="col-lg-7 col-xs-9 text-right">
<button id="sendButton" class="btn btn-default" type="button"><?php echo $this->p->t('ui', 'senden')?></button>
<button id="sendButton" class="btn btn-default" type="button"><?php echo $this->p->t('ui', 'senden'); ?></button>
</div>
</div>
<?php if (isset($receivers) && count($receivers) > 0): ?>
<hr>
<div class="row">
<div class="col-lg-12">
<label><?php echo ucfirst($this->p->t('global', 'vorschau')) . ':'?></label>
</div>
</div>
<div class="well">
<?php
if (isset($recipients) && count($recipients) > 0)
{
?>
<hr>
<div class="row">
<div class="col-lg-5">
<div class="form-grop form-inline">
<label><?php echo ucfirst($this->p->t('global', 'empfaenger')) . ': ' ?></label>
<select id="recipients">
<?php
if (count($receivers) > 1)
echo '<option value="-1">Select...</option>';
foreach ($receivers as $receiver)
{
?>
<option value="<?php echo $receiver->person_id; ?>"><?php echo $receiver->Vorname." ".$receiver->Nachname; ?></option>
<div class="col-lg-12">
<label><?php echo ucfirst($this->p->t('global', 'vorschau')).':'; ?></label>
</div>
</div>
<div class="well">
<div class="row">
<div class="col-lg-5">
<div class="form-grop form-inline">
<label><?php echo ucfirst($this->p->t('global', 'empfaenger')).': '; ?></label>
<select id="recipients">
<?php
}
?>
</select>
&nbsp;
<strong><a href="#" id="refresh">Refresh</a></strong>
if (count($recipients) > 1)
echo '<option value="-1">Select...</option>';
foreach ($recipients as $receiver)
{
?>
<option value="<?php echo $receiver->person_id; ?>">
<?php echo $receiver->Vorname." ".$receiver->Nachname; ?>
</option>
<?php
}
?>
</select>
&nbsp;
<strong><a href="#" id="refresh">Refresh</a></strong>
</div>
</div>
<div class="col-lg-2">
</div>
</div>
<div class="col-lg-2">
</div>
<br>
<textarea id="tinymcePreview"></textarea>
</div>
<br>
<textarea id="tinymcePreview"></textarea>
</div>
<?php
endif;
<?php
}
?>
<?php
for ($i = 0; $i < count($receivers); $i++)
{
echo '<input type="hidden" name="persons[]" value="'.$receiver->person_id.'">'."\n";
}
for ($i = 0; $i < count($recipients); $i++)
{
echo '<input type="hidden" name="persons[]" value="'.$receiver->person_id.'">'."\n";
}
?>
<?php
if (isset($message))
{
?>
<input type="hidden" name="relationmessage_id" value="<?php echo $message->message_id; ?>">
<?php
}
if (isset($message))
{
?>
<input type="hidden" name="relationmessage_id" value="<?php echo $message->message_id; ?>">
<?php
}
?>
</form>
+191 -191
View File
@@ -1,191 +1,191 @@
<?php
/* Copyright (C) 2016 fhcomplete.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at>
*/
require_once('../config/vilesci.config.inc.php');
?>
// ********** FUNKTIONEN ********** //
var MessagePersonID=null;
var MessagesTreeDatasource=''; // Datasource des Adressen Trees
var MessagesSelectID='';
var MessageSenderPersonID='';
var MessageIFrameIsInitialized=false;
var MessagesTreeSinkObserver =
{
onBeginLoad : function(pSink) {},
onInterrupt : function(pSink) {},
onResume : function(pSink) {},
onError : function(pSink, pStatus, pError) {},
onEndLoad : function(pSink)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
document.getElementById('messages-tree').builder.rebuild();
}
};
var MessagesTreeListener =
{
willRebuild : function(builder) { },
didRebuild : function(builder)
{
//timeout nur bei Mozilla notwendig da sonst die rows
//noch keine values haben. Ab Seamonkey funktionierts auch
//ohne dem setTimeout
//window.setTimeout(KontaktAdressenTreeSelectID,10);
}
};
// ****
// * Laedt die Trees
// ****
function loadMessages(person_id, fas_person_id)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
MessagePersonID = person_id;
MessageSenderPersonID=fas_person_id;
//Adressen laden
url = "<?php echo APP_ROOT; ?>rdf/messages.rdf.php?person_id="+person_id+"&"+gettimestamp();
var tree=document.getElementById('messages-tree');
try
{
MessagesTreeDatasource.removeXMLSinkObserver(MessagesTreeSinkObserver);
tree.builder.removeListener(MessagesTreeListener);
}
catch(e)
{}
//Alte DS entfernen
var oldDatasources = tree.database.GetDataSources();
while(oldDatasources.hasMoreElements())
{
tree.database.RemoveDataSource(oldDatasources.getNext());
}
var rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
MessagesTreeDatasource = rdfService.GetDataSource(url);
MessagesTreeDatasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
MessagesTreeDatasource.QueryInterface(Components.interfaces.nsIRDFXMLSink);
tree.database.AddDataSource(MessagesTreeDatasource);
MessagesTreeDatasource.addXMLSinkObserver(MessagesTreeSinkObserver);
tree.builder.addListener(MessagesTreeListener);
}
// ****
// * Zeigt HTML Seite zum Erstellen neuer Nachrichten
// ****
function MessagesNewMessage()
{
var tree = parent.document.getElementById('student-tree');
if (tree.currentIndex == -1)
{
alert("Bitte markieren Sie zuerst eine Person");
}
else
{
var prestudentIdArray = getMultipleTreeCellText(tree, 'student-treecol-prestudent_id');
var action = '<?php echo APP_ROOT ?>index.ci.php/system/FASMessages/write/' + MessageSenderPersonID;
openWindowPostArray(action, 'prestudent_id', prestudentIdArray);
}
}
/**
* Oeffnet Nachrichtenseite um eine Antwort auf eine Nachricht zu schicken
*/
function MessagesSendAnswer()
{
var messagesTree = document.getElementById('messages-tree');
var studentsTree = parent.document.getElementById('student-tree');
if (messagesTree.currentIndex == -1)
{
alert("Bitte markieren Sie zuerst eine Nachricht");
}
else
{
var MessageId = getTreeCellText(messagesTree, 'messages-tree-message_id', messagesTree.currentIndex);
var RecipientID = getTreeCellText(messagesTree, 'messages-tree-recipient_id', messagesTree.currentIndex);
var prestudentIdArray = new Array(getTreeCellText(studentsTree, 'student-treecol-prestudent_id', studentsTree.currentIndex));
var action = '<?php echo APP_ROOT ?>index.ci.php/system/FASMessages/write/' + MessageSenderPersonID + '/' + MessageId + '/' + RecipientID;
openWindowPostArray(action, 'prestudent_id', prestudentIdArray);
}
}
function MessageAuswahl()
{
var tree=document.getElementById('messages-tree');
if(tree.currentIndex==-1)
{
alert("Bitte markieren Sie zuerst eine Nachricht");
}
else
{
var text = getTreeCellText(tree, 'messages-tree-body', tree.currentIndex);
var recipient_id = getTreeCellText(tree, 'messages-tree-recipient_id', tree.currentIndex);
// Antworten ist nur moeglich wenn die Message vom User kommt
if(recipient_id==MessagePersonID)
{
document.getElementById('messages-tree-popup-answer').disabled=true;
document.getElementById('messages-button-answer').disabled=true;
}
else
{
document.getElementById('messages-tree-popup-answer').disabled=false;
document.getElementById('messages-button-answer').disabled=false;
}
}
MessagesIFrameSetHTML(text);
}
function MessagesIFrameSetHTML(val)
{
MessageIFrameInit();
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
editor = document.getElementById('message-wysiwyg');
if(editor.contentWindow.document.body.innerHTML!='')
{
//Inhalt leeren
editor.contentDocument.execCommand("selectall", false, null);
editor.contentDocument.execCommand("delete", false, null);
}
//Value setzen
if(val!='')
editor.contentDocument.execCommand("inserthtml", false, val);
}
function MessageIFrameInit()
{
if(!MessageIFrameIsInitialized)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
editor = document.getElementById('message-wysiwyg');
editor.contentDocument.designMode = 'on';
editor.style.backgroundColor="#FFFFFF";
MessageIFrameIsInitialized=true;
}
}
<?php
/* Copyright (C) 2016 fhcomplete.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at>
*/
require_once('../config/vilesci.config.inc.php');
?>
// ********** FUNKTIONEN ********** //
var MessagePersonID=null;
var MessagesTreeDatasource=''; // Datasource des Adressen Trees
var MessagesSelectID='';
var MessageSenderPersonID='';
var MessageIFrameIsInitialized=false;
var MessagesTreeSinkObserver =
{
onBeginLoad : function(pSink) {},
onInterrupt : function(pSink) {},
onResume : function(pSink) {},
onError : function(pSink, pStatus, pError) {},
onEndLoad : function(pSink)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
document.getElementById('messages-tree').builder.rebuild();
}
};
var MessagesTreeListener =
{
willRebuild : function(builder) { },
didRebuild : function(builder)
{
//timeout nur bei Mozilla notwendig da sonst die rows
//noch keine values haben. Ab Seamonkey funktionierts auch
//ohne dem setTimeout
//window.setTimeout(KontaktAdressenTreeSelectID,10);
}
};
// ****
// * Laedt die Trees
// ****
function loadMessages(person_id, fas_person_id)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
MessagePersonID = person_id;
MessageSenderPersonID=fas_person_id;
//Adressen laden
url = "<?php echo APP_ROOT; ?>rdf/messages.rdf.php?person_id="+person_id+"&"+gettimestamp();
var tree=document.getElementById('messages-tree');
try
{
MessagesTreeDatasource.removeXMLSinkObserver(MessagesTreeSinkObserver);
tree.builder.removeListener(MessagesTreeListener);
}
catch(e)
{}
//Alte DS entfernen
var oldDatasources = tree.database.GetDataSources();
while(oldDatasources.hasMoreElements())
{
tree.database.RemoveDataSource(oldDatasources.getNext());
}
var rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
MessagesTreeDatasource = rdfService.GetDataSource(url);
MessagesTreeDatasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
MessagesTreeDatasource.QueryInterface(Components.interfaces.nsIRDFXMLSink);
tree.database.AddDataSource(MessagesTreeDatasource);
MessagesTreeDatasource.addXMLSinkObserver(MessagesTreeSinkObserver);
tree.builder.addListener(MessagesTreeListener);
}
// ****
// * Zeigt HTML Seite zum Erstellen neuer Nachrichten
// ****
function MessagesNewMessage()
{
var tree = parent.document.getElementById('student-tree');
if (tree.currentIndex == -1)
{
alert("Bitte markieren Sie zuerst eine Person");
}
else
{
var prestudentIdArray = getMultipleTreeCellText(tree, 'student-treecol-prestudent_id');
var action = '<?php echo APP_ROOT ?>index.ci.php/system/FASMessages/write/' + MessageSenderPersonID;
openWindowPostArray(action, 'prestudent_id', prestudentIdArray);
}
}
/**
* Oeffnet Nachrichtenseite um eine Antwort auf eine Nachricht zu schicken
*/
function MessagesSendAnswer()
{
var messagesTree = document.getElementById('messages-tree');
var studentsTree = parent.document.getElementById('student-tree');
if (messagesTree.currentIndex == -1)
{
alert("Bitte markieren Sie zuerst eine Nachricht");
}
else
{
var MessageId = getTreeCellText(messagesTree, 'messages-tree-message_id', messagesTree.currentIndex);
var RecipientID = getTreeCellText(messagesTree, 'messages-tree-recipient_id', messagesTree.currentIndex);
var prestudentIdArray = new Array(getTreeCellText(studentsTree, 'student-treecol-prestudent_id', studentsTree.currentIndex));
var action = '<?php echo APP_ROOT ?>index.ci.php/system/FASMessages/writeReply/' + MessageSenderPersonID + '/' + MessageId + '/' + RecipientID;
openWindowPostArray(action, 'prestudent_id', prestudentIdArray);
}
}
function MessageAuswahl()
{
var tree=document.getElementById('messages-tree');
if (tree.currentIndex == -1)
{
alert("Bitte markieren Sie zuerst eine Nachricht");
}
else
{
var text = getTreeCellText(tree, 'messages-tree-body', tree.currentIndex);
var recipient_id = getTreeCellText(tree, 'messages-tree-recipient_id', tree.currentIndex);
// Antworten ist nur moeglich wenn die Message vom User kommt
if (recipient_id == MessagePersonID)
{
document.getElementById('messages-tree-popup-answer').disabled=true;
document.getElementById('messages-button-answer').disabled=true;
}
else
{
document.getElementById('messages-tree-popup-answer').disabled=false;
document.getElementById('messages-button-answer').disabled=false;
}
}
MessagesIFrameSetHTML(text);
}
function MessagesIFrameSetHTML(val)
{
MessageIFrameInit();
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
editor = document.getElementById('message-wysiwyg');
if(editor.contentWindow.document.body.innerHTML!='')
{
//Inhalt leeren
editor.contentDocument.execCommand("selectall", false, null);
editor.contentDocument.execCommand("delete", false, null);
}
//Value setzen
if(val!='')
editor.contentDocument.execCommand("inserthtml", false, val);
}
function MessageIFrameInit()
{
if(!MessageIFrameIsInitialized)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
editor = document.getElementById('message-wysiwyg');
editor.contentDocument.designMode = 'on';
editor.style.backgroundColor="#FFFFFF";
MessageIFrameIsInitialized=true;
}
}