From 9bd5f6dcb62573ce62c33a7007d47a109f62abfa Mon Sep 17 00:00:00 2001 From: Alexei Karpenko Date: Wed, 26 Feb 2025 19:38:09 +0100 Subject: [PATCH] Studierendenverwaltung Archiv: enabled download of documents --- .../controllers/api/frontend/v1/stv/Akte.php | 70 +++++++++++++++++++ .../Stv/Studentenverwaltung/Details/Archiv.js | 2 +- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 application/controllers/api/frontend/v1/stv/Akte.php diff --git a/application/controllers/api/frontend/v1/stv/Akte.php b/application/controllers/api/frontend/v1/stv/Akte.php new file mode 100644 index 000000000..1d38c96d4 --- /dev/null +++ b/application/controllers/api/frontend/v1/stv/Akte.php @@ -0,0 +1,70 @@ +. + */ + +if (!defined('BASEPATH')) exit('No direct script access allowed'); + +/** + * Controller for downloading Akte + */ +class Akte extends Auth_Controller +{ + /** + * Calls the parent's constructor and prepares libraries and phrases + */ + public function __construct() + { + parent::__construct([ + 'download' => ['admin:w', 'assistenz:w'], + ]); + + // Load models + $this->load->model('crm/Akte_model', 'AkteModel'); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * + * Downloads an Akte + */ + public function download() + { + $akte_id = $this->input->get('akte_id'); + + if (!is_numeric($akte_id)) $this->terminateWithError('akte Id missing'); + + $result = $this->AkteModel->load($akte_id); + + if (!hasData($result)) $this->terminateWithError('Akte not found'); + + $data = getData($result)[0]; + + if (isset($data->inhalt) && $data->inhalt != '') + { + header('Content-Description: File Transfer'); + header('Content-Type: '. $data->mimetype); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Disposition: attachment; filename="'.$data->titel.'"'); + echo base64_decode($data->inhalt); + die(); + } + } +} diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Archiv.js b/public/js/components/Stv/Studentenverwaltung/Details/Archiv.js index f69e89838..1856815a1 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Archiv.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Archiv.js @@ -221,7 +221,7 @@ export default { actionDownload(akte_id) { window.open( FHC_JS_DATA_STORAGE_OBJECT.app_root - + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/api/frontend/v1/stv/archiv/download?akte_id=' + encodeURIComponent(akte_id), + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/api/frontend/v1/stv/akte/download?akte_id=' + encodeURIComponent(akte_id), '_blank' ); },