Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev

This commit is contained in:
Gowtham M 2025-12-11 18:23:08 +05:30
commit 204991c8bb
3 changed files with 74 additions and 58 deletions

View File

@ -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 ;
// }
// }

View File

@ -3177,32 +3177,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 {

View File

@ -51,15 +51,15 @@ table.dataTable thead th {
<?php foreach($addImageList as $row){ ?>
<tr >
<td class="client_info" data-id="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></td>
<td class="client_info" ><?php echo $row['client_name']; ?></td>
<td class="client_info" ><?php echo $row['short_name']; ?></td>
<td class="client_info" ><?php echo $row['client_id'] != 0 ? $row['client_name'] : '-' ; ?></td>
<td class="client_info" ><?php echo $row['client_id'] != 0 ? $row['short_name'] : '-'; ?></td>
<td class="client_info" ><?php echo $row['status']; ?></td>
<td>
<div class="btn-group dropdown">
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown"aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item advertise_image_edit" href="#" data-toggle="modal" data-wholearray='<?php echo json_encode($row, JSON_HEX_APOS); ?>' data-target="#bike_make_login-modal"><i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<a class="dropdown-item" onclick="remove_advertise_image('<?= $row['id'];?>')"><i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete</a>
<?php if($row['client_id'] != 0) { ?> <a class="dropdown-item" onclick="remove_advertise_image('<?= $row['id'];?>')"><i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete</a> <?php } ?>
</div>
</div>
</td>
@ -136,6 +136,7 @@ table.dataTable thead th {
<label for="client_branch">Client <span class="text-danger">*</span></label>
<select class="form-control" id="client_id" name="client_id" required>
<option value="">Select Client</option>
<option value="0">Default Image</option>
<?php
if (isset($client) && count($client)) {
foreach ($client as $value) {
@ -209,7 +210,7 @@ table.dataTable thead th {
if (response.status) {
$('#bike_make_login-modal').modal('hide');
$('#advertise_image').val('');
$('#client_id').val('');
$('#client_id').val(null).trigger('change');
$('#uploadPreview').attr('src', '<?= base_url('public/assets/images/avatar_2x.png') ?>');
toastr.success('Image uploaded successfully!');
window.location.reload();
@ -292,9 +293,9 @@ table.dataTable thead th {
var table;
$(document).ready(function() {
$('#add_image_id').val('');
$('#client_id').val('');
$('#client_id').select2();
$('#add_image_id').val('');
$('#client_id').val(null).trigger('change');
$('#advertise_image').val('');
table = $('#tickets-table').DataTable({
// dom: "<'row'<'col-sm-1'f><'col-sm-11 text-right'B>>" + // Filter left, button right
@ -333,6 +334,7 @@ table.dataTable thead th {
// ✅ Define your modal function separately
function callmodal() {
$('#add_image_id').val(0);
$('#client_id').val(null).trigger('change');
$('#advertise_add_edit').html('Add Advertise Image');
$('#uploadPreview').attr('src', '<?= base_url()."public/assets/images/avatar_2x.png" ?>');
$('#bike_model_login-modal').modal('show'); // ✅ this shows the modal
@ -394,7 +396,7 @@ table.dataTable thead th {
// 1. Clear fields first for a clean state (Good practice)
$('#add_image_id').val('');
$('#client_id').val('');
$('#client_id').val(null).trigger('change');
$('#advertise_image').val('');
// Reset preview to default before processing to avoid flicker/old image
$('#uploadPreview').attr('src', '<?= base_url("public/assets/images/avatar_2x.png") ?>');
@ -404,8 +406,8 @@ table.dataTable thead th {
let ad_id = wholearray.id;
let c_id = wholearray.client_id; // This holds the Client ID for the dropdown
console.log('Whole array:', wholearray);
console.log('Clicked ID:', c_id);
// console.log('Whole array:', wholearray);
// console.log('Clicked ID:', ad_id);
// 2. Set the data fields and title
$('#add_image_id').val(ad_id);
@ -413,14 +415,13 @@ table.dataTable thead th {
// 🎯 CRITICAL FIX: Set the value of the Client SELECT dropdown
// This pre-selects the client associated with the image.
$('#client_id').val(c_id);
$('#client_id').val(c_id).trigger('change');
// 3. Construct the image URL
// NOTE: If this path fails (404/403), revert to the previous controller path:
const imgUrl = '<?= base_url("showAdvertiseImage/"); ?>' + ad_name;
// const imgUrl = '<?= base_url("writable/uploads/advertiseImage/"); ?>' + ad_name;
// const imgUrl = '<?= base_url('public/uploads/add_image_upload/'); ?>' + ad_name;
// 4. Set the image source AND add robust error handling for default image
$('#uploadPreview').attr('src', imgUrl).on('error', function() {