diff --git a/app/Config/Routes.php b/app/Config/Routes.php index bd9feb09..9ce825b5 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -52,10 +52,11 @@ $routes->get("importRules", "RuleImportController::upload"); // $routes->post("employeeUpload", "EmployeeRestController::employeeUpload"); $routes->post("add_advertise_image", "AppContentManagementController::add_advertise_image"); +$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)', 'AdvertiseController::showAdvertiseImage/$1'); +$routes->get('showAdvertiseImage/(:any)', 'AppContentManagementController::showAdvertiseImage/$1'); // $routes->get('/', 'LoginController::index'); diff --git a/app/Controllers/AppContentManagementController.php b/app/Controllers/AppContentManagementController.php index f9e1d356..83de29b6 100755 --- a/app/Controllers/AppContentManagementController.php +++ b/app/Controllers/AppContentManagementController.php @@ -10,6 +10,7 @@ use CodeIgniter\API\ResponseTrait; use App\Models\AddImgModel; use App\Models\FEContentModel; +use App\Models\ClientModel; class AppContentManagementController extends AdminController { @@ -17,19 +18,31 @@ class AppContentManagementController extends AdminController protected $myLogger; protected $addImgModel; protected $feContentModel; + protected $clientModel; + public function __construct() { $this->myLogger = \Config\Services::mylogger(); - $this->addImgModel = new AddImgModel(); + $this->addImgModel = new AddImgModel(); $this->feContentModel = new FEContentModel(); + $this->clientModel = new ClientModel(); } public function add_image_index() { $this->myLogger->logme('error','Addvertisement Image list function called'); $headerData['tab_name'] = 'Addvertisement Images'; $headerData['page_name'] = 'Addvertisement Images'; - $data['addImageList'] = $this->addImgModel->findAll(); + // $data['addImageList'] = $this->addImgModel->findAll(); + $data['addImageList'] = $this->addImgModel->select('advertisement_images.*, + clients.client_name, + clients.short_name, + CASE WHEN advertisement_images.is_active = 1 THEN "Active" ELSE "Inactive" END AS status', false) + ->join('clients', 'advertisement_images.client_id = clients.id', 'left') + ->where('advertisement_images.is_active', 1) + ->findAll(); + + $data['client'] = $this->clientModel->where('is_active', 1)->findAll(); // dd($data); @@ -40,12 +53,14 @@ class AppContentManagementController extends AdminController // $this->loadLayout('client_onboarding', $data); } + // using add and edit public function add_advertise_image() { try { $file = $this->request->getFile('advertise_image'); + $client_id = $this->request->getPost('client_id'); //1) original file name for vaildations $fileName = $file->getClientName(); //original file name for vaildations - $existing = $this->addImgModel->where('name', $fileName)->where('is_active', 1)->first(); + $existing = $this->addImgModel->where('name', $fileName)->where('client_id', $fileName)->where('is_active', 1)->first(); if($existing){ return $this->respond(['status' => false, 'message' => 'This file has already been uploaded in active state.'], 400); } //skip 1) and use this @@ -62,7 +77,7 @@ class AppContentManagementController extends AdminController $file->move($uploadPath, $fileName); $id = $this->request->getPost('add_image_id'); - $data = ['name' => $fileName]; + $data = ['name' => $fileName,'client_id'=>$client_id]; if ($id == 0) { $this->addImgModel->insert($data); @@ -76,22 +91,57 @@ class AppContentManagementController extends AdminController } } - public function showAdvertiseImage($fileName) + public function remove_advertise_image() { + try { + $id = $this->request->getPost('add_image_id'); - $filePath = WRITEPATH . 'uploads/advertiseImage/' . $fileName; + if (!$id) { + return $this->respond(['status' => false, 'message' => 'ID missing'], 400); + } - if (!file_exists($filePath)) { - return $this->response->setStatusCode(404, 'File not found'); + $data = ['is_active' => 0]; + $this->addImgModel->update($id, $data); + + return $this->respond(['status' => true, 'message' => 'Deleted successfully']); + + } catch (\Exception $e) { + return $this->respond(['status' => false, 'message' => $e->getMessage()], 500); + } + } + + + // 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) + + public function showAdvertiseImage($filename) + { + $path = WRITEPATH . 'uploads/advertiseImage/' . $filename; + + if (!file_exists($path)) { + throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); } - $mimeType = mime_content_type($filePath); - header('Content-Type: ' . $mimeType); - readfile($filePath); - exit; + $mime = mime_content_type($path); + 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(); diff --git a/app/Views/add_image_list.php b/app/Views/add_image_list.php index ff3770a1..a8552d0b 100755 --- a/app/Views/add_image_list.php +++ b/app/Views/add_image_list.php @@ -40,6 +40,8 @@ table.dataTable thead th {
Advertisement Image Name
+
Client Name
+
Client Short Name
Status
Action
@@ -49,19 +51,18 @@ table.dataTable thead th { + + + - - - -