Preparacion examen

This commit is contained in:
Marklogo 2024-04-03 13:54:49 +02:00
parent 29f5fc3d08
commit 35ee82dcf9
14 changed files with 489 additions and 85 deletions

View File

@ -0,0 +1,25 @@
<?php
include("connection.php");
$con = connection();
$detalle_pedido_id=$_GET["detalle_pedido_id"];
$pedido_id=$_GET["pedido_id"];
// Borrar en productos
$sql="DELETE FROM detalles_pedido WHERE detalle_pedido_id='$detalle_pedido_id'";
$query = mysqli_query($con, $sql);
if($query){
$mensaje ="Se ha borrado el producto del pedido.";
$mensaje_codificado = urlencode($mensaje);
header("Location: detalles_pedido.php?mensaje=".$mensaje_codificado."&pedido_id=$pedido_id");
exit;
}else{
$mensaje ="Se ha producido un error al borrar el producto.";
$mensaje_codificado = urlencode($mensaje);
header("Location: detalles_pedido.php?mensaje=".$mensaje_codificado."&pedido_id=$pedido_id");
exit;
}
?>

View File

@ -11,7 +11,9 @@ $sql = "DELETE FROM pedidos WHERE pedido_id='$pedido_id'";
$query = mysqli_query($con, $sql);
if ($query) {
Header("Location: index_pedidos.php");
$mensaje = "Se ha eliminado el registro.";
$mensaje_codificado = urlencode($mensaje);
header("Location: index_pedidos.php?mensaje=" . $mensaje_codificado);
} else {
$mensaje = "Se ha producido un error al borrar el registro.";
$mensaje_codificado = urlencode($mensaje);

View File

@ -0,0 +1,79 @@
<?php
// Incluye el archivo de conexión a la base de datos
include("connection.php");
// Establece la conexión
$con = connection();
$pedido_id=$_GET['pedido_id'];
// Consulta para obtener los detalles del pedido
$sql = "SELECT * FROM vista_detalles_pedido_producto WHERE pedido_id = '$pedido_id'";
$query = mysqli_query($con, $sql);
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/style.css" rel="stylesheet">
<title>Detalles del Pedido</title>
</head>
<body>
<nav>
<ul>
<li><a href="index_clientes.php">Clientes</a></li>
<li><a href="index_productos.php">Productos</a></li>
<li><a href="index_pedidos.php">Pedidos</a></li>
</ul>
</nav>
<h2>Detalles del Pedido</h2>
<?php if (isset($_GET['mensaje'])) echo "<p>" . $_GET['mensaje'] . "</p>"; ?>
<div class="users-table">
<table>
<thead>
<tr>
<th>Detalles pedido ID</th>
<th>Pedido ID</th>
<th>Nombre Producto</th>
<th>Cantidad</th>
<th>Precio Unitario</th>
<th>Total por producto</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$total = 0; // Declarar $total fuera del bucle
while ($fila = mysqli_fetch_array($query)){
?>
<tr>
<th><?php echo $fila['detalle_pedido_id'] ?></th>
<th><?php echo $pedido_id ?></th>
<th><?php echo $fila['nombre_producto'] ?></th>
<th><?php echo $fila['cantidad'] ?></th>
<th><?php echo $fila['precio_unitario'] ?></th>
<th><?php echo $fila['Total_producto'] ?></th>
<th><a href="update_detail_order.php?detalle_pedido_id=<?php echo $fila['detalle_pedido_id'] ?>&pedido_id=<?php echo $fila['pedido_id'] ?>" class="users-table--edit">Editar</a></th>
<th><a href="delete_detail_order.php?detalle_pedido_id=<?php echo $fila['detalle_pedido_id'] ?>&pedido_id=<?php echo $fila['pedido_id'] ?>" class="users-table--delete" >Eliminar</a></th>
<?php
$total = $total + $fila['Total_producto'];
?>
</tr>
<?php } ?>
<tr>
<td colspan="5"><b>Coste total</b></td>
<td><?php echo "<p><b>$total</b></p>" ?></td>
<td colspan="2"></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

View File

@ -0,0 +1,31 @@
<?php
include("connection.php");
$con = connection();
// Recuperar los datos del formulario
$detalle_pedido_id = $_POST["detalle_pedido_id"];
$pedido_id = $_POST["pedido_id"];
$producto_id = $_POST["producto_id"];
$cantidad = $_POST["cantidad"];
$precio_unitario = $_POST["precio_unitario"];
// Actualizar en detalles_pedido
$sql = "UPDATE detalles_pedido
SET pedido_id='$pedido_id',
cantidad='$cantidad',
precio_unitario='$precio_unitario'
WHERE detalle_pedido_id='$detalle_pedido_id'";
$query = mysqli_query($con, $sql);
if ($query) {
$mensaje = "Detalle de pedido actualizado.";
$mensaje_codificado = urlencode($mensaje);
header("Location: detalles_pedido.php?mensaje=" . $mensaje_codificado."&pedido_id=$pedido_id");
exit;
} else {
$mensaje = "Se ha producido un error al actualizar el detalle del pedido.";
$mensaje_codificado = urlencode($mensaje);
header("Location: detalles_pedido.php?mensaje=" . $mensaje_codificado."&pedido_id=$pedido_id");
exit;
}
?>

View File

@ -0,0 +1,29 @@
<?php
include("connection.php");
$con = connection();
// Recuperar los datos del formulario
$pedido_id = $_POST["pedido_id"];
$cliente_id = $_POST["cliente_id"];
$fecha = $_POST["fecha"];
$estado = $_POST["estado"];
$total = $_POST["total_pedido"];
// Actualizo en pedidos
$sql="UPDATE pedidos SET cliente_id='$cliente_id', fecha='$fecha', estado='$estado', total='$total' WHERE pedido_id='$pedido_id'";
$query = mysqli_query($con, $sql);
if($query){
$mensaje ="Pedido actualizado.";
$mensaje_codificado = urlencode($mensaje);
header("Location: index_pedidos.php?mensaje=".$mensaje_codificado);
exit;
}else{
$mensaje ="Se ha producido un error al actualizar.";
$mensaje_codificado = urlencode($mensaje);
header("Location: index_pedidos.php?mensaje=".$mensaje_codificado);
exit;
}
?>

View File

@ -28,47 +28,47 @@ $query = mysqli_query($con, $sql);
<div class="users-table">
<h2>Registro de Clientes</h2>
<table>
<tr>
<td>
<form action="insert_user.php" method="POST">
<form action="insert_user.php" method="POST">
<tr>
<td>
<label for="nombre">Nombre:</label>
</td>
<td>
<label for="correo">Correo electrónico:</label>
</td>
<td>
<label for="direccion">Dirección:</label>
</td>
<td>
<label for="nombre_usuario">Nombre de usuario:</label>
</td>
<td>
<label for="contrasena">Contraseña:</label>
</td>
<td>
</td> <!-- Celda vacía para el botón de envío -->
</tr>
<tr>
<td>
<input type="text" name="nombre" id="nombre" required>
</td>
<td>
<input type="email" name="correo" id="correo" required>
</td>
<td>
<input type="text" name="direccion" id="direccion" required>
</td>
<td>
<input type="text" name="nombre_usuario" id="nombre_usuario" required>
</td>
<td>
<input type="password" name="contrasena" id="contrasena" required>
</td>
<td>
<input type="submit" value="Registrarse">
</td>
</form>
</tr>
</td>
<td>
<label for="correo">Correo electrónico:</label>
</td>
<td>
<label for="direccion">Dirección:</label>
</td>
<td>
<label for="nombre_usuario">Nombre de usuario:</label>
</td>
<td>
<label for="contrasena">Contraseña:</label>
</td>
<td>
</td> <!-- Celda vacía para el botón de envío -->
</tr>
<tr>
<td>
<input type="text" name="nombre" id="nombre" required>
</td>
<td>
<input type="email" name="correo" id="correo" required>
</td>
<td>
<input type="text" name="direccion" id="direccion" required>
</td>
<td>
<input type="text" name="nombre_usuario" id="nombre_usuario" required>
</td>
<td>
<input type="password" name="contrasena" id="contrasena" required>
</td>
<td>
<input type="submit" value="Registrarse">
</td>
</tr>
</form>
</table>
@ -93,12 +93,12 @@ $query = mysqli_query($con, $sql);
<tbody>
<?php while ($fila = mysqli_fetch_array($query)) { ?>
<tr>
<th><?php echo $fila['cliente_id'] ?></th>
<th><?php echo $fila['nombre'] ?></th>
<th><?php echo $fila['correo_electronico'] ?></th>
<th><?php echo $fila['direccion'] ?></th>
<th><?php echo $fila['nombre_usuario'] ?></th>
<th><?php echo $fila['contraseña'] ?></th>
<th><?= $fila['cliente_id'] ?></th>
<th><?= $fila['nombre'] ?></th>
<th><?= $fila['correo_electronico'] ?></th>
<th><?= $fila['direccion'] ?></th>
<th><?= $fila['nombre_usuario'] ?></th>
<th><?= $fila['contraseña'] ?></th>
<th><a href="update_user.php?cliente_id=<?php echo $fila['cliente_id'] ?>" class="users-table--edit">Editar</a></th>
<th><a href="delete_user.php?cliente_id=<?php echo $fila['cliente_id'] ?>" class="users-table--delete">Eliminar</a></th>
</tr>

View File

@ -2,7 +2,7 @@
include("connection.php");
$con = connection();
$sql = "SELECT * FROM pedidos";
$sql = "SELECT * FROM `vista_pedidos_total`";
$query = mysqli_query($con, $sql);
?>
@ -14,7 +14,7 @@ $query = mysqli_query($con, $sql);
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/style.css" rel="stylesheet">
<title>Predidos CRUD</title>
<title>Pedidos CRUD</title>
</head>
<body>
@ -25,40 +25,9 @@ $query = mysqli_query($con, $sql);
<li class="active"><a href="index_pedidos.php">Pedidos</a></li>
</ul>
</nav>
<!-- <div class="users-table">
<h2>Registro de Productos</h2>
<table>
<tr>
<td>
<form action="insert_producto.php" method="POST">
<label for="nombre">Nombre:</label>
</td>
<td>
<label for="correo">Precio:</label>
</td>
<td>
</td>
</tr>
<tr>
<td>
<input type="text" name="nombre" id="nombre" required>
</td>
<td>
<input type="text" name="precio" id="precio" required>
</td>
<td>
<td>
<input type="submit" value="Registrarse">
</td>
</form>
</tr>
</table>
<div>
<?php if (isset($_GET['mensaje'])) echo "<p>" . $_GET['mensaje'] . "</p>"; ?>
</div> -->
</div>
<div class="users-table">
<h2>Pedidos registrados</h2>
<table>
@ -85,9 +54,9 @@ $query = mysqli_query($con, $sql);
<option <?php echo $fila['estado'] === 'enviado' ? 'selected' : ''; ?> value="enviado">Enviado</option>
<option <?php echo $fila['estado'] === 'completado' ? 'selected' : ''; ?> value="completado">Completado</option>
</select></th>
<th><?php echo $fila['total'] ?></th>
<th><a href="update_producto.php?producto_id=<?php echo $fila['pedido_id'] ?>" class="users-table--edit">Ver Detalle</a></th>
<th><?php echo $fila['total_pedido'] ?></th>
<th><a href="detalles_pedido.php?pedido_id=<?php echo $fila['pedido_id'] ?>" class="users-table--detail">Detalles pedido</a></th>
<th><a href="update_pedido.php?pedido_id=<?php echo $fila['pedido_id'] ?>" class="users-table--edit">Editar</a></th>
<th><a href="delete_pedido.php?pedido_id=<?php echo $fila['pedido_id'] ?>" class="users-table--delete">Eliminar</a></th>
</tr>
<?php } ?>

View File

@ -0,0 +1,20 @@
<?php
include("connection.php");
$con = connection();
$producto_id = $_GET["producto_id"];
// Borrar en productos
$sql = "DELETE FROM productos WHERE producto_id='$producto_id'";
$query = mysqli_query($con, $sql);
if ($query) {
Header("Location: index_productos.php");
} else {
$mensaje = "Se ha producido un error al borrar el registro.";
$mensaje_codificado = urlencode($mensaje);
header("Location: index_productos.php?mensaje=" . $mensaje_codificado);
exit;
}

View File

@ -0,0 +1,27 @@
<?php
include("connection.php");
$con = connection();
// Recuperar los datos del formulario
$producto_id = $_POST["producto_id"];
$nombre = $_POST["nombre"];
$precio = $_POST["precio"];
// Actualizo en productos
$sql = "UPDATE productos SET nombre='$nombre', precio='$precio' WHERE producto_id='$producto_id'";
$query = mysqli_query($con, $sql);
if($query){
$mensaje ="Producto actualizado.";
$mensaje_codificado = urlencode($mensaje);
header("Location: index_productos.php?mensaje=".$mensaje_codificado);
exit;
}else{
$mensaje ="Se ha producido un error al actualizar.";
$mensaje_codificado = urlencode($mensaje);
header("Location: index_productos.php?mensaje=".$mensaje_codificado);
exit;
}

View File

@ -0,0 +1,90 @@
<?php
include("connection.php");
$con = connection();
$sql = "SELECT * FROM productos"; //TODO: Cambiar tabla
$query = mysqli_query($con, $sql);
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/style.css" rel="stylesheet">
<title></title> //TODO: Cambiar titulo
</head>
<body>
<nav> //TODO: Cambiar Navegacion
<ul>
<li><a href="index_clientes.php">Clientes</a></li>
<li class="active"><a href="index_productos.php">Productos</a></li>
<li><a href="index_pedidos.php">Pedidos</a></li>
</ul>
</nav>
<div class="users-table">
<h2></h2>//TODO: Cambiar cabecera tabla titulo
<form action="insert_xxx.php" method="POST"> //TODO: Cambiar archivo para guardar el registro
<table>
<tr>
<td>
<label for="nombre">Nombre:</label>
</td>
<td>
<label for="correo">Precio:</label>
</td>
<td>
</td> <!-- Celda vacía para el botón de envío -->
</tr>
<tr>
<td>
<input type="text" name="nombre" id="nombre" required>
</td>
<td>
<input type="text" name="precio" id="precio" required>
</td>
<td>
<td>
<input type="submit" value="Registrarse">
</td>
</tr>
</table>
</form>
<?php if (isset($_GET['mensaje'])) echo "<p>" . $_GET['mensaje'] . "</p>"; ?>
</div>
<div class="users-table">
<h2>Productos registrados</h2>
<table>
<thead>
<tr>
<th>Producto ID</th>
<th>Nombre</th>
<th>Precio</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php while ($fila = mysqli_fetch_array($query)) { ?>
<tr>
<th><?= $fila['producto_id'] ?></th>
<th><?= $fila['nombre'] ?></th>
<th><?= $fila['precio'] ?></th>
<th><a href="update_producto.php?producto_id=<?php echo $fila['producto_id'] ?>" class="users-table--edit">Editar</a></th>
<th><a href="delete_producto.php?producto_id=<?php echo $fila['producto_id'] ?>" class="users-table--delete">Eliminar</a></th>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</body>
</html>

View File

@ -0,0 +1,40 @@
<?php
include("connection.php");
$con = connection();
$producto_id = $_GET['producto_id'];
$sql = "SELECT * FROM productos
WHERE producto_id = '$producto_id'";
$query = mysqli_query($con, $sql);
$fila = mysqli_fetch_array($query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/style.css" rel="stylesheet">
<title>Editar producto</title>
</head>
<body>
<div class="users-form">
<form action="edit_producto.php" method="POST">
<input type="hidden" name="producto_id" id="producto_id" value="<?= $fila['producto_id'] ?>" />
<label for="nombre">Nombre:</label>
<input type="text" name="nombre" id="nombre" value="<?= $fila['nombre'] ?>" required>
<br><br>
<label for="precio">Precio:</label>
<input type="text" name="precio" id="precio" value="<?= $fila['precio'] ?>" required>
<br><br>
<input type="submit" value="Actualizar">
</form>
</div>
</body>
</html>

View File

@ -0,0 +1,47 @@
<?php
include("connection.php");
$con = connection();
$detalle_pedido_id = $_GET['detalle_pedido_id'];
$sql = "SELECT * FROM vista_detalles_pedido_producto WHERE detalle_pedido_id = '$detalle_pedido_id'";
$query = mysqli_query($con, $sql);
$fila = mysqli_fetch_array($query);
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/style.css" rel="stylesheet">
<title>Editar detalles de pedido</title>
</head>
<body>
<div class="users-form">
<form action="edit_detail_order.php" method="POST">
<input type="hidden" name="detalle_pedido_id" id="detalle_pedido_id" value="<?= $fila['detalle_pedido_id']?>" />
<label for="pedido_id">Pedido Id:</label>
<input type="text" name="pedido_id" id="pedido_id" value="<?= $fila['pedido_id']?>" required>
<br><br>
<label for="producto_id">Nombre Producto:</label>
<input type="text" name="nombre_producto" id="nombre_producto" value="<?= $fila['nombre_producto']?>" required>
<br><br>
<label for="cantidad">Cantidad:</label>
<input type="text" name="cantidad" id="cantidad" value="<?= $fila['cantidad']?>" required>
<br><br>
<label for="precio_unitario">Precio Unitario:</label>
<input type="text" name="precio_unitario" id="precio_unitario" value="<?= $fila['precio_unitario']?>" required>
<br><br>
<input type="submit" value="Actualizar">
</form>
</div>
</body>
</html>

View File

@ -0,0 +1,45 @@
<?php
include("connection.php");
$con=connection();
$pedido_id=$_GET['pedido_id'];
$sql = "SELECT * FROM vista_pedidos_total
WHERE pedido_id = '$pedido_id'";
$query=mysqli_query($con, $sql);
$fila=mysqli_fetch_array($query);
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/style.css" rel="stylesheet">
<title>Editar pedidos</title>
</head>
<body>
<div class="users-form">
<form action="edit_pedido.php" method="POST">
<input type="hidden" name="pedido_id" id="pedido_id" value="<?= $fila['pedido_id']?>" />
<label for="cliente_id">Cliente Id:</label>
<input type="text" name="cliente_id" id="cliente_id" value="<?= $fila['cliente_id']?>" required>
<br><br>
<label for="fecha">Fecha:</label>
<input type="text" name="fecha" id="fecha" value="<?= $fila['fecha']?>" required>
<br><br>
<br><br>
<label for="estado">Estado:</label>
<input type="text" name="estado" id="estado" value="<?= $fila['estado']?>" required>
<br><br>
<br><br>
<label for="total">Total:</label>
<input type="text" name="total_pedido" id="total_pedido" value="<?= $fila['total_pedido']?>" readonly required>
<br><br>
<input type="submit" value="Actualizar">
</form>
</div>
</body>
</html>