Skip to content
Open

UF1 #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions examen-sesiones/ejercicio1/contacto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
session_start();
?>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>contacto</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>

<body class="bg-light text-dark">

<header>
<?php
require_once 'header.php';
?>
</header>

<div class="container mt-5">
<h1 class="text-center mb-4">pgina de contacto</h1>

</div>
</body>

</html>
18 changes: 18 additions & 0 deletions examen-sesiones/ejercicio1/header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

echo '
<header class="bg-light py-3 mb-4 shadow-sm">
<div class="container d-flex align-items-center justify-content-between">
<div class="d-flex align-items-center">
<div>
<h4 class="m-0">Hola, ' . $_SESSION['nombre'] . ' ' . $_SESSION['apellido'] . '</h4>
</div>
</div>
<div class="d-flex align-items-center">
<a href="inicio.php" class="me-3">Inicio</a>
<a href="productos.php" class="me-3">Productos</a>
<a href="contacto.php">Contacto</a>
</div>
</div>
</header>
';
55 changes: 55 additions & 0 deletions examen-sesiones/ejercicio1/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

session_start();

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$_SESSION['nombre'] = $_POST['nombre'];
$_SESSION['apellido'] = $_POST['apellido'];

header('Location: inicio.php');
exit;
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Examen</title>
<link rel="stylesheet" href="style.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>

<body class="bg-light">

<?php for ($i = 0; $i < 180; $i++): ?>
<span></span>
<?php endfor; ?>

<section>
<div class="signin">
<div class="content text-center">
<h2>Inicia sesión</h2>
<form method="post" action="index.php">
<div class="mb-3">
<input class="form-control p-2 m-2" placeholder="Nombre" type="text" name="nombre" id="nombre" required>
</div>
<div class="mb-3">
<input class="form-control p-2 m-2" placeholder="Apellido" type="text" name="apellido" id="apellido" required>
</div>
<?php if (!empty($error)) : ?>
<div class="alert alert-danger"><?= $error ?></div>
<?php endif; ?>

<div>
<input class="btn btn-warning w-100 mt-3" type="submit" value="Iniciar">
</div>
</form>
</div>
</div>
</section>
</body>

</html>
29 changes: 29 additions & 0 deletions examen-sesiones/ejercicio1/inicio.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
session_start();
?>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>inicio</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>

<body class="bg-light text-dark">

<header>
<?php
require_once 'header.php';
?>
</header>

<div class="container mt-5">
<h1 class="text-center mb-4">pagina de inicio</h1>

</div>
</body>

</html>
29 changes: 29 additions & 0 deletions examen-sesiones/ejercicio1/productos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
session_start();
?>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>productos</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>

<body class="bg-light text-dark">

<header>
<?php
require_once 'header.php';
?>
</header>

<div class="container mt-5">
<h1 class="text-center mb-4">pgina de productos</h1>

</div>
</body>

</html>
58 changes: 58 additions & 0 deletions examen-sesiones/ejercicio2/agregarProducto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
session_start();
include 'functiones.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
array_push($_SESSION['productos'], [
"nombre" => $_POST['nombre'],
"precio" => $_POST['precio'],
"descripcion" => $_POST['descripcion'],
]);
header('Location: index.php');
exit;
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>agregarProducto</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>

<body class="bg-light text-dark">

<div class="container d-flex justify-content-center align-items-center" style="height: 100vh;">
<div class="col-12 col-md-6 col-lg-4">
<h2 class="text-center mb-4">Agregar Producto</h2>
<form method="post" action="agregarProducto.php" class="bg-white p-4 rounded shadow-sm">

<div class="mb-3">
<input class="form-control" placeholder="Nombre" type="text" name="nombre" id="nombre" required>
</div>

<div class="mb-3">
<input class="form-control" placeholder="Precio" type="text" name="precio" id="precio" required>
</div>

<div class="mb-3">
<input class="form-control" placeholder="Descripción" type="text" name="descripcion" id="descripcion" required>
</div>

<?php if (isset($error)) : ?>
<div class="alert alert-danger"><?= $error ?></div>
<?php endif; ?>

<div class="text-center">
<input class="btn btn-warning w-100 mt-3" type="submit" value="Agregar Producto">
</div>
</form>
</div>
</div>
</body>

</html>
47 changes: 47 additions & 0 deletions examen-sesiones/ejercicio2/functiones.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
session_start();

$productos = [
[
"nombre" => "manzana",
"precio" => "0.33€",
"descripcion" => "es una manzana"
],
[
"nombre" => "leche",
"precio" => "1.29€",
"descripcion" => "un litro de leche"
],
[
"nombre" => "canelones",
"precio" => "5.99€",
"descripcion" => "pack de 6 canelones"
],
[
"nombre" => "zanahoria",
"precio" => "0.20€",
"descripcion" => "es naranja"
],
[
"nombre" => "mango",
"precio" => "2.99€",
"descripcion" => "bastante dulce"
]
];

if (!isset($_SESSION["productos"])) {
$_SESSION["productos"] = $productos;
}

function agregar()
{
foreach ($_SESSION['productos'] as $producto) {
echo '
<tr>
<td>' . $producto['nombre'] . '</td>
<td>' . $producto['precio'] . '</td>
<td>' . $producto['descripcion']. '</td>
</tr>
';
}
}
44 changes: 44 additions & 0 deletions examen-sesiones/ejercicio2/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
session_start();
include 'functiones.php';
?>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>

<body class="bg-light text-dark">

<div class="container mt-5">
<h2 class="text-center mb-4">Productos</h2>

<table class="table table-striped table-bordered table-hover">
<thead class="table-light">
<tr>
<th>Nombre</th>
<th>Precio</th>
<th>Descripción</th>
</tr>
</thead>
<tbody>
<?php
agregar();
?>
</tbody>
</table>

<div class="text-center mt-3">
<a href="agregarProducto.php" class="btn btn-primary">Agregar nuevo</a>
</div>
</div>

</body>

</html>
27 changes: 27 additions & 0 deletions examen-sesiones/ejercicio3/home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
session_start();
?>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>home</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>

<body class="bg-light text-dark">

<div class="container d-flex justify-content-center align-items-center" style="height: 100vh;">
<div class="text-center">
<h1 class="mb-4">Hola, <?= $_SESSION['user']; ?></h1>
<form action="logout.php" method="POST">
<button type="submit" class="btn btn-danger">Cerrar Sesión</button>
</form>
</div>
</div>
</body>

</html>
Loading