diff --git a/admin/integrations.php b/admin/integrations.php index edca34d..bf3664c 100644 --- a/admin/integrations.php +++ b/admin/integrations.php @@ -1,113 +1,93 @@ ['cybermail_api_key', 'cybermail_from_email', 'cybermail_from_name', 'email_notifications_enabled'], - 'twilio' => ['twilio_account_sid', 'twilio_auth_token', 'twilio_phone_number', 'sms_notifications_enabled'], - 'push' => ['vapid_public_key', 'vapid_private_key', 'push_notifications_enabled'], - 'loyalty' => ['loyalty_enabled'] - ]; - - if (isset($settingsMap[$section])) { - foreach ($settingsMap[$section] as $key) { - $value = $_POST[$key] ?? ''; - - $existing = db()->fetch("SELECT id FROM settings WHERE setting_key = :key", ['key' => $key]); - - if ($existing) { - db()->query( - "UPDATE settings SET setting_value = :value, updated_at = NOW() WHERE setting_key = :key", - ['value' => $value, 'key' => $key] - ); - } else { - db()->insert('settings', [ - 'setting_key' => $key, - 'setting_value' => $value - ]); - } - } - - setFlash('success', ucfirst($section) . ' settings saved successfully!'); + if ($section === 'cybermail') { + setSetting('cybermail_api_key', trim($_POST['cybermail_api_key'] ?? '')); + setSetting('cybermail_from_email', trim($_POST['cybermail_from_email'] ?? '')); + setSetting('cybermail_from_name', trim($_POST['cybermail_from_name'] ?? '')); + setSetting('email_notifications_enabled', isset($_POST['email_notifications_enabled']) ? '1' : '0'); + setFlash('success', 'CyberMail settings saved.'); } - redirect('/admin/integrations.php'); + if ($section === 'twilio') { + setSetting('twilio_account_sid', trim($_POST['twilio_account_sid'] ?? '')); + setSetting('twilio_auth_token', trim($_POST['twilio_auth_token'] ?? '')); + setSetting('twilio_phone_number', trim($_POST['twilio_phone_number'] ?? '')); + setSetting('sms_notifications_enabled', isset($_POST['sms_notifications_enabled']) ? '1' : '0'); + setFlash('success', 'Twilio settings saved.'); + } + + if ($section === 'push') { + setSetting('vapid_public_key', trim($_POST['vapid_public_key'] ?? '')); + setSetting('vapid_private_key', trim($_POST['vapid_private_key'] ?? '')); + setSetting('push_notifications_enabled', isset($_POST['push_notifications_enabled']) ? '1' : '0'); + setFlash('success', 'Push notification settings saved.'); + } + + if ($section === 'loyalty') { + setSetting('loyalty_enabled', isset($_POST['loyalty_enabled']) ? '1' : '0'); + setFlash('success', 'Loyalty program settings saved.'); + } + + header('Location: /admin/integrations.php'); + exit; } +// --- GET: render page --- +ob_start(); +$pageTitle = 'Integrations'; +$currentPage = 'integrations'; +require_once __DIR__ . '/includes/header.php'; + // Load current settings -$settings = []; -$allSettings = db()->fetchAll("SELECT setting_key, setting_value FROM settings"); -foreach ($allSettings as $s) { - $settings[$s['setting_key']] = $s['setting_value']; -} +$cm = [ + 'api_key' => getSetting('cybermail_api_key', ''), + 'from_email' => getSetting('cybermail_from_email', 'noreply@tomsjavajive.com'), + 'from_name' => getSetting('cybermail_from_name', "Tom's Java Jive"), + 'enabled' => getSetting('email_notifications_enabled', '0'), +]; +$tw = [ + 'sid' => getSetting('twilio_account_sid', ''), + 'token' => getSetting('twilio_auth_token', ''), + 'phone' => getSetting('twilio_phone_number', ''), + 'enabled' => getSetting('sms_notifications_enabled', '0'), +]; +$push = [ + 'pub' => getSetting('vapid_public_key', ''), + 'priv' => getSetting('vapid_private_key', ''), + 'enabled' => getSetting('push_notifications_enabled', '0'), +]; +$loyaltyEnabled = getSetting('loyalty_enabled', '1') === '1'; ?>
- Send transactional emails (order confirmations, shipping updates, etc.) -
+Transactional email — order confirmations, shipping updates