diff --git a/app/Controllers/Settings.php b/app/Controllers/Settings.php index e34dd252..a2230d69 100755 --- a/app/Controllers/Settings.php +++ b/app/Controllers/Settings.php @@ -1,7 +1,7 @@ setTable('settings'); $details = $model->where(['setting_id' => $id, 'isactive' => 1])->first(); $data['details'] = $details; + } + $data['business_details']=$this->business_details(); $this->render_page('setting_form', $data); } + public function business_details() + { + $model = new BusinessModel(); + $model->setTable('business'); + $business_details = $model->orderBy('business_id', 'DESC')->findAll(); + return $business_details; + } ## To Save/Update Setting Data on DB. @@ -49,26 +58,144 @@ class Settings extends BaseController helper('session'); $session_bid = get_business_id(); $session_uid = get_logged_user_id(); + + $validationRule = [ + 'usersetiing' => [ + 'label' => 'Image File', + 'rules' => [ + 'uploaded[slogo]', + 'is_image[slogo]', + 'mime_in[slogo,image/jpg,image/jpeg,image/gif,image/png,image/webp]', - $model = new SettingsModel(); - $model->setTable('settings'); - if ($this->request->is('post')) { - $requestData = $this->request->getVar(); + ], + ], + + 'favicon' => [ + 'label' => 'Favicon', + 'rules' => [ + 'uploaded[favicon]', + 'is_image[favicon]', + 'mime_in[favicon,image/ico,image/x-icon]', + ], + ], + ]; + + if (!$this->validate($validationRule)) { + // Validation failed, return to the form with errors + $data['validation_errors'] = $this->validator->getErrors(); + $this->render_page('setting_form', $data); + return; } - $requestData['business_id'] = $session_bid; - if ($requestData['setting_id']) { - #edit - $requestData['updated_by'] = $session_uid; - $requestData['isactive'] = isset($requestData['isactive']) && $requestData['isactive'] == 'on' ? 1 : 0; - $model->saveData($requestData, $requestData['setting_id']); - $alert_message = "Site Settings details successfully updated."; + $img = $this->request->getFile('slogo'); + $setting_id = $this->request->getPost('setting_id'); + $business_id = $this->request->getPost('business_id'); + + + $filePath ='public/uploads/' . $this->request->getPost('slogo'); + + + ## File Already Existing or not + + if ($img->isValid() && !$img->hasMoved()) { + $fileName = $img->getName(); + $img->move('public/uploads/', $fileName); + + + // Delete the previous image file if it exists + if ($setting_id) { + $previousFileName = $this->request->getPost('previous_sfile'); + if ($previousFileName && is_file('public/uploads/' . $previousFileName)) { + unlink('public/uploads/' . $previousFileName); + } + } } else { - #add - $requestData['created_by'] = $session_uid; - $requestData['isactive'] = 1; - $model->saveData($requestData, null); - $alert_message = "Site Settings details successfully created."; + $fileName = $this->request->getPost('previous_sfile', ''); // Use the previous filename if no new image is provided + } + $favicon = $this->request->getFile('favicon'); + if ($favicon->isValid() && !$favicon->hasMoved()) { + $faviconName = $favicon->getName(); + $favicon->move('public/uploads/', $faviconName); + + // Delete the previous favicon file if it exists + if ($setting_id) { + $previousFaviconName = $this->request->getPost('previous_favicon'); + if ($previousFaviconName && is_file('public/uploads/' . $previousFaviconName)) { + unlink('public/uploads/' . $previousFaviconName); + } + } +} else { + $faviconName = $this->request->getPost('previous_favicon', ''); // Use the previous favicon filename if no new favicon is provided +} + + $SettingsModel = new SettingsModel(); + $data = [ + + 'site_name' => $this->request->getPost('site_name'), + 'site_title' => $this->request->getPost('site_title'), + 'favicon' => $this->request->getPost('favicon'), + 'logo' => $this->request->getPost('logo'), + 'terms_service' => $this->request->getPost('terms_service'), + 'footer_about' => $this->request->getPost('footer_about'), + 'admin_email' => $this->request->getPost('admin_email'), + 'mobile'=> $this->request->getPost('mobile'), + 'copyright'=> $this->request->getPost('copyright'), + 'pagination_limit'=> $this->request->getPost('pagination_limit'), + 'site_info'=> $this->request->getPost('site_info'), + 'about_info'=> $this->request->getPost('about_info'), + 'mail_protocol'=> $this->request->getPost('mail_protocol'), + 'mail_title'=> $this->request->getPost('mail_title'), + 'mail_host'=> $this->request->getPost('mail_host'), + 'mail_port'=> $this->request->getPost('mail_port'), + 'mail_encryption'=> $this->request->getPost('mail_encryption'), + 'mail_username'=> $this->request->getPost('mail_username'), + 'mail_password'=> $this->request->getPost('mail_password'), + 'currency'=> $this->request->getPost('currency'), + 'country'=> $this->request->getPost('country'), + 'business_id'=> $this->request->getPost('business_id'), + 'logo'=>$fileName, + 'favicon'=>$faviconName + ]; + $setting_id = $this->request->getPost('setting_id'); // Get the business ID for update + + + if (empty($setting_id)) { + // It's an insert operation + $data['isactive'] = 1; + $data['created_by'] = $session_uid; + + $SettingsModel->insert($data); + // print_r($data);die; + } else { + // It's an update operation + $isactive = $this->request->getPost('isactive'); + $data['isactive'] = ($isactive == 'on') ? 1 : 0; + $data['updated_by'] = $session_uid; + $SettingsModel->update($setting_id, $data); } return redirect()->route('sitesetting_list'); } } + + +// $model = new SettingsModel(); +// $model->setTable('settings'); +// if ($this->request->is('post')) { +// $requestData = $this->request->getVar(); +// } +// $requestData['business_id'] = $session_bid; +// if ($requestData['setting_id']) { +// #edit +// $requestData['updated_by'] = $session_uid; +// $requestData['isactive'] = isset($requestData['isactive']) && $requestData['isactive'] == 'on' ? 1 : 0; +// $model->saveData($requestData, $requestData['setting_id']); +// $alert_message = "Site Settings details successfully updated."; +// } else { +// #add +// $requestData['created_by'] = $session_uid; +// $requestData['isactive'] = 1; +// $model->saveData($requestData, null); +// $alert_message = "Site Settings details successfully created."; +// } +// return redirect()->route('sitesetting_list'); +// } +// } diff --git a/app/Helpers/session_helper.php b/app/Helpers/session_helper.php index 2c73082e..123cbcba 100644 --- a/app/Helpers/session_helper.php +++ b/app/Helpers/session_helper.php @@ -18,7 +18,7 @@ if (!function_exists('get_logged_user_id')) { } } -if (!function_exists('set_logged_user')) { +if (!function_exists('set_logged_user_id')) { function set_logged_user_id($userId) { $session = \Config\Services::session(); diff --git a/app/Views/book_form.php b/app/Views/book_form.php index 981ca74f..833a9847 100644 --- a/app/Views/book_form.php +++ b/app/Views/book_form.php @@ -1,3 +1,25 @@ + + + + + + + +
@@ -10,70 +32,84 @@
">
-
+
Please provide.
-
-
+ +
Please provide.
+
+
Please provide.
-
-
+ +
Please provide.
- -
- - coverpicture -
- -
- -
- - +
+ +
+
+ + +
Please provide.
-
-
-
+ + + +
- +
-
-
-
- - -
Please provide.
- -
-
-
+
+ + +
Please provide.
+
- - + +
Please provide.
+ + + +
+ +
+
+
+
+
+
+
+
+ +
+ +
+
+
+
@@ -97,4 +133,40 @@
-
\ No newline at end of file +
+ + + + + + diff --git a/app/Views/setting_form.php b/app/Views/setting_form.php index 66c256b0..49a1f2c4 100644 --- a/app/Views/setting_form.php +++ b/app/Views/setting_form.php @@ -1,3 +1,19 @@ + + + + + + +
@@ -6,18 +22,26 @@

getFlashdata('success')): ?> -
getFlashdata('success') ?>
+
getFlashdata('success') ?>
- " method="post"> + ">
- - + +
- - + +
@@ -27,102 +51,187 @@
-
- - +
+ +
- - + +
- - + +
- - + +
- - + +
- - + +
- +
- - + +
- +
+ +
+ + Logo +
+
- +
+ +
+ + Icon +
+
- - + +
- - + +
- - + +
- - + +
- - + +
- - + +
- - + +
- - + +
- - + + +
+
+
+ + +
- - + +
- > + >

diff --git a/app/Views/setting_list.php b/app/Views/setting_list.php index 6ddece15..55fcc6dd 100644 --- a/app/Views/setting_list.php +++ b/app/Views/setting_list.php @@ -11,7 +11,7 @@
getFlashdata('success') ?>
- +
@@ -19,6 +19,8 @@ + + @@ -40,6 +42,8 @@ + +
Site NameAdmin email Mobile Number CopyrightLogoIcon Status Action