| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <?php
- // Αρχείο: /var/www/html/hockey-cms/admin/texts.php
- session_start();
- if (!isset($_SESSION['user_id']) || $_SESSION['role_id'] != 1) {
- header("Location: ../login.php");
- exit;
- }
- require_once '../config/database.php';
- // --- Μηχανισμός Αλλαγής Γλώσσας ---
- if (isset($_GET['lang']) && in_array($_GET['lang'], ['el', 'en'])) {
- $_SESSION['lang'] = $_GET['lang'];
- }
- $current_lang = $_SESSION['lang'] ?? 'el';
- $translations = [
- 'el' => [
- 'page_title' => 'Διαχείριση Κειμένων & Logo - Hockey CMS',
- 'header_title' => '✏️ Διαχείριση Στατικών Κειμένων & Logo',
- 'logo_title' => '🖼️ Λογότυπο Site (Logo)',
- 'btn_logo' => '📤 Ανέβασμα & Αποθήκευση Logo',
- 'texts_title' => '📝 Δίγλωσσα Στατικά Λεκτικά',
- 'texts_desc' => 'Συμπληρώστε τα κείμενα και για τις δύο γλώσσες.',
- 'th_key' => 'Κλειδί / Περιγραφή',
- 'th_gr' => '🇬🇷 Ελληνικά (Greek)',
- 'th_en' => '🇬🇧 Αγγλικά (English)',
- 'btn_save' => '💾 Αποθήκευση Γλωσσών',
- 'msg_texts_ok' => 'Όλα τα δίγλωσσα κείμενα ενημερώθηκαν επιτυχώς!',
- 'msg_logo_ok' => 'Το λογότυπο ανέβηκε επιτυχώς!',
- 'msg_err_type' => 'Μη επιτρεπτός τύπος αρχείου.',
- 'msg_err_sql' => 'Προσοχή: Δεν βρέθηκαν τα πεδία. Τρέξατε το SQL query;',
- 'no_texts' => 'Δεν βρέθηκαν κείμενα στη βάση.'
- ],
- 'en' => [
- 'page_title' => 'Texts & Logo Management - Hockey CMS',
- 'header_title' => '✏️ Static Texts & Logo Management',
- 'logo_title' => '🖼️ Site Logo',
- 'btn_logo' => '📤 Upload & Save Logo',
- 'texts_title' => '📝 Bilingual Static Texts',
- 'texts_desc' => 'Fill in the texts for both languages.',
- 'th_key' => 'Key / Description',
- 'th_gr' => '🇬🇷 Greek',
- 'th_en' => '🇬🇧 English',
- 'btn_save' => '💾 Save Languages',
- 'msg_texts_ok' => 'All bilingual texts updated successfully!',
- 'msg_logo_ok' => 'Logo uploaded successfully!',
- 'msg_err_type' => 'Invalid file type.',
- 'msg_err_sql' => 'Warning: Fields not found. Did you run the SQL query?',
- 'no_texts' => 'No texts found in database.'
- ]
- ];
- $t = $translations[$current_lang];
- header('Content-Type: text/html; charset=utf-8');
- $message = '';
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_texts'])) {
- try {
- $pdo->beginTransaction();
- $stmt = $pdo->prepare("UPDATE site_texts SET text_value_el = ?, text_value_en = ? WHERE text_key = ?");
-
- if (isset($_POST['texts_el']) && is_array($_POST['texts_el'])) {
- foreach ($_POST['texts_el'] as $key => $val_el) {
- $val_en = isset($_POST['texts_en'][$key]) ? $_POST['texts_en'][$key] : '';
- $stmt->execute([trim($val_el), trim($val_en), $key]);
- }
- }
- $pdo->commit();
- $message = "<div class='alert success'>{$t['msg_texts_ok']}</div>";
- } catch (Exception $e) {
- $pdo->rollBack();
- $message = "<div class='alert error'>Σφάλμα: " . $e->getMessage() . "</div>";
- }
- }
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['upload_logo'])) {
- if (isset($_FILES['logo_file']) && $_FILES['logo_file']['error'] === UPLOAD_ERR_OK) {
- $upload_dir = __DIR__ . '/../uploads/';
- if (!is_dir($upload_dir)) { @mkdir($upload_dir, 0755, true); }
- $file_extension = strtolower(pathinfo($_FILES['logo_file']['name'], PATHINFO_EXTENSION));
- $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'];
-
- if (in_array($file_extension, $allowed_extensions)) {
- $filename = 'logo_' . time() . '.' . $file_extension;
- $target_path = $upload_dir . $filename;
-
- if (move_uploaded_file($_FILES['logo_file']['tmp_name'], $target_path)) {
- $logo_url = 'uploads/' . $filename;
- try {
- $stmtCheck = $pdo->prepare("SELECT COUNT(*) FROM settings WHERE `key` = 'site_logo'");
- $stmtCheck->execute();
- if ($stmtCheck->fetchColumn() > 0) {
- $stmtUpd = $pdo->prepare("UPDATE settings SET value = ? WHERE `key` = 'site_logo'");
- $stmtUpd->execute([$logo_url]);
- } else {
- $stmtIns = $pdo->prepare("INSERT INTO settings (`key`, value) VALUES ('site_logo', ?)");
- $stmtIns->execute([$logo_url]);
- }
- $message = "<div class='alert success'>{$t['msg_logo_ok']}</div>";
- } catch (Exception $e) {
- $message = "<div class='alert error'>Σφάλμα: " . $e->getMessage() . "</div>";
- }
- }
- } else {
- $message = "<div class='alert error'>{$t['msg_err_type']}</div>";
- }
- }
- }
- $current_logo = '';
- try {
- $logoStmt = $pdo->prepare("SELECT value FROM settings WHERE `key` = 'site_logo'");
- $logoStmt->execute();
- $current_logo = $logoStmt->fetchColumn();
- } catch (Exception $e) {}
- $texts = [];
- try {
- $texts = $pdo->query("SELECT * FROM site_texts ORDER BY description ASC")->fetchAll(PDO::FETCH_ASSOC);
- } catch (Exception $e) {
- $message = "<div class='alert error'>{$t['msg_err_sql']}</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; }
-
- table { width: 100%; border-collapse: collapse; margin-top: 15px; }
- table th, table td { padding: 15px; border-bottom: 1px solid rgba(255,255,255,0.05); text-align: left; vertical-align: top; }
- table th { background: rgba(0,0,0,0.2); color: var(--text-muted); text-transform: uppercase; font-size: 13px; font-weight: 700; }
-
- input[type="file"] { color: var(--text-main); font-family: 'Inter', sans-serif;}
- textarea { width: 100%; padding: 12px; background: #0f172a; border: 1px solid var(--border-color); color: var(--text-main); border-radius: 6px; font-family: 'Inter', sans-serif; font-size: 14px; box-sizing: border-box; resize: vertical; outline: none; transition: 0.2s; }
- textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.2); }
-
- .btn { padding: 12px 25px; 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-success { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.2); }
- .btn-success: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); }
-
- .desc-text { font-size: 12px; color: var(--text-muted); display: block; margin-top: 6px; line-height: 1.4; }
- .lang-label { font-size: 11px; font-weight: 800; color: #3b82f6; display: block; margin-bottom: 6px; letter-spacing: 0.5px;}
- </style>
- </head>
- <body>
- <?php include 'sidebar.php'; ?>
- <div class="content">
- <h2><?php echo $t['header_title']; ?></h2>
- <?php echo $message; ?>
- <div class="card">
- <h3><?php echo $t['logo_title']; ?></h3>
- <?php if ($current_logo): ?>
- <div style="margin-bottom: 20px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; display: inline-block; border: 1px solid var(--border-color);">
- <img src="../<?php echo htmlspecialchars($current_logo); ?>" style="max-height: 45px; display: block;">
- </div>
- <?php endif; ?>
- <form method="POST" enctype="multipart/form-data">
- <input type="file" name="logo_file" accept="image/*" required style="margin-bottom: 20px; display: block;">
- <button type="submit" name="upload_logo" value="1" class="btn btn-success"><?php echo $t['btn_logo']; ?></button>
- </form>
- </div>
- <div class="card">
- <h3><?php echo $t['texts_title']; ?></h3>
- <p style="font-size: 13px; color: var(--text-muted); margin-bottom: 20px;"><?php echo $t['texts_desc']; ?></p>
-
- <form method="POST">
- <table>
- <thead>
- <tr>
- <th style="width: 25%;"><?php echo $t['th_key']; ?></th>
- <th style="width: 37.5%;"><?php echo $t['th_gr']; ?></th>
- <th style="width: 37.5%;"><?php echo $t['th_en']; ?></th>
- </tr>
- </thead>
- <tbody>
- <?php
- if (!empty($texts)) {
- foreach($texts as $text_row) {
- echo "<tr>";
- echo "<td><strong style='color: var(--text-main); font-size: 14px;'>" . htmlspecialchars($text_row['text_key']) . "</strong><span class='desc-text'>" . htmlspecialchars($text_row['description']) . "</span></td>";
-
- echo "<td>";
- echo "<span class='lang-label'>GR</span>";
- echo "<textarea name='texts_el[" . htmlspecialchars($text_row['text_key']) . "]' rows='3'>" . htmlspecialchars($text_row['text_value_el'] ?? '', ENT_QUOTES) . "</textarea>";
- echo "</td>";
- echo "<td>";
- echo "<span class='lang-label'>EN</span>";
- echo "<textarea name='texts_en[" . htmlspecialchars($text_row['text_key']) . "]' rows='3'>" . htmlspecialchars($text_row['text_value_en'] ?? '', ENT_QUOTES) . "</textarea>";
- echo "</td>";
- echo "</tr>";
- }
- } else {
- echo "<tr><td colspan='3' style='text-align:center; padding:30px; color:var(--text-muted);'>{$t['no_texts']}</td></tr>";
- }
- ?>
- </tbody>
- </table>
- <br>
- <button type="submit" name="update_texts" value="1" class="btn"><?php echo $t['btn_save']; ?></button>
- </form>
- </div>
- </div>
- </body>
- </html>
|