diff --git a/app/Controllers/AppContentManagementController.php b/app/Controllers/AppContentManagementController.php index fcc9a6d6..da65a7b1 100755 --- a/app/Controllers/AppContentManagementController.php +++ b/app/Controllers/AppContentManagementController.php @@ -28,11 +28,11 @@ class AppContentManagementController extends AdminController $this->feContentModel = new FEContentModel(); $this->clientModel = new ClientModel(); } + //listing public function add_image_index() { - $this->myLogger->logme('error','Addvertisement Image list function called'); - $headerData['tab_name'] = 'Addvertisement Images'; - $headerData['page_name'] = 'Addvertisement Images'; + $headerData['tab_name'] = 'Advertisement Images'; + $headerData['page_name'] = 'Advertisement Images'; // $data['addImageList'] = $this->addImgModel->findAll(); $data['addImageList'] = $this->addImgModel->select('advertisement_images.*, clients.client_name, @@ -53,7 +53,7 @@ class AppContentManagementController extends AdminController // $this->loadLayout('client_onboarding', $data); } - // using add and edit + // add and edit public function add_advertise_image() { try { $file = $this->request->getFile('advertise_image'); @@ -70,7 +70,8 @@ class AppContentManagementController extends AdminController return $this->respond(['status' => false, 'message' => 'No file uploaded or invalid file.'], 400); } - $uploadPath = WRITEPATH . 'uploads/advertiseImage/'; + // $uploadPath = WRITEPATH . 'uploads/advertiseImage/'; + $uploadPath = ROOTPATH . 'public/uploads/add_image_upload/'; if (!is_dir($uploadPath)) mkdir($uploadPath, 0755, true); @@ -91,6 +92,7 @@ class AppContentManagementController extends AdminController } } + // soft delete public function remove_advertise_image() { try { @@ -111,47 +113,34 @@ class AppContentManagementController extends AdminController } - // public function showAdvertiseImage($fileName) - // { - - // $filePath = WRITEPATH . 'uploads/advertiseImage/' . $fileName; - - // if (!file_exists($filePath)) { - // return $this->response->setStatusCode(404, 'File not found'); - // } - - // $mimeType = mime_content_type($filePath); - // header('Content-Type: ' . $mimeType); - // readfile($filePath); - // exit; - // } - - // In AppContentManagementController.php (This is what needs to be fixed if the direct path fails) - + // Preview image Went Edit. public function showAdvertiseImage($filename) { - $path = WRITEPATH . 'uploads/advertiseImage/' . $filename; + // $path = WRITEPATH . 'uploads/advertiseImage/' . $filename; + $path = ROOTPATH . 'public/uploads/add_image_upload/' . $filename; if (!file_exists($path)) { throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); + // return $this->response->setStatusCode(404, 'File not found'); } $mime = mime_content_type($path); + // header('Content-Type: ' . $mimeType); + // readfile($path); + // exit; return $this->response->setHeader('Content-Type', $mime)->setBody(file_get_contents($path)); } - 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 getAdvertiseImage($image_id){ + // $image_data = $this->addImgModel->select('name')->where(['id' => $image_id])->first(); + // if($image_data){ + // return $image_data['name']; + // }else{ + // return ; + // } + // } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index d80f9176..1a488767 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3176,32 +3176,58 @@ class EmployeeRestController extends AdminController } } + // public function getAdvertisementImage_old() + // { + // try { + + // $client_id = $this->request->getGet('client_id'); + + // $img = $this->addImgModel->where('is_active', 1)->where('client_id',$client_id)->findAll(); + + // if (count($img) > 0) { + // $data = []; + // foreach ($img as $key => $value) { + // $url = base_url('public/uploads/add_image_upload/') . $value['name']; + // array_push($data, $url); + // } + + // return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200); + // } else { + + // return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'No Data'], 404); + // } + // } catch (\Throwable $th) { + // return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $th], 500); + // } + // } + public function getAdvertisementImage() { try { $client_id = $this->request->getGet('client_id'); + // get client_id & convert empty/null/undefined → 0 + // $client_id = ($client_id === null || $client_id === '' || $client_id === 'undefined') ? 0 : $client_id; - $img = $this->addImgModel->where('is_active', 1)->where('client_id',$client_id)->findAll(); + // fetch images for client + $images = $this->addImgModel->where('is_active', 1)->where('client_id', $client_id)->findAll(); - if (count($img) > 0) { - $data = []; - foreach ($img as $key => $value) { - $url = base_url('public/uploads/add_image_upload/') . $value['name']; - array_push($data, $url); - } - - return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200); - } else { - - return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'No Data'], 404); + // if no client images → load default client 0 + if (count($images) == 0) { + $images = $this->addImgModel->where('is_active', 1)->where('client_id', 0)->findAll(); } + + // prepare URLs + $data = array_map(function($img){ return base_url('public/uploads/add_image_upload/' . $img['name']); }, $images); + + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200); + } catch (\Throwable $th) { + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $th], 500); } } - public function storeFireBase() { try { diff --git a/app/Views/add_image_list.php b/app/Views/add_image_list.php index e83cc7d7..a69924ea 100755 --- a/app/Views/add_image_list.php +++ b/app/Views/add_image_list.php @@ -51,15 +51,15 @@ table.dataTable thead th { - - + + @@ -136,6 +136,7 @@ table.dataTable thead th {