Fix OPD scan delete button for direct file-list page and AJAX modal
This commit is contained in:
parent
a0b724e30d
commit
1cea1495fc
|
|
@ -5242,13 +5242,32 @@ class Opd extends BaseController
|
||||||
|
|
||||||
public function opd_file_delete(int $fileId)
|
public function opd_file_delete(int $fileId)
|
||||||
{
|
{
|
||||||
|
$isAjax = $this->request->isAJAX();
|
||||||
|
$requestedOpdId = (int) ($this->request->getGetPost('opd_id') ?? 0);
|
||||||
|
$respondDelete = function (int $update, string $message, int $opdId = 0) use ($isAjax, $requestedOpdId) {
|
||||||
|
$effectiveOpdId = $opdId > 0 ? $opdId : $requestedOpdId;
|
||||||
|
if ($isAjax) {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'update' => $update,
|
||||||
|
'opd_id' => $effectiveOpdId,
|
||||||
|
'error_text' => $message,
|
||||||
|
'csrfName' => csrf_token(),
|
||||||
|
'csrfHash' => csrf_hash(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($effectiveOpdId > 0) {
|
||||||
|
$target = base_url('Opd/opd_file_list/' . $effectiveOpdId);
|
||||||
|
return redirect()->to($target)
|
||||||
|
->with($update === 1 ? 'success' : 'error', $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->to(base_url('Opd'))
|
||||||
|
->with($update === 1 ? 'success' : 'error', $message);
|
||||||
|
};
|
||||||
|
|
||||||
if (! $this->db->tableExists('file_upload_data')) {
|
if (! $this->db->tableExists('file_upload_data')) {
|
||||||
return $this->response->setJSON([
|
return $respondDelete(0, 'File table not found');
|
||||||
'update' => 0,
|
|
||||||
'error_text' => 'File table not found',
|
|
||||||
'csrfName' => csrf_token(),
|
|
||||||
'csrfHash' => csrf_hash(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$row = $this->db->table('file_upload_data')
|
$row = $this->db->table('file_upload_data')
|
||||||
|
|
@ -5258,12 +5277,7 @@ class Opd extends BaseController
|
||||||
->getRowArray();
|
->getRowArray();
|
||||||
|
|
||||||
if (empty($row)) {
|
if (empty($row)) {
|
||||||
return $this->response->setJSON([
|
return $respondDelete(0, 'File not found');
|
||||||
'update' => 0,
|
|
||||||
'error_text' => 'File not found',
|
|
||||||
'csrfName' => csrf_token(),
|
|
||||||
'csrfHash' => csrf_hash(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$insertDate = (string) ($row['insert_date'] ?? '');
|
$insertDate = (string) ($row['insert_date'] ?? '');
|
||||||
|
|
@ -5272,12 +5286,7 @@ class Opd extends BaseController
|
||||||
$isWithin24Hours = ($insertTs !== false) && (($nowTs - $insertTs) <= 86400);
|
$isWithin24Hours = ($insertTs !== false) && (($nowTs - $insertTs) <= 86400);
|
||||||
$isSameDate = ($insertTs !== false) && (date('Y-m-d', $insertTs) === date('Y-m-d', $nowTs));
|
$isSameDate = ($insertTs !== false) && (date('Y-m-d', $insertTs) === date('Y-m-d', $nowTs));
|
||||||
if (! ($isWithin24Hours || $isSameDate)) {
|
if (! ($isWithin24Hours || $isSameDate)) {
|
||||||
return $this->response->setJSON([
|
return $respondDelete(0, 'Delete allowed only within 24 hours or same current date uploads', (int) ($row['opd_id'] ?? 0));
|
||||||
'update' => 0,
|
|
||||||
'error_text' => 'Delete allowed only within 24 hours or same current date uploads',
|
|
||||||
'csrfName' => csrf_token(),
|
|
||||||
'csrfHash' => csrf_hash(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$fullPath = (string) ($row['full_path'] ?? '');
|
$fullPath = (string) ($row['full_path'] ?? '');
|
||||||
|
|
@ -5287,13 +5296,7 @@ class Opd extends BaseController
|
||||||
|
|
||||||
$this->db->table('file_upload_data')->where('id', (int) $fileId)->delete();
|
$this->db->table('file_upload_data')->where('id', (int) $fileId)->delete();
|
||||||
|
|
||||||
return $this->response->setJSON([
|
return $respondDelete(1, 'Scan deleted', (int) ($row['opd_id'] ?? 0));
|
||||||
'update' => 1,
|
|
||||||
'opd_id' => (int) ($row['opd_id'] ?? 0),
|
|
||||||
'error_text' => 'Scan deleted',
|
|
||||||
'csrfName' => csrf_token(),
|
|
||||||
'csrfHash' => csrf_hash(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function insertOpdFileUploadRecord(string $fullPath, string $publicPath, int $pid, int $opdid, int $caseId, string $uploadBy, int $uploadById, string $mimeType = 'image/jpeg', int $isImageFile = 1, string $fileExt = '.jpg'): int
|
private function insertOpdFileUploadRecord(string $fullPath, string $publicPath, int $pid, int $opdid, int $caseId, string $uploadBy, int $uploadById, string $mimeType = 'image/jpeg', int $isImageFile = 1, string $fileExt = '.jpg'): int
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,11 @@
|
||||||
Uploaded: <?= esc($item['insert_date'] ?? '') ?>
|
Uploaded: <?= esc($item['insert_date'] ?? '') ?>
|
||||||
</div>
|
</div>
|
||||||
<?php if ((int) ($item['can_delete_limited'] ?? $item['can_delete_today'] ?? 0) === 1) : ?>
|
<?php if ((int) ($item['can_delete_limited'] ?? $item['can_delete_today'] ?? 0) === 1) : ?>
|
||||||
<button type="button" class="btn btn-outline-danger btn-sm" onclick="deleteOpdScanFromList(<?= (int) ($item['id'] ?? 0) ?>, <?= (int) ($opdid ?? 0) ?>)">Delete</button>
|
<a
|
||||||
|
href="<?= base_url('Opd/opd_file_delete/' . (int) ($item['id'] ?? 0)) . '?opd_id=' . (int) ($opdid ?? 0) ?>"
|
||||||
|
class="btn btn-outline-danger btn-sm"
|
||||||
|
onclick="if (typeof window.deleteOpdScanFromList === 'function') { window.deleteOpdScanFromList(<?= (int) ($item['id'] ?? 0) ?>, <?= (int) ($opdid ?? 0) ?>); return false; } return window.confirm('Delete this scan document?');"
|
||||||
|
>Delete</a>
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
<span class="badge bg-secondary">Delete: within 24h or same date</span>
|
<span class="badge bg-secondary">Delete: within 24h or same date</span>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user