alter document download to use dmslib and new terminateWithFileOutput funtion of FHCAPI_Controller, render download button as link

This commit is contained in:
Harald Bamberger
2025-05-28 16:38:26 +02:00
parent 4d3d06e1d6
commit 8bcf01d1bb
3 changed files with 41 additions and 33 deletions
@@ -24,6 +24,7 @@ class Dokumente extends FHCAPI_Controller
// Load Libraries
$this->load->library('VariableLib', ['uid' => getAuthUID()]);
$this->load->library('form_validation');
$this->load->library('DmsLib', array('who' => getAuthUID()));
// Load language phrases
$this->loadPhrases([
@@ -417,26 +418,35 @@ class Dokumente extends FHCAPI_Controller
$result = $this->AkteModel->load($akte_id);
if (!hasData($result)) $this->terminateWithError('Akte not found');
$data = getData($result)[0];
header('Content-Description: File Transfer');
header('Content-Type: '. $data->mimetype);
header('Content-Disposition: attachment; filename="'.$data->titel.'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
if (isset($data->inhalt) && !empty($data->inhalt)) {
$decodedContent = base64_decode($data->inhalt, true);
$mimetype = $data->mimetype;
$filecontentbase64 = $data->inhalt;
$filename = $data->titel;
if ($decodedContent === false) {
die('Error: Base64-Dekodierung failed.');
}
echo $decodedContent;
if(intval($data->dms_id) > 0)
{
$dmsdokres = $this->dmslib->read($data->dms_id);
if (!hasData($dmsdokres)) $this->terminateWithError('DMS File not found');
$dmsdok = getData($dmsdokres)[0];
$mimetype = $dmsdok->mimetype;
$filecontentbase64 = $dmsdok->file_content;
$filename = $dmsdok->name;
}
die();
$filecontent = '';
if (!empty($filecontentbase64)) {
$filecontent = base64_decode($filecontentbase64, true);
if ($filecontent === false) {
$this->terminateWithError('Base64-Dekodierung failed.');
}
}
$this->terminateWithFileOutput($mimetype, $filecontent, $filename);
}
private function _getMissingDocuments($studiengang_kz, $prestudent_id)
@@ -101,13 +101,13 @@ export default {
container.className = "d-flex gap-2";
if(cell.getData().vorhanden){
let button = document.createElement('button');
let button = document.createElement('a');
button.className = 'btn btn-outline-secondary btn-action';
button.innerHTML = '<i class="fa fa-download"></i>';
button.title = this.$p.t('ui', 'downloadDok');
button.addEventListener('click', (event) =>
this.actionDownloadFile(cell.getData().akte_id)
);
button.href = this.actionDownloadFile(cell.getData().akte_id);
button.role = 'button';
button.target = '_blank';
container.append(button);
button = document.createElement('button');
@@ -205,11 +205,10 @@ export default {
},
methods: {
actionDownloadFile(akte_id){
window.open(
FHC_JS_DATA_STORAGE_OBJECT.app_root
+ FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/api/frontend/v1/stv/dokumente/download?akte_id=' + encodeURIComponent(akte_id),
'_blank'
);
return FHC_JS_DATA_STORAGE_OBJECT.app_root
+ FHC_JS_DATA_STORAGE_OBJECT.ci_router
+ '/api/frontend/v1/stv/dokumente/download?akte_id='
+ encodeURIComponent(akte_id);
},
actionUploadFile(dokument_kurzbz){
this.$refs.modalUpload.open(this.prestudent_id, dokument_kurzbz);
@@ -118,13 +118,13 @@ export default {
container.className = "d-flex gap-2";
if(cell.getData().akte_id){
let button = document.createElement('button');
let button = document.createElement('a');
button.className = 'btn btn-outline-secondary btn-action';
button.innerHTML = '<i class="fa fa-download"></i>';
button.title = this.$p.t('ui', 'downloadDok');
button.addEventListener('click', (event) =>
this.actionDownloadFile(cell.getData().akte_id)
);
button.href = this.actionDownloadFile(cell.getData().akte_id);
button.role = 'button';
button.target = '_blank';
container.append(button);
button = document.createElement('button');
@@ -213,11 +213,10 @@ export default {
},
methods: {
actionDownloadFile(akte_id){
window.open(
FHC_JS_DATA_STORAGE_OBJECT.app_root
+ FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/api/frontend/v1/stv/dokumente/download?akte_id=' + encodeURIComponent(akte_id),
'_blank'
);
return FHC_JS_DATA_STORAGE_OBJECT.app_root
+ FHC_JS_DATA_STORAGE_OBJECT.ci_router
+ '/api/frontend/v1/stv/dokumente/download?akte_id='
+ encodeURIComponent(akte_id);
},
actionUploadFile(dokument_kurzbz){
this.$refs.modalUpload.open(this.prestudent_id, dokument_kurzbz);