diff --git a/application/config/fhcomplete.php b/application/config/fhcomplete.php index a5d5f2c2f..380a629e9 100755 --- a/application/config/fhcomplete.php +++ b/application/config/fhcomplete.php @@ -231,6 +231,8 @@ $config['fhc_acl'] = array 'wawi.tbl_rechnungsbetrag' => 'basis/rechnungsbetrag', 'wawi.tbl_rechnungstyp' => 'basis/rechnungstyp', 'wawi.tbl_zahlungstyp' => 'basis/zahlungstyp', + + DMS_PATH => 'fs/dms', 'public.tbl_sprache' => 'admin' ); diff --git a/application/controllers/api/v1/content/Dms.php b/application/controllers/api/v1/content/Dms.php index 6d37bc5db..5800832f1 100644 --- a/application/controllers/api/v1/content/Dms.php +++ b/application/controllers/api/v1/content/Dms.php @@ -23,9 +23,13 @@ class Dms extends APIv1_Controller { parent::__construct(); // Load model PersonModel - $this->load->model('content/dms_model', 'DmsModel'); - // Load set the uid of the model to let to check the permissions + $this->load->model('content/Dms_model', 'DmsModel'); + $this->load->model('content/DmsVersion_model', 'DmsVersionModel'); + $this->load->model('content/DmsFS_model', 'DmsFSModel'); + // Set the uid of the model to let to check the permissions $this->DmsModel->setUID($this->_getUID()); + $this->DmsVersionModel->setUID($this->_getUID()); + $this->DmsFSModel->setUID($this->_getUID()); } /** @@ -41,9 +45,52 @@ class Dms extends APIv1_Controller $result = $this->_getDms($dms_id, $version); if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0) { - if (($fileContent = $this->_readFile($result->retval[0]->filename)) != false) + $resultFS = $this->DmsFSModel->read($result->retval[0]->filename); + if (is_object($resultFS) && $resultFS->error == EXIT_SUCCESS) { - $result->retval[0]->file_content = $fileContent; + $result->retval[0]->file_content = $resultFS->retval; + } + } + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + + /** + * + */ + public function postDms() + { + $dms = $this->_parseData($this->post()); + + if ($this->_validate($dms)) + { + $result = null; + + if (isset($dms['dms_id'])) + { + if ($this->_saveFileOnUpdate($dms)) + { + $result = $this->DmsModel->update($dms['dms_id'], $this->DmsModel->filterFields($dms)); + if ($result->error == EXIT_SUCCESS) + { + $result = $this->DmsVersionModel->update(array($dms['dms_id'], $dms['version']), $this->DmsVersionModel->filterFields($dms)); + } + } + } + else + { + if (($filename = $this->_saveFileOnInsert($dms)) !== false) + { + $result = $this->DmsModel->insert($this->DmsModel->filterFields($dms)); + if ($result->error == EXIT_SUCCESS) + { + $result = $this->DmsVersionModel->insert($this->DmsVersionModel->filterFields($dms, $result->retval, $filename)); + } } } @@ -89,102 +136,6 @@ class Dms extends APIv1_Controller return $result; } - /** - * - */ - public function postDms() - { - $dms = $this->_parseData($this->post()); - if ($this->_validate($dms)) - { - if (isset($dms['dms_id'])) - { - if ($this->_saveFileOnUpdate($dms)) - { - $result = $this->DmsModel->update($dms['dms_id'], $this->_dmsFieldsArray($dms)); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->DmsModel->updateDmsVersion($dms['dms_id'], $this->_dmsVersionFieldsArray($dms)); - } - } - } - else - { - if (($fileName = $this->_saveFileOnInsert($dms)) !== false) - { - $result = $this->DmsModel->insert($this->_dmsFieldsArray($dms)); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->DmsModel->insertDmsVersion($this->_dmsVersionFieldsArray($dms, $result->retval, $fileName)); - } - } - } - - $this->response($result, REST_Controller::HTTP_OK); - } - else - { - $this->response(); - } - } - - /** - * - */ - private function _dmsFieldsArray($dms) - { - $fieldsArray = array('oe_kurzbz', 'dokument_kurzbz', 'kategorie_kurzbz'); - $returnArray = array(); - - foreach ($fieldsArray as $value) - { - if (isset($dms[$value])) - { - $returnArray[$value] = $dms[$value]; - } - } - - return $returnArray; - } - - /** - * - */ - private function _dmsVersionFieldsArray($dms, $dms_id = null, $fileName = null) - { - $fieldsArray = array( - 'version', - 'mimetype', - 'name', - 'beschreibung', - 'letzterzugriff', - 'insertamum', - 'insertvon', - 'updateamum', - 'updatevon' - ); - $returnArray = array(); - - foreach ($fieldsArray as $value) - { - if (isset($dms[$value])) - { - $returnArray[$value] = $dms[$value]; - } - } - - if (isset($dms_id)) - { - $returnArray['dms_id'] = $dms_id; - } - if (isset($fileName)) - { - $returnArray['filename'] = $fileName; - } - - return $returnArray; - } - /** * */ @@ -193,19 +144,11 @@ class Dms extends APIv1_Controller if(isset($dms['version'])) { $result = $this->_getDms($dms['dms_id'], $dms['version']); - } - else - { - $result = $this->_getDms($dms['dms_id']); - } - if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0) - { - $fileName = DMS_PATH . $result->retval[0]->filename; - - if (($fileContent = base64_decode($dms['file_content']))) + if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0) { - if (file_put_contents($fileName, $fileContent)) + $result = $this->DmsFSModel->write($result->retval[0]->filename, $dms['file_content']); + if (is_object($result) && $result->error == EXIT_SUCCESS) { return true; } @@ -220,47 +163,17 @@ class Dms extends APIv1_Controller */ private function _saveFileOnInsert($dms) { - $fileName = uniqid() . '.' . pathinfo($dms['name'], PATHINFO_EXTENSION); - $FileNamePath = DMS_PATH . $fileName; + $filename = uniqid() . '.' . pathinfo($dms['name'], PATHINFO_EXTENSION); - if (($fileContent = base64_decode($dms['file_content']))) + $result = $this->DmsFSModel->write($filename, $dms['file_content']); + if (is_object($result) && $result->error == EXIT_SUCCESS) { - if ($fileHandle = fopen($FileNamePath, 'w')) - { - if(fwrite($fileHandle, $fileContent)) - { - fclose($fileHandle); - return $fileName; - } - } + return $filename; } return false; } - /** - * - */ - private function _readFile($fileName) - { - $fileNamePath = DMS_PATH . $fileName; - if (file_exists($fileNamePath)) - { - if ($fileHandle = fopen($fileNamePath, 'r')) - { - $cTmpHEX = ''; - while (!feof($fileHandle)) - { - $cTmpHEX .= fread($fileHandle, 8192); - } - fclose($fileHandle); - return base64_encode($cTmpHEX); - } - } - - return false; - } - private function _validate($dms = NULL) { if (!isset($dms['file_content']) || (isset($dms['file_content']) && $dms['file_content'] == '')) @@ -274,4 +187,4 @@ class Dms extends APIv1_Controller return true; } -} +} \ No newline at end of file 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/Messages.php b/application/controllers/system/Messages.php index 4c203e478..c61fd5e75 100755 --- a/application/controllers/system/Messages.php +++ b/application/controllers/system/Messages.php @@ -1,34 +1,43 @@ load->library('messaging'); + $this->load->library('MessageLib'); //$this->load->model('person/Person_model'); //$this->load->model('system/Message_model'); } public function index() { - //$messages = $this->Message_model->getMessages(); - $msg = $this->Message_model->load(1); + $this->load->view('system/messages.php'); + } + + public function table() + { + $person_id = $this->input->post('person_id', TRUE); + if ($person_id) + $msg = $this->messagelib->getMessagesByPerson($person_id); + else + $msg = $this->messagelib->getMessagesByUID($this->getUID()); if ($msg->error) show_error($msg->retval); $data = array ( - 'message' => $msg->retval[0] + 'messages' => $msg->retval ); - $v = $this->load->view('message.php', $data); + var_dump ($data); + $this->load->view('system/messagesList.php', $data); } public function view($msg_id) { - $msg = $this->messaging->getMessage($msg_id); + $msg = $this->messagelib->getMessage($msg_id); //var_dump($msg); if ($msg->error) show_error($msg->retval); @@ -57,9 +66,9 @@ class Messages extends FHC_Controller { $body = $this->input->post('body', TRUE); $subject = $this->input->post('subject', TRUE); - if (! $this->messaging->addRecipient(1)) + if (! $this->messagelib->addRecipient(1)) show_error('Error: AddRecipient'); - $msg = $this->messaging->sendMessage(1,$body ,$subject); + $msg = $this->messagelib->sendMessage(1,$body ,$subject); if ($msg->error) show_error($msg->retval); $msg_id = $msg->retval; diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php index f0e224914..4e5f2474d 100644 --- a/application/core/DB_Model.php +++ b/application/core/DB_Model.php @@ -2,11 +2,11 @@ class DB_Model extends FHC_Model { - protected $dbTable; // Name of the DB-Table for CI-Insert, -Update, ... - protected $pk; // Name of the PrimaryKey for DB-Update, Load, ... + protected $dbTable; // Name of the DB-Table for CI-Insert, -Update, ... + protected $pk; // Name of the PrimaryKey for DB-Update, Load, ... protected $hasSequence; // False if this table has a composite primary key that is not using a sequence // True if this table has a primary key that uses a sequence - protected $acl; // Name of the PrimaryKey for DB-Update, Load, ... + protected $acl; // Name of the PrimaryKey for DB-Update, Load, ... function __construct($dbTable = null, $pk = null, $hasSequence = true) { diff --git a/application/core/FHC_Controller.php b/application/core/FHC_Controller.php index e3026dbb8..3216bbb63 100644 --- a/application/core/FHC_Controller.php +++ b/application/core/FHC_Controller.php @@ -3,21 +3,23 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); class FHC_Controller extends CI_Controller { - public $uid; - - function __construct() + protected $_uid; // needs to be changed to protected $_uid + + public function __construct() { parent::__construct(); $this->load->library('session'); - //$this->load->helper('language'); - - // look if User is logged in and set uid - if (isset($_SERVER['PHP_AUTH_USER'])) - $this->uid = $_SERVER['PHP_AUTH_USER']; - if (isset($_SESSION['uid'])) - $this->uid = $_SESSION['uid']; - $this->session->set_userdata('uid', 'pam'); + $this->load->helper('fhcauth'); + + $this->_uid = getAuthUID(); + } + public function getUID() + { + if (empty($this->_uid)) + return false; + else + return $this->_uid; } } diff --git a/application/core/FHC_Model.php b/application/core/FHC_Model.php index 485678c94..13457057f 100644 --- a/application/core/FHC_Model.php +++ b/application/core/FHC_Model.php @@ -40,6 +40,16 @@ class FHC_Model extends CI_Model { return $this->fhc_db_acl->setUID($uid); } + + /** --------------------------------------------------------------- + * get UID + * + * @return string or (bool)false + */ + public function getUID() + { + return $this->fhc_db_acl->getUID(); + } /** --------------------------------------------------------------- * Success @@ -61,4 +71,4 @@ class FHC_Model extends CI_Model { return error($retval, $message); } -} \ No newline at end of file +} diff --git a/application/core/FS_Model.php b/application/core/FS_Model.php new file mode 100644 index 000000000..1bcaaa251 --- /dev/null +++ b/application/core/FS_Model.php @@ -0,0 +1,170 @@ +load->library('FilesystemLib'); + $this->acl = $this->config->item('fhc_acl'); + $this->filepath = $filepath; + } + + /** --------------------------------------------------------------- + * Read data from file system + * + * @return array + */ + public function read($filename) + { + // Check Class-Attributes + if (is_null($this->filepath)) + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + + // Check method parameters + if (is_null($filename)) + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + + // Check rights + if (! $this->fhc_db_acl->isBerechtigt($this->acl[$this->filepath], 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->filepath], FHC_MODEL_ERROR); + + if (!is_null($data = $this->filesystemlib->read($this->filepath, $filename))) + { + return $this->_success(base64_encode($data)); + } + else + { + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + } + } + + /** --------------------------------------------------------------- + * Writing data to file system + * + * @param string $fileContent File content + * @return object + */ + public function write($filename, $content) + { + // Check Class-Attributes + if (is_null($this->filepath)) + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + + // Check method parameters + if (is_null($filename)) + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + if (is_null($content)) + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + + // Check rights + if (! $this->fhc_db_acl->isBerechtigt($this->acl[$this->filepath], 'i')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->filepath], FHC_MODEL_ERROR); + + if ($this->filesystemlib->write($this->filepath, $filename, base64_decode($content)) === true) + { + return $this->_success(FHC_SUCCESS); + } + else + { + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + } + } + + /** --------------------------------------------------------------- + * Append data to a file + * + * @param array $data File content + * @return array + */ + public function append($filename, $content) + { + // Check Class-Attributes + if (is_null($this->filepath)) + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + + // Check method parameters + if (is_null($filename)) + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + if (is_null($content)) + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + + // Check rights + if (! $this->fhc_db_acl->isBerechtigt($this->acl[$this->filepath], 'i')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->filepath], FHC_MODEL_ERROR); + + if ($this->filesystemlib->append($this->filepath, $filename, base64_decode($content)) === true) + { + return $this->_success(FHC_SUCCESS); + } + else + { + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + } + } + + /** --------------------------------------------------------------- + * Delete data from file system + * + * @param string $id Primary Key for DELETE + * @return array + */ + public function remove($filename) + { + // Check Class-Attributes + if (is_null($this->filepath)) + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + + // Check method parameters + if (is_null($filename)) + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + + // Check rights + if (! $this->fhc_db_acl->isBerechtigt($this->acl[$this->filepath], 'd')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->filepath], FHC_MODEL_ERROR); + + if ($this->filesystemlib->remove($this->filepath, $filename) === true) + { + return $this->_success(FHC_SUCCESS); + } + else + { + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + } + } + + /** --------------------------------------------------------------- + * Rename a file + * + * @param string $id Primary Key for DELETE + * @return array + */ + public function rename($filename, $newFilename) + { + // Check Class-Attributes + if (is_null($this->filepath)) + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + + // Check method parameters + if (is_null($filename)) + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + if (is_null($newFilename)) + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + + // Check rights + if (! $this->fhc_db_acl->isBerechtigt($this->acl[$this->filepath], 'u')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->filepath], FHC_MODEL_ERROR); + + if ($this->filesystemlib->rename($this->filepath, $filename, $this->filepath, $newFilename) === true) + { + return $this->_success(FHC_SUCCESS); + } + else + { + return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR); + } + } +} \ No newline at end of file diff --git a/application/helpers/fhcauth_helper.php b/application/helpers/fhcauth_helper.php index 1a904ee55..7a5f782b0 100644 --- a/application/helpers/fhcauth_helper.php +++ b/application/helpers/fhcauth_helper.php @@ -48,4 +48,20 @@ if ( ! function_exists('auth')) return false; } } + + /** + * Look if User is logged in and return uid + * Otherwise return false + * + * @return string or (bool)false + */ + function getAuthUID() + { + // look if User is logged in and return uid + if (isset($_SERVER['PHP_AUTH_USER'])) + return $_SERVER['PHP_AUTH_USER']; + if (isset($_SESSION['uid'])) + return $_SESSION['uid']; + return false; + } } diff --git a/application/libraries/FHC_DB_ACL.php b/application/libraries/FHC_DB_ACL.php index 702b193e7..0c88af34d 100644 --- a/application/libraries/FHC_DB_ACL.php +++ b/application/libraries/FHC_DB_ACL.php @@ -68,4 +68,14 @@ class FHC_DB_ACL { return $this->_uid = $uid; } + + /** --------------------------------------------------------------- + * get UID + * + * @return string or (bool)false + */ + public function getUID() + { + return $this->_uid; + } } diff --git a/application/libraries/FilesystemLib.php b/application/libraries/FilesystemLib.php new file mode 100644 index 000000000..0b1dbc5d0 --- /dev/null +++ b/application/libraries/FilesystemLib.php @@ -0,0 +1,148 @@ +checkParameters($filepath, $filename)) + { + $resource = $filepath . DIRECTORY_SEPARATOR . $filename; + if (file_exists($resource) && $fileHandle = fopen($resource, 'r')) + { + $result = ''; + while (!feof($fileHandle)) + { + $result .= fread($fileHandle, 8192); + } + fclose($fileHandle); + } + } + + return $result; + } + + /* + * + */ + public function write($filepath, $filename, $content) + { + $result = null; + + if ($this->checkParameters($filepath, $filename) && isset($content)) + { + $resource = $filepath . DIRECTORY_SEPARATOR . $filename; + if (is_writable($filepath) && $fileHandle = fopen($resource, 'w')) + { + if (fwrite($fileHandle, $content) !== false) + { + $result = true; + } + fclose($fileHandle); + } + } + + return $result; + } + + /* + * + */ + public function append($filepath, $filename, $content) + { + $result = null; + + if ($this->checkParameters($filepath, $filename) && isset($content)) + { + $resource = $filepath . DIRECTORY_SEPARATOR . $filename; + if (is_writable($resource) && $fileHandle = fopen($resource, 'a')) + { + if (fwrite($fileHandle, $content) !== false) + { + $result = true; + } + fclose($fileHandle); + } + } + + return $result; + } + + /* + * + */ + public function remove($filepath, $filename) + { + $result = null; + + if ($this->checkParameters($filepath, $filename)) + { + if (is_writable($filepath)) + { + $resource = $filepath . DIRECTORY_SEPARATOR . $filename; + $result = unlink($resource); + } + } + + return $result; + } + + /* + * + */ + public function rename($filepath, $filename, $newFilepath, $newFilename) + { + $result = null; + + if ($this->checkParameters($filepath, $filename) && $this->checkParameters($newFilepath, $newFilename)) + { + $resource = $filepath . DIRECTORY_SEPARATOR . $filename; + if (is_writable($filepath) && is_writable($newFilepath) && file_exists($resource)) + { + $destination = $newFilepath . DIRECTORY_SEPARATOR . $newFilename; + $result = rename($resource, $destination); + } + } + + return $result; + } +} \ No newline at end of file diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index fa280938a..9d1cb1ce1 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) { require_once APPPATH.'config/message.php'; $this->ci =& get_instance(); //$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'); @@ -53,6 +58,40 @@ class MessageLib return $msg; } + /** + * getMessagesByUID() - will return all messages, including the latest status for specified user. It don´t returns Attachments. + * + * @param string $uid REQUIRED + * @return array + */ + function getMessagesByUID($uid, $all = false) + { + if (empty($uid)) + return $this->_error(MSG_ERR_INVALID_MSG_ID); + + $msg = $this->ci->MessageModel->getMessagesByUID($uid, $all); + + // General Error Occurred + return $msg; + } + + /** + * getMessagesByPerson() - will return all messages, including the latest status for specified user. It don´t returns Attachments. + * + * @param bigint $person_id REQUIRED + * @return array + */ + function getMessagesByPerson($person_id, $all = false) + { + if (empty($person_id)) + return $this->_error(MSG_ERR_INVALID_MSG_ID); + + $msg = $this->ci->MessageModel->getMessagesByPerson($person_id, $all); + + // General Error Occurred + return $msg; + } + // ------------------------------------------------------------------------ /** @@ -66,8 +105,7 @@ class MessageLib if (!is_numeric($msg_id)) return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); - $msg = $this->getMessage($msg_id); - return $msg; + return $this->getMessage($msg_id); } // ------------------------------------------------------------------------ diff --git a/application/migrations/010_vorlage.php b/application/migrations/010_vorlage.php index f6b7b7cd5..0fda6823c 100755 --- a/application/migrations/010_vorlage.php +++ b/application/migrations/010_vorlage.php @@ -8,17 +8,37 @@ class Migration_Vorlage extends CI_Migration { { if (! @$this->db->simple_query('SELECT attribute FROM public.tbl_vorlage')) { + $this->db->insert('system.tbl_berechtigung', array( + 'berechtigung_kurzbz' => 'basis/vorlage', + 'beschreibung' => 'Vorlagen fuer Dokumente (DOC, PDF, eMail, ...')); + $this->db->insert('system.tbl_rolleberechtigung', array( + 'berechtigung_kurzbz' => 'basis/vorlage', + 'rolle_kurzbz' => 'admin', + 'art' => 'suid')); $query= "ALTER TABLE public.tbl_vorlage ADD COLUMN attribute json; "; if ($this->db->simple_query($query)) + { echo 'Column public.tbl_vorlage.attribute added!'; + // Insert Demo Data + $query= "INSERT INTO public.tbl_vorlage VALUES ('MailRegistration', 'eMail zur Registrierung', NULL, 'text/html', '{ \"\$schema\": \"http://json-schema.org/draft-03/schema#\", \"title\": \"Person\", \"type\": \"object\", \"properties\": { \"anrede\": { \"type\": \"string\", \"enum\": [ \"Herr\", \"Frau\" ], \"default\": \"Herr\" }, \"vorname\": { \"type\": \"string\", \"description\": \"Firstname\", \"minLength\": 2, \"default\": \"Vorname\" }, \"nachname\": { \"type\": \"string\", \"description\": \"Surename\", \"minLength\": 2, \"default\": \"Nachname\" }, \"code\": { \"type\": \"string\", \"description\": \"Accesscode\", \"minLength\": 6, \"default\": \"1q2w3e4r5t6z7u8i9o0\" }, \"link\": { \"type\": \"string\", \"description\": \"LoginURL\", \"minLength\": 6, \"default\": \"https://cis.fhcomplete.org/addon/aufnahme/cis/login/\" } }}'); + "; + $this->db->simple_query($query); + } else echo "Error adding public.tbl_vorlage.attribute!"; } if (! @$this->db->simple_query('SELECT subject FROM public.tbl_vorlagestudiengang')) { + $this->db->insert('system.tbl_berechtigung', array( + 'berechtigung_kurzbz' => 'basis/vorlagestudiengang', + 'beschreibung' => 'Vorlagen fuer Dokumente (DOC, PDF, eMail, ...')); + $this->db->insert('system.tbl_rolleberechtigung', array( + 'berechtigung_kurzbz' => 'basis/vorlagestudiengang', + 'rolle_kurzbz' => 'admin', + 'art' => 'suid')); $query= "ALTER TABLE public.tbl_vorlagestudiengang ADD COLUMN subject text; "; @@ -34,7 +54,17 @@ class Migration_Vorlage extends CI_Migration { ADD COLUMN orgform_kurzbz varchar(3) references bis.tbl_orgform(orgform_kurzbz); "; if ($this->db->simple_query($query)) + { echo 'Column public.tbl_vorlagestudiengang.orgform_kurzbz added!'; + // Insert Demo Data + $query= "INSERT INTO public.tbl_vorlagestudiengang VALUES ('MailRegistration', 0, 1, '

Sehr geehrte/r {anrede} {vorname} {nachname},

+

vielen Dank für Ihre Registrierung an unserer Hochschule. Im Anhang senden wir ihnen den Zugangscode.

+

Code: {code}

+

Unter folgenden Link können sie sich direkt für unser Service einloggen: {link}{code}

+

Mit freundlichen Grüßen,
FH Technikum Wien

', 'etw'); + "; + $this->db->simple_query($query); + } else echo "Error adding public.tbl_vorlagestudiengang.orgform_kurzbz!"; } @@ -44,6 +74,12 @@ class Migration_Vorlage extends CI_Migration { { try { + $this->db->delete('system.tbl_rolleberechtigung', array('berechtigung_kurzbz' => 'basis/vorlage')); + $this->db->delete('system.tbl_berechtigung', array('berechtigung_kurzbz' => 'basis/vorlage')); + $this->db->delete('system.tbl_rolleberechtigung', array('berechtigung_kurzbz' => 'basis/vorlagestudiengang')); + $this->db->delete('system.tbl_berechtigung', array('berechtigung_kurzbz' => 'basis/vorlagestudiengang')); + $this->db->delete('public.tbl_vorlagestudiengang', array('vorlage_kurzbz' => 'MailRegistration')); + $this->db->delete('public.tbl_vorlage', array('vorlage_kurzbz' => 'MailRegistration')); $this->dbforge->drop_column('public.tbl_vorlage', 'attribute'); $this->dbforge->drop_column('public.tbl_vorlagestudiengang', 'subject'); $this->dbforge->drop_column('public.tbl_vorlagestudiengang', 'orgform_kurzbz'); diff --git a/application/models/content/DmsFS_model.php b/application/models/content/DmsFS_model.php new file mode 100644 index 000000000..38a72d853 --- /dev/null +++ b/application/models/content/DmsFS_model.php @@ -0,0 +1,13 @@ +filepath = DMS_PATH; + } +} \ No newline at end of file diff --git a/application/models/content/DmsVersion_model.php b/application/models/content/DmsVersion_model.php new file mode 100644 index 000000000..5cc3b556e --- /dev/null +++ b/application/models/content/DmsVersion_model.php @@ -0,0 +1,53 @@ +dbTable = 'campus.tbl_dms_version'; + $this->pk = array('dms_id', 'version'); + $this->hasSequence = false; + } + + /** + * + */ + public function filterFields($dms, $dms_id = null, $fileName = null) + { + $fieldsArray = array( + 'version', + 'mimetype', + 'name', + 'beschreibung', + 'letzterzugriff', + 'insertamum', + 'insertvon', + 'updateamum', + 'updatevon' + ); + $returnArray = array(); + + foreach ($fieldsArray as $value) + { + if (isset($dms[$value])) + { + $returnArray[$value] = $dms[$value]; + } + } + + if (isset($dms_id)) + { + $returnArray['dms_id'] = $dms_id; + } + if (isset($fileName)) + { + $returnArray['filename'] = $fileName; + } + + return $returnArray; + } +} \ No newline at end of file diff --git a/application/models/content/Dms_model.php b/application/models/content/Dms_model.php index 55af1371e..e9db6d903 100644 --- a/application/models/content/Dms_model.php +++ b/application/models/content/Dms_model.php @@ -12,39 +12,22 @@ class Dms_model extends DB_Model $this->pk = 'dms_id'; } - public function insertDmsVersion($data) + /** + * + */ + public function filterFields($dms) { - $tableName = 'campus.tbl_dms_version'; + $fieldsArray = array('oe_kurzbz', 'dokument_kurzbz', 'kategorie_kurzbz'); + $returnArray = array(); - // Check rights - if (! $this->fhc_db_acl->isBerechtigt($this->acl[$tableName], 'i')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$tableName], FHC_MODEL_ERROR); - - // DB-INSERT - if ($this->db->insert($tableName, $data)) - return $this->_success($this->db->insert_id()); - else - return $this->_error($this->db->error(), FHC_DB_ERROR); - } - - public function updateDmsVersion($id, $data) - { - $tableName = 'campus.tbl_dms_version'; + foreach ($fieldsArray as $value) + { + if (isset($dms[$value])) + { + $returnArray[$value] = $dms[$value]; + } + } - // Check Class-Attributes - if (is_null($this->pk)) - return $this->_error(lang('fhc_'.FHC_NOPK), FHC_MODEL_ERROR); - - // Check rights - if (! $this->fhc_db_acl->isBerechtigt($this->acl[$tableName], 'u')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$tableName], FHC_MODEL_ERROR); - - // DB-UPDATE - $this->db->where('dms_id', $id); - - if ($this->db->update($tableName, $data)) - return $this->_success($id); - else - return $this->_error($this->db->error(), FHC_DB_ERROR); + return $returnArray; } } \ No newline at end of file diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index 0523789db..cc7d2e930 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -16,5 +16,86 @@ class Message_model extends DB_Model $this->pk = 'message_id'; } + public function getMessagesByUID($uid, $all) + { + // Check wrights + // @ToDo: Define the special wright for reading own messages "basis/message:own" + // if same user + if ($uid === $this->getUID()) + { + if (! $this->fhc_db_acl->isBerechtigt('basis/message', 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> system/message', FHC_MODEL_ERROR); + } + // if different user, for reading messages from other users + else + { + if (! $this->fhc_db_acl->isBerechtigt('basis/message', 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> system/message:all', FHC_MODEL_ERROR); + } + + // get Data + $sql = 'SELECT uid, person_id, message_id, subject, priority, relationmessage_id, oe_kurzbz, m.insertamum, anrede, titelpost, titelpre, nachname, vorname, vornamen, +status, statusinfo, s.insertamum AS statusamum +FROM public.tbl_msg_message m +JOIN public.tbl_person USING (person_id) +JOIN public.tbl_benutzer USING (person_id) +LEFT JOIN +( + SELECT message_id, person_id, status, statusinfo, tbl_msg_status.insertamum + FROM public.tbl_msg_status + INNER JOIN + ( + SELECT message_id, person_id, max(insertamum) AS insertamum + FROM public.tbl_msg_status + GROUP BY message_id, person_id + ) status + USING (message_id, person_id) + WHERE tbl_msg_status.insertamum=status.insertamum +) s +USING (message_id, person_id) +WHERE uid = ?'; + if (! $all) + $sql .= ' AND status<2'; + $result = $this->db->query($sql, array($uid)); + if (is_object($result)) + return $this->_success($result->result()); + else + return $this->_error($this->db->error(), FHC_DB_ERROR); + } + +public function getMessagesByPerson($person_id, $all) + { + // Check wrights + if (! $this->fhc_db_acl->isBerechtigt('basis/message', 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> system/message', FHC_MODEL_ERROR); + + // get Data + $sql = 'SELECT person_id, message_id, subject, priority, relationmessage_id, oe_kurzbz, m.insertamum, anrede, titelpost, titelpre, nachname, vorname, vornamen, +status, statusinfo, s.insertamum AS statusamum +FROM public.tbl_msg_message m +JOIN public.tbl_person USING (person_id) +LEFT JOIN +( + SELECT message_id, person_id, status, statusinfo, tbl_msg_status.insertamum + FROM public.tbl_msg_status + INNER JOIN + ( + SELECT message_id, person_id, max(insertamum) AS insertamum + FROM public.tbl_msg_status + GROUP BY message_id, person_id + ) status + USING (message_id, person_id) + WHERE tbl_msg_status.insertamum=status.insertamum +) s +USING (message_id, person_id) +WHERE person_id = ?'; + if (! $all) + $sql .= ' AND status<2'; + $result = $this->db->query($sql, array($person_id)); + //var_dump($result); + if (is_object($result)) + return $this->_success($result->result()); + else + return $this->_error($this->db->error(), FHC_DB_ERROR); + } } -/* end of file Message_model.php */ diff --git a/application/views/system/messages.php b/application/views/system/messages.php index 9e76a00b0..dd194c9f9 100644 --- a/application/views/system/messages.php +++ b/application/views/system/messages.php @@ -1,22 +1,20 @@ - -
-
-

Nachricht message_id,': ',$message->subject; ?>

+ + -Absender: person_id; ?>
-Betreff: subject; ?>
-Text: body; ?>
-template->widget("organisationseinheit_widget", array('title' => 'Organisationseinheit', 'oe_kurzbz' => $message->oe_kurzbz)); -?> -
-template->widget("tinymce_widget", array()); -?> - - - -
-
+ + VileSci - Messages + + + + + + + + <body bgcolor="#FFFFFF"> + This application works only with a frames-enabled browser.<br /> + <a href="MessagesList">Use without frames</a> + </body> + + + + diff --git a/application/views/system/messagesList.php b/application/views/system/messagesList.php new file mode 100644 index 000000000..035e2b309 --- /dev/null +++ b/application/views/system/messagesList.php @@ -0,0 +1,35 @@ +load->view('templates/header', array('title' => 'MessagesList', 'tablesort' => true, 'tableid' => 't1', 'headers' => '4:{sorter:false}')); +?> +
+
+

Vorlagen

+
+Person + + +
+ + + + + + + + + + + + + + + + + + + +
VorlageBezeichnungAnmerkungMimeType
vorlage_kurzbz; ?>bezeichnung; ?>anmerkung; ?>mimetype; ?>View
+
+
+ + diff --git a/application/views/system/templatesEdit.php b/application/views/system/templatesEdit.php index b9197f62c..4318f3ba1 100644 --- a/application/views/system/templatesEdit.php +++ b/application/views/system/templatesEdit.php @@ -22,7 +22,7 @@ + - diff --git a/system/checksystem.php b/system/checksystem.php index 383db1d43..3ee4685b6 100644 --- a/system/checksystem.php +++ b/system/checksystem.php @@ -97,6 +97,8 @@ $berechtigungen = array( array('basis/testtool','Administrationseite, Gebiete löschen/zurücksetzen'), array('basis/variable','Variablenverwaltung'), array('basis/vilesci','Grundrecht, um in VileSci irgendwelche Menüpunkte zu sehen'), + array('basis/vorlage','Erstellen und Bearbeiten von Vorlagen'), + array('basis/vorlagestudiengang','Bearbeiten der Texte zu den Vorlagen'), array('buchung/typen','Verwaltung von Buchungstypen'), array('buchung/mitarbeiter','Verwaltung von Buchungen fuer Mitarbeiter'), array('inout/incoming','Incomingverwaltung'), diff --git a/tests/codeception/_data/dump.sql b/tests/codeception/_data/dump.sql index 552d65f75..3a6fcb774 100644 --- a/tests/codeception/_data/dump.sql +++ b/tests/codeception/_data/dump.sql @@ -343,7 +343,8 @@ DELETE FROM system.tbl_rolleberechtigung WHERE berechtigung_kurzbz IN ( 'basis/lehrverband', 'basis/log', 'basis/mitarbeiter', - 'basis/msg_message', + 'basis/msg_message', + 'basis/message', 'basis/msg_thread', 'basis/notiz', 'basis/notizzuordnung', @@ -419,7 +420,8 @@ DELETE FROM system.tbl_rolleberechtigung WHERE berechtigung_kurzbz IN ( 'basis/vw_studiensemester', 'lehre/reservierung', 'lehre/reihungstest', - 'wawi/inventar:begrenzt' + 'wawi/inventar:begrenzt', + 'fs/dms' ); -- DELETE FROM system.tbl_berechtigung @@ -569,6 +571,7 @@ DELETE FROM system.tbl_berechtigung WHERE berechtigung_kurzbz IN ( 'basis/log', 'basis/mitarbeiter', 'basis/msg_message', + 'basis/message', 'basis/msg_thread', 'basis/notiz', 'basis/notizzuordnung', @@ -644,7 +647,8 @@ DELETE FROM system.tbl_berechtigung WHERE berechtigung_kurzbz IN ( 'basis/vw_studiensemester', 'lehre/reservierung', 'lehre/reihungstest', - 'wawi/inventar:begrenzt' + 'wawi/inventar:begrenzt', + 'fs/dms' ); -- INSERT Permissions @@ -869,6 +873,8 @@ INSERT INTO system.tbl_berechtigung (berechtigung_kurzbz, beschreibung) VALUES(' INSERT INTO system.tbl_berechtigung (berechtigung_kurzbz, beschreibung) VALUES('lehre/reservierung', ''); INSERT INTO system.tbl_berechtigung (berechtigung_kurzbz, beschreibung) VALUES('lehre/reihungstest', ''); INSERT INTO system.tbl_berechtigung (berechtigung_kurzbz, beschreibung) VALUES('wawi/inventar:begrenzt', ''); +INSERT INTO system.tbl_berechtigung (berechtigung_kurzbz, beschreibung) VALUES('fs/dms', ''); +INSERT INTO system.tbl_berechtigung (berechtigung_kurzbz, beschreibung) VALUES('basis/message', ''); -- INSERT link between user admin and permissions INSERT INTO system.tbl_rolleberechtigung (berechtigung_kurzbz, rolle_kurzbz, art) VALUES('basis/archiv', 'admin', 'suid'); @@ -1092,6 +1098,8 @@ INSERT INTO system.tbl_rolleberechtigung (berechtigung_kurzbz, rolle_kurzbz, art INSERT INTO system.tbl_rolleberechtigung (berechtigung_kurzbz, rolle_kurzbz, art) VALUES('lehre/reservierung', 'admin', 'suid'); INSERT INTO system.tbl_rolleberechtigung (berechtigung_kurzbz, rolle_kurzbz, art) VALUES('lehre/reihungstest', 'admin', 'suid'); INSERT INTO system.tbl_rolleberechtigung (berechtigung_kurzbz, rolle_kurzbz, art) VALUES('wawi/inventar:begrenzt', 'admin', 'suid'); +INSERT INTO system.tbl_rolleberechtigung (berechtigung_kurzbz, rolle_kurzbz, art) VALUES('fs/dms', 'admin', 'suid'); +INSERT INTO system.tbl_rolleberechtigung (berechtigung_kurzbz, rolle_kurzbz, art) VALUES('basis/message', 'admin', 'suid'); -- EMPTY public.tbl_statistik DELETE FROM public.tbl_statistik;