From 3f3ac7d8898a26ad69bf90e9ccf62b0cf1422d50 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 13 Mar 2026 13:31:02 +0000 Subject: [PATCH] change whatsapp setting --- admin_integrations.php | 108 +++++++++++++++++++++++------- includes/NotificationService.php | 110 +++++++++++++++++++++++++++++-- 2 files changed, 189 insertions(+), 29 deletions(-) diff --git a/admin_integrations.php b/admin_integrations.php index 46eb598..c0d0445 100644 --- a/admin_integrations.php +++ b/admin_integrations.php @@ -2,37 +2,65 @@ declare(strict_types=1); require_once __DIR__ . '/includes/layout.php'; +require_once __DIR__ . '/includes/NotificationService.php'; ensure_schema(); $errors = []; $success = ''; +$testSuccess = ''; +$testError = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $updates = [ - 'thawani_publishable_key' => trim($_POST['thawani_publishable_key'] ?? ''), - 'thawani_secret_key' => trim($_POST['thawani_secret_key'] ?? ''), - 'thawani_environment' => trim($_POST['thawani_environment'] ?? 'test'), - 'wablas_domain' => trim($_POST['wablas_domain'] ?? ''), - 'wablas_api_token' => trim($_POST['wablas_api_token'] ?? ''), - 'wablas_secret_key' => trim($_POST['wablas_secret_key'] ?? ''), - 'whatsapp_enabled' => isset($_POST['whatsapp_enabled']) ? '1' : '0', - 'smtp_host' => trim($_POST['smtp_host'] ?? ''), - 'smtp_port' => trim($_POST['smtp_port'] ?? ''), - 'smtp_secure' => trim($_POST['smtp_secure'] ?? ''), - 'smtp_user' => trim($_POST['smtp_user'] ?? ''), - 'smtp_pass' => trim($_POST['smtp_pass'] ?? ''), - 'mail_from' => trim($_POST['mail_from'] ?? ''), - 'mail_from_name' => trim($_POST['mail_from_name'] ?? ''), - ]; - - if (empty($errors)) { - $pdo = db(); - foreach ($updates as $key => $val) { - $stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (:k, :v) ON DUPLICATE KEY UPDATE setting_value = :v2"); - $stmt->execute([':k' => $key, ':v' => $val, ':v2' => $val]); + if (isset($_POST['action']) && $_POST['action'] === 'test_whatsapp') { + $testPhone = trim($_POST['test_phone'] ?? ''); + $testMessage = trim($_POST['test_message'] ?? ''); + + if ($testPhone === '') { + $testError = 'Phone number is required for testing.'; + } else { + // Check if settings are saved first? + // We rely on get_setting() which reads from DB. + // If user just changed input but didn't save, it won't work. + // That's standard behavior. + + try { + // We use the new public method in NotificationService + // This method handles the 968 prefix logic internally. + NotificationService::sendWhatsApp($testPhone, $testMessage ?: 'Test message from CargoLink'); + $testSuccess = 'Test message sent (check logs/phone).'; + } catch (Throwable $e) { + $testError = 'Error sending test: ' . $e->getMessage(); + } + } + + } else { + // Save Settings + $updates = [ + 'thawani_publishable_key' => trim($_POST['thawani_publishable_key'] ?? ''), + 'thawani_secret_key' => trim($_POST['thawani_secret_key'] ?? ''), + 'thawani_environment' => trim($_POST['thawani_environment'] ?? 'test'), + 'wablas_domain' => trim($_POST['wablas_domain'] ?? ''), + 'wablas_api_token' => trim($_POST['wablas_api_token'] ?? ''), + 'wablas_secret_key' => trim($_POST['wablas_secret_key'] ?? ''), + 'whatsapp_enabled' => isset($_POST['whatsapp_enabled']) ? '1' : '0', + 'smtp_host' => trim($_POST['smtp_host'] ?? ''), + 'smtp_port' => trim($_POST['smtp_port'] ?? ''), + 'smtp_secure' => trim($_POST['smtp_secure'] ?? ''), + 'smtp_user' => trim($_POST['smtp_user'] ?? ''), + 'smtp_pass' => trim($_POST['smtp_pass'] ?? ''), + 'mail_from' => trim($_POST['mail_from'] ?? ''), + 'mail_from_name' => trim($_POST['mail_from_name'] ?? ''), + ]; + + if (empty($errors)) { + $pdo = db(); + foreach ($updates as $key => $val) { + $stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (:k, :v) ON DUPLICATE KEY UPDATE setting_value = :v2"); + $stmt->execute([':k' => $key, ':v' => $val, ':v2' => $val]); + } + $success = "Integrations settings updated successfully."; } - $success = "Integrations settings updated successfully."; } } @@ -68,11 +96,17 @@ render_header('Integrations', 'admin', true);
+ +
+ + +
+
', $errors)) ?>
-
+