| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?php
- // Αρχείο: /var/www/html/hockey-cms/admin/sms_settings.php
- require_once 'admin_auth.php';
- require_once '../config/database.php';
- if (!isset($_SESSION['user_id']) or$_SESSION['role_id'] != 1) {
- header("Location: ../index.php");
- exit;
- }
- // --- Μηχανισμός Αλλαγής Γλώσσας ---
- if (isset($_GET['lang']) && in_array($_GET['lang'], ['el', 'en'])) {
- $_SESSION['lang'] =$_GET['lang'];
- }
- $current_lang =$_SESSION['lang'] ?? 'el';
- $translations = [
- 'el' => [
- 'page_title' => 'Ρυθμίσεις SMS (Brevo) - Hockey CMS',
- 'header_title' => 'Ρυθμίσεις SMS (Brevo API)',
- 'api_details' => 'Στοιχεία Σύνδεσης Brevo',
- 'api_instructions' => 'Οδηγίες: Κάντε δωρεάν εγγραφή στο <a href="https://www.brevo.com/" target="_blank" style="color: #60a5fa;">Brevo</a>, πηγαίνετε στις ρυθμίσεις του λογαριασμού σας (SMTP & API) και δημιουργήστε ένα νέο <strong>API v3 Key</strong>.',
- '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 <a href="https://www.brevo.com/" target="_blank" style="color: #60a5fa;">Brevo</a>, go to your account settings (SMTP & API) and create a new <strong>API v3 Key</strong>.',
- '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 = "<div class='alert success'>{$t['msg_save_ok']}</div>";
- } catch (PDOException $e) {
- $pdo->rollBack();$message = "<div class='alert error'>Σφάλμα αποθήκευσης: " . $e->getMessage() . "</div>";
- }
- }
- // --- Ανάγνωση υφιστάμενων ρυθμίσεων ---
- $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 = "<div class='alert error'>{$t['msg_err_empty']}</div>";
- } 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 = "<div class='alert success'>{$t['msg_test_ok']} <strong>{$test_phone}</strong>!</div>";
- } else {
- $message = "<div class='alert error'>{$t['msg_err_api']} (HTTP Code: {$http_code}). <br><small>{$response}</small></div>";
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="<?php echo $current_lang; ?>">
- <head>
- <meta charset="UTF-8">
- <title><?php echo $t['page_title']; ?></title>
- <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
- <style>
- :root {
- --primary: #f97316;
- --primary-hover: #ea580c;
- --bg-color: #0b1120;
- --panel-bg: #1e293b;
- --border-color: #334155;
- --text-main: #f8fafc;
- --text-muted: #94a3b8;
- }
- body { font-family: 'Inter', sans-serif; background-color: var(--bg-color); color: var(--text-main); margin: 0; }
- .content { margin-left: 250px; padding: 30px; }
- .content h2 { margin-top: 0; color: var(--primary); font-size: 26px; text-transform: uppercase; letter-spacing: 0.5px; }
-
- .card { background: var(--panel-bg); padding: 25px; border-radius: 8px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3); border: 1px solid var(--border-color); margin-bottom: 25px; }
- .card h3 { margin-top: 0; color: var(--text-main); border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 15px; font-size: 18px; text-transform: uppercase; letter-spacing: 0.5px; }
-
- .form-group { margin-bottom: 20px; }
- .form-group label { display: block; margin-bottom: 8px; font-weight: 700; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;}
- .form-group input, .form-group textarea { width: 100%; padding: 12px; background: #0f172a; border: 1px solid var(--border-color); color: var(--text-main); border-radius: 6px; box-sizing: border-box; font-family: 'Inter', sans-serif; outline: none; transition: 0.2s; }
- .form-group input:focus, .form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.2); }
-
- .btn { padding: 12px 20px; background: var(--primary); color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: 800; font-size: 14px; text-transform: uppercase; transition: 0.2s; }
- .btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
- .btn-test { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.2); }
- .btn-test:hover { background: #10b981; color: white; }
-
- .alert { padding: 15px; border-radius: 6px; margin-bottom: 20px; font-weight: 600; font-size: 14px;}
- .success { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.2); }
- .error { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2); }
-
- .info-box { background: rgba(59, 130, 246, 0.1); border-left: 4px solid #3b82f6; padding: 15px; border-radius: 4px; font-size: 13px; color: #60a5fa; margin-bottom: 20px; line-height: 1.5; }
- </style>
- </head>
- <body>
-
- <?php include 'sidebar.php'; ?>
- <div class="content">
- <h2><?php echo $t['header_title']; ?></h2>
- <?php echo $message; ?>
- <div style="display: grid; grid-template-columns: 2fr 1fr; gap: 25px;">
-
- <div class="card">
- <h3><?php echo $t['api_details']; ?></h3>
-
- <div class="info-box">
- <?php echo $t['api_instructions']; ?>
- </div>
- <form method="POST" action="sms_settings.php">
- <input type="hidden" name="action" value="save_settings">
-
- <div class="form-group">
- <label><?php echo $t['api_key']; ?></label>
- <input type="password" name="brevo_api_key" value="<?php echo htmlspecialchars($current_settings['brevo_api_key'] ?? ''); ?>" placeholder="xkeysib-..." required>
- </div>
- <div class="form-group">
- <label><?php echo $t['sender_name']; ?></label>
- <input type="text" name="brevo_sender_name" value="<?php echo htmlspecialchars($current_settings['brevo_sender_name'] ?? 'HockeyShop'); ?>" maxlength="11" placeholder="HockeyShop" required>
- <small style="color: var(--text-muted);"><?php echo $t['sender_hint']; ?></small>
- </div>
-
- <button type="submit" class="btn"><?php echo $t['btn_save']; ?></button>
- </form>
- </div>
- <div class="card" style="height: fit-content;">
- <h3><?php echo $t['test_title']; ?></h3>
- <p style="font-size: 13px; color: var(--text-muted); margin-bottom: 20px;"><?php echo $t['test_desc']; ?></p>
-
- <form method="POST" action="sms_settings.php">
- <input type="hidden" name="action" value="test_sms">
- <div class="form-group">
- <label><?php echo $t['test_phone']; ?></label>
- <input type="text" name="test_phone" value="+30" placeholder="+306912345678" required>
- </div>
- <div class="form-group">
- <label><?php echo $t['test_text']; ?></label>
- <textarea name="test_text" rows="3" required>Γεια σας! Αυτό είναι ένα δοκιμαστικό SMS από το Hockey CMS.</textarea>
- </div>
- <button type="submit" class="btn btn-test"><?php echo $t['btn_test']; ?></button>
- </form>
- </div>
-
- </div>
- </div>
- </body>
- </html>
|