From b57a3ec90f6a50f5746eafbb527055fa09623735 Mon Sep 17 00:00:00 2001 From: Cris Date: Thu, 14 Jan 2021 14:13:17 +0100 Subject: [PATCH] Added logic to download and open a document Signed-off-by: cris-technikum --- .../lehre/anrechnung/RequestAnrechnung.php | 14 +++++++ application/libraries/DmsLib.php | 41 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/application/controllers/lehre/anrechnung/RequestAnrechnung.php b/application/controllers/lehre/anrechnung/RequestAnrechnung.php index d831f4f2d..68e06ca80 100644 --- a/application/controllers/lehre/anrechnung/RequestAnrechnung.php +++ b/application/controllers/lehre/anrechnung/RequestAnrechnung.php @@ -191,6 +191,20 @@ class requestAnrechnung extends Auth_Controller } } + /** + * Download and open uploaded document (Nachweisdokument). + */ + public function download() + { + $dms_id = $this->input->get('dms_id'); + + if (!is_numeric($dms_id)) + { + show_error('Wrong parameter'); + } + + $this->dmslib->download($dms_id); + } /** * Retrieve the UID of the logged user and checks if it is valid diff --git a/application/libraries/DmsLib.php b/application/libraries/DmsLib.php index bad9e0acf..64d58f987 100644 --- a/application/libraries/DmsLib.php +++ b/application/libraries/DmsLib.php @@ -132,6 +132,47 @@ class DmsLib // return result of uploaded data return success($upload_data); // data about the uploaded file } + + /** + * Download a document + * @param $dms_id + */ + public function download($dms_id) + { + if (!is_numeric($dms_id)) + { + show_error('Wrong parameter'); + } + + $this->ci->DmsVersionModel->addSelect('filename'); + $result = $this->ci->DmsVersionModel->loadWhere(array('dms_id' => $dms_id)); + + if (isError($result)) + { + show_error(getError($result)); + } + + $filename = $result->retval[0]->filename; + $file = DMS_PATH. $filename; + + if (file_exists($file)) + { + $finfo = new finfo(FILEINFO_MIME); + + header('Content-Description: File Transfer'); + header('Content-Type: '.$finfo->file($file)); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Length: ' . filesize($file)); + readfile($file); + exit; + } + else + { + show_error('File does not exist'); + } + } /** * Saves a Document