[ 'page_title' => 'Ρυθμίσεις SMS (Brevo) - Hockey CMS', 'header_title' => 'Ρυθμίσεις SMS (Brevo API)', 'api_details' => 'Στοιχεία Σύνδεσης Brevo', 'api_instructions' => 'Οδηγίες: Κάντε δωρεάν εγγραφή στο Brevo, πηγαίνετε στις ρυθμίσεις του λογαριασμού σας (SMTP & API) και δημιουργήστε ένα νέο API v3 Key.', 'api_key' => 'Brevo API Key *', 'sender_name' => 'Όνομα Αποστολέα SMS (Sender Name) *', 'sender_hint' => 'Το όνομα που θα φαίνεται στον παραλήπτη (μόνο λατινικοί χαρακτήρες, έως 11 γράμματα).', 'btn_save' => '💾 Αποθήκευση Ρυθμίσεων', 'test_title' => 'Δοκιμή Αποστολής SMS', 'test_desc' => 'Στείλτε ένα δοκιμαστικό SMS στο κινητό σας (με κωδικό χώρας, π.χ. +3069...).', 'test_phone' => 'Αριθμός Κινητού Παραλήπτη', 'test_text' => 'Κείμενο Μηνύματος', 'btn_test' => '💬 Αποστολή SMS', 'msg_save_ok' => 'Οι ρυθμίσεις SMS αποθηκεύτηκαν επιτυχώς!', 'msg_err_empty' => 'Συμπληρώστε το Brevo API Key και τον αριθμό παραλήπτη!', 'msg_test_ok' => 'Το δοκιμαστικό SMS στάλθηκε επιτυχώς στο ', 'msg_err_api' => 'Αποτυχία αποστολής SMS' ], 'en' => [ 'page_title' => 'SMS Settings (Brevo) - Hockey CMS', 'header_title' => 'SMS Settings (Brevo API)', 'api_details' => 'Brevo Connection Details', 'api_instructions' => 'Instructions: Register for free on Brevo, go to your account settings (SMTP & API) and create a new API v3 Key.', 'api_key' => 'Brevo API Key *', 'sender_name' => 'SMS Sender Name *', 'sender_hint' => 'The name the recipient will see (Latin characters only, up to 11 letters).', 'btn_save' => '💾 Save Settings', 'test_title' => 'Test SMS Delivery', 'test_desc' => 'Send a test SMS to your mobile phone (with country code, e.g. +3069...).', 'test_phone' => 'Recipient Mobile Number', 'test_text' => 'Message Text', 'btn_test' => '💬 Send SMS', 'msg_save_ok' => 'SMS settings saved successfully!', 'msg_err_empty' => 'Please fill in the Brevo API Key and the recipient number!', 'msg_test_ok' => 'Test SMS sent successfully to ', 'msg_err_api' => 'SMS Delivery Failed' ] ]; $t = $translations[$current_lang]; header('Content-Type: text/html; charset=utf-8'); $message = ''; $setting_keys = ['brevo_api_key', 'brevo_sender_name']; // --- 1. ΑΠΟΘΗΚΕΥΣΗ ΡΥΘΜΙΣΕΩΝ --- if ($_SERVER['REQUEST_METHOD'] === 'POST' and isset($_POST['action']) and$_POST['action'] == 'save_settings') { try { $pdo->beginTransaction(); foreach ($setting_keys as $key) {$value = trim($_POST[$key] ?? ''); $check =$pdo->prepare("SELECT COUNT(*) FROM settings WHERE `key` = ?"); $check->execute([$key]); if ($check->fetchColumn() > 0) { $stmt =$pdo->prepare("UPDATE settings SET `value` = ? WHERE `key` = ?"); $stmt->execute([$value,$key]); } else { $stmt =$pdo->prepare("INSERT INTO settings (`key`, `value`) VALUES (?, ?)"); $stmt->execute([$key,$value]); } } $pdo->commit();$message = "
{$t['msg_save_ok']}
"; } catch (PDOException $e) { $pdo->rollBack();$message = "
Σφάλμα αποθήκευσης: " . $e->getMessage() . "
"; } } // --- Ανάγνωση υφιστάμενων ρυθμίσεων --- $current_settings = []; $stmt =$pdo->query("SELECT `key`, `value` FROM settings WHERE `key` IN ('" . implode("','", $setting_keys) . "')"); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {$current_settings[$row['key']] =$row['value']; } // --- 2. ΑΠΟΣΤΟΛΗ ΔΟΚΙΜΑΣΤΙΚΟΥ SMS --- if ($_SERVER['REQUEST_METHOD'] === 'POST' and isset($_POST['action']) and$_POST['action'] == 'test_sms') { $test_phone = trim($_POST['test_phone']); $test_text = trim($_POST['test_text']); $api_key =$current_settings['brevo_api_key'] ?? ''; $sender =$current_settings['brevo_sender_name'] ?? 'HockeyShop'; if (empty($test_phone) or empty($api_key)) {$message = "
{$t['msg_err_empty']}
"; } else { $url = "https://api.brevo.com/v3/transactionalSMS/sms"; $data = [ "sender" => $sender, "recipient" => $test_phone, "content" => $test_text, "type" => "transactional" ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "accept: application/json", "api-key: " . $api_key, "content-type: application/json" ]); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($http_code === 201 or $http_code === 200) {$message = "
{$t['msg_test_ok']} {$test_phone}!
"; } else { $message = "
{$t['msg_err_api']} (HTTP Code: {$http_code}).
{$response}
"; } } } ?> <?php echo $t['page_title']; ?>