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'; ?> -
- -
+
- +
-
- -
+
-

CyberMail

-

- Send transactional emails (order confirmations, shipping updates, etc.) -

+

CyberMail

+

Transactional email — order confirmations, shipping updates

- - - + + +
- -
-
- - -

- Manage at - CyberMail Dashboard -

-
+
+ + +

Manage at CyberMail Dashboard

-
- +
- "> +
-
- -
- - +
+ +
@@ -197,69 +151,44 @@ foreach ($allSettings as $s) {
-
- -
+
-

Twilio SMS

-

- Send SMS notifications for orders, shipping updates, and promotions -

+

Twilio SMS

+

SMS notifications for orders, shipping, and promotions

- - - + + +
-
- +
- +
-
- -

- Get your credentials from - Twilio Console -

+ +

Get credentials at Twilio Console

-
- -
- - +
+ +
@@ -269,57 +198,36 @@ foreach ($allSettings as $s) {
-
- -
+
-

Push Notifications

-

- Web push notifications for order updates and promotions -

+

Push Notifications

+

Web push for order updates and promotions

- - - + + +
-
- +
-
- -

- Generate VAPID keys at - Web Push Codelab -

+ +

Generate at Web Push Codelab

-
- - +
@@ -328,79 +236,37 @@ foreach ($allSettings as $s) {
-
- -
+
-

Loyalty Program

-

- Reward customers with points and tiers (Bronze, Silver, Gold, Platinum) -

+

Loyalty Program

+

Reward customers with points and tiers

- - - - +
-
- -
-

Tier Structure

- - - - - - - - - +
+

Tier Structure

+
TierMin PointsMultiplierKey Benefits
+ - - - - - - - - - - - - - - - - - - - - - - - - + + + +
TierMin PointsMultiplierKey Benefits
Bronze Bean01x1 point/$1, Birthday reward
Silver Roast5001.25xFree shipping $25+, Double points weekends
Gold Blend1,5001.5xFree shipping all orders, Priority support
Platinum Reserve5,0002xExpress shipping, VIP events, Account manager
Bronze Bean01x1 point/$1, Birthday reward
Silver Roast5001.25xFree shipping $25+, Double points weekends
Gold Blend1,5001.5xFree shipping all orders, Priority support
Platinum Reserve5,0002xExpress shipping, VIP events, Account manager
-

- 100 points = $1 credit • Points earned on every purchase -

+

100 points = $1 credit • Points earned on every purchase

- - +
@@ -418,13 +284,11 @@ foreach ($allSettings as $s) {
- +
@@ -432,7 +296,6 @@ foreach ($allSettings as $s) {