diff --git a/admin/case_report.php b/admin/case_report.php index 149ff22..d1a125a 100644 --- a/admin/case_report.php +++ b/admin/case_report.php @@ -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 = '
Email sent successfully!
'; } else { - $email_msg = '
Failed to send email. Error: ' . ($res['error'] ?? 'Unknown') . '
'; + $error = $res['error'] ?? 'Unknown'; + $response = ['success' => false, 'error' => $error]; + $email_msg = '
Failed to send email. Error: ' . $error . '
'; } } else { + $response = ['success' => false, 'error' => 'Invalid recipient email address.']; $email_msg = '
Invalid recipient email address.
'; } + + // Return JSON if AJAX + if (isset($_POST['ajax'])) { + header('Content-Type: application/json'); + echo json_encode($response); + exit; + } } // Handle PDF view diff --git a/admin/cases.php b/admin/cases.php index f3f6f4b..1e5145e 100644 --- a/admin/cases.php +++ b/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'); - + @@ -220,6 +224,7 @@ $is_rtl = (get_current_lang() === 'ar'); - + \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..d5869a7 --- /dev/null +++ b/manifest.json @@ -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" + } + ] +} diff --git a/service-worker.js b/service-worker.js new file mode 100644 index 0000000..eaf6848 --- /dev/null +++ b/service-worker.js @@ -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); + }) + ); +});