Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev
This commit is contained in:
commit
5986e5b263
@ -52,10 +52,11 @@ $routes->get("importRules", "RuleImportController::upload");
|
|||||||
// $routes->post("employeeUpload", "EmployeeRestController::employeeUpload");
|
// $routes->post("employeeUpload", "EmployeeRestController::employeeUpload");
|
||||||
|
|
||||||
$routes->post("add_advertise_image", "AppContentManagementController::add_advertise_image");
|
$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("add_image_index", "AppContentManagementController::add_image_index");
|
||||||
$routes->get("getAdvertiseImage/(:any)", "AppContentManagementController::getAdvertiseImage/$1");
|
$routes->get("getAdvertiseImage/(:any)", "AppContentManagementController::getAdvertiseImage/$1");
|
||||||
$routes->get("frontend_content", "AppContentManagementController::frontend_content");
|
$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');
|
// $routes->get('/', 'LoginController::index');
|
||||||
|
|||||||
@ -10,6 +10,7 @@ use CodeIgniter\API\ResponseTrait;
|
|||||||
|
|
||||||
use App\Models\AddImgModel;
|
use App\Models\AddImgModel;
|
||||||
use App\Models\FEContentModel;
|
use App\Models\FEContentModel;
|
||||||
|
use App\Models\ClientModel;
|
||||||
|
|
||||||
class AppContentManagementController extends AdminController
|
class AppContentManagementController extends AdminController
|
||||||
{
|
{
|
||||||
@ -17,19 +18,31 @@ class AppContentManagementController extends AdminController
|
|||||||
protected $myLogger;
|
protected $myLogger;
|
||||||
protected $addImgModel;
|
protected $addImgModel;
|
||||||
protected $feContentModel;
|
protected $feContentModel;
|
||||||
|
protected $clientModel;
|
||||||
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->myLogger = \Config\Services::mylogger();
|
$this->myLogger = \Config\Services::mylogger();
|
||||||
$this->addImgModel = new AddImgModel();
|
$this->addImgModel = new AddImgModel();
|
||||||
$this->feContentModel = new FEContentModel();
|
$this->feContentModel = new FEContentModel();
|
||||||
|
$this->clientModel = new ClientModel();
|
||||||
}
|
}
|
||||||
public function add_image_index()
|
public function add_image_index()
|
||||||
{
|
{
|
||||||
$this->myLogger->logme('error','Addvertisement Image list function called');
|
$this->myLogger->logme('error','Addvertisement Image list function called');
|
||||||
$headerData['tab_name'] = 'Addvertisement Images';
|
$headerData['tab_name'] = 'Addvertisement Images';
|
||||||
$headerData['page_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)->where('client_type', 1)->findAll();
|
||||||
|
|
||||||
// dd($data);
|
// dd($data);
|
||||||
|
|
||||||
@ -40,12 +53,14 @@ class AppContentManagementController extends AdminController
|
|||||||
// $this->loadLayout('client_onboarding', $data);
|
// $this->loadLayout('client_onboarding', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// using 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');
|
||||||
|
$client_id = $this->request->getPost('client_id');
|
||||||
//1) original file name for vaildations
|
//1) original file name for vaildations
|
||||||
$fileName = $file->getClientName(); //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); }
|
if($existing){ return $this->respond(['status' => false, 'message' => 'This file has already been uploaded in active state.'], 400); }
|
||||||
|
|
||||||
//skip 1) and use this
|
//skip 1) and use this
|
||||||
@ -62,7 +77,7 @@ class AppContentManagementController extends AdminController
|
|||||||
$file->move($uploadPath, $fileName);
|
$file->move($uploadPath, $fileName);
|
||||||
|
|
||||||
$id = $this->request->getPost('add_image_id');
|
$id = $this->request->getPost('add_image_id');
|
||||||
$data = ['name' => $fileName];
|
$data = ['name' => $fileName,'client_id'=>$client_id];
|
||||||
|
|
||||||
if ($id == 0) {
|
if ($id == 0) {
|
||||||
$this->addImgModel->insert($data);
|
$this->addImgModel->insert($data);
|
||||||
@ -76,20 +91,55 @@ 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');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$mimeType = mime_content_type($filePath);
|
$data = ['is_active' => 0];
|
||||||
header('Content-Type: ' . $mimeType);
|
$this->addImgModel->update($id, $data);
|
||||||
readfile($filePath);
|
|
||||||
exit;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mime = mime_content_type($path);
|
||||||
|
return $this->response->setHeader('Content-Type', $mime)->setBody(file_get_contents($path));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function getAdvertiseImage($image_id){
|
public function getAdvertiseImage($image_id){
|
||||||
|
|||||||
@ -176,7 +176,7 @@ class DeployController extends AdminController
|
|||||||
public function fedeploy()
|
public function fedeploy()
|
||||||
{
|
{
|
||||||
$request = $this->request;
|
$request = $this->request;
|
||||||
|
echo 'HI';die();
|
||||||
// Single zip file: <input type="file" name="zip_file">
|
// Single zip file: <input type="file" name="zip_file">
|
||||||
$file = $request->getFile('zip_file');
|
$file = $request->getFile('zip_file');
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ class DeployController extends AdminController
|
|||||||
'message' => 'No valid zip file uploaded',
|
'message' => 'No valid zip file uploaded',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
echo 'cool';die();
|
||||||
// Read scalar form values
|
// Read scalar form values
|
||||||
$zipFolder = (string) $request->getPost('zip_folder') ?: 'web/';
|
$zipFolder = (string) $request->getPost('zip_folder') ?: 'web/';
|
||||||
$s3Bucket = (string) $request->getPost('s3_bucket') ?: '';
|
$s3Bucket = (string) $request->getPost('s3_bucket') ?: '';
|
||||||
@ -283,4 +283,10 @@ class DeployController extends AdminController
|
|||||||
$this->loadLayout('fedeploy');
|
$this->loadLayout('fedeploy');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function fetest()
|
||||||
|
{
|
||||||
|
echo 'Hello from DeployController fetest!';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2308,6 +2308,10 @@ class EmployeeController extends AdminController
|
|||||||
}
|
}
|
||||||
$message = isset($message) ? ($message . ' not defined for choosed policy') : null;
|
$message = isset($message) ? ($message . ' not defined for choosed policy') : null;
|
||||||
|
|
||||||
|
if ($policy_details['cd_ac_pk'] == null) {
|
||||||
|
$message = isset($message) ? ($message . ' The policy does not have a CD account number.') : null;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->respond(['dataStatus' => true, 'code' => 200, 'message' => $message, 'si_enhancement' => $si_enhancement_true_or_false, 'insurer_multi_event' => $insurer_details['is_multi_event'], 'tpa_api_service_status' => $tpa_api_service_status], 200);
|
return $this->respond(['dataStatus' => true, 'code' => 200, 'message' => $message, 'si_enhancement' => $si_enhancement_true_or_false, 'insurer_multi_event' => $insurer_details['is_multi_event'], 'tpa_api_service_status' => $tpa_api_service_status], 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ class InsuranceCommissionController extends AdminController
|
|||||||
use ResponseTrait;
|
use ResponseTrait;
|
||||||
|
|
||||||
private $rules = [];
|
private $rules = [];
|
||||||
|
private $myLogger;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@ -66,7 +67,7 @@ class InsuranceCommissionController extends AdminController
|
|||||||
$folderName = $month . $year; // SEP2025
|
$folderName = $month . $year; // SEP2025
|
||||||
|
|
||||||
$insurerId = $input['insurer_id']; // 5
|
$insurerId = $input['insurer_id']; // 5
|
||||||
$department = ucfirst(strtolower($input['department'])); // Motor, Health, Fire
|
$department = (strtolower($input['department'])); // Motor, Health, Fire
|
||||||
|
|
||||||
// Final Path: WRITEPATH/rules/SEP2025/5_Motor.json
|
// Final Path: WRITEPATH/rules/SEP2025/5_Motor.json
|
||||||
$rulesPath = WRITEPATH . "uploads/commission/rules/{$folderName}/{$insurerId}_{$department}.json";
|
$rulesPath = WRITEPATH . "uploads/commission/rules/{$folderName}/{$insurerId}_{$department}.json";
|
||||||
@ -183,6 +184,8 @@ class InsuranceCommissionController extends AdminController
|
|||||||
|
|
||||||
private function compareValues($actual, string $operator, $expected): bool
|
private function compareValues($actual, string $operator, $expected): bool
|
||||||
{
|
{
|
||||||
|
$actual = strtolower($actual);
|
||||||
|
$expected = strtolower($expected);
|
||||||
switch ($operator) {
|
switch ($operator) {
|
||||||
case '==':
|
case '==':
|
||||||
return $actual == $expected;
|
return $actual == $expected;
|
||||||
|
|||||||
@ -40,6 +40,8 @@ table.dataTable thead th {
|
|||||||
<thead class="bg-light">
|
<thead class="bg-light">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="font-weight-medium"><div class="column-header">Advertisement Image Name</div></th>
|
<th class="font-weight-medium"><div class="column-header">Advertisement Image Name</div></th>
|
||||||
|
<th class="font-weight-medium"><div class="column-header">Client Name</div></th>
|
||||||
|
<th class="font-weight-medium"><div class="column-header">Client Short Name</div></th>
|
||||||
<th class="font-weight-medium"><div class="column-header">Status</div></th>
|
<th class="font-weight-medium"><div class="column-header">Status</div></th>
|
||||||
<th class="font-weight-medium"><div class="column-header">Action</div></th>
|
<th class="font-weight-medium"><div class="column-header">Action</div></th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -49,19 +51,18 @@ 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>
|
<td class="client_info" ><?php echo $row['client_name']; ?></td>
|
||||||
<?php echo $row['is_active']; ?>
|
<td class="client_info" ><?php echo $row['short_name']; ?></td>
|
||||||
</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-id="<?php echo $row['id']; ?>" data-name="<?php echo $row['name']; ?>" 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" data-id="<?= $row['id'];?>" onclick="removeClient(this)"><i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete</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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
@ -88,6 +89,7 @@ table.dataTable thead th {
|
|||||||
<form id="model_form_data" class="px-4" enctype="multipart/form-data">
|
<form id="model_form_data" class="px-4" enctype="multipart/form-data">
|
||||||
<input type="hidden" name="add_image_id" id="add_image_id" value="0">
|
<input type="hidden" name="add_image_id" id="add_image_id" value="0">
|
||||||
|
|
||||||
|
<!-- old
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@ -100,8 +102,63 @@ table.dataTable thead th {
|
|||||||
<div class="form-group col-md-6 float-left" style="position: relative;top: 0px;">
|
<div class="form-group col-md-6 float-left" style="position: relative;top: 0px;">
|
||||||
<img src=" " width="100" height="100" id="uploadPreview" class="avatar img-circle img-thumbnail" alt="avatar"/>
|
<img src=" " width="100" height="100" id="uploadPreview" class="avatar img-circle img-thumbnail" alt="avatar"/>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<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>
|
||||||
|
<?php
|
||||||
|
if (isset($client) && count($client)) {
|
||||||
|
foreach ($client as $key => $value) {
|
||||||
|
echo "<option value='" . $value['id'] . "'>" . $value['client_name'] . "</option>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<div class="row mb-2 align-items-stretch">
|
||||||
|
<!-- Left column: col-8 -->
|
||||||
|
<div class="col-md-8 d-flex flex-column justify-content-between">
|
||||||
|
<!-- Top section -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="branchname">Upload Image</label>
|
||||||
|
<div class="input-icon">
|
||||||
|
<input type="file" class="form-control" name="advertise_image" id="advertise_image" accept="image/*" onchange="PreviewImage();" required>
|
||||||
|
<i class="mdi mdi-upload additional-icon"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Bottom section -->
|
||||||
|
<div class="form-group">
|
||||||
|
<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>
|
||||||
|
<?php
|
||||||
|
if (isset($client) && count($client)) {
|
||||||
|
foreach ($client as $value) {
|
||||||
|
echo "<option value='" . $value['id'] . "'>" . $value['client_name'] . "</option>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Right column: col-4, preview image -->
|
||||||
|
<div class="col-md-4 d-flex flex-column align-items-center justify-content-center">
|
||||||
|
<img src="" class="avatar img-circle img-thumbnail" id="uploadPreview" alt="Preview" style="max-width: 100%; height: auto;">
|
||||||
|
|
||||||
|
<small style="font-size: x-small; margin-top: 5px; text-align: center;">
|
||||||
|
dimensions - 1640x664 pixels <br> size - 200kb
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="form-group text-center">
|
<div class="form-group text-center">
|
||||||
<button type="button" class="btn btn-primary" onclick="submitBranch()">Submit</button>
|
<button type="button" class="btn btn-primary" onclick="submitBranch()">Submit</button>
|
||||||
@ -119,6 +176,8 @@ table.dataTable thead th {
|
|||||||
function submitBranch() {
|
function submitBranch() {
|
||||||
const fileInput = $('#advertise_image')[0].files[0]; // get actual file object
|
const fileInput = $('#advertise_image')[0].files[0]; // get actual file object
|
||||||
const imageId = $('#add_image_id').val();
|
const imageId = $('#add_image_id').val();
|
||||||
|
const clientId = $('#client_id').val();
|
||||||
|
|
||||||
|
|
||||||
if (!fileInput) {
|
if (!fileInput) {
|
||||||
toastr.warning('Please upload an image before submitting', 'Warning');
|
toastr.warning('Please upload an image before submitting', 'Warning');
|
||||||
@ -126,10 +185,17 @@ table.dataTable thead th {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!clientId){
|
||||||
|
toastr.warning('Please Select Client.', 'Warning');
|
||||||
|
$('#client_id').focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var url = '<?= base_url("add_advertise_image") ?>';
|
var url = '<?= base_url("add_advertise_image") ?>';
|
||||||
var formData = new FormData();
|
var formData = new FormData();
|
||||||
formData.append('advertise_image', fileInput);
|
formData.append('advertise_image', fileInput);
|
||||||
formData.append('add_image_id', imageId);
|
formData.append('add_image_id', imageId);
|
||||||
|
formData.append('client_id', clientId);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@ -143,6 +209,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('');
|
||||||
$('#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();
|
||||||
@ -210,6 +277,7 @@ table.dataTable thead th {
|
|||||||
img.onload = function () {
|
img.onload = function () {
|
||||||
if (img.width !== 1640 || img.height !== 664) {
|
if (img.width !== 1640 || img.height !== 664) {
|
||||||
toastr.warning('Image dimensions must be 1640x664 pixels.', 'Invalid image dimensions.');
|
toastr.warning('Image dimensions must be 1640x664 pixels.', 'Invalid image dimensions.');
|
||||||
|
|
||||||
fileInput.value = ""; // Clear the file input
|
fileInput.value = ""; // Clear the file input
|
||||||
document.getElementById("uploadPreview").src = "<?= base_url()."public/assets/images/avatar_2x.png" ?>"; // Remove the preview image
|
document.getElementById("uploadPreview").src = "<?= base_url()."public/assets/images/avatar_2x.png" ?>"; // Remove the preview image
|
||||||
} else {
|
} else {
|
||||||
@ -221,9 +289,13 @@ table.dataTable thead th {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var table;
|
var table;
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
$('#add_image_id').val('');
|
||||||
|
$('#client_id').val('');
|
||||||
|
$('#client_id').select2();
|
||||||
|
$('#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
|
||||||
// "<'row'<'col-sm-12'tr>>" +
|
// "<'row'<'col-sm-12'tr>>" +
|
||||||
@ -256,17 +328,36 @@ $(document).ready(function() {
|
|||||||
},
|
},
|
||||||
paging: true
|
paging: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ✅ Define your modal function separately
|
// ✅ Define your modal function separately
|
||||||
function callmodal() {
|
function callmodal() {
|
||||||
$('#add_image_id').val(0);
|
$('#add_image_id').val(0);
|
||||||
$('#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
|
||||||
var myModal = new bootstrap.Modal(document.getElementById('bike_make_login-modal'));
|
var myModal = new bootstrap.Modal(document.getElementById('bike_make_login-modal'));
|
||||||
myModal.show();
|
myModal.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function remove_advertise_image(id) {
|
||||||
|
if (!confirm("Are you sure you want to delete this image?")) return;
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: '<?= base_url("remove_advertise_image"); ?>',
|
||||||
|
data: { add_image_id: id },
|
||||||
|
success: function (response) {
|
||||||
|
toastr.success('Deleted successfully');
|
||||||
|
location.reload(); // refresh page
|
||||||
|
},
|
||||||
|
error: function (xhr) {
|
||||||
|
console.error(xhr.responseText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// $('#btnAdd').click(function () {
|
// $('#btnAdd').click(function () {
|
||||||
// $('#add_image_id').val(0);
|
// $('#add_image_id').val(0);
|
||||||
@ -301,26 +392,49 @@ function callmodal() {
|
|||||||
$(document).on('click', '.advertise_image_edit', function (e) {
|
$(document).on('click', '.advertise_image_edit', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
// 1. Clear fields first for a clean state (Good practice)
|
||||||
|
$('#add_image_id').val('');
|
||||||
|
$('#client_id').val('');
|
||||||
|
$('#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") ?>');
|
||||||
|
|
||||||
const id = $(this).data('id');
|
let wholearray = JSON.parse($(this).attr('data-wholearray'));
|
||||||
const name = $(this).data('name');
|
let ad_name = wholearray.name;
|
||||||
console.log('Clicked ID:', id);
|
let ad_id = wholearray.id;
|
||||||
console.log('<?= base_url(); ?>');
|
let c_id = wholearray.client_id; // This holds the Client ID for the dropdown
|
||||||
|
|
||||||
$('#add_image_id').val(id);
|
console.log('Whole array:', wholearray);
|
||||||
$('#advertise_image').val(name);
|
console.log('Clicked ID:', c_id);
|
||||||
|
|
||||||
|
// 2. Set the data fields and title
|
||||||
|
$('#add_image_id').val(ad_id);
|
||||||
$('#advertise_add_edit').html('Edit Advertise Image');
|
$('#advertise_add_edit').html('Edit Advertise Image');
|
||||||
const imgUrl = '<?= base_url("showAdvertiseImage/"); ?>' + name;
|
|
||||||
|
|
||||||
$('#uploadPreview').attr('src', imgUrl)
|
// 🎯 CRITICAL FIX: Set the value of the Client SELECT dropdown
|
||||||
.on('error', function() {
|
// This pre-selects the client associated with the image.
|
||||||
$(this).attr('src', '<?= base_url()."public/assets/images/avatar_2x.png" ?>');
|
$('#client_id').val(c_id);
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
|
// 4. Set the image source AND add robust error handling for default image
|
||||||
|
$('#uploadPreview').attr('src', imgUrl).on('error', function() {
|
||||||
|
// Fallback: If the image fails to load, set the source to the default image.
|
||||||
|
$(this).attr('src', '<?= base_url("public/assets/images/avatar_2x.png") ?>');
|
||||||
|
});
|
||||||
|
|
||||||
|
// 5. Clear the file input
|
||||||
|
$('#advertise_image').val('');
|
||||||
|
|
||||||
|
// 6. Show the modal
|
||||||
|
var myModal = new bootstrap.Modal(document.getElementById('bike_make_login-modal'));
|
||||||
|
myModal.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user