diff --git a/application/config/migration.php b/application/config/migration.php index 65e90ad2e..102054bae 100755 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -23,7 +23,7 @@ $config['migration_enabled'] = TRUE; | be upgraded / downgraded to. | */ -$config['migration_version'] = 009; +$config['migration_version'] = '009'; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/api/v1/system/Message.php b/application/controllers/api/v1/system/Message.php index b7f70e187..a0f7d469f 100644 --- a/application/controllers/api/v1/system/Message.php +++ b/application/controllers/api/v1/system/Message.php @@ -23,45 +23,20 @@ class Message extends APIv1_Controller { parent::__construct(); // Load model MessageModel - $this->load->model('system/message_model', 'MessageModel'); - // Load set the uid of the model to let to check the permissions - $this->MessageModel->setUID($this->_getUID()); + $this->load->library('MessageLib', array('uid' => $this->_getUID())); } /** * @return void */ - public function getMessage() + public function getMessagesByPersonID() { - $messageID = $this->get('message_id'); + $person_id = $this->get('person_id'); + $all = $this->get('all'); - if (isset($messageID)) + if (isset($person_id)) { - $result = $this->MessageModel->load($messageID); - - $this->response($result, REST_Controller::HTTP_OK); - } - else - { - $this->response(); - } - } - - /** - * @return void - */ - public function postMessage() - { - if ($this->_validate($this->post())) - { - if (isset($this->post()['message_id'])) - { - $result = $this->MessageModel->update($this->post()['message_id'], $this->post()); - } - else - { - $result = $this->MessageModel->insert($this->post()); - } + $result = $this->messagelib->getMessagesByPerson($person_id, $all); $this->response($result, REST_Controller::HTTP_OK); } @@ -71,8 +46,39 @@ class Message extends APIv1_Controller } } - private function _validate($message = NULL) + /** + * @return void + */ + public function postMessage() { + if ($this->_validate($this->post())) + { + $this->messagelib->addRecipient($this->post()['person_id']); + $result = $this->messagelib->sendMessage( + $this->post()['person_id'], + $this->post()['subject'], + $this->post()['body'], + PRIORITY_NORMAL, + NULL, + $this->post()['oe_kurzbz'] + ); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + + private function _validate($message = null) + { + if (!isset($message['person_id']) || !isset($message['subject']) || + !isset($message['body']) || !isset($message['oe_kurzbz'])) + { + return false; + } + return true; } } \ No newline at end of file diff --git a/application/controllers/system/Phrases.php b/application/controllers/system/Phrases.php new file mode 100644 index 000000000..28e186014 --- /dev/null +++ b/application/controllers/system/Phrases.php @@ -0,0 +1,147 @@ +load->library('PhrasesLib'); + } + + public function index() + { + $this->load->view('system/phrases.php'); + } + + public function table() + { + $phrases = $this->phraseslib->getPhraseByApp('aufnahme'); + if ($phrases->error) + show_error($phrases->retval); + //var_dump($vorlage); + + $data = array + ( + 'app' => 'aufnahme', + 'phrases' => $phrases->retval + ); + $v = $this->load->view('system/phrasesList.php', $data); + } + + public function view($phrase_id = null) + { + if (empty($phrase_id)) + exit; + $phrase_inhalt = $this->phraseslib->getPhraseInhalt($phrase_id); + if ($phrase_inhalt->error) + show_error($phrase_inhalt->retval); + //var_dump($vorlage); + + $data = array + ( + 'phrase_id' => $phrase_id, + 'phrase_inhalt' => $phrase_inhalt->retval + ); + $v = $this->load->view('system/phrasesinhaltList.php', $data); + } + + public function edit($phrase_id = null) + { + if (empty($phrase_id)) + exit; + $phrase = $this->phraseslib->getPhrase($phrase_id); + //var_dump($vorlage); + if ($phrase->error) + show_error($phrase->retval); + if (count($phrase->retval) != 1) + show_error('Phrase nicht vorhanden! ID: '.$phrase_id); + + $data = array + ( + 'phrase' => $phrase->retval[0] + ); + //var_dump($data['message']); + $v = $this->load->view('system/phrasesEdit', $data); + } + + public function write($vorlage_kurzbz = null) + { + $data = array + ( + 'subject' => 'TestSubject', + 'body' => 'TestDevelopmentBodyText' + ); + $v = $this->load->view('system/messageWrite', $data); + } + + public function save() + { + $phrase_id = $this->input->post('phrase_id', TRUE); + $data['phrase'] = $this->input->post('phrase', TRUE); + $phrase = $this->phraseslib->savePhrase($phrase_id, $data); + if ($phrase->error) + show_error($phrase->retval); + $phrase_id = $phrase->retval; + + redirect('/system/Phrases/edit/'.$phrase_id); + } + + public function newText() + { + $vorlage_kurzbz = $this->input->post('vorlage_kurzbz', TRUE); + $data = array + ( + 'vorlage_kurzbz' => $vorlage_kurzbz, + 'studiengang_kz' => 0, + 'version' => 1, + 'oe_kurzbz' => 'etw' + ); + $vorlagetext = $this->vorlagelib->insertVorlagetext($data); + if ($vorlagetext->error) + show_error($vorlagetext->retval); + $vorlagestudiengang_id = $vorlagetext->retval; + + redirect('/system/Templates/editText/'.$vorlagestudiengang_id); + } + + public function editText($phrase_inhalt_id) + { + $phrase_inhalt = $this->phraseslib->getPhraseInhaltById($phrase_inhalt_id); + if ($phrase_inhalt->error) + show_error($phrase_inhalt->retval); + $data = $phrase_inhalt->retval[0]; + + $this->load->view('system/phraseinhaltEdit', $data); + } + + public function saveText() + { + $phrase_inhalt_id = $this->input->post('phrase_inhalt_id', TRUE); + $data['orgeinheit_kurzbz'] = $this->input->post('oe_kurzbz', TRUE); + $data['text'] = $this->input->post('text', TRUE); + $data['description'] = $this->input->post('description', TRUE); + $data['sprache'] = $this->input->post('sprache', TRUE); + $phrase_inhalt = $this->phraseslib->updatePhraseInhalt($phrase_inhalt_id, $data); + if ($phrase_inhalt->error) + show_error($phrase_inhalt->retval); + $data['phrase_inhalt_id'] = $phrase_inhalt_id; + redirect('/system/Phrases/editText/'.$phrase_inhalt_id); + //$this->load->view('system/templatetextEdit', $data); + } + + public function preview($vorlagestudiengang_id) + { + $formdata = $this->input->post('formdata', FALSE); + $daten = json_decode($formdata, TRUE); + $vorlagetext = $this->vorlagelib->getVorlagetextById($vorlagestudiengang_id); + if ($vorlagetext->error) + show_error($vorlagetext->retval); + $data = array + ( + 'text' => $this->vorlagelib->parseVorlagetext($vorlagetext->retval[0]->text, $daten) + ); + $this->load->view('system/templatetextPreview', $data); + } +} diff --git a/application/core/FHC_Controller.php b/application/core/FHC_Controller.php index d04ed2a0b..3216bbb63 100644 --- a/application/core/FHC_Controller.php +++ b/application/core/FHC_Controller.php @@ -21,4 +21,5 @@ class FHC_Controller extends CI_Controller else return $this->_uid; } + } diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 185e068a3..39ea6b131 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -11,13 +11,18 @@ class MessageLib { private $recipients = array(); - public function __construct() + public function __construct($params) { $this->ci =& get_instance(); $this->ci->config->load('message'); //$this->ci->load->model('person/Person_model', 'PersonModel'); $this->ci->load->model('system/Message_model', 'MessageModel'); + if (is_array($params) && isset($params['uid'])) + { + $this->ci->MessageModel->setUID($params['uid']); + } + $this->ci->load->model('system/MsgStatus_model', 'MsgStatusModel'); $this->ci->load->model('system/Recipient_model', 'RecipientModel'); $this->ci->load->model('system/Attachment_model', 'AttachmentModel'); diff --git a/application/libraries/PhrasesLib.php b/application/libraries/PhrasesLib.php new file mode 100644 index 000000000..1cc023863 --- /dev/null +++ b/application/libraries/PhrasesLib.php @@ -0,0 +1,159 @@ +ci =& get_instance(); + $this->ci->load->library('parser'); + $this->ci->load->model('system/Phrase_model', 'PhraseModel'); + $this->ci->load->model('system/Phrase_inhalt_model', 'PhraseInhaltModel'); + $this->ci->load->helper('language'); + //$this->ci->lang->load('fhcomplete'); + } + + /** + * getPhrase() - will load a spezific Phrase + * + * @param integer $vorlage_kurzbz REQUIRED + * @return struct + */ + function getPhrase($phrase_id) + { + if (empty($phrase_id)) + return $this->_error(MSG_ERR_INVALID_MSG_ID); + + $phrase = $this->ci->PhraseModel->load($phrase_id); + return $phrase; + } + + /** + * getSubMessages() - will return all Messages subordinated from a specified message. + * + * @param integer $msg_id REQUIRED + * @return array + */ + function getPhraseByApp($app = null) + { + $phrases = $this->ci->PhraseModel->loadWhere(array('app' => $app)); + return $phrases; + } + + function getPhraseInhalt($phrase_id) + { + if (empty($phrase_id)) + return $this->_error(MSG_ERR_INVALID_MSG_ID); + + $phrase_inhalt = $this->ci->PhraseInhaltModel->loadWhere(array('phrase_id' => $phrase_id)); + return $phrase_inhalt; + } + + /** + * savePhrase() - will save a spezific Phrase. + * + * @param array $data REQUIRED + * @return array + */ + function savePhrase($phrase_id, $data) + { + if (empty($data)) + return $this->_error(MSG_ERR_INVALID_MSG_ID); + + $phrase = $this->ci->PhraseModel->update($phrase_id, $data); + return $phrase; + } + + + /** + * getVorlagetextByVorlage() - will load tbl_vorlagestudiengang for a spezific Template. + * + * @param string $vorlage_kurzbz REQUIRED + * @return array + */ + function getPhraseInhaltById($phrase_inhalt_id) + { + if (empty($phrase_inhalt_id)) + return $this->_error($this->ci->lang->line('fhc_'.FHC_INVALIDID, false)); + + $phrase_inhalt = $this->ci->PhraseInhaltModel->loadWhere(array('phrase_inhalt_id' =>$phrase_inhalt_id)); + return $phrase_inhalt; + } + + /** + * loadVorlagetext() - will load the best fitting Template. + * + * @param string $vorlage_kurzbz REQUIRED + * @param string $oe_kurzbz OPTIONAL + * @param string $orgform_kurzbz OPTIONAL + * @return array + */ + function loadVorlagetext($vorlage_kurzbz, $oe_kurzbz=null, $orgform_kurzbz=null) + { + if (empty($vorlage_kurzbz)) + return $this->_error($this->ci->lang->line('fhc_'.FHC_INVALIDID, false)); + + $vorlage = $this->ci->VorlageStudiengangModel->getVorlageStudiengang($vorlage_kurzbz, $oe_kurzbz, $orgform_kurzbz); + return $vorlage; + } + + /** + * insertVorlagetext() - will load tbl_vorlagestudiengang for a spezific Template. + * + * @param string $vorlage_kurzbz REQUIRED + * @return array + */ + function insertVorlagetext($data) + { + $vorlagetext = $this->ci->VorlageStudiengangModel->insert($data); + return $vorlagetext; + } + + /** + * loadVorlagetext() - will load tbl_vorlagestudiengang for a spezific Template. + * + * @param string $vorlage_kurzbz REQUIRED + * @return array + */ + function getVorlagetextById($vorlagestudiengang_id) + { + $vorlagetext = $this->ci->VorlageStudiengangModel->load($vorlagestudiengang_id); + return $vorlagetext; + } + + /** + * saveVorlagetext() - will load tbl_vorlagestudiengang for a spezific Template. + * + * @param string $vorlage_kurzbz REQUIRED + * @return array + */ + function updatePhraseInhalt($phrase_inhalt_id, $data) + { + $phrase_inhalt = $this->ci->PhraseInhaltModel->update($phrase_inhalt_id, $data); + return $phrase_inhalt; + } + + /** + * parseVorlagetext() - will parse a Vorlagetext. + * + * @param string $text REQUIRED + * @param array $data REQUIRED + * @return string + */ + function parseVorlagetext($text, $data = array()) + { + if (empty($text)) + return $this->_error($this->ci->lang->line('fhc_'.FHC_INVALIDID, false)); + $text = $this->ci->parser->parse_string($text, $data, TRUE); + return $text; + } +} diff --git a/application/migrations/003_add_apikey.php b/application/migrations/003_add_apikey.php index 06ea42d65..c7bc4b578 100644 --- a/application/migrations/003_add_apikey.php +++ b/application/migrations/003_add_apikey.php @@ -54,4 +54,3 @@ class Migration_Add_apikey extends CI_Migration { $this->dbforge->drop_table('ci_apikey'); } } - diff --git a/application/migrations/009_phrase.php b/application/migrations/009_phrase.php index 708f1e6b6..ea354b5f9 100755 --- a/application/migrations/009_phrase.php +++ b/application/migrations/009_phrase.php @@ -44,9 +44,10 @@ class Migration_Phrase extends CI_Migration { phrase_inhalt_id serial, phrase_id bigint NOT NULL, sprache varchar(32) NOT NULL, - orgeinheit_kurzbz varchar(32) NOT NULL, - orgform_kurzbz varchar(32) NOT NULL, + orgeinheit_kurzbz varchar(32), + orgform_kurzbz varchar(32), text text, + description text, insertamum timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, insertvon varchar(32), PRIMARY KEY (phrase_inhalt_id) @@ -64,7 +65,7 @@ class Migration_Phrase extends CI_Migration { } } } - + public function down() { try diff --git a/application/models/system/Phrase_inhalt_model.php b/application/models/system/Phrase_inhalt_model.php new file mode 100644 index 000000000..806915bca --- /dev/null +++ b/application/models/system/Phrase_inhalt_model.php @@ -0,0 +1,15 @@ +dbTable = 'public.tbl_phrase_inhalt'; + $this->pk = 'phrase_inhalt_id'; + } + +} diff --git a/application/models/system/Phrase_model.php b/application/models/system/Phrase_model.php new file mode 100644 index 000000000..051ef170c --- /dev/null +++ b/application/models/system/Phrase_model.php @@ -0,0 +1,15 @@ +dbTable = 'public.tbl_phrase'; + $this->pk = 'phrase_id'; + } + +} diff --git a/application/views/system/phraseinhaltEdit.php b/application/views/system/phraseinhaltEdit.php new file mode 100644 index 000000000..2e2d39ded --- /dev/null +++ b/application/views/system/phraseinhaltEdit.php @@ -0,0 +1,31 @@ +load->view('templates/header', array('title' => 'TemplateEdit', 'tinymce' => true, 'jsonforms' => true)); +?> + +