diff --git a/application/controllers/system/FASMessages.php b/application/controllers/system/FASMessages.php new file mode 100644 index 000000000..29a9a2a31 --- /dev/null +++ b/application/controllers/system/FASMessages.php @@ -0,0 +1,117 @@ + 'basis/message:rw' + ) + ); + + // Loads the message library + $this->load->library('MessageLib'); + + // 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', + 'ui' + ) + ); + } + + /** + * Write + */ + public function write($sender_id = null, $msg_id = null, $receiver_id = null) + { + $prestudent_id = $this->input->post('prestudent_id'); + $oe_kurzbz = array(); // a person may belongs to more organisation units + $msg = null; + + 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; + } + } + + // 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); + } + + // 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; + } + } + + // Admin or commoner? + $this->load->model('system/Benutzerrolle_model', 'BenutzerrolleModel'); + $isAdmin = $this->BenutzerrolleModel->isAdminByPersonId($sender_id); + if (isError($isAdmin)) + { + show_error($isAdmin->retval); + } + + $data = array ( + 'sender_id' => $sender_id, + 'receivers' => $msgVarsData->retval, + 'message' => $msg, + 'variables' => $variablesArray, + 'oe_kurzbz' => $oe_kurzbz, // used to get the templates + 'isAdmin' => $isAdmin->retval, + 'personOnly' => false // indicates if sent only to persons + ); + + $this->load->view('system/messageWrite', $data); + } +} diff --git a/application/controllers/system/Messages.php b/application/controllers/system/Messages.php index d197f8458..27c029d20 100644 --- a/application/controllers/system/Messages.php +++ b/application/controllers/system/Messages.php @@ -4,8 +4,6 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); class Messages extends Auth_Controller { - private $uid; // contains the UID of the logged user - /** * */ @@ -28,43 +26,37 @@ class Messages 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', - 'person', - 'lehre', - 'ui', - 'infocenter' + 'ui' ) ); - - $this->_setAuthUID(); // sets property uid } + // ----------------------------------------------------------------------------------------------------------------- + // Public methods + /** - * write + * Write */ - public function write($sender_id = null, $msg_id = null, $receiver_id = null) + public function write() { - if ($sender_id === null) + $sender_id = null; + $recipients = $this->input->post('person_id'); + + $authUser = $this->PersonModel->getByUid(getAuthUID()); + if (isError($authUser)) { - $user_person = $this->PersonModel->getByUid($this->uid); - - if (isError($user_person)) - { - show_error($user_person->retval); - } - $sender_id = $user_person->retval[0]->person_id; + show_error($authUser->retval); + } + elseif (hasData($authUser)) + { + $sender_id = $authUser->retval[0]->person_id; } - - $prestudent_id = $this->input->post('prestudent_id'); - $person_id = $this->input->post('person_id'); - $personOnly = false; - - if (isset($person_id) && !isset($prestudent_id)) - $personOnly = true; $msg = null; @@ -87,10 +79,8 @@ class Messages extends Auth_Controller // Get variables $this->load->model('system/Message_model', 'MessageModel'); - if ($personOnly === true) - $this->getPersonMsgData($person_id, $variablesArray, $msgVarsData); - else - $this->getPrestudentMsgData($prestudent_id, $variablesArray, $msgVarsData); + + $this->getPersonMsgData($person_id, $variablesArray, $msgVarsData); // Organisation units used to get the templates $oe_kurzbz = array(); // A person can have more organisation units @@ -122,69 +112,7 @@ class Messages extends Auth_Controller 'personOnly' => $personOnly//indicates if sent only to persons ); - $v = $this->load->view('system/messageWrite', $data); - } - - /** - * gets Message Variables and their data for Prestudent - * @param $prestudent_id - * @param $variablesArray to be filled with variable names - * @param $msgVarsData to be filled with variable data - */ - private function getPrestudentMsgData($prestudent_id, &$variablesArray, &$msgVarsData) - { - $msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); - if ($msgVarsData->error) - { - show_error($msgVarsData->retval); - } - - if (!hasData($variables = $this->MessageModel->getMessageVars())) - { - unset($variables); - } - else - { - $variablesArray = array(); - // Skip person_id and prestudent_id - for ($i = 2; $i < count($variables->retval); $i++) - { - $variablesArray['{'.str_replace(" ", "_", strtolower($variables->retval[$i])).'}'] = $variables->retval[$i]; - } - } - - array_shift($variables->retval); // Remove person_id - array_shift($variables->retval); // Remove prestudent_id - } - - /** - * gets Message Variables and their data for Person - * @param $person_id - * @param $variablesArray to be filled with variable names - * @param $msgVarsData to be filled with variable data - */ - private function getPersonMsgData($person_id, &$variablesArray, &$msgVarsData) - { - $msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($person_id); - if ($msgVarsData->error) - { - show_error($msgVarsData->retval); - } - - if (!hasData($variables = $this->MessageModel->getMessageVarsPerson())) - { - unset($variables); - } - else - { - $variablesArray = array(); - // Skip person_id - for ($i = 1; $i < count($variables->retval); $i++) - { - $variablesArray['{'.str_replace(" ", "_", strtolower($variables->retval[$i])).'}'] = $variables->retval[$i]; - } - array_shift($variables->retval); // Remove person_id - } + $this->load->view('system/messageWrite', $data); } /** @@ -226,7 +154,7 @@ class Messages extends Auth_Controller { if ($sender_id === null) { - $user_person = $this->PersonModel->getByUid($this->uid); + $user_person = $this->PersonModel->getByUid(getAuthUID()); if (!hasData($user_person)) { @@ -326,7 +254,7 @@ class Messages extends Auth_Controller 'kommunikation', 'core', null, - $this->uid + getAuthUID() ); } @@ -334,40 +262,6 @@ class Messages extends Auth_Controller } } - /** - * getPersonId - */ - private function getPersonId() - { - $person_id = null; - - if ($this->input->get('person_id') !== null) - { - $person_id = $this->input->get('person_id'); - } - elseif ($this->input->post('person_id') !== null) - { - $person_id = $this->input->get('person_id'); - } - - if (!is_numeric($person_id)) - { - show_error('Person_id is not numeric'); - } - - return $person_id; - } - - /** - * Retrieve the UID of the logged user and checks if it is valid - */ - private function _setAuthUID() - { - $this->uid = getAuthUID(); - - if (!$this->uid) show_error('User authentification failed'); - } - /** * getVorlage */ @@ -440,4 +334,92 @@ class Messages extends Auth_Controller ->set_output(json_encode(array($msg->retval[0]))); } + // ----------------------------------------------------------------------------------------------------------------- + // Private methods + + /** + * gets Message Variables and their data for Prestudent + * @param $prestudent_id + * @param $variablesArray to be filled with variable names + * @param $msgVarsData to be filled with variable data + */ + private function getPrestudentMsgData($prestudent_id, &$variablesArray, &$msgVarsData) + { + $msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); + if ($msgVarsData->error) + { + show_error($msgVarsData->retval); + } + + if (!hasData($variables = $this->MessageModel->getMessageVars())) + { + unset($variables); + } + else + { + $variablesArray = array(); + // Skip person_id and prestudent_id + for ($i = 2; $i < count($variables->retval); $i++) + { + $variablesArray['{'.str_replace(" ", "_", strtolower($variables->retval[$i])).'}'] = $variables->retval[$i]; + } + } + + array_shift($variables->retval); // Remove person_id + array_shift($variables->retval); // Remove prestudent_id + } + + /** + * gets Message Variables and their data for Person + * @param $person_id + * @param $variablesArray to be filled with variable names + * @param $msgVarsData to be filled with variable data + */ + private function getPersonMsgData($person_id, &$variablesArray, &$msgVarsData) + { + $msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($person_id); + if ($msgVarsData->error) + { + show_error($msgVarsData->retval); + } + + if (!hasData($variables = $this->MessageModel->getMessageVarsPerson())) + { + unset($variables); + } + else + { + $variablesArray = array(); + // Skip person_id + for ($i = 1; $i < count($variables->retval); $i++) + { + $variablesArray['{'.str_replace(" ", "_", strtolower($variables->retval[$i])).'}'] = $variables->retval[$i]; + } + array_shift($variables->retval); // Remove person_id + } + } + + /** + * getPersonId + */ + private function getPersonId() + { + $person_id = null; + + if ($this->input->get('person_id') !== null) + { + $person_id = $this->input->get('person_id'); + } + elseif ($this->input->post('person_id') !== null) + { + $person_id = $this->input->get('person_id'); + } + + if (!is_numeric($person_id)) + { + show_error('Person_id is not numeric'); + } + + return $person_id; + } } diff --git a/application/controllers/system/infocenter/InfoCenter.php b/application/controllers/system/infocenter/InfoCenter.php index 65a6aec07..6799cd445 100644 --- a/application/controllers/system/infocenter/InfoCenter.php +++ b/application/controllers/system/infocenter/InfoCenter.php @@ -1154,8 +1154,6 @@ class InfoCenter extends Auth_Controller show_error($user_person->retval); } - $messagelink = site_url('/system/Messages/write/'.$user_person->retval[0]->person_id); - $data = array ( 'lockedby' => $lockedby, 'lockedbyother' => $lockedbyother, @@ -1165,8 +1163,7 @@ class InfoCenter extends Auth_Controller 'messages' => $messages->retval, 'logs' => $logs, 'notizen' => $notizen->retval, - 'notizenbewerbung' => $notizen_bewerbung->retval, - 'messagelink' => $messagelink + 'notizenbewerbung' => $notizen_bewerbung->retval ); return $data; diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 45ccce876..6c2dfd4f2 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -39,6 +39,9 @@ class MessageLib $this->ci->lang->load('message'); } + //------------------------------------------------------------------------------------------------------------------ + // Public methods + /** * getMessage() - returns the specified received message for a specified person */ @@ -750,7 +753,37 @@ class MessageLib return $sent; } - // ------------------------------------------------------------------------ + /** + * parseMessageText + */ + public function parseMessageText($text, $data = array()) + { + return $this->ci->parser->parse_string($text, $data, true); + } + + /** + * Gets data for Person from view vw_msg_vars_person + * @param $person_id + */ + public function getMessageVarsPerson() + { + $variablesArray = array(); + $variables = $this->ci->MessageModel->getMessageVarsPerson(); + + if (hasData($variables)) + { + // Skip person_id + for ($i = 1; $i < count($variables->retval); $i++) + { + $variablesArray['{'.str_replace(' ', '_', strtolower($variables->retval[$i])).'}'] = $variables->retval[$i]; + } + array_shift($variables->retval); // Remove person_id + } + + return $variablesArray; + } + + //------------------------------------------------------------------------------------------------------------------ // Private methods /** @@ -932,12 +965,4 @@ class MessageLib { return success($retval, $code, MessageLib::MSG_INDX_PREFIX); } - - /** - * - */ - public function parseMessageText($text, $data = array()) - { - return $this->ci->parser->parse_string($text, $data, true); - } } diff --git a/application/views/system/infocenter/stammdaten.php b/application/views/system/infocenter/stammdaten.php index 08058f099..2b481692e 100644 --- a/application/views/system/infocenter/stammdaten.php +++ b/application/views/system/infocenter/stammdaten.php @@ -66,7 +66,7 @@ - kontakte as $kontakt): ?> @@ -113,12 +113,11 @@
-
- -  p->t('ui','nachrichtSenden') ?> + + + +  p->t('ui','nachrichtSenden'); ?> +
zugangscode)): ?> diff --git a/application/views/system/messageWrite.php b/application/views/system/messageWrite.php index e53872ac4..ef41b24bd 100644 --- a/application/views/system/messageWrite.php +++ b/application/views/system/messageWrite.php @@ -9,311 +9,167 @@ $this->load->view( 'tinymce' => true, 'sbadmintemplate' => true, 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/messageWrite.css'), - 'customJSs' => array('public/js/bootstrapper.js') + 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/messageWrite.js') ) ); ?> - -
-
-
-
-
- -
-
-
+
+
+
-
-
- -
-
- 1 && $i % 10 == 0) +
+ +
+
+ +
+
+
+ +
+
+ '; - } - echo $receiver->Vorname." ".$receiver->Nachname."; "; - } - ?> -
-
-
-
-
-
- -
  - subject; - } - ?> -
- -
-
-
-
-
-
- - body; - } - ?> - -
- -
-
- - + echo $receiver->Vorname." ".$receiver->Nachname."; "; + } + ?>
- -
-
-
-
- widgetlib->widget( - 'Vorlage_widget', - array('oe_kurzbz' => $oe_kurzbz, 'isAdmin' => $isAdmin), - array('name' => 'vorlage', 'id' => 'vorlageDnD') - ); - ?>
-
- -
-
- 0): ?> -
-
- +
+
+ +
  + subject; + } + ?> +
+ +
-
-
-
-
- - +
+ +
+
+ + -   - Refresh
-
- + +
+
+
+
+ widgetlib->widget( + 'Vorlage_widget', + array('oe_kurzbz' => $oe_kurzbz, 'isAdmin' => $isAdmin), + array('name' => 'vorlage', 'id' => 'vorlageDnD') + ); + ?> +
+
+ +
+
+ 0): ?> +
+
+
+
-
- -
- +
+
+
+
+ + '."\n"; - } - ?> + foreach ($receivers as $receiver) + { + ?> + + + +   + Refresh +
+
+
- +
+
+ +
+ - - - + person_id.'">'."\n"; + } + ?> + + + + + + +
-
- - load->view("templates/FHC-Footer"); ?> diff --git a/content/fasoverlay.js.php b/content/fasoverlay.js.php index a4a2c4347..7f299f41d 100644 --- a/content/fasoverlay.js.php +++ b/content/fasoverlay.js.php @@ -1230,7 +1230,7 @@ function MessageNew() { var prestudentIdArray = getMultipleTreeCellText(tree, 'student-treecol-prestudent_id'); - var action = 'index.ci.php/system/Messages/write/' + person_id; ?>; + var action = 'index.ci.php/system/FASMessages/write/' + person_id; ?>; openWindowPostArray(action, 'prestudent_id', prestudentIdArray); } diff --git a/content/messages.js.php b/content/messages.js.php index e61108eb6..e98985c0c 100644 --- a/content/messages.js.php +++ b/content/messages.js.php @@ -104,7 +104,7 @@ function MessagesNewMessage() { var prestudentIdArray = getMultipleTreeCellText(tree, 'student-treecol-prestudent_id'); - var action = 'index.ci.php/system/Messages/write/' + MessageSenderPersonID; + var action = 'index.ci.php/system/FASMessages/write/' + MessageSenderPersonID; openWindowPostArray(action, 'prestudent_id', prestudentIdArray); } @@ -128,7 +128,7 @@ function MessagesSendAnswer() 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/Messages/write/' + MessageSenderPersonID + '/' + MessageId + '/' + RecipientID; + var action = 'index.ci.php/system/FASMessages/write/' + MessageSenderPersonID + '/' + MessageId + '/' + RecipientID; openWindowPostArray(action, 'prestudent_id', prestudentIdArray); } @@ -188,4 +188,4 @@ function MessageIFrameInit() editor.style.backgroundColor="#FFFFFF"; MessageIFrameIsInitialized=true; } -} \ No newline at end of file +} diff --git a/public/js/infocenter/infocenterPersonDataset.js b/public/js/infocenter/infocenterPersonDataset.js index d4dbd5bad..641bc7c42 100644 --- a/public/js/infocenter/infocenterPersonDataset.js +++ b/public/js/infocenter/infocenterPersonDataset.js @@ -27,7 +27,7 @@ var InfocenterPersonDataset = { appendTableActionsHtml: function() { var currurl = window.location.href; - var url = currurl.replace(/infocenter\/InfoCenter(.*)/, "Messages/write"); + var url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + "/system/Messages/write"; var formHtml = '
'; $("#datasetActionsTop").before(formHtml); diff --git a/public/js/messaging/messageWrite.js b/public/js/messaging/messageWrite.js new file mode 100644 index 000000000..17f73c51e --- /dev/null +++ b/public/js/messaging/messageWrite.js @@ -0,0 +1,127 @@ +const CONTROLLER_URL = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + "/system/Messages"; + +function tinymcePreviewSetContent() +{ + if ($("#tinymcePreview")) + { + if ($("#recipients").children(":selected").val() > -1) + { + parseMessageText($("#recipients").children(":selected").val(), tinyMCE.get("bodyTextArea").getContent()); + } + else + { + tinyMCE.get("tinymcePreview").setContent(""); + } + } +} + +function parseMessageText(receiver_id, text) +{ + $.ajax({ + dataType: "json", + url: CONTROLLER_URL + "/parseMessageText", + data: { + "person_id": receiver_id, + "text": text + }, + success: function(data, textStatus, jqXHR) + { + tinyMCE.get("tinymcePreview").setContent(data); + }, + error: function(jqXHR, textStatus, errorThrown) + { + alert(textStatus + " - " + errorThrown + " - " + jqXHR.responseText); + } + }); +} + +$(document).ready(function () +{ + tinymce.init({ + selector: "#bodyTextArea", + plugins: "autoresize", + autoresize_min_height: 150, + autoresize_max_height: 600, + autoresize_bottom_margin: 10 + }); + + tinymce.init({ + menubar: false, + toolbar: false, + statusbar: false, + readonly: 1, + selector: "#tinymcePreview", + plugins: "autoresize", + autoresize_min_height: 150, + autoresize_bottom_margin: 10 + }); + + if ($("#variables")) + { + $("#variables").dblclick(function () + { + if ($("#bodyTextArea")) + { + //if editor active add at cursor position, otherwise at end + if (tinymce.activeEditor.id === "bodyTextArea") + tinymce.activeEditor.execCommand('mceInsertContent', false, $(this).children(":selected").val()); + else + tinyMCE.get("bodyTextArea").setContent(tinyMCE.get("bodyTextArea").getContent() + $(this).children(":selected").val()); + } + }); + } + + if ($("#recipients")) + { + $("#recipients").change(tinymcePreviewSetContent); + } + + if ($("#refresh")) + { + $("#refresh").click(tinymcePreviewSetContent); + } + + if ($("#sendButton") && $("#sendForm")) + { + $("#sendButton").click(function () + { + if ($("#subject") && $("#subject").val() != '' && tinyMCE.get("bodyTextArea").getContent() != '') + { + $("#sendForm").submit(); + } + else + { + alert("Subject and text are required fields!"); + } + }); + } + + if ($("#vorlageDnD")) + { + $("#vorlageDnD").change(function () + { + if (this.value != '') + { + $.ajax({ + dataType: "json", + url: CONTROLLER_URL + "/getVorlage", + data: { + "vorlage_kurzbz": this.value + }, + success: function(data, textStatus, jqXHR) + { + tinyMCE.get("bodyTextArea").setContent(data.retval[0].text); + $("#subject").val(data.retval[0].subject); + }, + error: function(jqXHR, textStatus, errorThrown) + { + alert(textStatus + " - " + errorThrown); + } + }); + } + }); + } + + $("#subject").focus(); + +});