| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- <?php
- // Αρχείο: /var/www/html/hockey-cms/admin/attributes.php
- require_once 'admin_auth.php';
- 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' => 'Χαρακτηριστικά - Hockey CMS',
- 'header_title' => 'Διαχείριση Χαρακτηριστικών Εξοπλισμού',
- 'edit_group' => '✏️ Επεξεργασία Ομάδας',
- 'new_group' => '📁 Νέα Ομάδα (Group)',
- 'name_gr' => 'Όνομα 🇬🇷 (GR) *',
- 'name_en' => 'Όνομα 🇬🇧 (EN)',
- 'btn_save_group' => 'Αποθήκευση Ομάδας',
- 'btn_add_group' => 'Προσθήκη Ομάδας',
- 'edit_attr' => '✏️ Επεξεργασία Χαρακτηριστικού',
- 'new_attr' => '⚡ Νέο Χαρακτηριστικό',
- 'belongs_group' => 'Ανήκει στην Ομάδα *',
- 'select_group' => '-- Επίλεξε Ομάδα --',
- 'unit' => 'Μονάδα Μέτρησης (Προαιρετικό)',
- 'btn_save_attr' => 'Αποθήκευση Χαρακ.',
- 'btn_add_attr' => 'Προσθήκη Χαρακτηριστικού',
- 'existing_groups' => '📁 Υπάρχουσες Ομάδες',
- 'group_name' => 'Όνομα Ομάδας',
- 'actions' => 'Ενέργειες',
- 'no_groups' => 'Δεν υπάρχουν ομάδες.',
- 'existing_attrs' => '⚡ Υπάρχοντα Χαρακτηριστικά',
- 'attr_name' => 'Χαρακτηριστικό',
- 'no_attrs' => 'Δεν υπάρχουν χαρακτηριστικά.',
- 'btn_cancel' => 'Ακύρωση',
- 'msg_group_ok' => 'Η ομάδα δημιουργήθηκε!',
- 'msg_group_upd' => 'Η ομάδα ενημερώθηκε!',
- 'msg_attr_ok' => 'Το χαρακτηριστικό προστέθηκε!',
- 'msg_attr_upd' => 'Το χαρακτηριστικό ενημερώθηκε!',
- 'msg_group_del' => 'Η ομάδα διαγράφηκε επιτυχώς!',
- 'msg_attr_del' => 'Το χαρακτηριστικό διαγράφηκε επιτυχώς!',
- 'confirm_del_grp' => 'Σίγουρα διαγραφή της ομάδας;',
- 'confirm_del_attr' => 'Σίγουρα διαγραφή του χαρακτηριστικού;'
- ],
- 'en' => [
- 'page_title' => 'Attributes - Hockey CMS',
- 'header_title' => 'Equipment Attributes Management',
- 'edit_group' => '✏️ Edit Group',
- 'new_group' => '📁 New Group',
- 'name_gr' => 'Name 🇬🇷 (GR) *',
- 'name_en' => 'Name 🇬🇧 (EN)',
- 'btn_save_group' => 'Save Group',
- 'btn_add_group' => 'Add Group',
- 'edit_attr' => '✏️ Edit Attribute',
- 'new_attr' => '⚡ New Attribute',
- 'belongs_group' => 'Belongs to Group *',
- 'select_group' => '-- Select Group --',
- 'unit' => 'Unit of Measurement (Optional)',
- 'btn_save_attr' => 'Save Attr.',
- 'btn_add_attr' => 'Add Attribute',
- 'existing_groups' => '📁 Existing Groups',
- 'group_name' => 'Group Name',
- 'actions' => 'Actions',
- 'no_groups' => 'No groups found.',
- 'existing_attrs' => '⚡ Existing Attributes',
- 'attr_name' => 'Attribute',
- 'no_attrs' => 'No attributes found.',
- 'btn_cancel' => 'Cancel',
- 'msg_group_ok' => 'Group created!',
- 'msg_group_upd' => 'Group updated!',
- 'msg_attr_ok' => 'Attribute added!',
- 'msg_attr_upd' => 'Attribute updated!',
- 'msg_group_del' => 'Group deleted successfully!',
- 'msg_attr_del' => 'Attribute deleted successfully!',
- 'confirm_del_grp' => 'Are you sure you want to delete this group?',
- 'confirm_del_attr' => 'Are you sure you want to delete this attribute?'
- ]
- ];
- $t = $translations[$current_lang];
- header('Content-Type: text/html; charset=utf-8');
- $message = '';
- // ==========================================
- // 1. ΧΕΙΡΙΣΜΟΣ POST (Προσθήκη / Επεξεργασία)
- // ==========================================
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
- $action = $_POST['action'];
- if ($action === 'add_group' || $action === 'edit_group') {
- $name = trim($_POST['name']);
- $name_en = trim($_POST['name_en']);
-
- if (!empty($name)) {
- try {
- if ($action === 'add_group') {
- $stmt = $pdo->prepare("INSERT INTO attribute_groups (name, name_en) VALUES (?, ?)");
- $stmt->execute([$name, $name_en]);
- $message = "<div class='alert success'>{$t['msg_group_ok']}</div>";
- } else {
- $group_id = (int)$_POST['group_id'];
- $stmt = $pdo->prepare("UPDATE attribute_groups SET name = ?, name_en = ? WHERE id = ?");
- $stmt->execute([$name, $name_en, $group_id]);
- $message = "<div class='alert success'>{$t['msg_group_upd']}</div>";
- }
- } catch (Exception $e) {
- $message = "<div class='alert error'>Σφάλμα: " . $e->getMessage() . "</div>";
- }
- }
- }
- if ($action === 'add_attr' || $action === 'edit_attr') {
- $group_id = (int)$_POST['group_id'];
- $name = trim($_POST['name']);
- $name_en = trim($_POST['name_en']);
- $unit = trim($_POST['unit']);
-
- if (!empty($group_id) && !empty($name)) {
- try {
- if ($action === 'add_attr') {
- $stmt = $pdo->prepare("INSERT INTO attributes (group_id, name, name_en, unit) VALUES (?, ?, ?, ?)");
- $stmt->execute([$group_id, $name, $name_en, $unit]);
- $message = "<div class='alert success'>{$t['msg_attr_ok']}</div>";
- } else {
- $attr_id = (int)$_POST['attr_id'];
- $stmt = $pdo->prepare("UPDATE attributes SET group_id = ?, name = ?, name_en = ?, unit = ? WHERE id = ?");
- $stmt->execute([$group_id, $name, $name_en, $unit, $attr_id]);
- $message = "<div class='alert success'>{$t['msg_attr_upd']}</div>";
- }
- } catch (Exception $e) {
- $message = "<div class='alert error'>Σφάλμα: " . $e->getMessage() . "</div>";
- }
- }
- }
- }
- // ==========================================
- // 2. ΧΕΙΡΙΣΜΟΣ GET (Διαγραφές)
- // ==========================================
- if (isset($_GET['delete_group'])) {
- $del_id = (int)$_GET['delete_group'];
- $checkAttrs = $pdo->prepare("SELECT COUNT(*) FROM attributes WHERE group_id = ?");
- $checkAttrs->execute([$del_id]);
- $checkCats = $pdo->prepare("SELECT COUNT(*) FROM categories WHERE attribute_group_id = ?");
- $checkCats->execute([$del_id]);
-
- if ($checkAttrs->fetchColumn() > 0) {
- $message = "<div class='alert error'>Αδυναμία διαγραφής! Υπάρχουν χαρακτηριστικά μέσα σε αυτή την ομάδα.</div>";
- } elseif ($checkCats->fetchColumn() > 0) {
- $message = "<div class='alert error'>Αδυναμία διαγραφής! Η ομάδα συνδέεται με Κατηγορία.</div>";
- } else {
- $pdo->prepare("DELETE FROM attribute_groups WHERE id = ?")->execute([$del_id]);
- $message = "<div class='alert success'>{$t['msg_group_del']}</div>";
- }
- }
- if (isset($_GET['delete_attr'])) {
- $del_id = (int)$_GET['delete_attr'];
- $checkVals = $pdo->prepare("SELECT COUNT(*) FROM product_attribute_values WHERE attribute_id = ?");
- $checkVals->execute([$del_id]);
-
- if ($checkVals->fetchColumn() > 0) {
- $message = "<div class='alert error'>Αδυναμία διαγραφής! Το χαρακτηριστικό χρησιμοποιείται σε προϊόντα.</div>";
- } else {
- $pdo->prepare("DELETE FROM attributes WHERE id = ?")->execute([$del_id]);
- $message = "<div class='alert success'>{$t['msg_attr_del']}</div>";
- }
- }
- $edit_group = null;
- if (isset($_GET['edit_group'])) {
- $stmt = $pdo->prepare("SELECT * FROM attribute_groups WHERE id = ?");
- $stmt->execute([(int)$_GET['edit_group']]);
- $edit_group = $stmt->fetch(PDO::FETCH_ASSOC);
- }
- $edit_attr = null;
- if (isset($_GET['edit_attr'])) {
- $stmt = $pdo->prepare("SELECT * FROM attributes WHERE id = ?");
- $stmt->execute([(int)$_GET['edit_attr']]);
- $edit_attr = $stmt->fetch(PDO::FETCH_ASSOC);
- }
- $groups = $pdo->query("SELECT * FROM attribute_groups ORDER BY name")->fetchAll(PDO::FETCH_ASSOC);
- $attributes = $pdo->query("
- SELECT a.id, a.name, a.name_en, a.unit, ag.name as group_name
- FROM attributes a
- JOIN attribute_groups ag ON a.group_id = ag.id
- ORDER BY ag.name, a.name
- ")->fetchAll(PDO::FETCH_ASSOC);
- ?>
- <!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 select { 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 select: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-cancel { padding: 12px 20px; background: rgba(255,255,255,0.05); color: var(--text-main); text-decoration: none; border-radius: 6px; display: inline-block; font-weight: 700; border: 1px solid var(--border-color); text-transform: uppercase; transition: 0.2s;}
- .btn-cancel:hover { background: rgba(255,255,255,0.1); }
-
- .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 25px; }
-
- 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: 14px; }
-
- .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); }
-
- .action-link { padding: 6px 12px; text-decoration: none; border-radius: 4px; color: #fff; font-size: 12px; margin-right: 5px; display: inline-block; font-weight: 700; text-transform: uppercase; transition: 0.2s;}
- .action-edit { background-color: rgba(249, 115, 22, 0.1); color: var(--primary); border: 1px solid rgba(249, 115, 22, 0.2); }
- .action-edit:hover { background-color: var(--primary); color: white; }
- .action-delete { background-color: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2); }
- .action-delete:hover { background-color: #ef4444; color: white; }
- .lang-hint { font-size: 11px; color: var(--text-muted); }
- </style>
- </head>
- <body>
-
- <?php include 'sidebar.php'; ?>
- <div class="content">
- <h2><?php echo $t['header_title']; ?></h2>
- <?php echo $message; ?>
- <div class="grid-2">
- <div class="card">
- <h3><?php echo $edit_group ? $t['edit_group'] : $t['new_group']; ?></h3>
- <form method="POST" action="attributes.php">
- <input type="hidden" name="action" value="<?php echo $edit_group ? 'edit_group' : 'add_group'; ?>">
- <?php if ($edit_group): ?>
- <input type="hidden" name="group_id" value="<?php echo $edit_group['id']; ?>">
- <?php endif; ?>
-
- <div class="form-group">
- <label><?php echo $t['name_gr']; ?></label>
- <input type="text" name="name" value="<?php echo $edit_group ? htmlspecialchars($edit_group['name']) : ''; ?>" required>
- </div>
- <div class="form-group">
- <label><?php echo $t['name_en']; ?></label>
- <input type="text" name="name_en" value="<?php echo $edit_group ? htmlspecialchars($edit_group['name_en'] ?? '') : ''; ?>">
- </div>
-
- <button type="submit" class="btn"><?php echo $edit_group ? $t['btn_save_group'] : $t['btn_add_group']; ?></button>
- <?php if ($edit_group): ?>
- <a href="attributes.php" class="btn-cancel"><?php echo $t['btn_cancel']; ?></a>
- <?php endif; ?>
- </form>
- </div>
- <div class="card">
- <h3><?php echo $edit_attr ? $t['edit_attr'] : $t['new_attr']; ?></h3>
- <form method="POST" action="attributes.php">
- <input type="hidden" name="action" value="<?php echo $edit_attr ? 'edit_attr' : 'add_attr'; ?>">
- <?php if ($edit_attr): ?>
- <input type="hidden" name="attr_id" value="<?php echo $edit_attr['id']; ?>">
- <?php endif; ?>
-
- <div class="form-group">
- <label><?php echo $t['belongs_group']; ?></label>
- <select name="group_id" required>
- <option value=""><?php echo $t['select_group']; ?></option>
- <?php foreach($groups as $group): ?>
- <option value="<?php echo $group['id']; ?>" <?php echo ($edit_attr && $edit_attr['group_id'] == $group['id']) ? 'selected' : ''; ?>>
- <?php echo htmlspecialchars($group['name']); ?>
- </option>
- <?php endforeach; ?>
- </select>
- </div>
-
- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px;">
- <div class="form-group">
- <label><?php echo $t['name_gr']; ?></label>
- <input type="text" name="name" value="<?php echo $edit_attr ? htmlspecialchars($edit_attr['name']) : ''; ?>" required>
- </div>
- <div class="form-group">
- <label><?php echo $t['name_en']; ?></label>
- <input type="text" name="name_en" value="<?php echo $edit_attr ? htmlspecialchars($edit_attr['name_en'] ?? '') : ''; ?>">
- </div>
- </div>
-
- <div class="form-group">
- <label><?php echo $t['unit']; ?></label>
- <input type="text" name="unit" value="<?php echo $edit_attr ? htmlspecialchars($edit_attr['unit'] ?? '') : ''; ?>" placeholder="cm, kg, mm">
- </div>
-
- <button type="submit" class="btn" style="background: #10b981;"><?php echo $edit_attr ? $t['btn_save_attr'] : $t['btn_add_attr']; ?></button>
- <?php if ($edit_attr): ?>
- <a href="attributes.php" class="btn-cancel"><?php echo $t['btn_cancel']; ?></a>
- <?php endif; ?>
- </form>
- </div>
- </div>
- <div class="grid-2">
- <div class="card">
- <h3><?php echo $t['existing_groups']; ?></h3>
- <table>
- <thead>
- <tr>
- <th><?php echo $t['group_name']; ?></th>
- <th style="width: 120px;"><?php echo $t['actions']; ?></th>
- </tr>
- </thead>
- <tbody>
- <?php if (count($groups) > 0): ?>
- <?php foreach($groups as $grp): ?>
- <tr>
- <td>
- <strong><?php echo htmlspecialchars($grp['name']); ?></strong><br>
- <span class="lang-hint"><?php echo htmlspecialchars($grp['name_en'] ?? ''); ?></span>
- </td>
- <td>
- <a href="attributes.php?edit_group=<?php echo $grp['id']; ?>" class="action-link action-edit">Edit</a>
- <a href="attributes.php?delete_group=<?php echo $grp['id']; ?>" class="action-link action-delete" onclick="return confirm('<?php echo $t['confirm_del_grp']; ?>');">Del</a>
- </td>
- </tr>
- <?php endforeach; ?>
- <?php else: ?>
- <tr><td colspan="2" style="text-align:center; color:var(--text-muted);"><?php echo $t['no_groups']; ?></td></tr>
- <?php endif; ?>
- </tbody>
- </table>
- </div>
- <div class="card">
- <h3><?php echo $t['existing_attrs']; ?></h3>
- <table>
- <thead>
- <tr>
- <th>Group</th>
- <th><?php echo $t['attr_name']; ?></th>
- <th>Unit</th>
- <th style="width: 120px;"><?php echo $t['actions']; ?></th>
- </tr>
- </thead>
- <tbody>
- <?php if (count($attributes) > 0): ?>
- <?php foreach($attributes as $attr): ?>
- <tr>
- <td><?php echo htmlspecialchars($attr['group_name']); ?></td>
- <td>
- <strong><?php echo htmlspecialchars($attr['name']); ?></strong><br>
- <span class="lang-hint"><?php echo htmlspecialchars($attr['name_en'] ?? ''); ?></span>
- </td>
- <td><?php echo htmlspecialchars($attr['unit'] ? $attr['unit'] : '-'); ?></td>
- <td>
- <a href="attributes.php?edit_attr=<?php echo $attr['id']; ?>" class="action-link action-edit">Edit</a>
- <a href="attributes.php?delete_attr=<?php echo $attr['id']; ?>" class="action-link action-delete" onclick="return confirm('<?php echo $t['confirm_del_attr']; ?>');">Del</a>
- </td>
- </tr>
- <?php endforeach; ?>
- <?php else: ?>
- <tr><td colspan="4" style="text-align:center; color:var(--text-muted);"><?php echo $t['no_attrs']; ?></td></tr>
- <?php endif; ?>
- </tbody>
- </table>
- </div>
- </div>
- </div>
- </body>
- </html>
|