diff --git a/application/controllers/system/FASMessages.php b/application/controllers/system/FASMessages.php index 29a9a2a31..60f961c8b 100644 --- a/application/controllers/system/FASMessages.php +++ b/application/controllers/system/FASMessages.php @@ -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; + } } diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 6c2dfd4f2..e59f45d2d 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -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); } diff --git a/application/views/system/messageWrite.php b/application/views/system/messageWrite.php index ef41b24bd..af83ad9a2 100644 --- a/application/views/system/messageWrite.php +++ b/application/views/system/messageWrite.php @@ -19,27 +19,27 @@ $this->load->view(
- +
- +
1 && $i % 10 == 0) + for ($i = 0; $i < count($recipients); $i++) { - echo '
'; + $receiver = $recipients[$i]; + // Every 10 recipients a new line + if ($i > 1 && $i % 10 == 0) + { + echo '
'; + } + echo $receiver->Vorname." ".$receiver->Nachname."; "; } - echo $receiver->Vorname." ".$receiver->Nachname."; "; - } ?>
@@ -47,123 +47,130 @@ $this->load->view(
- +
  subject; - } + $subject = ''; + if (isset($message)) + { + $subject = 'Re: '.$message->subject; + } ?>
- +

- + body; - } + $body = ''; + if (isset($message)) + { + $body = $message->body; + } ?>
-
-
- - - + foreach ($variables as $key => $val) + { + ?> + + + +
-
- +

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') + ); ?>
- +
- 0): ?> -
-
-
- -
-
-
+ 0) + { + ?> +
-
-
- - - -   - Refresh + if (count($recipients) > 1) + echo ''; + + foreach ($recipients as $receiver) + { + ?> + + + +   + Refresh +
+
+
+
-
- -
+
+
-
- -
- person_id.'">'."\n"; - } + for ($i = 0; $i < count($recipients); $i++) + { + echo ''."\n"; + } ?> - - + + diff --git a/content/messages.js.php b/content/messages.js.php index e98985c0c..fae1db4ba 100644 --- a/content/messages.js.php +++ b/content/messages.js.php @@ -1,191 +1,191 @@ - - */ -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 = "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 = '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 = '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; - } -} + + */ +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 = "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 = '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 = '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; + } +}