file($f['tmp_name']); $allowed = ['image/png'=>'png','image/jpeg'=>'jpg','image/webp'=>'webp']; if (!isset($allowed[$mime])) throw new RuntimeException("Formato no permitido para $field. Usa PNG/JPG/WEBP."); if ($f['size'] > 5 * 1024 * 1024) throw new RuntimeException("Archivo muy grande para $field (máx 5MB)."); $ext = $allowed[$mime]; $base = sanitize_filename(pathinfo($f['name'], PATHINFO_FILENAME)); $fname = $base . '-' . uniqid() . '.' . $ext; $dest = rtrim($UPLOAD_DIR, "/\\") . DIRECTORY_SEPARATOR . $fname; if (!move_uploaded_file($f['tmp_name'], $dest)) throw new RuntimeException("No se pudo guardar $field."); return rtrim($PUBLIC_DIR, '/') . '/' . $fname; } function get_config(mysqli $conn, $juego_id) { $stmt = $conn->prepare("SELECT * FROM juegos_config WHERE juego_id=?"); $stmt->bind_param("i", $juego_id); $stmt->execute(); return $stmt->get_result()->fetch_assoc(); } $msg = $err = ''; $action = $_GET['action'] ?? ''; $juego_id = (int)($_GET['juego_id'] ?? 0); // CREATE/UPDATE if ($_SERVER['REQUEST_METHOD'] === 'POST') { $jid = (int)($_POST['juego_id'] ?? 0); $nombre = trim($_POST['nombre'] ?? ''); $ruleta_id = (int)($_POST['ruleta_id'] ?? 0); $olds = [ 'banner_1' => $_POST['old_banner_1'] ?? '', 'banner_2' => $_POST['old_banner_2'] ?? '', 'banner_3' => $_POST['old_banner_3'] ?? '', 'banner_4' => $_POST['old_banner_4'] ?? '', 'background_image' => $_POST['old_background_image'] ?? '', 'fullscreen_icon' => $_POST['old_fullscreen_icon'] ?? '', 'reverso_default' => $_POST['old_reverso_default'] ?? '' ]; if ($jid <= 0 || $nombre === '') { $err = "Debes indicar un juego_id (entero) y un nombre."; } else { try { $new = [ 'banner_1' => upload_image('banner_1', $UPLOAD_DIR, $PUBLIC_DIR), 'banner_2' => upload_image('banner_2', $UPLOAD_DIR, $PUBLIC_DIR), 'banner_3' => upload_image('banner_3', $UPLOAD_DIR, $PUBLIC_DIR), 'banner_4' => upload_image('banner_4', $UPLOAD_DIR, $PUBLIC_DIR), 'background_image' => upload_image('background_image', $UPLOAD_DIR, $PUBLIC_DIR), 'fullscreen_icon' => upload_image('fullscreen_icon', $UPLOAD_DIR, $PUBLIC_DIR), 'reverso_default' => upload_image('reverso_default', $UPLOAD_DIR, $PUBLIC_DIR), ]; foreach ($new as $k=>$v) { $new[$k] = $v ?: ($olds[$k] ?: null); } // upsert por juego_id $stmt = $conn->prepare("INSERT INTO juegos_config (juego_id, nombre, ruleta_id, banner_1,banner_2,banner_3,banner_4, background_image, fullscreen_icon, reverso_default) VALUES (?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE nombre=VALUES(nombre), ruleta_id=VALUES(ruleta_id), banner_1=VALUES(banner_1), banner_2=VALUES(banner_2), banner_3=VALUES(banner_3), banner_4=VALUES(banner_4), background_image=VALUES(background_image), fullscreen_icon=VALUES(fullscreen_icon), reverso_default=VALUES(reverso_default)"); $stmt->bind_param("isisssssss", $jid, $nombre, $ruleta_id, $new['banner_1'], $new['banner_2'], $new['banner_3'], $new['banner_4'], $new['background_image'], $new['fullscreen_icon'], $new['reverso_default']); $stmt->execute(); $msg = "Configuración guardada."; } catch (Throwable $e) { $err = $e->getMessage(); } } } // DELETE if ($action === 'delete' && $juego_id > 0) { $stmt = $conn->prepare("DELETE FROM juegos_config WHERE juego_id=?"); $stmt->bind_param("i", $juego_id); $stmt->execute(); $msg = "Configuración eliminada."; } // EDIT $edit = null; if ($action === 'edit' && $juego_id > 0) { $edit = get_config($conn, $juego_id); } // LIST $list = $conn->query("SELECT * FROM juegos_config ORDER BY juego_id ASC"); ?> Memoria | Configuración de Juegos

Config. Juegos de Memoria

'; } ?>
Cancelar
fetch_assoc()): ?>
Juego IDNombreRuleta B1B2B3B4 BGFSReversoAcciones
':'—' ?> ':'—' ?> ':'—' ?> ':'—' ?> ':'—' ?> ':'—' ?> ':'—' ?> Editar Eliminar Ver