From 000c4520e2edecde3125854d01e4f2ea755b1e4e Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Thu, 24 Aug 2023 13:16:18 +0530 Subject: [PATCH] Buiness Fixes : ps --- app/Controllers/Business.php | 72 +++++++++++++++++++++--------------- app/Views/business_form.php | 44 +++++++++++----------- 2 files changed, 64 insertions(+), 52 deletions(-) diff --git a/app/Controllers/Business.php b/app/Controllers/Business.php index 1dee7f3b..dced3b16 100644 --- a/app/Controllers/Business.php +++ b/app/Controllers/Business.php @@ -60,44 +60,58 @@ class Business extends BaseController ], ], ]; - if (!$this->validate($validationRule)) { + + if (!$this->validate($validationRule) && $this->request->getPost('bfile') === '') { $data = ['errors' => $this->validator->getErrors()]; print_r($data); return 'hello'; } $img = $this->request->getFile('bfile'); + $filePath = WRITEPATH . 'uploads/' . $this->request->getPost('bfile'); - if (!$img->hasMoved()) { - $filepath = WRITEPATH . 'uploads/Business_files' . $img->store(); - $fileName = $img->getName(); - - $BusinessModel = new BusinessModel(); - $data = [ - 'title' => $this->request->getPost('bname'), - 'email' => $this->request->getPost('bmail'), - 'mobile_no' => $this->request->getPost('bmobile'), - 'address' => $this->request->getPost('baddress'), - 'city' => $this->request->getPost('bcity'), - 'state' => $this->request->getPost('bstate'), - 'postal_code' => $this->request->getPost('bzip'), - 'business_logo' => $fileName - ]; - $business_id = $this->request->getPost('business_id'); // Get the business ID for update - - if (empty($business_id)) { - // It's an insert operation - $data['isactive'] = 1; - $data['created_by'] = $session_uid; - $BusinessModel->insert($data); + ## File Already Existing or not + if (!is_file($filePath)) { + ## echo 'File not Existing' + if (!$img->hasMoved()) { + ## echo 'File not Existing and Not Moved' + // $filepath = WRITEPATH . 'uploads/Business_files' . $img->store(); + // $fileName = $img->getName(); + $fileName = $img->getName(); + $img->move(WRITEPATH . 'uploads', $fileName); } else { - // It's an update operation - $isactive = $this->request->getPost('bcheckbox'); - $data['isactive'] = ($isactive == 'on') ? 1 : 0; - $data['updated_by'] = $session_uid; - $BusinessModel->update($business_id, $data); + ## display the error file not uploaded like that... } - return redirect()->route('business_list'); + } else { + ## echo 'File Existing' + $fileName = $this->request->getPost('bfile'); } + + $BusinessModel = new BusinessModel(); + $data = [ + 'title' => $this->request->getPost('bname'), + 'email' => $this->request->getPost('bmail'), + 'mobile_no' => $this->request->getPost('bmobile'), + 'address' => $this->request->getPost('baddress'), + 'city' => $this->request->getPost('bcity'), + 'state' => $this->request->getPost('bstate'), + 'postal_code' => $this->request->getPost('bzip'), + 'business_logo' => $fileName + ]; + $business_id = $this->request->getPost('business_id'); // Get the business ID for update + + if (empty($business_id)) { + // It's an insert operation + $data['isactive'] = 1; + $data['created_by'] = $session_uid; + $BusinessModel->insert($data); + } else { + // It's an update operation + $isactive = $this->request->getPost('bcheckbox'); + $data['isactive'] = ($isactive == 'on') ? 1 : 0; + $data['updated_by'] = $session_uid; + $BusinessModel->update($business_id, $data); + } + return redirect()->route('business_list'); } public function delete_business($id) { diff --git a/app/Views/business_form.php b/app/Views/business_form.php index 2bdbbc52..41ba31e7 100644 --- a/app/Views/business_form.php +++ b/app/Views/business_form.php @@ -5,7 +5,7 @@

-
+
@@ -14,22 +14,22 @@
-
+
- +
- +
- +
@@ -43,23 +43,28 @@
- +
- - + + + + + + +
- -
- > - -
-
+ +
+ > + +
+
-
+
- - - - - - - - \ No newline at end of file + \ No newline at end of file