Compare commits

..

1 Commits

Author SHA1 Message Date
Paolo aba680cd52 Long Run Tasks first draft 2026-04-28 16:53:25 +02:00
35 changed files with 1878 additions and 915 deletions
+20
View File
@@ -0,0 +1,20 @@
<?php
/**
* Configs for the Long Run Tasks
*/
if (! defined('BASEPATH')) exit('No direct script access allowed');
// Maximum LRTs for a single user in parallel
$config['lrt_max_number_single_user'] = 10;
// Maximum LRTs for the whole system in parallel
$config['lrt_max_number_system'] = 100;
// Maximum running time in hours for a single LRT before killing it
$config['lrt_max_run_timeout'] = 48;
// List of existing LRT types
$config['lrt_types'] = array('LRTDocumentConvertion');
+5 -10
View File
@@ -20,12 +20,8 @@ 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'
@@ -116,12 +112,10 @@ 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->aktelib->getByPersonId(
$person_id,
true
);
$result = $this->AkteModel->getArchiv($person_id, null, true);
if (isError($result))
return $this->load->view('errors/html/error_db.php', [
'heading' => 'Database Error',
@@ -153,13 +147,14 @@ class Documents extends Auth_Controller
if (!is_numeric($akte_id))
return show_404();
$result = $this->aktelib->getByAkteId($akte_id);
$this->load->model('crm/Akte_model', 'AkteModel');
$result = $this->AkteModel->load($akte_id);
if (isError($result))
return show_error(getError($result));
$akte = getData($result);
if (!$akte)
return show_404();
$akte = reset($akte);
$akte = current($akte);
$admin_access = false;
if ($uid !== null && $this->permissionlib->isBerechtigt('admin')) {
+1 -2
View File
@@ -64,7 +64,7 @@ class ProfilUpdate extends Auth_Controller
{
// Get file to be downloaded from DMS
$newFilename = $this->uid . "/document_" . $dms_id;
$download = $this->dmslib->getOutputFileInfo($dms_id);
$download = $this->dmslib->download($dms_id);
if (isError($download))
return $download;
@@ -84,4 +84,3 @@ class ProfilUpdate extends Auth_Controller
}
}
}
+82 -48
View File
@@ -29,15 +29,11 @@ class Pub extends Auth_Controller
*/
public function bild($source, $id)
{
$person_id_user = getAuthPersonId();
$serverzugriff = false;
// Default Bild (Dummy Profilbild)
$outputFileName = FHCPATH . 'skin/images/profilbild_dummy.jpg';
$outputFileContent = '';
$mimetype = 'application/jpeg';
$this->load->model('person/Person_model', 'PersonModel');
$person_id_user = '';
$serverzugriff = false;
// Wenn das Bild direkt aufgerufen wird, ist eine Authentifizierung erforderlich
// Wenn es vom Server selbst aufgerufen wird, ist keine Auth. notwendig
// (z.B. fuer die Erstellung von PDFs)
@@ -49,27 +45,31 @@ class Pub extends Auth_Controller
'zugangscode' => $_SESSION['incoming/user']
]);
if (hasData($result))
$person_id_user = getData($result)[0]->person_id;
$person_id_user = current(getData($result))->person_id;
} elseif (isset($_SESSION['prestudent/user'])) { // Von Prestudententool
$result = $this->PersonModel->loadWhere([
'zugangscode' => $_SESSION['prestudent/user']
]);
if (hasData($result))
$person_id_user = getData($result)[0]->person_id;
$person_id_user = current(getData($result))->person_id;
} elseif (isset($_SESSION['bewerbung/personId'])) { // Von Bewerbungstool
$person_id_user = $_SESSION['bewerbung/personId'];
} else {
$person_id_user = getAuthPersonId();
}
} else {
$serverzugriff = true;
}
// If the picture is from the person table
if ($source == 'person' && is_numeric($id)) {
// Default Bild (Dummy Profilbild)
$cTmpHEX = base64_encode(file_get_contents(FHCPATH . 'skin/images/profilbild_dummy.jpg'));
if ($source == 'person' && $id) {
$foto_gesperrt = false;
// Person laden und Fotosperre überprüfen
$result = $this->PersonModel->load($id);
if (hasData($result)) {
$person = getData($result)[0];
$person = current(getData($result));
if ($person->foto_sperre) {
// Wenn der User selbst darauf zugreift darf er das Bild sehen
$foto_gesperrt = ($person_id_user != $id);
@@ -77,57 +77,91 @@ class Pub extends Auth_Controller
$foto_gesperrt = true;
}
if (!isEmptyString($person->foto) && !$foto_gesperrt) {
$outputFileContent = base64_decode($person->foto);
if ($person->foto && !$foto_gesperrt) {
$cTmpHEX = base64_decode($person->foto);
}
}
}
// If the picture is from the akte/dms
if($source == 'akte' && is_numeric($id))
if($source == 'akte' && $id != '')
{
$mimetype = '';
$this->load->library('AkteLib');
$this->load->model('crm/Akte_model', 'AkteModel');
$akteResult = $this->aktelib->getByAkteId($id, 'Lichtbil');
$this->AkteModel->addJoin('public.tbl_person', 'person_id');
$result = $this->AkteModel->loadWhere([
'person_id' => $id,
'dokument_kurzbz' => 'Lichtbil'
]);
if (hasData($akteResult)) {
if (hasData($result)) {
$foto_gesperrt = false;
$akte = getData($akteResult)[0];
$personResult = $this->PersonModel->load($akte->person_id);
if (hasData($personResult)) {
$person = getData($personResult)[0];
if ($person->foto_sperre) {
$foto_gesperrt = ($person_id_user != $id);
} elseif (!$person_id_user && !$serverzugriff) {
$foto_gesperrt = true;
}
$akte = current(getData($result));
if ($akte->foto_sperre) {
// Wenn der User selbst darauf zugreift darf er das Bild sehen
$foto_gesperrt = ($person_id_user != $id);
} elseif (!$person_id_user && !$serverzugriff) {
$foto_gesperrt = true;
}
// Wenn das Foto nicht im Inhalt steht wird aus aus dem DMS geladen
if (!isEmptyString($akte->inhalt)) {
$outputFileContent = base64_decode($akte->inhalt);
$mimetype = $akte->mimetype;
if (!$akte->inhalt && $akte->dms_id) {
$this->load->model('content/Dms_model', 'DmsModel');
$this->load->model('content/DmsVersion_model', 'DmsVersionModel');
$this->DmsModel->addJoin('campus.tbl_dms_version', 'dms_id');
$this->DmsModel->addOrder('version', 'DESC');
$this->DmsModel->addLimit(1);
$result = $this->DmsModel->load($akte->dms_id);
if (!hasData($result))
die('Kein Dokument vorhanden');
$dms = current(getData($result));
$filename = DMS_PATH . $dms->filename;
$this->DmsVersionModel->update([
'dms_id' => $dms->dms_id,
'version' => $dms->version
], [
'letzterzugriff' => date('c')
]);
if (file_exists($filename)) {
$handle = fopen($filename, "r");
if ($handle) {
while (!feof($handle)) {
$akte->inhalt .= fread($handle, 8192);
}
fclose($handle);
} else {
echo 'Fehler: Datei konnte nicht geoeffnet werden';
}
} else {
echo 'Die Datei existiert nicht';
}
}
if ($akte->inhalt && !$foto_gesperrt) {
$cTmpHEX = $akte->inhalt;
}
}
}
// If file content is provided
if (!isEmptyString($outputFileContent))
{
// If a mimetype is still not found
if (isEmptyString($mimetype))
{
$fo = finfo_open();
$mimetype = finfo_buffer($fo, $outputFileContent, FILEINFO_MIME_TYPE);
}
$this->outputImageByContent($mimetype, $outputFileContent);
}
else // otherwise use the file
{
$this->outputImageByFile($mimetype, $outputFileName);
// die bilder werden, sofern es funktioniert, in jpg umgewandelt da es sonst zu fehlern beim erstellen
// von pdfs kommen kann.
$im = @imagecreatefromstring(base64_decode($cTmpHEX));
if ($im) {
@ob_clean();
header("Content-type: image/jpeg");
exit(imagejpeg($im));
} else {
// bei manchen Bildern funktioniert die konvertierung nicht
// diese werden dann einfach so angezeigt.
@ob_clean();
header("Content-type: image/gif");
exit($cTmpHEX);
}
}
}
+6 -18
View File
@@ -143,7 +143,7 @@ class Documents extends Auth_Controller
$result = $this->VorlagestudiengangModel->getCurrent($xsl, $xsl_oe_kurzbz, $version);
if (isError($result))
show_error(getError($result));
return show_error(getError($result));
if (!hasData($result))
return show_404();
@@ -226,13 +226,13 @@ class Documents extends Auth_Controller
$result = $this->VorlageModel->load($xsl);
if (isError($result))
show_error(getError($result));
return show_error(getError($result));
if (!hasData($result))
show_404();
$vorlage = current(getData($result));
if ($sign_user && !$vorlage->signierbar)
show_error($this->p->t("stv", "grades_error_sign"));
return show_error($this->p->t("stv", "grades_error_sign"));
// Filename
@@ -284,23 +284,11 @@ class Documents extends Auth_Controller
// XML Data
$result = $this->documentexportlib->getDataURL($xml, $params);
if (isError($result))
show_error(getError($result));
return show_error(getError($result));
$data = getData($result);
// Get the content
$contentResult = $this->documentexportlib->getContent($filename, $vorlage, $data, $xsl_oe_kurzbz, $version, $outputformat, $sign_user);
// If an error occurred
if (isError($contentResult)) show_error(getError($contentResult));
$fileObj = new stdClass();
$fileObj->file_content = getData($contentResult);
$fileObj->name = $filename;
$fileObj->mimetype = isEmptyString($vorlage->mimetype) ? 'application/pdf' : $vorlage->mimetype;
$fileObj->disposition = 'attachment';
// Download
$this->outputFile($fileObj);
// Output
$this->documentexportlib->showContent($filename, $vorlage, $data, $xsl_oe_kurzbz, $version, $outputformat, $sign_user);
}
}
@@ -51,8 +51,6 @@ class Documents extends FHCAPI_Controller
$this->loadPhrases([
'stv'
]);
$this->load->library('DocumentExportLib');
}
/**
@@ -102,11 +100,23 @@ class Documents extends FHCAPI_Controller
{
$akteExportData = $this->_getAkteExportData($xml, $xsl, $sign_user);
$akteData = $akteExportData['akteData'];
$exportData = $akteExportData['exportData'];
$akteData = $akteData['akteData'];
$exportData = $akteData['exportData'];
/**
* [
'vorlage' => $vorlage,
'xml_data' => $data,
'oe_kurzbz' => $xsl_oe_kurzbz,
'version' => $version,
'outputformat' => $outputformat,
'sign_user' => $sign_user
]
*/
// Output
$contentResult = $this->documentexportlib->getContent(
$result = $this->documentexportlib->showContent(
$akteData['akteData']['inhalt'],
$exportData['vorlage'],
$exportData['xml_data'],
$exportData['oe_kurzbz'],
@@ -115,9 +125,7 @@ class Documents extends FHCAPI_Controller
$exportData['sign_user']
);
$content = $this->getDataOrTerminateWithError($contentResult);
$this->terminateWithFileOutput($akteData['mimetype'], $content, $akteData['titel'] . '.pdf');
$this->terminateWithSuccess(true);
}
/**
@@ -153,10 +161,12 @@ class Documents extends FHCAPI_Controller
$this->load->library('form_validation');
if (!$xml) {
$xml = $this->input->post_get('xml');
$this->addMeta('xml', $xml);
$this->form_validation->set_rules('xml', 'xml', 'required');
}
if (!$xsl) {
$xsl = $this->input->post_get('xsl');
$this->addMeta('xsl', $xsl);
$this->form_validation->set_rules('xsl', 'xsl', 'required');
}
@@ -455,13 +465,18 @@ class Documents extends FHCAPI_Controller
if ($sign_user && !$vorlage->signierbar)
$this->terminateWithError($this->p->t("stv", "grades_error_sign"));
$this->load->library('DocumentExportLib');
// XML Data
$result = $this->documentexportlib->getDataURL($xml, $params);
$data = $this->getDataOrTerminateWithError($result);
$this->documentexportlib->addArchiveToData($data);
$contentResult = $this->documentexportlib->getContent($vorlage, $data, $xsl_oe_kurzbz, $version, $outputformat, $sign_user);
$content = $this->getDataOrTerminateWithError($contentResult);
// Output
$result = $this->documentexportlib->getContent($vorlage, $data, $xsl_oe_kurzbz, $version, $outputformat, $sign_user);
$content = $this->getDataOrTerminateWithError($result);
$akteData['titel'] .= '.pdf';
$akteData['inhalt'] = base64_encode($content);
@@ -479,4 +494,3 @@ class Documents extends FHCAPI_Controller
];
}
}
@@ -136,7 +136,7 @@ class ProfilUpdate extends FHCAPI_Controller
$this->uid == $profil_update->uid
) {
// Get file to be downloaded from DMS
$download = $this->dmslib->getOutputFileInfo($dms_id);
$download = $this->dmslib->download($dms_id);
$download = $this->getDataOrTerminateWithError($download);
// Download file
$this->outputFile($download);
@@ -456,28 +456,24 @@ class ProfilUpdate extends FHCAPI_Controller
$_FILES['files']['error'] = $files['error'][$i];
$_FILES['files']['size'] = $files['size'][$i];
// File upload
$uploadDataResult = $this->uploadFile('files', array('jpg', 'png', 'pdf'));
if (isError($uploadDataResult)) $this->addError(getError($uploadDataResult));
if (!hasData($uploadDataResult)) $this->addError('Upload failed');
$dms = [
"kategorie_kurzbz" => "profil_aenderung",
"version" => 0,
"name" => $_FILES['files']['name'],
"mimetype" => $_FILES['files']['type'],
"beschreibung" => $this->uid . " Profil Änderung",
"insertvon" => $this->uid,
"insertamum" => "NOW()",
];
if (hasData($uploadDataResult))
{
// Add file to the DMS (DB + file system)
$dms_res = $this->dmslib->add(
getData($uploadDataResult)['file_name'],
getData($uploadDataResult)['file_type'],
fopen(getData($uploadDataResult)['full_path'], 'r'),
'profil_aenderung', // kategorie_kurzbz
null, // dokument_kurzbz
null, // beschreibung
false, // cis_suche
null, // schlagworte
getAuthUID() // insertvon
);
$dms_res = $this->getDataOrTerminateWithError($dms_res);
array_push($res, $dms_res);
$tmp_res = $this->dmslib->upload($dms, 'files', array("jpg", "png", "pdf"));
if(isError($tmp_res)){
$this->addError(getError($tmp_res));
}
$tmp_res = $this->getDataOrTerminateWithError($tmp_res);
array_push($res, $tmp_res);
}
$this->terminateWithSuccess($res);
@@ -158,27 +158,19 @@ class Unterbrechung extends FHCAPI_Controller
if (isset($_FILES['attachment']) && (!isset($_FILES['attachment']['error']) || $_FILES['attachment']['error'] != UPLOAD_ERR_NO_FILE)) {
$this->load->library('DmsLib');
$dms = $this->config->item('unterbrechung_dms');
if (!count(array_filter($dms, function ($v) {
return $v !== null;
})))
$dms = ['kategorie_kurzbz' => 'Akte'];
$dms['version'] = 0;
$uploadDataResult = $this->uploadFile('attachment', $this->config->item('unterbrechung_dms_filetypes') ?: array('*'));
$allowed_filetypes = $this->config->item('unterbrechung_dms_filetypes') ?: ['*'];
$result = $this->dmslib->upload($dms, 'attachment', $allowed_filetypes);
$data = $this->getDataOrTerminateWithError($uploadDataResult);
// Add file to the DMS (DB + file system)
$dms_res = $this->dmslib->add(
getData($uploadDataResult)['file_name'],
getData($uploadDataResult)['file_type'],
fopen(getData($uploadDataResult)['full_path'], 'r'),
'studierendenantrag',
null, // dokument_kurzbz
null, // beschreibung
false, // cis_suche
null, // schlagworte
getAuthUID() // insertvon
);
$dms_data = $this->getDataOrTerminateWithError($dms_res);
$dms_id = $dms_data->dms_id;
$data = $this->getDataOrTerminateWithError($result);
$dms_id = $data['dms_id'];
}
$result = $this->antraglib->createUnterbrechung($prestudent_id, $studiensemester, getAuthUID(), $grund, $datum_wiedereinstieg, $dms_id);
@@ -32,8 +32,8 @@ class Akte extends Auth_Controller
'download' => ['admin:w', 'assistenz:w'],
]);
// Load libraries
$this->load->library('AkteLib');
// Load models
$this->load->model('crm/Akte_model', 'AkteModel');
}
//------------------------------------------------------------------------------------------------------------------
@@ -49,22 +49,22 @@ class Akte extends Auth_Controller
if (!is_numeric($akte_id)) $this->terminateWithError('akte Id missing');
$akteResult = $this->aktelib->getByAkteId($akte_id);
$result = $this->AkteModel->load($akte_id);
if (!hasData($akteResult)) $this->terminateWithError('Akte not found');
if (!hasData($result)) $this->terminateWithError('Akte not found');
$data = getData($akteResult)[0];
$data = getData($result)[0];
if (!isEmptyString($data->inhalt))
if (isset($data->inhalt) && $data->inhalt != '')
{
$fileObj = new stdClass();
$fileObj->file_content = base64_decode($data->inhalt);
$fileObj->name = $data->filename;
$fileObj->mimetype = $data->mimetype;
$fileObj->disposition = 'attachment';
$this->outputFile($fileObj);
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();
}
}
}
@@ -46,9 +46,6 @@ 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'
@@ -60,7 +57,7 @@ class Archiv extends FHCAPI_Controller
/**
* Get archive documents for a person
* @return void
*/
public function getArchiv()
@@ -77,11 +74,7 @@ class Archiv extends FHCAPI_Controller
$this->terminateWithValidationErrors($this->form_validation->error_array());
}
$result = $this->aktelib->getByPersonId(
$person_id,
null, // dokument_kurzbz
true // archiv
);
$result = $this->AkteModel->getArchiv($person_id);
$data = $this->getDataOrTerminateWithError($result);
@@ -101,6 +94,51 @@ class Archiv extends FHCAPI_Controller
$this->terminateWithSuccess($data);
}
/**
*
* @param
* @return object success or error
*/
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];
$fileObj = new stdClass();
if (isset($data->inhalt) && $data->inhalt != '')
{
// Define handle to output stream
$tmpFilePointer = fopen("php://output", 'w');
$meta_data = stream_get_meta_data($tmpFilePointer);
$filename = $meta_data["uri"];
fwrite($tmpFilePointer, $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-Length: ' . filesize($fileObj->file));
//header("Content-type: $data->mimetype");
header('Content-Disposition: attachment; filename="'.$data->titel.'"');
readfile($filename);
die();
}
else
{
$this->load->library('AkteLib');
$result = $this->aktelib->get($akte_id);
}
}
/**
* Updating an Akte
* @return void
@@ -155,7 +193,7 @@ class Archiv extends FHCAPI_Controller
$this->addMeta('content', base64_encode($content));
}
foreach ($allowed as $field)
if ($this->input->post($field) !== null)
$data[$field] = $this->input->post($field);
@@ -210,7 +248,7 @@ class Archiv extends FHCAPI_Controller
'akte_id' => $akte_id
]));
}
$result = $this->AkteModel->delete($akte_id);
if (isError($result)) $this->terminateWithError(getError($result));
@@ -27,8 +27,7 @@ class Dokumente extends FHCAPI_Controller
// Load Libraries
$this->load->library('VariableLib', ['uid' => getAuthUID()]);
$this->load->library('form_validation');
$this->load->library('AkteLib');
$this->load->library('DmsLib');
$this->load->library('DmsLib', array('who' => getAuthUID()));
// Load language phrases
$this->loadPhrases([
@@ -191,6 +190,8 @@ class Dokumente extends FHCAPI_Controller
$this->terminateWithValidationErrors($this->form_validation->error_array());
}
$uid = getAuthUID();
$result = $this->AkteModel->update(
[
'akte_id' => $this->input->post('akte_id'),
@@ -201,7 +202,7 @@ class Dokumente extends FHCAPI_Controller
'titel_intern' => $this->input->post('titel_intern'),
'nachgereicht_am' => $this->input->post('nachgereicht_am'),
'updateamum' => date('c'),
'updatevon' => getAuthUID(),
'updatevon' => $uid,
]
);
@@ -218,6 +219,8 @@ class Dokumente extends FHCAPI_Controller
if(!$dokument_kurzbz)
$this->terminateWithError($this->p->t('ui', 'errorMissingValue', ['value' => 'Dokument_kurzbz']), self::ERROR_TYPE_GENERAL);
$uid = getAuthUid();
//check if more than 1 dokumentkurzbz
//if()
@@ -225,10 +228,10 @@ class Dokumente extends FHCAPI_Controller
[
'prestudent_id' => $prestudent_id,
'dokument_kurzbz' => $dokument_kurzbz,
'mitarbeiter_uid' => getAuthUID(),
'mitarbeiter_uid' => $uid,
'datum' => date('c'),
'insertamum' => date('c'),
'insertvon' => getAuthUID(),
'insertvon' => $uid,
]
);
@@ -251,6 +254,7 @@ class Dokumente extends FHCAPI_Controller
$nachgereicht = current($dataAkte)->nachgereicht;
$inhalt = current($dataAkte)->inhalt;
$inhaltVorhanden = $inhalt != '';
$uid = getAuthUid();
$this->db->trans_start();
@@ -264,15 +268,16 @@ class Dokumente extends FHCAPI_Controller
$logdata_dms = "Logdata: " . var_export($logdata_dms, true);
//delete from dmsLib
$this->load->library('DmsLib');
$person_id = current($dataAkte)->person_id;
$result = $this->aktelib->removeByPersonIdAndDmsId($person_id, $dms_id);
$result = $this->dmslib->delete($person_id, $dms_id);
$this->getDataOrTerminateWithError($result);
//LOGGING Dms ID
$this->load->model('system/Log_model', 'LogModel');
$result = $this->LogModel->insert([
'executetime' => date('c'),
'mitarbeiter_uid' => getAuthUID(),
'mitarbeiter_uid' => $uid,
'beschreibung' => "Löschen der DMS_ID ". $dms_id,
'sql' => $logdata_dms
]);
@@ -289,7 +294,7 @@ class Dokumente extends FHCAPI_Controller
//Logging Deletion Akte
$result = $this->LogModel->insert([
'executetime' => date('c'),
'mitarbeiter_uid' => getAuthUID(),
'mitarbeiter_uid' => $uid,
'beschreibung' => "Löschen der Akte ". $akte_id,
'sql' => "DELETE FROM public.tbl_akte WHERE akte_id=" .$akte_id. " LogData: ". $logdata_akte
]);
@@ -308,7 +313,7 @@ class Dokumente extends FHCAPI_Controller
$result = $this->LogModel->insert([
'executetime' => date('c'),
'mitarbeiter_uid' => getAuthUID(),
'mitarbeiter_uid' => $uid,
'beschreibung' => "Löschen der Akte ". $akte_id,
'sql' => "DELETE FROM public.tbl_akte WHERE akte_id=" .$akte_id. " LogData: ". $logdata_akte
]);
@@ -323,6 +328,7 @@ class Dokumente extends FHCAPI_Controller
public function uploadDokument()
{
$this->load->library('DmsLib');
$prestudent_id = $this->input->post('prestudent_id');
$anmerkung_intern = $this->input->post('anmerkung_intern');
$titel_intern = $this->input->post('titel_intern');
@@ -345,44 +351,34 @@ class Dokumente extends FHCAPI_Controller
}
$this->db->trans_start();
$uid = getAuthUID();
$uploadDataResult = $this->uploadFile('anhang', array('jpg', 'png', 'pdf'));
if (isError($uploadDataResult))
$dms = array(
'kategorie_kurzbz' => 'Akte',
'version' => 0,
'name' => $_FILES['anhang']['name'],
'mimetype' => $_FILES['anhang']['type'],
'insertamum' => date('c'),
'insertvon' => $uid
);
$result = $this->dmslib->upload($dms, 'anhang', array("jpg", "png", "pdf"));
if (isError($result))
{
return $this->terminateWithError(getError($uploadDataResult), self::ERROR_TYPE_GENERAL);
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
}
// If data exists
if (hasData($uploadDataResult))
{
// Add file to the DMS (DB + file system)
$dms_res = $this->dmslib->add(
getData($uploadDataResult)['file_name'],
getData($uploadDataResult)['file_type'],
fopen(getData($uploadDataResult)['full_path'], 'r'),
'Akte', // kategorie_kurzbz
null, // dokument_kurzbz
null, // beschreibung
false, // cis_suche
null, // schlagworte
getAuthUID() // insertvon
);
}
// Error occurred or data not found
if (isError($dms_res) || !hasData($dms_res)) $this->terminateWithError(getError($dms_res), self::ERROR_TYPE_GENERAL);
$dms_id = getData($dms_res)->dms_id;
$dms_id = $result->retval['dms_id'];
$person_id = $this->_getPersonId($prestudent_id);
$dokumentResult = $this->DokumentModel->load($dokument_kurzbz);
$data = $this->getDataOrTerminateWithError($dokumentResult);
$result = $this->DokumentModel->load($dokument_kurzbz);
$data = $this->getDataOrTerminateWithError($result);
$bezeichnung = current($data)->bezeichnung;
// Save entry in akte
if ($dms_id)
//save entry in akte
if($dms_id)
{
$result = $this->AkteModel->insert([
'person_id' => $person_id,
@@ -391,7 +387,7 @@ class Dokumente extends FHCAPI_Controller
'mimetype' => $_FILES['anhang']['type'],
'insertamum' => date('c'),
'erstelltam' => date('c'),
'insertvon' => getAuthUID(),
'insertvon' => $uid,
'anmerkung_intern' => $anmerkung_intern,
'titel_intern' => $titel_intern,
'bezeichnung' => $bezeichnung,
@@ -438,26 +434,28 @@ class Dokumente extends FHCAPI_Controller
$filecontentbase64 = $data->inhalt;
$filename = $data->titel;
if (intval($data->dms_id) > 0)
if(intval($data->dms_id) > 0)
{
$file = $this->dmslib->getOutputFileInfo($data->dms_id, $filename);
$dmsdokres = $this->dmslib->read($data->dms_id);
if (!hasData($dmsdokres)) $this->terminateWithError('DMS File not found');
$dmsdok = getData($dmsdokres)[0];
$this->terminateWithFileOutput(getData($file)->mimetype, file_get_contents(getData($file)->file), $filename);
$mimetype = $dmsdok->mimetype;
$filecontentbase64 = $dmsdok->file_content;
$filename = $dmsdok->name;
}
else
{
$filecontent = '';
if (!empty($filecontentbase64)) {
$filecontent = base64_decode($filecontentbase64, true);
$filecontent = '';
if ($filecontent === false) {
$this->terminateWithError('Base64-Dekodierung failed.');
}
if (!empty($filecontentbase64)) {
$filecontent = base64_decode($filecontentbase64, true);
if ($filecontent === false) {
$this->terminateWithError('Base64-Dekodierung failed.');
}
$this->terminateWithFileOutput($mimetype, $filecontent, $filename);
}
$this->terminateWithFileOutput($mimetype, $filecontent, $filename);
}
private function _getMissingDocuments($studiengang_kz, $prestudent_id)
@@ -773,7 +771,10 @@ class Dokumente extends FHCAPI_Controller
);
$data = $this->getDataOrTerminateWithError($result);
return hasData($data) ? getData($data)[0]->prestudent_id : null;
$student = current($data);
return $student->prestudent_id;
}
/**
@@ -33,6 +33,11 @@ class Notiz extends Notiz_Controller
]);
}
/* public function getUid()
{
$this->terminateWithSuccess(getAuthUID());
}*/
public function getNotizen($id, $type)
{
@@ -54,6 +59,317 @@ class Notiz extends Notiz_Controller
}
/* public function loadNotiz()
{
$_POST = json_decode(utf8_encode($this->input->raw_input_stream), true);
$notiz_id = $this->input->post('notiz_id');
//$this->load->model('person/Notiz_model', 'NotizModel');
$this->NotizModel->addJoin('public.tbl_notiz_dokument', 'notiz_id', 'LEFT');
$this->NotizModel->addSelect('*');
$this->NotizModel->addSelect("TO_CHAR(CASE WHEN public.tbl_notiz.updateamum >= public.tbl_notiz.insertamum
THEN public.tbl_notiz.updateamum ELSE public.tbl_notiz.insertamum END::timestamp, 'DD.MM.YYYY HH24:MI:SS') AS lastUpdate");
$this->NotizModel->addLimit(1);
$result = $this->NotizModel->loadWhere(
array('notiz_id' => $notiz_id)
);
if (isError($result))
{
$this->terminateWithError($result, self::ERROR_TYPE_GENERAL);
}
elseif (!hasData($result))
{
$this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=>'Notiz_id']), self::ERROR_TYPE_GENERAL);
}
else
{
$this->terminateWithSuccess(current(getData($result)));
}
}
public function updateNotiz()
{
$this->load->library('form_validation');
$this->load->library('DmsLib');
if (isset($_POST['data']))
{
$data = json_decode($_POST['data']);
unset($_POST['data']);
foreach ($data as $k => $v) {
$_POST[$k] = $v;
}
}
$notiz_id = $this->input->post('notiz_id');
if(!$notiz_id)
{
$this->terminateWithError($this->p->t('ui','error_missingId',['id'=>'Notiz_id']), self::ERROR_TYPE_GENERAL);
}
//Form Validation
$this->form_validation->set_rules('titel', 'Titel', 'required', [
'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Titel'])
]);
$this->form_validation->set_rules('text', 'Text', 'required', [
'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Text'])
]);
if ($this->form_validation->run() == false)
{
$this->terminateWithValidationErrors($this->form_validation->error_array());
}
//update Notiz
$uid = getAuthUID();
$titel = $this->input->post('titel');
$text = $this->input->post('text');
$verfasser_uid = $this->input->post('verfasser');
$bearbeiter_uid = isset($_POST['bearbeiter']) ? $_POST['bearbeiter'] : $uid;
$erledigt = $this->input->post('erledigt');
$start = $this->input->post('start');
$ende = $this->input->post('ende');
$result = $this->NotizModel->update(
[
'notiz_id' => $notiz_id
],
[
'titel' => $titel,
'updatevon' => $uid,
'updateamum' => date('c'),
'text' => $text,
'verfasser_uid' => $verfasser_uid,
'bearbeiter_uid' => $bearbeiter_uid,
'start' => $start,
'ende' => $ende,
'erledigt' => $erledigt
]
);
if (isError($result))
{
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
}
//update(1) laden aller bereits mit dieser notiz_id verknüpften DMS-Einträge
$this->load->model('person/Notizdokument_model', 'NotizdokumentModel');
$this->NotizdokumentModel->addJoin('campus.tbl_dms_version', 'dms_id');
$dms_uploaded = null;
$result = $this->NotizdokumentModel->loadWhere(array('notiz_id' => $notiz_id));
if (isError($result))
{
$this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
}
elseif (!hasData($result))
{
$dms_id_arr = null;
}
else
{
$result = getData($result);
foreach($result as $doc) {
$dms_id_arr[] = array(
'name' => $doc->name,
'dms_id' => $doc->dms_id
);
}
}
foreach ($_FILES as $k => $file)
{
//update(2) alle neuen files (alle außer type application/x.fhc-dms+json) anhängen
if($file["type"] == 'application/x.fhc-dms+json')
{
$dms_uploaded[] = array(
'name' => $file["name"]
);
}
else
{
$dms = array(
'kategorie_kurzbz' => 'notiz',
'version' => 0,
'name' => $file["name"],
'mimetype' => $file["type"],
'insertamum' => date('c'),
'insertvon' => $uid
);
//Todo(manu) check if filetypes weiter eingeschränkt werden sollen
//Todo(manu)check name files: nicht gleiches file 2mal hochladen
$result = $this->dmslib->upload($dms, $k, array('*'));
if (isError($result))
{
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
}
$dms_id = $result->retval['dms_id'];
$result = $this->NotizdokumentModel->insert(array('notiz_id' => $notiz_id, 'dms_id' => $dms_id));
if (isError($result))
{
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
}
}
}
//update(3) check if Dateien gelöscht wurden
if(count($dms_uploaded) != count($dms_id_arr))
{
if (count($dms_uploaded) == 0)
{
$filesDeleted = $dms_id_arr;
}
else
{
$upload_new_names = array_column($dms_uploaded, "name");
$filesDeleted = array_filter($dms_id_arr, function ($file) use ($upload_new_names) {
return !in_array($file["name"], $upload_new_names);
});
}
foreach ($filesDeleted as $file)
{
$result = $this->dmslib->removeAll($file['dms_id']);
if (isError($result))
{
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
}
else
$this->outputJson($result);
}
}
return $this->terminateWithSuccess($result);
}*/
/* public function deleteNotiz()
{
$_POST = json_decode(utf8_encode($this->input->raw_input_stream), true);
$notiz_id = $this->input->post('notiz_id');
$type = $this->input->post('type_id');
$id = $this->input->post('id');
//dms_id auslesen aus notizdokument wenn vorhanden
$dms_id_arr = [];
$this->load->model('person/Notizdokument_model', 'NotizdokumentModel');
$result = $this->NotizdokumentModel->loadWhere(array('notiz_id' => $notiz_id));
if (isError($result))
{
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
}
if(hasData($result))
{
$result = getData($result);
foreach ($result as $doc) {
$dms_id_arr[] = $doc->dms_id;
}
}
if($dms_id_arr)
{
$this->load->library('DmsLib');
foreach($dms_id_arr as $dms_id)
{
$result = $this->dmslib->removeAll($dms_id);
if (isError($result))
{
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
}
$this->outputJson($result);
}
}
//delete Notizzuordnung
if($type == "software_id")
{
// Loads extension Model
$this->load->model('extensions/FHC-Core-Softwarebereitstellung/Softwarenotizzuordnung_model', 'ExtensionnotizzuordnungModel');
$result = $this->ExtensionnotizzuordnungModel->delete([
'notiz_id' => $notiz_id,
'id' => strval($id)
],
[
'type_id' => $type
]);
}
else
{
//notizzuordnungsid!
$result = $this->NotizzuordnungModel->delete(['notiz_id' => $notiz_id, $type => $id]);
}
$this->load->model('person/Notiz_model', 'NotizModel');
//$this->NotizModel->addJoin('public.tbl_notizzuordnung', 'notiz_id');
//TODO (erweitern um Type_id) für Extensions, damit auch Notizzuordnung gelöscht werden kann
//Löschen von Notiz
$result = $this->NotizModel->delete(
array('notiz_id' => $notiz_id)
);
if (isError($result))
{
return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL);
}
if(!hasData($result))
{
return $this->terminateWithError($this->p->t('ui','error_missingId', ['id'=> 'Notiz_id']), self::ERROR_TYPE_GENERAL);
}
return $this->terminateWithSuccess(current(getData($result)));
}*/
/* public function loadDokumente()
{
$_POST = json_decode(utf8_encode($this->input->raw_input_stream), true);
$notiz_id = $this->input->post('notiz_id');
$this->NotizModel->addSelect('campus.tbl_dms_version.*');
$this->NotizModel->addJoin('public.tbl_notiz_dokument', 'ON (public.tbl_notiz_dokument.notiz_id = public.tbl_notiz.notiz_id)');
$this->NotizModel->addJoin('campus.tbl_dms_version', 'ON (public.tbl_notiz_dokument.dms_id = campus.tbl_dms_version.dms_id)');
$result = $this->NotizModel->loadWhere(
array('public.tbl_notiz.notiz_id' => $notiz_id)
);
if (isError($result)) {
return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL);
}
if(!hasData($result))
{
return $this->terminateWithError($this->p->t('ui','error_missingId', ['id'=> 'Notiz_id']), self::ERROR_TYPE_GENERAL);
}
return $this->terminateWithSuccess(getData($result));
}*/
/* public function getMitarbeiter($searchString)
{
$this->load->model('ressource/Mitarbeiter_model', 'MitarbeiterModel');
$result = $this->MitarbeiterModel->searchMitarbeiter($searchString);
if (isError($result)) {
$this->terminateWithError($result, self::ERROR_TYPE_GENERAL);
}
return $this->terminateWithSuccess($result);
}*/
public function isBerechtigt($id, $typeId)
{
if(!$this->permissionlib->isBerechtigt('admin', 'suid') && !$this->permissionlib->isBerechtigt('assistenz', 'suid'))
@@ -63,6 +379,7 @@ class Notiz extends Notiz_Controller
return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL);
}
return success("berechtigt in überschreibender Funktion");
/* return $this->terminateWithError('keine Berechtigung bro', self::ERROR_TYPE_GENERAL);*/
}
}
}
@@ -73,7 +73,7 @@ class Attachment extends FHC_Controller
}
}
$result = $this->dmslib->getOutputFileInfo($dms_id);
$result = $this->dmslib->download($dms_id);
if (isError($result))
return show_error(getError($result));
@@ -393,7 +393,7 @@ class approveAnrechnungDetail extends Auth_Controller
$filename = $this->anrechnunglib->setFilenameOnDownload($dms_id);
// Get file to be downloaded from DMS
$download = $this->dmslib->getOutputFileInfo($dms_id, $filename);
$download = $this->dmslib->download($dms_id, $filename);
if (isError($download)) return $download;
// Download file
@@ -282,7 +282,7 @@ class approveAnrechnungUebersicht extends Auth_Controller
$filename = $this->anrechnunglib->setFilenameOnDownload($dms_id);
// Get file to be downloaded from DMS
$download = $this->dmslib->getOutputFileInfo($dms_id, $filename);
$download = $this->dmslib->download($dms_id, $filename);
if (isError($download)) return $download;
// Download file
@@ -150,12 +150,15 @@ class CreateAnrechnung extends Auth_Controller
}
// Upload document
$result = $this->_uploadFile();
$result = self::_uploadFile();
if (isError($result)) $this->terminateWithJsonError(getError($result));
if (isError($result))
{
$this->terminateWithJsonError($result->retval);
}
// Hold just inserted DMS ID
$lastInsert_dms_id = getData($result)->dms_id;
$lastInsert_dms_id = $result->retval['dms_id'];
// Save Anrechnung and Anrechnungstatus
$result = $this->AnrechnungModel->createAnrechnungsantrag(
@@ -224,25 +227,17 @@ class CreateAnrechnung extends Auth_Controller
*/
private function _uploadFile()
{
// Upload document
$uploadDataResult = $this->uploadFile('uploadfile', array('pdf'));
// If an error occurred while uploading the file
if (isError($uploadDataResult)) return $uploadDataResult;
if (!hasData($uploadDataResult)) return error('Upload failed');
// Add file to the DMS (DB + file system)
return $this->_ci->dmslib->add(
getData($uploadDataResult)['file_name'],
getData($uploadDataResult)['file_type'],
fopen(getData($uploadDataResult)['full_path'], 'r'),
'anrechnung', // kategorie_kurzbz
null, // dokument_kurzbz
null, // beschreibung
false, // cis_suche
null, // schlagworte
getAuthUID() // insertvon
$dms = array(
'kategorie_kurzbz' => 'anrechnung',
'version' => 0,
'name' => $_FILES['uploadfile']['name'],
'mimetype' => $_FILES['uploadfile']['type'],
'insertamum' => (new DateTime())->format('Y-m-d H:i:s'),
'insertvon' => $this->_uid
);
// Upload document
return $this->dmslib->upload($dms, 'uploadfile', array('pdf'));
}
private function _LVhasBlockingGrades($studiensemester_kurzbz, $lehrveranstaltung_id, $prestudent_id)
@@ -273,4 +268,4 @@ class CreateAnrechnung extends Auth_Controller
return false;
}
}
}
@@ -83,7 +83,7 @@ class requestAnrechnung extends Auth_Controller
$is_expired = $this->_isExpired($studiensemester_kurzbz);
// Check if Lehrveranstaltung was already graded with application blocking grades
$is_blocked = $this->_LVhasBlockingGrades($studiensemester_kurzbz, $lehrveranstaltung_id);
$is_blocked = self::_LVhasBlockingGrades($studiensemester_kurzbz, $lehrveranstaltung_id);
// Get Anrechung data
$anrechnungData = $this->anrechnunglib->getAnrechnungDataByLv($lehrveranstaltung_id, $studiensemester_kurzbz, $prestudent_id);
@@ -152,24 +152,27 @@ class requestAnrechnung extends Auth_Controller
$prestudent_id = getData($result)[0]->prestudent_id;
// Exit if application already exists
if ($this->_applicationExists($lehrveranstaltung_id, $studiensemester_kurzbz, $prestudent_id))
if (self::_applicationExists($lehrveranstaltung_id, $studiensemester_kurzbz, $prestudent_id))
{
return $this->outputJsonError($this->p->t('anrechnung', 'antragBereitsGestellt'));
}
// Exit if application is a past ( < actual ) studysemester
if ($this->_applicationIsPastSS($studiensemester_kurzbz))
if (self::_applicationIsPastSS($studiensemester_kurzbz))
{
return $this->outputJsonError($this->p->t('anrechnung', 'antragNichtFuerVerganganeSS'));
}
// Upload document
$result = $this->_uploadFile();
$result = self::_uploadFile();
if (isError($result)) return $this->outputJsonError(getError($result));
if (isError($result))
{
return $this->outputJsonError($result->retval);
}
// Hold just inserted DMS ID
$lastInsert_dms_id = getData($result)->dms_id;
$lastInsert_dms_id = $result->retval['dms_id'];
// Save Anrechnung and Anrechnungstatus
$result = $this->AnrechnungModel->createAnrechnungsantrag(
@@ -179,8 +182,8 @@ class requestAnrechnung extends Auth_Controller
$begruendung_id,
$lastInsert_dms_id,
$anmerkung,
$begruendung_ects,
$begruendung_lvinhalt
$begruendung_ects,
$begruendung_lvinhalt
);
if (isError($result))
@@ -212,11 +215,11 @@ class requestAnrechnung extends Auth_Controller
$this->_checkIfEntitledToReadDMSDoc($dms_id);
// Get file to be downloaded from DMS
$download = $this->dmslib->getOutputFileInfo($dms_id);
if (isError($download)) return $download;
$download = $this->dmslib->download($dms_id);
if (isError($download)) return $download;
// Download file
$this->outputFile(getData($download));
// Download file
$this->outputFile(getData($download));
}
/**
@@ -364,25 +367,16 @@ class requestAnrechnung extends Auth_Controller
*/
private function _uploadFile()
{
// Upload document
$uploadDataResult = $this->uploadFile('uploadfile', array('pdf'));
// If an error occurred while uploading the file
if (isError($uploadDataResult)) return $uploadDataResult;
// If an error occurred while uploading the file
if (!hasData($uploadDataResult)) return error('Upload failed');
// Add file to the DMS (DB + file system)
return $this->_ci->dmslib->add(
getData($uploadDataResult)['file_name'],
getData($uploadDataResult)['file_type'],
fopen(getData($uploadDataResult)['full_path'], 'r'),
'anrechnung',
null, // dokument_kurzbz
null, // beschreibung
false, // cis_suche
null, // schlagworte
getAuthUID() // insertvon
$dms = array(
'kategorie_kurzbz' => 'anrechnung',
'version' => 0,
'name' => $_FILES['uploadfile']['name'],
'mimetype' => $_FILES['uploadfile']['type'],
'insertamum' => (new DateTime())->format('Y-m-d H:i:s'),
'insertvon' => $this->_uid
);
// Upload document
return $this->dmslib->upload($dms, 'uploadfile', array('pdf'));
}
}
@@ -237,7 +237,7 @@ class reviewAnrechnungDetail extends Auth_Controller
$filename = $this->anrechnunglib->setFilenameOnDownload($dms_id);
// Get file to be downloaded from DMS
$download = $this->dmslib->getOutputFileInfo($dms_id, $filename);
$download = $this->dmslib->download($dms_id, $filename);
if (isError($download)) return $download;
// Download file
@@ -196,7 +196,7 @@ class reviewAnrechnungUebersicht extends Auth_Controller
$filename = $this->anrechnunglib->setFilenameOnDownload($dms_id);
// Get file to be downloaded from DMS
$download = $this->dmslib->getOutputFileInfo($dms_id, $filename);
$download = $this->dmslib->download($dms_id, $filename);
if (isError($download)) return $download;
// Download file
@@ -179,7 +179,6 @@ class InfoCenter extends Auth_Controller
// Loads libraries
$this->load->library('PersonLogLib');
$this->load->library('WidgetLib');
$this->load->library('AkteLib');
$this->load->config('infocenter');
@@ -453,7 +452,8 @@ class InfoCenter extends Auth_Controller
if (isset($akte_id) && isset($person_id))
{
$akte = $this->aktelib->getByAkteId($akte_id);
$this->load->library('AkteLib');
$akte = $this->aktelib->get($akte_id);
if (hasData($akte))
{
@@ -1169,6 +1169,8 @@ class InfoCenter extends Auth_Controller
*/
public function outputAkteContent($akte_id)
{
$this->load->library('DmsLib');
$akte = $this->AkteModel->load($akte_id);
if (isError($akte))
@@ -1176,7 +1178,7 @@ class InfoCenter extends Auth_Controller
show_error(getError($akte));
}
$aktecontent = $this->aktelib->getByAkteId($akte_id);
$aktecontent = $this->dmslib->getAkteContent($akte_id);
if (isError($aktecontent))
{
@@ -2466,4 +2468,4 @@ class InfoCenter extends Auth_Controller
$this->outputJsonSuccess("Success");
}
}
}
+16 -118
View File
@@ -136,77 +136,37 @@ abstract class FHC_Controller extends CI_Controller
/**
* To download the given file represented by the fileObj parameter.
* fileObj has the following structure:
* $fileObj->file OR $fileObj->file_content
* $fileObj->filename
* $fileObj->file
* $fileObj->name
* $fileObj->mimetype
* $fileObj->disposition (inline OR attachment)
* $fileObj->disposition
*/
protected function outputFile($fileObj)
{
// If the file exists
if ((isset($fileObj->file) && !isEmptyString($fileObj->file) && file_exists($fileObj->file))
|| (isset($fileObj->file_content) && !isEmptyString($fileObj->file_content)))
if (isset($fileObj->file) && !isEmptyString($fileObj->file) && file_exists($fileObj->file))
{
$content_length = 0;
// If file content has been provided
if (isset($fileObj->file_content) && !isEmptyString($fileObj->file_content))
{
$content_length = strlen($fileObj->file_content);
}
else // otherwise the path + name of the file
{
$content_length = filesize($fileObj->file);
}
header('Content-Description: File Transfer');
header('Content-Type: '. $fileObj->mimetype);
header('Content-Length: ' . $content_length);
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: '. $fileObj->disposition. '; filename="'. $fileObj->name. '"');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Expires: ' . date("D, d M Y H:i:s", time()));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($fileObj->file));
// Clean the output buffer
flush();
// If file content has been provided
if (isset($fileObj->file_content) && !isEmptyString($fileObj->file_content))
if (isset($fileObj->disposition)
&& ($fileObj->disposition == 'inline' || $fileObj->disposition == 'attachment'))
{
echo $fileObj->file_content;
}
else // otherwise get the content from file system
{
readfile($fileObj->file);
header('Content-Disposition: '. $fileObj->disposition. '; filename="'. $fileObj->name. '"');
}
// Terminate the execution
exit();
readfile($fileObj->file); // reads the file content to the output buffer
}
else
{
// Otherwise print an error
show_error('The provided file does not exist: '.(isset($fileObj->file) ? $fileObj->file : 'file not given'));
}
// Otherwise return an error
show_error('The provided file does not exist or file content is empty');
}
/**
*
*/
protected function outputImageByContent($mimetype, $file_content)
{
if (isEmptyString($file_content)) show_error('The provided file content is not valid');
$this->_outputImage($mimetype, $file_content);
}
/**
*
*/
protected function outputImageByFile($mimetype, $file_name)
{
if (!file_exists($file_name)) show_error('The provided file does not exist');
$this->_outputImage($mimetype, null, $file_name);
}
/**
@@ -218,29 +178,6 @@ abstract class FHC_Controller extends CI_Controller
return json_decode($this->input->raw_input_stream);
}
/**
* Utility function to upload a file
* - post_field_name: the name of the field in the HTTP POST payload, this is also the index in the super global $_FILES array
* - allowed_types: a list of file extensions that are allowed to be uploaded (ex. array('pdf', 'odt') or array('jpg', 'jpeg', 'gif')
*/
protected function uploadFile($post_field_name, $allowed_types = array('*'))
{
$this->load->library(
'upload',
array(
'upload_path' => sys_get_temp_dir(),
'allowed_types' => $allowed_types,
'overwrite' => true
)
);
// If the upload was a success then return the uploaded file info
if ($this->upload->do_upload($post_field_name)) return success($this->upload->data());
// If an error occurred then return it without tags
return error($this->upload->display_errors('', ''));
}
//------------------------------------------------------------------------------------------------------------------
// Private methods
@@ -256,44 +193,5 @@ abstract class FHC_Controller extends CI_Controller
show_error('This web site cannot work correctly without the HTTPS protocol enabled');
}
}
/**
*
*/
private function _outputImage($mimetype, $file_content = null, $file_name = null)
{
$content_length = 0;
// If file content has been provided
if ($file_content != null)
{
$content_length = strlen($file_content);
}
else // otherwise the path + name of the file
{
$content_length = filesize($file_name);
}
header('Content-Type: '. $mimetype);
header('Content-Length: ' . $content_length);
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Expires: ' . date("D, d M Y H:i:s", time()));
// Clean the output buffer
flush();
// If file content has been provided
if ($file_content != null)
{
echo $file_content;
}
else // otherwise get the content from file system
{
readfile($file_name);
}
// Terminate the execution
exit();
}
}
+73
View File
@@ -0,0 +1,73 @@
<?php
if (!defined("BASEPATH")) exit("No direct script access allowed");
/**
* Long Run Task
*
* This controller acts as interface of the LongRunTaskLib that contains
* all the needed functionalities to operate with the Long Run Task system
* that is built on top of the Jobs Queue System
* This is an abstract class that provide basic functionalities,
* it has to be extended to broaden its logic
*/
abstract class LRT_Controller extends JQW_Controller
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
// Changes the needed configs for LogLib
$this->LogLibJob->setConfigs(
array(
'dbExecuteUser' => 'LRTs queue system',
'requestId' => 'LTR'
)
);
// Loads LongRunTaskLib library
$this->load->library('LongRunTaskLib');
}
//------------------------------------------------------------------------------------------------------------------
// Protected methods
/**
* Get the oldest added LRTs to the queue having status = new
*/
protected function getLRTs()
{
$lrts = $this->longruntasklib->getLRTs();
// If an error occurred then log it in database
if (isError($lrts)) $this->logError(getError($lrts));
return $lrts;
}
/**
*
*/
protected function addNewLRTsToQueue($type, $lrts)
{
$result = $this->longruntasklib->addNewLRTsToQueue($type, $lrts);
// If an error occurred then log it in database
if (isError($result)) $this->logError(getError($result), $type);
return $result;
}
/**
* Utility method to generate a job with the given parameters and return it inside an array
* ready to be used by addNewJobsToQueue and updateJobsQueue
*/
protected function generateJobs($status, $input)
{
return JobsQueueLib::generateJobs($status, $input);
}
}
+26 -57
View File
@@ -196,39 +196,26 @@ abstract class Notiz_Controller extends FHCAPI_Controller
$dms_id_arr = [];
foreach ($_FILES as $k => $file)
{
$dms = array(
'kategorie_kurzbz' => 'notiz',
'version' => 0,
'name' => $file["name"],
'mimetype' => $file["type"],
'insertamum' => date('c'),
'insertvon' => $uid
);
//Todo(manu) check if filetypes weiter eingeschränkt werden sollen
//Todo(manu)check name files: nicht gleiches file 2mal hochladen
//Todo define in dms component: readFile, downloadFile
$uploadDataResult = $this->uploadFile($k);
if (isError($uploadDataResult))
$result = $this->dmslib->upload($dms, $k, ['*']);
/* $result = $this->dmslib->upload($dms, $k, ['application/pdf','application/x.fhc-dms+json']);*/
if (isError($result))
{
$this->db->trans_rollback();
$this->terminateWithError(getError($uploadDataResult), self::ERROR_TYPE_GENERAL);
$this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
}
if (!hasData($uploadDataResult))
{
$this->db->trans_rollback();
$this->terminateWithError('Upload failed', self::ERROR_TYPE_GENERAL);
}
// Add file to the DMS (DB + file system)
$addResult = $this->dmslib->add(
getData($uploadDataResult)['file_name'],
getData($uploadDataResult)['file_type'],
fopen(getData($uploadDataResult)['full_path'], 'r'),
'notiz', // kategorie_kurzbz
null, // dokument_kurzbz
null, // beschreibung
false, // cis_suche
null, // schlagworte
getAuthUID() // insertvon
);
// If error occurred
if (isError($addResult) || !hasData($addResult))
$this->terminateWithError(getError($addResult), self::ERROR_TYPE_GENERAL);
$dms_id_arr[] = getData($addResult)->dms_id;
$dms_id_arr[] = $result->retval['dms_id'];
}
//save entry in Notizdokument
@@ -332,40 +319,22 @@ abstract class Notiz_Controller extends FHCAPI_Controller
}
else
{
$dms = array(
'kategorie_kurzbz' => 'notiz',
'version' => 0,
'name' => $file["name"],
'mimetype' => $file["type"],
'insertamum' => date('c'),
'insertvon' => $uid
);
//Todo(manu) check if filetypes weiter eingeschränkt werden sollen
//Todo(manu)check name files: nicht gleiches file 2mal hochladen
//Todo define in dms component: readFile, downloadFile
$uploadDataResult = $this->uploadFile($k);
if (isError($uploadDataResult))
{
$this->db->trans_rollback();
$this->terminateWithError(getError($uploadDataResult), self::ERROR_TYPE_GENERAL);
}
if (!hasData($uploadDataResult))
{
$this->db->trans_rollback();
$this->terminateWithError('Upload failed', self::ERROR_TYPE_GENERAL);
}
$result = $this->dmslib->upload($dms, $k, array('*'));
// Add file to the DMS (DB + file system)
$addResult = $this->dmslib->add(
getData($uploadDataResult)['file_name'],
getData($uploadDataResult)['file_type'],
fopen(getData($uploadDataResult)['full_path'], 'r'),
'notiz', // kategorie_kurzbz
null, // dokument_kurzbz
null, // beschreibung
false, // cis_suche
null, // schlagworte
getAuthUID() // insertvon
);
// If error occurred
if (isError($addResult) || !hasData($addResult))
$this->terminateWithError(getError($addResult), self::ERROR_TYPE_GENERAL);
$addResult = $this->getDataOrTerminateWithError($addResult);
$dms_id = $addResult['dms_id'];
$result = $this->getDataOrTerminateWithError($result);
$dms_id = $result['dms_id'];
$result = $this->NotizdokumentModel->insert(array('notiz_id' => $post_data['notiz_id'], 'dms_id' => $dms_id));
+4 -4
View File
@@ -418,10 +418,10 @@ function findResource($path, $resource, $subdir = false, $extraDir = null)
if (!function_exists('array_is_list')) {
function array_is_list(array $arr)
{
if ($arr === []) {
return true;
}
return array_keys($arr) === range(0, count($arr) - 1);
if ($arr === []) {
return true;
}
return array_keys($arr) === range(0, count($arr) - 1);
}
}
+124 -203
View File
@@ -1,21 +1,12 @@
<?php
/* Copyright (C) 2025 fhcomplete.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
/**
* FH-Complete
*
* @package FHC-Helper
* @author FHC-Team
* @copyright Copyright (c) 2022 fhcomplete.net
* @license GPLv3
*/
if (! defined('BASEPATH')) exit('No direct script access allowed');
@@ -130,32 +121,90 @@ class AkteLib
* Gets akte data and associated dms data by akte Id
* Returns success with akte and dms data or error
*/
public function getByAkteId($akte_id, $dokument_kurzbz = null, $archiv = null, $signiert = null, $stud_selfservice = null)
public function get($akte_id)
{
return $this->_get(
$akte_id,
null, // person_id
$dokument_kurzbz,
$archiv,
$signiert,
$stud_selfservice
);
// 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);
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 and dokument_kurzbz
* Returns success with result array with akte and dms data or error
*/
public function getByPersonId($person_id, $dokument_kurzbz = null, $archiv = null, $signiert = null, $stud_selfservice = null)
public function getByPersonIdAndDocumentType($person_id, $dokument_kurzbz)
{
return $this->_get(
null, // akte_id
$person_id,
$dokument_kurzbz,
$archiv,
$signiert,
$stud_selfservice
// 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
)
);
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);
}
/**
@@ -164,184 +213,56 @@ class AkteLib
*/
public function remove($akte_id)
{
return $this->_remove($akte_id, null, null);
}
/**
* Removes Akte by $person_id and $dms_id, removes all associated dms entries and versions, and deletes all associated files
* Returns success with removed version numbers or error
*/
public function removeByPersonIdAndDmsId($person_id, $dms_id)
{
return $this->_remove(null, $person_id, $dms_id);
}
/**
*
*/
private function _get($akte_id = null, $person_id = null, $dokument_kurzbz = null, $archiv = null, $signiert = null, $stud_selfservice = null)
{
$dbModel = new DB_Model();
$query = 'SELECT akte_id,
person_id,
dokument_kurzbz,
inhalt,
CASE WHEN inhalt is not null THEN true ELSE false END as inhalt_vorhanden,
mimetype,
erstelltam,
gedruckt,
titel,
bezeichnung,
updateamum,
updatevon,
insertamum,
insertvon,
uid,
dms_id,
nachgereicht,
anmerkung,
titel_intern,
anmerkung_intern,
nachgereicht_am,
ausstellungsnation,
formal_geprueft_amum,
archiv,
signiert,
stud_selfservice,
akzeptiertamum
FROM public.tbl_akte
WHERE TRUE';
// Query parameters
$paramArray = array();
// akte_id
if (is_numeric($akte_id) || is_array($akte_id))
{
$paramArray[] = $akte_id;
if (is_numeric($akte_id)) $query .= ' AND akte_id = ?';
if (is_array($akte_id)) $query .= ' AND akte_id IN ?';
}
// person_id
if (is_numeric($person_id) || is_array($person_id))
{
$paramArray[] = $person_id;
if (is_numeric($person_id)) $query .= ' AND person_id = ?';
if (is_array($person_id)) $query .= ' AND person_id IN ?';
}
// dokument_kurzbz
if (!isEmptyString($dokument_kurzbz))
{
$paramArray[] = $dokument_kurzbz;
$query .= ' AND dokument_kurzbz = ?';
}
// archiv
if (is_bool($archiv))
{
$paramArray[] = $archiv;
$query .= ' AND archiv = ?';
}
// signiert
if (is_bool($signiert))
{
$paramArray[] = $signiert;
$query .= ' AND signiert = ?';
}
// stud_selfservice
if (is_bool($stud_selfservice))
{
$paramArray[] = $stud_selfservice;
$query .= ' AND stud_selfservice = ?';
}
// If no parameters has been provided exit
if (isEmptyArray($paramArray)) return error('Called without giving any parameter');
// Loads data from DB
$akteResult = $dbModel->execReadOnlyQuery($query, $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 (getData($akteResult) as $resultObject)
{
// 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');
// set dms properties
if (hasData($dmsResult))
{
$dmsData = getData($dmsResult)[0];
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));
}
/**
* Removes Akte by akte Id, person id and/or dms id
* Removes all associated dms entries and versions, and deletes all associated files
* Returns success with removed version numbers or error
*/
private function _remove($akte_id = null, $person_id = null, $dms_id = null)
{
// Get dms_id for akte
$this->_ci->AkteModel->addSelect('akte_id');
// get dms_id for akte
$this->_ci->AkteModel->addSelect('dms_id');
$paramArray = array();
if (is_numeric($akte_id)) $paramArray['akte_id'] = $akte_id;
if (is_numeric($person_id)) $paramArray['person_id'] = $person_id;
if (is_numeric($dms_id)) $paramArray['dms_id'] = $dms_id;
$akteResult = $this->_ci->AkteModel->loadWhere($paramArray);
$akteResult = $this->_ci->AkteModel->load($akte_id);
if (isError($akteResult)) return $akteResult;
if (!hasData($akteResult)) return error('Akte not found');
if (!hasData($akteResult)) return error("Akte not found");
// Delete Akte
$deleteResult = $this->_ci->AkteModel->delete(getData($akteResult)[0]->akte_id);
$dms_id = getData($akteResult)[0]->dms_id;
$error = null;
if (isError($deleteResult)) return $deleteResult;
// Start DB transaction to avoid deleting only part of the data
$this->_ci->db->trans_begin();
// Remove all dms entry for dms of the akte
$removeAllResult = $this->_ci->dmslib->removeAll(getData($akteResult)[0]->dms_id);
// delete Akte
$deleteResult = $this->_ci->AkteModel->delete($akte_id);
return $removeAllResult;
if (isError($deleteResult))
{
$error = $deleteResult;
}
else
{
// remove all dms entry for dms of the akte
$removeAllResult = $this->_ci->dmslib->removeAll($dms_id);
if (isError($removeAllResult))
$error = $removeAllResult;
}
// Transaction complete!
$this->_ci->db->trans_complete();
// Check if everything went ok during the transaction
if ($this->_ci->db->trans_status() === false || isset($error))
{
$this->_ci->db->trans_rollback();
// return occured error
if (isset($error))
return $error;
else
return error("Error occured when deleting, rolled back");
}
else
{
$this->_ci->db->trans_commit();
// return removed dms entry data
return $removeAllResult;
}
}
}
+523 -118
View File
@@ -1,21 +1,12 @@
<?php
/* Copyright (C) 2025 fhcomplete.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
/**
* FH-Complete
*
* @package FHC-Helper
* @author FHC-Team
* @copyright Copyright (c) 2022 fhcomplete.net
* @license GPLv3
*/
if (! defined('BASEPATH')) exit('No direct script access allowed');
@@ -24,17 +15,24 @@ use \stdClass as stdClass;
class DmsLib
{
const DMS_SYS_NAME = 'DMS System';
const FILE_CONTENT_PROPERTY = 'file_content'; // property name for file content
private $_ci; // code igniter instance
private $_who; // who added this document
/**
* Object initialization
*/
public function __construct()
public function __construct($params = null)
{
$this->_ci =& get_instance();
// 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');
@@ -48,85 +46,69 @@ class DmsLib
* Returns success info of added dms entry (dms_id, version, filename) or error
*/
public function add(
// Required parameters
$name, $mimetype, $fileHandle,
// Optional parameters
$kategorie_kurzbz = null, $dokument_kurzbz = null, $beschreibung = null, $cis_suche = false, $schlagworte = null, $insertvon = self::DMS_SYS_NAME
$name, $mimetype, $fileHandle, // Required parameters
$kategorie_kurzbz = null, $dokument_kurzbz = null, $beschreibung = null, $cis_suche = false, $schlagworte = null
)
{
// If the file handle is not valid
if ($fileHandle === false) return error('Was not possible to open the given file');
// create unique filename, using original document name to detect file extension
$filename = $this->_getUniqueFilename($name);
// Create unique filename, using original document name to detect file extension
$filename = $this->_getUniqueFilename($name);
// copy file from fileHandle to dms folder
$copyFileResult = $this->_copyFile($fileHandle, $filename);
// Copy file from fileHandle to dms folder
$copyFileResult = $this->_copyFile($fileHandle, $filename);
if (isError($copyFileResult)) return $copyFileResult;
// If an error occrured while copying the file
if (isError($copyFileResult)) return $copyFileResult;
// Insert the new DMS
$dmsResult = $this->_ci->DmsModel->insert(
array(
'kategorie_kurzbz' => $kategorie_kurzbz,
'dokument_kurzbz' => $dokument_kurzbz
)
);
// If an error occurred
if (isError($dmsResult)) return $dmsResult;
// If a DMS in the previous insert returned the new PK value
if (hasData($dmsResult))
{
$dms_id = getData($dmsResult);
// Insert the DMS version
$dmsVersion = array(
'dms_id' => $dms_id,
'version' => 0,
'filename' => $filename,
'mimetype' => $mimetype,
'name' => $name,
'beschreibung' => $beschreibung,
'cis_suche' => $cis_suche,
'schlagworte' => $schlagworte,
'insertvon' => $insertvon,
'insertamum' => date('Y-m-d H:i:s')
// if file written successful, insert dms
$dmsResult = $this->_ci->DmsModel->insert(
array(
'kategorie_kurzbz' => $kategorie_kurzbz,
'dokument_kurzbz' => $dokument_kurzbz
)
);
$dmsVersionResult = $this->_ci->DmsVersionModel->insert($dmsVersion);
if (isError($dmsResult)) return $dmsResult;
// If an error occured
if (isError($dmsVersionResult)) return $dmsVersionResult;
if (hasData($dmsResult))
{
$dms_id = getData($dmsResult);
$version = 0;
// Return dms info
$resObj = new stdClass();
$resObj->dms_id = $dms_id;
$resObj->version = 0;
$resObj->filename = $filename;
// insert dms version
$dmsVersion = array(
'dms_id' => $dms_id,
'version' => $version,
'filename' => $filename,
'mimetype' => $mimetype,
'name' => $name,
'beschreibung' => $beschreibung,
'cis_suche' => $cis_suche,
'schlagworte' => $schlagworte,
'insertvon' => $this->_who,
'insertamum' => date('Y-m-d H:i:s')
);
return success($resObj);
}
else
return success();
$dmsVersionResult = $this->_ci->DmsVersionModel->insert($dmsVersion);
if (isError($dmsVersionResult)) return $dmsVersionResult;
// return dms info
$resObj = new stdClass();
$resObj->dms_id = $dms_id;
$resObj->version = $version;
$resObj->filename = $filename;
return success($resObj);
}
else
return error("error when inserting DMS");
}
/**
* Writes a new file with content of fileHandle, adds a new dms version (max version number + 1) for the written file
* Returns success with info of added dms version (version, filename) or error
*/
public function addNewVersion(
// Required parameters
$dms_id, $fileHandle,
// Optional parameters
$name = null, $mimetype = null, $beschreibung = null, $cis_suche = false, $schlagworte = null, $insertvon = self::DMS_SYS_NAME
)
public function addNewVersion($dms_id, $fileHandle, $name = null, $mimetype = null, $beschreibung = null, $cis_suche = false, $schlagworte = null)
{
// If the file handle is not valid
if ($fileHandle === false) return error('Was not possible to open the given file');
// get the latest version
$lastVersionResult = $this->getLastVersion($dms_id);
@@ -159,7 +141,7 @@ class DmsLib
'beschreibung' => isset($beschreibung) ? $beschreibung : $lastVersion->beschreibung,
'cis_suche' => isset($cis_suche) ? $cis_suche : $lastVersion->cis_suche,
'schlagworte' => isset($schlagworte) ? $schlagworte : $lastVersion->schlagworte,
'insertvon' => $insertvon,
'insertvon' => $this->_who,
'insertamum' => date('Y-m-d H:i:s')
);
@@ -175,7 +157,7 @@ class DmsLib
return success($resObj);
}
else
return success();
return error("last version not found");
}
/**
@@ -185,9 +167,6 @@ class DmsLib
*/
public function updateLastVersion($dms_id, $fileHandle, $name = null, $mimetype = null, $beschreibung = null, $cis_suche = false, $schlagworte = null)
{
// If the file handle is not valid
if ($fileHandle === false) return error('Was not possible to open the given file');
// get the latest version
$lastVersionResult = $this->getLastVersion($dms_id);
@@ -229,12 +208,12 @@ class DmsLib
return success($resObj);
}
else
return success();
return error("last version not found");
}
/**
* Gets dms version with highest number
* Returns success with dms data or error
* Returns success with dms data and fileHandle with file content or error
*/
public function getLastVersion($dms_id)
{
@@ -258,12 +237,12 @@ class DmsLib
return $this->getVersion($dms_id, $lastDmsVersion);
}
else
return success();
return error("Dms last version not found");
}
/**
* Gets specified dms version
* Returns success with dms data or error
* Returns success with dms data and fileHandle with file content or error
*/
public function getVersion($dms_id, $version)
{
@@ -275,7 +254,34 @@ class DmsLib
)
);
return $dmsVersionResult;
if (isError($dmsVersionResult)) return $dmsVersionResult;
if (hasData($dmsVersionResult))
{
$dmsVersion = 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");
}
/**
@@ -414,34 +420,6 @@ class DmsLib
return success($removeVersionResultObj);
}
/**
* 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->file = DMS_PATH.$lastVersion->filename;
$fileObj->name = isEmptyString($file_name) ? $lastVersion->name : $file_name;
$fileObj->mimetype = $lastVersion->mimetype;
$fileObj->disposition = $disposition;
return success($fileObj);
}
return success();
}
// -----------------------------------------------------------------------------------------------------------
// Private methods
@@ -496,5 +474,432 @@ 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 = 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);
}
}
+236 -37
View File
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2025 fhcomplete.net
/* Copyright (C) 2024 fhcomplete.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -34,11 +34,15 @@ use SimpleXMLElement as SimpleXMLElement;
* modifiing said data (sign()/setXMLTag_archivierbar()) or adding
* images (addImage()) and then call output() and close().
* Now the create, output and close functions are combined into one function and adding data and images is done via parameters.
* There are now two functions getContent() and showContent() where showContent() equals to output(false) and getContent equals to output(true)
* Instead of calling addDataArray, addDataXML or addDataURL just call
* getDataArray, getDataXML or getDataURL respectevily and use the return
* value as $xml_data parameter in the getContent call.
* value as $xml_data parameter in the showContent and getContent calls.
* Instead of calling addImages just create an array and pass it as $images
* parameter to the getContent function.
* parameter to the showContent/getContent function.
* The old setFilename() function is now a parameter in showContent(). It is
* not needed in getContent() since that function does not do anything that
* requires a filename.
* To get/show a signed document just pass a valid uid as $sign_user
* parameter.
*
@@ -59,10 +63,21 @@ use SimpleXMLElement as SimpleXMLElement;
* 'name' => $imagename,
* 'contenttype' => $imagecontenttype
* ]];
* $this->documentexportlib->showContent(
* $filename,
* $vorlage,
* $xml_data,
* $oe_kurzbz,
* $version,
* $outputformat,
* null,
* null,
* $images
* );
*/
class DocumentExportLib
{
private $_ci;
private $unoconv_version;
/**
* Constructor
@@ -70,14 +85,33 @@ class DocumentExportLib
public function __construct()
{
// Gets CI instance
$this->_ci =& get_instance();
$this->ci =& get_instance();
// Load phrases
$this->_ci->load->library('PhrasesLib', ['document_export', null], 'DocumentExportPhrases');
// Load Phrases
$this->ci->load->library('PhrasesLib', ['document_export', null], 'documentExportPhrases');
// Load libraries
$this->_ci->load->library('DocumentLib');
$this->_ci->load->library('SignatureLib');
// Which document converter has to be used
if (defined('DOCSBOX_ENABLED') && DOCSBOX_ENABLED === true)
{
// Use docsbox!!
}
else
{
exec('unoconv --version', $ret_arr);
if(isset($ret_arr[0]))
{
$hlp = explode(' ', $ret_arr[0]);
if(isset($hlp[1]))
{
$this->unoconv_version = $hlp[1];
}
else
show_error($this->ci->documentExportPhrases->t("document_export", "error_unoconv_version"));
}
else
show_error($this->ci->documentExportPhrases->t("document_export", "error_unoconv"));
}
}
/**
@@ -138,7 +172,7 @@ class DocumentExportLib
$xml_data = new DOMDocument;
if (!$xml_data->load($xml_url))
return error($this->_ci->DocumentExportPhrases->t("document_export", "error_xml_load", [
return error($this->ci->documentExportPhrases->t("document_export", "error_xml_load", [
"url" => $xml_url,
"xml" => $xml,
"params" => $params
@@ -202,7 +236,7 @@ class DocumentExportLib
$outputformat = $this->getDefaultOutputFormat($outputformat, $vorlage->mimetype);
$createResult = $this->createAndSignContent(
$result = $this->createAndSignContent(
$temp_folder,
$outputformat,
$vorlage,
@@ -213,26 +247,118 @@ class DocumentExportLib
$sign_user,
$sign_profile
);
if (isError($createResult)) {
if (isError($result)) {
$this->close($temp_folder, $source_folder);
return $createResult;
return $result;
}
$temp_filename = getData($createResult);
$temp_filename = getData($result);
$fsize = filesize($temp_filename);
$handle = fopen($temp_filename, 'r');
if (!$handle)
return error($this->_ci->DocumentExportPhrases->t("document_export", "error_file_load"));
$fileContentResult = fread($handle, $fsize);
return error($this->ci->documentExportPhrases->t("document_export", "error_file_load"));
$result = fread($handle, $fsize);
fclose($handle);
$this->close($temp_folder, $source_folder);
return success($fileContentResult);
return success($result);
}
/**
* Helper function for getContent
* Sets the headers and displays the Document.
* On failure the exit() function will be called
*
* @param string $filename
* @param stdClass $vorlage A db entry from tbl_vorlage
* @param DomDocument $xml_data
* @param string $oe_kurzbz
* @param integer|null $version (optional)
* @param string $outputformat (optional)
* @param string $sign_user (optional) Must be a valid uid
* @param string $sign_profile (optional) Signatureprofile for signing
* @param array $images (optional) Each element should have a property path, name & contenttype which are all strings
*
* @return void
*/
public function showContent(
$filename,
$vorlage,
$xml_data,
$oe_kurzbz,
$version = null,
$outputformat = null,
$sign_user = null,
$sign_profile = null,
$images = []
) {
$source_folder = getcwd();
$temp_folder = sys_get_temp_dir() . '/fhcunoconv-' . uniqid();
$outputformat = $this->getDefaultOutputFormat($outputformat, $vorlage->mimetype);
$result = $this->createAndSignContent(
$temp_folder,
$outputformat,
$vorlage,
$oe_kurzbz,
$version,
$xml_data,
$images,
$sign_user,
$sign_profile
);
if (isError($result)) {
$this->close($temp_folder, $source_folder);
exit(getError($result));
}
$temp_filename = getData($result);
$fsize = filesize($temp_filename);
$handle = fopen($temp_filename, 'r');
if (!$handle) {
$this->close($temp_folder, $source_folder);
exit($this->ci->documentExportPhrases->t("document_export", "error_file_load"));
}
if (headers_sent()) {
$this->close($temp_folder, $source_folder);
exit($this->ci->documentExportPhrases->t("document_export", "error_headers"));
}
switch ($outputformat) {
case 'pdf':
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="' . $filename . '.pdf"');
header('Content-Length: ' . $fsize);
break;
case 'doc':
header('Content-type: application/vnd.ms-word');
header('Content-Disposition: attachment; filename="' . $filename . '.doc"');
header('Content-Length: ' . $fsize);
break;
case 'odt':
header('Content-type: application/vnd.oasis.opendocument.text');
header('Content-Disposition: attachment; filename="' . $filename . '.odt"');
header('Content-Length: ' . $fsize);
break;
default:
$this->close($temp_folder, $source_folder);
exit($this->ci->documentExportPhrases->t("document_export", "error_outputformat_missing"));
}
while (!feof($handle)) {
echo fread($handle, 8192);
}
fclose($handle);
$this->close($temp_folder, $source_folder);
}
/**
* Helper function for getContent and showContent.
* Creates the temp folder and calls create and sign functions.
*
* @param string $temp_folder
@@ -261,13 +387,13 @@ class DocumentExportLib
mkdir($temp_folder);
chdir($temp_folder);
$this->_ci->load->model('system/Vorlagestudiengang_model', 'VorlagestudiengangModel');
$this->ci->load->model('system/Vorlagestudiengang_model', 'VorlagestudiengangModel');
$result = $this->_ci->VorlagestudiengangModel->getCurrent($vorlage->vorlage_kurzbz, $oe_kurzbz, $version);
$result = $this->ci->VorlagestudiengangModel->getCurrent($vorlage->vorlage_kurzbz, $oe_kurzbz, $version);
if (isError($result))
return $result;
if (!hasData($result))
return error($this->_ci->DocumentExportPhrases->t("document_export", "error_template_missing"));
return error($this->ci->documentExportPhrases->t("document_export", "error_template_missing"));
$vorlage_stg = current(getData($result));
foreach ($vorlage_stg as $k => $v)
$vorlage->$k = $v;
@@ -311,7 +437,7 @@ class DocumentExportLib
{
$content_xsl = new DOMDocument();
if (!$content_xsl->loadXML($vorlage->text))
return error($this->_ci->DocumentExportPhrases->t("document_export", "error_xsl_load"));
return error($this->ci->documentExportPhrases->t("document_export", "error_xsl_load"));
$proc = new XSLTProcessor();
$proc->importStyleSheet($content_xsl);
@@ -328,7 +454,7 @@ class DocumentExportLib
if ($vorlage->style) {
$styles_xsl = new DOMDocument();
if (!$styles_xsl->loadXML($vorlage->style))
return error($this->_ci->DocumentExportPhrases->t("document_export", "error_styles_load"));
return error($this->ci->documentExportPhrases->t("document_export", "error_styles_load"));
$style_proc = new XSLTProcessor();
$style_proc->importStyleSheet($styles_xsl);
@@ -356,7 +482,7 @@ class DocumentExportLib
$tempname_zip = $temp_folder . '/out.zip';
if (!copy($zipfile, $tempname_zip))
return error($this->_ci->DocumentExportPhrases->t("document_export", "error_file_copy"));
return error($this->ci->documentExportPhrases->t("document_export", "error_file_copy"));
exec("zip $tempname_zip content.xml");
if (!is_null($styles_xsl))
@@ -376,7 +502,7 @@ class DocumentExportLib
$manifest_xml = new DOMDocument;
if (!$manifest_xml->loadXML($manifest))
return error($this->_ci->DocumentExportPhrases->t("document_export", "error_manifest"));
return error($this->ci->documentExportPhrases->t("document_export", "error_manifest"));
//root-node holen
$root = $manifest_xml->getElementsByTagName('manifest')->item(0);
@@ -403,16 +529,42 @@ class DocumentExportLib
clearstatcache();
$temp_filename = $temp_folder . '/out.' . $outputformat;
switch ($outputformat) {
case 'pdf':
case 'doc':
$converResult = $this->_ci->documentlib->convert($tempname_zip, $temp_filename, $outputformat);
$ret = 0;
$temp_filename = $temp_folder . '/out.' . $outputformat;
if (isError($converResult))
return error($this->_ci->DocumentExportPhrases->t('document_export', 'error_conv_timeout'));
if (defined('DOCSBOX_ENABLED') && DOCSBOX_ENABLED === true) {
// Use docsbox
$this->ci->load->library("DocsboxLib");
$docboxlib = get_class($this->ci->docboxlib);
$ret = $docboxlib::convert($tempname_zip, $temp_filename, $outputformat);
} else {
// Use unoconv
// Unoconv Version 0.6 hat eine Bug wodurch die Berechtigungen des PDF/Doc nicht korrekt gesetzt
// werden. Deshalb wird dies hier speziell behandelt.
// Die 2. Variante hat den Vorteil dass hier eine bessere Fehlerbehandlung moeglich ist
if ($this->unoconv_version == '0.6')
$command = 'unoconv -e IsSkipEmptyPages=false -f ' . $outputformat . ' %2$s > %1$s';
else
$command = 'unoconv -e IsSkipEmptyPages=false -f ' . $outputformat . ' --output %s %s 2>&1';
$command = sprintf($command, $temp_filename, $tempname_zip);
exec($command, $out, $ret);
}
if ($ret)
return error($this->ci->documentExportPhrases->t("document_export", "error_conv_timeout"));
break;
case 'odt':
default:
$temp_filename = $tempname_zip;
}
return success($temp_filename);
@@ -432,15 +584,63 @@ class DocumentExportLib
*/
protected function sign($temp_folder, $temp_filename, $outputformat, $user, $profile)
{
if ($outputformat != 'pdf') return error($this->_ci->DocumentExportPhrases->t('document_export', 'error_sign_pdf'));
if ($outputformat != 'pdf')
return error($this->ci->documentExportPhrases->t("document_export", "error_sign_pdf"));
$signed_filename = $this->_ci->signaturelib->sign($temp_folder, $temp_filename, $user, $profile);
// Load the File
$file_data = file_get_contents($temp_filename);
// If fine then return it
if (isSuccess($signed_filename)) return $signed_filename;
$data = new stdClass();
$data->document = base64_encode($file_data);
// Otherwise it is an error
return error($this->_ci->DocumentExportPhrases->t('global', 'unknown_error', ['error' => getError($signed_filename)]));
// Signatur Profil
if (!is_null($profile))
$data->profile = $profile;
else
$data->profile = SIGNATUR_DEFAULT_PROFILE;
// Username des Endusers der die Signatur angefordert hat
$data->user = $user;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, SIGNATUR_URL . '/' . SIGNATUR_SIGN_API);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 7);
curl_setopt($ch, CURLOPT_USERAGENT, "FH-Complete");
// SSL Zertifikatsprüfung deaktivieren
// Besser ist es das Zertifikat am Server zu installieren!
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data_string = json_encode($data, JSON_FORCE_OBJECT);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length:' . mb_strlen($data_string),
'Authorization: Basic ' . base64_encode(SIGNATUR_USER . ":" . SIGNATUR_PASSWORD)
]);
$result = curl_exec($ch);
if (curl_errno($ch)) {
curl_close($ch);
return error($this->ci->documentExportPhrases->t("document_export", "error_sign_timeout"));
}
curl_close($ch);
$resultdata = json_decode($result);
// If it is success
if (isset($resultdata->error) && $resultdata->error == 0) {
$signed_filename = $temp_folder . '/signed.pdf';
file_put_contents($signed_filename, base64_decode($resultdata->retval));
return success($signed_filename);
}
// otherwise if it is an error
return error($resultdata->retval ?? $this->ci->documentExportPhrases->t("global", "unknown_error", ["error" => $result]));
}
/**
@@ -517,4 +717,3 @@ class DocumentExportLib
return 'pdf';
}
}
+24 -25
View File
@@ -4,8 +4,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed');
class DocumentLib
{
private $_ci;
private $_unoconv_version;
private $unoconv_version;
/**
* Constructor
@@ -13,10 +12,7 @@ class DocumentLib
public function __construct()
{
// Gets CI instance
$this->_ci =& get_instance();
// Load phrases
$this->_ci->load->library('PhrasesLib', ['document_export', null], 'DocumentExportPhrases');
$this->ci =& get_instance();
// Which document converter has to be used
if (defined('DOCSBOX_ENABLED') && DOCSBOX_ENABLED === true)
@@ -32,13 +28,13 @@ class DocumentLib
$hlp = explode(' ', $ret_arr[0]);
if(isset($hlp[1]))
{
$this->_unoconv_version = $hlp[1];
$this->unoconv_version = $hlp[1];
}
else
show_error($this->_ci->DocumentExportPhrases->t('document_export', 'error_unoconv_version'));
show_error('Could not get Unoconv Version');
}
else
show_error($this->_ci->DocumentExportPhrases->t('document_export', 'error_unoconv'));
show_error('Unoconv not found - Please install Unoconv');
}
}
@@ -60,7 +56,7 @@ class DocumentLib
case 'image/jpeg':
case 'image/jpg':
case 'image/pjpeg':
$this->_jpegToPdf($filename, $outFile);
$this->_jpegtopdf($filename, $outFile);
return success($outFile);
case 'application/vnd.oasis.opendocument.spreadsheet':
case 'application/msword':
@@ -76,19 +72,23 @@ class DocumentLib
else
{
// Unoconv Version 0.6 seems to fail on converting TXT Files
if ($this->_unoconv_version == '0.6') return error('Unoconv Version 0.6 does not convert TXT Files correctly');
if ($this->unoconv_version == '0.6')
return error();
}
// Convertion
$ret = $this->convert($filename, $outFile, 'pdf');
if(isSuccess($ret)) return success($outFile);
// Error
return $ret;
if(isSuccess($ret))
{
return success($outFile);
}
else
{
return error(getError($ret));
}
case 'application/pdf':
return success($filename);
default:
return error('Unknown Mimetype:' . $mimetype);
return error('Unknown Mimetype:'.$mimetype);
}
}
@@ -101,20 +101,20 @@ class DocumentLib
*/
public function mergePDF($files, $outFile)
{
$cmd = 'gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outFile ';
$cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outFile ";
$finfo = finfo_open(FILEINFO_MIME_TYPE);
// add all pdf files to the command
foreach ($files as $f)
{
$cmd .= $f.' ';
$cmd .= $f." ";
if (!file_exists($f))
{
return error("File not found: '$f'");
}
if (finfo_file($finfo, $f) != 'application/pdf')
if (finfo_file($finfo, $f) != "application/pdf")
{
return error('Wrong format('.finfo_file($finfo, $f)."): '$f'");
return error("Wrong format(".finfo_file($finfo, $f)."): '$f'");
}
}
@@ -144,13 +144,13 @@ class DocumentLib
// If it is set to use docsbox
if (defined('DOCSBOX_ENABLED') && DOCSBOX_ENABLED === true)
{
require_once(dirname(__FILE__).'/DocsboxLib.php');
require_once(dirname(__FILE__).'/../application/libraries/DocsboxLib.php');
$ret = DocsboxLib::convert($inFile, $outFile, $format);
}
else // otherwise use unoconv
{
if ($this->_unoconv_version == '0.6')
if ($this->unoconv_version == '0.6')
$command = 'unoconv -f %1$s %3$s > %2$s';
else
$command = 'unoconv -f %s --output %s %s 2>&1';
@@ -175,7 +175,7 @@ class DocumentLib
* @param string $outfile Path to Output (pdf) File.
* @return success or error object
*/
private function _jpegToPdf($filename, $outfile)
private function _jpegtopdf($filename, $outfile)
{
if (!file_exists($filename))
return error('File does not exists');
@@ -230,4 +230,3 @@ class DocumentLib
return true;
}
}
+4 -2
View File
@@ -2,6 +2,8 @@
if (!defined('BASEPATH')) exit('No direct script access allowed');
use \stdClass as stdClass;
/**
* Library that contains all the needed functionalities to operate with the Jobs Queue System
*/
@@ -24,12 +26,12 @@ class JobsQueueLib
const PROPERTY_END_TIME = 'endtime';
const PROPERTY_ERROR = 'error';
private $_ci; // CI instance
protected $_ci; // CI instance
/**
* Constructor
*/
public function __construct($authenticate = true)
public function __construct()
{
// Gets CI instance
$this->_ci =& get_instance();
+66
View File
@@ -0,0 +1,66 @@
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Library that contains all the needed functionalities to operate with the Long Run Tasks
*/
class LongRunTaskLib extends JobsQueueLib
{
const CFG_LRT_MAX_NUMBER_SYSTEM = 'lrt_max_number_system';
const CFG_LRT_TYPES = 'lrt_types';
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
// Loads the Long Run Tasks configs
$this->_ci->config->load('lrt');
}
//------------------------------------------------------------------------------------------------------------------
// Public methods
/**
* Get the oldest added LRTs to the queue having status = new
* The maximum number of returned queued LRTs is limited by:
* number of currently running LRTs - maximum allowed number of LRTs for the system
*/
public function getLRTs()
{
// Get all the running LRTs
$runningLrtsResult = $this->getJobsByTypeStatus($this->_ci->config->item(self::CFG_LRT_TYPES)), JobsQueueLib::STATUS_RUNNING);
if (isError($runningLrtsResult)) return $runningLrtsResult;
// The number of the currently running LRTs - the maximum LRTs for the system
$max_number_of_lrts = $this->_ci->config->item(self::CFG_LRT_MAX_NUMBER_SYSTEM)) - count(getData($runningLrtsResult));
// Get the oldest LRTs added to the queue
return $this->getOldestJobs($this->_ci->config->item(self::CFG_LRT_TYPES)), $max_number_of_lrts);
}
/**
*
*/
public function addNewLRTsToQueue($type, $lrts)
{
return $this->addNewJobsToQueue($type, $lrts);
}
//------------------------------------------------------------------------------------------------------------------
// Public static methods
/**
* Utility method to generate a LTR with the given parameters and return it inside an array
* ready to be used by addNewLRTsToQueue
*/
public static function generateLtrs($status, $input)
{
return self::generateJobs($status, $input);
}
}
+9 -77
View File
@@ -36,7 +36,15 @@ class SignatureLib
try
{
// Dont send Document if it is bigger than 30 MB (Limit of Signature Server)
if (filesize($inputFileName) > 30000000) return $this->_returnObject(1, 1, 'File too big');
if (filesize($inputFileName) > 30000000)
{
$returnObject = new stdClass();
$returnObject->code = 1;
$returnObject->error = 1;
$returnObject->retval = 'File to big';
return $returnObject;
}
// Get the content of the given file
$inputFileContent = file_get_contents($inputFileName);
@@ -74,80 +82,4 @@ class SignatureLib
// Otherwise return a null as error
return null;
}
/**
*
*/
public function sign($temp_folder, $inputFileName, $user, $profile)
{
// Load the File
$file_data = file_get_contents($inputFileName);
$data = new stdClass();
$data->document = base64_encode($file_data);
// Signatur Profil
if (!is_null($profile))
$data->profile = $profile;
else
$data->profile = SIGNATUR_DEFAULT_PROFILE;
// Username des Endusers der die Signatur angefordert hat
$data->user = $user;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, SIGNATUR_URL . '/' . SIGNATUR_SIGN_API);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 7);
curl_setopt($ch, CURLOPT_USERAGENT, "FH-Complete");
// SSL Zertifikatsprüfung deaktivieren
// Besser ist es das Zertifikat am Server zu installieren!
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data_string = json_encode($data, JSON_FORCE_OBJECT);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length:' . mb_strlen($data_string),
'Authorization: Basic ' . base64_encode(SIGNATUR_USER . ':' . SIGNATUR_PASSWORD)
]);
$result = curl_exec($ch);
if (curl_errno($ch)) {
curl_close($ch);
return $this->_returnObject(1, 1, 'CURL error');
}
curl_close($ch);
$resultdata = json_decode($result);
// If it is success
if (isset($resultdata->error) && $resultdata->error == 0)
{
$signed_filename = $temp_folder . '/signed.pdf';
file_put_contents($signed_filename, base64_decode($resultdata->retval));
return $this->_returnObject(0, 0, $signed_filename);
}
// Otherwise it is an error
return $this->_returnObject(1, 1, 'Error while signing the given document');
}
/**
*
*/
private function _returnObject($code, $error, $retval)
{
$returnObject = new stdClass();
$returnObject->code = $code;
$returnObject->error = $error;
$returnObject->retval = $retval;
return $returnObject;
}
}
+56 -1
View File
@@ -248,5 +248,60 @@ 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
]);
}
}
@@ -341,8 +341,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/akte/download?akte_id=' + encodeURIComponent(akte_id),
+ FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/api/frontend/v1/stv/dokumente/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'
);
},
+2 -1
View File
@@ -94,6 +94,7 @@ require_once('dbupdate_3.4/71399_dashboard_update_widget_paths.php');
require_once('dbupdate_3.4/71645_studvw_messagetab_ladezeit.php');
require_once('dbupdate_3.4/71566_studienordnungsdokument_neuer_organisationseinheitstyp_programm.php');
require_once('dbupdate_3.4/70376_lohnguide.php');
require_once('dbupdate_3.4/76203_Asynchrone_Tasks.php');
// *** Pruefung und hinzufuegen der neuen Attribute und Tabellen
echo '<H2>Pruefe Tabellen und Attribute!</H2>';
@@ -429,7 +430,7 @@ $tabellen=array(
"system.tbl_log" => array("log_id","person_id","zeitpunkt","app","oe_kurzbz","logtype_kurzbz","logdata","insertvon","taetigkeit_kurzbz"),
"system.tbl_logtype" => array("logtype_kurzbz", "data_schema"),
"system.tbl_filters" => array("filter_id","app","dataset_name","filter_kurzbz","person_id","description","sort","default_filter","filter","oe_kurzbz","statistik_kurzbz"),
"system.tbl_jobsqueue" => array("jobid", "type", "creationtime", "status", "input", "output", "starttime", "endtime", "insertvon", "insertamum"),
"system.tbl_jobsqueue" => array("jobid", "type", "creationtime", "status", "input", "output", "starttime", "endtime", "insertvon", "insertamum", "pid", "uid", "progress"),
"system.tbl_jobstatuses" => array("status"),
"system.tbl_jobtriggers" => array("type", "status", "following_type"),
"system.tbl_jobtypes" => array("type", "description"),
@@ -0,0 +1,59 @@
<?php
// Add column pid to system.tbl_jobsqueue
if (!$result = @$db->db_query('SELECT "pid" FROM "system"."tbl_jobsqueue" LIMIT 1'))
{
$qry = 'ALTER TABLE "system"."tbl_jobsqueue" ADD "pid" INT NULL DEFAULT 0;';
if (!$db->db_query($qry))
echo '<strong>system.tbl_jobsqueue: '.$db->db_last_error().'</strong><br>';
else
echo '<br>Added column pid to table system.tbl_jobsqueue';
}
// Add column uid to system.tbl_jobsqueue
if (!$result = @$db->db_query('SELECT "uid" FROM "system"."tbl_jobsqueue" LIMIT 1'))
{
$qry = 'ALTER TABLE "system"."tbl_jobsqueue" ADD "uid" VARCHAR(32) NULL DEFAULT NULL;';
if (!$db->db_query($qry))
echo '<strong>system.tbl_jobsqueue: '.$db->db_last_error().'</strong><br>';
else
echo '<br>Added column uid to table system.tbl_jobsqueue';
}
// Add column progress to system.tbl_jobsqueue
if (!$result = @$db->db_query('SELECT "progress" FROM "system"."tbl_jobsqueue" LIMIT 1'))
{
$qry = 'ALTER TABLE "system"."tbl_jobsqueue" ADD "progress" NUMERIC(2,1) NULL DEFAULT 0;';
if (!$db->db_query($qry))
echo '<strong>system.tbl_jobsqueue: '.$db->db_last_error().'</strong><br>';
else
echo '<br>Added column progress to table system.tbl_jobsqueue';
}
// Add foreign key fk_jobsqueue_benutzer_uid on system.tbl_jobsqueue.uid with public.tbl_benutzer.uid
if ($result = $db->db_query("SELECT conname FROM pg_constraint WHERE conname = 'fk_jobsqueue_benutzer_uid'"))
{
if ($db->db_num_rows($result) == 0)
{
$qry = 'ALTER TABLE "system"."tbl_jobsqueue" ADD CONSTRAINT "fk_jobsqueue_benutzer_uid" FOREIGN KEY ("uid") REFERENCES "public"."tbl_benutzer" ("uid") ON DELETE RESTRICT ON UPDATE CASCADE;';
if (!$db->db_query($qry))
echo '<strong>system.tbl_jobsqueue: '.$db->db_last_error().'</strong><br>';
else
echo '<br>Created foreign key fk_jobsqueue_benutzer_uid';
}
}
// Add new webservice type in system.tbl_webservicetyp
if ($result = @$db->db_query("SELECT 1 FROM system.tbl_webservicetyp WHERE webservicetyp_kurzbz = 'lrt';"))
{
if ($db->db_num_rows($result) == 0)
{
$qry = "INSERT INTO system.tbl_webservicetyp(webservicetyp_kurzbz, beschreibung) VALUES('lrt', 'Long Run Task');";
if (!$db->db_query($qry))
echo '<strong>system.tbl_webservicetyp '.$db->db_last_error().'</strong><br>';
else
echo ' system.tbl_webservicetyp: Added webservice type "lrt"<br>';
}
}