diff --git a/application/controllers/Cis/Documents.php b/application/controllers/Cis/Documents.php index c5a6684d3..7fd1c4f47 100644 --- a/application/controllers/Cis/Documents.php +++ b/application/controllers/Cis/Documents.php @@ -20,8 +20,12 @@ class Documents extends Auth_Controller 'download' => [self::PERM_LOGGED] ]); + // Load models $this->load->model('crm/Prestudentstatus_model', 'PrestudentstatusModel'); + // Load libraries + $this->load->library('AkteLib'); + $this->loadPhrases([ 'global', 'tools' @@ -112,10 +116,12 @@ class Documents extends Auth_Controller $selfservice = null; if (!defined('CIS_DOKUMENTE_SELFSERVICE') || CIS_DOKUMENTE_SELFSERVICE) { - $this->load->model('crm/Akte_model', 'AkteModel'); $selfservice = []; foreach ($person_ids as $person_id) { - $result = $this->AkteModel->getArchiv($person_id, null, true); + $result = $this->aktelib->getByPersonId( + $person_id, + true + ); if (isError($result)) return $this->load->view('errors/html/error_db.php', [ 'heading' => 'Database Error', @@ -147,14 +153,13 @@ class Documents extends Auth_Controller if (!is_numeric($akte_id)) return show_404(); - $this->load->model('crm/Akte_model', 'AkteModel'); - $result = $this->AkteModel->load($akte_id); + $result = $this->aktelib->getByPersonId($akte_id); if (isError($result)) return show_error(getError($result)); $akte = getData($result); if (!$akte) return show_404(); - $akte = current($akte); + $akte = reset($akte); $admin_access = false; if ($uid !== null && $this->permissionlib->isBerechtigt('admin')) { diff --git a/application/controllers/api/frontend/v1/stv/Archiv.php b/application/controllers/api/frontend/v1/stv/Archiv.php index cc636951d..6f01bb89c 100644 --- a/application/controllers/api/frontend/v1/stv/Archiv.php +++ b/application/controllers/api/frontend/v1/stv/Archiv.php @@ -46,6 +46,9 @@ class Archiv extends FHCAPI_Controller $this->load->model('crm/Akte_model', 'AkteModel'); $this->load->model('system/Vorlage_model', 'VorlageModel'); + // Load libraries + $this->load->library('AkteLib'); + // Load language phrases $this->loadPhrases([ 'archiv' @@ -74,7 +77,10 @@ class Archiv extends FHCAPI_Controller $this->terminateWithValidationErrors($this->form_validation->error_array()); } - $result = $this->AkteModel->getArchiv($person_id); + $result = $this->aktelib->getByPersonId( + $person_id, + true // archiv + ); $data = $this->getDataOrTerminateWithError($result); @@ -105,53 +111,55 @@ class Archiv extends FHCAPI_Controller if (!is_numeric($akte_id)) $this->terminateWithError('akte Id missing'); - $result = $this->AkteModel->load($akte_id); - + $result = $this->aktelib->getByAkteId($akte_id); if (!hasData($result)) $this->terminateWithError('Akte not found'); - $data = $this->getDataOrTerminateWithError($result); + $data = $this->getDataOrTerminateWithError($result)[0]; - $data = getData($result)[0]; - //$this->addMeta("daa", $data->inhalt); - - $fileObj = new stdClass(); - if (isset($data->inhalt) && $data->inhalt != '') + // If the file content is from the akte table or from the DMS + if (!isEmptyString($data->inhalt) || !isEmptyString($data->filename)) { // Define handle to output stream - $tmpFilePointer = fopen("php://output", 'w'); + $tmpFilePointer = fopen("php://output", 'w'); $meta_data = stream_get_meta_data($tmpFilePointer); $filename = $meta_data["uri"]; - fwrite($tmpFilePointer, $data->inhalt); + + // File content from akte... + if (!isEmptyString($data->inhalt)) + { + // Writes into the output buffer + fwrite($tmpFilePointer, $data->inhalt); + } + else //...or from DMS + { + $this->load->model('content/DmsFS_model', 'DmsFSModel'); + + $fileHandleResult = $this->DmsFSModel->openRead($data->filename); + if (isError($fileHandleResult) || !hasData($fileHandleResult)) $this->terminateWithError('DMS is not able to load this file'); + + // Read blocks from the file and writes them into the output buffer + while (hasData($fileData = readBlock($fileHandleResult))) + { + fwrite($tmpFilePointer, $fileData); + } + } + + fclose($tmpFilePointer); header('Content-Description: File Transfer'); header('Content-Type: '. $data->mimetype); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); - //header('Content-Length: ' . filesize($fileObj->file)); - //header("Content-type: $data->mimetype"); header('Content-Disposition: attachment; filename="'.$data->titel.'"'); readfile($filename); - //echo base64_decode($data->inhalt); die(); - //~ $fileObj->file = $data->inhalt; - //~ $fileObj->name = $data->titel; - //~ $fileObj->mimetype = $data->mimetype; - //~ $fileObj->disposition = 'attachment'; } else { - $this->load->library('AkteLib'); - - $result = $this->aktelib->get($akte_id); + $this->terminateWithError('This file content is not available'); } - - /* $fileObj->filename - * $fileObj->file - * $fileObj->name - * $fileObj->mimetype - * $fileObj->disposition*/ } /** diff --git a/application/controllers/system/infocenter/InfoCenter.php b/application/controllers/system/infocenter/InfoCenter.php index 1fc49c72f..dc2bc0913 100644 --- a/application/controllers/system/infocenter/InfoCenter.php +++ b/application/controllers/system/infocenter/InfoCenter.php @@ -177,6 +177,7 @@ class InfoCenter extends Auth_Controller // Loads libraries $this->load->library('PersonLogLib'); $this->load->library('WidgetLib'); + $this->load->library('AkteLib'); $this->load->config('infocenter'); @@ -441,8 +442,7 @@ class InfoCenter extends Auth_Controller if (isset($akte_id) && isset($person_id)) { - $this->load->library('AkteLib'); - $akte = $this->aktelib->get($akte_id); + $akte = $this->aktelib->getByAkteId($akte_id); if (hasData($akte)) { @@ -1158,8 +1158,6 @@ class InfoCenter extends Auth_Controller */ public function outputAkteContent($akte_id) { - $this->load->library('DmsLib'); - $akte = $this->AkteModel->load($akte_id); if (isError($akte)) @@ -1167,7 +1165,7 @@ class InfoCenter extends Auth_Controller show_error(getError($akte)); } - $aktecontent = $this->dmslib->getAkteContent($akte_id); + $aktecontent = $this->aktelib->getByAkteId($akte_id); if (isError($aktecontent)) { @@ -2422,4 +2420,4 @@ class InfoCenter extends Auth_Controller $this->outputJsonSuccess("Success"); } -} \ No newline at end of file +} diff --git a/application/libraries/AkteLib.php b/application/libraries/AkteLib.php index c4aee0095..3f09853dc 100644 --- a/application/libraries/AkteLib.php +++ b/application/libraries/AkteLib.php @@ -121,54 +121,32 @@ class AkteLib * Gets akte data and associated dms data by akte Id * Returns success with akte and dms data or error */ - public function get($akte_id) + public function getByAkteId($akte_id, $archiv = null, $signiert = null, $stud_selfservice = null) { - // get Akte data - $this->_ci->AkteModel->addSelect('person_id, dokument_kurzbz, mimetype, erstelltam, titel, bezeichnung, - gedruckt, uid, dms_id, nachgereicht, nachgereicht_am, anmerkung, - ausstellungsnation, formal_geprueft_amum, archiv, signiert, - stud_selfservice, akzeptiertamum, insertvon, insertamum, updatevon, updateamum'); - $this->_ci->AkteModel->load($akte_id); - $akteResult = $this->_ci->AkteModel->load($akte_id); + return $this->_get( + $akte_id, + null, // person_id + null, // dokument_kurzbz + $archiv, + $signiert, + $stud_selfservice + ); + } - if (isError($akteResult)) return $akteResult; - - if (!hasData($akteResult)) return error("Akte not found"); - - $resultObject = getData($akteResult)[0]; - - // set properties with same name in Akte and Dms table - $resultObject->akte_mimetype = $resultObject->mimetype; - - // get dms data - $dmsResult = $this->_ci->dmslib->getLastVersion($resultObject->dms_id); - - if (isError($dmsResult)) return $dmsResult; - - // properties to retrieve from dms - $dmsProperties = array('version', 'filename', 'mimetype', 'name', 'beschreibung', 'cis_suche', 'schlagworte', DmsLib::FILE_CONTENT_PROPERTY); - - // set dms properties - if (hasData($dmsResult)) - { - $dmsData = getData($dmsResult); - - foreach ($dmsProperties as $dmsProperty) - { - $resultObject->{$dmsProperty} = $dmsData->{$dmsProperty}; - } - } - else - { - // set null if no dms result found - foreach ($dmsProperties as $dmsProperty) - { - $resultObject->{$dmsProperty} = null; - } - } - - // return the object containing akte and dms data - return success($resultObject); + /** + * Gets Akte data and associated dms data by person Id + * Returns success with result array with akte and dms data or error + */ + public function getByPersonId($person_id, $archiv = null, $signiert = null, $stud_selfservice = null) + { + return $this->_get( + null, // akte_id + $person_id, + null, // dokument_kurzbz + $archiv, + $signiert, + $stud_selfservice + ); } /** @@ -177,34 +155,14 @@ class AkteLib */ public function getByPersonIdAndDocumentType($person_id, $dokument_kurzbz) { - // load all Akte entries for given person and dokument_kurzbz - $this->_ci->AkteModel->addSelect('akte_id'); - $akteResult = $this->_ci->AkteModel->loadWhere( - array( - 'person_id' => $person_id, - 'dokument_kurzbz' => $dokument_kurzbz - ) + return $this->_get( + null, // akte_id + $person_id, + $dokument_kurzbz, + $archiv, + $signiert, + $stud_selfservice ); - - if (!hasData($akteResult)) return error("Akte not found"); - - $akteData = getData($akteResult); - - $resultArr = array(); - - // for each found akte entry - foreach ($akteData as $akte) - { - // get dms and akte data from akte Id - $getAkteDmsResult = $this->get($akte->akte_id); - - if (isError($getAkteDmsResult)) return $getAkteDmsResult; - - $resultArr[] = getData($getAkteDmsResult); - } - - // return all found entries - return success($resultArr); } /** @@ -265,4 +223,99 @@ class AkteLib return $removeAllResult; } } + + /** + * + */ + private function _get($akte_id = null, $person_id = null, $dokument_kurzbz = null, $archiv = null, $signiert = null, $stud_selfservice = null) + { + // get Akte data + $this->_ci->AkteModel->addSelect('akte_id'); + $this->_ci->AkteModel->addSelect('person_id'); + $this->_ci->AkteModel->addSelect('dokument_kurzbz'); + $this->_ci->AkteModel->addSelect('inhalt'); + $this->_ci->AkteModel->addSelect('CASE WHEN inhalt is not null THEN true ELSE false END as inhalt_vorhanden', false); + $this->_ci->AkteModel->addSelect('mimetype'); + $this->_ci->AkteModel->addSelect('erstelltam'); + $this->_ci->AkteModel->addSelect('gedruckt'); + $this->_ci->AkteModel->addSelect('titel'); + $this->_ci->AkteModel->addSelect('bezeichnung'); + $this->_ci->AkteModel->addSelect('updateamum'); + $this->_ci->AkteModel->addSelect('updatevon'); + $this->_ci->AkteModel->addSelect('insertamum'); + $this->_ci->AkteModel->addSelect('insertvon'); + $this->_ci->AkteModel->addSelect('uid'); + $this->_ci->AkteModel->addSelect('dms_id'); + $this->_ci->AkteModel->addSelect('nachgereicht'); + $this->_ci->AkteModel->addSelect('anmerkung'); + $this->_ci->AkteModel->addSelect('titel_intern'); + $this->_ci->AkteModel->addSelect('anmerkung_intern'); + $this->_ci->AkteModel->addSelect('nachgereicht_am'); + $this->_ci->AkteModel->addSelect('ausstellungsnation'); + $this->_ci->AkteModel->addSelect('formal_geprueft_amum'); + $this->_ci->AkteModel->addSelect('archiv'); + $this->_ci->AkteModel->addSelect('signiert'); + $this->_ci->AkteModel->addSelect('stud_selfservice'); + $this->_ci->AkteModel->addSelect('akzeptiertamum'); + + // Query parameters + $paramArray = array(); + + // Key to access the table + if (is_int($akte_id) || is_array($akte_id)) $paramArray['akte_id'] = $akte_id; + if (is_int($person_id) || is_array($person_id)) $paramArray['person_id'] = $person_id; + if (!isEmptyString($dokument_kurzbz)) $paramArray['dokument_kurzbz'] = $dokument_kurzbz; + + // If parameters are provided then use them in the query + if (is_bool($archiv)) $paramArray['archiv'] = $archiv; + if (is_bool($signiert)) $paramArray['signiert'] = $signiert; + if (is_bool($stud_selfservice)) $paramArray['stud_selfservice'] = $stud_selfservice; + + // Loads data from DB + $akteResult = $this->_ci->AkteModel->loadWhere($paramArray); + + // If error or data not found then exit + if (isError($akteResult)) return $akteResult; + if (!hasData($akteResult)) return error('Akte not found'); + + // For each record from the akte + foreach ($resultObject as getData($akteResult)) + { + // get dms data + $dmsResult = $this->_ci->dmslib->getLastVersion($resultObject->dms_id); + + if (isError($dmsResult)) return $dmsResult; + + // properties to retrieve from dms + $dmsProperties = array('version', 'filename', 'mimetype', 'name', 'beschreibung', 'cis_suche', 'schlagworte', DmsLib::FILE_CONTENT_PROPERTY); + + // set dms properties + if (hasData($dmsResult)) + { + $dmsData = getData($dmsResult); + + foreach ($dmsProperties as $dmsProperty) + { + // If the property is _not_ 'mimetype' _or_ + // If the mimetype from the akte table is null then overwrite it with the one from the DMS + if ($dmsProperty != 'mimetype' || ($dmsProperty == 'mimetype' && $resultObject->{$dmsProperty} == null)) + { + $resultObject->{$dmsProperty} = $dmsData->{$dmsProperty}; + } + } + } + else + { + // set null if no dms result found + foreach ($dmsProperties as $dmsProperty) + { + if ($dmsProperty != 'mimetype') $resultObject->{$dmsProperty} = null; + } + } + } + + // return the object containing akte and dms data + return success(getData($akteResult)); + } } + diff --git a/application/libraries/DmsLib.php b/application/libraries/DmsLib.php index 774ebdc79..7b8eef339 100644 --- a/application/libraries/DmsLib.php +++ b/application/libraries/DmsLib.php @@ -17,6 +17,8 @@ class DmsLib { const FILE_CONTENT_PROPERTY = 'file_content'; // property name for file content + private $_UPLOAD_PATH; // temporary directory to store the uploaded file + private $_ci; // code igniter instance private $_who; // who added this document @@ -27,12 +29,13 @@ class DmsLib { $this->_ci =& get_instance(); + $this->_UPLOAD_PATH = APPPATH.'tmp/'; + // Set the the _who property $this->_who = 'DMS system'; // default // It is possible to set it using the who parameter if (!isEmptyArray($params) && isset($params['who']) && !isEmptyString($params['who'])) $this->_who = $params['who']; - $this->_ci->load->model('crm/Akte_model', 'AkteModel'); // deprecated, should not be used here! $this->_ci->load->model('content/Dms_model', 'DmsModel'); $this->_ci->load->model('content/DmsVersion_model', 'DmsVersionModel'); $this->_ci->load->model('content/DmsFS_model', 'DmsFSModel'); @@ -256,32 +259,9 @@ class DmsLib if (isError($dmsVersionResult)) return $dmsVersionResult; - if (hasData($dmsVersionResult)) - { - $dmsVersion = getData($dmsVersionResult)[0]; + if (hasData($dmsVersionResult)) return getData($dmsVersionResult)[0]; - // get file content as file pointer - $fileHandleResult = $this->_ci->DmsFSModel->openRead($dmsVersion->filename); - - if (isError($fileHandleResult)) return $fileHandleResult; - - if (hasData($fileHandleResult)) - { - $fileHandle = getData($fileHandleResult); - $dmsVersion->{self::FILE_CONTENT_PROPERTY} = $fileHandle; - - // close file pointer - $closeResult = $this->_ci->DmsFSModel->close($fileHandle); - - if (isError($closeResult)) return $closeResult; - - return success($dmsVersion); - } - else - return error("File could not be opened"); - } - else - return error("Dms version not found"); + return error("Dms version not found"); } /** @@ -420,6 +400,50 @@ class DmsLib return success($removeVersionResultObj); } + /** + * Perform an upload of a file spcifically for the DMS and returns the uploaded file info + */ + public function upload($allowed_types = array('*')) + { + // Loads the CI upload library + $this->_loadUploadLibrary($allowed_types); + + // If the upload was a success then return the uploaded file info + if ($this->_ci->upload->do_upload(DmsLib::FILE_CONTENT_PROPERTY)) return success($this->_ci->upload->data()); + + // If an error occurred then return it + return error($this->_ci->upload->display_errors('', '')); + } + + /** + * Get info from the DMS to be provided to the FHC_Controller->outputFile + */ + public function getOutputFileInfo($dms_id, $file_name = '', $disposition = 'attachment') + { + // Loads the last DMS version from database + $lastVersionResult = $this->getLastVersion($dms_id); + + // If an error occurred then return it + if (isError($lastVersionResult)) return $lastVersionResult; + + // If has been found + if (hasData($lastVersionResult)) + { + $lastVersion = getData(lastVersionResult)[0]; + + $fileObj = new stdClass(); + $fileObj->filename = $lastVersion->filename; + $fileObj->file = DMS_PATH.$lastVersion->filename; + $fileObj->name = isEmptyString($file_name) ? DMS_PATH.$lastVersion->name : $file_name; + $fileObj->mimetype = $lastVersion->mimetype; + $fileObj->disposition = $disposition; + + return success($fileObj); + } + + return success(); + } + // ----------------------------------------------------------------------------------------------------------- // Private methods @@ -475,431 +499,19 @@ class DmsLib return $uniqueFilename; } - // ----------------------------------------------------------------------------------------------------------- - // Deprecated methods, not to be used - - /** - * Load a DMS Document. - * If no version is particularly given, the latest version is loaded. - * - * @param $dms_id - * @param integer $version - * @return array - */ - public function load($dms_id, $version = null) - { - if (is_numeric($dms_id)) - { - $this->_ci->DmsModel->addJoin('campus.tbl_dms_version', 'dms_id'); - $this->_ci->DmsModel->addOrder('version', 'DESC'); - $this->_ci->DmsModel->addLimit(1); - - if (!is_numeric($version)) - { - return $this->_ci->DmsModel->load($dms_id); - } - else - { - return $this->_ci->DmsModel->loadWhere(array('dms_id' => $dms_id, 'version' => $version)); - } - } - - return error('The parameter DMS ID must be a number'); - } - - /** - * Read a DMS Document from the Filesystem - * @param int $dms_id ID of the Document. - * @param int $version The version of the Document (latest if null). - * @return object success or error - */ - public function read($dms_id, $version = null) - { - $result = error('Wrong dms_id parameter'); - - if (isset($dms_id)) - { - $this->_ci->DmsModel->addJoin('campus.tbl_dms_version', 'dms_id'); - $this->_ci->DmsModel->addOrder('version', 'DESC'); - $this->_ci->DmsModel->addLimit(1); - - if (!isset($version)) - { - $result = $this->_ci->DmsModel->load($dms_id); - } - else - { - $result = $this->_ci->DmsModel->loadWhere(array('dms_id' => $dms_id, 'version' => $version)); - } - - // If a dms has been found - if (hasData($result)) - { - $resultFS = $this->_ci->DmsFSModel->readBase64(getData($result)[0]->filename); - if (isError($resultFS)) return $resultFS; // if an error occurred return it - - $result->retval[0]->{self::FILE_CONTENT_PROPERTY} = getData($resultFS); - } - } - - return $result; - } - - /** - * Get all accepted Documents of a Person - * - * @param int $person_id ID of the person. - * @param string $dokument_kurzbz Type of document. - * @param bool $no_file If null then loads also the content. - * @return object success or error - */ - public function getAktenAcceptedDms($person_id, $dokument_kurzbz = null, $no_file = null) - { - $result = $this->_ci->AkteModel->getAktenAcceptedDms($person_id, $dokument_kurzbz); - - if (hasData($result) && $no_file == null) - { - for ($i = 0; $i < count(getData($result)); $i++) - { - $resultFS = $this->_ci->DmsFSModel->readBase64(getData($result)[$i]->filename); - if (isError($resultFS)) return $resultFS; // if an error occurred return it - - $result->retval[$i]->{self::FILE_CONTENT_PROPERTY} = getData($resultFS); - } - } - - return $result; - } - - /** - * Uploads a document and saves it to DMS - * @param $dms DMS assoc array - * @param $field_name Name of the HTML uploadfile input name attribute - * @param array $allowed_types Default: all. Param example: array(jpg, pdf) - * @return array - */ - public function upload($dms, $field_name, $allowed_types = array('*')) - { - // Init upload configs - $this->_loadUploadLibrary($allowed_types); - - if (!$this->_ci->upload->do_upload($field_name)) - { - return error($this->_ci->upload->display_errors()); - } - - $upload_data = $this->_ci->upload->data(); // data about the uploaded file - - // Insert to DMS table - $insDmsResult = $this->_ci->DmsModel->insert($this->_ci->DmsModel->filterFields($dms)); - if (isError($insDmsResult)) return $insDmsResult; - - $upload_data['dms_id'] = getData($insDmsResult); - if(isset($upload_data['file_type']) && !isset($dms['mimetype'])) - $dms['mimetype'] = $upload_data['file_type']; - - // Insert DMS version - $insVersionResult = $this->_ci->DmsVersionModel->insert( - $this->_ci->DmsVersionModel->filterFields( - $dms, - $upload_data['dms_id'], - $upload_data['file_name'] - ) - ); - if (isError($insVersionResult)) return $insVersionResult; - - // Return result of uploaded data - return success($upload_data); - } - - /** - * Download a document. - * - * @param $dms_id - * @param string $filename $filename If String is given, it will be used as filename on download - * @param string $disposition [inline | attachment] - * Inline opens doc in new tab. Attachment displays download dialog box. - */ - public function download($dms_id, $filename = null, $disposition = 'inline') - { - // Retrieves info about the given dms - $fileInfoResult = $this->getFileInfo($dms_id); - if (isError($fileInfoResult)) return error(getError($fileInfoResult)); - - // If data have been found - if (hasData($fileInfoResult)) - { - $fileObj = getData($fileInfoResult); - - // Change filename, if filename is provided - if (!isEmptyString($filename)) $fileObj->name = $filename; - - // Add file disposition if disposition has a valid value - if ($disposition == 'attachment' || $disposition == 'inline') - { - $fileObj->disposition = $disposition; - } - - return success($fileObj); - } - - // If no data have been found then return an empty success - return success(); - } - - /** - * Get file information. - * - * @param $dms_id - * @param integer $version - * @return array with File Object. - */ - public function getFileInfo($dms_id, $version = null) - { - // Checks the dms_id parameter - if (!is_numeric($dms_id)) return error('Wrong parameter'); - - // Load DMS from database - $result = $this->load($dms_id, $version); - if (isError($result)) return error(getError($result)); - - // If data have been found - if (hasData($result)) - { - // Store file information in fileObj - $fileObj = new stdClass(); - $fileObj->filename = getData($result)[0]->filename; - $fileObj->file = DMS_PATH.getData($result)[0]->filename; - $fileObj->name = DMS_PATH.getData($result)[0]->name; // original user filename - $fileObj->mimetype = getData($result)[0]->mimetype; - - return success($fileObj); - } - - // If no data have been found return an empty success - return success(); - } - - /** - * Saves a Document - * @param object $dms DMS Object ot be saved. - * @return object - */ - public function save($dms) - { - $result = null; - - if (isset($dms['new']) && $dms['new'] == true) - { - // Remove new parameter to avoid DB insert errors - unset($dms['new']); - - $result = $this->_saveFileOnInsert($dms); - if (isSuccess($result)) - { - $filename = getData($result); - if (isset($dms['dms_id']) && $dms['dms_id'] != '') - { - $result = $this->_ci->DmsVersionModel->insert( - $this->_ci->DmsVersionModel->filterFields($dms, $dms['dms_id'], $filename) - ); - } - else - { - $result = $this->_ci->DmsModel->insert($this->_ci->DmsModel->filterFields($dms)); - if (isSuccess($result)) - { - $result = $this->_ci->DmsVersionModel->insert( - $this->_ci->DmsVersionModel->filterFields($dms, getData($result), $filename) - ); - } - } - } - } - else - { - $result = $this->_saveFileOnUpdate($dms); - if (isSuccess($result)) - { - $result = $this->_ci->DmsModel->update($dms['dms_id'], $this->_ci->DmsModel->filterFields($dms)); - if (isSuccess($result)) - { - $result = $this->_ci->DmsVersionModel->update( - array( - $dms['dms_id'], - $dms['version'] - ), - $this->_ci->DmsVersionModel->filterFields($dms) - ); - } - } - } - - return $result; - } - - /** - * Deletes a Akte of a Person - * @param int $person_id ID of the person. - * @param int $dms_id Id of the Document. - * @return object - */ - public function delete($person_id, $dms_id) - { - $result = null; - - // If the parameters are valid - if (is_numeric($person_id) && is_numeric($dms_id)) - { - // Start DB transaction - $this->_ci->db->trans_start(false); - - // Get akte_id from table tbl_akte - $result = $this->_ci->AkteModel->loadWhere(array('person_id' => $person_id, 'dms_id' => $dms_id)); - if (isSuccess($result)) - { - // Delete all entries in tbl_akte - for ($i = 0; $i < count(getData($result)); $i++) - { - $this->_ci->AkteModel->delete(getData($result)[$i]->akte_id); - } - - // Get all filenames related to this dms - $resultFileNames = $this->_ci->DmsVersionModel->loadWhere(array('dms_id' => $dms_id)); - if (isSuccess($resultFileNames)) - { - // Delete from tbl_dms_version - $result = $this->_ci->DmsVersionModel->delete(array('dms_id' => $dms_id)); - if (isSuccess($result)) - { - // Delete from tbl_dms - $result = $this->_ci->DmsModel->delete($dms_id); - } - } - } - - // Transaction complete! - $this->_ci->db->trans_complete(); - - // Check if everything went ok during the transaction - if ($this->_ci->db->trans_status() === false || isError($result)) - { - $this->_ci->db->trans_rollback(); - $result = error('An error occurred while performing a delete operation', EXIT_ERROR); - } - else - { - $this->_ci->db->trans_commit(); - $result = success('Dms successfully removed from DB'); - } - - // If everything is ok - if (isSuccess($result)) - { - // Remove all files related to this person and dms - for ($i = 0; $i < count(getData($resultFileNames)); $i++) - { - $this->_ci->DmsFSModel->removeBase64(getData($resultFileNames)[$i]->filename); - } - } - } - else - { - $result = error('Invalid parameters'); - } - - return $result; - } - - /** - * Loads the Content of an akte - * @param int $akte_id Id of the akte. - * @return object with document content or error - */ - public function getAkteContent($akte_id) - { - $akte = $this->_ci->AkteModel->load($akte_id); - if (hasData($akte)) - { - if (getData($akte)[0]->inhalt != '') - { - return success(base64_decode(getData($akte)[0]->inhalt)); - } - elseif (getData($akte)[0]->dms_id != '') - { - $dmscontent = $this->read(getData($akte)[0]->dms_id); - if (isSuccess($dmscontent)) - { - return success(base64_decode(getData($dmscontent)[0]->file_content)); - } - else - { - return error(getError($dmscontent)); - } - } - else - { - return error('No Content available'); - } - } - else - { - return error(getError($akte)); - } - } - - /** - * Saves the Content of a DMS in the Filesystem - * @param object $dms DMS object to be saved. - * @return object - */ - private function _saveFileOnInsert($dms) - { - $filename = uniqid().'.'.pathinfo($dms['name'], PATHINFO_EXTENSION); - - $result = $this->_ci->DmsFSModel->writeBase64($filename, $dms['file_content']); - if (isSuccess($result)) - { - $result = success($filename); - } - - return $result; - } - - /** - * Updates the File in the Filesystem - * @param object $dms DMS object to update. - * @return object - */ - private function _saveFileOnUpdate($dms) - { - $result = null; - - if (isset($dms['version'])) - { - $result = $this->read($dms['dms_id'], $dms['version']); - - if (hasData($result)) - { - $result = $this->_ci->DmsFSModel->writeBase64(getData($result)[0]->filename, $dms['file_content']); - } - } - - return $result; - } - /** * Loads the upload library of CI */ private function _loadUploadLibrary($allowed_types) { - $config = array(); - $config['upload_path'] = DMS_PATH; - $config['allowed_types'] = implode('|', $allowed_types); - $config['overwrite'] = true; - $config['file_name'] = uniqid().'.pdf'; - - $this->_ci->load->library('upload', $config); - $this->_ci->upload->initialize($config); + $this->_ci->load->library( + 'upload', + array( + 'upload_path' => $this->_UPLOAD_PATH, + 'allowed_types' => $allowed_types, + 'overwrite' => true + ) + ); } } + diff --git a/application/models/crm/Akte_model.php b/application/models/crm/Akte_model.php index b945f414a..dc072d4af 100644 --- a/application/models/crm/Akte_model.php +++ b/application/models/crm/Akte_model.php @@ -248,60 +248,5 @@ class Akte_model extends DB_Model return success($dokumente->retval); } - - /** - * Liefert die Archivdokumente einer Person/mehrerer Personen - * - * @param integer/array $person_id - * @param boolean|null $signiert Wenn true werden nur Dokumente geliefert die digital signiert wurden. - * @param boolean|null $stud_selfservice Wenn true werden nur Dokumente geliefert die Studierende selbst herunterladen duerfen. - * - * @return stdClass - */ - public function getArchiv($person_id, $signiert = null, $stud_selfservice = null) - { - $this->addSelect('akte_id'); - $this->addSelect('person_id'); - $this->addSelect('dokument_kurzbz'); - $this->addSelect('mimetype'); - $this->addSelect('erstelltam'); - $this->addSelect('gedruckt'); - $this->addSelect('titel_intern'); - $this->addSelect('anmerkung_intern'); - $this->addSelect('titel'); - $this->addSelect('bezeichnung'); - $this->addSelect('updateamum'); - $this->addSelect('insertamum'); - $this->addSelect('updatevon'); - $this->addSelect('insertvon'); - $this->addSelect('uid'); - $this->addSelect('dms_id'); - $this->addSelect('anmerkung'); - $this->addSelect('nachgereicht'); - $this->addSelect('CASE WHEN inhalt is not null THEN true ELSE false END as inhalt_vorhanden', false); - $this->addSelect('nachgereicht_am'); - $this->addSelect('ausstellungsnation'); - $this->addSelect('formal_geprueft_amum'); - $this->addSelect('archiv'); - $this->addSelect('signiert'); - $this->addSelect('stud_selfservice'); - $this->addSelect('akzeptiertamum'); - - if ($signiert !== null) - $this->db->where('signiert', (boolean)$signiert); - if ($stud_selfservice !== null) - $this->db->where('stud_selfservice', (boolean)$stud_selfservice); - - if (is_array($person_id)) - $this->db->where_in('person_id', $person_id); - else - $this->db->where('person_id', $person_id); - - $this->addOrder('erstelltam', 'DESC'); - $this->addOrder('akte_id', 'DESC'); - - return $this->loadWhere([ - 'archiv' => true - ]); - } } +