prepare('INSERT INTO puzzles (name, file_name, original_image, pieces, is_public, is_admin_upload) VALUES (?, ?, ?, ?, ?, 1)'); $stmt->execute([$puzzle_name, $safe_filename, $safe_filename, $pieces, $is_public]); $puzzle_id = $pdo->lastInsertId(); create_puzzle_pieces($upload_path, $puzzle_id, $pieces); header("Location: admin.php?success=1"); exit; } } header("Location: admin.php?error=1"); exit; } // Handle puzzle deletion if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_puzzle'])) { $puzzle_id_to_delete = $_POST['puzzle_id']; $stmt = $pdo->prepare('SELECT file_name FROM puzzles WHERE id = ?'); $stmt->execute([$puzzle_id_to_delete]); $puzzle = $stmt->fetch(PDO::FETCH_ASSOC); if ($puzzle) { $original_image_path = __DIR__ . '/uploads/' . $puzzle['file_name']; if (file_exists($original_image_path)) { unlink($original_image_path); } } $stmt = $pdo->prepare('DELETE FROM puzzles WHERE id = ?'); $stmt->execute([$puzzle_id_to_delete]); $puzzle_dir = __DIR__ . '/puzzles/' . $puzzle_id_to_delete; if (is_dir($puzzle_dir)) { function delete_directory($dir) { if (!is_dir($dir)) return; $files = array_diff(scandir($dir), array('.','..')); foreach ($files as $file) { (is_dir("$dir/$file")) ? delete_directory("$dir/$file") : unlink("$dir/$file"); } rmdir($dir); } delete_directory($puzzle_dir); } header("Location: admin.php?deleted=1"); exit; } // Handle user deletion if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_user'])) { $user_id_to_delete = $_POST['user_id']; // Prevent self-deletion if ($user_id_to_delete == $_SESSION['user_id']) { header("Location: admin.php?error=self_delete"); exit; } // Add logic here to delete user-related data if necessary (e.g., scores) $stmt = $pdo->prepare('DELETE FROM users WHERE id = ?'); $stmt->execute([$user_id_to_delete]); header("Location: admin.php?user_deleted=1"); exit; } $puzzles = $pdo->query('SELECT id, name, file_name, pieces, is_public, created_at FROM puzzles ORDER BY created_at DESC')->fetchAll(PDO::FETCH_ASSOC); // Fetch users $users = $pdo->query('SELECT id, username, email, created_at FROM users ORDER BY created_at DESC')->fetchAll(PDO::FETCH_ASSOC); $page_title = 'Pannello di Amministrazione'; require_once 'includes/header.php'; ?> Puzzle aggiunto con successo! Puzzle eliminato con successo. Utente eliminato con successo. Aggiungi Nuovo Puzzle Nome del Puzzle Immagine Numero di Pezzi 16 (4x4) 32 (8x4) 64 (8x8) Rendi Pubblico Aggiungi Puzzle Gestione Puzzle ID Nome Immagine Pezzi Pubblico Creato il Azioni Nessun puzzle trovato. > Elimina Gestione Utenti ID Username Email Registrato il Azioni Nessun utente trovato. Elimina