diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 11f6eb98..6aaa781f 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -44,12 +44,10 @@ $routes->get("user_list/", "Users::index"); $routes->get("user_page/(:any)", "Users::user_page/$1"); $routes->post("user_synchronization", "Users::user_synchronization"); -$routes->get("user_confirmation", "Users::user_confirmation"); - # Books Routes $routes->get("book_list/", "Books::index"); $routes->get("book_page/(:any)", "Books::book_page/$1"); -$routes->post("book_synchronization", "Books::book_synchronization"); +$routes->post("insert_books", "Books::insert_books"); # Site-Setting Routes $routes->get("sitesetting_list/", "Settings::index"); @@ -63,6 +61,7 @@ $routes->post("insert_business/", "Business::insert_business"); $routes->get("delete_business/(:any)", "Business::delete_business/$1"); + $routes->get("subscribers_list/", "Home::subscribers_list"); $routes->get("add_subscribers/", "Home::add_subscribers"); $routes->get("edit_subscribers/", "Home::edit_subscribers"); @@ -71,6 +70,7 @@ $routes->get("edit_subscribers/", "Home::edit_subscribers"); $routes->get("customer_list/", "Customer::index"); $routes->get("new_customer/(:any)", "Customer::new_customer/$1"); $routes->post("insert_customer/", "Customer::insert_customer"); +$routes->get("delete_customer/(:any)", "Customer::delete_customer/$1"); #scheme routes $routes->get("scheme_list/", "Scheme::index"); $routes->get("new_scheme/(:any)", "Scheme::new_scheme/$1"); diff --git a/app/Controllers/Authentication.php b/app/Controllers/Authentication.php index 05a29b1a..b284188f 100755 --- a/app/Controllers/Authentication.php +++ b/app/Controllers/Authentication.php @@ -32,6 +32,7 @@ class Authentication extends BaseController $password = $this->request->getPost('password'); $user = $auth_model->where('email', $username)->first(); + // print_r($user);die; if (is_null($user)) { return redirect()->back()->with('error', 'Invalid username or password.'); // return redirect()->back()->withInput()->with('error', 'Invalid username or password.'); diff --git a/app/Controllers/Books.php b/app/Controllers/Books.php index f29614e3..b7069f77 100755 --- a/app/Controllers/Books.php +++ b/app/Controllers/Books.php @@ -33,43 +33,99 @@ class Books extends BaseController ## To Load Book Add/Update page public function book_page($id) { + helper('session'); + $data['session_bid'] = get_business_id(); if ($id === '0') { $data['page_name'] = 'Add Book'; $data['details'] = []; } else if ($id !== '0') { $data['page_name'] = 'Edit Book'; - $model = new BooksModel(); - $model->setTable('books'); - $details = $model->where(['book_id' => $id, 'isactive' => 1])->first(); + $model = new UsersModel(); + $model->setTable('users'); + $details = $model->where(['user_id' => $id, 'isactive' => 1])->first(); $data['details'] = $details; } - $this->render_page('book_form', $data); + $this->render_page('user_form', $data); } ## To Save/Update Book Data on DB. - public function book_synchronization() + public function insert_books() { helper('session'); - $model = new BooksModel(); - $model->setTable('books'); - if ($this->request->is('post')) { - $requestData = $this->request->getVar(); + $session_uid = get_logged_user_id(); + $session_bid = get_business_id(); + + // print_r($_FILES);die(); + $validationRule = [ + 'userfile' => [ + 'label' => 'Image File', + 'rules' => [ + 'uploaded[coverpicture]', + 'is_image[coverpicture]', + 'mime_in[coverpicture,image/jpg,image/jpeg,image/gif,image/png,image/webp]', + + ], + ], + ]; + + if (!$this->validate($validationRule) && $this->request->getPost('coverpicture') === '') { + $data = ['errors' => $this->validator->getErrors()]; + print_r($data); + return 'hello'; } - $requestData['business_id'] = get_business_id('business_id'); - if ($requestData['book_id']) { - #edit - $requestData['updated_by'] = get_logged_user_id(); - $requestData['isactive'] = isset($requestData['isactive']) && $requestData['isactive'] == 'on' ? 1 : 0; - $model->saveData($requestData, $requestData['book_id']); - $alert_message = "Book details successfully updated."; + $img = $this->request->getFile('coverpicture'); + $book_id = $this->request->getPost('book_id'); + $business_id = $this->request->getPost('business_id'); + $filePath ='public/uploads/' . $this->request->getPost('coverpicture'); + + ## 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 ($book_id) { + $previousFileName = $this->request->getPost('previous_file'); + if ($previousFileName && is_file('public/uploads/' . $previousFileName)) { + link('public/uploads/' . $previousFileName); + } + } } else { - #add - $requestData['created_by'] = get_logged_user_id(); - $requestData['isactive'] = 1; - $model->saveData($requestData, null); - $alert_message = "Book details successfully created."; + $fileName = $this->request->getPost('previous_file', ''); // Use the previous filename if no new image is provided } - return redirect()->route('book_list')->with('success', $alert_message); + + + $BooksModel = new BooksModel(); + $data = [ + + 'title' => $this->request->getPost('title'), + 'cover_picture' => $fileName, + 'publication_date' => $this->request->getPost('publication_date'), + 'publisher' => $this->request->getPost('publisher'), + 'genre' => $this->request->getPost('genre'), + 'language' => $this->request->getPost('language'), + 'description' => $this->request->getPost('description'), + 'page_count'=> $this->request->getPost('page_count'), + 'price'=> $this->request->getPost('price'), + 'business_id'=>$business_id + ]; + $book_id = $this->request->getPost('book_id'); // Get the business ID for update + + if (empty($book_id)) { + // It's an insert operation + $data['isactive'] = 1; + $data['created_by'] = $session_uid; + //print_r($data);die; + $BooksModel->insert($data); + } else { + // It's an update operation + $isactive = $this->request->getPost('bcheckbox'); + $data['isactive'] = ($isactive == 'on') ? 1 : 0; + $data['updated_by'] = $session_uid; + $BooksModel->update($book_id, $data); + } + return redirect()->route('book_list'); } -} +} \ No newline at end of file diff --git a/app/Controllers/Business.php b/app/Controllers/Business.php index 1f0332a2..c0edb68e 100644 --- a/app/Controllers/Business.php +++ b/app/Controllers/Business.php @@ -50,7 +50,7 @@ class Business extends BaseController // print_r($_FILES);die(); $validationRule = [ - 'userfile' => [ + 'user' => [ 'label' => 'Image File', 'rules' => [ 'uploaded[bfile]', @@ -67,24 +67,26 @@ class Business extends BaseController return 'hello'; } $img = $this->request->getFile('bfile'); - $filePath = WRITEPATH . 'uploads/' . $this->request->getPost('bfile'); + $business_id = $this->request->getPost('business_id'); + $filePath ='public/uploads/' . $this->request->getPost('bfile'); ## 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 { - ## display the error file not uploaded like that... + if ($img->isValid() && !$img->hasMoved()) { + $fileName = $img->getName(); + $img->move('public/uploads/', $fileName); + + + // Delete the previous image file if it exists + if ($business_id) { + $previousFileName = $this->request->getPost('previous_bfile'); + if ($previousFileName && is_file('public/uploads/' . $previousFileName)) { + link('public/uploads/' . $previousFileName); + } } } else { - ## echo 'File Existing' - $fileName = $this->request->getPost('bfile'); + $fileName = $this->request->getPost('previous_bfile', ''); // Use the previous filename if no new image is provided } + $BusinessModel = new BusinessModel(); $data = [ @@ -113,6 +115,7 @@ class Business extends BaseController } return redirect()->route('business_list'); } + public function delete_business($id) { $BusinessModel = new BusinessModel(); @@ -124,8 +127,13 @@ class Business extends BaseController return redirect()->route('business_list'); } + helper('session'); + $session_uid = get_logged_user_id(); // Delete the business record - $BusinessModel->delete($id); + $data['isactive'] = 0; + $data['updated_by'] = $session_uid; + $BusinessModel->update($id, $data); + //$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/Customer.php b/app/Controllers/Customer.php index 8a5ba75d..102513c7 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -100,7 +100,28 @@ class Customer extends BaseController return redirect()->route('customer_list'); } } + public function delete_customer($id) + { + $CustomerModel =new CustomerModel(); + + + $existingCustomer = $CustomerModel->find($id); + if (!$existingCustomer) { + + return redirect()->route('customer_list'); + } + + helper('session'); + $session_uid = get_logged_user_id(); + + $data['isactive'] = 0; + $data['updated_by'] = $session_uid; + $CustomerModel->update($id, $data); + print_r($data); die(); + return redirect()->route('customer_list'); + } +} + -} \ No newline at end of file diff --git a/app/Controllers/Users.php b/app/Controllers/Users.php index 0704b434..5c2895c1 100755 --- a/app/Controllers/Users.php +++ b/app/Controllers/Users.php @@ -65,76 +65,84 @@ class Users extends BaseController public function user_synchronization() { helper('session'); - $session_bid = get_business_id(); $session_uid = get_logged_user_id(); + $session_bid = get_business_id(); + // print_r($_FILES);die(); $validationRule = [ - 'profile_picture' => [ + 'userfile' => [ 'label' => 'Image File', 'rules' => [ 'uploaded[profile_picture]', 'is_image[profile_picture]', 'mime_in[profile_picture,image/jpg,image/jpeg,image/gif,image/png,image/webp]', - 'max_size[profile_picture,100]', - 'max_dims[profile_picture,1024,768]', + ], ], ]; - if (! $this->validate($validationRule)) { - $data['success'] = ''; - $data['errors'] = $this->validator->getErrors(); + if (!$this->validate($validationRule) && $this->request->getPost('profile_picture') === '') { + $data = ['errors' => $this->validator->getErrors()]; + print_r($data); + return 'hello'; } - $img = $this->request->getFile('profile_picture'); - $filePath = WRITEPATH . 'uploads/' . $this->request->getPost('profile_picture'); + $user_id = $this->request->getPost('user_id'); + $business_id = $this->request->getPost('business_id'); + $filePath ='public/uploads/' . $this->request->getPost('profile_picture'); ## File Already Existing or not - if (!is_file($filePath)) { - if (! $img->hasMoved()) { - // $filepath = WRITEPATH . 'uploads/' . $img->store(); - // $data['uploaded_fileinfo'] = new File($filepath); - $fileName = $img->getName(); - $img->move(WRITEPATH . 'uploads', $fileName); - $data['success'] = 'User Profile Uploaded'; - $data['errors'] = ''; - }else{ - $data['success'] = ''; - $data['errors'] = 'The file has already been moved.'; + if ($img->isValid() && !$img->hasMoved()) { + $fileName = $img->getName(); + $img->move('public/uploads/', $fileName); + + + // Delete the previous image file if it exists + if ($user_id) { + $previousFileName = $this->request->getPost('previous_file'); + if ($previousFileName && is_file('public/uploads/' . $previousFileName)) { + link('public/uploads/' . $previousFileName); + } } - } - - $model = new UsersModel(); - $model->setTable('users'); - if ($this->request->is('post')) { - $requestData = $this->request->getVar(); - } - $requestData['business_id'] = $session_bid; - if ($requestData['user_id']) { - #edit - $requestData['updated_by'] = $session_uid; - $requestData['isactive'] = isset($requestData['isactive']) && $requestData['isactive'] == 'on' ? 1 : 0; - unset($requestData['password']); - $model->saveData($requestData, $requestData['user_id']); - $data['success'] = 'User successfully updated.'; - $data['errors'] = ''; - $alert_message = "User successfully updated."; } else { - #add - $hash_password = password_hash($requestData['password'], PASSWORD_DEFAULT); - $requestData['password'] = $hash_password; - $requestData['created_by'] = $session_uid; - $requestData['isactive'] = 1; - $model->saveData($requestData, null); - $data['success'] = 'User successfully created.'; - $data['errors'] = ''; - $alert_message = "User successfully created."; + $fileName = $this->request->getPost('previous_file', ''); // Use the previous filename if no new image is provided + } + + + $UsersModel = new UsersModel(); + $data = [ + + 'user_name' => $this->request->getPost('user_name'), + 'profile_picture' => $fileName, + 'city' => $this->request->getPost('city'), + 'state' => $this->request->getPost('state'), + 'postal_code' => $this->request->getPost('postal_code'), + 'country' => $this->request->getPost('country'), + 'role' => $this->request->getPost('role'), + 'first_name' => $this->request->getPost('first_name'), + 'last_name' => $this->request->getPost('last_name'), + 'password' => $this->request->getPost('password'), + 'mobile_no' => $this->request->getPost('mobile_no'), + 'date_of_birth' => $this->request->getPost('date_of_birth'), + 'address'=> $this->request->getPost('address'), + 'gender'=> $this->request->getPost('gender'), + 'business_id'=>$business_id + ]; + $user_id = $this->request->getPost('user_id'); // Get the business ID for update + + if (empty($user_id)) { + // It's an insert operation + $data['isactive'] = 1; + $data['created_by'] = $session_uid; + //print_r($data);die; + $UsersModel->insert($data); + } else { + // It's an update operation + $isactive = $this->request->getPost('bcheckbox'); + $data['isactive'] = ($isactive == 'on') ? 1 : 0; + $data['updated_by'] = $session_uid; + $BooksModel->update($book_id, $data); } - // $data['page_name'] = 'User Confirmation'; - // if(!empty($data['success'])){ - // $this->render_page('user_confirmation', $data); - // }else{ return redirect()->route('user_list'); - // } } -} +} \ No newline at end of file diff --git a/app/Models/AuthenticationModel.php b/app/Models/AuthenticationModel.php index a810e91f..2e481bda 100644 --- a/app/Models/AuthenticationModel.php +++ b/app/Models/AuthenticationModel.php @@ -5,7 +5,7 @@ class AuthenticationModel extends Model { protected $table = 'users'; protected $primaryKey = 'user_id'; - protected $allowedFields = ['user_id','user_name','email','first_name','last_name','password','mobile_no','date_of_birth','address','gender','profile_picture','city','state','postal_code','country','role','isactive']; + protected $allowedFields = ['user_id','user_name','email','first_name','last_name','password','mobile_no','date_of_birth','address','gender','profile_picture','city','state','postal_code','country','role','isactive','business_id']; public function getheringDetailsForHeader($user_id) { diff --git a/app/Views/book_form.php b/app/Views/book_form.php index 286aa797..ee73befd 100644 --- a/app/Views/book_form.php +++ b/app/Views/book_form.php @@ -7,7 +7,7 @@ getFlashdata('success')): ?>