[ 'manage_cats' => 'Διαχείριση Κατηγοριών', 'edit_cat' => '✏️ Επεξεργασία Κατηγορίας', 'add_cat' => '📁 Προσθήκη Νέας Κατηγορίας', 'name_el' => 'Όνομα 🇬🇷 (Ελληνικά) *', 'name_en' => 'Όνομα 🇬🇧 (Αγγλικά)', 'parent_cat' => 'Ανήκει σε... (Προαιρετικό)', 'is_main' => '-- Είναι Κεντρική Κατηγορία --', 'attr_group' => 'Ομάδα Χαρακτηριστικών', 'no_attr' => '-- Χωρίς Ειδικά Χαρακτηριστικά --', 'btn_save' => 'Αποθήκευση Αλλαγών', 'btn_add' => 'Προσθήκη Κατηγορίας', 'btn_cancel' => 'Ακύρωση', 'tree_title' => 'Δέντρο Κατηγοριών (Treeview)', 'no_cats' => 'Δεν υπάρχουν κατηγορίες ακόμα.', 'msg_add_ok' => 'Η κατηγορία προστέθηκε επιτυχώς!', 'msg_edit_ok' => 'Η κατηγορία ενημερώθηκε επιτυχώς!', 'msg_err_name' => 'Το Ελληνικό όνομα είναι υποχρεωτικό.', 'msg_err_slug' => 'Σφάλμα: (Μήπως το URL/Slug υπάρχει ήδη;)', 'msg_del_ok' => 'Η κατηγορία διεγράφη επιτυχώς!', 'msg_err_prod' => 'Αδυναμία διαγραφής! Υπάρχουν προϊόντα σε αυτή την κατηγορία.', 'msg_err_child' => 'Αδυναμία διαγραφής! Υπάρχουν υποκατηγορίες μέσα σε αυτή την κατηγορία.', 'confirm_del' => 'Είστε σίγουρος ότι θέλετε να διαγράψετε αυτή την κατηγορία;' ], 'en' => [ 'manage_cats' => 'Manage Categories', 'edit_cat' => '✏️ Edit Category', 'add_cat' => '📁 Add New Category', 'name_el' => 'Name 🇬🇷 (Greek) *', 'name_en' => 'Name 🇬🇧 (English)', 'parent_cat' => 'Belongs to... (Optional)', 'is_main' => '-- Is Main Category --', 'attr_group' => 'Attribute Group', 'no_attr' => '-- No Special Attributes --', 'btn_save' => 'Save Changes', 'btn_add' => 'Add Category', 'btn_cancel' => 'Cancel', 'tree_title' => 'Category Tree (Treeview)', 'no_cats' => 'No categories found.', 'msg_add_ok' => 'Category added successfully!', 'msg_edit_ok' => 'Category updated successfully!', 'msg_err_name' => 'The Greek name is required.', 'msg_err_slug' => 'Error: (Maybe the URL/Slug already exists?)', 'msg_del_ok' => 'Category deleted successfully!', 'msg_err_prod' => 'Cannot delete! There are products in this category.', 'msg_err_child' => 'Cannot delete! There are subcategories inside this category.', 'confirm_del' => 'Are you sure you want to delete this category?' ] ]; $t = $translations[$current_lang]; header('Content-Type: text/html; charset=utf-8'); $message = ''; function createSlug($string) { $greek = ['α','ά','Α','Ά','β','Β','γ','Γ','δ','Δ','ε','έ','Ε','Έ','ζ','Ζ','η','ή','Η','Ή','θ','Θ','ι','ί','ϊ','ΐ','Ι','Ί','Ϊ','κ','Κ','λ','Λ','μ','Μ','ν','Ν','ξ','Ξ','ο','ό','Ο','Ό','π','Π','ρ','Ρ','σ','ς','Σ','τ','Τ','υ','ύ','ϋ','ΰ','Υ','Ύ','Ϋ','φ','Φ','χ','Χ','ψ','Ψ','ω','ώ','Ω','Ώ']; $latin = ['a','a','a','a','b','b','g','g','d','d','e','e','e','e','z','z','i','i','i','i','th','th','i','i','i','i','i','i','i','k','k','l','l','m','m','n','n','x','x','o','o','o','o','p','p','r','r','s','s','s','t','t','y','y','y','y','y','y','y','f','f','ch','ch','ps','ps','o','o','o','o']; $string = str_replace($greek, $latin, $string); $string = strtolower(trim($string)); $string = preg_replace('/[^a-z0-9-]/', '-', $string); $string = preg_replace('/-+/', "-", $string); return trim($string, '-'); } // Χειρισμός Μετακίνησης if (isset($_GET['move']) && isset($_GET['id'])) { $move_id = (int)$_GET['id']; $direction = $_GET['move']; $all = $pdo->query(" SELECT c1.id FROM categories c1 LEFT JOIN categories c2 ON c1.parent_id = c2.id ORDER BY c1.sort_order ASC, c2.name_el ASC, c1.name_el ASC ")->fetchAll(PDO::FETCH_ASSOC); $current_index = -1; $seq = 1; foreach ($all as $idx => $row) { $pdo->prepare("UPDATE categories SET sort_order = ? WHERE id = ?")->execute([$seq, $row['id']]); $all[$idx]['sort_order'] = $seq; if ($row['id'] == $move_id) { $current_index = $idx; } $seq++; } if ($current_index !== -1) { if ($direction === 'up' && $current_index > 0) { $prev_id = $all[$current_index - 1]['id']; $current_order = $all[$current_index]['sort_order']; $prev_order = $all[$current_index - 1]['sort_order']; $pdo->prepare("UPDATE categories SET sort_order = ? WHERE id = ?")->execute([$prev_order, $move_id]); $pdo->prepare("UPDATE categories SET sort_order = ? WHERE id = ?")->execute([$current_order, $prev_id]); } elseif ($direction === 'down' && $current_index < count($all) - 1) { $next_id = $all[$current_index + 1]['id']; $current_order = $all[$current_index]['sort_order']; $next_order = $all[$current_index + 1]['sort_order']; $pdo->prepare("UPDATE categories SET sort_order = ? WHERE id = ?")->execute([$next_order, $move_id]); $pdo->prepare("UPDATE categories SET sort_order = ? WHERE id = ?")->execute([$current_order, $next_id]); } } header("Location: categories.php"); exit; } // Χειρισμός POST if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $action = $_POST['action']; $name_el = trim($_POST['name_el']); $name_en = trim($_POST['name_en']); $parent_id = !empty($_POST['parent_id']) ? $_POST['parent_id'] : null; $attribute_group_id = !empty($_POST['attribute_group_id']) ? (int)$_POST['attribute_group_id'] : null; if (!empty($name_el)) { $slug_source = !empty($name_en) ? $name_en : $name_el; $slug = createSlug($slug_source); try { if ($action == 'add') { $stmt = $pdo->prepare("INSERT INTO categories (parent_id, name_el, name_en, slug, attribute_group_id, sort_order) VALUES (?, ?, ?, ?, ?, 999)"); $stmt->execute([$parent_id, $name_el, $name_en, $slug, $attribute_group_id]); $message = "