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): ?>