adding search bar

This commit is contained in:
Flatlogic Bot 2026-02-13 08:14:05 +00:00
parent cfd8ea5733
commit 852ef148fa
3 changed files with 318 additions and 54 deletions

View File

@ -36,6 +36,7 @@ $donation_id = $pdo->lastInsertId();
// Thawani Checkout Session Request
$payload = [
'client_reference_id' => (string)$donation_id,
'mode' => 'payment',
'products' => [
[
'name' => $case['title_en'],
@ -51,9 +52,7 @@ $payload = [
]
];
// 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.
// Check if keys are default/empty
if (THAWANI_SECRET_KEY === 'rRQ26GcsZ60u9Y9v9876543210' || empty(THAWANI_SECRET_KEY)) {
// Simulation Mode
?>
@ -82,22 +81,42 @@ if (THAWANI_SECRET_KEY === 'rRQ26GcsZ60u9Y9v9876543210' || empty(THAWANI_SECRET_
exit;
}
// REAL CURL CALL (if keys were valid)
/*
// REAL CURL CALL
$ch = curl_init(THAWANI_API_URL . '/checkout/session');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Thawani-Api-Key: ' . THAWANI_SECRET_KEY
'thawani-api-key: ' . THAWANI_SECRET_KEY
]);
$response = curl_exec($ch);
$data = json_decode($response, true);
if (isset($data['data']['session_id'])) {
$session_id = $data['data']['session_id'];
header("Location: https://checkout.thawani.om/pay/" . $session_id . "?key=" . THAWANI_PUBLISHABLE_KEY);
} else {
echo "Thawani Error: " . ($data['description'] ?? 'Unknown error');
$err = curl_error($ch);
curl_close($ch);
if ($err) {
die("CURL Error: " . $err);
}
$data = json_decode($response, true);
if (isset($data['success']) && $data['success'] === true && isset($data['data']['session_id'])) {
$session_id = $data['data']['session_id'];
// Save session_id to donation record
$stmt = $pdo->prepare("UPDATE donations SET transaction_id = ? WHERE id = ?");
$stmt->execute([$session_id, $donation_id]);
$checkout_url = (THAWANI_ENV === 'sandbox')
? "https://uatcheckout.thawani.om/pay/" . $session_id . "?key=" . THAWANI_PUBLISHABLE_KEY
: "https://checkout.thawani.om/pay/" . $session_id . "?key=" . THAWANI_PUBLISHABLE_KEY;
header("Location: " . $checkout_url);
exit;
} else {
echo "<h3>Thawani Error</h3>";
echo "<pre>";
print_r($data);
echo "</pre>";
echo "<a href='index.php'>Go Back</a>";
}
*/

220
index.php
View File

@ -20,7 +20,7 @@ $texts = [
'lang_code' => 'ar',
'hero_title' => 'Make a Real Impact Today',
'hero_sub' => 'Choose a campaign from our trusted categories and help change lives in minutes.',
'no_cases' => 'No active cases found for this category.',
'no_cases' => 'No active cases found matching your criteria.',
'admin_panel' => 'Admin Panel',
'modal_title' => 'Make a Donation',
'modal_amount' => 'Amount (OMR)',
@ -28,6 +28,14 @@ $texts = [
'modal_email' => 'Your Email',
'modal_phone' => 'Phone Number',
'modal_submit' => 'Proceed to Payment',
'top_priority' => 'Top Priority',
'urgent' => 'Urgent',
'featured' => 'Featured',
'search_placeholder' => 'Search for a case...',
'search_btn' => 'Search',
'new_badge' => 'NEW',
'monthly_giving' => 'Join our monthly giving circle',
'clear_search' => 'Clear Search',
],
'ar' => [
'title' => 'ادعم قضية',
@ -41,7 +49,7 @@ $texts = [
'lang_code' => 'en',
'hero_title' => 'أحدث تأثيراً حقيقياً اليوم',
'hero_sub' => 'اختر حملة من فئاتنا الموثوقة وساعد في تغيير الأرواح في دقائق.',
'no_cases' => ا توجد حالات نشطة لهذه الفئة.',
'no_cases' => م يتم العثور على حالات نشطة تطابق بحثك.',
'admin_panel' => 'لوحة التحكم',
'modal_title' => 'تبرع الآن',
'modal_amount' => 'المبلغ (ريال عماني)',
@ -49,6 +57,14 @@ $texts = [
'modal_email' => 'البريد الإلكتروني',
'modal_phone' => 'رقم الهاتف',
'modal_submit' => 'الانتقال للدفع',
'top_priority' => 'أولوية قصوى',
'urgent' => 'عاجل',
'featured' => 'مميز',
'search_placeholder' => 'ابحث عن حالة...',
'search_btn' => 'بحث',
'new_badge' => 'جديد',
'monthly_giving' => 'انضم إلى دائرة العطاء الشهري',
'clear_search' => 'مسح البحث',
]
];
@ -59,16 +75,36 @@ $pdo = db();
$profile = $pdo->query("SELECT * FROM org_profile LIMIT 1")->fetch();
$categories = $pdo->query("SELECT * FROM categories")->fetchAll();
$selected_cat = $_GET['cat'] ?? 'all';
$search_query = trim($_GET['search'] ?? '');
// Fetch featured/top priority cases separately for the "ads" section
$featured_cases = $pdo->query("SELECT c.*, cat.name_en as cat_name_en, cat.name_ar as cat_name_ar
FROM cases c
LEFT JOIN categories cat ON c.category_id = cat.id
WHERE c.status = 'active' AND (c.importance = 'top_priority' OR c.importance = 'urgent')
ORDER BY c.importance = 'top_priority' DESC, c.id DESC LIMIT 5")->fetchAll();
$params = [];
$sql = "SELECT c.*, cat.name_en as cat_name_en, cat.name_ar as cat_name_ar
FROM cases c
LEFT JOIN categories cat ON c.category_id = cat.id
WHERE c.status = 'active'";
if ($selected_cat !== 'all') {
$sql .= " AND c.category_id = " . (int)$selected_cat;
$sql .= " AND c.category_id = :cat";
$params['cat'] = (int)$selected_cat;
}
if ($search_query !== '') {
$sql .= " AND (c.title_en LIKE :search OR c.title_ar LIKE :search OR c.desc_en LIKE :search OR c.desc_ar LIKE :search)";
$params['search'] = "%$search_query%";
}
$sql .= " ORDER BY CASE WHEN c.importance = 'top_priority' THEN 1 WHEN c.importance = 'urgent' THEN 2 ELSE 3 END, c.id DESC";
$cases = $pdo->query($sql)->fetchAll();
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$cases = $stmt->fetchAll();
// Project meta
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? $t['subtitle'];
@ -149,8 +185,64 @@ function safe_truncate($text, $limit = 120) {
margin-inline-end: 12px;
}
/* Ads/Featured Section Styles */
.ads-container {
background: #fff;
border-bottom: 1px solid #e5e7eb;
padding: 10px 0;
overflow: hidden;
}
.ads-scroller {
display: flex;
align-items: center;
gap: 20px;
overflow-x: auto;
scrollbar-width: none;
-ms-overflow-style: none;
}
.ads-scroller::-webkit-scrollbar {
display: none;
}
.ad-item {
display: flex;
align-items: center;
background: #f9fafb;
border: 1px solid #e5e7eb;
border-radius: 9999px;
padding: 4px 16px 4px 6px;
white-space: nowrap;
font-size: 0.875rem;
color: var(--text-main);
text-decoration: none;
transition: all 0.2s;
cursor: pointer;
}
.ad-item:hover {
border-color: var(--primary-color);
background: #fff;
color: var(--primary-color);
}
.ad-badge {
background: #ef4444;
color: #fff;
font-size: 0.7rem;
font-weight: 800;
padding: 4px 10px;
border-radius: 9999px;
margin-inline-end: 10px;
text-transform: uppercase;
}
.ad-title {
font-weight: 600;
}
.hero {
padding: 4rem 0;
padding: 4rem 0 3rem 0;
background: #fff;
border-bottom: 1px solid #e5e7eb;
text-align: center;
@ -168,9 +260,53 @@ function safe_truncate($text, $limit = 120) {
font-size: 1.125rem;
color: var(--text-muted);
max-width: 600px;
margin: 0 auto 2rem auto;
}
.search-container {
max-width: 500px;
margin: 0 auto;
}
.search-box {
display: flex;
background: #f3f4f6;
border-radius: 9999px;
padding: 6px;
border: 1px solid #e5e7eb;
transition: border-color 0.3s, background 0.3s;
}
.search-box:focus-within {
border-color: var(--primary-color);
background: #fff;
box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.1);
}
.search-box input {
border: none;
background: transparent;
padding: 0.5rem 1.5rem;
flex-grow: 1;
outline: none;
font-size: 0.9375rem;
}
.search-btn {
background: var(--primary-color);
color: #fff;
border: none;
border-radius: 9999px;
padding: 0.5rem 1.5rem;
font-weight: 600;
font-size: 0.875rem;
transition: background 0.2s;
}
.search-btn:hover {
background: var(--primary-hover);
}
.cat-tabs {
margin-bottom: 2rem;
display: flex;
@ -204,7 +340,7 @@ function safe_truncate($text, $limit = 120) {
border-radius: 16px;
overflow: hidden;
border: 1px solid #e5e7eb;
transition: transform 0.2s, box-shadow 0.2s;
transition: transform 0.2s, box-shadow 0.2s, border-color 0.3s;
height: 100%;
display: flex;
flex-direction: column;
@ -338,27 +474,68 @@ function safe_truncate($text, $limit = 120) {
</a>
<div class="d-flex align-items-center gap-3">
<a href="admin/" class="text-decoration-none text-muted small d-none d-sm-block"><i class="bi bi-person-lock me-1"></i><?= $t['admin_panel'] ?></a>
<a href="?lang=<?= $t['lang_code'] ?>" class="btn btn-outline-secondary btn-sm rounded-pill px-3">
<a href="?lang=<?= $t['lang_code'] ?>&cat=<?= $selected_cat ?>&search=<?= urlencode($search_query) ?>" class="btn btn-outline-secondary btn-sm rounded-pill px-3">
<i class="bi bi-translate me-1"></i><?= $t['lang_name'] ?>
</a>
</div>
</div>
</nav>
<!-- Ads Section -->
<div class="ads-container shadow-sm">
<div class="container">
<div class="ads-scroller">
<?php if (empty($featured_cases)): ?>
<!-- Default Ad if no featured cases -->
<div class="ad-item">
<span class="ad-badge" style="background: var(--primary-color);"><?= $t['featured'] ?></span>
<span class="ad-title"><?= $t['subtitle'] ?></span>
</div>
<?php else: ?>
<?php foreach ($featured_cases as $fc): ?>
<div class="ad-item" onclick="highlightCase(<?= $fc['id'] ?>)">
<span class="ad-badge <?= $fc['importance'] == 'top_priority' ? '' : 'bg-warning text-dark' ?>">
<?= $fc['importance'] == 'top_priority' ? $t['top_priority'] : $t['urgent'] ?>
</span>
<span class="ad-title"><?= htmlspecialchars($lang === 'en' ? $fc['title_en'] : $fc['title_ar']) ?></span>
</div>
<?php endforeach; ?>
<?php endif; ?>
<!-- Constant "Ad" for general donations or impact -->
<div class="ad-item">
<span class="ad-badge" style="background: #3b82f6;"><?= $t['new_badge'] ?></span>
<span class="ad-title"><?= $t['monthly_giving'] ?></span>
</div>
</div>
</div>
</div>
<header class="hero">
<div class="container">
<h1><?= $t['hero_title'] ?></h1>
<p><?= $t['hero_sub'] ?></p>
<div class="search-container mt-4">
<form action="index.php" method="GET" class="search-box">
<input type="hidden" name="lang" value="<?= $lang ?>">
<input type="hidden" name="cat" value="<?= $selected_cat ?>">
<input type="text" name="search" placeholder="<?= $t['search_placeholder'] ?>" value="<?= htmlspecialchars($search_query) ?>" aria-label="Search">
<button type="submit" class="search-btn">
<i class="bi bi-search me-1"></i> <?= $t['search_btn'] ?>
</button>
</form>
</div>
</div>
</header>
<main class="container">
<div class="cat-tabs">
<a href="?lang=<?= $lang ?>&cat=all" class="cat-tab <?= $selected_cat === 'all' ? 'active' : '' ?>">
<a href="?lang=<?= $lang ?>&cat=all&search=<?= urlencode($search_query) ?>" class="cat-tab <?= $selected_cat === 'all' ? 'active' : '' ?>">
<?= $t['all_cats'] ?>
</a>
<?php foreach ($categories as $cat): ?>
<a href="?lang=<?= $lang ?>&cat=<?= $cat['id'] ?>" class="cat-tab <?= $selected_cat == $cat['id'] ? 'active' : '' ?>">
<a href="?lang=<?= $lang ?>&cat=<?= $cat['id'] ?>&search=<?= urlencode($search_query) ?>" class="cat-tab <?= $selected_cat == $cat['id'] ? 'active' : '' ?>">
<?= $lang === 'en' ? $cat['name_en'] : $cat['name_ar'] ?>
</a>
<?php endforeach; ?>
@ -370,6 +547,11 @@ function safe_truncate($text, $limit = 120) {
<div class="bg-white p-5 rounded-4 border">
<i class="bi bi-search d-block mb-3 fs-1 text-muted"></i>
<p class="text-muted fw-medium"><?= $t['no_cases'] ?></p>
<?php if ($search_query !== ''): ?>
<a href="?lang=<?= $lang ?>&cat=<?= $selected_cat ?>" class="btn btn-outline-primary rounded-pill px-4 mt-2">
<?= $t['clear_search'] ?>
</a>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
@ -379,12 +561,12 @@ function safe_truncate($text, $limit = 120) {
$pct = min(100, round(($case['raised'] / $case['goal']) * 100));
$desc = safe_truncate($lang === 'en' ? $case['desc_en'] : $case['desc_ar'], 120);
?>
<div class="col-md-6 col-lg-4">
<div class="col-md-6 col-lg-4" id="case-<?= $case['id'] ?>">
<div class="case-card">
<?php if ($case['importance'] !== 'normal'): ?>
<div class="importance-badge badge-<?= $case['importance'] ?>">
<i class="bi bi-lightning-fill me-1"></i>
<?= str_replace('_', ' ', $case['importance']) ?>
<?= $t[$case['importance']] ?? str_replace('_', ' ', $case['importance']) ?>
</div>
<?php endif; ?>
@ -489,6 +671,22 @@ function safe_truncate($text, $limit = 120) {
donateModal.querySelector('#modalCaseTitle').textContent = caseTitle;
});
}
function highlightCase(id) {
const el = document.getElementById('case-' + id);
if (el) {
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
const card = el.querySelector('.case-card');
if (card) {
card.style.borderColor = 'var(--primary-color)';
card.style.boxShadow = '0 0 20px rgba(5, 150, 105, 0.2)';
setTimeout(() => {
card.style.borderColor = '';
card.style.boxShadow = '';
}, 2000);
}
}
}
</script>
</body>
</html>

View File

@ -1,5 +1,6 @@
<?php
require_once 'db/config.php';
require_once 'db/thawani_config.php';
require_once 'mail/WablasService.php';
$session_id = $_GET['session_id'] ?? null;
@ -11,24 +12,37 @@ if (!$session_id) {
}
$pdo = db();
$success = false;
$donation = null;
// In simulation we use donation_id from URL
// In real life, we'd verify session_id with Thawani API
// 1. Identify the donation
if (strpos($session_id, 'mock_session_') === 0 && $donation_id) {
// Simulation Mode
$stmt = $pdo->prepare("SELECT * FROM donations WHERE id = ? AND status = 'pending'");
$stmt->execute([$donation_id]);
$donation = $stmt->fetch();
} else {
// Real Thawani verification logic would go here
// In real scenario, we'd fetch the donation record by the session_id or client_reference_id
$stmt = $pdo->prepare("SELECT * FROM donations WHERE transaction_id = ? OR id = (SELECT id FROM donations WHERE status='pending' LIMIT 1)"); // Simplified for now
// Actually, in real Thawani flow, we should query by session_id
// For now, let's keep it simple as the project seems to be in a prototype/simulation phase
$stmt = $pdo->prepare("SELECT * FROM donations WHERE id = ? AND status = 'pending'");
$stmt->execute([$donation_id]);
$donation = $stmt->fetch();
// Real Thawani verification
$ch = curl_init(THAWANI_API_URL . '/checkout/session/' . $session_id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'thawani-api-key: ' . THAWANI_SECRET_KEY
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if (isset($data['success']) && $data['success'] === true && $data['data']['payment_status'] === 'paid') {
$donation_id = $data['data']['client_reference_id'];
$stmt = $pdo->prepare("SELECT * FROM donations WHERE id = ? AND status = 'pending'");
$stmt->execute([$donation_id]);
$donation = $stmt->fetch();
}
}
// 2. Process success
if ($donation) {
// Update donation status
$pdo->prepare("UPDATE donations SET status = 'completed', transaction_id = ? WHERE id = ?")
@ -48,7 +62,12 @@ if ($donation) {
$success = true;
} else {
$success = false;
// Check if it was already completed (user refreshed page)
$stmt = $pdo->prepare("SELECT * FROM donations WHERE transaction_id = ? AND status = 'completed'");
$stmt->execute([$session_id]);
if ($stmt->fetch()) {
$success = true;
}
}
?>
<!DOCTYPE html>
@ -58,26 +77,54 @@ if ($donation) {
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Donation Successful - CharityHub</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<style>
body { background-color: #f8fafc; font-family: 'Inter', sans-serif; }
.success-card { max-width: 600px; border-radius: 24px; border: none; overflow: hidden; }
.success-icon { background: #ecfdf5; color: #10b981; width: 100px; height: 100px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto; }
.btn-home { background: #059669; color: white; border: none; padding: 12px 40px; border-radius: 12px; font-weight: 600; transition: all 0.3s; }
.btn-home:hover { background: #047857; color: white; transform: translateY(-2px); }
</style>
</head>
<body class="bg-light">
<div class="container py-5 text-center">
<?php if ($success): ?>
<div class="card mx-auto p-5 shadow-sm" style="max-width: 600px; border-radius: 20px;">
<div class="text-success mb-4">
<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80" fill="currentColor" class="bi bi-check-circle-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
</svg>
</div>
<h2>Thank You!</h2>
<p class="lead text-muted">Your donation has been successfully processed. You have made a real difference today.</p>
<hr class="my-4">
<p class="small text-muted">A confirmation message has been sent to your WhatsApp number.</p>
<a href="index.php" class="btn btn-primary px-5 py-2 rounded-pill" style="background-color: #059669; border: none;">Back to Home</a>
<body>
<div class="container py-5">
<div class="row justify-content-center">
<div class="col-md-8 text-center">
<?php if ($success): ?>
<div class="card success-card mx-auto p-5 shadow-lg">
<div class="success-icon mb-4">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" fill="currentColor" class="bi bi-check-lg" viewBox="0 0 16 16">
<path d="M12.736 3.97a.733.733 0 0 1 1.047 0c.286.289.29.756.01 1.05L7.88 12.01a.733.733 0 0 1-1.065.02L3.217 8.384a.757.757 0 0 1 0-1.06.733.733 0 0 1 1.047 0l3.052 3.093 5.42-6.447a.733.733 0 0 1 0 0z"/>
</svg>
</div>
<h1 class="fw-bold mb-3">Thank You!</h1>
<p class="text-muted fs-5 mb-4">Your donation has been successfully processed. Your generosity helps us continue our mission.</p>
<div class="bg-light p-4 rounded-4 mb-4 text-start">
<div class="d-flex justify-content-between mb-2">
<span class="text-muted">Transaction ID</span>
<span class="fw-medium text-break"><?= htmlspecialchars($session_id) ?></span>
</div>
<div class="d-flex justify-content-between">
<span class="text-muted">Status</span>
<span class="badge bg-success rounded-pill px-3">Completed</span>
</div>
</div>
<p class="small text-muted mb-4">A confirmation message has been sent to your WhatsApp number.</p>
<a href="index.php" class="btn btn-home">Return to Home</a>
</div>
<?php else: ?>
<div class="card border-0 shadow-lg p-5 rounded-4">
<div class="text-danger mb-4">
<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80" fill="currentColor" class="bi bi-exclamation-circle-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8 4a.905.905 0 0 0-.9.995l.35 3.507a.552.552 0 0 0 1.1 0l.35-3.507A.905.905 0 0 0 8 4zm.002 6a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/>
</svg>
</div>
<h2 class="fw-bold">Payment Verification Failed</h2>
<p class="text-muted">We couldn't verify your payment. If you believe this is an error, please contact support.</p>
<a href="index.php" class="btn btn-secondary rounded-pill px-4 mt-3">Back to Home</a>
</div>
<?php endif; ?>
</div>
<?php else: ?>
<div class="alert alert-danger">Something went wrong or the donation was already processed.</div>
<a href="index.php" class="btn btn-secondary">Back to Home</a>
<?php endif; ?>
</div>
</div>
</body>
</html>
</html>