diff --git a/app/Controllers/Business.php b/app/Controllers/Business.php index 9c51d6ce..1dee7f3b 100644 --- a/app/Controllers/Business.php +++ b/app/Controllers/Business.php @@ -10,38 +10,44 @@ class Business extends BaseController ## For Business Listing public function index() { - $session = \Config\Services::session(); - $session_role = $session->get('user_role'); - $session_bid = $session->get('business_id'); + helper('session'); + if (is_session_active()) { + $session_role = get_user_role('user_role'); + $session_bid = get_business_id('business_id'); - $BusinessModel = new BusinessModel(); - $data['page_name'] = 'Buiness Listing'; - $data['businesses'] = $BusinessModel->findAll(); - $this->render_page('business_list', $data); + $BusinessModel = new BusinessModel(); + $data['page_name'] = 'Buiness Listing'; + $data['businesses'] = $BusinessModel->findAll(); + $this->render_page('business_list', $data); + } else { + // Session is not active or user is not logged in + return redirect()->to('login'); + } } ## For Business page load add and Update public function new_bussiness($id) { if ($id === '0') { - $data['page_name'] = 'Add User'; + $data['page_name'] = 'Add Business'; $data['businesses'] = []; } else if ($id !== '0') { - $data['page_name'] = 'Edit User'; + $data['page_name'] = 'Edit Business'; $model = new BusinessModel(); $model->setTable('business'); $edit_user_details = $model->where(['business_id ' => $id])->first(); - + $data['businesses'] = $edit_user_details; } - - - $this->render_page('business', $data); + $this->render_page('business_form', $data); } ## For inserting/updating details of business public function insert_business() { + helper('session'); + $session_uid = get_logged_user_id(); + // print_r($_FILES);die(); $validationRule = [ 'userfile' => [ @@ -50,21 +56,22 @@ class Business extends BaseController 'uploaded[bfile]', 'is_image[bfile]', 'mime_in[bfile,image/jpg,image/jpeg,image/gif,image/png,image/webp]', - + ], ], ]; - if (! $this->validate($validationRule)) { + if (!$this->validate($validationRule)) { $data = ['errors' => $this->validator->getErrors()]; print_r($data); return 'hello'; } $img = $this->request->getFile('bfile'); - if (! $img->hasMoved()) { - $filepath = WRITEPATH . 'uploads/' . $img->store(); - - $BusinessModel = new BusinessModel(); + 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'), @@ -73,39 +80,40 @@ class Business extends BaseController 'city' => $this->request->getPost('bcity'), 'state' => $this->request->getPost('bstate'), 'postal_code' => $this->request->getPost('bzip'), - 'business_logo'=>$this->request->getPost('bfile'), - 'isactive' => $this->request->getPost('bcheckbox') ? 1 : 0 + '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); } - - $this->index(); - } - } - public function delete_business($id) - { - $BusinessModel = new BusinessModel(); - - // Check if the business ID exists - $existingBusiness = $BusinessModel->find($id); - if (!$existingBusiness) { - // return redirect()->to(base_url('Business/index'))->with('error', 'Business not found.'); - return redirect()->route('business_list'); - } - - // Delete the business record - $BusinessModel->delete($id); - - // return redirect()->to(base_url('Business/index'))->with('success', 'Business deleted successfully.'); - return redirect()->route('business_list'); + return redirect()->route('business_list'); } } - + public function delete_business($id) + { + $BusinessModel = new BusinessModel(); + // Check if the business ID exists + $existingBusiness = $BusinessModel->find($id); + if (!$existingBusiness) { + // return redirect()->to(base_url('Business/index'))->with('error', 'Business not found.'); + return redirect()->route('business_list'); + } + + // Delete the business record + $BusinessModel->delete($id); + + // return redirect()->to(base_url('Business/index'))->with('success', 'Business deleted successfully.'); + return redirect()->route('business_list'); + } +} diff --git a/app/Controllers/Users.php b/app/Controllers/Users.php index 13f2eca4..ee1df519 100755 --- a/app/Controllers/Users.php +++ b/app/Controllers/Users.php @@ -47,7 +47,7 @@ class Users extends BaseController public function user_synchronization() { helper('session'); - $session_bid = get_business_id('business_id'); + $session_bid = get_business_id(); $session_uid = get_logged_user_id(); $model = new UsersModel(); $model->setTable('users'); diff --git a/app/Views/book_form.php b/app/Views/book_form.php index b976378c..286aa797 100644 --- a/app/Views/book_form.php +++ b/app/Views/book_form.php @@ -26,33 +26,39 @@
| Business Name | + +Business Name | Mobile Number | Address | @@ -28,40 +25,33 @@Zip | File | Action | - -||
|---|---|---|---|---|---|---|---|---|
| = $business['title']; ?> | -= $business['email']; ?> | -= $business['mobile_no']; ?> | -= $business['address'] ; ?> | -= $business['city']; ?> | -= $business['state']; ?> | -= $business['postal_code']; ?> | -=$business['business_logo'];?> | -- " class="edit-button"> - - - " class="delete-button"> | -
| = $business['title']; ?> | += $business['email']; ?> | += $business['mobile_no']; ?> | += $business['address']; ?> | += $business['city']; ?> | += $business['state']; ?> | += $business['postal_code']; ?> | += $business['business_logo']; ?> | ++ " class="edit-button"> + " class="delete-button"> + | +