diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index eae64452f..f2afcff1b 100755 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -27,8 +27,12 @@ class Profil extends Auth_Controller 'insertFile' => ['student/anrechnung_beantragen:r', 'user:r'], 'getProfilRequestFiles' => ['student/anrechnung_beantragen:r', 'user:r'], 'deleteOldVersionFiles' => ['student/anrechnung_beantragen:r', 'user:r'], + 'test' => ['student/anrechnung_beantragen:r', 'user:r'], ]); + + + $this->load->model('ressource/mitarbeiter_model', 'MitarbeiterModel'); $this->load->model('crm/Student_model', 'StudentModel'); $this->load->model('person/Benutzer_model', 'BenutzerModel'); @@ -40,13 +44,16 @@ class Profil extends Auth_Controller $this->load->model('person/Kontakt_model', 'KontaktModel'); $this->load->model('person/Profil_change_model', 'ProfilChangeModel'); $this->load->model('content/DmsVersion_model', 'DmsVersionModel'); - + $this->load->model('DmsVersion_model','DmsVersionModel'); + + $this->load->library('DmsLib'); //? put the uid and pid inside the controller to reuse in controller $this->uid = getAuthUID(); $this->pid = getAuthPersonID(); + } // ----------------------------------------------------------------------------------------------------------------- @@ -84,14 +91,15 @@ class Profil extends Auth_Controller echo json_encode([]); return; } - $res=[]; + - $this->load->library('DmsLib'); - $this->load->model('DmsVersion_model','DmsVersionModel'); + $files = $_FILES['files']; $file_count = count($files['name']); + $res=[]; + for ($i = 0; $i < $file_count; $i++) { $_FILES['files']['name'] = $files['name'][$i]; $_FILES['files']['type'] = $files['type'][$i]; @@ -100,7 +108,7 @@ class Profil extends Auth_Controller $_FILES['files']['size'] = $files['size'][$i]; $dms = [ - "kategorie_kurzbz"=>"dokumente", + "kategorie_kurzbz"=>"profil_aenderung", "version"=>0, "name"=>$_FILES['files']['name'], "mimetype"=>$_FILES['files']['type'], @@ -118,16 +126,37 @@ class Profil extends Auth_Controller public function deleteOldVersionFiles(){ - //? table dms_version has a composite primary key with dms_id and dms_version $file_array = json_decode($this->input->raw_input_stream); + if(!isset($file_array) || !sizeof($file_array)){ + return; + } + $res =[]; - foreach($file_array as $value){ + foreach($file_array as $id){ + //? delete all the different versions of the dms_file - array_push($res, $this->DmsVersionModel->delete([$value,0])); + $zwischen_res = $this->DmsVersionModel->loadWhere(["dms_id"=>$id]); + $zwischen_res = hasData($zwischen_res) ? getData($zwischen_res) : null; + if(isset($zwischen_res)){ + $zwischen_res = array_map(function($item){ return $item->version;},$zwischen_res); + foreach($zwischen_res as $version){ + array_push($res, $this->DmsVersionModel->delete([$id,$version])); + } + }else{ + echo json_encode(error("No version of the file has been found")); + } } echo json_encode($res); } + public function test(){ + + // Loads permission lib + $this->load->library('PermissionLib'); + var_dump($this->permissionlib->getOE_isEntitledFor()); + } + + public function selectProfilRequest(){ $_GET = json_decode($this->input->raw_input_stream, true); @@ -529,9 +558,8 @@ class Profil extends Auth_Controller if ( - isSuccess($adresse_res = $this->AdresseModel->addSelect(["adresse_id","strasse", "tbl_adressentyp.bezeichnung as typ", "plz", "ort"])) && + isSuccess($adresse_res = $this->AdresseModel->addSelect(["adresse_id","strasse", "tbl_adressentyp.bezeichnung as typ", "plz", "ort","zustelladresse"])) && isSuccess($adresse_res = $this->AdresseModel->addOrder("zustelladresse", "DESC")) && - isSuccess($adresse_res = $this->AdresseModel->addOrder("sort")) && isSuccess($adresse_res = $this->AdresseModel->addJoin("tbl_adressentyp", "typ=adressentyp_kurzbz")) ) { $adresse_res = $this->AdresseModel->loadWhere(array("person_id" => $this->pid)); diff --git a/application/controllers/Cis/ProfilUpdate.php b/application/controllers/Cis/ProfilUpdate.php index c075221b0..ac1815d6e 100755 --- a/application/controllers/Cis/ProfilUpdate.php +++ b/application/controllers/Cis/ProfilUpdate.php @@ -37,6 +37,7 @@ class ProfilUpdate extends Auth_Controller $this->load->library('DmsLib'); //? downloads the file using the dms_id $file = $this->dmslib->download($dms_id); + $file = hasData($file) ? getData($file) : null; //? returns the downloaded file to the user $res = $this->outputFile($file); @@ -148,8 +149,9 @@ class ProfilUpdate extends Auth_Controller if(array_key_exists('add',$requested_change) && $requested_change['add']){ //? removes add flag unset($requested_change['add']); - //? fields like insertvon are not filled when inserting new row $requested_change['person_id'] = $personID; + $requested_change['insertamum'] = "NOW()"; + $requested_change['insertvon'] = getAuthUID(); $insertID = $this->KontaktModel->insert($requested_change); } @@ -159,6 +161,8 @@ class ProfilUpdate extends Auth_Controller } //! UPDATE else{ + $requested_change['updateamum']="NOW()"; + $requested_change['updatemvon']=getAuthUID(); $this->KontaktModel->update($kontakt_id,$requested_change); } return isset($insertID) ? $insertID : null; @@ -181,7 +185,8 @@ class ProfilUpdate extends Auth_Controller if(array_key_exists('add',$requested_change) && $requested_change['add']){ //? removes add flag unset($requested_change['add']); - //? fields like insertvon are not filled when inserting new row + $requested_change['insertamum']="NOW()"; + $requested_change['insertvon']=getAuthUID(); $requested_change['person_id'] = $personID; //TODO: zustelladresse, heimatadresse, rechnungsadresse und nation werden nicht beachtet $insertID = $this->AdresseModel->insert($requested_change); @@ -192,6 +197,8 @@ class ProfilUpdate extends Auth_Controller } //! UPDATE else{ + $requested_change['updateamum'] = "NOW()"; + $requested_change['updatevon'] = getAuthUID(); $this->AdresseModel->update($adresse_id,$requested_change); } return isset($insertID)? $insertID : null; diff --git a/public/js/components/Cis/Profil/EditProfil.js b/public/js/components/Cis/Profil/EditProfil.js index 8f5a2d824..2963f7371 100755 --- a/public/js/components/Cis/Profil/EditProfil.js +++ b/public/js/components/Cis/Profil/EditProfil.js @@ -38,16 +38,12 @@ export default { methods: { async submitProfilChange() { - //? when the update contains a file upload - - //TODO: check if the updated value is different from the original value before submitting the request if (this.topic && this.profilUpdate) { if (this.profilUpdate.files) { const fileIDs = await this.uploadFiles(this.profilUpdate.files); if (fileIDs) { this.profilUpdate.files = fileIDs; - console.log("here is the update", this.profilUpdate); } } //? inserts new row in public.tbl_cis_profil_update @@ -98,8 +94,6 @@ export default { let filesToKeep = []; let filesToDelete = []; - console.log(existingFiles); - console.log(files); existingFiles.forEach((file) => { Array.from(files).some((f) => f.name === file.name) ? filesToKeep.push(file) @@ -107,11 +101,13 @@ export default { }); //? only keeps the newest version of the documents and deletes the old versions in the database - Vue.$fhcapi.UserData.deleteOldVersionFiles( - filesToDelete - ).then((res) => { - console.log(res); - }); + if(filesToDelete.length > 0) { + Vue.$fhcapi.UserData.deleteOldVersionFiles( + filesToDelete + ).then((res) => { + console.log(res); + }); + } updatedFiles = [...filesToKeep]; @@ -122,7 +118,7 @@ export default { if (files[i].type !== "application/x.fhc-dms+json") formData.append("files[]", files[i]); } - + if(Array.from(formData).length > 0){ await Vue.$fhcapi.UserData.insertFile(formData) .then((res) => { /* returns file information as @@ -130,7 +126,6 @@ export default { updatedFiles = updatedFiles.concat( res.data?.map((file) => { - console.log("here are the files:",file); return { dms_id: file.dms_id, name: file.client_name}; }) ); @@ -138,6 +133,7 @@ export default { .catch((err) => { console.log(err); }); + } return updatedFiles; }, @@ -163,6 +159,7 @@ export default {