From c00017d36eb69d3758dc986f00b84e97a00eadf9 Mon Sep 17 00:00:00 2001 From: Monique Date: Mon, 7 Nov 2022 15:04:41 +0100 Subject: [PATCH] insertschooldetails als ze nog niet bestaan --- application/controllers/monpas/Compactsop.php | 31 +++++++++++++------ application/core/MY_Controller.php | 2 +- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/application/controllers/monpas/Compactsop.php b/application/controllers/monpas/Compactsop.php index 4070fca..3b14272 100644 --- a/application/controllers/monpas/Compactsop.php +++ b/application/controllers/monpas/Compactsop.php @@ -160,22 +160,35 @@ class Compactsop extends MY_Controller{ public function uploadLogo($schoolID) { - $savePath = MYROOTPATH.'public/images/logos/'; + $savePath = MYROOTPATH . 'public/images/logos/'; $this->load->helper('string'); $pathParts = pathinfo($_FILES['image_file']['name']); $extension = $pathParts['extension']; - $filename = random_string('alnum', 15).'.'.$extension; + $filename = random_string('alnum', 15) . '.' . $extension; $source = $_FILES['image_file']['tmp_name']; - $target = $savePath.$filename; + $target = $savePath . $filename; - rename($source, $target ); + rename($source, $target); chmod($target, '0777'); - //TODO: unlink eventueel oud logo - $logo = $this->Schooldetails_model->getLogo($schoolID); - $padNaam = $savePath.$logo; - unlink($padNaam); - $this->Schooldetails_model->update_record_where(['logo'=>$filename], ['organisatie_id' =>$schoolID]); + + $details = $this->Schooldetails_model->get_records_where(['organisatie_id' => $schoolID]); + if ($details) { + $logo = $details['logo']; + if ($logo) { + $padNaam = $savePath . $logo; + unlink($padNaam); + } + $this->Schooldetails_model->update_record_where(['logo' => $filename], ['organisatie_id' => $schoolID]); + } else { + + $org = $this->Organisaties_model->get_record_by_id($schoolID); + $this->Schooldetails_model->insert_record([ + 'logo' => $filename, + 'organisatie_id' => $schoolID, + 'plaats' => $org->plaats ? $org->plaats : '' + ]); + } } function getLogo(){ diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 8d8a908..338162b 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -79,7 +79,7 @@ class MY_Controller extends CI_Controller{ // public $version = '1.18.05';// fout schoolgegevens compactsop // public $version = '1.18.08';// kleurenfout // public $version = '1.18.09';// zoek gebruikers sneller - public $version = '1.18.12';// compactsops maken van valtonderorgs + public $version = '1.18.13';// compactsops maken van valtonderorgs