diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 22cb5f00..986dc906 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -55,7 +55,6 @@ $routes->post("add_advertise_image", "AppContentManagementController::add_advert $routes->post('remove_advertise_image', 'AppContentManagementController::remove_advertise_image'); $routes->get("add_image_index", "AppContentManagementController::add_image_index"); $routes->get("getAdvertiseImage/(:any)", "AppContentManagementController::getAdvertiseImage/$1"); -$routes->get("frontend_content", "AppContentManagementController::frontend_content"); $routes->get('showAdvertiseImage/(:any)', 'AppContentManagementController::showAdvertiseImage/$1'); @@ -794,7 +793,8 @@ $routes->get("ticketHistoryList", "ThzController::ticketHistoryList"); // General FAQ $routes->match(['get','post','delete'], 'FAQ', 'AppContentManagementController::FAQ'); - +$routes->match(['get','post','delete'], 'frontend_content', 'AppContentManagementController::frontend_content'); +$routes->get("getFEContent", "EmployeeRestController::getFEContent"); //for testing $routes->group('test', function($routes) { diff --git a/app/Controllers/AppContentManagementController.php b/app/Controllers/AppContentManagementController.php index a85d1bd6..0dc36282 100755 --- a/app/Controllers/AppContentManagementController.php +++ b/app/Controllers/AppContentManagementController.php @@ -136,61 +136,90 @@ class AppContentManagementController extends AdminController - // public function getAdvertiseImage($image_id){ - // $image_data = $this->addImgModel->select('name')->where(['id' => $image_id])->first(); - // if($image_data){ - // return $image_data['name']; - // }else{ - // return ; - // } - // } + public function frontend_content() + { + + $method = $this->request->getMethod(); + + if ($this->request->getMethod() === 'post') { + $id = $this->request->getPost('fe_id'); + $data = $this->request->getPost(); + unset($data['fe_id']); - // Front End Content Area - public function frontend_content(){ + foreach ($data as $k => $v) { + if ($v === '' || $v === null) {unset($data[$k]);} + } + + // INSERT / UPDATE + if (empty($id)) { + $status = $this->feContentModel->insert($data); + $text = "Created"; + } else { + $status = $this->feContentModel->update($id, $data); + $text = "Updated"; + } - $data['test'] = $this->feContentModel->findAll(); - $headerData['tab_name'] = 'Front-End Content'; - $headerData['page_name'] = 'Front-End Content'; + return $this->respond([ + 'status' => $status ? true : false, + 'message' => "Frontend Content $text " . ($status ? 'successfully' : 'failed'), + 'code' => $status ? 200 : 400, + 'data' => $data, + ] , $status ? 200 : 400 ); + } + elseif ($method === 'get') { - echo view('layout/header', $headerData); - echo view('frontend_content_list', $data); - echo view('layout/footer'); + $id = $this->request->getGet('fe_id') ?? null; + + if (!empty($id)) { + + $data['fe_list'] = $this->feContentModel->where('id', $id)->orderBy('id', 'DESC')->findAll(); + + if (!empty($data)) { + return $this->respond(['status' => true, 'code' => 200, 'data' => $data], 200); + } else { + return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found'], 200); + } + } + + $data['fe_list'] = $this->feContentModel->orderBy('id', 'DESC')->findAll(); + + return $this->loadLayout('frontend_content_list', ['data' => $data,'tab_name' => 'Front-End Content','page_name' => 'Front-End Content']); + + } elseif ($method === 'delete') { + + // $input = $this->request->getRawInput(); + $id = $this->request->getGet('fe_id'); // ✅ THIS + $id = $id ?? null; + + if (empty($id)) { + return $this->respond([ + 'status' => false, + 'code' => 404, + 'message' => 'No ID provided for deletion' + ], 200); + } + + $update_status = $this->feContentModel->where('id', $id)->set(['is_active' => 0])->update(); + + if ($update_status) { + return $this->respond([ + 'status' => true, + 'code' => 200, + 'message' => 'Data removed successfully', + 'fe_id' => $id + ], 200); + } else { + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'Failed to remove data', + 'fe_id' => $id + ], 200); + } + } } - - - // - // public function FAQ() - // { - - // $data['tab_name'] = "FAQ's"; - // $data['page_name'] = "FAQ's"; - // return $this->loadLayout('faq_list', $data); - - // $returnType = strtolower($this->request->getGet('return_type') ?? 'api'); - - // $data = $this->request->getGet(); - - // $faq_list = $this->faqModel->select('*')->where('is_active', 1)->orderBy('id', 'desc')->findAll(); - - // if ($returnType === 'api') { - // if (empty($faq_list)) { - // $this->myLogger->logme('error', 'empty tickets in ticket list: ' . json_encode($faq)); - // return $this->response->setJSON([ 'status' => 'error','message' => 'No Details found'])->setStatusCode(404); - // } - // } else { - // $data['tab_name'] = "FAQ's"; - // $data['page_name'] = "FAQ's"; - // return $this->loadLayout('faq_list', $data); - // } - - // return $this->response->setJSON([ - // 'status' => 'success', - // 'data' => [], - // ])->setStatusCode(200); - // } - public function FAQ() diff --git a/app/Models/FAQModel.php b/app/Models/FAQModel.php index aa7ca44f..7fe5dd48 100644 --- a/app/Models/FAQModel.php +++ b/app/Models/FAQModel.php @@ -34,9 +34,7 @@ class FAQModel extends Model protected function checkAndADDCreatedByValue(array $data) { - // Check if 'updated_by' value is null or empty if (empty($data['data']['created_by'])) { - // Set 'updated_by' value to the current session user ID $data['data']['created_by'] = get_session_userid(); } @@ -45,12 +43,13 @@ class FAQModel extends Model protected function checkAndUpdateUpdatedByValue(array $data) { - // Check if 'updated_by' value is null or empty if (empty($data['data']['updated_by'])) { - // Set 'updated_by' value to the current session user ID $data['data']['updated_by'] = get_session_userid(); } - + + $data['data']['updated_on'] = date('Y-m-d H:i:s'); + return $data; } + } \ No newline at end of file diff --git a/app/Models/FEContentModel.php b/app/Models/FEContentModel.php index c1b572d3..fa6a4764 100755 --- a/app/Models/FEContentModel.php +++ b/app/Models/FEContentModel.php @@ -19,6 +19,25 @@ class FEContentModel extends Model "is_active", ]; + protected $beforeInsert = ["checkAndADDCreatedByValue"]; + protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"]; + + protected function checkAndADDCreatedByValue(array $data) + { + if (empty($data['data']['created_by'])) { + $data['data']['created_by'] = get_session_userid(); + } + return $data; + } + + protected function checkAndUpdateUpdatedByValue(array $data) + { + if (empty($data['data']['updated_by'])) { + $data['data']['updated_by'] = get_session_userid(); + } + return $data; + } + } diff --git a/app/Models/PartnerPosModel.php b/app/Models/PartnerPosModel.php index b1b99328..4b16c161 100644 --- a/app/Models/PartnerPosModel.php +++ b/app/Models/PartnerPosModel.php @@ -66,6 +66,7 @@ class PartnerPosModel extends Model 'aadhar', 'aadhar_file_name', 'is_active', + 'updated_on', 'created_by', 'updated_by', 'manager_id', @@ -111,11 +112,9 @@ class PartnerPosModel extends Model protected $beforeInsert = ["checkAndADDCreatedByValue"]; protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"]; - protected function checkAndADDCreatedByValue(array $data) + protected function checkAndADDCreatedByValue(array $data) { - // Check if 'updated_by' value is null or empty if (empty($data['data']['created_by'])) { - // Set 'updated_by' value to the current session user ID $data['data']['created_by'] = get_session_userid(); } @@ -124,12 +123,12 @@ class PartnerPosModel extends Model protected function checkAndUpdateUpdatedByValue(array $data) { - // Check if 'updated_by' value is null or empty if (empty($data['data']['updated_by'])) { - // Set 'updated_by' value to the current session user ID $data['data']['updated_by'] = get_session_userid(); } + $data['data']['updated_on'] = date('Y-m-d H:i:s'); + return $data; } diff --git a/app/Views/faq_list.php b/app/Views/faq_list.php index f38f1349..394034d9 100644 --- a/app/Views/faq_list.php +++ b/app/Views/faq_list.php @@ -249,9 +249,6 @@ let formData; if (type === 'submit') { - if (editor) { - $('#answer').val(editor.value); - } // CREATE FORMDATA FROM FORM formData = new FormData(form); formData.set('return_type', 'web'); diff --git a/app/Views/frontend_content_list2.php b/app/Views/frontend_content_list.php similarity index 56% rename from app/Views/frontend_content_list2.php rename to app/Views/frontend_content_list.php index 4c867152..fec27d76 100644 --- a/app/Views/frontend_content_list2.php +++ b/app/Views/frontend_content_list.php @@ -18,28 +18,28 @@ Type Content Section Heading - + Status Action - - $row) { ?> + + $row) { ?> - +