texts.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. // Αρχείο: /var/www/html/hockey-cms/admin/texts.php
  3. session_start();
  4. if (!isset($_SESSION['user_id']) || $_SESSION['role_id'] != 1) {
  5. header("Location: ../login.php");
  6. exit;
  7. }
  8. require_once '../config/database.php';
  9. // --- Μηχανισμός Αλλαγής Γλώσσας ---
  10. if (isset($_GET['lang']) && in_array($_GET['lang'], ['el', 'en'])) {
  11. $_SESSION['lang'] = $_GET['lang'];
  12. }
  13. $current_lang = $_SESSION['lang'] ?? 'el';
  14. $translations = [
  15. 'el' => [
  16. 'page_title' => 'Διαχείριση Κειμένων & Logo - Hockey CMS',
  17. 'header_title' => '✏️ Διαχείριση Στατικών Κειμένων & Logo',
  18. 'logo_title' => '🖼️ Λογότυπο Site (Logo)',
  19. 'btn_logo' => '📤 Ανέβασμα & Αποθήκευση Logo',
  20. 'texts_title' => '📝 Δίγλωσσα Στατικά Λεκτικά',
  21. 'texts_desc' => 'Συμπληρώστε τα κείμενα και για τις δύο γλώσσες.',
  22. 'th_key' => 'Κλειδί / Περιγραφή',
  23. 'th_gr' => '🇬🇷 Ελληνικά (Greek)',
  24. 'th_en' => '🇬🇧 Αγγλικά (English)',
  25. 'btn_save' => '💾 Αποθήκευση Γλωσσών',
  26. 'msg_texts_ok' => 'Όλα τα δίγλωσσα κείμενα ενημερώθηκαν επιτυχώς!',
  27. 'msg_logo_ok' => 'Το λογότυπο ανέβηκε επιτυχώς!',
  28. 'msg_err_type' => 'Μη επιτρεπτός τύπος αρχείου.',
  29. 'msg_err_sql' => 'Προσοχή: Δεν βρέθηκαν τα πεδία. Τρέξατε το SQL query;',
  30. 'no_texts' => 'Δεν βρέθηκαν κείμενα στη βάση.'
  31. ],
  32. 'en' => [
  33. 'page_title' => 'Texts & Logo Management - Hockey CMS',
  34. 'header_title' => '✏️ Static Texts & Logo Management',
  35. 'logo_title' => '🖼️ Site Logo',
  36. 'btn_logo' => '📤 Upload & Save Logo',
  37. 'texts_title' => '📝 Bilingual Static Texts',
  38. 'texts_desc' => 'Fill in the texts for both languages.',
  39. 'th_key' => 'Key / Description',
  40. 'th_gr' => '🇬🇷 Greek',
  41. 'th_en' => '🇬🇧 English',
  42. 'btn_save' => '💾 Save Languages',
  43. 'msg_texts_ok' => 'All bilingual texts updated successfully!',
  44. 'msg_logo_ok' => 'Logo uploaded successfully!',
  45. 'msg_err_type' => 'Invalid file type.',
  46. 'msg_err_sql' => 'Warning: Fields not found. Did you run the SQL query?',
  47. 'no_texts' => 'No texts found in database.'
  48. ]
  49. ];
  50. $t = $translations[$current_lang];
  51. header('Content-Type: text/html; charset=utf-8');
  52. $message = '';
  53. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_texts'])) {
  54. try {
  55. $pdo->beginTransaction();
  56. $stmt = $pdo->prepare("UPDATE site_texts SET text_value_el = ?, text_value_en = ? WHERE text_key = ?");
  57. if (isset($_POST['texts_el']) && is_array($_POST['texts_el'])) {
  58. foreach ($_POST['texts_el'] as $key => $val_el) {
  59. $val_en = isset($_POST['texts_en'][$key]) ? $_POST['texts_en'][$key] : '';
  60. $stmt->execute([trim($val_el), trim($val_en), $key]);
  61. }
  62. }
  63. $pdo->commit();
  64. $message = "<div class='alert success'>{$t['msg_texts_ok']}</div>";
  65. } catch (Exception $e) {
  66. $pdo->rollBack();
  67. $message = "<div class='alert error'>Σφάλμα: " . $e->getMessage() . "</div>";
  68. }
  69. }
  70. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['upload_logo'])) {
  71. if (isset($_FILES['logo_file']) && $_FILES['logo_file']['error'] === UPLOAD_ERR_OK) {
  72. $upload_dir = __DIR__ . '/../uploads/';
  73. if (!is_dir($upload_dir)) { @mkdir($upload_dir, 0755, true); }
  74. $file_extension = strtolower(pathinfo($_FILES['logo_file']['name'], PATHINFO_EXTENSION));
  75. $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'];
  76. if (in_array($file_extension, $allowed_extensions)) {
  77. $filename = 'logo_' . time() . '.' . $file_extension;
  78. $target_path = $upload_dir . $filename;
  79. if (move_uploaded_file($_FILES['logo_file']['tmp_name'], $target_path)) {
  80. $logo_url = 'uploads/' . $filename;
  81. try {
  82. $stmtCheck = $pdo->prepare("SELECT COUNT(*) FROM settings WHERE `key` = 'site_logo'");
  83. $stmtCheck->execute();
  84. if ($stmtCheck->fetchColumn() > 0) {
  85. $stmtUpd = $pdo->prepare("UPDATE settings SET value = ? WHERE `key` = 'site_logo'");
  86. $stmtUpd->execute([$logo_url]);
  87. } else {
  88. $stmtIns = $pdo->prepare("INSERT INTO settings (`key`, value) VALUES ('site_logo', ?)");
  89. $stmtIns->execute([$logo_url]);
  90. }
  91. $message = "<div class='alert success'>{$t['msg_logo_ok']}</div>";
  92. } catch (Exception $e) {
  93. $message = "<div class='alert error'>Σφάλμα: " . $e->getMessage() . "</div>";
  94. }
  95. }
  96. } else {
  97. $message = "<div class='alert error'>{$t['msg_err_type']}</div>";
  98. }
  99. }
  100. }
  101. $current_logo = '';
  102. try {
  103. $logoStmt = $pdo->prepare("SELECT value FROM settings WHERE `key` = 'site_logo'");
  104. $logoStmt->execute();
  105. $current_logo = $logoStmt->fetchColumn();
  106. } catch (Exception $e) {}
  107. $texts = [];
  108. try {
  109. $texts = $pdo->query("SELECT * FROM site_texts ORDER BY description ASC")->fetchAll(PDO::FETCH_ASSOC);
  110. } catch (Exception $e) {
  111. $message = "<div class='alert error'>{$t['msg_err_sql']}</div>";
  112. }
  113. ?>
  114. <!DOCTYPE html>
  115. <html lang="<?php echo $current_lang; ?>">
  116. <head>
  117. <meta charset="UTF-8">
  118. <title><?php echo $t['page_title']; ?></title>
  119. <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
  120. <style>
  121. :root {
  122. --primary: #f97316;
  123. --primary-hover: #ea580c;
  124. --bg-color: #0b1120;
  125. --panel-bg: #1e293b;
  126. --border-color: #334155;
  127. --text-main: #f8fafc;
  128. --text-muted: #94a3b8;
  129. }
  130. body { font-family: 'Inter', sans-serif; background-color: var(--bg-color); color: var(--text-main); margin: 0; }
  131. .content { margin-left: 250px; padding: 30px; }
  132. .content h2 { margin-top: 0; color: var(--primary); font-size: 26px; text-transform: uppercase; letter-spacing: 0.5px; }
  133. .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; }
  134. .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; }
  135. table { width: 100%; border-collapse: collapse; margin-top: 15px; }
  136. table th, table td { padding: 15px; border-bottom: 1px solid rgba(255,255,255,0.05); text-align: left; vertical-align: top; }
  137. table th { background: rgba(0,0,0,0.2); color: var(--text-muted); text-transform: uppercase; font-size: 13px; font-weight: 700; }
  138. input[type="file"] { color: var(--text-main); font-family: 'Inter', sans-serif;}
  139. 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; }
  140. textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.2); }
  141. .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; }
  142. .btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
  143. .btn-success { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.2); }
  144. .btn-success:hover { background: #10b981; color: white; }
  145. .alert { padding: 15px; border-radius: 6px; margin-bottom: 20px; font-weight: 600; font-size: 14px;}
  146. .success { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.2); }
  147. .error { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2); }
  148. .desc-text { font-size: 12px; color: var(--text-muted); display: block; margin-top: 6px; line-height: 1.4; }
  149. .lang-label { font-size: 11px; font-weight: 800; color: #3b82f6; display: block; margin-bottom: 6px; letter-spacing: 0.5px;}
  150. </style>
  151. </head>
  152. <body>
  153. <?php include 'sidebar.php'; ?>
  154. <div class="content">
  155. <h2><?php echo $t['header_title']; ?></h2>
  156. <?php echo $message; ?>
  157. <div class="card">
  158. <h3><?php echo $t['logo_title']; ?></h3>
  159. <?php if ($current_logo): ?>
  160. <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);">
  161. <img src="../<?php echo htmlspecialchars($current_logo); ?>" style="max-height: 45px; display: block;">
  162. </div>
  163. <?php endif; ?>
  164. <form method="POST" enctype="multipart/form-data">
  165. <input type="file" name="logo_file" accept="image/*" required style="margin-bottom: 20px; display: block;">
  166. <button type="submit" name="upload_logo" value="1" class="btn btn-success"><?php echo $t['btn_logo']; ?></button>
  167. </form>
  168. </div>
  169. <div class="card">
  170. <h3><?php echo $t['texts_title']; ?></h3>
  171. <p style="font-size: 13px; color: var(--text-muted); margin-bottom: 20px;"><?php echo $t['texts_desc']; ?></p>
  172. <form method="POST">
  173. <table>
  174. <thead>
  175. <tr>
  176. <th style="width: 25%;"><?php echo $t['th_key']; ?></th>
  177. <th style="width: 37.5%;"><?php echo $t['th_gr']; ?></th>
  178. <th style="width: 37.5%;"><?php echo $t['th_en']; ?></th>
  179. </tr>
  180. </thead>
  181. <tbody>
  182. <?php
  183. if (!empty($texts)) {
  184. foreach($texts as $text_row) {
  185. echo "<tr>";
  186. 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>";
  187. echo "<td>";
  188. echo "<span class='lang-label'>GR</span>";
  189. echo "<textarea name='texts_el[" . htmlspecialchars($text_row['text_key']) . "]' rows='3'>" . htmlspecialchars($text_row['text_value_el'] ?? '', ENT_QUOTES) . "</textarea>";
  190. echo "</td>";
  191. echo "<td>";
  192. echo "<span class='lang-label'>EN</span>";
  193. echo "<textarea name='texts_en[" . htmlspecialchars($text_row['text_key']) . "]' rows='3'>" . htmlspecialchars($text_row['text_value_en'] ?? '', ENT_QUOTES) . "</textarea>";
  194. echo "</td>";
  195. echo "</tr>";
  196. }
  197. } else {
  198. echo "<tr><td colspan='3' style='text-align:center; padding:30px; color:var(--text-muted);'>{$t['no_texts']}</td></tr>";
  199. }
  200. ?>
  201. </tbody>
  202. </table>
  203. <br>
  204. <button type="submit" name="update_texts" value="1" class="btn"><?php echo $t['btn_save']; ?></button>
  205. </form>
  206. </div>
  207. </div>
  208. </body>
  209. </html>