change currency symbol
This commit is contained in:
parent
157c143969
commit
0e4184bcba
@ -139,8 +139,8 @@ if (isset($_GET['edit'])) {
|
||||
</td>
|
||||
<td><?= htmlspecialchars($case['cat_name'] ?? 'N/A') ?></td>
|
||||
<td>
|
||||
<div>$<?= number_format($case['goal']) ?></div>
|
||||
<small class="text-muted">Raised: $<?= number_format($case['raised']) ?></small>
|
||||
<div>OMR <?= number_format($case['goal'], 3) ?></div>
|
||||
<small class="text-muted">Raised: OMR <?= number_format($case['raised'], 3) ?></small>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($case['status'] === 'active'): ?>
|
||||
@ -215,8 +215,8 @@ if (isset($_GET['edit'])) {
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Goal Amount ($)</label>
|
||||
<input type="number" name="goal" id="caseGoal" class="form-control" step="0.01" required>
|
||||
<label class="form-label">Goal Amount (OMR)</label>
|
||||
<input type="number" name="goal" id="caseGoal" class="form-control" step="0.001" required>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Importance</label>
|
||||
@ -297,4 +297,4 @@ if (isset($_GET['edit'])) {
|
||||
<?php endif; ?>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
@ -70,7 +70,7 @@ $donations = $pdo->query("SELECT d.*, c.title_en as case_title, cat.name_en as c
|
||||
<div class="small fw-bold"><?= htmlspecialchars($don['case_title']) ?></div>
|
||||
<div class="small text-muted"><?= htmlspecialchars($don['cat_name'] ?? 'General') ?></div>
|
||||
</td>
|
||||
<td>$<?= number_format($don['amount'], 2) ?></td>
|
||||
<td>OMR <?= number_format($don['amount'], 3) ?></td>
|
||||
<td>
|
||||
<span class="badge badge-<?= $don['status'] ?>">
|
||||
<?= ucfirst($don['status']) ?>
|
||||
@ -90,4 +90,4 @@ $donations = $pdo->query("SELECT d.*, c.title_en as case_title, cat.name_en as c
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
@ -84,7 +84,7 @@ $recent_donations = $pdo->query("
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<div class="text-muted small">Total Donations</div>
|
||||
<div class="h3 mb-0">$<?= number_format($total_donations, 2) ?></div>
|
||||
<div class="h3 mb-0">OMR <?= number_format($total_donations, 3) ?></div>
|
||||
</div>
|
||||
<i class="bi bi-cash-stack stat-icon"></i>
|
||||
</div>
|
||||
@ -121,7 +121,7 @@ $recent_donations = $pdo->query("
|
||||
<div class="small text-muted"><?= htmlspecialchars($donation['donor_email']) ?></div>
|
||||
</td>
|
||||
<td><?= htmlspecialchars($donation['case_title']) ?></td>
|
||||
<td>$<?= number_format($donation['amount'], 2) ?></td>
|
||||
<td>OMR <?= number_format($donation['amount'], 3) ?></td>
|
||||
<td>
|
||||
<span class="badge badge-<?= $donation['status'] ?> rounded-pill">
|
||||
<?= ucfirst($donation['status']) ?>
|
||||
@ -137,4 +137,4 @@ $recent_donations = $pdo->query("
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
19
checkout.php
19
checkout.php
@ -13,6 +13,12 @@ $donor_name = $_POST['donor_name'] ?? 'Anonymous';
|
||||
$donor_email = $_POST['donor_email'] ?? '';
|
||||
$donor_phone = $_POST['donor_phone'] ?? '';
|
||||
|
||||
// Gift fields
|
||||
$is_gift = (int)($_POST['is_gift'] ?? 0);
|
||||
$gift_recipient_name = $_POST['gift_recipient_name'] ?? null;
|
||||
$gift_recipient_phone = $_POST['gift_recipient_phone'] ?? null;
|
||||
$gift_message = $_POST['gift_message'] ?? null;
|
||||
|
||||
if ($amount <= 0) {
|
||||
die("Invalid amount");
|
||||
}
|
||||
@ -29,8 +35,10 @@ if (!$case) {
|
||||
}
|
||||
|
||||
// Create pending donation
|
||||
$stmt = $pdo->prepare("INSERT INTO donations (case_id, amount, status, donor_name, donor_email, donor_phone) VALUES (?, ?, 'pending', ?, ?, ?)");
|
||||
$stmt->execute([$case_id, $amount, $donor_name, $donor_email, $donor_phone]);
|
||||
$sql = "INSERT INTO donations (case_id, amount, status, donor_name, donor_email, donor_phone, is_gift, gift_recipient_name, gift_recipient_phone, gift_message)
|
||||
VALUES (?, ?, 'pending', ?, ?, ?, ?, ?, ?, ?)";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$case_id, $amount, $donor_name, $donor_email, $donor_phone, $is_gift, $gift_recipient_name, $gift_recipient_phone, $gift_message]);
|
||||
$donation_id = $pdo->lastInsertId();
|
||||
|
||||
// Thawani Checkout Session Request
|
||||
@ -39,7 +47,7 @@ $payload = [
|
||||
'mode' => 'payment',
|
||||
'products' => [
|
||||
[
|
||||
'name' => $case['title_en'],
|
||||
'name' => ($is_gift ? "Gift Donation: " : "") . $case['title_en'],
|
||||
'unit_amount' => (int)($amount * 1000), // Thawani uses OMR baiza (1 OMR = 1000 baiza)
|
||||
'quantity' => 1
|
||||
]
|
||||
@ -66,6 +74,9 @@ if (THAWANI_SECRET_KEY === 'rRQ26GcsZ60u9Y9v9876543210' || empty(THAWANI_SECRET_
|
||||
<h3>Thawani Checkout Simulation</h3>
|
||||
<p>Donation ID: #<?= $donation_id ?></p>
|
||||
<p>Amount: OMR <?= number_format($amount, 3) ?></p>
|
||||
<?php if ($is_gift): ?>
|
||||
<div class="alert alert-success small">Gift for: <?= htmlspecialchars($gift_recipient_name) ?> (<?= htmlspecialchars($gift_recipient_phone) ?>)</div>
|
||||
<?php endif; ?>
|
||||
<div class="alert alert-info small">This is a simulation because no valid Thawani keys are configured in <code>db/thawani_config.php</code>.</div>
|
||||
<form action="success.php" method="GET">
|
||||
<input type="hidden" name="session_id" value="mock_session_<?= time() ?>">
|
||||
@ -119,4 +130,4 @@ if (isset($data['success']) && $data['success'] === true && isset($data['data'][
|
||||
print_r($data);
|
||||
echo "</pre>";
|
||||
echo "<a href='index.php'>Go Back</a>";
|
||||
}
|
||||
}
|
||||
107
index.php
107
index.php
@ -36,7 +36,13 @@ $texts = [
|
||||
'new_badge' => 'NEW',
|
||||
'monthly_giving' => 'Join our monthly giving circle',
|
||||
'clear_search' => 'Clear Search',
|
||||
'priority_notice' => 'LATEST UPDATES'
|
||||
'priority_notice' => 'LATEST UPDATES',
|
||||
'donate_type_me' => 'Donate for myself',
|
||||
'donate_type_gift' => 'Donate as a gift',
|
||||
'recipient_name' => 'Recipient Name',
|
||||
'recipient_phone' => 'Recipient Phone',
|
||||
'gift_message' => 'Gift Message',
|
||||
'gift_notice' => 'The system will send a notification to the recipient.'
|
||||
],
|
||||
'ar' => [
|
||||
'title' => 'ادعم قضية',
|
||||
@ -66,7 +72,13 @@ $texts = [
|
||||
'new_badge' => 'جديد',
|
||||
'monthly_giving' => 'انضم إلى دائرة العطاء الشهري',
|
||||
'clear_search' => 'مسح البحث',
|
||||
'priority_notice' => 'آخر التحديثات'
|
||||
'priority_notice' => 'آخر التحديثات',
|
||||
'donate_type_me' => 'تبرع لنفسي',
|
||||
'donate_type_gift' => 'تبرع كهدية لشخص آخر',
|
||||
'recipient_name' => 'اسم المستلم',
|
||||
'recipient_phone' => 'رقم هاتف المستلم',
|
||||
'gift_message' => 'رسالة الهدية',
|
||||
'gift_notice' => 'سيقوم النظام بإرسال إشعار إلى المستلم.'
|
||||
]
|
||||
];
|
||||
|
||||
@ -502,6 +514,40 @@ function safe_truncate($text, $limit = 120) {
|
||||
[dir="rtl"] .hero h1 {
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.donate-type-selector {
|
||||
display: flex;
|
||||
background: #f3f4f6;
|
||||
padding: 4px;
|
||||
border-radius: 12px;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.donate-type-btn {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 8px;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
font-size: 0.875rem;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.donate-type-btn.active {
|
||||
background: #fff;
|
||||
color: var(--primary-color);
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
#giftFields {
|
||||
display: none;
|
||||
border: 1px solid #e5e7eb;
|
||||
padding: 1.25rem;
|
||||
border-radius: 12px;
|
||||
background: #f9fafb;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -633,8 +679,8 @@ function safe_truncate($text, $limit = 120) {
|
||||
<div class="progress-bar" role="progressbar" style="width: <?= $pct ?>%" aria-valuenow="<?= $pct ?>" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<div class="progress-stats">
|
||||
<span><strong><?= $t['raised'] ?>:</strong> $<?= number_format($case['raised']) ?></span>
|
||||
<span><strong><?= $t['goal'] ?>:</strong> $<?= number_format($case['goal']) ?></span>
|
||||
<span><strong><?= $t['raised'] ?>:</strong> OMR <?= number_format($case['raised']) ?></span>
|
||||
<span><strong><?= $t['goal'] ?>:</strong> OMR <?= number_format($case['goal']) ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -663,11 +709,23 @@ function safe_truncate($text, $limit = 120) {
|
||||
<div class="p-3 bg-light rounded-3 mb-4 border-start border-success border-4">
|
||||
<p id="modalCaseTitle" class="fw-bold text-success mb-0"></p>
|
||||
</div>
|
||||
|
||||
<!-- Donate Type Selector -->
|
||||
<div class="donate-type-selector">
|
||||
<div class="donate-type-btn active" data-type="me" onclick="setDonateType('me')">
|
||||
<?= $t['donate_type_me'] ?>
|
||||
</div>
|
||||
<div class="donate-type-btn" data-type="gift" onclick="setDonateType('gift')">
|
||||
<?= $t['donate_type_gift'] ?>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="is_gift" id="isGiftInput" value="0">
|
||||
|
||||
<input type="hidden" name="case_id" id="modalCaseId">
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-bold text-muted"><?= $t['modal_amount'] ?></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-white border-end-0">$</span>
|
||||
<span class="input-group-text bg-white border-end-0">OMR</span>
|
||||
<input type="number" name="amount" class="form-control border-start-0 ps-0" step="1" min="1" placeholder="10" required>
|
||||
</div>
|
||||
</div>
|
||||
@ -675,7 +733,7 @@ function safe_truncate($text, $limit = 120) {
|
||||
<label class="form-label small fw-bold text-muted"><?= $t['modal_name'] ?></label>
|
||||
<input type="text" name="donor_name" class="form-control" placeholder="John Doe">
|
||||
</div>
|
||||
<div class="row g-3">
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label small fw-bold text-muted"><?= $t['modal_email'] ?></label>
|
||||
<input type="email" name="donor_email" class="form-control" placeholder="john@example.com">
|
||||
@ -685,6 +743,26 @@ function safe_truncate($text, $limit = 120) {
|
||||
<input type="tel" name="donor_phone" class="form-control" placeholder="96812345678" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Gift Fields -->
|
||||
<div id="giftFields">
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-bold text-muted"><?= $t['recipient_name'] ?></label>
|
||||
<input type="text" name="gift_recipient_name" class="form-control" placeholder="Recipient Name">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-bold text-muted"><?= $t['recipient_phone'] ?></label>
|
||||
<input type="tel" name="gift_recipient_phone" id="giftRecipientPhone" class="form-control" placeholder="96812345678">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-bold text-muted"><?= $t['gift_message'] ?></label>
|
||||
<textarea name="gift_message" class="form-control" rows="2" placeholder="Your message here..."></textarea>
|
||||
</div>
|
||||
<div class="small text-success">
|
||||
<i class="bi bi-info-circle me-1"></i> <?= $t['gift_notice'] ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer border-0 p-4 pt-0">
|
||||
<button type="submit" class="btn btn-donate py-3"><?= $t['modal_submit'] ?></button>
|
||||
@ -717,6 +795,23 @@ function safe_truncate($text, $limit = 120) {
|
||||
});
|
||||
}
|
||||
|
||||
function setDonateType(type) {
|
||||
const isGift = type === 'gift';
|
||||
document.getElementById('isGiftInput').value = isGift ? '1' : '0';
|
||||
document.getElementById('giftFields').style.display = isGift ? 'block' : 'none';
|
||||
|
||||
document.querySelectorAll('.donate-type-btn').forEach(btn => {
|
||||
btn.classList.toggle('active', btn.getAttribute('data-type') === type);
|
||||
});
|
||||
|
||||
const recipientPhone = document.getElementById('giftRecipientPhone');
|
||||
if (isGift) {
|
||||
recipientPhone.setAttribute('required', 'required');
|
||||
} else {
|
||||
recipientPhone.removeAttribute('required');
|
||||
}
|
||||
}
|
||||
|
||||
function highlightCase(id) {
|
||||
const el = document.getElementById('case-' + id);
|
||||
if (el) {
|
||||
|
||||
@ -18,6 +18,11 @@ class WablasService {
|
||||
// Clean phone number (remove +, spaces, etc)
|
||||
$to = preg_replace('/[^0-9]/', '', $to);
|
||||
|
||||
// Add 968 prefix if missing and it's an 8-digit Omani number
|
||||
if (strlen($to) === 8) {
|
||||
$to = '968' . $to;
|
||||
}
|
||||
|
||||
// Prepare data
|
||||
$data = [
|
||||
'phone' => $to,
|
||||
@ -76,4 +81,25 @@ class WablasService {
|
||||
|
||||
return ['success' => false, 'error' => 'No phone number provided'];
|
||||
}
|
||||
|
||||
public static function sendGiftNotification($donation) {
|
||||
if (empty($donation['is_gift']) || empty($donation['gift_recipient_phone'])) {
|
||||
return ['success' => false, 'error' => 'Not a gift or no recipient phone'];
|
||||
}
|
||||
|
||||
$donorName = !empty($donation['donor_name']) ? $donation['donor_name'] : 'A generous donor';
|
||||
$recipientName = !empty($donation['gift_recipient_name']) ? $donation['gift_recipient_name'] : 'Friend';
|
||||
$giftMessage = !empty($donation['gift_message']) ? "\n\nMessage: \"" . $donation['gift_message'] . "\"" : "";
|
||||
|
||||
// Fetch case title
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT title_en FROM cases WHERE id = ?");
|
||||
$stmt->execute([$donation['case_id']]);
|
||||
$case = $stmt->fetch();
|
||||
$caseTitle = $case ? $case['title_en'] : 'a charitable cause';
|
||||
|
||||
$message = "Hello $recipientName! ✨\n\n$donorName has made a donation to \"$caseTitle\" in your name as a special gift.$giftMessage\n\nMay this kindness bring joy to your day! ❤️\n\nCharityHub Team";
|
||||
|
||||
return self::sendMessage($donation['gift_recipient_phone'], $message);
|
||||
}
|
||||
}
|
||||
|
||||
15
success.php
15
success.php
@ -52,18 +52,23 @@ if ($donation) {
|
||||
$pdo->prepare("UPDATE cases SET raised = raised + ? WHERE id = ?")
|
||||
->execute([$donation['amount'], $donation['case_id']]);
|
||||
|
||||
// Refresh donation data to get name/phone
|
||||
// Refresh donation data to get name/phone/gift info
|
||||
$stmt = $pdo->prepare("SELECT * FROM donations WHERE id = ?");
|
||||
$stmt->execute([$donation['id']]);
|
||||
$fullDonation = $stmt->fetch();
|
||||
|
||||
// Send WhatsApp notification via Wablas
|
||||
// Send WhatsApp notification to donor
|
||||
WablasService::sendThankYou($fullDonation);
|
||||
|
||||
// Send WhatsApp notification to recipient if it's a gift
|
||||
if ($fullDonation['is_gift']) {
|
||||
WablasService::sendGiftNotification($fullDonation);
|
||||
}
|
||||
|
||||
$success = true;
|
||||
} else {
|
||||
// Check if it was already completed (user refreshed page)
|
||||
$stmt = $pdo->prepare("SELECT * FROM donations WHERE transaction_id = ? AND status = 'completed'");
|
||||
$stmt = $pdo->prepare("SELECT * FROM donations transaction_id = ? AND status = 'completed'");
|
||||
$stmt->execute([$session_id]);
|
||||
if ($stmt->fetch()) {
|
||||
$success = true;
|
||||
@ -108,7 +113,7 @@ if ($donation) {
|
||||
<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>
|
||||
<p class="small text-muted mb-4">Confirmation messages have been sent to the relevant parties.</p>
|
||||
<a href="index.php" class="btn btn-home">Return to Home</a>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
@ -127,4 +132,4 @@ if ($donation) {
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user