diff --git a/admin/ajax_test_whatsapp.php b/admin/ajax_test_whatsapp.php index d5efca8..43f4397 100644 --- a/admin/ajax_test_whatsapp.php +++ b/admin/ajax_test_whatsapp.php @@ -26,6 +26,6 @@ if (empty($recipient)) { exit; } -$result = WablasService::sendMessage($recipient, $message); +$result = WablasService::sendMessage(prefix_phone($recipient), $message); -echo json_encode($result); +echo json_encode($result); \ No newline at end of file diff --git a/admin/cases.php b/admin/cases.php index bd03c3f..e3e6f82 100644 --- a/admin/cases.php +++ b/admin/cases.php @@ -60,7 +60,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' $goal = $_POST['goal']; $importance = $_POST['importance'] ?? 'normal'; $status = $_POST['status'] ?? 'active'; - $contact_phone = $_POST['contact_phone'] ?? null; + $contact_phone = prefix_phone($_POST['contact_phone'] ?? null); $image_url = $_POST['image_url_existing'] ?? ''; // Handle File Upload @@ -301,8 +301,8 @@ $is_rtl = (get_current_lang() === 'ar');
- -
+ +
@@ -455,4 +455,4 @@ $is_rtl = (get_current_lang() === 'ar'); - + \ No newline at end of file diff --git a/admin/i18n.php b/admin/i18n.php index 6d5e1c9..e4fe783 100644 --- a/admin/i18n.php +++ b/admin/i18n.php @@ -232,6 +232,8 @@ $translations = [ 'Enabled' => 'Enabled', 'Contact Phone' => 'Contact Phone', 'Optional: For WhatsApp notifications to the case manager.' => 'Optional: For WhatsApp notifications to the case manager.', + 'Enter 8 digits for notifications. 968 will be added automatically.' => 'Enter 8 digits for notifications. 968 will be added automatically.', + 'Enter 8 digits. 968 will be added automatically.' => 'Enter 8 digits. 968 will be added automatically.', ], 'ar' => [ 'about_us_page' => 'صفحة من نحن', @@ -452,6 +454,8 @@ $translations = [ 'Enabled' => 'مفعل', 'Contact Phone' => 'رقم هاتف الاتصال', 'Optional: For WhatsApp notifications to the case manager.' => 'اختياري: لإشعارات الواتساب لمدير الحالة.', + 'Enter 8 digits for notifications. 968 will be added automatically.' => 'أدخل 8 أرقام للإشعارات. ستتم إضافة 968 تلقائيًا.', + 'Enter 8 digits. 968 will be added automatically.' => 'أدخل 8 أرقام. ستتم إضافة 968 تلقائيًا.', ] ]; diff --git a/admin/profile.php b/admin/profile.php index dbcb81d..0e6c667 100644 --- a/admin/profile.php +++ b/admin/profile.php @@ -17,7 +17,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $description_en = $_POST['description_en']; $description_ar = $_POST['description_ar']; $email = $_POST['email']; - $phone = $_POST['phone']; + $phone = prefix_phone($_POST['phone']); $address = $_POST['address']; $logo_url = $profile['logo_url'] ?? ''; $favicon_url = $profile['favicon_url'] ?? ''; @@ -127,7 +127,8 @@ $is_rtl = (get_current_lang() === 'ar');
- + +
@@ -165,4 +166,4 @@ $is_rtl = (get_current_lang() === 'ar'); - \ No newline at end of file + diff --git a/admin/settings.php b/admin/settings.php index 6ec7131..8f51d3b 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -247,7 +247,8 @@ $is_rtl = (get_current_lang() === 'ar');

- + +
@@ -381,4 +382,4 @@ $is_rtl = (get_current_lang() === 'ar');
- + \ No newline at end of file diff --git a/case.php b/case.php index e12502e..e424b06 100644 --- a/case.php +++ b/case.php @@ -38,6 +38,8 @@ $texts = [ 'goal_reached' => 'Goal Reached! Campaign Completed.', 'modal_name_placeholder' => 'Anonymous Donor', 'modal_email_placeholder' => 'you@example.com', + 'modal_phone_placeholder' => '12345678', + 'modal_phone_hint' => 'Enter 8 digits. 968 will be added automatically.', ], 'ar' => [ 'title' => 'تفاصيل الحالة', @@ -69,6 +71,8 @@ $texts = [ 'goal_reached' => 'تم تحقيق الهدف! الحملة مكتملة.', 'modal_name_placeholder' => 'فاعل خير', 'modal_email_placeholder' => 'you@example.com', + 'modal_phone_placeholder' => '12345678', + 'modal_phone_hint' => 'أدخل 8 أرقام. ستتم إضافة 968 تلقائيًا.', ] ]; @@ -227,7 +231,8 @@ require_once 'includes/header.php';
- + +
@@ -238,7 +243,8 @@ require_once 'includes/header.php';
- + +
@@ -300,4 +306,4 @@ require_once 'includes/header.php'; } - \ No newline at end of file + diff --git a/checkout.php b/checkout.php index dcfd954..cb15569 100644 --- a/checkout.php +++ b/checkout.php @@ -11,13 +11,13 @@ $case_id = (int)$_POST['case_id']; $amount = (float)$_POST['amount']; $donor_name = $_POST['donor_name'] ?? 'Anonymous'; $donor_email = $_POST['donor_email'] ?? ''; -$donor_phone = $_POST['donor_phone'] ?? ''; +$donor_phone = prefix_phone($_POST['donor_phone'] ?? ''); $lang = $_POST['lang'] ?? 'ar'; // 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_recipient_phone = prefix_phone($_POST['gift_recipient_phone'] ?? null); $gift_message = $_POST['gift_message'] ?? null; if ($amount <= 0) { @@ -132,4 +132,4 @@ if (isset($data['success']) && $data['success'] === true && isset($data['data'][ print_r($data); echo ""; echo "Go Back"; -} +} \ No newline at end of file diff --git a/db/config.php b/db/config.php index 8ffbe83..7ca613b 100644 --- a/db/config.php +++ b/db/config.php @@ -15,3 +15,32 @@ function db() { } return $pdo; } + +function prefix_phone($phone) { + if (empty($phone)) { + return null; + } + // Remove any non-digit characters except '+' + $phone = preg_replace('/[^0-9+]/', '', $phone); + + // Check if it already has the prefix + if (preg_match('/^(|\+|00)968/', $phone)) { + // If it has a +, remove it for consistency and re-add 968 + if (strpos($phone, '+') === 0) { + $phone = ltrim($phone, '+'); + } + if (strpos($phone, '00') === 0) { + $phone = substr($phone, 2); + } + if (strpos($phone, '968') === 0) { + return $phone; // Already correctly formatted + } + } + + // Normalize to 8 digits if it's longer + if (strlen($phone) > 8) { + $phone = substr($phone, -8); + } + + return '968' . $phone; +} \ No newline at end of file diff --git a/index.php b/index.php index 9e1adf8..ffd5c62 100644 --- a/index.php +++ b/index.php @@ -50,6 +50,8 @@ $texts = [ 'contact_us' => 'Contact Us', 'modal_name_placeholder' => 'Anonymous Donor', 'modal_email_placeholder' => 'you@example.com', + 'modal_phone_placeholder' => '12345678', + 'modal_phone_hint' => 'Enter 8 digits. 968 will be added automatically.', ], 'ar' => [ 'title' => 'ادعم قضية', @@ -93,6 +95,8 @@ $texts = [ 'contact_us' => 'اتصل بنا', 'modal_name_placeholder' => 'فاعل خير', 'modal_email_placeholder' => 'you@example.com', + 'modal_phone_placeholder' => '12345678', + 'modal_phone_hint' => 'أدخل 8 أرقام. ستتم إضافة 968 تلقائيًا.', ] ]; @@ -550,7 +554,8 @@ require_once 'includes/header.php';
- + +
@@ -562,7 +567,8 @@ require_once 'includes/header.php';
- + +
@@ -642,4 +648,4 @@ require_once 'includes/header.php'; } - + \ No newline at end of file diff --git a/mail/WablasService.php b/mail/WablasService.php index d069abf..9d98fb2 100644 --- a/mail/WablasService.php +++ b/mail/WablasService.php @@ -15,10 +15,7 @@ class WablasService { return ['success' => false, 'error' => 'Settings missing']; } - $to = preg_replace('/[^0-9]/', '', $to); - if (strlen($to) === 8) { - $to = '968' . $to; - } + $to = prefix_phone($to); $data = ['phone' => $to, 'message' => $message]; if (!empty($securityKey)) { @@ -143,4 +140,4 @@ class WablasService { return self::sendTemplatedMessage($case['contact_phone'], 'case_donation_notification', $vars, $lang); } -} \ No newline at end of file +}