diff --git a/application/controllers/api/frontend/v1/ProfilUpdate.php b/application/controllers/api/frontend/v1/ProfilUpdate.php index 827654d21..4a26e5bf8 100644 --- a/application/controllers/api/frontend/v1/ProfilUpdate.php +++ b/application/controllers/api/frontend/v1/ProfilUpdate.php @@ -44,6 +44,7 @@ class ProfilUpdate extends FHCAPI_Controller 'updateProfilRequest' => self::PERM_LOGGED, 'deleteProfilRequest' => self::PERM_LOGGED, 'insertFile' => self::PERM_LOGGED, + 'updateProfilbild' => self::PERM_LOGGED, 'show' => self::PERM_LOGGED, ]); @@ -478,6 +479,106 @@ class ProfilUpdate extends FHCAPI_Controller $this->terminateWithSuccess($res); } + public function updateProfilbild() + { + + $resize = function($filename, $width, $height){ + // Hoehe und Breite neu berechnen + list($width_orig, $height_orig) = getimagesize($filename); + + if ($width && ($width_orig < $height_orig)) + { + $width = ($height / $height_orig) * $width_orig; + } + else + { + $height = ($width / $width_orig) * $height_orig; + } + + $image_p = imagecreatetruecolor($width, $height); + + $image = imagecreatefromjpeg($filename); + + //Bild nur verkleinern aber nicht vergroessern + if($width_orig>$width || $height_orig>$height) + imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); + else + $image_p = $image; + + imagejpeg($image_p, $filename, 80); + + @imagedestroy($image_p); + @imagedestroy($image); + }; + + if (!count($_FILES)) { + $this->terminateWithError("No file available for upload"); + } + + //? if replace is set it contains the profil_update_id in which the attachment_id has to be replaced + $files = $_FILES['files']; + $file_count = count($files['name']); + $count = 0; + for ($i = 0; $i < $file_count; $i++) { + $count++; + $_FILES['files']['name'] = $files['name'][$i]; + $_FILES['files']['type'] = $files['type'][$i]; + $_FILES['files']['tmp_name'] = $files['tmp_name'][$i]; + $_FILES['files']['error'] = $files['error'][$i]; + $_FILES['files']['size'] = $files['size'][$i]; + $_FILES['files']['tmp_name'] = $files['tmp_name'][$i]; + + $filename = $_FILES['files']['tmp_name']; + + $ext = substr($files['name'][$i], strrpos($files['name'][$i], '.') + 1); + if($ext!='jpg' && $ext!='jpeg'){ + $this->terminateWithError("Only jpg and jpeg files are allowed for profilbild upload"); + } + + $width = 827; + $height = 1063; + // resize + $resize($filename, $width, $height); + + + //akte + $fp = fopen($filename,'r'); + //auslesen + $content = fread($fp, filesize($filename)); + $base64_content = base64_encode($content); + $this->load->library('AkteLib'); + $aktenInsertResult = $this->aktelib->add($this->pid,'Lichtbil',"Lichtbild_".$this->pid.".jpg","image/jpg",$fp,"Lichtbild gross"); + fclose($fp); + if (isError($aktenInsertResult)) { + $this->terminateWithError(getError($aktenInsertResult)); + } + + // in person abspeichern + $resize($filename, 101, 130); + $fp = fopen($filename,'r'); + $content = fread($fp, filesize($filename)); + fclose($fp); + $base64_content = base64_encode($content); + $this->load->model('person/Person_model','PersonModel'); + $personUpdate = $this->PersonModel->update($this->pid, ["foto"=>$base64_content]); + if(isError($personUpdate)){ + $this->terminateWithError(getError($personUpdate)); + } + // update foto status + $this->load->model('person/Fotostatusperson_model','FotostatusModel'); + $fotoInsert = $this->FotostatusModel->insert(["person_id"=>$this->pid,"fotostatus_kurzbz"=>"hochgeladen","datum"=>date('Y-m-d'),"insertamum"=>date('Y-m-d H:i:s'),"insertvon"=>$this->uid,"updateamum"=>date('Y-m-d H:i:s'),"updatevon"=>$this->uid]); + if(isError($fotoInsert)){ + $this->terminateWithError(getError($fotoInsert)); + } + + } + + + $this->terminateWithSuccess(["fotoStatus"=>getData($fotoInsert),"personUpdate"=>getData($personUpdate),"akteInsert"=>getData($aktenInsertResult)]); + + + } + public function getProfilUpdateWithPermission($status = null) { // early return if no status has been passed as argument diff --git a/public/js/api/factory/profilUpdate.js b/public/js/api/factory/profilUpdate.js index 42e87ae0e..dfef399bf 100644 --- a/public/js/api/factory/profilUpdate.js +++ b/public/js/api/factory/profilUpdate.js @@ -61,6 +61,13 @@ export default { params: dms }; }, + updateProfilbild(dms) { + return { + method: 'post', + url: `/api/frontend/v1/ProfilUpdate/updateProfilbild`, + params: dms + }; + }, getProfilRequestFiles(requestID) { return { method: 'get', diff --git a/public/js/components/Cis/Profil/ProfilComponents/ProfilInformation.js b/public/js/components/Cis/Profil/ProfilComponents/ProfilInformation.js index 2881ecec1..e0ed7da5b 100644 --- a/public/js/components/Cis/Profil/ProfilComponents/ProfilInformation.js +++ b/public/js/components/Cis/Profil/ProfilComponents/ProfilInformation.js @@ -1,4 +1,5 @@ import ApiProfil from '../../../../api/factory/profil.js'; +import ImageUpload from '../../Profil/ProfilModal/EditProfilComponents/ImageUpload.js'; export default { props: { @@ -17,6 +18,9 @@ export default { default: true } }, + components:{ + ImageUpload, + }, data() { return { FotoSperre: this.data.foto_sperre, @@ -25,6 +29,9 @@ export default { emits: ["showEditProfilModal"], methods: { + showModal(){ + this.$refs.imageUpload.show(); + }, sperre_foto_function() { //TODO: refactor if (!this.data) { @@ -66,6 +73,7 @@ export default { template: /*html*/ `
{{$p.t('profilUpdate','profilUpdateInformationMessage',[titel])}}
+ + +