editing pdf report
This commit is contained in:
parent
c1267b50a7
commit
d750ff8c23
@ -15,11 +15,17 @@ require_once 'i18n.php';
|
||||
|
||||
use I18N\Arabic;
|
||||
|
||||
// Get case ID from URL
|
||||
if (!isset($_GET['case_id']) || !is_numeric($_GET['case_id'])) {
|
||||
// Get case ID from URL or POST
|
||||
$case_id_val = $_GET['case_id'] ?? ($_POST['case_id'] ?? null);
|
||||
|
||||
if (!$case_id_val || !is_numeric($case_id_val)) {
|
||||
if (isset($_POST['ajax'])) {
|
||||
echo json_encode(['success' => false, 'error' => 'Invalid Case ID']);
|
||||
exit;
|
||||
}
|
||||
die('Invalid Case ID');
|
||||
}
|
||||
$case_id = intval($_GET['case_id']);
|
||||
$case_id = intval($case_id_val);
|
||||
|
||||
// Fetch case details
|
||||
$stmt = $pdo->prepare('SELECT c.*, cat.name_en as category_name, cat.name_ar as category_name_ar FROM cases c JOIN categories cat ON c.category_id = cat.id WHERE c.id = ?');
|
||||
@ -27,6 +33,10 @@ $stmt->execute([$case_id]);
|
||||
$case = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$case) {
|
||||
if (isset($_POST['ajax'])) {
|
||||
echo json_encode(['success' => false, 'error' => 'Case not found']);
|
||||
exit;
|
||||
}
|
||||
die('Case not found');
|
||||
}
|
||||
|
||||
@ -216,8 +226,9 @@ function generate_pdf($case, $donations, $audit_logs)
|
||||
$email_msg = '';
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['send_email'])) {
|
||||
$recipient = filter_var($_POST['recipient_email'], FILTER_VALIDATE_EMAIL);
|
||||
$message = htmlspecialchars($_POST['message']);
|
||||
$message = htmlspecialchars($_POST['message'] ?? '');
|
||||
|
||||
$response = [];
|
||||
if ($recipient) {
|
||||
// Generate and save PDF
|
||||
$pdf = generate_pdf($case, $donations, $audit_logs);
|
||||
@ -234,13 +245,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['send_email'])) {
|
||||
// Clean up and set message
|
||||
unlink($filepath);
|
||||
if ($res['success']) {
|
||||
$response = ['success' => true, 'message' => 'Email sent successfully!'];
|
||||
$email_msg = '<div class="alert alert-success">Email sent successfully!</div>';
|
||||
} else {
|
||||
$email_msg = '<div class="alert alert-danger">Failed to send email. Error: ' . ($res['error'] ?? 'Unknown') . '</div>';
|
||||
$error = $res['error'] ?? 'Unknown';
|
||||
$response = ['success' => false, 'error' => $error];
|
||||
$email_msg = '<div class="alert alert-danger">Failed to send email. Error: ' . $error . '</div>';
|
||||
}
|
||||
} else {
|
||||
$response = ['success' => false, 'error' => 'Invalid recipient email address.'];
|
||||
$email_msg = '<div class="alert alert-danger">Invalid recipient email address.</div>';
|
||||
}
|
||||
|
||||
// Return JSON if AJAX
|
||||
if (isset($_POST['ajax'])) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle PDF view
|
||||
|
||||
106
admin/cases.php
106
admin/cases.php
@ -50,7 +50,7 @@ $cases = $pdo->query("SELECT c.*, cat.name_en as cat_name_en, cat.name_ar as cat
|
||||
$categories = $pdo->query("SELECT * FROM categories")->fetchAll();
|
||||
|
||||
// Handle Add/Edit
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'save_case') {
|
||||
$id = $_POST['id'] ?? null;
|
||||
$category_id = $_POST['category_id'];
|
||||
$title_en = $_POST['title_en'];
|
||||
@ -202,7 +202,11 @@ $is_rtl = (get_current_lang() === 'ar');
|
||||
</span>
|
||||
</td>
|
||||
<td class="<?= $is_rtl ? 'text-start ps-4' : 'text-end pe-4' ?>">
|
||||
<a href="case_report.php?case_id=<?= $case['id'] ?>" target="_blank" class="btn btn-sm btn-outline-secondary <?= $is_rtl ? 'ms-1' : 'me-1' ?>"><i class="bi bi-printer"></i></a>
|
||||
<button type="button"
|
||||
class="btn btn-sm btn-outline-secondary <?= $is_rtl ? 'ms-1' : 'me-1' ?>"
|
||||
onclick="openReportModal(<?= $case['id'] ?>, '<?= addslashes($is_rtl ? ($case['title_ar'] ?: $case['title_en']) : $case['title_en']) ?>')">
|
||||
<i class="bi bi-printer"></i>
|
||||
</button>
|
||||
<a href="case_history.php?case_id=<?= $case['id'] ?>" class="btn btn-sm btn-outline-info <?= $is_rtl ? 'ms-1' : 'me-1' ?>"><i class="bi bi-clock-history"></i></a>
|
||||
<a href="?edit=<?= $case['id'] ?>" class="btn btn-sm btn-outline-primary <?= $is_rtl ? 'ms-1' : 'me-1' ?>"><i class="bi bi-pencil"></i></a>
|
||||
<a href="?delete=<?= $case['id'] ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('<?= __('Are you sure?') ?>')"><i class="bi bi-trash"></i></a>
|
||||
@ -220,6 +224,7 @@ $is_rtl = (get_current_lang() === 'ar');
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<input type="hidden" name="action" value="save_case">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="modalTitle"><?= __('New Case') ?></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
@ -302,9 +307,57 @@ $is_rtl = (get_current_lang() === 'ar');
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min..js"></script>
|
||||
<!-- Report Modal -->
|
||||
<div class="modal fade" id="reportModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><?= __('Report Options') ?></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<h6 id="reportCaseTitle" class="mb-3 text-muted"></h6>
|
||||
|
||||
<div class="d-grid gap-2 mb-4">
|
||||
<a href="#" id="btnDownloadPdf" target="_blank" class="btn btn-primary btn-lg">
|
||||
<i class="bi bi-file-earmark-pdf <?= $is_rtl ? 'ms-2' : 'me-2' ?>"></i> <?= __('Download PDF') ?>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<h6 class="mb-3"><?= __('Email Report') ?></h6>
|
||||
<form id="emailReportForm" onsubmit="sendEmailReport(event)">
|
||||
<input type="hidden" name="case_id" id="reportCaseId">
|
||||
<input type="hidden" name="send_email" value="1">
|
||||
<input type="hidden" name="ajax" value="1">
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="recipientEmail" class="form-label"><?= __('Recipient Email') ?></label>
|
||||
<input type="email" class="form-control" name="recipient_email" id="recipientEmail" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="emailMessage" class="form-label"><?= __('Message (Optional)') ?></label>
|
||||
<textarea class="form-control" name="message" id="emailMessage" rows="2"></textarea>
|
||||
</div>
|
||||
|
||||
<div id="emailResult" class="mb-3"></div>
|
||||
|
||||
<div class="d-flex justify-content-end">
|
||||
<button type="submit" id="btnSendEmail" class="btn btn-success">
|
||||
<i class="bi bi-send <?= $is_rtl ? 'ms-2' : 'me-2' ?>"></i> <?= __('Send Email') ?>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
const caseModal = new bootstrap.Modal(document.getElementById('caseModal'));
|
||||
const reportModal = new bootstrap.Modal(document.getElementById('reportModal'));
|
||||
|
||||
function clearForm() {
|
||||
document.getElementById('caseId').value = '';
|
||||
@ -321,6 +374,53 @@ $is_rtl = (get_current_lang() === 'ar');
|
||||
document.getElementById('modalTitle').innerText = '<?= __('New Case') ?>';
|
||||
}
|
||||
|
||||
function openReportModal(caseId, caseTitle) {
|
||||
document.getElementById('reportCaseId').value = caseId;
|
||||
document.getElementById('reportCaseTitle').innerText = caseTitle;
|
||||
document.getElementById('btnDownloadPdf').href = 'case_report.php?case_id=' + caseId + '&view=pdf';
|
||||
document.getElementById('emailResult').innerHTML = '';
|
||||
document.getElementById('recipientEmail').value = '';
|
||||
document.getElementById('emailMessage').value = '';
|
||||
reportModal.show();
|
||||
}
|
||||
|
||||
function sendEmailReport(e) {
|
||||
e.preventDefault();
|
||||
const form = document.getElementById('emailReportForm');
|
||||
const btn = document.getElementById('btnSendEmail');
|
||||
const resultDiv = document.getElementById('emailResult');
|
||||
const formData = new FormData(form);
|
||||
|
||||
// Disable button
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> <?= __('Sending...') ?>';
|
||||
resultDiv.innerHTML = '';
|
||||
|
||||
fetch('case_report.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
resultDiv.innerHTML = '<div class="alert alert-success py-2">' + data.message + '</div>';
|
||||
form.reset();
|
||||
// Keep case_id after reset
|
||||
document.getElementById('reportCaseId').value = formData.get('case_id');
|
||||
} else {
|
||||
resultDiv.innerHTML = '<div class="alert alert-danger py-2">' + data.error + '</div>';
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
resultDiv.innerHTML = '<div class="alert alert-danger py-2"><?= __('An error occurred. Please try again.') ?></div>';
|
||||
console.error('Error:', error);
|
||||
})
|
||||
.finally(() => {
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '<i class="bi bi-send <?= $is_rtl ? 'ms-2' : 'me-2' ?>"></i> <?= __('Send Email') ?>';
|
||||
});
|
||||
}
|
||||
|
||||
<?php if ($edit_case): ?>
|
||||
window.addEventListener('load', () => {
|
||||
document.getElementById('caseId').value = '<?= $edit_case['id'] ?>';
|
||||
|
||||
@ -179,6 +179,23 @@ $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<!-- PWA Manifest & Service Worker -->
|
||||
<link rel="manifest" href="manifest.json">
|
||||
<meta name="theme-color" content="#059669">
|
||||
<script>
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker.register('service-worker.js')
|
||||
.then(registration => {
|
||||
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('ServiceWorker registration failed: ', err);
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@ -240,4 +257,4 @@ $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</nav>
|
||||
21
manifest.json
Normal file
21
manifest.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Donation Platform",
|
||||
"short_name": "Donation",
|
||||
"start_url": "index.php",
|
||||
"display": "standalone",
|
||||
"background_color": "#ffffff",
|
||||
"theme_color": "#059669",
|
||||
"orientation": "portrait",
|
||||
"icons": [
|
||||
{
|
||||
"src": "assets/images/logo_1770967720.jpg",
|
||||
"sizes": "192x192",
|
||||
"type": "image/jpeg"
|
||||
},
|
||||
{
|
||||
"src": "assets/images/logo_1770967720.jpg",
|
||||
"sizes": "512x512",
|
||||
"type": "image/jpeg"
|
||||
}
|
||||
]
|
||||
}
|
||||
25
service-worker.js
Normal file
25
service-worker.js
Normal file
@ -0,0 +1,25 @@
|
||||
const CACHE_NAME = 'donation-platform-v1';
|
||||
const urlsToCache = [
|
||||
'./',
|
||||
'index.php',
|
||||
'assets/css/custom.css',
|
||||
'assets/js/main.js'
|
||||
];
|
||||
|
||||
self.addEventListener('install', event => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME)
|
||||
.then(cache => {
|
||||
return cache.addAll(urlsToCache);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
event.respondWith(
|
||||
caches.match(event.request)
|
||||
.then(response => {
|
||||
return response || fetch(event.request);
|
||||
})
|
||||
);
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user