updating phone numbers by adding prefix 968
This commit is contained in:
parent
e37d1f25a4
commit
921e3675c0
@ -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);
|
||||
@ -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');
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label"><?= __('Contact Phone') ?></label>
|
||||
<input type="text" name="contact_phone" id="caseContactPhone" class="form-control">
|
||||
<div class="form-text"><?= __('Optional: For WhatsApp notifications to the case manager.') ?></div>
|
||||
<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"><?= __('Enter 8 digits for notifications. 968 will be added automatically.') ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -455,4 +455,4 @@ $is_rtl = (get_current_lang() === 'ar');
|
||||
<?php endif; ?>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
@ -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 تلقائيًا.',
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
@ -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');
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<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 class="col-md-4">
|
||||
<label class="form-label"><?= __('Address') ?></label>
|
||||
@ -165,4 +166,4 @@ $is_rtl = (get_current_lang() === 'ar');
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@ -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>
|
||||
<div class="mb-3">
|
||||
<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 class="mb-3">
|
||||
<label class="form-label"><?= __('Message') ?></label>
|
||||
@ -381,4 +382,4 @@ $is_rtl = (get_current_lang() === 'ar');
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
12
case.php
12
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';
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<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>
|
||||
|
||||
@ -238,7 +243,8 @@ require_once 'includes/header.php';
|
||||
</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">
|
||||
<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 class="mb-3">
|
||||
<label class="form-label small fw-bold text-muted"><?= $t['gift_message'] ?></label>
|
||||
@ -300,4 +306,4 @@ require_once 'includes/header.php';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@ -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 "</pre>";
|
||||
echo "<a href='index.php?lang=" . htmlspecialchars($lang) . "'>Go Back</a>";
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
12
index.php
12
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';
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<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>
|
||||
|
||||
@ -562,7 +567,8 @@ require_once 'includes/header.php';
|
||||
</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">
|
||||
<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 class="mb-3">
|
||||
<label class="form-label small fw-bold text-muted"><?= $t['gift_message'] ?></label>
|
||||
@ -642,4 +648,4 @@ require_once 'includes/header.php';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user