From 8171e13d85c9e898b682669179c8e00405962019 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 13 Feb 2026 06:51:33 +0000 Subject: [PATCH] Autosave: 20260213-065133 --- admin/auth.php | 30 +++ admin/cases.php | 245 ++++++++++++++++++ admin/donations.php | 111 +++++++++ admin/index.php | 107 ++++++++ admin/login.php | 99 ++++++++ admin/logout.php | 13 + admin/organizations.php | 183 ++++++++++++++ admin/session_test.php | 9 + checkout.php | 102 ++++++++ db/thawani_config.php | 12 + index.php | 537 +++++++++++++++++++++++++++++----------- success.php | 67 +++++ 12 files changed, 1374 insertions(+), 141 deletions(-) create mode 100644 admin/auth.php create mode 100644 admin/cases.php create mode 100644 admin/donations.php create mode 100644 admin/index.php create mode 100644 admin/login.php create mode 100644 admin/logout.php create mode 100644 admin/organizations.php create mode 100644 admin/session_test.php create mode 100644 checkout.php create mode 100644 db/thawani_config.php create mode 100644 success.php diff --git a/admin/auth.php b/admin/auth.php new file mode 100644 index 0000000..c1ec291 --- /dev/null +++ b/admin/auth.php @@ -0,0 +1,30 @@ +prepare("DELETE FROM cases WHERE id = ?")->execute([$id]); + } else { + $pdo->prepare("DELETE FROM cases WHERE id = ? AND org_id = ?")->execute([$id, $user['org_id']]); + } + header('Location: cases.php?success=deleted'); + exit; +} + +// Fetch cases +if (is_super_admin()) { + $cases = $pdo->query("SELECT c.*, o.name_en as org_name FROM cases c JOIN organizations o ON c.org_id = o.id")->fetchAll(); + $orgs = $pdo->query("SELECT * FROM organizations")->fetchAll(); +} else { + $cases = $pdo->prepare("SELECT c.*, o.name_en as org_name FROM cases c JOIN organizations o ON c.org_id = o.id WHERE c.org_id = ?"); + $cases->execute([$user['org_id']]); + $cases = $cases->fetchAll(); + $orgs = []; // Org admin doesn't need to select org +} + +// Handle Add/Edit +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $id = $_POST['id'] ?? null; + $org_id = is_super_admin() ? $_POST['org_id'] : $user['org_id']; + $title_en = $_POST['title_en']; + $title_ar = $_POST['title_ar']; + $desc_en = $_POST['desc_en']; + $desc_ar = $_POST['desc_ar']; + $goal = $_POST['goal']; + $image_url = $_POST['image_url']; + + if ($id) { + $stmt = $pdo->prepare("UPDATE cases SET org_id=?, title_en=?, title_ar=?, desc_en=?, desc_ar=?, goal=?, image_url=? WHERE id=?"); + $stmt->execute([$org_id, $title_en, $title_ar, $desc_en, $desc_ar, $goal, $image_url, $id]); + } else { + $stmt = $pdo->prepare("INSERT INTO cases (org_id, title_en, title_ar, desc_en, desc_ar, goal, raised, image_url) VALUES (?, ?, ?, ?, ?, ?, 0, ?)"); + $stmt->execute([$org_id, $title_en, $title_ar, $desc_en, $desc_ar, $goal, $image_url]); + } + header('Location: cases.php?success=saved'); + exit; +} + +$edit_case = null; +if (isset($_GET['edit'])) { + $id = (int)$_GET['edit']; + if (is_super_admin()) { + $stmt = $pdo->prepare("SELECT * FROM cases WHERE id = ?"); + $stmt->execute([$id]); + } else { + $stmt = $pdo->prepare("SELECT * FROM cases WHERE id = ? AND org_id = ?"); + $stmt->execute([$id, $user['org_id']]); + } + $edit_case = $stmt->fetch(); +} +?> + + + + + + Manage Cases - CharityHub Admin + + + + + + + +
+
+

Manage Donation Cases

+ +
+ + +
+ Operation successful! + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + +
Title (EN/AR)OrganizationGoalRaisedActions
+
+ +
$$ + + +
+
+
+
+ + + + + + + + diff --git a/admin/donations.php b/admin/donations.php new file mode 100644 index 0000000..fabacb3 --- /dev/null +++ b/admin/donations.php @@ -0,0 +1,111 @@ +query("SELECT d.*, c.title_en as case_title, o.name_en as org_name + FROM donations d + JOIN cases c ON d.case_id = c.id + JOIN organizations o ON c.org_id = o.id + ORDER BY d.created_at DESC")->fetchAll(); +} else { + $donations = $pdo->prepare("SELECT d.*, c.title_en as case_title, o.name_en as org_name + FROM donations d + JOIN cases c ON d.case_id = c.id + JOIN organizations o ON c.org_id = o.id + WHERE c.org_id = ? + ORDER BY d.created_at DESC"); + $donations->execute([$user['org_id']]); + $donations = $donations->fetchAll(); +} +?> + + + + + + Donations - CharityHub Admin + + + + + + + +
+
+

Donations History

+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DonorCaseOrganizationAmountStatusDate
+
+ +
$ + + + +
No donations found.
+
+
+
+ + diff --git a/admin/index.php b/admin/index.php new file mode 100644 index 0000000..1eb20d8 --- /dev/null +++ b/admin/index.php @@ -0,0 +1,107 @@ +query("SELECT COUNT(*) FROM organizations")->fetchColumn(); + $total_cases = $pdo->query("SELECT COUNT(*) FROM cases")->fetchColumn(); + $total_donations = $pdo->query("SELECT SUM(amount) FROM donations WHERE status = 'completed'")->fetchColumn() ?: 0; +} else { + $org_id = $user['org_id']; + $total_cases = $pdo->query("SELECT COUNT(*) FROM cases WHERE org_id = $org_id")->fetchColumn(); + $total_donations = $pdo->query("SELECT SUM(d.amount) FROM donations d JOIN cases c ON d.case_id = c.id WHERE c.org_id = $org_id AND d.status = 'completed'")->fetchColumn() ?: 0; +} +?> + + + + + + Dashboard - CharityHub Admin + + + + + + + +
+
+

Welcome,

+
+
+ +
+ +
+
+
+
+
Organizations
+
+
+ +
+
+
+ +
+
+
+
+
Active Cases
+
+
+ +
+
+
+
+
+
+
+
Total Donations
+
$
+
+ +
+
+
+
+ +
+
Recent Activity
+

New donations and case updates will appear here.

+ +
+
+ + diff --git a/admin/login.php b/admin/login.php new file mode 100644 index 0000000..70f138e --- /dev/null +++ b/admin/login.php @@ -0,0 +1,99 @@ +prepare("SELECT * FROM users WHERE email = ?"); + $stmt->execute([$email]); + $user = $stmt->fetch(); + + if (!$user) { + $error = 'Email not found.'; + $debug[] = "Auth: Email '$email' not in database."; + } elseif (!password_verify($password, $user['password'])) { + $error = 'Incorrect password.'; + $debug[] = "Auth: Password mismatch for '$email'."; + } else { + $_SESSION['user_id'] = $user['id']; + $_SESSION['user'] = $user; + + // Force session write before redirect + session_write_close(); + + ob_end_clean(); + header('Location: index.php'); + exit; + } + } catch (PDOException $e) { + $error = 'Database error: ' . $e->getMessage(); + } + } +} +?> + + + + + + Admin Login - CharityHub + + + + + +
+

CharityHub Admin

+ + +
+ + +
+
+ + +
+
+ + +
+ +
+ +
+ Test: admin@charityhub.com / admin123 +
+ +
+ Troubleshooting:
+ "; ?> + • Time: +
+
+ + + \ No newline at end of file diff --git a/admin/logout.php b/admin/logout.php new file mode 100644 index 0000000..d07bfa7 --- /dev/null +++ b/admin/logout.php @@ -0,0 +1,13 @@ +prepare("DELETE FROM organizations WHERE id = ?")->execute([$id]); + header('Location: organizations.php?success=deleted'); + exit; +} + +// Handle Add/Edit +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $id = $_POST['id'] ?? null; + $name_en = $_POST['name_en']; + $name_ar = $_POST['name_ar']; + $logo_url = $_POST['logo_url']; + + if ($id) { + $stmt = $pdo->prepare("UPDATE organizations SET name_en=?, name_ar=?, logo_url=? WHERE id=?"); + $stmt->execute([$name_en, $name_ar, $logo_url, $id]); + } else { + $stmt = $pdo->prepare("INSERT INTO organizations (name_en, name_ar, logo_url) VALUES (?, ?, ?)"); + $stmt->execute([$name_en, $name_ar, $logo_url]); + } + header('Location: organizations.php?success=saved'); + exit; +} + +$orgs = $pdo->query("SELECT * FROM organizations")->fetchAll(); + +$edit_org = null; +if (isset($_GET['edit'])) { + $id = (int)$_GET['edit']; + $stmt = $pdo->prepare("SELECT * FROM organizations WHERE id = ?"); + $stmt->execute([$id]); + $edit_org = $stmt->fetch(); +} +?> + + + + + + Manage Organizations - CharityHub Admin + + + + + + + +
+
+

Manage Organizations

+ +
+ + +
+ Operation successful! + +
+ + +
+
+ + + + + + + + + + + + + + + + + +
Name (EN/AR)LogoActions
+
+ +
logo + + +
+
+
+
+ + + + + + + + diff --git a/admin/session_test.php b/admin/session_test.php new file mode 100644 index 0000000..9bba401 --- /dev/null +++ b/admin/session_test.php @@ -0,0 +1,9 @@ +"; +echo "Count: " . $_SESSION['test_count'] . "
"; +echo "Refresh"; diff --git a/checkout.php b/checkout.php new file mode 100644 index 0000000..dc51841 --- /dev/null +++ b/checkout.php @@ -0,0 +1,102 @@ +prepare("SELECT * FROM cases WHERE id = ?"); +$stmt->execute([$case_id]); +$case = $stmt->fetch(); + +if (!$case) { + die("Case not found"); +} + +// Create pending donation +$stmt = $pdo->prepare("INSERT INTO donations (case_id, amount, status, donor_name, donor_email) VALUES (?, ?, 'pending', ?, ?)"); +$stmt->execute([$case_id, $amount, $donor_name, $donor_email]); +$donation_id = $pdo->lastInsertId(); + +// Thawani Checkout Session Request +$payload = [ + 'client_reference_id' => (string)$donation_id, + 'products' => [ + [ + 'name' => $case['title_en'], + 'unit_amount' => (int)($amount * 1000), // Thawani uses OMR baiza (1 OMR = 1000 baiza) + 'quantity' => 1 + ] + ], + 'success_url' => 'http://' . $_SERVER['HTTP_HOST'] . '/success.php?session_id={CHECKOUT_SESSION_ID}', + 'cancel_url' => 'http://' . $_SERVER['HTTP_HOST'] . '/index.php', + 'metadata' => [ + 'donation_id' => $donation_id, + 'case_id' => $case_id + ] +]; + +// In a real scenario, we'd use CURL to call Thawani API. +// Since we don't have real keys, we'll mock the redirect or show a simulation. + +if (THAWANI_SECRET_KEY === 'rRQ26GcsZ60u9Y9v9876543210') { + // Simulation Mode + ?> + + + Simulating Thawani Checkout + +
+
+ Thawani +

Thawani Checkout Simulation

+

Donation ID: #

+

Amount: OMR

+
This is a simulation because no valid Thawani keys are configured in db/thawani_config.php.
+
+ + + +
+ Cancel +
+
+ + + - - - - - - New Style - [ + 'title' => 'Support a Cause', + 'subtitle' => 'Empower communities worldwide through your generosity.', + 'all_orgs' => 'All Organizations', + 'raised' => 'Raised', + 'of' => 'of', + 'goal' => 'Goal', + 'donate_now' => 'Donate Now', + 'lang_name' => 'العربية', + 'lang_code' => 'ar', + 'hero_title' => 'Make a Real Impact Today', + 'hero_sub' => 'Choose a campaign from our trusted partner organizations and help change lives in minutes.', + 'no_cases' => 'No active cases found for this organization.', + 'admin_panel' => 'Admin Panel', + 'modal_title' => 'Make a Donation', + 'modal_amount' => 'Amount (OMR)', + 'modal_name' => 'Your Name', + 'modal_email' => 'Your Email', + 'modal_submit' => 'Proceed to Payment', + ], + 'ar' => [ + 'title' => 'ادعم قضية', + 'subtitle' => 'مكن المجتمعات في جميع أنحاء العالم من خلال كرمك.', + 'all_orgs' => 'جميع المؤسسات', + 'raised' => 'تم جمع', + 'of' => 'من', + 'goal' => 'الهدف', + 'donate_now' => 'تبرع الآن', + 'lang_name' => 'English', + 'lang_code' => 'en', + 'hero_title' => 'أحدث تأثيراً حقيقياً اليوم', + 'hero_sub' => 'اختر حملة من مؤسساتنا الشريكة الموثوقة وساعد في تغيير الأرواح في دقائق.', + 'no_cases' => 'لا توجد حالات نشطة لهذه المؤسسة.', + 'admin_panel' => 'لوحة التحكم', + 'modal_title' => 'تبرع الآن', + 'modal_amount' => 'المبلغ (ريال عماني)', + 'modal_name' => 'الاسم', + 'modal_email' => 'البريد الإلكتروني', + 'modal_submit' => 'الانتقال للدفع', + ] +]; + +$t = $texts[$lang]; + +// Database fetch +$pdo = db(); +$orgs = $pdo->query("SELECT * FROM organizations")->fetchAll(); +$selected_org = $_GET['org'] ?? 'all'; + +$sql = "SELECT c.*, o.name_en as org_name_en, o.name_ar as org_name_ar + FROM cases c + JOIN organizations o ON c.org_id = o.id"; +if ($selected_org !== 'all') { + $sql .= " WHERE c.org_id = " . (int)$selected_org; +} +$cases = $pdo->query($sql)->fetchAll(); + +// Project meta +$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? $t['subtitle']; $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? ''; ?> - - - - - - - - - - - - - - - - - - + + + + + + <?= $t['title'] ?> + + + + + + + + + + + + + + + + + + + + + + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

+ +
- + + +
+
+

+

+
+
+ +
+
+ + + + + + + + +
+ +
+ +
+ +

+
+ + + + +
+
+ Case Image +
+ +

+

+ +
+
+
+
+
+ : OMR + : OMR +
+
+ + +
+
+
+ +
+
+ + + + + + + + diff --git a/success.php b/success.php new file mode 100644 index 0000000..09f9f09 --- /dev/null +++ b/success.php @@ -0,0 +1,67 @@ +prepare("SELECT * FROM donations WHERE id = ? AND status = 'pending'"); + $stmt->execute([$donation_id]); + $donation = $stmt->fetch(); +} else { + // Real Thawani verification logic would go here + // $donation = ... fetch by session_id/client_reference_id +} + +if ($donation) { + // Update donation status + $pdo->prepare("UPDATE donations SET status = 'completed', transaction_id = ? WHERE id = ?") + ->execute([$session_id, $donation['id']]); + + // Update case raised amount + $pdo->prepare("UPDATE cases SET raised = raised + ? WHERE id = ?") + ->execute([$donation['amount'], $donation['case_id']]); + + $success = true; +} else { + $success = false; +} +?> + + + + + + Donation Successful - CharityHub + + + +
+ +
+
+ + + +
+

Thank You!

+

Your donation has been successfully processed. You have made a real difference today.

+
+ Back to Home +
+ +
Something went wrong or the donation was already processed.
+ Back to Home + +
+ +