updating phone numbers by adding prefix 968

This commit is contained in:
Flatlogic Bot 2026-02-15 06:07:23 +00:00
parent e37d1f25a4
commit 921e3675c0
10 changed files with 69 additions and 25 deletions

View File

@ -26,6 +26,6 @@ if (empty($recipient)) {
exit; exit;
} }
$result = WablasService::sendMessage($recipient, $message); $result = WablasService::sendMessage(prefix_phone($recipient), $message);
echo json_encode($result); echo json_encode($result);

View File

@ -60,7 +60,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
$goal = $_POST['goal']; $goal = $_POST['goal'];
$importance = $_POST['importance'] ?? 'normal'; $importance = $_POST['importance'] ?? 'normal';
$status = $_POST['status'] ?? 'active'; $status = $_POST['status'] ?? 'active';
$contact_phone = $_POST['contact_phone'] ?? null; $contact_phone = prefix_phone($_POST['contact_phone'] ?? null);
$image_url = $_POST['image_url_existing'] ?? ''; $image_url = $_POST['image_url_existing'] ?? '';
// Handle File Upload // Handle File Upload
@ -301,8 +301,8 @@ $is_rtl = (get_current_lang() === 'ar');
</div> </div>
<div class="col-md-6 mb-3"> <div class="col-md-6 mb-3">
<label class="form-label"><?= __('Contact Phone') ?></label> <label class="form-label"><?= __('Contact Phone') ?></label>
<input type="text" name="contact_phone" id="caseContactPhone" class="form-control"> <input type="tel" name="contact_phone" id="caseContactPhone" class="form-control" placeholder="12345678" pattern="\d{8}" title="Please enter 8 digits.">
<div class="form-text"><?= __('Optional: For WhatsApp notifications to the case manager.') ?></div> <div class="form-text"><?= __('Enter 8 digits for notifications. 968 will be added automatically.') ?></div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -232,6 +232,8 @@ $translations = [
'Enabled' => 'Enabled', 'Enabled' => 'Enabled',
'Contact Phone' => 'Contact Phone', 'Contact Phone' => 'Contact Phone',
'Optional: For WhatsApp notifications to the case manager.' => 'Optional: For WhatsApp notifications to the case manager.', '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' => [ 'ar' => [
'about_us_page' => 'صفحة من نحن', 'about_us_page' => 'صفحة من نحن',
@ -452,6 +454,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.' => 'أدخل 8 أرقام للإشعارات. ستتم إضافة 968 تلقائيًا.',
'Enter 8 digits. 968 will be added automatically.' => 'أدخل 8 أرقام. ستتم إضافة 968 تلقائيًا.',
] ]
]; ];

View File

@ -17,7 +17,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$description_en = $_POST['description_en']; $description_en = $_POST['description_en'];
$description_ar = $_POST['description_ar']; $description_ar = $_POST['description_ar'];
$email = $_POST['email']; $email = $_POST['email'];
$phone = $_POST['phone']; $phone = prefix_phone($_POST['phone']);
$address = $_POST['address']; $address = $_POST['address'];
$logo_url = $profile['logo_url'] ?? ''; $logo_url = $profile['logo_url'] ?? '';
$favicon_url = $profile['favicon_url'] ?? ''; $favicon_url = $profile['favicon_url'] ?? '';
@ -127,7 +127,8 @@ $is_rtl = (get_current_lang() === 'ar');
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<label class="form-label"><?= __('Phone') ?></label> <label class="form-label"><?= __('Phone') ?></label>
<input type="text" name="phone" class="form-control" value="<?= htmlspecialchars($profile['phone'] ?? '') ?>"> <input type="tel" name="phone" class="form-control" value="<?= htmlspecialchars(str_replace('968','',$profile['phone'] ?? '')) ?>" placeholder="12345678" pattern="\d{8}" title="Please enter 8 digits.">
<div class="form-text"><?= __('Enter 8 digits. 968 will be added automatically.') ?></div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<label class="form-label"><?= __('Address') ?></label> <label class="form-label"><?= __('Address') ?></label>

View File

@ -247,7 +247,8 @@ $is_rtl = (get_current_lang() === 'ar');
<p class="text-muted small"><?= __('Please save your settings before testing if you have made any changes.') ?></p> <p class="text-muted small"><?= __('Please save your settings before testing if you have made any changes.') ?></p>
<div class="mb-3"> <div class="mb-3">
<label class="form-label"><?= __('Recipient Phone Number') ?></label> <label class="form-label"><?= __('Recipient Phone Number') ?></label>
<input type="tel" id="test_recipient_phone" class="form-control" placeholder="e.g. 96812345678"> <input type="tel" id="test_recipient_phone" class="form-control" placeholder="12345678" pattern="\d{8}" title="Please enter 8 digits.">
<div class="form-text"><?= __('Enter 8 digits. 968 will be added automatically.') ?></div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label"><?= __('Message') ?></label> <label class="form-label"><?= __('Message') ?></label>

View File

@ -38,6 +38,8 @@ $texts = [
'goal_reached' => 'Goal Reached! Campaign Completed.', 'goal_reached' => 'Goal Reached! Campaign Completed.',
'modal_name_placeholder' => 'Anonymous Donor', 'modal_name_placeholder' => 'Anonymous Donor',
'modal_email_placeholder' => 'you@example.com', 'modal_email_placeholder' => 'you@example.com',
'modal_phone_placeholder' => '12345678',
'modal_phone_hint' => 'Enter 8 digits. 968 will be added automatically.',
], ],
'ar' => [ 'ar' => [
'title' => 'تفاصيل الحالة', 'title' => 'تفاصيل الحالة',
@ -69,6 +71,8 @@ $texts = [
'goal_reached' => 'تم تحقيق الهدف! الحملة مكتملة.', 'goal_reached' => 'تم تحقيق الهدف! الحملة مكتملة.',
'modal_name_placeholder' => 'فاعل خير', 'modal_name_placeholder' => 'فاعل خير',
'modal_email_placeholder' => 'you@example.com', 'modal_email_placeholder' => 'you@example.com',
'modal_phone_placeholder' => '12345678',
'modal_phone_hint' => 'أدخل 8 أرقام. ستتم إضافة 968 تلقائيًا.',
] ]
]; ];
@ -227,7 +231,8 @@ require_once 'includes/header.php';
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label class="form-label small fw-bold text-muted"><?= $t['modal_phone'] ?></label> <label class="form-label small fw-bold text-muted"><?= $t['modal_phone'] ?></label>
<input type="tel" name="donor_phone" class="form-control" placeholder="96812345678" required> <input type="tel" name="donor_phone" class="form-control" placeholder="<?= $t['modal_phone_placeholder'] ?>" required pattern="\d{8}" title="Please enter 8 digits.">
<div class="form-text small"><?= $t['modal_phone_hint'] ?></div>
</div> </div>
</div> </div>
@ -238,7 +243,8 @@ require_once 'includes/header.php';
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label small fw-bold text-muted"><?= $t['recipient_phone'] ?></label> <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"> <input type="tel" name="gift_recipient_phone" id="giftRecipientPhone" class="form-control" placeholder="<?= $t['modal_phone_placeholder'] ?>" pattern="\d{8}" title="Please enter 8 digits.">
<div class="form-text small"><?= $t['modal_phone_hint'] ?></div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label small fw-bold text-muted"><?= $t['gift_message'] ?></label> <label class="form-label small fw-bold text-muted"><?= $t['gift_message'] ?></label>

View File

@ -11,13 +11,13 @@ $case_id = (int)$_POST['case_id'];
$amount = (float)$_POST['amount']; $amount = (float)$_POST['amount'];
$donor_name = $_POST['donor_name'] ?? 'Anonymous'; $donor_name = $_POST['donor_name'] ?? 'Anonymous';
$donor_email = $_POST['donor_email'] ?? ''; $donor_email = $_POST['donor_email'] ?? '';
$donor_phone = $_POST['donor_phone'] ?? ''; $donor_phone = prefix_phone($_POST['donor_phone'] ?? '');
$lang = $_POST['lang'] ?? 'ar'; $lang = $_POST['lang'] ?? 'ar';
// Gift fields // Gift fields
$is_gift = (int)($_POST['is_gift'] ?? 0); $is_gift = (int)($_POST['is_gift'] ?? 0);
$gift_recipient_name = $_POST['gift_recipient_name'] ?? null; $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; $gift_message = $_POST['gift_message'] ?? null;
if ($amount <= 0) { if ($amount <= 0) {

View File

@ -15,3 +15,32 @@ function db() {
} }
return $pdo; 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;
}

View File

@ -50,6 +50,8 @@ $texts = [
'contact_us' => 'Contact Us', 'contact_us' => 'Contact Us',
'modal_name_placeholder' => 'Anonymous Donor', 'modal_name_placeholder' => 'Anonymous Donor',
'modal_email_placeholder' => 'you@example.com', 'modal_email_placeholder' => 'you@example.com',
'modal_phone_placeholder' => '12345678',
'modal_phone_hint' => 'Enter 8 digits. 968 will be added automatically.',
], ],
'ar' => [ 'ar' => [
'title' => 'ادعم قضية', 'title' => 'ادعم قضية',
@ -93,6 +95,8 @@ $texts = [
'contact_us' => 'اتصل بنا', 'contact_us' => 'اتصل بنا',
'modal_name_placeholder' => 'فاعل خير', 'modal_name_placeholder' => 'فاعل خير',
'modal_email_placeholder' => 'you@example.com', 'modal_email_placeholder' => 'you@example.com',
'modal_phone_placeholder' => '12345678',
'modal_phone_hint' => 'أدخل 8 أرقام. ستتم إضافة 968 تلقائيًا.',
] ]
]; ];
@ -550,7 +554,8 @@ require_once 'includes/header.php';
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label class="form-label small fw-bold text-muted"><?= $t['modal_phone'] ?></label> <label class="form-label small fw-bold text-muted"><?= $t['modal_phone'] ?></label>
<input type="tel" name="donor_phone" class="form-control" placeholder="96812345678" required> <input type="tel" name="donor_phone" class="form-control" placeholder="<?= $t['modal_phone_placeholder'] ?>" required pattern="\d{8}" title="Please enter 8 digits.">
<div class="form-text small"><?= $t['modal_phone_hint'] ?></div>
</div> </div>
</div> </div>
@ -562,7 +567,8 @@ require_once 'includes/header.php';
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label small fw-bold text-muted"><?= $t['recipient_phone'] ?></label> <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"> <input type="tel" name="gift_recipient_phone" id="giftRecipientPhone" class="form-control" placeholder="<?= $t['modal_phone_placeholder'] ?>" pattern="\d{8}" title="Please enter 8 digits.">
<div class="form-text small"><?= $t['modal_phone_hint'] ?></div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label small fw-bold text-muted"><?= $t['gift_message'] ?></label> <label class="form-label small fw-bold text-muted"><?= $t['gift_message'] ?></label>

View File

@ -15,10 +15,7 @@ class WablasService {
return ['success' => false, 'error' => 'Settings missing']; return ['success' => false, 'error' => 'Settings missing'];
} }
$to = preg_replace('/[^0-9]/', '', $to); $to = prefix_phone($to);
if (strlen($to) === 8) {
$to = '968' . $to;
}
$data = ['phone' => $to, 'message' => $message]; $data = ['phone' => $to, 'message' => $message];
if (!empty($securityKey)) { if (!empty($securityKey)) {