gestor_models/editar_modelo.php
2025-06-25 08:47:02 -04:00

87 lines
3.4 KiB
PHP

<?php
require 'config.php';
$id = intval($_GET['id'] ?? 0);
if ($id <= 0) {
header('Location: list_tables.php?error=ID inválido');
exit;
}
// Obtener datos actuales
$stmt = $pdo->prepare("SELECT * FROM models WHERE id = ?");
$stmt->execute([$id]);
$model = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$model) {
header('Location: list_tables.php?error=Modelo no encontrado');
exit;
}
// Si se envió el formulario
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'] ?? '';
$version = $_POST['version'] ?? '';
$description = $_POST['description'] ?? '';
$layers = $_POST['layers'] !== '' ? intval($_POST['layers']) : null;
$model_size = $_POST['model_size'] !== '' ? floatval($_POST['model_size']) : null;
$stmt = $pdo->prepare("UPDATE models SET name=?, version=?, description=?, layers=?, model_size=? WHERE id=?");
$ok = $stmt->execute([$name, $version, $description, $layers, $model_size, $id]);
if ($ok) {
header('Location: list_tables.php?success=Modelo actualizado');
} else {
header('Location: editar_modelo.php?id=' . $id . '&error=No se pudo actualizar');
}
exit;
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Editar Modelo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container py-5">
<div class="card shadow-sm">
<div class="card-header bg-primary text-white">
Editar Modelo
</div>
<div class="card-body">
<?php if (isset($_GET['error'])): ?>
<div class="alert alert-danger"><?= htmlspecialchars($_GET['error']) ?></div>
<?php endif; ?>
<form method="POST">
<div class="mb-3">
<label class="form-label">Nombre</label>
<input type="text" name="name" class="form-control" value="<?= htmlspecialchars($model['name']) ?>" required>
</div>
<div class="mb-3">
<label class="form-label">Versión</label>
<input type="text" name="version" class="form-control" value="<?= htmlspecialchars($model['version']) ?>" required>
</div>
<div class="mb-3">
<label class="form-label">Descripción</label>
<textarea name="description" class="form-control"><?= htmlspecialchars($model['description']) ?></textarea>
</div>
<div class="mb-3">
<label class="form-label">Capas</label>
<input type="number" name="layers" class="form-control" value="<?= htmlspecialchars($model['layers']) ?>">
</div>
<div class="mb-3">
<label class="form-label">Tamaño/Peso</label>
<input type="number" step="0.01" name="model_size" class="form-control" value="<?= htmlspecialchars($model['model_size']) ?>">
</div>
<button type="submit" class="btn btn-success">Guardar Cambios</button>
<a href="list_tables.php" class="btn btn-secondary">Volver</a>
</form>
</div>
</div>
</div>
</body>
</html>