| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- <?php
- // Αρχείο: /var/www/html/hockey-cms/admin/themes.php
- require_once 'admin_auth.php';
- require_once '../config/database.php';
- session_start();
- if (!isset($_SESSION['user_id']) or$_SESSION['role_id'] != 1) {
- header("Location: ../login.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' => 'Διαχείριση Themes - Hockey CMS',
- 'header_title' => '🎨 Διαχείριση Εμφάνισης (Themes)',
- 'upload_title' => 'Μεταφόρτωση Νέου Theme (.zip)',
- 'choose_zip' => 'Επιλέξτε αρχείο Zip Θέματος',
- 'btn_upload' => 'Ανέβασμα & Εγκατάσταση',
- 'list_title' => 'Εγκατεστημένα Themes',
- 'th_name' => 'Όνομα Φακέλου Theme',
- 'th_status' => 'Κατάσταση',
- 'th_action' => 'Ενέργεια',
- 'badge_active' => 'Ενεργό',
- 'badge_inactive' => 'Ανενεργό',
- 'btn_activate' => 'Ενεργοποίηση',
- 'btn_delete' => 'Διαγραφή',
- 'in_use' => 'Σε χρήση',
- 'msg_upload_ok' => 'Το θέμα ανέβηκε και αποσυμπιέστηκε επιτυχώς!',
- 'msg_err_read' => 'Αποτυχία: Δεν ήταν δυνατή η ανάγνωση του αρχείου ZIP.',
- 'msg_err_ext' => 'Επιτρέπονται μόνο αρχεία .zip',
- 'msg_err_upload' => 'Σφάλμα κατά το ανέβασμα του αρχείου.',
- 'msg_act_ok' => 'Το ενεργό θέμα άλλαξε επιτυχώς!',
- 'msg_err_del_def' => 'Δεν μπορείτε να διαγράψετε το προεπιλεγμένο θέμα (default).',
- 'msg_err_del_act' => 'Δεν μπορείτε να διαγράψετε το θέμα που είναι αυτή τη στιγμή ενεργό. Ενεργοποιήστε πρώτα ένα άλλο.',
- 'msg_del_ok' => 'Το θέμα διαγράφηκε επιτυχώς!',
- 'msg_err_perms' => 'Σφάλμα κατά τη διαγραφή. Ελέγξτε τα δικαιώματα (permissions).'
- ],
- 'en' => [
- 'page_title' => 'Theme Management - Hockey CMS',
- 'header_title' => '🎨 Appearance Management (Themes)',
- 'upload_title' => 'Upload New Theme (.zip)',
- 'choose_zip' => 'Select Theme Zip File',
- 'btn_upload' => 'Upload & Install',
- 'list_title' => 'Installed Themes',
- 'th_name' => 'Theme Folder Name',
- 'th_status' => 'Status',
- 'th_action' => 'Action',
- 'badge_active' => 'Active',
- 'badge_inactive' => 'Inactive',
- 'btn_activate' => 'Activate',
- 'btn_delete' => 'Delete',
- 'in_use' => 'In Use',
- 'msg_upload_ok' => 'Theme uploaded and extracted successfully!',
- 'msg_err_read' => 'Failure: Could not read ZIP file.',
- 'msg_err_ext' => 'Only .zip files are allowed.',
- 'msg_err_upload' => 'Error uploading file.',
- 'msg_act_ok' => 'Active theme changed successfully!',
- 'msg_err_del_def' => 'You cannot delete the default theme.',
- 'msg_err_del_act' => 'You cannot delete the currently active theme. Activate another one first.',
- 'msg_del_ok' => 'Theme deleted successfully!',
- 'msg_err_perms' => 'Error deleting files. Check permissions.'
- ]
- ];
- $t = $translations[$current_lang];
- header('Content-Type: text/html; charset=utf-8');
- $message = '';$themes_dir = __DIR__ . '/../themes/';
- function deleteDirectory($dir) {
- if (!file_exists($dir)) { return true; }
- if (!is_dir($dir)) { return unlink($dir); }
- foreach (scandir($dir) as$item) {
- if ($item == '.' or$item == '..') { continue; }
- if (!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) { return false; }
- }
- return rmdir($dir);
- }
- try {
- $pdo->exec("CREATE TABLE IF NOT EXISTS settings (`key` VARCHAR(50) PRIMARY KEY, `value` TEXT NOT NULL)");
- } catch (Exception $e) {}
- $stmt =$pdo->prepare("SELECT value FROM settings WHERE `key` = 'active_theme'");
- $stmt->execute();
- $active_theme =$stmt->fetchColumn();
- if (!$active_theme) {$active_theme = 'default'; }
- if ($_SERVER['REQUEST_METHOD'] === 'POST' and isset($_FILES['theme_zip'])) {
- if ($_FILES['theme_zip']['error'] == 0) {
- $file_name =$_FILES['theme_zip']['name'];
- $file_tmp =$_FILES['theme_zip']['tmp_name'];
- $ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
- if ($ext === 'zip') {$zip = new ZipArchive;
- if ($zip->open($file_tmp) === TRUE) {$theme_name = pathinfo($file_name, PATHINFO_FILENAME);$target_path = $themes_dir .$theme_name;
- if (!is_dir($target_path)) { mkdir($target_path, 0755, true); }
- $zip->extractTo($target_path);
- $zip->close();$message = "<div class='alert success'>{$t['msg_upload_ok']}</div>";
- } else {
- $message = "<div class='alert error'>{$t['msg_err_read']}</div>";
- }
- } else {
- $message = "<div class='alert error'>{$t['msg_err_ext']}</div>";
- }
- } else {
- $message = "<div class='alert error'>{$t['msg_err_upload']}</div>";
- }
- }
- if (isset($_GET['activate'])) {
- $new_theme = basename($_GET['activate']);
- if (is_dir($themes_dir .$new_theme)) {
- $stmt =$pdo->prepare("REPLACE INTO settings (`key`, `value`) VALUES ('active_theme', ?)");
- $stmt->execute([$new_theme]);
- $active_theme =$new_theme;
- $message = "<div class='alert success'>{$t['msg_act_ok']}</div>";
- }
- }
- if (isset($_GET['delete'])) {
- $theme_to_delete = basename($_GET['delete']);
- if ($theme_to_delete === 'default') {$message = "<div class='alert error'>{$t['msg_err_del_def']}</div>";
- } elseif ($theme_to_delete === $active_theme) {$message = "<div class='alert error'>{$t['msg_err_del_act']}</div>";
- } else {
- $delete_path = $themes_dir .$theme_to_delete;
- if (is_dir($delete_path)) {
- if (deleteDirectory($delete_path)) {$message = "<div class='alert success'>{$t['msg_del_ok']}</div>";
- } else {
- $message = "<div class='alert error'>{$t['msg_err_perms']}</div>";
- }
- }
- }
- }
- $available_themes = [];
- if (is_dir($themes_dir)) {
- $scan = scandir($themes_dir);
- foreach ($scan as$folder) {
- if ($folder !== '.' and$folder !== '..' and is_dir($themes_dir .$folder)) {
- $available_themes[] =$folder;
- }
- }
- }
- ?>
- <!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; margin-bottom: 30px;}
-
- .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;}
- input[type="file"] { color: var(--text-main); font-family: 'Inter', sans-serif;}
-
- .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); }
-
- table { width: 100%; border-collapse: collapse; margin-top: 10px; }
- table th, table td { padding: 15px; border-bottom: 1px solid rgba(255,255,255,0.05); text-align: left; vertical-align: middle; }
- table th { background: rgba(0,0,0,0.2); color: var(--text-muted); text-transform: uppercase; font-size: 13px; font-weight: 700; }
- table td { color: var(--text-main); font-size: 15px; }
-
- .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); }
-
- .badge-active { background: #10b981; color: white; padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 800; text-transform: uppercase; }
-
- .btn-activate { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.2); padding: 8px 15px; font-size: 12px; text-decoration: none; border-radius: 6px; display: inline-block; font-weight: 700; text-transform: uppercase; transition: 0.2s;}
- .btn-activate:hover { background: #10b981; color: white; }
- .btn-delete { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2); padding: 8px 15px; font-size: 12px; text-decoration: none; border-radius: 6px; display: inline-block; margin-left: 5px; font-weight: 700; text-transform: uppercase; transition: 0.2s;}
- .btn-delete:hover { background: #ef4444; color: white; }
- </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: 1fr 2fr; gap: 30px;">
- <div class="card">
- <h3><?php echo $t['upload_title']; ?></h3>
- <form method="POST" action="themes.php" enctype="multipart/form-data">
- <div class="form-group">
- <label><?php echo $t['choose_zip']; ?></label>
- <input type="file" name="theme_zip" accept=".zip" required style="margin-bottom: 15px; display: block;">
- </div>
- <button type="submit" class="btn" style="width: 100%;"><?php echo $t['btn_upload']; ?></button>
- </form>
- </div>
- <div class="card">
- <h3><?php echo $t['list_title']; ?></h3>
- <table>
- <thead>
- <tr>
- <th><?php echo $t['th_name']; ?></th>
- <th><?php echo $t['th_status']; ?></th>
- <th><?php echo $t['th_action']; ?></th>
- </tr>
- </thead>
- <tbody>
- <?php foreach($available_themes as$th): ?>
- <tr>
- <td><strong style="font-family: monospace; font-size: 16px; color: var(--primary);"><?php echo htmlspecialchars($th); ?></strong></td>
- <td>
- <?php if ($th ===$active_theme): ?>
- <span class="badge-active"><?php echo $t['badge_active']; ?></span>
- <?php else: ?>
- <span style="color: var(--text-muted); font-size: 13px; font-weight: 600; text-transform: uppercase;"><?php echo $t['badge_inactive']; ?></span>
- <?php endif; ?>
- </td>
- <td>
- <?php if ($th !==$active_theme): ?>
- <a href="themes.php?activate=<?php echo urlencode($th); ?>" class="btn-activate"><?php echo $t['btn_activate']; ?></a>
-
- <?php if ($th !== 'default'): ?>
- <a href="themes.php?delete=<?php echo urlencode($th); ?>" class="btn-delete" onclick="return confirm('Σίγουρα διαγραφή;');"><?php echo $t['btn_delete']; ?></a>
- <?php endif; ?>
-
- <?php else: ?>
- <em style="color: var(--text-muted); font-size: 13px; font-weight: 600;"><?php echo $t['in_use']; ?></em>
- <?php endif; ?>
- </td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- </div>
- </div>
- </div>
- </body>
- </html>
|