diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 166dccc2..22cb5f00 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -654,7 +654,8 @@ $routes->group("employeeRest", ["filter" => ['appSignature' , 'authJWT']], funct $routes->post("ticketSave", "ThzController::ticketSave"); }); - + //API FAQ + $routes->match(['get','post','delete'], 'FAQ', 'AppContentManagementController::FAQ'); //claims $routes->post('initiateClaim',"EmployeeRestController::initiateClaim"); @@ -791,6 +792,9 @@ $routes->post('ticketAutoFetchDetails',"ThzController::ticketAutoFetchDetails"); $routes->match(['get','post','put'], 'ticketType', 'ThzController::ticketType'); $routes->get("ticketHistoryList", "ThzController::ticketHistoryList"); +// General FAQ +$routes->match(['get','post','delete'], 'FAQ', 'AppContentManagementController::FAQ'); + //for testing $routes->group('test', function($routes) { diff --git a/app/Controllers/AppContentManagementController.php b/app/Controllers/AppContentManagementController.php index da65a7b1..a85d1bd6 100755 --- a/app/Controllers/AppContentManagementController.php +++ b/app/Controllers/AppContentManagementController.php @@ -11,6 +11,7 @@ use CodeIgniter\API\ResponseTrait; use App\Models\AddImgModel; use App\Models\FEContentModel; use App\Models\ClientModel; +use App\Models\FAQModel; class AppContentManagementController extends AdminController { @@ -19,6 +20,7 @@ class AppContentManagementController extends AdminController protected $addImgModel; protected $feContentModel; protected $clientModel; + protected $faqModel; public function __construct() @@ -27,6 +29,7 @@ class AppContentManagementController extends AdminController $this->addImgModel = new AddImgModel(); $this->feContentModel = new FEContentModel(); $this->clientModel = new ClientModel(); + $this->faqModel = new FAQModel(); } //listing public function add_image_index() @@ -156,4 +159,139 @@ class AppContentManagementController extends AdminController echo view('layout/footer'); } + + // + // 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() + { + $method = strtolower($this->request->getMethod()); + $returnType = strtolower($this->request->getGet('return_type') ?? 'api'); + $ref = ['timestamp' => date('Y-m-d H:i:s')]; + + try { + // --- 1. POST: CREATE OR UPDATE --- + if ($method === 'post') { + $id = $this->request->getPost('faq_id'); + $data = array_filter($this->request->getPost(), fn($v) => $v !== '' && $v !== null); + + if (empty($id)) { + $status = $this->faqModel->insert($data); + $msg = "Created"; + } else { + $status = $this->faqModel->update($id, $data); + $msg = "Updated"; + } + + // if ($returnType === 'web') { + // return redirect()->back()->with($status ? 'success' : 'error', "FAQ $msg " . ($status ? 'successfully' : 'failed')); + // } + + // return $this->response->setJSON([ + // ])->setStatusCode($result ? 200 : 400); + return $this->response->setJSON([ + 'status' => $status ? 'success' : 'error', + 'message' => "FAQ $msg " . ($status ? 'successfully' : 'failed'), + 'code' => $status ? 200 : 400, + 'data' => $data, + 'ref' => $ref + ])->setStatusCode($status ? 200 : 400); + } + + // --- 2. GET: FETCH LIST OR SINGLE --- + elseif ($method === 'get') { + + $id = $this->request->getGet('faq_id'); + + if (!empty($id)) { + // $row = $this->faqModel->where('is_active', 1)->find($id); + $row = $this->faqModel->find($id); + $data['faq_list'] = $row ? [$row] : []; + } else { + // $data['faq_list'] = $this->faqModel->where('is_active', 1)->orderBy('id', 'desc')->findAll(); + $data['faq_list'] = $this->faqModel->orderBy('id', 'desc')->findAll(); + } + + if ($returnType === 'web') { + $data['tab_name'] = "FAQ's"; + $data['page_name'] = "FAQ's"; + // print_r($data);die; + return $this->loadLayout('faq_list', $data); + } + + // API Response Logic + if (empty($data['faq_list'])) { + return $this->response->setJSON([ + 'status' => $returnType === 'web' ? false : 'error', + 'message' => 'No data found', + 'code' => 404, + 'data' => [], + 'ref' => $ref + ])->setStatusCode(200); // Using 200 with error status is common for mobile apps to prevent crashes + } + + return $this->response->setJSON([ + 'status' => $returnType === 'web' ? true : 'success', + 'message' => 'Data retrieved', + 'code' => 200, + 'data' => $data, + 'ref' => $ref + ])->setStatusCode(200); + } + + // --- 3. DELETE: SOFT DELETE --- + elseif ($method === 'delete') { + $id = $this->request->getGet('faq_id'); + $status = (!empty($id)) ? $this->faqModel->update($id, ['is_active' => 0]) : false; + + return $this->response->setJSON([ + 'status' => $status ? ($returnType === 'web' ? true : 'success') : ($returnType === 'web' ? false : 'error'), + 'message' => $status ? 'Data removed successfully' : 'Failed to remove or ID missing', + 'code' => $status ? 200 : 400, + 'data' => [], + 'ref' => $ref + ])->setStatusCode( 200 ); + } + + } catch (\Throwable $e) { + $msg = $e->getMessage(); + return $this->response->setJSON([ + 'status' => $returnType === 'web' ? false : 'error', + 'code' => 500, + 'message' => $msg, + 'ref' => ['file' => $e->getFile(), 'line' => $e->getLine()] + ])->setStatusCode(500); + } + } + } \ No newline at end of file diff --git a/app/Models/FAQModel.php b/app/Models/FAQModel.php new file mode 100644 index 00000000..d7c75131 --- /dev/null +++ b/app/Models/FAQModel.php @@ -0,0 +1,56 @@ + +.dataTables_filter { + position: absolute; +} +.dataTables_length label {height: 21px !important;} + + + +
+
+
+
+ + + + + + + + + + + + + + $row) { ?> + + + + + + + + + + + + + + +
S.No.CategoryQuestionAnswerStatusAction
50) + ? htmlspecialchars(substr($category, 0, 50)) . "..." + : htmlspecialchars($category); + ?> 50) + ? htmlspecialchars(substr($question, 0, 50)) . "..." + : htmlspecialchars($question); + ?> 50) + ? htmlspecialchars(substr($answer, 0, 50)) . "..." + : htmlspecialchars($answer); + ?> + + + + + +
+
+
+
+
+ + + + + + diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 96061707..62a6f880 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -2098,6 +2098,9 @@
  • Front-end Content
  • +
  • + FAQ's +
  • diff --git a/app/Views/nhance_branch_list.php b/app/Views/nhance_branch_list.php index d85b83ce..29700edd 100644 --- a/app/Views/nhance_branch_list.php +++ b/app/Views/nhance_branch_list.php @@ -107,7 +107,7 @@ text: 'Add', className: 'btn app-btn-primary mr-2', action: function(e, dt, node, config) { - openModal() + resetValues();openModal(); } }, { @@ -150,7 +150,6 @@ }) function openModal(){ - resetValues(); var myModal = new bootstrap.Modal(document.getElementById('con-close-modal')); myModal.show(); } diff --git a/app/Views/pos_list.php b/app/Views/pos_list.php index f2de943b..3ca34dff 100644 --- a/app/Views/pos_list.php +++ b/app/Views/pos_list.php @@ -226,7 +226,7 @@ text: 'Add', className: 'btn app-btn-primary mr-2', action: function(e, dt, node, config) { - openModal() + resetValues();openModal(); } }, {