Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev
This commit is contained in:
commit
204991c8bb
@ -28,11 +28,11 @@ class AppContentManagementController extends AdminController
|
|||||||
$this->feContentModel = new FEContentModel();
|
$this->feContentModel = new FEContentModel();
|
||||||
$this->clientModel = new ClientModel();
|
$this->clientModel = new ClientModel();
|
||||||
}
|
}
|
||||||
|
//listing
|
||||||
public function add_image_index()
|
public function add_image_index()
|
||||||
{
|
{
|
||||||
$this->myLogger->logme('error','Addvertisement Image list function called');
|
$headerData['tab_name'] = 'Advertisement Images';
|
||||||
$headerData['tab_name'] = 'Addvertisement Images';
|
$headerData['page_name'] = 'Advertisement Images';
|
||||||
$headerData['page_name'] = 'Addvertisement Images';
|
|
||||||
// $data['addImageList'] = $this->addImgModel->findAll();
|
// $data['addImageList'] = $this->addImgModel->findAll();
|
||||||
$data['addImageList'] = $this->addImgModel->select('advertisement_images.*,
|
$data['addImageList'] = $this->addImgModel->select('advertisement_images.*,
|
||||||
clients.client_name,
|
clients.client_name,
|
||||||
@ -53,7 +53,7 @@ class AppContentManagementController extends AdminController
|
|||||||
// $this->loadLayout('client_onboarding', $data);
|
// $this->loadLayout('client_onboarding', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// using add and edit
|
// add and edit
|
||||||
public function add_advertise_image() {
|
public function add_advertise_image() {
|
||||||
try {
|
try {
|
||||||
$file = $this->request->getFile('advertise_image');
|
$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);
|
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);
|
if (!is_dir($uploadPath)) mkdir($uploadPath, 0755, true);
|
||||||
|
|
||||||
|
|
||||||
@ -91,6 +92,7 @@ class AppContentManagementController extends AdminController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// soft delete
|
||||||
public function remove_advertise_image()
|
public function remove_advertise_image()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -111,47 +113,34 @@ class AppContentManagementController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// public function showAdvertiseImage($fileName)
|
// Preview image Went Edit.
|
||||||
// {
|
|
||||||
|
|
||||||
// $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)
|
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)) {
|
if (!file_exists($path)) {
|
||||||
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
||||||
|
// return $this->response->setStatusCode(404, 'File not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$mime = mime_content_type($path);
|
$mime = mime_content_type($path);
|
||||||
|
// header('Content-Type: ' . $mimeType);
|
||||||
|
// readfile($path);
|
||||||
|
// exit;
|
||||||
return $this->response->setHeader('Content-Type', $mime)->setBody(file_get_contents($path));
|
return $this->response->setHeader('Content-Type', $mime)->setBody(file_get_contents($path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function getAdvertiseImage($image_id){
|
// public function getAdvertiseImage($image_id){
|
||||||
|
// $image_data = $this->addImgModel->select('name')->where(['id' => $image_id])->first();
|
||||||
$image_data = $this->addImgModel->select('name')->where(['id' => $image_id])->first();
|
// if($image_data){
|
||||||
|
// return $image_data['name'];
|
||||||
if($image_data){
|
// }else{
|
||||||
return $image_data['name'];
|
// return ;
|
||||||
}else{
|
// }
|
||||||
return ;
|
// }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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()
|
public function getAdvertisementImage()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$client_id = $this->request->getGet('client_id');
|
$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) {
|
// if no client images → load default client 0
|
||||||
$data = [];
|
if (count($images) == 0) {
|
||||||
foreach ($img as $key => $value) {
|
$images = $this->addImgModel->where('is_active', 1)->where('client_id', 0)->findAll();
|
||||||
$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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
} catch (\Throwable $th) {
|
||||||
|
|
||||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $th], 500);
|
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $th], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function storeFireBase()
|
public function storeFireBase()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -51,15 +51,15 @@ table.dataTable thead th {
|
|||||||
<?php foreach($addImageList as $row){ ?>
|
<?php foreach($addImageList as $row){ ?>
|
||||||
<tr >
|
<tr >
|
||||||
<td class="client_info" data-id="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></td>
|
<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['client_id'] != 0 ? $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['short_name'] : '-'; ?></td>
|
||||||
<td class="client_info" ><?php echo $row['status']; ?></td>
|
<td class="client_info" ><?php echo $row['status']; ?></td>
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-group dropdown">
|
<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>
|
<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">
|
<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 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>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
@ -136,6 +136,7 @@ table.dataTable thead th {
|
|||||||
<label for="client_branch">Client <span class="text-danger">*</span></label>
|
<label for="client_branch">Client <span class="text-danger">*</span></label>
|
||||||
<select class="form-control" id="client_id" name="client_id" required>
|
<select class="form-control" id="client_id" name="client_id" required>
|
||||||
<option value="">Select Client</option>
|
<option value="">Select Client</option>
|
||||||
|
<option value="0">Default Image</option>
|
||||||
<?php
|
<?php
|
||||||
if (isset($client) && count($client)) {
|
if (isset($client) && count($client)) {
|
||||||
foreach ($client as $value) {
|
foreach ($client as $value) {
|
||||||
@ -209,7 +210,7 @@ table.dataTable thead th {
|
|||||||
if (response.status) {
|
if (response.status) {
|
||||||
$('#bike_make_login-modal').modal('hide');
|
$('#bike_make_login-modal').modal('hide');
|
||||||
$('#advertise_image').val('');
|
$('#advertise_image').val('');
|
||||||
$('#client_id').val('');
|
$('#client_id').val(null).trigger('change');
|
||||||
$('#uploadPreview').attr('src', '<?= base_url('public/assets/images/avatar_2x.png') ?>');
|
$('#uploadPreview').attr('src', '<?= base_url('public/assets/images/avatar_2x.png') ?>');
|
||||||
toastr.success('Image uploaded successfully!');
|
toastr.success('Image uploaded successfully!');
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
@ -292,9 +293,9 @@ table.dataTable thead th {
|
|||||||
var table;
|
var table;
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#add_image_id').val('');
|
|
||||||
$('#client_id').val('');
|
|
||||||
$('#client_id').select2();
|
$('#client_id').select2();
|
||||||
|
$('#add_image_id').val('');
|
||||||
|
$('#client_id').val(null).trigger('change');
|
||||||
$('#advertise_image').val('');
|
$('#advertise_image').val('');
|
||||||
table = $('#tickets-table').DataTable({
|
table = $('#tickets-table').DataTable({
|
||||||
// dom: "<'row'<'col-sm-1'f><'col-sm-11 text-right'B>>" + // Filter left, button right
|
// 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
|
// ✅ Define your modal function separately
|
||||||
function callmodal() {
|
function callmodal() {
|
||||||
$('#add_image_id').val(0);
|
$('#add_image_id').val(0);
|
||||||
|
$('#client_id').val(null).trigger('change');
|
||||||
$('#advertise_add_edit').html('Add Advertise Image');
|
$('#advertise_add_edit').html('Add Advertise Image');
|
||||||
$('#uploadPreview').attr('src', '<?= base_url()."public/assets/images/avatar_2x.png" ?>');
|
$('#uploadPreview').attr('src', '<?= base_url()."public/assets/images/avatar_2x.png" ?>');
|
||||||
$('#bike_model_login-modal').modal('show'); // ✅ this shows the modal
|
$('#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)
|
// 1. Clear fields first for a clean state (Good practice)
|
||||||
$('#add_image_id').val('');
|
$('#add_image_id').val('');
|
||||||
$('#client_id').val('');
|
$('#client_id').val(null).trigger('change');
|
||||||
$('#advertise_image').val('');
|
$('#advertise_image').val('');
|
||||||
// Reset preview to default before processing to avoid flicker/old image
|
// Reset preview to default before processing to avoid flicker/old image
|
||||||
$('#uploadPreview').attr('src', '<?= base_url("public/assets/images/avatar_2x.png") ?>');
|
$('#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 ad_id = wholearray.id;
|
||||||
let c_id = wholearray.client_id; // This holds the Client ID for the dropdown
|
let c_id = wholearray.client_id; // This holds the Client ID for the dropdown
|
||||||
|
|
||||||
console.log('Whole array:', wholearray);
|
// console.log('Whole array:', wholearray);
|
||||||
console.log('Clicked ID:', c_id);
|
// console.log('Clicked ID:', ad_id);
|
||||||
|
|
||||||
// 2. Set the data fields and title
|
// 2. Set the data fields and title
|
||||||
$('#add_image_id').val(ad_id);
|
$('#add_image_id').val(ad_id);
|
||||||
@ -413,14 +415,13 @@ table.dataTable thead th {
|
|||||||
|
|
||||||
// 🎯 CRITICAL FIX: Set the value of the Client SELECT dropdown
|
// 🎯 CRITICAL FIX: Set the value of the Client SELECT dropdown
|
||||||
// This pre-selects the client associated with the image.
|
// 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
|
// 3. Construct the image URL
|
||||||
// NOTE: If this path fails (404/403), revert to the previous controller path:
|
// NOTE: If this path fails (404/403), revert to the previous controller path:
|
||||||
const imgUrl = '<?= base_url("showAdvertiseImage/"); ?>' + ad_name;
|
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
|
// 4. Set the image source AND add robust error handling for default image
|
||||||
$('#uploadPreview').attr('src', imgUrl).on('error', function() {
|
$('#uploadPreview').attr('src', imgUrl).on('error', function() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user