Compare commits
15 Commits
bb3a34af71
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 35ee82dcf9 | |||
| 29f5fc3d08 | |||
| 06fc0ee834 | |||
| 2f48dbdb45 | |||
| 3439474297 | |||
| e0be3772ad | |||
| 2eb0e06e7b | |||
| cea9405670 | |||
| ac6c9c7d8a | |||
| d72a399125 | |||
| 560be43dff | |||
| d5ec1107a1 | |||
| 11eeb5339c | |||
| a37b2c9a64 | |||
| 84e6977fd7 |
117
Practicas/Practicas_PHP/POO/INTRO8_PHP_POO.php
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>INTRO8 POO EN PHP</title>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>POO EN PHP</h1>
|
||||||
|
<h2>Clases en POO</h2>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Definición de la clase
|
||||||
|
class Coche {
|
||||||
|
// Propiedades
|
||||||
|
public $marca;
|
||||||
|
public $modelo;
|
||||||
|
public $color;
|
||||||
|
|
||||||
|
// Método constructor
|
||||||
|
public function __construct($marca, $modelo, $color) {
|
||||||
|
$this->marca = $marca;
|
||||||
|
$this->modelo = $modelo;
|
||||||
|
$this->color = $color;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Método para mostrar la información del coche
|
||||||
|
public function mostrarInformacion() {
|
||||||
|
echo "Marca: " . $this->marca . "<br>";
|
||||||
|
echo "Modelo: " . $this->modelo . "<br>";
|
||||||
|
echo "Color: " . $this->color . "<br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creación de un objeto (instancia de la clase Coche)
|
||||||
|
$miCoche = new Coche("Toyota", "Corolla", "Rojo");
|
||||||
|
|
||||||
|
var_dump($miCoche);
|
||||||
|
$miCoche->marca = "Seat"; // Modificar una propiedad
|
||||||
|
var_dump($miCoche);
|
||||||
|
|
||||||
|
|
||||||
|
// Acceso a las propiedades del objeto y llamada a un método
|
||||||
|
echo "<h2>Información de mi coche:</h2>";
|
||||||
|
$miCoche->mostrarInformacion();
|
||||||
|
|
||||||
|
//Herencia
|
||||||
|
// Definición de la clase hija CocheDeportivo que hereda de Coche (Superclase y subclase)
|
||||||
|
class CocheDeportivo extends Coche {
|
||||||
|
// Propiedades adicionales para un coche deportivo
|
||||||
|
public $potencia;
|
||||||
|
public $aceleracion;
|
||||||
|
|
||||||
|
// Método constructor
|
||||||
|
public function __construct($marca, $modelo, $color, $potencia, $aceleracion) {
|
||||||
|
// Llamada al constructor de la clase padre
|
||||||
|
parent::__construct($marca, $modelo, $color);
|
||||||
|
// Asignación de las propiedades adicionales
|
||||||
|
$this->potencia = $potencia;
|
||||||
|
$this->aceleracion = $aceleracion;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Método para mostrar información específica de un coche deportivo
|
||||||
|
public function mostrarInformacionDeportiva() {
|
||||||
|
//parent::mostrarInformacion();
|
||||||
|
echo "Potencia: " . $this->potencia . "<br>";
|
||||||
|
echo "Aceleración: " . $this->aceleracion . "<br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creación de un objeto CocheDeportivo
|
||||||
|
$miCocheDeportivo = new CocheDeportivo("Ferrari", "458 Italia", "Rojo", "570 CV", "3,4 segundos");
|
||||||
|
|
||||||
|
// Acceso a los métodos de la clase base y de la clase hija
|
||||||
|
echo "<h2>Información de mi coche deportivo:</h2>";
|
||||||
|
$miCocheDeportivo->mostrarInformacion(); // Método de la clase base
|
||||||
|
$miCocheDeportivo->mostrarInformacionDeportiva(); // Método de la clase hija
|
||||||
|
|
||||||
|
|
||||||
|
// Encapsulación
|
||||||
|
class Persona {
|
||||||
|
private $nombre;
|
||||||
|
private $edad;
|
||||||
|
|
||||||
|
public function __construct($nombre, $edad) {
|
||||||
|
$this->nombre = $nombre;
|
||||||
|
$this->edad = $edad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNombre() {
|
||||||
|
return $this->nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNombre($nombre) {
|
||||||
|
$this->nombre = $nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEdad() {
|
||||||
|
return $this->edad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEdad($edad) {
|
||||||
|
$this->edad = $edad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$persona = new Persona("Juan", 30);
|
||||||
|
|
||||||
|
//$persona->nombre = "Pedro";Acceso privado
|
||||||
|
//echo $persona->nombre; // Acceso privado
|
||||||
|
echo "Nombre: " . $persona->getNombre() . ", Edad: " . $persona->getEdad();
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
//Abrir un directorio y obtener un identificador de directorio
|
||||||
|
//$conexion=opendir($ruta);
|
||||||
|
|
||||||
|
// Leer el directorio (lee tanto archivos como subdirectorios) va de uno en uno.
|
||||||
|
//readdir($conexion);
|
||||||
|
|
||||||
|
// Saber si es un archivo o un subdirectorio
|
||||||
|
//is_dir($ruta_archivo) Verifica si una ruta dada es un directorio.
|
||||||
|
//is_file($ruta_archivo) Verifica si una ruta dada es un archivo.
|
||||||
|
|
||||||
|
// Cerrar conexión
|
||||||
|
//closedir($conexion);
|
||||||
|
|
||||||
|
|
||||||
|
///// Otras operaciones con directorios
|
||||||
|
//rewinddir(): Reinicia el puntero del directorio al principio del directorio
|
||||||
|
//scandir(): Devuelve un array de nombres de archivos y subdirectorios
|
||||||
|
//mkdir($ruta_nuevo_directorio): Crea un nuevo directorio
|
||||||
|
//rmdir(): Elimina un directorio vacío.
|
||||||
|
//chdir(): Cambia el directorio actual a la ruta especificada.
|
||||||
|
//getcwd(): Devuelve el directorio de trabajo actual.
|
||||||
|
//realpath(): Devuelve la ruta real absoluta de un archivo o directorio
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////Operaciones para la gestión de archivos
|
||||||
|
//file_exists() Comprueba si un archivo o directorio
|
||||||
|
//filesize() Obtiene el tamaño del archivo en bytes.
|
||||||
|
//rename() Cambia el nombre de un archivo o directorio.
|
||||||
|
//rename($viejo_nombre, $nuevo_nombre)
|
||||||
|
|
||||||
|
//unlink() Elimina un archivo.
|
||||||
|
|
||||||
|
//copy() Copia un archivo.
|
||||||
|
//copy($archivo_origen, $archivo_destino)
|
||||||
|
|
||||||
|
//Ejemplo
|
||||||
|
//echo getcwd();
|
||||||
|
//mkdir("prueba/");
|
||||||
|
//rmdir("prueba/");
|
||||||
|
//chdir("prueba/");
|
||||||
|
//echo getcwd();
|
||||||
|
//scandir();
|
||||||
|
//var_dump(scandir(.));
|
||||||
|
//echo realpath("prueba/");
|
||||||
|
//unlink("prueba_1.txt");
|
||||||
44
Practicas/Practicas_PHP/codigo/INTRO7_PHP_ENVIAR_CORREOS.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>INTRO7 PHP ENVIAR EMAIL</title>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>1. ENVIAR EMAIL</h2>
|
||||||
|
<?php
|
||||||
|
// Envío de mail en PHP
|
||||||
|
|
||||||
|
// Necesitamos un servidor SMTP (Postfix, Sendmail,Exim o Mercury Mail).
|
||||||
|
// Configuración del servidor SMTP (En UNISERVER MSMTP).
|
||||||
|
// Nosotros lo usaremos con la cuenta de Gmail del curso.
|
||||||
|
|
||||||
|
// Función mail()
|
||||||
|
//mail(dirección del destinatario, el asunto,cuerpo del mensaje, encabezados)
|
||||||
|
//Headers////////////"\r\n"
|
||||||
|
//Remitente $headers = 'From: miemail@example.com';
|
||||||
|
//Asunto $headers = 'Subject: Asunto del correo';
|
||||||
|
//Responder a $headers = 'Reply-To: responder@example.com';
|
||||||
|
//Con copia $headers = 'Cc: copia1@example.com, copia2@example.com';
|
||||||
|
//Con copia oculta $headers = 'Bcc: oculta1@example.com, oculta2@example.com';
|
||||||
|
//Cabecera tipo MIME $headers = "MIME-Version: 1.0" . "\r\n";
|
||||||
|
//Cabecera Tipo contenido para HTML $headers = "Content-type:text/html;charset=UTF-8" . "\r\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Prueba de envío
|
||||||
|
$destinatario ="appasin12@gmail.com";
|
||||||
|
$asunto="Prueba correo desde PHP";
|
||||||
|
$mensaje="Esta es una prueba de envío de correo desde mi servidor PHP \r\n Y ha salido muy bien";
|
||||||
|
$headers='Bcc: otrocorreo@gmail.com'."\r\n".'Reply-To: appasin04@gmail.com'. "\r\n";
|
||||||
|
if (mail($destinatario,$asunto,$mensaje,$headers)) {
|
||||||
|
echo "Correo enviado";
|
||||||
|
} else { echo "No se ha podido enviar el correo";}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
38
Practicas/Practicas_PHP/codigo/INTRO_PHP_HEADER.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
// La función header() permite enviar encabezados HTTP desde el servidor al cliente.
|
||||||
|
//Para que:
|
||||||
|
|
||||||
|
//- Tipo de Contenido (Content-Type): Especificar el tipo de contenido
|
||||||
|
header('Content-Type: text/html');
|
||||||
|
|
||||||
|
//- Redirecciones: Redirigir al usuario a otra página utilizando el encabezado Location.
|
||||||
|
header('Location: http://www.ejemplo.com/nueva_pagina.php');
|
||||||
|
|
||||||
|
//- Redirigir despues de un tiempo - header('Refresh: segundos; url=URL');
|
||||||
|
header('Refresh: 5; url=http://www.ejemplo.com/otra_pagina.php');
|
||||||
|
|
||||||
|
//-Control de Caché: Controlar cómo se almacenan en caché las páginas web.
|
||||||
|
header('Cache-Control: no-cache, no-store, must-revalidate');
|
||||||
|
|
||||||
|
//- Codificación (Content-Encoding): Especificar la codificación del contenido que se está enviando.
|
||||||
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
|
|
||||||
|
//- Descarga de Archivos: Forzar la descarga de archivos adjuntos mediante encabezados específicos.
|
||||||
|
header('Content-Type: application/pdf');
|
||||||
|
header('Content-Disposition: attachment; filename="nombre_archivo.pdf"');
|
||||||
|
|
||||||
|
//- Control de Cookies: Configurar cookies para ser enviadas al cliente.
|
||||||
|
header('Set-Cookie: nombre=valor; expires=Fecha; path=Ruta; domain=Dominio', false);
|
||||||
|
|
||||||
|
/////Construir una URL que incluya parámetros GET (LOCATION,REFRESH)
|
||||||
|
|
||||||
|
$pagina = 'pagina.php';
|
||||||
|
$id = 123;
|
||||||
|
$nombre = 'Ejemplo';
|
||||||
|
|
||||||
|
$url = $pagina . '?id=' . urlencode($id) . '&nombre=' . urlencode($nombre);
|
||||||
|
echo $url;
|
||||||
|
|
||||||
|
//pagina.php?id=123&nombre=Ejemplo
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/***** Explicación *****/
|
||||||
|
// array_diff: Compara $claves_a_comprobar con $___SESSION y devuelve los valores de $claves_a_comprobar que no estén presentes en $___SESSION (si están todas, devuelve un array vacío)
|
||||||
|
// array_keys: Devuelve un array con todas las claves de array
|
||||||
|
|
||||||
|
// Comprobación básica => array_diff($claves_a_comprobar, array_keys($___SESSION)
|
||||||
|
// Forma 1 => array_diff($claves_a_comprobar, array_keys($___SESSION)) === []
|
||||||
|
// Forma 2 => empty(array_diff($claves_a_comprobar, array_keys($___SESSION)))
|
||||||
|
// Forma 3 => count(array_diff($claves_a_comprobar, array_keys($___SESSION))) === 0
|
||||||
|
|
||||||
|
/***** Ejemplo *****/
|
||||||
|
$___SESSION = [
|
||||||
|
'cero' => 0,
|
||||||
|
'uno' => '1',
|
||||||
|
'dos' => 'dos',
|
||||||
|
'tres' => 3,
|
||||||
|
'cuatro' => '4',
|
||||||
|
];
|
||||||
|
|
||||||
|
/*----- Caso 1: Todas las claves existen -----*/
|
||||||
|
$claves_a_comprobar = ['uno', 'dos', 'tres'];
|
||||||
|
|
||||||
|
// Forma 1
|
||||||
|
if(array_diff($claves_a_comprobar, array_keys($___SESSION)) === []) {
|
||||||
|
echo 'OK-[]' . PHP_EOL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo 'NOOOO-[]' . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forma 2
|
||||||
|
if(empty(array_diff($claves_a_comprobar, array_keys($___SESSION)))) {
|
||||||
|
echo 'OK-EMPTY' . PHP_EOL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo 'NOOOO-EMPTY' . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forma 3
|
||||||
|
if(count(array_diff($claves_a_comprobar, array_keys($___SESSION))) === 0) {
|
||||||
|
echo 'OK-COUNT' . PHP_EOL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo 'NOOOO-COUNT' . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----- Caso 2: No existen todas las claves -----*/
|
||||||
|
$claves_a_comprobar = ['uno', 'two', 'tres'];
|
||||||
|
|
||||||
|
// Forma 1
|
||||||
|
if(array_diff($claves_a_comprobar, array_keys($___SESSION)) === []) {
|
||||||
|
echo 'OK-[]' . PHP_EOL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo 'NOOOO-[]' . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forma 2
|
||||||
|
if(empty(array_diff($claves_a_comprobar, array_keys($___SESSION)))) {
|
||||||
|
echo 'OK-EMPTY' . PHP_EOL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo 'NOOOO-EMPTY' . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forma 3
|
||||||
|
if(count(array_diff($claves_a_comprobar, array_keys($___SESSION))) === 0) {
|
||||||
|
echo 'OK-COUNT' . PHP_EOL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo 'NOOOO-COUNT' . PHP_EOL;
|
||||||
|
}
|
||||||
21
Practicas/Practicas_PHP/codigo/cookies/INTRO_COOKIES_PHP.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Mecanismo cookies
|
||||||
|
//1.Creación en el servidor
|
||||||
|
//2.Almacenamiento en el cliente
|
||||||
|
//3.Envío al servidor con cada solicitud Http
|
||||||
|
//4.Procesamiento en el servidor
|
||||||
|
//5.Actualización o eliminación
|
||||||
|
|
||||||
|
|
||||||
|
// Establecer cookies -- No estrán disponibles hasta la siguiente petición HTTP.
|
||||||
|
//setcookie($nombre, $valor = "", $vencimiento = 0, $ruta = "", $dominio = "", $seguro = false, $httponly = false)
|
||||||
|
//$vencimiento en tiempo UNIX si se establece en 0 se convierte en cookie de sesión.
|
||||||
|
//$ruta en la que estará disponible, por defecto directorio actual, si se establece '/' será valida para todo el dominio.
|
||||||
|
//$dominio en el que estará disponible, por defecto para el dominio actual.
|
||||||
|
//$seguro si se envía solo por https(true)
|
||||||
|
//$httponly si es accesible desde javascript (false)
|
||||||
|
setrawcookie("nombre", "Juan", time() + 3600, "/"); // Cookie con nombre "nombre" y valor "Juan", válida por una hora
|
||||||
|
setcookie("idioma", "es", time() + (86400 * 30), "/"); // Cookie con nombre "idioma" y valor "es", válida por 30 días
|
||||||
|
setcookie("ultima_visita", date("Y-m-d H:i:s"), time() + 3600, "/"); // Cookie con nombre "ultima_visita" y valor de la fecha y hora actual, válida por una hora
|
||||||
|
?>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
// Acceder a las cookies desde otra página
|
||||||
|
|
||||||
|
|
||||||
|
// Leer cookies
|
||||||
|
$nombre = $_COOKIE['nombre'];
|
||||||
|
$idioma = $_COOKIE['idioma'];
|
||||||
|
$ultimaVisita = $_COOKIE['ultima_visita'];
|
||||||
|
|
||||||
|
var_dump($_COOKIE);
|
||||||
|
|
||||||
|
// Mostrar valores de las cookies
|
||||||
|
echo "Hola, $nombre. ";
|
||||||
|
echo "Tu idioma preferido es $idioma. ";
|
||||||
|
echo "Tu última visita fue el $ultimaVisita.";
|
||||||
|
?>
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
// Sesiones en PHP
|
||||||
|
//Pasos uso de sesiones en PHP
|
||||||
|
/*
|
||||||
|
1. Identificación de sesión: se le asigna un identificador y se guarda en una cookie del navegador.
|
||||||
|
|
||||||
|
2. Almacenamiento de datos de sesión: variable superglobal $_SESSION se utiliza para acceder y modificar estos datos.
|
||||||
|
|
||||||
|
3. Inicio y cierre de sesión: Inicio de sesión session_start(). Esto inicializa o reanuda una sesión existente.
|
||||||
|
Una vez que la sesión ha comenzado, se pueden guardar y recuperar datos utilizando la superglobal $_SESSION.
|
||||||
|
Finalizar una sesión, se utiliza session_destroy(), elimina todos los datos y destruye la sesión.
|
||||||
|
|
||||||
|
4. Configuración de sesiones: configuración php.ini o mediante funciones como session_set_cookie_params().
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Crear una Sesión
|
||||||
|
session_start(); // Lo primero que debe aparecer en la página
|
||||||
|
// Definir Variables
|
||||||
|
$_SESSION['nombre'] = 'Juan';
|
||||||
|
$_SESSION['apellido'] = 'Perez';
|
||||||
|
// Modificar variables
|
||||||
|
$_SESSION['apellido'] = 'Porto';
|
||||||
|
// Consultar la sesión
|
||||||
|
echo '<br>';
|
||||||
|
var_dump($_SESSION);
|
||||||
|
// Añadir variables
|
||||||
|
$_SESSION['apodo'] = 'Totoki';
|
||||||
|
// ID de sesión la indentifica
|
||||||
|
echo '<br>';
|
||||||
|
echo session_id();
|
||||||
|
echo '<br>';
|
||||||
|
var_dump($_SESSION);
|
||||||
|
// Destruir la sesión
|
||||||
|
//$_SESSION = []; // Borra las variables pero la sesión sigue activa
|
||||||
|
//session_destroy() // Finaliza la sesión y borra los datos
|
||||||
|
echo '<br>';
|
||||||
|
//var_dump($_SESSION);
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>INTRO8 PHP SESIONES</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<a href="INTRO8_PHP_SESIONES2.php">Continuar sesión</a>
|
||||||
|
<a href="destruir_sesion.php">Cerrar sesión</a>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>INTRO8 PHP SESIONES2</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
//Conectar a una Sesión
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
//Añadimos una variable
|
||||||
|
$_SESSION['edad'] = '30';
|
||||||
|
// Accedo a datos de la sesión
|
||||||
|
echo $_SESSION['nombre'];
|
||||||
|
echo '<br>';
|
||||||
|
echo $_SESSION['apellido'];
|
||||||
|
echo '<br>';
|
||||||
|
echo $_SESSION['apodo'];
|
||||||
|
echo '<br>';
|
||||||
|
echo $_SESSION['edad'];
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>INTRO8 PHP SESIONES3</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// Sesiones en PHP
|
||||||
|
// Nombrar la sesión o consultar su nombre , por defecto(PHPSESSID)
|
||||||
|
session_name("ejemplo1");// Se debe usar antes de iniciar la sesión
|
||||||
|
echo session_name();//Consultar nombre de sesión
|
||||||
|
//Parametros de la cookie de sesión
|
||||||
|
//session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
|
||||||
|
session_set_cookie_params(
|
||||||
|
0,//Tiempo de vida de la cookie de sesión, definido en segundos.
|
||||||
|
'/',//Ruta en el servidor donde la cookie trabajará.
|
||||||
|
'www.php.net',//Dominio de la cookie, por ejemplo 'www.php.net'.
|
||||||
|
false,//Si es true la cookie sólo será enviada sobre conexiones seguras.
|
||||||
|
false // Si es false puede ser accesible por javascript.
|
||||||
|
);
|
||||||
|
session_start();//Inicio la sesión
|
||||||
|
// Para consultar los parametros de la cookie de sesión
|
||||||
|
var_dump(session_get_cookie_params());
|
||||||
|
//Borrar todos los valores de $_SESSION
|
||||||
|
//session_unset();
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
44
Practicas/Practicas_PHP/codigo/sesiones/login.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<p>
|
||||||
|
<input type="text" name="usuario" placeholder="Usuario">
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<input type="password" name="contraseña" placeholder="Contraseña">
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<input type="submit" value="Entrar">
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Comprobamos que nos llega los datos del formulario
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||||
|
|
||||||
|
// Variables que teóricamente estarían en una base de datos o en un archivo
|
||||||
|
$usuarioBueno = 'flecha';
|
||||||
|
$contraseñaBuena = '5454';
|
||||||
|
|
||||||
|
// Variables del formulario
|
||||||
|
$usuario = isset($_POST['usuario']) ? $_POST['usuario'] : null;
|
||||||
|
$contraseña = isset($_POST['contraseña']) ? $_POST['contraseña'] : null;
|
||||||
|
|
||||||
|
// Comprobamos si los datos son correctos
|
||||||
|
if ($usuarioBueno === $usuario && $contraseñaBuena === $contraseña) {
|
||||||
|
// Si son correctos, creamos la sesión
|
||||||
|
session_start();
|
||||||
|
$_SESSION['usuario'] = $_POST['usuario'];
|
||||||
|
// Redireccionamos a la página personalizada
|
||||||
|
header('Location: perfil.php');
|
||||||
|
die();
|
||||||
|
} else {
|
||||||
|
// Si no son correctos, informamos al usuario
|
||||||
|
echo '<p style="color: red">El apodo o la contraseña es incorrecta.</p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
9
Practicas/Practicas_PHP/codigo/sesiones/logout.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
// Iniciamos las sesiones
|
||||||
|
session_start();
|
||||||
|
// Destruimos las sesiones
|
||||||
|
session_destroy();
|
||||||
|
// Llevamos a login.php
|
||||||
|
header('Location: login.php');
|
||||||
|
// Cortamos el script
|
||||||
|
die();
|
||||||
18
Practicas/Practicas_PHP/codigo/sesiones/perfil.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
// Comprobamos si existe la sesión de apodo
|
||||||
|
session_start();
|
||||||
|
if (!isset($_SESSION['usuario'])) {
|
||||||
|
// En caso contrario devolvemos a la página login.php
|
||||||
|
header('Location: login.php');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<!-- Saludamos -->
|
||||||
|
<h1>Bienvenido <?php echo $_SESSION['usuario']; ?></h1>
|
||||||
|
<!-- Botón para cerrar la sesión -->
|
||||||
|
<a href="logout.php">Cerrar sesión</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
$archivo = "formularios/registro.txt";
|
||||||
|
|
||||||
|
// Verifico si existe
|
||||||
|
if (file_exists($archivo)) {
|
||||||
|
/*
|
||||||
|
//Con file_get_contents
|
||||||
|
// Leo el contenido del archivo
|
||||||
|
$contenido = file_get_contents($archivo);
|
||||||
|
|
||||||
|
// Divide el contenido en líneas
|
||||||
|
$lineas = explode("\n", $contenido);
|
||||||
|
array_pop($lineas);// Borro la última línea vacia
|
||||||
|
//var_dump($lineas);
|
||||||
|
// Comienzo la tabla HTML
|
||||||
|
echo "<table border='1'>";
|
||||||
|
echo "<tr><th>Número</th><th>Nombre</th><th>Email</th><th>Ruta de Archivo</th></tr>";
|
||||||
|
|
||||||
|
// Itero sobre cada línea
|
||||||
|
$num=0;
|
||||||
|
foreach ($lineas as $linea) {
|
||||||
|
// Divido los datos de la línea utilizando el delimitador "/_/"
|
||||||
|
$datos = explode("/_/", $linea);
|
||||||
|
$num++;
|
||||||
|
// Muestra los datos en una fila de la tabla
|
||||||
|
echo "<tr>";
|
||||||
|
echo "<td>" . $num . "</td>"; // Número
|
||||||
|
echo "<td>" . $datos[0] . "</td>"; // Nombre
|
||||||
|
echo "<td>" . $datos[1] . "</td>"; // Email
|
||||||
|
echo "<td>" . $datos[2] . "</td>"; // Ruta de Archivo
|
||||||
|
echo "</tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cierro la tabla HTML
|
||||||
|
echo "</table>";
|
||||||
|
} else {
|
||||||
|
echo "El archivo no existe.";
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Con fgets
|
||||||
|
// Abrir el archivo en modo lectura
|
||||||
|
$gestor = fopen($archivo, "r");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Comienzo la tabla HTML
|
||||||
|
echo "<table border='1'>";
|
||||||
|
echo "<tr><th>Número</th><th>Nombre</th><th>Email</th><th>Ruta de Archivo</th></tr>";
|
||||||
|
|
||||||
|
$num = 0;
|
||||||
|
|
||||||
|
// Iterar sobre cada línea del archivo
|
||||||
|
while (($linea = fgets($gestor)) !== false) {
|
||||||
|
|
||||||
|
// Dividir los datos de la línea utilizando el delimitador "/_/"
|
||||||
|
$datos = explode("/_/", $linea);
|
||||||
|
|
||||||
|
// Incrementar el número de fila
|
||||||
|
$num++;
|
||||||
|
|
||||||
|
// Mostrar los datos en una fila de la tabla
|
||||||
|
echo "<tr>";
|
||||||
|
echo "<td>" . $num . "</td>"; // Número
|
||||||
|
echo "<td>" . $datos[0] . "</td>"; // Nombre
|
||||||
|
echo "<td>" . $datos[1] . "</td>"; // Email
|
||||||
|
echo "<td>" . $datos[2] . "</td>"; // Ruta de Archivo
|
||||||
|
echo "</tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cerrar el archivo
|
||||||
|
fclose($gestor);
|
||||||
|
|
||||||
|
// Cerrar la tabla HTML
|
||||||
|
echo "</table>";
|
||||||
|
} else {
|
||||||
|
echo "El archivo no existe.";
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
// Con fgetcsv
|
||||||
|
|
||||||
|
echo '<table border="2">';
|
||||||
|
$archivo = fopen($nombre_archivo,'r');
|
||||||
|
while(($linea = fgetcsv($archivo, 0, ';'))) {
|
||||||
|
echo '<tr>';
|
||||||
|
echo '<td>' . $linea[0] . '</td>';
|
||||||
|
echo '<td>' . $linea[1] . '</td>';
|
||||||
|
echo '<td>' . $linea[2] . '</td>';
|
||||||
|
echo '</tr>';
|
||||||
|
}
|
||||||
|
echo '<table>';
|
||||||
|
fclose($archivo);
|
||||||
|
*/
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
$tamanoMaximo = 5 * 1024 * 1024;
|
$tamanoMaximo = 5 * 1024 * 1024;
|
||||||
|
|
||||||
if ($tamanoArchivo <= $tamanoMaximo && in_array($tipoArchivo, $ext_permitidas)) {
|
if ($tamanoArchivo <= $tamanoMaximo && in_array($tipoArchivo, $ext_permitidas)) {
|
||||||
$nombreUnico = time() . "_" . mt_rand(100, 999) . "_" . $email . "_" . $nombre_archivo . "." . $tipoArchivo;
|
$nombreUnico = time() . "_" . mt_rand(100, 999) . "_" . $email . "_" . $nombre_archivo;
|
||||||
$rutaArchivoDestino = $directorioDestino . $nombreUnico;
|
$rutaArchivoDestino = $directorioDestino . $nombreUnico;
|
||||||
move_uploaded_file($_FILES["nif"]["tmp_name"], $rutaArchivoDestino);
|
move_uploaded_file($_FILES["nif"]["tmp_name"], $rutaArchivoDestino);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
49
Practicas/Practicas_PHP/ejercicios/Ejercicio6V2_04.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Ejercicio6v2_04</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$nombre_archivo = "formularios/registro.txt";
|
||||||
|
$contenido = file_get_contents($nombre_archivo);
|
||||||
|
|
||||||
|
$lineas = array();
|
||||||
|
$archivo = fopen($nombre_archivo, 'r');
|
||||||
|
|
||||||
|
while (($linea = fgets($archivo)) !== false) {
|
||||||
|
$lineas[] = $linea;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($archivo);
|
||||||
|
|
||||||
|
echo '<table border="2">
|
||||||
|
<tr>
|
||||||
|
<th># Index</th>
|
||||||
|
<th>Nombre</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Ruta archivo</th>
|
||||||
|
</tr>
|
||||||
|
<tbody>';
|
||||||
|
foreach ($lineas as $index => $linea) {
|
||||||
|
$contenido_linea = explode("/_/", $linea);
|
||||||
|
echo '<tr>';
|
||||||
|
echo '<td>' . $index + 1 . '</td>';
|
||||||
|
foreach ($contenido_linea as $contenido) {
|
||||||
|
echo '<td>' . $contenido . '</td>';
|
||||||
|
}
|
||||||
|
echo '</tr>';
|
||||||
|
}
|
||||||
|
echo '</tbody>
|
||||||
|
</table>';
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
51
Practicas/Practicas_PHP/ejercicios/Ejercicio6_04.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Ejercicio6_04</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
<label for="nombre">Nombre: </label><input type="text" name="nombre" id="nombre" required> <br><br>
|
||||||
|
<label for="email">E-Mail: </label><input type="text" name="email" id="email" required> <br><br>
|
||||||
|
<label for="nif">NIF: </label><input type="file" name="nif" id="nif" accept=".jpg,.pdf" required> <br> <br>
|
||||||
|
<input type="submit" value="Enviar">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<a href="./Ejercicio6V2_04.php"> Ir a la vista de tabla</a>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["nif"])) {
|
||||||
|
|
||||||
|
$directorioDestino = 'uploads/';
|
||||||
|
|
||||||
|
$nombre = $_POST['nombre'];
|
||||||
|
$email = $_POST['email'];
|
||||||
|
$nombre_archivo = basename($_FILES["nif"]['name']);
|
||||||
|
$tipoArchivo = strtolower(pathinfo($nombre_archivo, PATHINFO_EXTENSION));
|
||||||
|
|
||||||
|
$tamanoArchivo = $_FILES["nif"]["size"];
|
||||||
|
$ext_permitidas = array("jpg", "pdf");
|
||||||
|
$tamanoMaximo = 5 * 1024 * 1024;
|
||||||
|
|
||||||
|
if ($tamanoArchivo <= $tamanoMaximo && in_array($tipoArchivo, $ext_permitidas)) {
|
||||||
|
$nombreUnico = time() . "_" . mt_rand(100, 999) . "_" . $email . "_" . $nombre_archivo;
|
||||||
|
$rutaArchivoDestino = $directorioDestino . $nombreUnico;
|
||||||
|
move_uploaded_file($_FILES["nif"]["tmp_name"], $rutaArchivoDestino);
|
||||||
|
|
||||||
|
$archivo="formularios/registro.txt";
|
||||||
|
$contenido=$nombre."/_/".$email."/_/".$rutaArchivoDestino."\r\n";
|
||||||
|
file_put_contents($archivo, $contenido,FILE_APPEND | LOCK_EX);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
echo 'No se ha podido subir el fichero';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Formulario de Registro</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>Formulario de Registro</h2>
|
||||||
|
<form action="" method="post">
|
||||||
|
<label for="nombre">Nombre:</label>
|
||||||
|
<input type="text" id="nombre" name="nombre" required><br><br>
|
||||||
|
<label for="email">Correo Electrónico:</label>
|
||||||
|
<input type="email" id="email" name="email" required><br><br>
|
||||||
|
<input type="submit" value="Enviar">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
// Obtener los datos del formulario
|
||||||
|
$nombre = $_POST["nombre"];
|
||||||
|
$email = $_POST["email"];
|
||||||
|
|
||||||
|
// Abrir el archivo para escritura (modo append)
|
||||||
|
$archivo = fopen("usuarios.txt", "a");
|
||||||
|
|
||||||
|
// Escribir los datos en el archivo
|
||||||
|
fwrite($archivo,"$nombre - $email" . PHP_EOL);
|
||||||
|
|
||||||
|
// Cerrar el archivo
|
||||||
|
fclose($archivo);
|
||||||
|
|
||||||
|
echo "¡Datos guardados correctamente!";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<p></p>
|
||||||
|
<h2>Pulsa el enlace para ver la tabla de usuarios</h2>
|
||||||
|
<a href="leer_usuarios.php">Tabla de usuarios</a>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
33
Practicas/Practicas_PHP/ejercicios/Ejercicio7_04.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Ejercicio7_04</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
<label for="nombre">Nombre: </label><input type="text" name="nombre" id="nombre" required> <br><br>
|
||||||
|
<label for="email">E-Mail: </label><input type="text" name="email" id="email" required> <br><br>
|
||||||
|
<input type="submit" value="Enviar">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<a href="./Ejercicio7_04_Tabla.php">Tabla de usuarios introducidos</a>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$nombre = $_POST['nombre'];
|
||||||
|
$email = $_POST['email'];
|
||||||
|
|
||||||
|
$nombre_archivo = "formularios/usuarios.txt";
|
||||||
|
$archivo = fopen($nombre_archivo, 'a');
|
||||||
|
fwrite($archivo, $nombre . " - " . $email . PHP_EOL);
|
||||||
|
fclose($archivo);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
48
Practicas/Practicas_PHP/ejercicios/Ejercicio7_04_Tabla.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Ejercicio7_04_Tabla</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$nombre_archivo = "formularios/usuarios.txt";
|
||||||
|
$contenido = file_get_contents($nombre_archivo);
|
||||||
|
|
||||||
|
$lineas = array();
|
||||||
|
$archivo = fopen($nombre_archivo, 'r');
|
||||||
|
|
||||||
|
while (($linea = fgets($archivo)) !== false) {
|
||||||
|
$lineas[] = $linea;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($archivo);
|
||||||
|
|
||||||
|
echo '<table border="2">
|
||||||
|
<tr>
|
||||||
|
<th># Index</th>
|
||||||
|
<th>Nombre</th>
|
||||||
|
<th>Email</th>
|
||||||
|
</tr>
|
||||||
|
<tbody>';
|
||||||
|
foreach ($lineas as $index => $linea) {
|
||||||
|
$contenido_linea = explode(" - ", $linea);
|
||||||
|
echo '<tr>';
|
||||||
|
echo '<td>' . $index + 1 . '</td>';
|
||||||
|
foreach ($contenido_linea as $contenido) {
|
||||||
|
echo '<td>' . $contenido . '</td>';
|
||||||
|
}
|
||||||
|
echo '</tr>';
|
||||||
|
}
|
||||||
|
echo '</tbody>
|
||||||
|
</table>';
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 3.3 MiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 255 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 64 KiB |
158
Practicas/Practicas_PHP/ejercicios/Plantilla Examen/busqueda.php
Executable file
@@ -0,0 +1,158 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<?php
|
||||||
|
echo $_COOKIE['tema'] === 'claro' ? '<link rel="stylesheet" type="text/css" href="estilos_claro.css" />'
|
||||||
|
: '<link rel="stylesheet" type="text/css" href="estilos.css" />' ?>
|
||||||
|
<title>Busqueda y eliminacion de registros</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
$nombre_usuario = $_SESSION['nombre'];
|
||||||
|
$tipo_usuario = $_SESSION['tipo'];
|
||||||
|
echo "<div>
|
||||||
|
<h2>Bienvenido $nombre_usuario </h2>
|
||||||
|
<a href=\"logout.php\">Cerrar session</a>
|
||||||
|
</div>"
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<p>*Término a buscar: </p>
|
||||||
|
<p><input type="text" name="termBusqueda" id="termBusqueda" size="30" placeholder="Introduzca la palabra de Busqueda" required></p>
|
||||||
|
<input type="submit" name="buscar" value="Buscar">
|
||||||
|
</form>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
include_once('caracteres.php');
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['buscar'])) {
|
||||||
|
$termBusqueda = isset($_POST['termBusqueda']) ? $_POST['termBusqueda'] : '';
|
||||||
|
$termBusqueda !== "" ? busqueda($termBusqueda) : null;
|
||||||
|
unset($_POST);
|
||||||
|
}
|
||||||
|
|
||||||
|
function busqueda($termBusqueda)
|
||||||
|
{
|
||||||
|
$termBusqueda = eliminar_tildes(strtolower($termBusqueda));
|
||||||
|
$nombre_archivo = "listado_reservas.txt";
|
||||||
|
$registros = [];
|
||||||
|
$archivo = fopen($nombre_archivo, 'r');
|
||||||
|
|
||||||
|
while (($linea = fgets($archivo)) !== false) {
|
||||||
|
if (strpos(eliminar_tildes(strtolower($linea)), $termBusqueda) !== false) {
|
||||||
|
$registros[] = $linea;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($archivo);
|
||||||
|
|
||||||
|
if (count($registros) > 0) {
|
||||||
|
echo "<table>
|
||||||
|
<tbody>
|
||||||
|
<thead>
|
||||||
|
<th>Id Reserva</th>
|
||||||
|
<th>Nombre</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Nº Telefono</th>
|
||||||
|
<th>Fecha de entrada</th>
|
||||||
|
<th>Fecha de salida</th>
|
||||||
|
<th>Fecha de registro</th>
|
||||||
|
<th>Nº de noches</th>
|
||||||
|
<th>Acciones</th>
|
||||||
|
</thead>";
|
||||||
|
foreach ($registros as $registro) {
|
||||||
|
$campos = explode("/_/", $registro);
|
||||||
|
echo "<tr>";
|
||||||
|
foreach ($campos as $campo) {
|
||||||
|
echo "<td> $campo </td>";
|
||||||
|
}
|
||||||
|
echo "<td>" . genButtonDel($campos[0]) . "</td>";
|
||||||
|
echo "</tr>";
|
||||||
|
}
|
||||||
|
echo "</tbody>";
|
||||||
|
echo "</table>";
|
||||||
|
} else {
|
||||||
|
echo "<div><h4> No se han encontrado registros con los terminos indicados </h4></div>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function genButtonDel($idReserva)
|
||||||
|
{
|
||||||
|
return "<form method=\"POST\" style=\"border: none; padding:0.2rem; min-width: auto; margin:0\">
|
||||||
|
<input type=\"hidden\" name=\"idReserva\" value=\"$idReserva\" style=\"border: none; padding:0; min-width: auto; margin:0\">
|
||||||
|
<input type=\"submit\" name=\"borrar\" value=\"Eliminar\" style=\"cursor: pointer; padding:0.2rem 0.4rem; min-width: auto; margin:0\">
|
||||||
|
</form>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<p>*ID de reserva para borrar: </p>
|
||||||
|
<input type="text" name="idReserva" value="" id="idReserva" size="15" minlength="15" maxlength="15" placeholder="Id de reserva" />
|
||||||
|
<input type="submit" name="borrar" value="Borrar reserva de alquiler">
|
||||||
|
</form>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['borrar'])) {
|
||||||
|
$idReserva = isset($_POST['idReserva']) ? $_POST['idReserva'] : '';
|
||||||
|
if ($idReserva !== "") {
|
||||||
|
echo "<div>";
|
||||||
|
echo "<h4>Actuaciones sobre el registro: $idReserva</h4> <br>";
|
||||||
|
echo eliminaDeLista($idReserva) ?
|
||||||
|
"<p>Se ha encontrado el registro en el archivo y se ha eliminado</p>" :
|
||||||
|
"<p>No se encontro el registro especificado en el archivo</p>";
|
||||||
|
echo eliminaRegistro($idReserva) ?
|
||||||
|
"<p>Se ha eliminado correctamente el registro de reserva</p>" :
|
||||||
|
"No se ha encontrado el registro de reserva especificado</p>";
|
||||||
|
echo eliminaUpload($idReserva) ?
|
||||||
|
"<p>Se ha eliminado el documento almacenado con el registro</p>" :
|
||||||
|
"<p>No se ha encontrado documentos asociados al registro</p>";
|
||||||
|
echo "</div>";
|
||||||
|
}
|
||||||
|
unset($_POST);
|
||||||
|
}
|
||||||
|
|
||||||
|
function eliminaDeLista($idReserva)
|
||||||
|
{
|
||||||
|
$nombre_archivo = "listado_reservas.txt";
|
||||||
|
$flagEncontrado = false;
|
||||||
|
$registros = [];
|
||||||
|
$archivo = fopen($nombre_archivo, 'r');
|
||||||
|
|
||||||
|
while (($linea = fgets($archivo)) !== false) {
|
||||||
|
if (strpos($linea, $idReserva) === false) {
|
||||||
|
$registros[] = $linea;
|
||||||
|
} else {
|
||||||
|
$flagEncontrado = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($archivo);
|
||||||
|
return ($flagEncontrado && file_put_contents($nombre_archivo, $registros));
|
||||||
|
}
|
||||||
|
|
||||||
|
function eliminaRegistro($idReserva)
|
||||||
|
{
|
||||||
|
$dir_reservas = "reservas/";
|
||||||
|
$nombre_archivo = "$idReserva.txt";
|
||||||
|
return file_exists($dir_reservas . $nombre_archivo) ?
|
||||||
|
unlink($dir_reservas . $nombre_archivo) :
|
||||||
|
false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function eliminaUpload($idReserva)
|
||||||
|
{
|
||||||
|
$dir_uploads = "dni_clientes/";
|
||||||
|
$file = glob($dir_uploads . "*" . $idReserva . "*");
|
||||||
|
return (count($file) > 0) ? unlink($file[0]) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
42
Practicas/Practicas_PHP/ejercicios/Plantilla Examen/caracteres.php
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
// Eliminar tildes
|
||||||
|
function eliminar_tildes($cadena){
|
||||||
|
|
||||||
|
//Codificamos la cadena en formato utf8 en caso de que nos de errores
|
||||||
|
//$cadena = utf8_encode($cadena);
|
||||||
|
|
||||||
|
//Ahora reemplazamos las letras
|
||||||
|
$cadena = str_replace(
|
||||||
|
array('á', 'à', 'ä', 'â', 'ª', 'Á', 'À', 'Â', 'Ä'),
|
||||||
|
array('a', 'a', 'a', 'a', 'a', 'A', 'A', 'A', 'A'),
|
||||||
|
$cadena
|
||||||
|
);
|
||||||
|
|
||||||
|
$cadena = str_replace(
|
||||||
|
array('é', 'è', 'ë', 'ê', 'É', 'È', 'Ê', 'Ë'),
|
||||||
|
array('e', 'e', 'e', 'e', 'E', 'E', 'E', 'E'),
|
||||||
|
$cadena );
|
||||||
|
|
||||||
|
$cadena = str_replace(
|
||||||
|
array('í', 'ì', 'ï', 'î', 'Í', 'Ì', 'Ï', 'Î'),
|
||||||
|
array('i', 'i', 'i', 'i', 'I', 'I', 'I', 'I'),
|
||||||
|
$cadena );
|
||||||
|
|
||||||
|
$cadena = str_replace(
|
||||||
|
array('ó', 'ò', 'ö', 'ô', 'Ó', 'Ò', 'Ö', 'Ô'),
|
||||||
|
array('o', 'o', 'o', 'o', 'O', 'O', 'O', 'O'),
|
||||||
|
$cadena );
|
||||||
|
|
||||||
|
$cadena = str_replace(
|
||||||
|
array('ú', 'ù', 'ü', 'û', 'Ú', 'Ù', 'Û', 'Ü'),
|
||||||
|
array('u', 'u', 'u', 'u', 'U', 'U', 'U', 'U'),
|
||||||
|
$cadena );
|
||||||
|
|
||||||
|
$cadena = str_replace(
|
||||||
|
array('ñ', 'Ñ', 'ç', 'Ç'),
|
||||||
|
array('n', 'N', 'c', 'C'),
|
||||||
|
$cadena
|
||||||
|
);
|
||||||
|
|
||||||
|
return $cadena;
|
||||||
|
}
|
||||||
129
Practicas/Practicas_PHP/ejercicios/Plantilla Examen/estilos.css
Executable file
@@ -0,0 +1,129 @@
|
|||||||
|
@charset "UTF-8";
|
||||||
|
|
||||||
|
*{
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
list-style: none;
|
||||||
|
text-decoration: none;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
p{
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width:80%;
|
||||||
|
min-width:350px;
|
||||||
|
margin:auto;
|
||||||
|
background-color:#9d2236;
|
||||||
|
border:2px solid #000000;
|
||||||
|
color:white;
|
||||||
|
}
|
||||||
|
|
||||||
|
td,th {
|
||||||
|
text-align: center;
|
||||||
|
padding:3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
form,div {
|
||||||
|
width:80%;
|
||||||
|
min-width:350px;
|
||||||
|
background-color:#9d2236;
|
||||||
|
border:2px solid #000000;
|
||||||
|
padding:10px;
|
||||||
|
box-sizing:border-box;
|
||||||
|
color:white;
|
||||||
|
font-size:18px;
|
||||||
|
margin:auto;
|
||||||
|
margin-top: 20px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldset {
|
||||||
|
background-color:#9d2236;
|
||||||
|
border:2px solid #ffffff;
|
||||||
|
padding:10px;
|
||||||
|
box-sizing:border-box;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#flex {
|
||||||
|
display:flex;
|
||||||
|
justify-content:space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
margin-right:10px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
color:white;
|
||||||
|
background-color:#9d2236;
|
||||||
|
border: 2px solid white;
|
||||||
|
padding: 2px;
|
||||||
|
min-width: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
legend {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 20px;
|
||||||
|
margin:10px;
|
||||||
|
}
|
||||||
|
select,option {
|
||||||
|
color:white;
|
||||||
|
background-color:#9d2236;
|
||||||
|
border: 2px solid white;
|
||||||
|
padding: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
background-color:#9d2236;
|
||||||
|
width:100%;
|
||||||
|
height:200px;
|
||||||
|
color:white;
|
||||||
|
border: 2px solid white;
|
||||||
|
padding:10px;
|
||||||
|
box-sizing:border-box;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=submit], input[type=button],input[type=reset] {
|
||||||
|
background-color:#9d2236;
|
||||||
|
color:white;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: lighter;
|
||||||
|
margin-top: 10px;
|
||||||
|
padding: 5px;
|
||||||
|
border:2px solid #000000;
|
||||||
|
border-radius:5px;
|
||||||
|
box-shadow: 1px 2px 3px #fff;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Media query para pantallas de menos de 450 píxeles de ancho */
|
||||||
|
@media (max-width: 450px) {
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
#flex {
|
||||||
|
flex-wrap:wrap;
|
||||||
|
flex-direction: column-reverse;
|
||||||
|
}
|
||||||
|
textarea {
|
||||||
|
margin-left: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
display: block;
|
||||||
|
width: 80%;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
@charset "UTF-8";
|
||||||
|
|
||||||
|
*{
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
list-style: none;
|
||||||
|
text-decoration: none;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
p{
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width:80%;
|
||||||
|
min-width:350px;
|
||||||
|
margin:auto;
|
||||||
|
background-color: #ffffff;;
|
||||||
|
border:2px solid #9d2236;
|
||||||
|
color:#9d2236;
|
||||||
|
}
|
||||||
|
|
||||||
|
td,th {
|
||||||
|
text-align: center;
|
||||||
|
padding:3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #9d2236;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
form,div {
|
||||||
|
width:80%;
|
||||||
|
min-width:350px;
|
||||||
|
background-color: #ffffff;
|
||||||
|
border:2px solid #9d2236;
|
||||||
|
padding:10px;
|
||||||
|
box-sizing:border-box;
|
||||||
|
color:#9d2236;
|
||||||
|
font-size:18px;
|
||||||
|
margin:auto;
|
||||||
|
margin-top: 20px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldset {
|
||||||
|
background-color: #ffffff;
|
||||||
|
border:2px solid #9d2236;
|
||||||
|
padding:10px;
|
||||||
|
box-sizing:border-box;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#flex {
|
||||||
|
display:flex;
|
||||||
|
justify-content:space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
margin-right:10px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
color:#9d2236;
|
||||||
|
background-color: #ffffff;
|
||||||
|
border:2px solid #9d2236;
|
||||||
|
padding: 2px;
|
||||||
|
min-width: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
legend {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 20px;
|
||||||
|
margin:10px;
|
||||||
|
}
|
||||||
|
select,option {
|
||||||
|
color:#9d2236;
|
||||||
|
background-color: #ffffff;
|
||||||
|
border:2px solid #9d2236;
|
||||||
|
padding: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
background-color: #ffffff;
|
||||||
|
width:100%;
|
||||||
|
height:200px;
|
||||||
|
color:#9d2236;
|
||||||
|
border:2px solid #9d2236;
|
||||||
|
padding:10px;
|
||||||
|
box-sizing:border-box;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=submit], input[type=button],input[type=reset] {
|
||||||
|
background-color: #ffffff;
|
||||||
|
color:#9d2236;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: lighter;
|
||||||
|
margin-top: 10px;
|
||||||
|
padding: 5px;
|
||||||
|
border:2px solid #9d2236;
|
||||||
|
border-radius:5px;
|
||||||
|
box-shadow: 1px 2px 3px #000;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Media query para pantallas de menos de 450 píxeles de ancho */
|
||||||
|
@media (max-width: 450px) {
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
#flex {
|
||||||
|
flex-wrap:wrap;
|
||||||
|
flex-direction: column-reverse;
|
||||||
|
}
|
||||||
|
textarea {
|
||||||
|
margin-left: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
display: block;
|
||||||
|
width: 80%;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
210
Practicas/Practicas_PHP/ejercicios/Plantilla Examen/formulario_hotel.php
Executable file
@@ -0,0 +1,210 @@
|
|||||||
|
<!Doctype html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
|
||||||
|
<title>Reservas hotel</title>
|
||||||
|
<?php
|
||||||
|
echo $_COOKIE['tema'] === 'claro' ? '<link rel="stylesheet" type="text/css" href="estilos_claro.css" />'
|
||||||
|
: '<link rel="stylesheet" type="text/css" href="estilos.css" />' ?>
|
||||||
|
<script>
|
||||||
|
// Función obtener() que realizará la captación de datos,los cálculos y la escritura del mensaje de info
|
||||||
|
|
||||||
|
function obtener() {
|
||||||
|
// Declaro y obtengo el valor de las variables
|
||||||
|
|
||||||
|
//Calcular periodo de la estancia (noches)
|
||||||
|
const inicio = document.getElementById("entradaH").valueAsNumber;
|
||||||
|
const fin = document.getElementById("salida").valueAsNumber;
|
||||||
|
const dif = fin - inicio;
|
||||||
|
const noches = Math.ceil(dif / (1000 * 60 * 60 * 24));
|
||||||
|
document.getElementById("noches").value = noches;
|
||||||
|
|
||||||
|
|
||||||
|
const habitacion = document.getElementById("habitacion").value;
|
||||||
|
const regimen = document.getElementById("regimen").value;
|
||||||
|
const spa = document.getElementById("spa").value;
|
||||||
|
const guia = document.getElementById("guia").value;
|
||||||
|
const nombreCliente = document.getElementById("nombre").value;
|
||||||
|
|
||||||
|
//Cáculo extras (spa y guia)
|
||||||
|
let spaT;
|
||||||
|
|
||||||
|
if (spa > 5) {
|
||||||
|
spaT = spa * 20;
|
||||||
|
} else {
|
||||||
|
spaT = spa * 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
let guiaT;
|
||||||
|
|
||||||
|
if (guia > 7) {
|
||||||
|
guiaT = guia * 40;
|
||||||
|
} else {
|
||||||
|
guiaT = guia * 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tipo habitación
|
||||||
|
let hotel;
|
||||||
|
if (habitacion === "simple") {
|
||||||
|
hotel = 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (habitacion === "doble") {
|
||||||
|
hotel = 80;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (habitacion === "triple") {
|
||||||
|
hotel = 120;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (habitacion === "suite") {
|
||||||
|
hotel = 150;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Tipo de regimen
|
||||||
|
let comidas;
|
||||||
|
if (regimen === "desayuno") {
|
||||||
|
comidas = 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regimen === "mediapension") {
|
||||||
|
comidas = 80;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regimen === "pensioncompleta") {
|
||||||
|
comidas = 120;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regimen === "todoincluido") {
|
||||||
|
comidas = 150;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gastos estancia hotel+comidas
|
||||||
|
const hotelT = hotel * noches;
|
||||||
|
const regimenT = comidas * noches;
|
||||||
|
|
||||||
|
const estancia = hotelT + regimenT;
|
||||||
|
|
||||||
|
// Descuento por larga estancia
|
||||||
|
let estanciaDescuento;
|
||||||
|
if (noches <= 4) {
|
||||||
|
estanciaDescuento = estancia;
|
||||||
|
} else if (noches >= 5 && noches <= 10) {
|
||||||
|
estanciaDescuento = estancia * 0.85;
|
||||||
|
} else if (noches >= 11) {
|
||||||
|
estanciaDescuento = estancia * 0.75;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Envío el precio total sin IVA al formulario
|
||||||
|
document.getElementById("estancia").value = estanciaDescuento;
|
||||||
|
|
||||||
|
//Coste total con extras
|
||||||
|
const total = estanciaDescuento + spaT + guiaT;
|
||||||
|
const totalI = (total * 1.21).toFixed(2);
|
||||||
|
// Envío el precio con IVA al formulario
|
||||||
|
document.getElementById("total").value = totalI;
|
||||||
|
// Precio de anulación
|
||||||
|
const precioAnulacion = (total * 0.2).toFixed(2);
|
||||||
|
|
||||||
|
|
||||||
|
// Calcular días que faltan y fecha de regreso
|
||||||
|
const hoy = new Date().getTime(); // Fecha de la reserva
|
||||||
|
const entrada = document.getElementById("entradaH").valueAsNumber;
|
||||||
|
const dif2 = entrada - hoy;
|
||||||
|
const diasFaltan = dif2 / (1000 * 60 * 60 * 24); // Días que faltan
|
||||||
|
|
||||||
|
const regresoF = new Date(fin); // Obtener en UTC
|
||||||
|
const regresoP = regresoF.toLocaleDateString(); //Pasar fecha a formato corto dd/mm/xxxx
|
||||||
|
|
||||||
|
const anulacion = entrada - (3 * 24 * 60 * 60 * 1000); //Fecha de anulación
|
||||||
|
const anulacionF = new Date(anulacion);
|
||||||
|
const anulacionP = anulacionF.toLocaleDateString();
|
||||||
|
//Mensaje de información
|
||||||
|
const frase =
|
||||||
|
"Hola " + nombreCliente + "\n" +
|
||||||
|
"Faltan " + (Math.ceil(diasFaltan)) + " días " + "para tu viaje" + "\n" +
|
||||||
|
"Tu fecha de regreso es el " + regresoP + "\n" +
|
||||||
|
"Puedes anular tu reserva hasta el día " + anulacionP + "\n" +
|
||||||
|
"El coste de la anulación será de " + precioAnulacion + " euros";
|
||||||
|
//Enviar mensaje al formulario
|
||||||
|
document.getElementById("info").value = frase;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
$nombre_usuario = $_SESSION['nombre'];
|
||||||
|
$tipo_usuario = $_SESSION['tipo'];
|
||||||
|
echo "<div>
|
||||||
|
<h2>Bienvenido $nombre_usuario </h2>
|
||||||
|
<a href=\"logout.php\">Cerrar session</a>
|
||||||
|
</div>"
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div id="container">
|
||||||
|
<form action="recibe_formulario_hotel.php" method="post" enctype="multipart/form-data">
|
||||||
|
<h1>Reserve su habitación</h1>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Datos de la reserva</legend>
|
||||||
|
<p><label for="entradaH">Elige la fecha de entrada</label> <input type="date" id="entradaH" name="entrada" value="2024-03-01">
|
||||||
|
<p><label for="salida">Elige la fecha de salida</label> <input type="date" id="salida" name="salida" value="2024-03-10"></p>
|
||||||
|
<p><label for="habitacion">Seleccione el tipo de habitación</label>
|
||||||
|
<!-- Lista de selección -->
|
||||||
|
<select name="habitacion" id="habitacion">
|
||||||
|
<option value="simple">Simple</option>
|
||||||
|
<option value="doble">Doble</option>
|
||||||
|
<option value="triple">Triple</option>
|
||||||
|
<option value="suite">Suite</option>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
<p><label for="regimen">Seleccione el regimen de alojamiento</label>
|
||||||
|
<!-- Lista de selección -->
|
||||||
|
<select name="regimen" id="regimen">
|
||||||
|
<option value="desayuno">Desayuno</option>
|
||||||
|
<option value="mediapension">Media pensión</option>
|
||||||
|
<option value="pensioncompleta">Pensión Completa</option>
|
||||||
|
<option value="todoincluido">Todo Incluido</option>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
<p><label for="estancia">Coste de la estancia (Habitación + Comidas)</label> <input type="text" name="estancia" id="estancia"></p>
|
||||||
|
<p><label for="spa">Acceso al Spa, elija cuantos días</label> <input type="number" name="spa" id="spa" value="0" size="3"></p>
|
||||||
|
|
||||||
|
<p><label for="guia">Servicio de guía turístico, elija cuantos días </label><input type="number" name="guia" id="guia" value="0" size="3"></p>
|
||||||
|
<p><label for="total">Coste total con IVA incluido </label><input type="text" name="total" id="total"></p>
|
||||||
|
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Datos personales</legend>
|
||||||
|
<p><label for="nombre">*Nombre: </label><input type="text" name="nombre" id="nombre" placeholder="Nombre y Apellidos" required value="Marcos Lopez Gomez"></p>
|
||||||
|
<p><label for="mail">*Correo electrónico: </label><input type="email" name="email" id="mail" placeholder="Escribe tu correo" required value="marklogo@gmail.com"></p>
|
||||||
|
<p><label for="telefono">*Teléfono:</label> <input type="tel" id="telefono" name="telefono" required value="649348375"></p>
|
||||||
|
<p>Check-in online (opcional):</p>
|
||||||
|
<p><label for="dni">DNI:</label> <input type="text" id="dni" name="dni" value="33340763D"></p>
|
||||||
|
<p><label for="adjuntos">Adjunte fotocopia de DNI </label><input type="file" name="dnifile" id="dnifile" accept=".pdf,.jpg"></p>
|
||||||
|
<div id="flex">
|
||||||
|
<div>
|
||||||
|
<input type="button" value="Calcular coste total" onclick="obtener()">
|
||||||
|
<br><input type="reset" name="limpiar" value="Borrar" />
|
||||||
|
<br><input type="submit" value="Enviar la reserva">
|
||||||
|
<input id="noches" name="noches" type="hidden" value="noches">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<textarea name="info" id="info">Información de su viaje</textarea>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
1709555328_6286/_/Marcos Lopez Gomez/_/marklogo@gmail.com/_/649348375/_/2024-03-08/_/2024-03-21/_/04-03-2024 12:28:48/_/13
|
||||||
|
1709555366_8127/_/Marcos Lopez Gomez/_/marklogo1@gmail.com/_/649348375/_/2024-03-05/_/2024-03-10/_/04-03-2024 12:29:26/_/5
|
||||||
|
1709632003_8349/_/Marcos Lopez Gomez/_/marklogo1@gmail.com/_/649348375/_/2024-03-14/_/2024-03-21/_/05-03-2024 09:46:43/_/7
|
||||||
110
Practicas/Practicas_PHP/ejercicios/Plantilla Examen/login.php
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
// Leer cookies
|
||||||
|
$tema = isset($_COOKIE['tema']) ? $_COOKIE['tema'] : 'oscuro';
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "GET" && !empty($_GET)) {
|
||||||
|
$tema = $_GET['tema'];
|
||||||
|
setcookie("tema", $tema, time() + (86400 * 30), "/");
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<?php
|
||||||
|
echo $tema === 'claro' ? '<link rel="stylesheet" type="text/css" href="estilos_claro.css" />'
|
||||||
|
: '<link rel="stylesheet" type="text/css" href="estilos.css" />' ?>
|
||||||
|
<title>Login</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3>Seleccione su tema preferido</h3>
|
||||||
|
<form method="get">
|
||||||
|
<label for="claro">Tema Claro</label>
|
||||||
|
<input style="min-width: auto;" type="radio" id="claro" name="tema" value="claro" <?php echo $tema === 'claro' ? 'checked' : '' ?>>
|
||||||
|
<label for="oscuro">Tema Oscuro</label>
|
||||||
|
<input style="min-width: auto;" type="radio" id="oscuro" name="tema" value="oscuro" <?php echo $tema === 'oscuro' ? 'checked' : '' ?>> <br>
|
||||||
|
<input type="submit" value="Guardar">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h2>Login de usuario</h2>
|
||||||
|
<form method="post">
|
||||||
|
<p style="display:flex; flex-direction: column; ">
|
||||||
|
<label for="email">Usuario</label>
|
||||||
|
<input type="usuario" name="usuario" placeholder="Usuario" required>
|
||||||
|
</p>
|
||||||
|
<p style="display:flex; flex-direction: column; ">
|
||||||
|
<label for="password">Contraseña</label>
|
||||||
|
<input type="password" name="password" placeholder="Password" required>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<input type="submit" value="Entrar">
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<a href="./registro.php?tipo=cliente">Registrarse como cliente</a> <br>
|
||||||
|
<a href="./registro.php?tipo=hotel">Registrarse como personal del hotel</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
// Validar si se han enviado los datos del formulario
|
||||||
|
if (isset($_POST["usuario"]) && isset($_POST["password"])) {
|
||||||
|
$usuario = trim($_POST["usuario"]);
|
||||||
|
$password = trim($_POST["password"]);
|
||||||
|
|
||||||
|
// Obtener datos de usuarios registrados
|
||||||
|
$archivo = "usuarios.txt";
|
||||||
|
if (file_exists($archivo)) {
|
||||||
|
$usuarios = file_get_contents($archivo);
|
||||||
|
$lineas = explode("\n", $usuarios);
|
||||||
|
$credenciales_correctas = false;
|
||||||
|
$nombre_usuario = "";
|
||||||
|
$email_usuario = "";
|
||||||
|
$tipo_usuario = "";
|
||||||
|
foreach ($lineas as $linea) {
|
||||||
|
$datos = explode(":", $linea);
|
||||||
|
if (isset($datos[1]) && ($datos[1] == $usuario && password_verify($password, $datos[2]))) {
|
||||||
|
$credenciales_correctas = true;
|
||||||
|
$nombre_usuario = $datos[0];
|
||||||
|
$email_usuario = $datos[1];
|
||||||
|
$tipo_usuario = $datos[3];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($credenciales_correctas) {
|
||||||
|
session_start();
|
||||||
|
$_SESSION['nombre'] = $nombre_usuario;
|
||||||
|
$_SESSION['email'] = $email_usuario;
|
||||||
|
$_SESSION['tipo'] = $tipo_usuario;
|
||||||
|
switch ($tipo_usuario) {
|
||||||
|
case 'hotel':
|
||||||
|
header('Location: busqueda.php');
|
||||||
|
break;
|
||||||
|
case 'cliente':
|
||||||
|
header('Location: perfil_cliente.php');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
exit();
|
||||||
|
} else {
|
||||||
|
echo "<div> Credenciales incorrectas. Por favor, inténtalo de nuevo. </div>";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "<div> No hay usuarios registrados aún. </div>";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "<div> Por favor, complete todos los campos. </div>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
session_destroy();
|
||||||
|
header('Location: login.php');
|
||||||
|
exit();
|
||||||
|
?>
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<?php
|
||||||
|
echo $_COOKIE['tema'] === 'claro' ? '<link rel="stylesheet" type="text/css" href="estilos_claro.css" />'
|
||||||
|
: '<link rel="stylesheet" type="text/css" href="estilos.css" />' ?>
|
||||||
|
<title>Perfil de cliente</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
// Leer cookies
|
||||||
|
$contador = isset($_COOKIE['contador']) ? $_COOKIE['contador'] : 1;
|
||||||
|
setcookie("contador", $contador + 1, 0, "/");
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
$nombre_usuario = $_SESSION['nombre'];
|
||||||
|
$tipo_usuario = $_SESSION['tipo'];
|
||||||
|
$email_usuario = $_SESSION['email'];
|
||||||
|
echo "<div>
|
||||||
|
<h2>Bienvenido $nombre_usuario </h2>
|
||||||
|
<span>Has visitado la pagina $contador veces.</span> <br>
|
||||||
|
<a href=\"logout.php\">Cerrar session</a>
|
||||||
|
</div> <br>";
|
||||||
|
busqueda($email_usuario);
|
||||||
|
|
||||||
|
echo "<div>
|
||||||
|
<a href=\"formulario_hotel.php\">Registrar reserva</a>
|
||||||
|
</div>";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function busqueda($termBusqueda)
|
||||||
|
{
|
||||||
|
include_once('caracteres.php');
|
||||||
|
$termBusqueda = eliminar_tildes(strtolower($termBusqueda));
|
||||||
|
$nombre_archivo = "listado_reservas.txt";
|
||||||
|
$registros = [];
|
||||||
|
|
||||||
|
|
||||||
|
$archivo = file_exists($nombre_archivo) ? fopen($nombre_archivo, 'r') : false;
|
||||||
|
if ($archivo !== false) {
|
||||||
|
while (($linea = fgets($archivo)) !== false) {
|
||||||
|
if (strpos(eliminar_tildes(strtolower($linea)), $termBusqueda) !== false) {
|
||||||
|
$registros[] = $linea;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($archivo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($registros) > 0) {
|
||||||
|
echo "<table>
|
||||||
|
<tbody>
|
||||||
|
<thead>
|
||||||
|
<th>Id Reserva</th>
|
||||||
|
<th>Nombre</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Nº Telefono</th>
|
||||||
|
<th>Fecha de entrada</th>
|
||||||
|
<th>Fecha de salida</th>
|
||||||
|
<th>Fecha de registro</th>
|
||||||
|
<th>Nº de noches</th>
|
||||||
|
</thead>";
|
||||||
|
foreach ($registros as $registro) {
|
||||||
|
$campos = explode("/_/", $registro);
|
||||||
|
echo "<tr>";
|
||||||
|
foreach ($campos as $campo) {
|
||||||
|
echo "<td> $campo </td>";
|
||||||
|
}
|
||||||
|
echo "</tr>";
|
||||||
|
}
|
||||||
|
echo "</tbody>";
|
||||||
|
echo "</table>";
|
||||||
|
} else {
|
||||||
|
echo "<div><h4> No se han encontrado registros con los terminos indicados </h4></div>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
178
Practicas/Practicas_PHP/ejercicios/Plantilla Examen/recibe_formulario_hotel.php
Executable file
@@ -0,0 +1,178 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<?php
|
||||||
|
echo $_COOKIE['tema'] === 'claro' ? '<link rel="stylesheet" type="text/css" href="estilos_claro.css" />'
|
||||||
|
: '<link rel="stylesheet" type="text/css" href="estilos.css" />' ?>
|
||||||
|
<title>Reservas Hotel!!!</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
$nombre_usuario = $_SESSION['nombre'];
|
||||||
|
$tipo_usuario = $_SESSION['tipo'];
|
||||||
|
echo "<div>
|
||||||
|
<h2>Bienvenido $nombre_usuario </h2>
|
||||||
|
<a href=\"logout.php\">Cerrar session</a>
|
||||||
|
</div>"
|
||||||
|
?>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// Validar el método de solicitud HTTP
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$datosReserva = recopilarDatosReserva($_POST,['entrada', 'salida', 'habitacion', 'regimen', 'estancia', 'spa', 'guia', 'total', 'nombre', 'email', 'telefono', 'dni', 'noches', 'info']);
|
||||||
|
$resultadoProcesamiento = procesarReserva($datosReserva);
|
||||||
|
mostrarResultado($resultadoProcesamiento);
|
||||||
|
} else {
|
||||||
|
echo "<h2>No se han recibido datos del formulario</h2>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Función para recopilar datos del formulario y sanitizarlos
|
||||||
|
function recopilarDatosReserva($formulario, $campos )
|
||||||
|
{
|
||||||
|
$datos = [];
|
||||||
|
foreach ($campos as $campo) {
|
||||||
|
$datos[$campo] = trim($formulario[$campo]) ?? '';
|
||||||
|
}
|
||||||
|
return $datos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Función para procesar la reserva
|
||||||
|
function procesarReserva($datosReserva)
|
||||||
|
{
|
||||||
|
// Variables para el resultado del procesamiento
|
||||||
|
$exito = true;
|
||||||
|
$msgExito = [];
|
||||||
|
$msgError = [];
|
||||||
|
|
||||||
|
// Obtener datos de reserva
|
||||||
|
$entrada = $datosReserva['entrada'];
|
||||||
|
$salida = $datosReserva['salida'];
|
||||||
|
$habitacion = $datosReserva['habitacion'];
|
||||||
|
$regimen = $datosReserva['regimen'];
|
||||||
|
$spa = $datosReserva['spa'];
|
||||||
|
$guia = $datosReserva['guia'];
|
||||||
|
$nombre = $datosReserva['nombre'];
|
||||||
|
$email = $datosReserva['email'];
|
||||||
|
$telefono = $datosReserva['telefono'];
|
||||||
|
$dni = $datosReserva['dni'];
|
||||||
|
$noches = $datosReserva['noches'];
|
||||||
|
$total = $datosReserva['total'];
|
||||||
|
|
||||||
|
// Generar identificador de reserva
|
||||||
|
$idReserva = time() . '_' . mt_rand(1000, 9999);
|
||||||
|
// Fecha de reserva
|
||||||
|
$fechaReserva = date("d-m-Y H:i:s");
|
||||||
|
|
||||||
|
// Estructurar ficha de reserva
|
||||||
|
$fichaReserva = "Id reserva: $idReserva \r\n";
|
||||||
|
$fichaReserva .= "Fecha de reserva: $fechaReserva \r\n";
|
||||||
|
$fichaReserva .= "Fecha de entrada: $entrada \r\n";
|
||||||
|
$fichaReserva .= "Fecha de salida: $salida \r\n";
|
||||||
|
$fichaReserva .= "Tipo de habitación: $habitacion \r\n";
|
||||||
|
$fichaReserva .= "Regimen de alojamiento: $regimen \r\n";
|
||||||
|
$fichaReserva .= "Días Spa: $spa \r\n";
|
||||||
|
$fichaReserva .= "Días Guia: $guia \r\n";
|
||||||
|
$fichaReserva .= "Duración estancia: $noches \r\n";
|
||||||
|
$fichaReserva .= "Coste Total: $total \r\n";
|
||||||
|
$fichaReserva .= "Nombre: $nombre \r\n";
|
||||||
|
$fichaReserva .= "Correo electrónico: $email \r\n";
|
||||||
|
$fichaReserva .= "Teléfono: $telefono \r\n";
|
||||||
|
$fichaReserva .= "DNI: $dni \r\n";
|
||||||
|
|
||||||
|
// Enviar correo electrónico con los detalles de la reserva
|
||||||
|
$destinatario = "appasin04@gmail.com";
|
||||||
|
$asunto = "Informacion de reserva - $idReserva";
|
||||||
|
$headers = 'Reply-To: appasin04@gmail.com' . "\r\n";
|
||||||
|
$headers .= 'Bcc: ' . $email . "\r\n";
|
||||||
|
if (!mail($destinatario, $asunto, $fichaReserva, $headers)) {
|
||||||
|
$exito = false;
|
||||||
|
$msgError[] = "Error al enviar el correo electrónico.";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Guardar la ficha de reserva en un archivo
|
||||||
|
$dir_reservas ="reservas/";
|
||||||
|
!is_dir($dir_reservas) ? !mkdir($dir_reservas, 0777, true) : null;
|
||||||
|
$nombre_archivo = $dir_reservas . $idReserva . ".txt";
|
||||||
|
if (file_put_contents($nombre_archivo, $fichaReserva) === false) {
|
||||||
|
$exito = false;
|
||||||
|
$msgError[] = "Error al guardar la ficha de reserva.";
|
||||||
|
} else {
|
||||||
|
$msgExito[] = "<h2> Reserva confirmada ! </h2>" . "<p>". nl2br($fichaReserva)."</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Añadir al listado_reservas.txt una línea de reserva
|
||||||
|
$registroReserva = implode('/_/', [$idReserva, $nombre, $email, $telefono, $entrada, $salida, $fechaReserva, $noches]) . "\r\n";
|
||||||
|
$nombre_archivo = "listado_reservas.txt";
|
||||||
|
if (file_put_contents($nombre_archivo, $registroReserva, FILE_APPEND | LOCK_EX) === false) {
|
||||||
|
$exito = false;
|
||||||
|
$msgError[] = "Error al guardar la lista de reservas.";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_FILES['dnifile']) && $_FILES['dnifile']['error'] === UPLOAD_ERR_OK){
|
||||||
|
$exitoUpload = true;
|
||||||
|
$dir_uploads= "dni_clientes/";
|
||||||
|
!is_dir($dir_uploads) ? !mkdir($dir_uploads, 0777, true) : null;
|
||||||
|
$nombreArchivo = implode("_", [$dni, $idReserva, $_FILES['dnifile']['name']]);
|
||||||
|
$extension_archivo = strtolower(pathinfo($_FILES["dnifile"]["name"], PATHINFO_EXTENSION));
|
||||||
|
$tamano_maximo = 2 * 1024 * 1024;
|
||||||
|
$extensiones_permitidas = array("jpg", "jpeg", "pdf");
|
||||||
|
|
||||||
|
if(!in_array($extension_archivo, $extensiones_permitidas)){
|
||||||
|
$exitoUpload =false;
|
||||||
|
$exito = false;
|
||||||
|
$msgError[] = "El fichero no tiene una extension valida.";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_FILES["dnifile"]["size"] > $tamano_maximo){
|
||||||
|
$exitoUpload =false;
|
||||||
|
$exito = false;
|
||||||
|
$msgError[] = "El fichero excede el tamaño maximo (2Mb).";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($exitoUpload){
|
||||||
|
if(move_uploaded_file($_FILES["dnifile"]["tmp_name"],$dir_uploads . $nombreArchivo)){
|
||||||
|
$msgExito [] = "<h4>El fichero adjunto se almaceno correctamente</h4>";
|
||||||
|
}else{
|
||||||
|
$exito = false;
|
||||||
|
$msgError = "Ocurrio un error al almacenar el fichero adjunto";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$resultado = [
|
||||||
|
'exito' => $exito,
|
||||||
|
'msgExito'=> $msgExito,
|
||||||
|
'msgError' => $msgError
|
||||||
|
];
|
||||||
|
return $resultado;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function mostrarResultado($resultado)
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach ($resultado['msgExito'] as $key => $value) {
|
||||||
|
echo "<p> $value </p>";
|
||||||
|
}
|
||||||
|
if (!$resultado['exito']) {
|
||||||
|
echo "<h4>Se han encontrado los siguientes problemas al procesar su solicitud:</h4>";
|
||||||
|
echo "<ul>";
|
||||||
|
foreach ($resultado['msgError'] as $key => $value) {
|
||||||
|
echo "<li> $value </li>";
|
||||||
|
}
|
||||||
|
echo "</ul>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<?php
|
||||||
|
echo $_COOKIE['tema'] === 'claro' ? '<link rel="stylesheet" type="text/css" href="estilos_claro.css" />'
|
||||||
|
: '<link rel="stylesheet" type="text/css" href="estilos.css" />' ?>
|
||||||
|
<title>Registro de personal de hotel</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "GET") {
|
||||||
|
$tipo_usuario = "";
|
||||||
|
if (!(isset($_GET["tipo"]) && ($_GET["tipo"] === 'cliente' || $_GET["tipo"] === 'hotel'))) {
|
||||||
|
header('Location: login.php');
|
||||||
|
}
|
||||||
|
$tipo_usuario = $_GET["tipo"];
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<h2>Registro
|
||||||
|
<?php
|
||||||
|
echo $tipo_usuario === 'hotel' ? "de personal del hotel" : "de clientes";
|
||||||
|
?>
|
||||||
|
</h2>
|
||||||
|
<form method="post">
|
||||||
|
<p style="display:flex; flex-direction: column; ">
|
||||||
|
<label for="nombre">Nombre:</label>
|
||||||
|
<input type="nombre" name="nombre" placeholder="Nombre" required>
|
||||||
|
</p>
|
||||||
|
<p style="display:flex; flex-direction: column; ">
|
||||||
|
<label for="email">Correo electrónico:</label>
|
||||||
|
<input type="email" name="email" placeholder="Email" required>
|
||||||
|
</p>
|
||||||
|
<p style="display:flex; flex-direction: column; ">
|
||||||
|
<label for="password">Contraseña:</label>
|
||||||
|
<input type="password" name="password" placeholder="Password" required>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<input type="submit" value="Registrar">
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
// Validar si se han enviado los datos del formulario
|
||||||
|
if (isset($_POST["email"]) && isset($_POST["password"])) {
|
||||||
|
$nombre = trim($_POST["nombre"]);
|
||||||
|
$email = trim($_POST["email"]);
|
||||||
|
$password = password_hash(trim($_POST["password"]),PASSWORD_DEFAULT);
|
||||||
|
$tipo_usuario= trim($_GET["tipo"]);
|
||||||
|
|
||||||
|
// Validar si el archivo de almacenamiento existe, si no, crearlo
|
||||||
|
$archivo = "usuarios.txt";
|
||||||
|
if (!file_exists($archivo)) {
|
||||||
|
fopen($archivo, "w");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validar si el email ya está registrado
|
||||||
|
$usuarios = file_get_contents($archivo);
|
||||||
|
$lineas = explode("\n", $usuarios);
|
||||||
|
$email_existe = false;
|
||||||
|
foreach ($lineas as $linea) {
|
||||||
|
$datos = explode(":", $linea);
|
||||||
|
if (isset($datos[1]) && ($datos[1] == $email)) {
|
||||||
|
$email_existe = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si el email no está registrado, almacenarlo en el archivo
|
||||||
|
if (!$email_existe) {
|
||||||
|
$nueva_linea = $nombre . ":" . $email . ":" . $password . ":" . $tipo_usuario . "\n";
|
||||||
|
file_put_contents($archivo, $nueva_linea, FILE_APPEND | LOCK_EX);
|
||||||
|
header('Location: login.php');
|
||||||
|
exit();
|
||||||
|
} else {
|
||||||
|
echo "Este email ya está registrado.";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "Por favor, complete todos los campos.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
Id reserva: 1709555328_6286
|
||||||
|
Fecha de reserva: 04-03-2024 12:28:48
|
||||||
|
Fecha de entrada: 2024-03-08
|
||||||
|
Fecha de salida: 2024-03-21
|
||||||
|
Tipo de habitación: simple
|
||||||
|
Regimen de alojamiento: desayuno
|
||||||
|
Días Spa: 0
|
||||||
|
Días Guia: 0
|
||||||
|
Duración estancia: 13
|
||||||
|
Coste Total: 1179.75
|
||||||
|
Nombre: Marcos Lopez Gomez
|
||||||
|
Correo electrónico: marklogo@gmail.com
|
||||||
|
Teléfono: 649348375
|
||||||
|
DNI: 33340763D
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
Id reserva: 1709555366_8127
|
||||||
|
Fecha de reserva: 04-03-2024 12:29:26
|
||||||
|
Fecha de entrada: 2024-03-05
|
||||||
|
Fecha de salida: 2024-03-10
|
||||||
|
Tipo de habitación: simple
|
||||||
|
Regimen de alojamiento: desayuno
|
||||||
|
Días Spa: 0
|
||||||
|
Días Guia: 0
|
||||||
|
Duración estancia: 5
|
||||||
|
Coste Total: 514.25
|
||||||
|
Nombre: Marcos Lopez Gomez
|
||||||
|
Correo electrónico: marklogo1@gmail.com
|
||||||
|
Teléfono: 649348375
|
||||||
|
DNI: 33340763D
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
Id reserva: 1709632003_8349
|
||||||
|
Fecha de reserva: 05-03-2024 09:46:43
|
||||||
|
Fecha de entrada: 2024-03-14
|
||||||
|
Fecha de salida: 2024-03-21
|
||||||
|
Tipo de habitación: simple
|
||||||
|
Regimen de alojamiento: desayuno
|
||||||
|
Días Spa: 0
|
||||||
|
Días Guia: 0
|
||||||
|
Duración estancia: 7
|
||||||
|
Coste Total: 719.95
|
||||||
|
Nombre: Marcos Lopez Gomez
|
||||||
|
Correo electrónico: marklogo1@gmail.com
|
||||||
|
Teléfono: 649348375
|
||||||
|
DNI: 33340763D
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
Pablo López Gómez:marklogo@gmail.com:$2y$10$NDc/iJcOFm9EvP3UXKI0PumtcfUe.2VfxfrXR2OXOBScw8pDu.IKa:hotel
|
||||||
|
Marcos Lopez Gomez:marklogo1@gmail.com:$2y$10$yRaUcaYDGod1zRRLizbfi..hEPa8kkZre7Xk83c1pe/W/wXXrj6jW:cliente
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
// Comprobamos si existe la sesión de apodo
|
||||||
|
session_start();
|
||||||
|
if (!isset($_SESSION['usuario'])) {
|
||||||
|
// En caso contrario devolvemos a la página login.php
|
||||||
|
header('Location: login_usuarios.php');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!Doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
|
||||||
|
<title>Buscador de reservas</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<!-- Saludamos -->
|
||||||
|
<h1>Bienvenido <?php echo $_SESSION['usuario']; ?></h1>
|
||||||
|
<!-- Botón para cerrar la sesión -->
|
||||||
|
<a href="logout.php">Cerrar sesión</a>
|
||||||
|
<form method="post">
|
||||||
|
<p>*Término a buscar: </p><p><input type="text" name="busqueda" id="busqueda" size="30" placeholder="Introduzca la palabra de busqueda" required></p>
|
||||||
|
<input type="submit" name="buscar" value="Buscar" >
|
||||||
|
</form></div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
//Suponiendo que el archivo caracteres.php está en la misma carpeta:
|
||||||
|
include('caracteres.php');
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['buscar'])) {
|
||||||
|
// Busca una palabra
|
||||||
|
$busqueda=isset($_REQUEST['busqueda'])? $_REQUEST['busqueda']: "" ;
|
||||||
|
|
||||||
|
|
||||||
|
//Abrir el archivo
|
||||||
|
$archivo = fopen('listado_reservas.txt', 'r');
|
||||||
|
|
||||||
|
//Leer el archivo
|
||||||
|
|
||||||
|
if (!$archivo) { echo("Error abriendo archivo"); }
|
||||||
|
|
||||||
|
// Abro la tabla
|
||||||
|
echo '<br>';
|
||||||
|
echo '<table border="2">';
|
||||||
|
echo "<tr><th>Id Reserva</th><th>Nombre</th><th>Correo</th><th>Teléfono</th><th>Entrada</th><th>Salida</th><th>Fecha reserva</th><th>Duración</th></tr>";
|
||||||
|
|
||||||
|
//Busco la coincidencia
|
||||||
|
|
||||||
|
while (($linea = fgets($archivo)) != false) {
|
||||||
|
if(strpos(eliminar_tildes(strtolower($linea)), eliminar_tildes(strtolower($busqueda))) !== false){
|
||||||
|
|
||||||
|
// Mostrar la tabla con array
|
||||||
|
$arrayLinea=explode('/_/', $linea);
|
||||||
|
//foreach ($arrayLinea as $dato) {
|
||||||
|
// echo "<td>$dato</td>";
|
||||||
|
//}
|
||||||
|
echo "<tr><td>$arrayLinea[0]</td><td>$arrayLinea[1]</td><td>$arrayLinea[2]</td><td>$arrayLinea[3]</td><td>$arrayLinea[4]</td><td>$arrayLinea[5]</td><td>$arrayLinea[6]</td><td>$arrayLinea[7]</td></tr>";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Cierrro la tabla
|
||||||
|
echo "</table>";
|
||||||
|
//cerrar el archivo
|
||||||
|
fclose($archivo);
|
||||||
|
|
||||||
|
// Vacio los datos de POST
|
||||||
|
unset($_POST);
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<br>
|
||||||
|
<div><form method="post">
|
||||||
|
<p>*ID de alquiler para borrar: </p><input type="text" name="Id_borrar" value="" id="Id_borrar" size="15" minlength="15" maxlength="15" placeholder="Id Alquiler"/>
|
||||||
|
<input type="submit" name="borrar" value="Borrar reserva de alquiler" >
|
||||||
|
</form></div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Borrar reservas de alquiler
|
||||||
|
$listaReservas = "listado_reservas.txt";
|
||||||
|
$temporal = "temp.txt";
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['borrar']) && isset($_POST['Id_borrar'])) {
|
||||||
|
$borrado = $_POST['Id_borrar'];
|
||||||
|
|
||||||
|
$accesoLista = fopen($listaReservas, 'r');
|
||||||
|
$accesoTemporal = fopen($temporal, 'w');
|
||||||
|
|
||||||
|
// Buscar la reserva por ID
|
||||||
|
while (($linea = fgets($accesoLista)) !== false) {
|
||||||
|
// Obtener el ID de reserva de la línea actual
|
||||||
|
$arrayLinea = explode('/_/', $linea);
|
||||||
|
$id_reserva = $arrayLinea[0];
|
||||||
|
|
||||||
|
// Si el ID de reserva no coincide
|
||||||
|
if(trim($id_reserva) !== trim($borrado)) {
|
||||||
|
fwrite($accesoTemporal, $linea);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($accesoLista);
|
||||||
|
fclose($accesoTemporal);
|
||||||
|
|
||||||
|
// Borrar listado y renombrar el temporal
|
||||||
|
unlink($listaReservas);
|
||||||
|
rename($temporal, $listaReservas);
|
||||||
|
|
||||||
|
// Borrar ficha de reserva individual
|
||||||
|
$ficha_individual = "reservas/reserva_" .$borrado.".txt";
|
||||||
|
if (file_exists($ficha_individual)) {
|
||||||
|
if (unlink("reservas/reserva_" .$borrado.".txt") !== false) {
|
||||||
|
echo "<div><p>La ficha de reserva se ha borrado</p></div>";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "<div><p>La ficha de reserva no se ha encontrado</p></div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Borrar DNI con glob()
|
||||||
|
$dni_archivos = glob("dni_clientes/*_{$borrado}_*");
|
||||||
|
|
||||||
|
foreach ($dni_archivos as $dni_aborrar) {
|
||||||
|
if (unlink($dni_aborrar)) {
|
||||||
|
echo '<div><p>El archivo ' . $dni_aborrar . ' fue eliminado exitosamente.</p></div>';
|
||||||
|
} else {
|
||||||
|
echo '<div><p>Ocurrió un error al intentar eliminar el archivo ' . $dni_aborrar . '.</p></div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vacio los datos de POST
|
||||||
|
unset($_POST);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
209
Practicas/Practicas_PHP/ejercicios/Sesiones/formulario_hotel.php
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
|
||||||
|
<?php
|
||||||
|
// Comprobamos si existe la sesión
|
||||||
|
session_start();
|
||||||
|
if (!isset($_SESSION['usuario'])) {
|
||||||
|
// En caso contrario devolvemos a la página login.php
|
||||||
|
header('Location: login_usuarios.php');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!Doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
|
||||||
|
<title>Reservas hotel</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
<script>
|
||||||
|
// Función obtener() que realizará la captación de datos,los cálculos y la escritura del mensaje de info
|
||||||
|
|
||||||
|
function obtener() {
|
||||||
|
// Declaro y obtengo el valor de las variables
|
||||||
|
|
||||||
|
//Calcular periodo de la estancia (noches)
|
||||||
|
const inicio=document.getElementById("entradaH").valueAsNumber;
|
||||||
|
const fin=document.getElementById("salida").valueAsNumber;
|
||||||
|
const dif=fin - inicio;
|
||||||
|
const noches=Math.ceil(dif/(1000*60*60*24));
|
||||||
|
document.getElementById("noches").value=noches;
|
||||||
|
|
||||||
|
|
||||||
|
const habitacion=document.getElementById("habitacion").value;
|
||||||
|
const regimen=document.getElementById("regimen").value;
|
||||||
|
const spa=document.getElementById("spa").value;
|
||||||
|
const guia=document.getElementById("guia").value;
|
||||||
|
const nombreCliente=document.getElementById("nombre").value;
|
||||||
|
|
||||||
|
//Cáculo extras (spa y guia)
|
||||||
|
let spaT;
|
||||||
|
|
||||||
|
if (spa>5) {
|
||||||
|
spaT=spa*20;
|
||||||
|
}else {
|
||||||
|
spaT=spa*30;
|
||||||
|
}
|
||||||
|
|
||||||
|
let guiaT;
|
||||||
|
|
||||||
|
if(guia>7) {
|
||||||
|
guiaT=guia*40;
|
||||||
|
} else {
|
||||||
|
guiaT=guia*50;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tipo habitación
|
||||||
|
let hotel;
|
||||||
|
if (habitacion === "simple") {
|
||||||
|
hotel=50;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (habitacion === "doble") {
|
||||||
|
hotel=80;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (habitacion === "triple") {
|
||||||
|
hotel=120;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (habitacion === "suite") {
|
||||||
|
hotel=150;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Tipo de regimen
|
||||||
|
let comidas;
|
||||||
|
if (regimen === "desayuno") {
|
||||||
|
comidas=50;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regimen === "mediapension") {
|
||||||
|
comidas=80;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regimen === "pensioncompleta") {
|
||||||
|
comidas=120;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regimen === "todoincluido") {
|
||||||
|
comidas=150;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gastos estancia hotel+comidas
|
||||||
|
const hotelT=hotel*noches;
|
||||||
|
const regimenT=comidas*noches;
|
||||||
|
|
||||||
|
const estancia=hotelT+regimenT;
|
||||||
|
|
||||||
|
// Descuento por larga estancia
|
||||||
|
let estanciaDescuento;
|
||||||
|
if (noches <= 4) {
|
||||||
|
estanciaDescuento = estancia;
|
||||||
|
} else if (noches >= 5 && noches <= 10) {
|
||||||
|
estanciaDescuento = estancia * 0.85;
|
||||||
|
} else if (noches >= 11) {
|
||||||
|
estanciaDescuento = estancia * 0.75;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Envío el precio total sin IVA al formulario
|
||||||
|
document.getElementById("estancia").value=estanciaDescuento;
|
||||||
|
|
||||||
|
//Coste total con extras
|
||||||
|
const total=estanciaDescuento+spaT+guiaT;
|
||||||
|
const totalI=(total*1.21).toFixed(2);
|
||||||
|
// Envío el precio con IVA al formulario
|
||||||
|
document.getElementById("total").value=totalI;
|
||||||
|
// Precio de anulación
|
||||||
|
const precioAnulacion=(total*0.2).toFixed(2);
|
||||||
|
|
||||||
|
|
||||||
|
// Calcular días que faltan y fecha de regreso
|
||||||
|
const hoy=new Date().getTime();// Fecha de la reserva
|
||||||
|
const entrada=document.getElementById("entradaH").valueAsNumber;
|
||||||
|
const dif2=entrada-hoy;
|
||||||
|
const diasFaltan=dif2/(1000*60*60*24);// Días que faltan
|
||||||
|
|
||||||
|
const regresoF=new Date(fin);// Obtener en UTC
|
||||||
|
const regresoP=regresoF.toLocaleDateString();//Pasar fecha a formato corto dd/mm/xxxx
|
||||||
|
|
||||||
|
const anulacion=entrada-(3*24*60*60*1000);//Fecha de anulación
|
||||||
|
const anulacionF=new Date(anulacion);
|
||||||
|
const anulacionP=anulacionF.toLocaleDateString();
|
||||||
|
//Mensaje de información
|
||||||
|
const frase=
|
||||||
|
"Hola "+nombreCliente+"\n"
|
||||||
|
+"Faltan "+(Math.ceil(diasFaltan))+ " días "+"para tu viaje"+"\n"
|
||||||
|
+"Tu fecha de regreso es el "+regresoP+"\n"
|
||||||
|
+"Puedes anular tu reserva hasta el día "+anulacionP+"\n"
|
||||||
|
+"El coste de la anulación será de " +precioAnulacion+ " euros" ;
|
||||||
|
//Enviar mensaje al formulario
|
||||||
|
document.getElementById("info").value=frase;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div><!-- Saludamos -->
|
||||||
|
<h1>Hola <?php echo $_SESSION['usuario']; ?> puede realizar su reserva</h1>
|
||||||
|
<!-- Botón para cerrar la sesión -->
|
||||||
|
<a href="logout.php">Cerrar sesión</a></div>
|
||||||
|
|
||||||
|
<div id="container">
|
||||||
|
<form action="recibe_formulario_hotel.php" method="post" enctype="multipart/form-data">
|
||||||
|
<h2>Reserve su habitación</h2>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Datos de la reserva</legend>
|
||||||
|
<p><label for="entradaH">Elige la fecha de entrada</label> <input type="date" id="entradaH" name="entrada">
|
||||||
|
<p><label for="salida">Elige la fecha de salida</label> <input type="date" id="salida" name="salida"></p>
|
||||||
|
<p><label for="habitacion">Seleccione el tipo de habitación</label>
|
||||||
|
<!-- Lista de selección -->
|
||||||
|
<select name="habitacion" id="habitacion">
|
||||||
|
<option value="simple">Simple</option>
|
||||||
|
<option value="doble">Doble</option>
|
||||||
|
<option value="triple">Triple</option>
|
||||||
|
<option value="suite">Suite</option>
|
||||||
|
</select></p>
|
||||||
|
<p><label for="regimen">Seleccione el regimen de alojamiento</label>
|
||||||
|
<!-- Lista de selección -->
|
||||||
|
<select name="regimen" id="regimen">
|
||||||
|
<option value="desayuno">Desayuno</option>
|
||||||
|
<option value="mediapension">Media pensión</option>
|
||||||
|
<option value="pensioncompleta">Pensión Completa</option>
|
||||||
|
<option value="todoincluido">Todo Incluido</option>
|
||||||
|
</select></p>
|
||||||
|
<p><label for="estancia">Coste de la estancia (Habitación + Comidas)</label> <input type="text" name="estancia" id="estancia"></p>
|
||||||
|
<p><label for="spa">Acceso al Spa, elija cuantos días</label> <input type="number" name="spa" id="spa" value="0" size="3"></p>
|
||||||
|
|
||||||
|
<p><label for="guia">Servicio de guía turístico, elija cuantos días </label><input type="number" name="guia" id="guia" value="0" size="3"></p>
|
||||||
|
<p><label for="total">Coste total con IVA incluido </label><input type="text" name="total" id="total" ></p>
|
||||||
|
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Datos personales</legend>
|
||||||
|
<p><label for="nombre">*Nombre: </label><input type="text" name="nombre" id="nombre" placeholder="Nombre y Apellidos" required></p>
|
||||||
|
<p><label for="mail">*Correo electrónico: </label><input type="email" name="email" id="mail" placeholder="Escribe tu correo" required></p>
|
||||||
|
<p><label for="telefono">*Teléfono:</label> <input type="tel" id="telefono" name="telefono" required></p>
|
||||||
|
<p>Check-in online (opcional):</p>
|
||||||
|
<p><label for="dni">DNI:</label> <input type="text" id="dni" name="dni" ></p>
|
||||||
|
<p><label for="adjuntos">Adjunte fotocopia de DNI </label><input type="file" name="dnifile" id="dnifile" accept=".pdf,.jpg" ></p>
|
||||||
|
<div id="flex">
|
||||||
|
<div>
|
||||||
|
<input type="button" value="Calcular coste total" onclick="obtener()">
|
||||||
|
<br><input type="reset" name="limpiar" value="Borrar" />
|
||||||
|
<br><input type="submit" value="Enviar la reserva" >
|
||||||
|
<input id="noches" name="noches" type="hidden" value="noches">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<textarea name="info" id="info" >Información de su viaje</textarea>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Login de acceso</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
<body>
|
||||||
|
<div><h2>Login de Usuarios</h2>
|
||||||
|
<form method="post">
|
||||||
|
<p>
|
||||||
|
<label for="usuario">Usuario:</label>
|
||||||
|
<input type="text" id="usuario" name="usuario" placeholder="Usuario">
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label for="contraseña">Contraseña:</label>
|
||||||
|
<input type="password" id="contraseña" name="contraseña" placeholder="Contraseña">
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<input type="submit" value="Entrar">
|
||||||
|
</p>
|
||||||
|
</form></div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p><a href="registro_usuarios_cliente.php">Registarse como cliente</a></p>
|
||||||
|
<p><a href="registro_usuarios_hotel.php">Registarse como personal del hotel</a></p>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
// Verificar si se ha enviado el formulario
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
// Obtener los datos del formulario
|
||||||
|
$usuario = $_POST['usuario'];
|
||||||
|
$contraseña = $_POST['contraseña'];
|
||||||
|
|
||||||
|
// Archivo de usuarios
|
||||||
|
$archivo = "usuarios.txt";
|
||||||
|
|
||||||
|
// Verificar si el archivo existe
|
||||||
|
if (file_exists($archivo)) {
|
||||||
|
// Abrir el archivo en modo de lectura
|
||||||
|
$conexion = fopen($archivo, "r");
|
||||||
|
|
||||||
|
// Variable para usuario
|
||||||
|
$usuario_encontrado = false;
|
||||||
|
$nombre_usuario;
|
||||||
|
$acceso_usuario;
|
||||||
|
// Leer el archivo línea por línea
|
||||||
|
while (($linea = fgets($conexion)) !== false) {
|
||||||
|
// Separar el nombre de usuario y la contraseña de cada línea
|
||||||
|
list($usuario_registrado, $contraseña_registrada, $nombre_registrado ,$acceso_registrado) = explode(":", trim($linea));
|
||||||
|
|
||||||
|
// Comparar los datos
|
||||||
|
if ($usuario === $usuario_registrado && password_verify($contraseña, $contraseña_registrada)) {
|
||||||
|
$usuario_encontrado = true;
|
||||||
|
$nombre_usuario=$nombre_registrado;
|
||||||
|
$acceso_usuario=$acceso_registrado;
|
||||||
|
$correo_usuario=$usuario_registrado;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cerrar el archivo
|
||||||
|
fclose($conexion);
|
||||||
|
|
||||||
|
// Verificar si se encontró
|
||||||
|
if ($usuario_encontrado) {
|
||||||
|
// Si los datos son válidos, iniciar sesión y redirigir al usuario
|
||||||
|
session_start();
|
||||||
|
$_SESSION['usuario'] = $nombre_usuario;
|
||||||
|
$_SESSION['correo'] = $correo_usuario;
|
||||||
|
|
||||||
|
if ($acceso_usuario === "cliente") {
|
||||||
|
header('Location: perfil_cliente.php'); // Redireccionar a la página de cliente
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($acceso_usuario === "hotel") {
|
||||||
|
header('Location: buscador_reservas.php'); // Redireccionar a la página de gestión
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Si los datos no son válidos, mostrar un mensaje de error
|
||||||
|
echo '<p style="color: red">El nombre de usuario o la contraseña son incorrectos.</p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Login de acceso</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
<body>
|
||||||
|
<div><h2>Login de Usuarios</h2>
|
||||||
|
<form method="post">
|
||||||
|
<p>
|
||||||
|
<label for="usuario">Usuario:</label>
|
||||||
|
<input type="text" id="usuario" name="usuario" placeholder="Usuario">
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label for="contraseña">Contraseña:</label>
|
||||||
|
<input type="password" id="contraseña" name="contraseña" placeholder="Contraseña">
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<input type="submit" value="Entrar">
|
||||||
|
</p>
|
||||||
|
</form></div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p><a href="registro_usuarios_comun.php?acceso=cliente">Registarse como cliente</a></p>
|
||||||
|
<p><a href="registro_usuarios_comun.php?acceso=hotel">Registarse como personal del hotel</a></p>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
// Verificar si se ha enviado el formulario
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
// Obtener los datos del formulario
|
||||||
|
$usuario = $_POST['usuario'];
|
||||||
|
$contraseña = $_POST['contraseña'];
|
||||||
|
|
||||||
|
// Archivo de usuarios
|
||||||
|
$archivo = "usuarios.txt";
|
||||||
|
|
||||||
|
// Verificar si el archivo existe
|
||||||
|
if (file_exists($archivo)) {
|
||||||
|
// Abrir el archivo en modo de lectura
|
||||||
|
$conexion = fopen($archivo, "r");
|
||||||
|
|
||||||
|
// Variable para usuario
|
||||||
|
$usuario_encontrado = false;
|
||||||
|
$nombre_usuario;
|
||||||
|
$acceso_usuario;
|
||||||
|
// Leer el archivo línea por línea
|
||||||
|
while (($linea = fgets($conexion)) !== false) {
|
||||||
|
// Separar el nombre de usuario y la contraseña de cada línea
|
||||||
|
list($usuario_registrado, $contraseña_registrada, $nombre_registrado ,$acceso_registrado) = explode(":", trim($linea));
|
||||||
|
|
||||||
|
// Comparar los datos
|
||||||
|
if ($usuario === $usuario_registrado && password_verify($contraseña, $contraseña_registrada)) {
|
||||||
|
$usuario_encontrado = true;
|
||||||
|
$nombre_usuario=$nombre_registrado;
|
||||||
|
$acceso_usuario=$acceso_registrado;
|
||||||
|
$correo_usuario=$usuario_registrado;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cerrar el archivo
|
||||||
|
fclose($conexion);
|
||||||
|
|
||||||
|
// Verificar si se encontró
|
||||||
|
if ($usuario_encontrado) {
|
||||||
|
// Si los datos son válidos, iniciar sesión y redirigir al usuario
|
||||||
|
session_start();
|
||||||
|
$_SESSION['usuario'] = $nombre_usuario;
|
||||||
|
$_SESSION['correo'] = $correo_usuario;
|
||||||
|
|
||||||
|
if ($acceso_usuario === "cliente") {
|
||||||
|
header('Location: perfil_cliente.php'); // Redireccionar a la página de cliente
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($acceso_usuario === "hotel") {
|
||||||
|
header('Location: buscador_reservas.php'); // Redireccionar a la página de gestión
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Si los datos no son válidos, mostrar un mensaje de error
|
||||||
|
echo '<p style="color: red">El nombre de usuario o la contraseña son incorrectos.</p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
9
Practicas/Practicas_PHP/ejercicios/Sesiones/logout.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
// Conectar con la sesión
|
||||||
|
session_start();
|
||||||
|
// Destruimos las sesiones
|
||||||
|
session_destroy();
|
||||||
|
// Llevamos a login.php
|
||||||
|
header('Location: login_usuarios.php');
|
||||||
|
// Cortamos el script
|
||||||
|
exit();
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
// Comprobamos si existe la sesión
|
||||||
|
session_start();
|
||||||
|
if (!isset($_SESSION['usuario'])) {
|
||||||
|
// En caso contrario devolvemos a la página login.php
|
||||||
|
header('Location: login_usuarios.php');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!Doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Reservas hotel</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div><!-- Saludamos -->
|
||||||
|
<h1>Bienvenido <?php echo $_SESSION['usuario']; ?></h1>
|
||||||
|
<!-- Botón para cerrar la sesión -->
|
||||||
|
<a href="logout.php">Cerrar sesión</a></div>
|
||||||
|
|
||||||
|
|
||||||
|
<div><h2>Estas son sus reservas:</h2>
|
||||||
|
<?php
|
||||||
|
//Suponiendo que el archivo caracteres.php está en la misma carpeta:
|
||||||
|
include('caracteres.php');
|
||||||
|
|
||||||
|
//Abrir el archivo
|
||||||
|
$archivo = fopen('listado_reservas.txt', 'r');
|
||||||
|
|
||||||
|
//Leer el archivo
|
||||||
|
if (!$archivo) { echo("Error abriendo archivo"); }
|
||||||
|
|
||||||
|
// Abro la tabla
|
||||||
|
echo '<br>';
|
||||||
|
echo '<table border="2">';
|
||||||
|
echo "<tr><th>Id Reserva</th><th>Nombre</th><th>Correo</th><th>Teléfono</th><th>Entrada</th><th>Salida</th><th>Fecha reserva</th><th>Duración</th></tr>";
|
||||||
|
|
||||||
|
//Busco la coincidencia
|
||||||
|
$contador=0;
|
||||||
|
while (($linea = fgets($archivo)) != false) {
|
||||||
|
if(strpos(eliminar_tildes(strtolower($linea)), eliminar_tildes(strtolower($_SESSION['correo']))) !== false){
|
||||||
|
|
||||||
|
// Mostrar la tabla con array
|
||||||
|
$arrayLinea=explode('/_/', $linea);
|
||||||
|
//foreach ($arrayLinea as $dato) {
|
||||||
|
// echo "<td>$dato</td>";
|
||||||
|
//}
|
||||||
|
echo "<tr><td>$arrayLinea[0]</td><td>$arrayLinea[1]</td><td>$arrayLinea[2]</td><td>$arrayLinea[3]</td><td>$arrayLinea[4]</td><td>$arrayLinea[5]</td><td>$arrayLinea[6]</td><td>$arrayLinea[7]</td></tr>";
|
||||||
|
$contador++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Cierrro la tabla
|
||||||
|
echo "</table>";
|
||||||
|
if ($contador == 0) {
|
||||||
|
echo "<p>Usted no tiene reservas</p>";
|
||||||
|
}
|
||||||
|
//cerrar el archivo
|
||||||
|
fclose($archivo);
|
||||||
|
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div><p><a href="formulario_hotel.php">Realize su reserva</a></p></div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
|
||||||
|
<?php
|
||||||
|
// Comprobamos si existe la sesión
|
||||||
|
session_start();
|
||||||
|
if (!isset($_SESSION['usuario'])) {
|
||||||
|
// En caso contrario devolvemos a la página login.php
|
||||||
|
header('Location: login_usuarios.php');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!Doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
|
||||||
|
<title>Reservas hotel</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div><!-- Saludamos -->
|
||||||
|
<h1>Usuario: <?php echo $_SESSION['usuario']; ?></h1>
|
||||||
|
<!-- Botón para cerrar la sesión -->
|
||||||
|
<a href="logout.php">Cerrar sesión</a></div>
|
||||||
|
<div id="container">
|
||||||
|
<?php
|
||||||
|
// Verificar si se recibieron los datos del formulario
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
// Obtener los datos del formulario
|
||||||
|
$entrada = $_POST["entrada"];
|
||||||
|
$salida = $_POST["salida"];
|
||||||
|
$habitacion = $_POST["habitacion"];
|
||||||
|
$regimen = $_POST["regimen"];
|
||||||
|
$spa = $_POST["spa"];
|
||||||
|
$guia = $_POST["guia"];
|
||||||
|
$noches = $_POST["noches"];
|
||||||
|
$coste = $_POST["total"];
|
||||||
|
$nombre = $_POST["nombre"];
|
||||||
|
$email = $_POST["email"];
|
||||||
|
$telefono = $_POST["telefono"];
|
||||||
|
$dni = $_POST["dni"];
|
||||||
|
$info = $_POST["info"];
|
||||||
|
//var_dump($_POST);
|
||||||
|
echo "<br>";
|
||||||
|
// Identificador reserva
|
||||||
|
$id_reserva = time()."_".rand(1000,9999);
|
||||||
|
// Fecha de la reserva
|
||||||
|
$fecha_reserva = date('d-m-Y H:i:s', time());
|
||||||
|
|
||||||
|
// Formatear los datos para escribir en el archivo
|
||||||
|
$datosReserva = "Id reserva: " . $id_reserva . "\n" .
|
||||||
|
"Fecha de reserva: " . $fecha_reserva . "\n" .
|
||||||
|
"Fecha de entrada: " . $entrada . "\n" .
|
||||||
|
"Fecha de salida: " . $salida . "\n" .
|
||||||
|
"Tipo de habitación: " . $habitacion . "\n" .
|
||||||
|
"Regimen de alojamiento: " . $regimen . "\n" .
|
||||||
|
"Días Spa: " . $spa . "\n" .
|
||||||
|
"Días Guia: " . $guia . "\n" .
|
||||||
|
"Duración estancia: " . $noches . "\n" .
|
||||||
|
"Coste Total: " . $coste . "\n" .
|
||||||
|
"Nombre: " . $nombre . "\n" .
|
||||||
|
"Correo electrónico: " . $email . "\n" .
|
||||||
|
"Teléfono: " . $telefono . "\n" .
|
||||||
|
"DNI: " . $dni . "\n\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Mensaje correo para el hotel
|
||||||
|
// Correo electrónico de destino
|
||||||
|
$destinatario = "asinxx@gmail.com";
|
||||||
|
|
||||||
|
// Asunto del correo electrónico
|
||||||
|
$asunto = "Hay una nueva reserva: $id_reserva ";
|
||||||
|
$headers = "Reply-To: " . $email . "\r\n".'Bcc: '.$email."\r\n";
|
||||||
|
// Envía el correo electrónico
|
||||||
|
//mail($destinatario, $asunto, $datosReserva,$headers);
|
||||||
|
|
||||||
|
// Ruta del archivo de reserva (dentro del directorio "reservas")
|
||||||
|
$archivoReserva = "reservas/reserva_" . $id_reserva . ".txt";
|
||||||
|
|
||||||
|
// Crear la ficha de reserva
|
||||||
|
if (file_put_contents($archivoReserva, $datosReserva) !== false) {
|
||||||
|
|
||||||
|
echo "<p>Reserva confirmada !</p>";
|
||||||
|
echo "<br>";
|
||||||
|
} else {
|
||||||
|
echo "<p>Error al registrar la reserva!</p>";
|
||||||
|
echo "<br>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escribir en listado de reservas
|
||||||
|
$lista_reservas="listado_reservas.txt";
|
||||||
|
$datos_reserva=$id_reserva."/_/".$nombre."/_/".$email."/_/".$telefono."/_/".$entrada."/_/".$salida."/_/".$fecha_reserva."/_/".$noches."\r\n";
|
||||||
|
file_put_contents($lista_reservas, $datos_reserva,FILE_APPEND | LOCK_EX);
|
||||||
|
|
||||||
|
|
||||||
|
// Mensaje cliente confirmación de opciones
|
||||||
|
echo nl2br($info);
|
||||||
|
echo "<br>";
|
||||||
|
echo "<br>";
|
||||||
|
echo "<p>Esta es la información detallada de tu reserva:</p>";
|
||||||
|
echo nl2br($datosReserva);
|
||||||
|
|
||||||
|
// Recibir DNI cliente
|
||||||
|
// Directorio donde se guardarán los archivos subidos
|
||||||
|
$directorio_subida = "dni_clientes/";
|
||||||
|
|
||||||
|
// Nombre del archivo y ruta de destino
|
||||||
|
$nombre_archivo=$_FILES["dnifile"]["name"];
|
||||||
|
$nombre_archivo_final = $dni.'_'.$id_reserva.'_'.$nombre_archivo;
|
||||||
|
$ruta_archivo = $directorio_subida . $nombre_archivo_final;
|
||||||
|
|
||||||
|
// Tamaño máximo permitido (2MB)
|
||||||
|
$tamano_maximo = 2 * 1024 * 1024;
|
||||||
|
|
||||||
|
// Obtiene la extensión del archivo en minúsculas
|
||||||
|
$extension_archivo = strtolower(pathinfo($_FILES["dnifile"]["name"], PATHINFO_EXTENSION));
|
||||||
|
|
||||||
|
// Array de extensiones permitidas
|
||||||
|
$extensiones_permitidas = array("jpg", "jpeg", "pdf");
|
||||||
|
|
||||||
|
// Verifica si el archivo es una extensión permitida y no excede el tamaño máximo
|
||||||
|
if (in_array($extension_archivo, $extensiones_permitidas) && $_FILES["dnifile"]["size"] <= $tamano_maximo) {
|
||||||
|
|
||||||
|
// Intenta mover el archivo al directorio de destino
|
||||||
|
if (move_uploaded_file($_FILES["dnifile"]["tmp_name"], $ruta_archivo)) {
|
||||||
|
echo "Su DNI ha sido recibido.";
|
||||||
|
} else {
|
||||||
|
echo "Lo siento, hubo un error al subir su DNI.";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "Lo siento, solo se permiten archivos en formato JPG o PDF con un tamaño máximo de 2MB.";
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Si no se recibieron datos por POST, mostrar un mensaje de error
|
||||||
|
echo "Error: No se recibieron datos del formulario.";
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Registro de Clientes</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
<body>
|
||||||
|
<div><h2>Registro de Clientes</h2>
|
||||||
|
<form action="" method="post">
|
||||||
|
<label for="nombre">Nombre:</label><br>
|
||||||
|
<input type="text" id="nombre" name="nombre" required><br><br>
|
||||||
|
<label for="email">Correo electrónico:</label><br>
|
||||||
|
<input type="email" id="email" name="email" required><br><br>
|
||||||
|
<label for="password">Contraseña:</label><br>
|
||||||
|
<input type="password" id="password" name="password" required><br><br>
|
||||||
|
<input type="submit" value="Registrar">
|
||||||
|
</form></div>
|
||||||
|
<?php
|
||||||
|
// Verificar si se ha enviado el formulario
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
// Obtener los datos del formulario
|
||||||
|
$nombre = $_POST["nombre"];
|
||||||
|
$email = $_POST["email"];
|
||||||
|
$password = $_POST["password"];
|
||||||
|
|
||||||
|
// Verificar si el correo electrónico ya está registrado
|
||||||
|
$archivo = 'usuarios.txt';
|
||||||
|
|
||||||
|
if (file_exists($archivo)) {
|
||||||
|
$conexion = fopen($archivo, 'r'); // Abrir el archivo en modo de lectura ('r')
|
||||||
|
|
||||||
|
// Recorrer el archivo línea por línea
|
||||||
|
while (($linea = fgets($conexion)) !== false) {
|
||||||
|
// Separar el correo electrónico y la contraseña de cada línea
|
||||||
|
list($usuario_email, $usuario_password, $usuario_nombre ,$usuario_acceso) = explode(':', trim($linea));
|
||||||
|
|
||||||
|
// Comparar el correo electrónico actual con el del archivo
|
||||||
|
if ($email === $usuario_email) {
|
||||||
|
fclose($conexion); // Cerrar el archivo
|
||||||
|
exit("El correo electrónico ya está registrado");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($conexion); // Cerrar el archivo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guardar el usuario en el archivo (fuera del bucle)
|
||||||
|
$password_encriptada=password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
$linea = "$email:$password_encriptada:$nombre:cliente\n";
|
||||||
|
file_put_contents($archivo, $linea, FILE_APPEND | LOCK_EX);
|
||||||
|
|
||||||
|
|
||||||
|
header('Location: login_usuarios.php');
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Registro de Clientes</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
<body>
|
||||||
|
<div><h2>Registro de Común</h2>
|
||||||
|
<form action="" method="post">
|
||||||
|
<label for="nombre">Nombre:</label><br>
|
||||||
|
<input type="text" id="nombre" name="nombre" required><br><br>
|
||||||
|
<label for="email">Correo electrónico:</label><br>
|
||||||
|
<input type="email" id="email" name="email" required><br><br>
|
||||||
|
<label for="password">Contraseña:</label><br>
|
||||||
|
<input type="password" id="password" name="password" required><br><br>
|
||||||
|
<input type="submit" value="Registrar">
|
||||||
|
</form></div>
|
||||||
|
<?php
|
||||||
|
// Verificar si se ha enviado el formulario
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
// Obtener los datos del formulario
|
||||||
|
$nombre = $_POST["nombre"];
|
||||||
|
$email = $_POST["email"];
|
||||||
|
$password = $_POST["password"];
|
||||||
|
$acceso=$_GET["acceso"];
|
||||||
|
|
||||||
|
// Verificar si el correo electrónico ya está registrado
|
||||||
|
$archivo = 'usuarios.txt';
|
||||||
|
|
||||||
|
if (file_exists($archivo)) {
|
||||||
|
$conexion = fopen($archivo, 'r'); // Abrir el archivo en modo de lectura ('r')
|
||||||
|
|
||||||
|
// Recorrer el archivo línea por línea
|
||||||
|
while (($linea = fgets($conexion)) !== false) {
|
||||||
|
// Separar el correo electrónico y la contraseña de cada línea
|
||||||
|
list($usuario_email, $usuario_password, $usuario_nombre ,$usuario_acceso) = explode(':', trim($linea));
|
||||||
|
|
||||||
|
// Comparar el correo electrónico actual con el del archivo
|
||||||
|
if ($email === $usuario_email) {
|
||||||
|
fclose($conexion); // Cerrar el archivo
|
||||||
|
exit("El correo electrónico ya está registrado");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($conexion); // Cerrar el archivo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guardar el usuario en el archivo (fuera del bucle)
|
||||||
|
$password_encriptada=password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
$linea = "$email:$password_encriptada:$nombre:$acceso\n";
|
||||||
|
file_put_contents($archivo, $linea, FILE_APPEND | LOCK_EX);
|
||||||
|
|
||||||
|
|
||||||
|
header('Location: login_usuarios_dos.php');
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Registro de Personal Hotel</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
<body>
|
||||||
|
<div><h2>Registro de Personal Hotel</h2>
|
||||||
|
<form action="" method="post">
|
||||||
|
<label for="nombre">Nombre:</label><br>
|
||||||
|
<input type="text" id="nombre" name="nombre" required><br><br>
|
||||||
|
<label for="email">Correo electrónico:</label><br>
|
||||||
|
<input type="email" id="email" name="email" required><br><br>
|
||||||
|
<label for="password">Contraseña:</label><br>
|
||||||
|
<input type="password" id="password" name="password" required><br><br>
|
||||||
|
<input type="submit" value="Registrar">
|
||||||
|
</form></div>
|
||||||
|
<?php
|
||||||
|
// Verificar si se ha enviado el formulario
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
// Obtener los datos del formulario
|
||||||
|
$nombre = $_POST["nombre"];
|
||||||
|
$email = $_POST["email"];
|
||||||
|
$password = $_POST["password"];
|
||||||
|
|
||||||
|
// Verificar si el correo electrónico ya está registrado
|
||||||
|
$archivo = 'usuarios.txt';
|
||||||
|
|
||||||
|
if (file_exists($archivo)) {
|
||||||
|
$conexion = fopen($archivo, 'r'); // Abrir el archivo en modo de lectura ('r')
|
||||||
|
|
||||||
|
// Recorrer el archivo línea por línea
|
||||||
|
while (($linea = fgets($conexion)) !== false) {
|
||||||
|
// Separar el correo electrónico y la contraseña de cada línea
|
||||||
|
list($usuario_email, $usuario_password, $usuario_nombre ,$usuario_acceso) = explode(':', trim($linea));
|
||||||
|
|
||||||
|
// Comparar el correo electrónico actual con el del archivo
|
||||||
|
if ($email === $usuario_email) {
|
||||||
|
fclose($conexion); // Cerrar el archivo
|
||||||
|
exit("El correo electrónico ya está registrado");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($conexion); // Cerrar el archivo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guardar el usuario en el archivo (fuera del bucle)
|
||||||
|
$password_encriptada=password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
$linea = "$email:$password_encriptada:$nombre:hotel\n";
|
||||||
|
file_put_contents($archivo, $linea, FILE_APPEND | LOCK_EX);
|
||||||
|
|
||||||
|
|
||||||
|
header('Location: login_usuarios.php');
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<form action="" method="POST">
|
||||||
|
<h2>Buqueda de cliente</h2>
|
||||||
|
<div style="display: flex; flex-direction:column; width:fit-content; gap: 0.5rem;">
|
||||||
|
<div style="display: flex; flex-direction:column;">
|
||||||
|
<label for="matricula">Matricula</label>
|
||||||
|
<input type="text" name="matricula" id="matricula">
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; flex-direction:column;">
|
||||||
|
<label for="telefono">Telefono</label>
|
||||||
|
<input type="text" name="telefono" id="telefono">
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; flex-direction:column;">
|
||||||
|
<label for="email">Email</label>
|
||||||
|
<input type="email" name="email" id="email">
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; flex-direction:column; margin-bottom: 1rem;">
|
||||||
|
<label for="Id Usuario">Id Usuario</label>
|
||||||
|
<input type="text" name="idUsuario" id="idUsuario">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="submit" value="Buscar">
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
|
||||||
|
$directorioSeguros = "seguros";
|
||||||
|
$terminoBusqueda = "";
|
||||||
|
if (isset($_POST['matricula'])) {
|
||||||
|
$terminoBusqueda = $_POST['matricula'];
|
||||||
|
} elseif (isset($_POST['telefono'])) {
|
||||||
|
$terminoBusqueda = $_POST['telefono'];
|
||||||
|
} elseif (isset($_POST['email'])) {
|
||||||
|
$terminoBusqueda = $_POST['email'];
|
||||||
|
} elseif (isset($_POST['idUsuario'])) {
|
||||||
|
$terminoBusqueda = $_POST['idUsuario'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$separador = "/_/";
|
||||||
|
$nombre_archivo = "listado_clientes.txt";
|
||||||
|
$archivo = fopen($nombre_archivo, 'r');
|
||||||
|
|
||||||
|
$matriculas = [];
|
||||||
|
while (($linea = fgets($archivo)) !== false) {
|
||||||
|
if (strpos($linea, $terminoBusqueda) !== false) {
|
||||||
|
$matriculas[] = trim(explode("/_/", $linea)[4]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($archivo);
|
||||||
|
|
||||||
|
foreach ($matriculas as $matricula) {
|
||||||
|
$archivo = "$matricula" . "_fichacliente.txt";
|
||||||
|
$contenido = file_get_contents($directorioSeguros . '/' . $archivo);
|
||||||
|
echo implode("<br>", explode("\n", $contenido)); // o echo nl2br($contenido);
|
||||||
|
echo "<br><br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<form action="" method="POST">
|
||||||
|
<h2>Filtrado entre fechas</h2>
|
||||||
|
<div style="display: flex; flex-direction:column; width:fit-content; gap:1rem">
|
||||||
|
<input type="date" name="fechaIni" id="fechaIni">
|
||||||
|
<input type="date" name="fechaFin" id="fechaFin">
|
||||||
|
<input type="submit" value="Enviar">
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$fechaIni = strtotime($_POST['fechaIni']);
|
||||||
|
$fechaFin = strtotime($_POST['fechaFin']);
|
||||||
|
|
||||||
|
$separador = "/_/";
|
||||||
|
$nombre_archivo = "listado_clientes.txt";
|
||||||
|
$archivo = fopen($nombre_archivo, 'r');
|
||||||
|
|
||||||
|
while (($linea = fgets($archivo)) !== false) {
|
||||||
|
$contenido_linea = explode("/_/", $linea);
|
||||||
|
$tiempo = $contenido_linea[0];
|
||||||
|
$tiempo = intval(substr($tiempo, 0, strpos($tiempo, '_')));
|
||||||
|
|
||||||
|
if ($tiempo >= $fechaIni && $tiempo <= $fechaFin) {
|
||||||
|
echo "Cliente: $contenido_linea[1] - $contenido_linea[2] <br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($nombre_archivo);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$directorio = "seguros";
|
||||||
|
$archivos = scandir($directorio);
|
||||||
|
$tipo_seguro = 'Todo Riesgo';
|
||||||
|
|
||||||
|
$ofertaText = file_get_contents('./oferta_aseguradora.txt');
|
||||||
|
|
||||||
|
foreach ($archivos as $archivo) {
|
||||||
|
if (is_file($directorio . '/' . $archivo)) {
|
||||||
|
$contenido = file_get_contents($directorio . '/' . $archivo);
|
||||||
|
if (strpos($contenido, $tipo_seguro) === false) {
|
||||||
|
$lineas = explode("\n", $contenido);
|
||||||
|
$arrayDatos = array(
|
||||||
|
trim((explode(": ", $lineas[0]))[1]),
|
||||||
|
trim((explode(": ", $lineas[3]))[1]),
|
||||||
|
trim((explode(": ", $lineas[4]))[1]),
|
||||||
|
trim((explode(": ", $lineas[6]))[1])
|
||||||
|
);
|
||||||
|
$arraySusti = array(
|
||||||
|
'[Nombre del Cliente]',
|
||||||
|
'[Marca]',
|
||||||
|
'[Modelo]',
|
||||||
|
'[Matricula]'
|
||||||
|
);
|
||||||
|
|
||||||
|
$emailOferta = str_replace($arraySusti, $arrayDatos, $ofertaText);
|
||||||
|
$destinatario = trim((explode(": ", $lineas[1]))[1]);
|
||||||
|
$asunto = "Oferta Seguro a todo Riesgo";
|
||||||
|
$headers = 'Reply-To: appasin04@gmail.com' . "\r\n";
|
||||||
|
if (mail($destinatario, $asunto, $emailOferta, $headers)) {
|
||||||
|
echo "Correo enviado a $arrayDatos[0] - $destinatario <br>";
|
||||||
|
} else {
|
||||||
|
echo "No se ha podido enviar el correo a $arrayDatos[0] - $destinatario <br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$lineas = array();
|
||||||
|
$correos = array();
|
||||||
|
$nombres = array();
|
||||||
|
$separador = "/_/";
|
||||||
|
$nombre_archivo = "listado_clientes.txt";
|
||||||
|
$archivo = fopen($nombre_archivo, 'r');
|
||||||
|
|
||||||
|
/* Enviar Email a todos los detinatarios sin personalizar*/
|
||||||
|
// while (($linea = fgets($archivo)) !== false) {
|
||||||
|
// $contenido_linea = explode("/_/", $linea);
|
||||||
|
// $nombres[] = $contenido_linea[1];
|
||||||
|
// $correos[] = $contenido_linea[2];
|
||||||
|
// $lineas[] = $contenido_linea;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $destinatarios=implode(',',$correos);
|
||||||
|
// $asunto = "Estimado cliente";
|
||||||
|
// $emailText = file_get_contents('./correo_generico.txt');
|
||||||
|
// $headers="";
|
||||||
|
// if (mail($destinatarios, $asunto, $emailText, $headers)) {
|
||||||
|
// echo "Correo enviado";
|
||||||
|
// } else {
|
||||||
|
// echo "No se ha podido enviar el correo";
|
||||||
|
// }
|
||||||
|
|
||||||
|
$emailText = file_get_contents('./correo_generico.txt');
|
||||||
|
|
||||||
|
while (($linea = fgets($archivo)) !== false) {
|
||||||
|
$contenido_linea = explode("/_/", $linea);
|
||||||
|
$nombre = $contenido_linea[1];
|
||||||
|
$correo = $contenido_linea[2];
|
||||||
|
|
||||||
|
$destinatario=$correo;
|
||||||
|
$asunto = "Estimado $nombre";
|
||||||
|
$headers="";
|
||||||
|
$emailTextPersonalizado= str_replace("cliente",$nombre,$emailText);
|
||||||
|
if (mail($destinatario, $asunto, $emailTextPersonalizado, $headers)) {
|
||||||
|
echo "Correo enviado correctamente a la direccion $destinatario <br>";
|
||||||
|
} else {
|
||||||
|
echo "No se ha podido enviar el correo a la direccion $destinatario <br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Ejercicio Aseguradora</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<form action="" method="POST">
|
||||||
|
<label for="nombre">Nombre completo:</label><br>
|
||||||
|
<input type="text" id="nombre" name="nombre" required><br><br>
|
||||||
|
|
||||||
|
<label for="email">Correo electrónico:</label><br>
|
||||||
|
<input type="email" id="email" name="email" required><br><br>
|
||||||
|
|
||||||
|
<label for="telefono">Teléfono:</label><br>
|
||||||
|
<input type="tel" id="telefono" name="telefono"><br><br>
|
||||||
|
|
||||||
|
<label for="marca">Marca del coche:</label><br>
|
||||||
|
<input type="text" id="marca" name="marca" required><br><br>
|
||||||
|
|
||||||
|
<label for="modelo">Modelo del coche:</label><br>
|
||||||
|
<input type="text" id="modelo" name="modelo" required><br><br>
|
||||||
|
|
||||||
|
<label for="anio">Año del coche:</label><br>
|
||||||
|
<input type="number" id="anio" name="anio" min="1900" max="2099" required><br><br>
|
||||||
|
|
||||||
|
<label for="matricula">Matricula:</label><br>
|
||||||
|
<input type="text" id="matricula" name="matricula" required><br><br>
|
||||||
|
|
||||||
|
<label for="tipo_seguro">Tipo de seguro:</label><br>
|
||||||
|
<select id="tipo_seguro" name="tipo_seguro" required>
|
||||||
|
<option value="">Selecciona el tipo de seguro</option>
|
||||||
|
<option value="Terceros">Terceros</option>
|
||||||
|
<option value="Terceros Ampliado">Terceros Ampliado</option>
|
||||||
|
<option value="Todo Riesgo">Todo Riesgo</option>
|
||||||
|
</select><br><br>
|
||||||
|
|
||||||
|
<label for="comentarios">Comentarios:</label><br>
|
||||||
|
<textarea id="comentarios" name="comentarios" rows="4" cols="50"></textarea><br><br>
|
||||||
|
|
||||||
|
<input type="submit" value="Enviar">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$nombre = $_POST['nombre'];
|
||||||
|
$email = $_POST['email'];
|
||||||
|
$telefono = $_POST['telefono'];
|
||||||
|
$marca = $_POST['marca'];
|
||||||
|
$modelo = $_POST['modelo'];
|
||||||
|
$anio = $_POST['anio'];
|
||||||
|
$matricula = $_POST['matricula'];
|
||||||
|
$tipoSeguro = $_POST['tipo_seguro'];
|
||||||
|
$comentarios = $_POST['comentarios'];
|
||||||
|
|
||||||
|
|
||||||
|
$emailText = 'Detalles del seguro de coche \r\n';
|
||||||
|
$emailText .= "Nombre: $nombre \r\n";
|
||||||
|
$emailText .= "Email: $email \r\n";
|
||||||
|
$emailText .= "Telefono: $telefono \r\n";
|
||||||
|
$emailText .= "Marca: $marca \r\n";
|
||||||
|
$emailText .= "Modelo: $modelo \r\n";
|
||||||
|
$emailText .= "Año: $anio \r\n";
|
||||||
|
$emailText .= "Matricula: $matricula \r\n";
|
||||||
|
$emailText .= "Tipo seguro: $tipoSeguro \r\n";
|
||||||
|
$emailText .= "Comentarios: $comentarios \r\n";
|
||||||
|
|
||||||
|
|
||||||
|
$destinatario = "appasin04@gmail.com";
|
||||||
|
$asunto = "Solicitud informacion seguro";
|
||||||
|
$headers = 'Reply-To: appasin04@gmail.com' . "\r\n";
|
||||||
|
if (mail($destinatario, $asunto, $emailText, $headers)) {
|
||||||
|
echo "Correo enviado";
|
||||||
|
} else {
|
||||||
|
echo "No se ha podido enviar el correo";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Ejercicio Aseguradora</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<form action="" method="POST">
|
||||||
|
<label for="nombre">Nombre completo:</label><br>
|
||||||
|
<input type="text" id="nombre" name="nombre" required><br><br>
|
||||||
|
|
||||||
|
<label for="email">Correo electrónico:</label><br>
|
||||||
|
<input type="email" id="email" name="email" required><br><br>
|
||||||
|
|
||||||
|
<label for="telefono">Teléfono:</label><br>
|
||||||
|
<input type="tel" id="telefono" name="telefono"><br><br>
|
||||||
|
|
||||||
|
<label for="marca">Marca del coche:</label><br>
|
||||||
|
<input type="text" id="marca" name="marca" required><br><br>
|
||||||
|
|
||||||
|
<label for="modelo">Modelo del coche:</label><br>
|
||||||
|
<input type="text" id="modelo" name="modelo" required><br><br>
|
||||||
|
|
||||||
|
<label for="anio">Año del coche:</label><br>
|
||||||
|
<input type="number" id="anio" name="anio" min="1900" max="2099" required><br><br>
|
||||||
|
|
||||||
|
<label for="matricula">Matricula:</label><br>
|
||||||
|
<input type="text" id="matricula" name="matricula" required><br><br>
|
||||||
|
|
||||||
|
<label for="tipo_seguro">Tipo de seguro:</label><br>
|
||||||
|
<select id="tipo_seguro" name="tipo_seguro" required>
|
||||||
|
<option value="">Selecciona el tipo de seguro</option>
|
||||||
|
<option value="Terceros">Terceros</option>
|
||||||
|
<option value="Terceros Ampliado">Terceros Ampliado</option>
|
||||||
|
<option value="Todo Riesgo">Todo Riesgo</option>
|
||||||
|
</select><br><br>
|
||||||
|
|
||||||
|
<label for="comentarios">Comentarios:</label><br>
|
||||||
|
<textarea id="comentarios" name="comentarios" rows="4" cols="50"></textarea><br><br>
|
||||||
|
|
||||||
|
<input type="submit" value="Enviar">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$nombre = $_POST['nombre'];
|
||||||
|
$email = $_POST['email'];
|
||||||
|
$telefono = $_POST['telefono'];
|
||||||
|
$marca = $_POST['marca'];
|
||||||
|
$modelo = $_POST['modelo'];
|
||||||
|
$anio = $_POST['anio'];
|
||||||
|
$matricula = $_POST['matricula'];
|
||||||
|
$tipoSeguro = $_POST['tipo_seguro'];
|
||||||
|
$comentarios = $_POST['comentarios'];
|
||||||
|
|
||||||
|
|
||||||
|
$emailText = "Detalles del seguro de coche \r\n";
|
||||||
|
$emailText .= "Nombre: $nombre \r\n";
|
||||||
|
$emailText .= "Email: $email \r\n";
|
||||||
|
$emailText .= "Telefono: $telefono \r\n";
|
||||||
|
$emailText .= "Marca: $marca \r\n";
|
||||||
|
$emailText .= "Modelo: $modelo \r\n";
|
||||||
|
$emailText .= "Año: $anio \r\n";
|
||||||
|
$emailText .= "Matricula: $matricula \r\n";
|
||||||
|
$emailText .= "Tipo seguro: $tipoSeguro \r\n";
|
||||||
|
$emailText .= "Comentarios: $comentarios \r\n";
|
||||||
|
|
||||||
|
|
||||||
|
$destinatario = "appasin04@gmail.com";
|
||||||
|
$asunto = "Solicitud informacion seguro";
|
||||||
|
$headers = 'Reply-To: appasin04@gmail.com' . "\r\n";
|
||||||
|
if (mail($destinatario, $asunto, $emailText, $headers)) {
|
||||||
|
echo "Correo enviado";
|
||||||
|
guardarRegistro($emailText,$matricula);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
echo "No se ha podido enviar el correo";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function guardarRegistro($emailText,$matricula){
|
||||||
|
$emailText = preg_replace('/^.+\r\n/', '', $emailText);
|
||||||
|
$nombre_archivo = "seguros/" . $matricula ."_fichacliente.txt";
|
||||||
|
$archivo = fopen($nombre_archivo, 'w');
|
||||||
|
fwrite($archivo, $emailText);
|
||||||
|
fclose($archivo);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
109
Practicas/Practicas_PHP/ejercicios/aseguradora/Ejercicio7 v3.php
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Ejercicio Aseguradora</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<form action="" method="POST">
|
||||||
|
<label for="nombre">Nombre completo:</label><br>
|
||||||
|
<input type="text" id="nombre" name="nombre" required><br><br>
|
||||||
|
|
||||||
|
<label for="email">Correo electrónico:</label><br>
|
||||||
|
<input type="email" id="email" name="email" required><br><br>
|
||||||
|
|
||||||
|
<label for="telefono">Teléfono:</label><br>
|
||||||
|
<input type="tel" id="telefono" name="telefono"><br><br>
|
||||||
|
|
||||||
|
<label for="marca">Marca del coche:</label><br>
|
||||||
|
<input type="text" id="marca" name="marca" required><br><br>
|
||||||
|
|
||||||
|
<label for="modelo">Modelo del coche:</label><br>
|
||||||
|
<input type="text" id="modelo" name="modelo" required><br><br>
|
||||||
|
|
||||||
|
<label for="anio">Año del coche:</label><br>
|
||||||
|
<input type="number" id="anio" name="anio" min="1900" max="2099" required><br><br>
|
||||||
|
|
||||||
|
<label for="matricula">Matricula:</label><br>
|
||||||
|
<input type="text" id="matricula" name="matricula" required><br><br>
|
||||||
|
|
||||||
|
<label for="tipo_seguro">Tipo de seguro:</label><br>
|
||||||
|
<select id="tipo_seguro" name="tipo_seguro" required>
|
||||||
|
<option value="">Selecciona el tipo de seguro</option>
|
||||||
|
<option value="Terceros">Terceros</option>
|
||||||
|
<option value="Terceros Ampliado">Terceros Ampliado</option>
|
||||||
|
<option value="Todo Riesgo">Todo Riesgo</option>
|
||||||
|
</select><br><br>
|
||||||
|
|
||||||
|
<label for="comentarios">Comentarios:</label><br>
|
||||||
|
<textarea id="comentarios" name="comentarios" rows="4" cols="50"></textarea><br><br>
|
||||||
|
|
||||||
|
<input type="submit" value="Enviar">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$nombre = $_POST['nombre'];
|
||||||
|
$email = $_POST['email'];
|
||||||
|
$telefono = $_POST['telefono'];
|
||||||
|
$marca = $_POST['marca'];
|
||||||
|
$modelo = $_POST['modelo'];
|
||||||
|
$anio = $_POST['anio'];
|
||||||
|
$matricula = $_POST['matricula'];
|
||||||
|
$tipoSeguro = $_POST['tipo_seguro'];
|
||||||
|
$comentarios = $_POST['comentarios'];
|
||||||
|
|
||||||
|
|
||||||
|
$emailText = "Detalles del seguro de coche \r\n";
|
||||||
|
$emailText .= "Nombre: $nombre \r\n";
|
||||||
|
$emailText .= "Email: $email \r\n";
|
||||||
|
$emailText .= "Telefono: $telefono \r\n";
|
||||||
|
$emailText .= "Marca: $marca \r\n";
|
||||||
|
$emailText .= "Modelo: $modelo \r\n";
|
||||||
|
$emailText .= "Año: $anio \r\n";
|
||||||
|
$emailText .= "Matricula: $matricula \r\n";
|
||||||
|
$emailText .= "Tipo seguro: $tipoSeguro \r\n";
|
||||||
|
$emailText .= "Comentarios: $comentarios \r\n";
|
||||||
|
|
||||||
|
|
||||||
|
$destinatario = "appasin04@gmail.com";
|
||||||
|
$asunto = "Solicitud informacion seguro";
|
||||||
|
$headers = 'Reply-To: appasin04@gmail.com' . "\r\n";
|
||||||
|
guardarRegistro($emailText, $matricula);
|
||||||
|
guardaListaDatos($nombre, $email, $telefono, $matricula);
|
||||||
|
|
||||||
|
|
||||||
|
// if (mail($destinatario, $asunto, $emailText, $headers)) {
|
||||||
|
// echo "Correo enviado";
|
||||||
|
// } else {
|
||||||
|
// echo "No se ha podido enviar el correo";
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
function guardarRegistro($emailText, $matricula)
|
||||||
|
{
|
||||||
|
$emailText = preg_replace('/^.+\r\n/', '', $emailText);
|
||||||
|
$nombre_archivo = "seguros/" . $matricula . "_fichacliente.txt";
|
||||||
|
$archivo = fopen($nombre_archivo, 'w');
|
||||||
|
fwrite($archivo, $emailText);
|
||||||
|
fclose($archivo);
|
||||||
|
}
|
||||||
|
|
||||||
|
function guardaListaDatos($nombre, $email, $telefono, $matricula)
|
||||||
|
{
|
||||||
|
$separador = "/_/";
|
||||||
|
$slug = time() . '_' . mt_rand(1000, 9999);
|
||||||
|
$registro= $slug . $separador . $nombre . $separador . $email . $separador . $telefono . $separador . $matricula . "\r\n";
|
||||||
|
$nombre_archivo = "listado_clientes.txt";
|
||||||
|
$archivo = fopen($nombre_archivo, 'a');
|
||||||
|
fwrite($archivo, $registro);
|
||||||
|
fclose($archivo);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
Estimado(a) cliente,
|
||||||
|
|
||||||
|
En nombre de todo el equipo de Matre Seguros, queremos expresar nuestro más sincero agradecimiento por confiar en nosotros como su aseguradora de confianza para proteger su vehículo.
|
||||||
|
|
||||||
|
En Matre, nos esforzamos continuamente para brindarle el mejor servicio y la tranquilidad que merece al conducir su automóvil. Su confianza en nosotros nos impulsa a mejorar y a superar sus expectativas cada día.
|
||||||
|
|
||||||
|
Queremos que sepa que estamos aquí para usted en todo momento. Si tiene alguna pregunta, necesita asistencia o simplemente desea compartir sus comentarios, no dude en ponerse en contacto con nuestro equipo. Estamos disponibles para ayudarlo en cualquier momento y en cualquier situación.
|
||||||
|
|
||||||
|
Una vez más, gracias por elegir Matre Seguros. Valoramos su confianza y esperamos seguir siendo su socio confiable en la protección de su vehículo.
|
||||||
|
|
||||||
|
Atentamente,
|
||||||
|
|
||||||
|
El equipo de Matre Seguros
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
1708593337_2207/_/Marcos Lopez/_/appasin04@gmail.com/_/999999999/_/7935jpc
|
||||||
|
1708593365_7374/_/Perico Perez/_/appasin04@gmail.com/_/999999999/_/7854ase
|
||||||
|
1708593397_7743/_/Pedro/_/appasin04@gmail.com/_/999999999/_/8975trp
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
Estimad@ [Nombre del Cliente],
|
||||||
|
|
||||||
|
Como propietario de tu vehículo marca [Marca] y modelo [Modelo] con matricula [Matricula], en MATRE, siempre nos esforzamos por brindarte los mejores servicios y beneficios para garantizar tu tranquilidad y seguridad en todo momento.
|
||||||
|
|
||||||
|
Nos complace informarte sobre una emocionante oportunidad que hemos preparado especialmente para ti. Como cliente valioso de Matre, te ofrecemos un descuento exclusivo al actualizar tu póliza de seguro a todo riesgo.
|
||||||
|
|
||||||
|
Al cambiar a nuestro seguro de todo riesgo, disfrutarás de una cobertura más amplia que te protegerá en una variedad de situaciones imprevistas, proporcionándote la tranquilidad que mereces mientras estás en la carretera.
|
||||||
|
|
||||||
|
¡No dejes pasar esta oportunidad de proteger tu vehículo con la cobertura más completa al mejor precio posible!
|
||||||
|
|
||||||
|
Para obtener más información sobre nuestra oferta especial y discutir cómo podemos adaptarla a tus necesidades específicas, no dudes en contactarnos. Estamos aquí para ayudarte y responder a cualquier pregunta que puedas tener.
|
||||||
|
|
||||||
|
Esperamos poder ayudarte a tomar la decisión correcta para ti y tu vehículo. ¡No esperes más para aprovechar este descuento exclusivo y garantizar tu tranquilidad en la carretera!
|
||||||
|
|
||||||
|
¡Estamos ansiosos por recibir noticias tuyas y poder trabajar juntos para brindarte la mejor protección posible!
|
||||||
|
|
||||||
|
Saludos cordiales,
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
Nombre: Perico Perez
|
||||||
|
Email: appasin04@gmail.com
|
||||||
|
Telefono: 999999999
|
||||||
|
Marca: Audi
|
||||||
|
Modelo: Rx8
|
||||||
|
Año: 2016
|
||||||
|
Matricula: 7854ase
|
||||||
|
Tipo seguro: Terceros Ampliado
|
||||||
|
Comentarios:
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
Nombre: Marcos Lopez
|
||||||
|
Email: appasin04@gmail.com
|
||||||
|
Telefono: 999999999
|
||||||
|
Marca: Mazda
|
||||||
|
Modelo: 3 tdi
|
||||||
|
Año: 2016
|
||||||
|
Matricula: 7935jpc
|
||||||
|
Tipo seguro: Terceros
|
||||||
|
Comentarios:
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
Nombre: Pedro
|
||||||
|
Email: appasin04@gmail.com
|
||||||
|
Telefono: 999999999
|
||||||
|
Marca: Renault
|
||||||
|
Modelo: Fuego
|
||||||
|
Año: 1985
|
||||||
|
Matricula: 8975trp
|
||||||
|
Tipo seguro: Todo Riesgo
|
||||||
|
Comentarios:
|
||||||
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 3.3 MiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 255 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 64 KiB |
@@ -0,0 +1,141 @@
|
|||||||
|
<!Doctype html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
|
||||||
|
<title>Buscador de reservas</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<form method="post">
|
||||||
|
<p>*Término a buscar: </p>
|
||||||
|
<p><input type="text" name="busqueda" id="busqueda" size="30" placeholder="Introduzca la palabra de busqueda" required></p>
|
||||||
|
<input type="submit" name="buscar" value="Buscar">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
//Suponiendo que el archivo caracteres.php está en la misma carpeta:
|
||||||
|
include('caracteres.php');
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['buscar'])) {
|
||||||
|
// Busca una palabra
|
||||||
|
$busqueda = isset($_REQUEST['busqueda']) ? $_REQUEST['busqueda'] : "";
|
||||||
|
|
||||||
|
|
||||||
|
//Abrir el archivo
|
||||||
|
$archivo = fopen('listado_reservas.txt', 'r');
|
||||||
|
|
||||||
|
//Leer el archivo
|
||||||
|
|
||||||
|
if (!$archivo) {
|
||||||
|
echo ("Error abriendo archivo");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Abro la tabla
|
||||||
|
echo '<br>';
|
||||||
|
echo '<table border="2">';
|
||||||
|
echo "<tr><th>Id Reserva</th><th>Nombre</th><th>Correo</th><th>Teléfono</th><th>Entrada</th><th>Salida</th><th>Fecha reserva</th><th>Duración</th></tr>";
|
||||||
|
|
||||||
|
//Busco la coincidencia
|
||||||
|
$id_encontrado = null;
|
||||||
|
while (($linea = fgets($archivo)) != false) {
|
||||||
|
if (strpos(eliminar_tildes(strtolower($linea)), eliminar_tildes(strtolower($busqueda))) !== false) {
|
||||||
|
|
||||||
|
// Mostrar la tabla con array
|
||||||
|
$arrayLinea = explode('/_/', $linea);
|
||||||
|
//foreach ($arrayLinea as $dato) {
|
||||||
|
// echo "<td>$dato</td>";
|
||||||
|
//}
|
||||||
|
echo "<tr><td>$arrayLinea[0]</td><td>$arrayLinea[1]</td><td>$arrayLinea[2]</td><td>$arrayLinea[3]</td><td>$arrayLinea[4]</td><td>$arrayLinea[5]</td><td>$arrayLinea[6]</td><td>$arrayLinea[7]</td></tr>";
|
||||||
|
|
||||||
|
//Guardar el ID de reserva encontrado
|
||||||
|
//file_put_contents("dato_temporal.txt",$arrayLinea[0]);
|
||||||
|
$id_encontrado = $arrayLinea[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Cierrro la tabla
|
||||||
|
echo "</table>";
|
||||||
|
//cerrar el archivo
|
||||||
|
fclose($archivo);
|
||||||
|
|
||||||
|
// Vacio los datos de POST
|
||||||
|
unset($_POST);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<br>
|
||||||
|
<form method="post">
|
||||||
|
<p>*ID de alquiler para borrar: </p><input type="text" name="Id_borrar" value="" id="Id_borrar" size="15" minlength="15" maxlength="15" placeholder="Id Alquiler" />
|
||||||
|
<input type="submit" name="borrar" value="Borrar reserva de alquiler">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Borrar reservas de alquiler
|
||||||
|
$listaReservas = "listado_reservas.txt";
|
||||||
|
$temporal = "temp.txt";
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['borrar']) && isset($_POST['Id_borrar'])) {
|
||||||
|
$borrado = $_POST['Id_borrar'];
|
||||||
|
|
||||||
|
$accesoLista = fopen($listaReservas, 'r');
|
||||||
|
$accesoTemporal = fopen($temporal, 'w');
|
||||||
|
|
||||||
|
// Buscar la reserva por ID
|
||||||
|
while (($linea = fgets($accesoLista)) !== false) {
|
||||||
|
// Obtener el ID de reserva de la línea actual
|
||||||
|
$arrayLinea = explode('/_/', $linea);
|
||||||
|
$id_reserva = $arrayLinea[0];
|
||||||
|
|
||||||
|
// Si el ID de reserva no coincide
|
||||||
|
if (trim($id_reserva) !== trim($borrado)) {
|
||||||
|
fwrite($accesoTemporal, $linea);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($accesoLista);
|
||||||
|
fclose($accesoTemporal);
|
||||||
|
|
||||||
|
// Borrar listado y renombrar el temporal
|
||||||
|
unlink($listaReservas);
|
||||||
|
rename($temporal, $listaReservas);
|
||||||
|
|
||||||
|
// Borrar ficha de reserva individual
|
||||||
|
$ficha_individual = "reservas/reserva_" . $borrado . ".txt";
|
||||||
|
if (file_exists($ficha_individual)) {
|
||||||
|
if (unlink("reservas/reserva_" . $borrado . ".txt") !== false) {
|
||||||
|
echo "<div><p>La ficha de reserva se ha borrado</p></div>";
|
||||||
|
} else {
|
||||||
|
echo "<div><p>La ficha de reserva no se ha encontrado</p></div>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Borrar DNI
|
||||||
|
$directorio = "dni_clientes";
|
||||||
|
// Obtener la lista de elemntos del directorio
|
||||||
|
$dni_clientes = scandir("dni_clientes");
|
||||||
|
|
||||||
|
// Iterar sobre la lista de archivos
|
||||||
|
foreach ($dni_clientes as $archivo_dni) {
|
||||||
|
// Verificar si es archivo o directorio
|
||||||
|
|
||||||
|
if (is_file('dni_clientes/' . $archivo_dni)) {
|
||||||
|
// Verificar si el nombre del archivo contiene la cadena determinada
|
||||||
|
if (strpos($archivo_dni, $borrado) !== false) {
|
||||||
|
// Borrar el archivo
|
||||||
|
unlink('dni_clientes/' . $archivo_dni);
|
||||||
|
echo "<div><p>Archivo borrado: $archivo_dni </p></div>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vacio los datos de POST
|
||||||
|
unset($_POST);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
<title>Busqueda de registros</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<form action="" method="POST">
|
||||||
|
<h2>Buqueda de registro</h2>
|
||||||
|
<input type="text" name="terminoBusqueda" id="terminoBusqueda">
|
||||||
|
<input type="submit" value="Buscar" required>
|
||||||
|
<br>
|
||||||
|
</form>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
include_once('./caracteres.php');
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$terminoBusqueda = $_POST['terminoBusqueda'];
|
||||||
|
|
||||||
|
$terminoBusqueda = eliminar_tildes(strtolower($terminoBusqueda));
|
||||||
|
|
||||||
|
$separador = "/_/";
|
||||||
|
$nombre_archivo = "listado_reservas.txt";
|
||||||
|
$archivo = fopen($nombre_archivo, 'r');
|
||||||
|
|
||||||
|
$registros = [];
|
||||||
|
while (($linea = fgets($archivo)) !== false) {
|
||||||
|
if (strpos(eliminar_tildes(strtolower($linea)), $terminoBusqueda) !== false) {
|
||||||
|
$registros[] = $linea;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($archivo);
|
||||||
|
|
||||||
|
echo "<table>
|
||||||
|
<tbody>
|
||||||
|
<thead>
|
||||||
|
<th>Id Usuario</th>
|
||||||
|
<th>Nombre</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Nº Telefono</th>
|
||||||
|
<th>Fecha de entrada</th>
|
||||||
|
<th>Fecha de salida</th>
|
||||||
|
<th>Fecha de registro</th>
|
||||||
|
<th>Nº de noches</th>
|
||||||
|
<th>Acciones</th>
|
||||||
|
</thead>";
|
||||||
|
foreach ($registros as $registro) {
|
||||||
|
$campos = explode("/_/", $registro);
|
||||||
|
echo "<tr>";
|
||||||
|
foreach ($campos as $campo) {
|
||||||
|
echo "<td> $campo </td>";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "<td><form action=\"./eliminar_registro.php\" method=\"POST\">
|
||||||
|
<input type=\"hidden\" name=\"idRegistro\" value=\"$campos[0]\">
|
||||||
|
<input type=\"submit\" value=\"Eliminar\">
|
||||||
|
</form></td>";
|
||||||
|
|
||||||
|
echo "</tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "</tbody>";
|
||||||
|
echo "</table>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form action="./eliminar_registro.php" method="POST">
|
||||||
|
<h2>Eliminacion de registro</h2>
|
||||||
|
<input type="text" name="idRegistro" id="idRegistro">
|
||||||
|
<input type="submit" value="Eliminar" required>
|
||||||
|
<br>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
// Eliminar tildes
|
||||||
|
function eliminar_tildes($cadena){
|
||||||
|
|
||||||
|
//Codificamos la cadena en formato utf8 en caso de que nos de errores
|
||||||
|
//$cadena = utf8_encode($cadena);
|
||||||
|
|
||||||
|
//Ahora reemplazamos las letras
|
||||||
|
$cadena = str_replace(
|
||||||
|
array('á', 'à', 'ä', 'â', 'ª', 'Á', 'À', 'Â', 'Ä'),
|
||||||
|
array('a', 'a', 'a', 'a', 'a', 'A', 'A', 'A', 'A'),
|
||||||
|
$cadena
|
||||||
|
);
|
||||||
|
|
||||||
|
$cadena = str_replace(
|
||||||
|
array('é', 'è', 'ë', 'ê', 'É', 'È', 'Ê', 'Ë'),
|
||||||
|
array('e', 'e', 'e', 'e', 'E', 'E', 'E', 'E'),
|
||||||
|
$cadena );
|
||||||
|
|
||||||
|
$cadena = str_replace(
|
||||||
|
array('í', 'ì', 'ï', 'î', 'Í', 'Ì', 'Ï', 'Î'),
|
||||||
|
array('i', 'i', 'i', 'i', 'I', 'I', 'I', 'I'),
|
||||||
|
$cadena );
|
||||||
|
|
||||||
|
$cadena = str_replace(
|
||||||
|
array('ó', 'ò', 'ö', 'ô', 'Ó', 'Ò', 'Ö', 'Ô'),
|
||||||
|
array('o', 'o', 'o', 'o', 'O', 'O', 'O', 'O'),
|
||||||
|
$cadena );
|
||||||
|
|
||||||
|
$cadena = str_replace(
|
||||||
|
array('ú', 'ù', 'ü', 'û', 'Ú', 'Ù', 'Û', 'Ü'),
|
||||||
|
array('u', 'u', 'u', 'u', 'U', 'U', 'U', 'U'),
|
||||||
|
$cadena );
|
||||||
|
|
||||||
|
$cadena = str_replace(
|
||||||
|
array('ñ', 'Ñ', 'ç', 'Ç'),
|
||||||
|
array('n', 'N', 'c', 'C'),
|
||||||
|
$cadena
|
||||||
|
);
|
||||||
|
|
||||||
|
return $cadena;
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['idRegistro']) && $_POST['idRegistro'] !== "") {
|
||||||
|
$idRegistro = $_POST['idRegistro'];
|
||||||
|
$separador = "/_/";
|
||||||
|
$nombre_archivo = "listado_reservas.txt";
|
||||||
|
|
||||||
|
$nombreArchivoReserva = "";
|
||||||
|
$nombreImagenDni = "";
|
||||||
|
|
||||||
|
$archivo = fopen($nombre_archivo, 'r');
|
||||||
|
$flagEncontrado = false;
|
||||||
|
$registros = [];
|
||||||
|
while (($linea = fgets($archivo)) !== false) {
|
||||||
|
if (strpos($linea, $idRegistro) === false) {
|
||||||
|
$registros[] = $linea;
|
||||||
|
} else {
|
||||||
|
$flagEncontrado = true;
|
||||||
|
$idRegistro = explode("/_/", $linea)[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($archivo);
|
||||||
|
|
||||||
|
if ($flagEncontrado) {
|
||||||
|
file_put_contents($nombre_archivo, $registros);
|
||||||
|
$directorio = "./reservas/";
|
||||||
|
$nombreArchivoReserva = $directorio . $idRegistro . '.txt';
|
||||||
|
if (deleteFile($nombreArchivoReserva)) {
|
||||||
|
echo "El archivo de registro se ha eliminado correctamente";
|
||||||
|
} else {
|
||||||
|
echo "Ocurrio un error al eliminar el archivo de registro";
|
||||||
|
}
|
||||||
|
|
||||||
|
$directorio = "./dni_clientes";
|
||||||
|
$patron = $directorio . "/*" . $idRegistro . "*";
|
||||||
|
$archivoDni = glob($patron);
|
||||||
|
if (count($archivoDni) > 0) {
|
||||||
|
deleteFile($archivoDni[0]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "No se ha encontrado el registro indicado";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "No se ha especificado id a eliminar";
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteFile($rutaArchivo)
|
||||||
|
{
|
||||||
|
if (file_exists($rutaArchivo)) {
|
||||||
|
if (unlink($rutaArchivo)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
@charset "UTF-8";
|
||||||
|
|
||||||
|
*{
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
list-style: none;
|
||||||
|
text-decoration: none;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
p{
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width:80%;
|
||||||
|
min-width:350px;
|
||||||
|
margin:auto;
|
||||||
|
background-color:#9d2236;
|
||||||
|
border:2px solid #000000;
|
||||||
|
color:white;
|
||||||
|
}
|
||||||
|
|
||||||
|
td,th {
|
||||||
|
text-align: center;
|
||||||
|
padding:3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
form,div {
|
||||||
|
width:80%;
|
||||||
|
min-width:350px;
|
||||||
|
background-color:#9d2236;
|
||||||
|
border:2px solid #000000;
|
||||||
|
padding:10px;
|
||||||
|
box-sizing:border-box;
|
||||||
|
color:white;
|
||||||
|
font-size:18px;
|
||||||
|
margin:auto;
|
||||||
|
margin-top: 20px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldset {
|
||||||
|
background-color:#9d2236;
|
||||||
|
border:2px solid #ffffff;
|
||||||
|
padding:10px;
|
||||||
|
box-sizing:border-box;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#flex {
|
||||||
|
display:flex;
|
||||||
|
justify-content:space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
margin-right:10px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
color:white;
|
||||||
|
background-color:#9d2236;
|
||||||
|
border: 2px solid white;
|
||||||
|
padding: 2px;
|
||||||
|
min-width: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
legend {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 20px;
|
||||||
|
margin:10px;
|
||||||
|
}
|
||||||
|
select,option {
|
||||||
|
color:white;
|
||||||
|
background-color:#9d2236;
|
||||||
|
border: 2px solid white;
|
||||||
|
padding: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
background-color:#9d2236;
|
||||||
|
width:100%;
|
||||||
|
height:200px;
|
||||||
|
color:white;
|
||||||
|
border: 2px solid white;
|
||||||
|
padding:10px;
|
||||||
|
box-sizing:border-box;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=submit], input[type=button],input[type=reset] {
|
||||||
|
background-color:#9d2236;
|
||||||
|
color:white;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: lighter;
|
||||||
|
margin-top: 10px;
|
||||||
|
padding: 5px;
|
||||||
|
border:2px solid #000000;
|
||||||
|
border-radius:5px;
|
||||||
|
box-shadow: 1px 2px 3px #fff;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Media query para pantallas de menos de 450 píxeles de ancho */
|
||||||
|
@media (max-width: 450px) {
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
#flex {
|
||||||
|
flex-wrap:wrap;
|
||||||
|
flex-direction: column-reverse;
|
||||||
|
}
|
||||||
|
textarea {
|
||||||
|
margin-left: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
display: block;
|
||||||
|
width: 80%;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,197 @@
|
|||||||
|
|
||||||
|
<!Doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
|
||||||
|
<title>Reservas hotel</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
<script>
|
||||||
|
// Función obtener() que realizará la captación de datos,los cálculos y la escritura del mensaje de info
|
||||||
|
|
||||||
|
function obtener() {
|
||||||
|
// Declaro y obtengo el valor de las variables
|
||||||
|
|
||||||
|
//Calcular periodo de la estancia (noches)
|
||||||
|
const inicio=document.getElementById("entradaH").valueAsNumber;
|
||||||
|
const fin=document.getElementById("salida").valueAsNumber;
|
||||||
|
const dif=fin - inicio;
|
||||||
|
const noches=Math.ceil(dif/(1000*60*60*24));
|
||||||
|
document.getElementById("noches").value=noches;
|
||||||
|
|
||||||
|
|
||||||
|
const habitacion=document.getElementById("habitacion").value;
|
||||||
|
const regimen=document.getElementById("regimen").value;
|
||||||
|
const spa=document.getElementById("spa").value;
|
||||||
|
const guia=document.getElementById("guia").value;
|
||||||
|
const nombreCliente=document.getElementById("nombre").value;
|
||||||
|
|
||||||
|
//Cáculo extras (spa y guia)
|
||||||
|
let spaT;
|
||||||
|
|
||||||
|
if (spa>5) {
|
||||||
|
spaT=spa*20;
|
||||||
|
}else {
|
||||||
|
spaT=spa*30;
|
||||||
|
}
|
||||||
|
|
||||||
|
let guiaT;
|
||||||
|
|
||||||
|
if(guia>7) {
|
||||||
|
guiaT=guia*40;
|
||||||
|
} else {
|
||||||
|
guiaT=guia*50;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tipo habitación
|
||||||
|
let hotel;
|
||||||
|
if (habitacion === "simple") {
|
||||||
|
hotel=50;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (habitacion === "doble") {
|
||||||
|
hotel=80;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (habitacion === "triple") {
|
||||||
|
hotel=120;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (habitacion === "suite") {
|
||||||
|
hotel=150;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Tipo de regimen
|
||||||
|
let comidas;
|
||||||
|
if (regimen === "desayuno") {
|
||||||
|
comidas=50;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regimen === "mediapension") {
|
||||||
|
comidas=80;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regimen === "pensioncompleta") {
|
||||||
|
comidas=120;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regimen === "todoincluido") {
|
||||||
|
comidas=150;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gastos estancia hotel+comidas
|
||||||
|
const hotelT=hotel*noches;
|
||||||
|
const regimenT=comidas*noches;
|
||||||
|
|
||||||
|
const estancia=hotelT+regimenT;
|
||||||
|
|
||||||
|
// Descuento por larga estancia
|
||||||
|
let estanciaDescuento;
|
||||||
|
if (noches <= 4) {
|
||||||
|
estanciaDescuento = estancia;
|
||||||
|
} else if (noches >= 5 && noches <= 10) {
|
||||||
|
estanciaDescuento = estancia * 0.85;
|
||||||
|
} else if (noches >= 11) {
|
||||||
|
estanciaDescuento = estancia * 0.75;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Envío el precio total sin IVA al formulario
|
||||||
|
document.getElementById("estancia").value=estanciaDescuento;
|
||||||
|
|
||||||
|
//Coste total con extras
|
||||||
|
const total=estanciaDescuento+spaT+guiaT;
|
||||||
|
const totalI=(total*1.21).toFixed(2);
|
||||||
|
// Envío el precio con IVA al formulario
|
||||||
|
document.getElementById("total").value=totalI;
|
||||||
|
// Precio de anulación
|
||||||
|
const precioAnulacion=(total*0.2).toFixed(2);
|
||||||
|
|
||||||
|
|
||||||
|
// Calcular días que faltan y fecha de regreso
|
||||||
|
const hoy=new Date().getTime();// Fecha de la reserva
|
||||||
|
const entrada=document.getElementById("entradaH").valueAsNumber;
|
||||||
|
const dif2=entrada-hoy;
|
||||||
|
const diasFaltan=dif2/(1000*60*60*24);// Días que faltan
|
||||||
|
|
||||||
|
const regresoF=new Date(fin);// Obtener en UTC
|
||||||
|
const regresoP=regresoF.toLocaleDateString();//Pasar fecha a formato corto dd/mm/xxxx
|
||||||
|
|
||||||
|
const anulacion=entrada-(3*24*60*60*1000);//Fecha de anulación
|
||||||
|
const anulacionF=new Date(anulacion);
|
||||||
|
const anulacionP=anulacionF.toLocaleDateString();
|
||||||
|
//Mensaje de información
|
||||||
|
const frase=
|
||||||
|
"Hola "+nombreCliente+"\n"
|
||||||
|
+"Faltan "+(Math.ceil(diasFaltan))+ " días "+"para tu viaje"+"\n"
|
||||||
|
+"Tu fecha de regreso es el "+regresoP+"\n"
|
||||||
|
+"Puedes anular tu reserva hasta el día "+anulacionP+"\n"
|
||||||
|
+"El coste de la anulación será de " +precioAnulacion+ " euros" ;
|
||||||
|
//Enviar mensaje al formulario
|
||||||
|
document.getElementById("info").value=frase;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="container">
|
||||||
|
<form action="recibe_formulario_hotel.php" method="post" enctype="multipart/form-data">
|
||||||
|
<h1>Reserve su habitación</h1>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Datos de la reserva</legend>
|
||||||
|
<p><label for="entradaH">Elige la fecha de entrada</label> <input type="date" id="entradaH" name="entrada">
|
||||||
|
<p><label for="salida">Elige la fecha de salida</label> <input type="date" id="salida" name="salida"></p>
|
||||||
|
<p><label for="habitacion">Seleccione el tipo de habitación</label>
|
||||||
|
<!-- Lista de selección -->
|
||||||
|
<select name="habitacion" id="habitacion">
|
||||||
|
<option value="simple">Simple</option>
|
||||||
|
<option value="doble">Doble</option>
|
||||||
|
<option value="triple">Triple</option>
|
||||||
|
<option value="suite">Suite</option>
|
||||||
|
</select></p>
|
||||||
|
<p><label for="regimen">Seleccione el regimen de alojamiento</label>
|
||||||
|
<!-- Lista de selección -->
|
||||||
|
<select name="regimen" id="regimen">
|
||||||
|
<option value="desayuno">Desayuno</option>
|
||||||
|
<option value="mediapension">Media pensión</option>
|
||||||
|
<option value="pensioncompleta">Pensión Completa</option>
|
||||||
|
<option value="todoincluido">Todo Incluido</option>
|
||||||
|
</select></p>
|
||||||
|
<p><label for="estancia">Coste de la estancia (Habitación + Comidas)</label> <input type="text" name="estancia" id="estancia"></p>
|
||||||
|
<p><label for="spa">Acceso al Spa, elija cuantos días</label> <input type="number" name="spa" id="spa" value="0" size="3"></p>
|
||||||
|
|
||||||
|
<p><label for="guia">Servicio de guía turístico, elija cuantos días </label><input type="number" name="guia" id="guia" value="0" size="3"></p>
|
||||||
|
<p><label for="total">Coste total con IVA incluido </label><input type="text" name="total" id="total" ></p>
|
||||||
|
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Datos personales</legend>
|
||||||
|
<p><label for="nombre">*Nombre: </label><input type="text" name="nombre" id="nombre" placeholder="Nombre y Apellidos" required></p>
|
||||||
|
<p><label for="mail">*Correo electrónico: </label><input type="email" name="email" id="mail" placeholder="Escribe tu correo" required></p>
|
||||||
|
<p><label for="telefono">*Teléfono:</label> <input type="tel" id="telefono" name="telefono" required></p>
|
||||||
|
<p>Check-in online (opcional):</p>
|
||||||
|
<p><label for="dni">DNI:</label> <input type="text" id="dni" name="dni" ></p>
|
||||||
|
<p><label for="adjuntos">Adjunte fotocopia de DNI </label><input type="file" name="dnifile" id="dnifile" accept=".pdf,.jpg" ></p>
|
||||||
|
<div id="flex">
|
||||||
|
<div>
|
||||||
|
<input type="button" value="Calcular coste total" onclick="obtener()">
|
||||||
|
<br><input type="reset" name="limpiar" value="Borrar" />
|
||||||
|
<br><input type="submit" value="Enviar la reserva" >
|
||||||
|
<input id="noches" name="noches" type="hidden" value="noches">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<textarea name="info" id="info" >Información de su viaje</textarea>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
<title>Reservas hotel</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$entrada = $_POST['entrada'];
|
||||||
|
$salida = $_POST['salida'];
|
||||||
|
$habitacion = $_POST['habitacion'];
|
||||||
|
$regimen = $_POST['regimen'];
|
||||||
|
$estancia = $_POST['estancia'];
|
||||||
|
$spa = $_POST['spa'];
|
||||||
|
$guia = $_POST['guia'];
|
||||||
|
$total = $_POST['total'];
|
||||||
|
$nombre = $_POST['nombre'];
|
||||||
|
$email = $_POST['email'];
|
||||||
|
$telefono = $_POST['telefono'];
|
||||||
|
$dni = $_POST['dni'];
|
||||||
|
$noches = $_POST['noches'];
|
||||||
|
$info = $_POST['info'];
|
||||||
|
$idReserva = time() . '_' . mt_rand(0000, 9999);
|
||||||
|
$fechaReserva = date("d-m-Y H:i:s");
|
||||||
|
$separador = '/_/';
|
||||||
|
$fichaReserva = "Id reserva: $idReserva \r\n";
|
||||||
|
$fichaReserva .= "Fecha de reserva: $fechaReserva \r\n";
|
||||||
|
$fichaReserva .= "Fecha de entrada: $entrada \r\n";
|
||||||
|
$fichaReserva .= "Fecha de salida: $salida \r\n";
|
||||||
|
$fichaReserva .= "Tipo de habitación: $habitacion \r\n";
|
||||||
|
$fichaReserva .= "Regimen de alojamiento: $regimen \r\n";
|
||||||
|
$fichaReserva .= "Días Spa: $spa \r\n";
|
||||||
|
$fichaReserva .= "Días Guia: $guia \r\n";
|
||||||
|
$fichaReserva .= "Duración estancia: $noches \r\n";
|
||||||
|
$fichaReserva .= "Coste Total: $total \r\n";
|
||||||
|
$fichaReserva .= "Nombre: $nombre \r\n";
|
||||||
|
$fichaReserva .= "Correo electrónico: $email \r\n";
|
||||||
|
$fichaReserva .= "Teléfono: $telefono \r\n";
|
||||||
|
$fichaReserva .= "DNI: $dni \r\n";
|
||||||
|
$registroReserva = implode($separador, [$idReserva, $nombre, $email, $telefono, $entrada, $salida, $fechaReserva, $noches]) . "\r\n";
|
||||||
|
|
||||||
|
// Enviar un mensaje de correo al hotel con los detalles de la reserva y con su identificador
|
||||||
|
$destinatario = "appasin04@gmail.com";
|
||||||
|
$asunto = "Informacion de reserva - $idReserva";
|
||||||
|
$headers = 'Reply-To: appasin04@gmail.com' . "\r\n";
|
||||||
|
$headers .= 'Bcc: ' . $email . "\r\n";
|
||||||
|
if (mail($destinatario, $asunto, $fichaReserva, $headers)) {
|
||||||
|
|
||||||
|
// Crear la ficha de reserva con nombre(reserva_1708677602_7461.txt) y con esta estructura:
|
||||||
|
$nombre_archivo = "reservas/" . $idReserva . ".txt";
|
||||||
|
guardarFichaReserva($fichaReserva, $nombre_archivo);
|
||||||
|
|
||||||
|
// Añadir al listado_reservas.txt un línea de reserva:
|
||||||
|
$nombre_archivo = "listado_reservas.txt";
|
||||||
|
guardaListaDatos($registroReserva, $nombre_archivo);
|
||||||
|
|
||||||
|
// Mostrar el mensaje en pantalla al cliente con la siguiente estructura:
|
||||||
|
echo "Reserva confirmada ! <br> <br>";
|
||||||
|
echo nl2br($fichaReserva);
|
||||||
|
echo "<br>";
|
||||||
|
// Subir el DNI del cliente si cumple con con las siguientes características , tipo de archivo (jpg y pdf) y tamaño máximo 2mb.
|
||||||
|
if (isset($_FILES['dnifile']) && $_FILES['dnifile']['error'] === UPLOAD_ERR_OK) {
|
||||||
|
$nombreArchivo = implode("_", [$dni, $idReserva, $_FILES['dnifile']['name']]);
|
||||||
|
if (subirArchivo($_FILES['dnifile'], 2, ['image/jpeg', 'image/jpg', 'application/pdf'], 'dni_clientes/', $nombreArchivo)) {
|
||||||
|
echo "<p>Su DNI ha sido recibido</p>";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "<p>No se ha enviado documento identificado con la reserva</p>";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "<p>No se ha podido realizar la reserva correctamente!!!</p>";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "No se han recibido datos del formulario";
|
||||||
|
}
|
||||||
|
// ************************************************************
|
||||||
|
function guardarFichaReserva($fichaReserva, $nombre_archivo)
|
||||||
|
{
|
||||||
|
$archivo = fopen($nombre_archivo, 'w');
|
||||||
|
fwrite($archivo, $fichaReserva);
|
||||||
|
fclose($archivo);
|
||||||
|
}
|
||||||
|
function guardaListaDatos($registroReserva, $nombre_archivo)
|
||||||
|
{
|
||||||
|
$archivo = fopen($nombre_archivo, 'a');
|
||||||
|
fwrite($archivo, $registroReserva);
|
||||||
|
fclose($archivo);
|
||||||
|
}
|
||||||
|
function subirArchivo($archivo, $tamanoMaximo, $tiposPermitidos, $carpetaDestino, $nombreArchivo)
|
||||||
|
{
|
||||||
|
$nombre = $nombreArchivo;
|
||||||
|
$tipo = $archivo['type'];
|
||||||
|
$tamano = $archivo['size'];
|
||||||
|
$tmp_name = $archivo['tmp_name'];
|
||||||
|
|
||||||
|
if (!in_array($tipo, $tiposPermitidos)) {
|
||||||
|
echo "<p>Error al enviar el fichero al servidor</p>";
|
||||||
|
echo "<p>Has intentado subir un archivo no permitido</p>";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($tamano > ($tamanoMaximo * 1024 * 1024)) {
|
||||||
|
echo "<p>Error al enviar el fichero al servidor</p>";
|
||||||
|
echo "<p>El tamaño excede de $tamanoMaximo Mbytes </p>";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (move_uploaded_file($tmp_name, $carpetaDestino . $nombre)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
echo "<p>Error al enviar el fichero al servidor</p>";
|
||||||
|
echo "<p>Error de servidor en el almacenamiento del fichero</p>";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
<!Doctype html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
|
||||||
|
<title>Reservas hotel</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="container">
|
||||||
|
<?php
|
||||||
|
// Verificar si se recibieron los datos del formulario
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
// Obtener los datos del formulario
|
||||||
|
$entrada = $_POST["entrada"];
|
||||||
|
$salida = $_POST["salida"];
|
||||||
|
$habitacion = $_POST["habitacion"];
|
||||||
|
$regimen = $_POST["regimen"];
|
||||||
|
$spa = $_POST["spa"];
|
||||||
|
$guia = $_POST["guia"];
|
||||||
|
$noches = $_POST["noches"];
|
||||||
|
$coste = $_POST["total"];
|
||||||
|
$nombre = $_POST["nombre"];
|
||||||
|
$email = $_POST["email"];
|
||||||
|
$telefono = $_POST["telefono"];
|
||||||
|
$dni = $_POST["dni"];
|
||||||
|
$info = $_POST["info"];
|
||||||
|
//var_dump($_POST);
|
||||||
|
echo "<br>";
|
||||||
|
// Identificador reserva
|
||||||
|
$id_reserva = time() . "_" . rand(1000, 9999);
|
||||||
|
// Fecha de la reserva
|
||||||
|
$fecha_reserva = date('d-m-Y H:i:s', time());
|
||||||
|
// Formatear los datos para escribir en el archivo
|
||||||
|
$datosReserva = "Id reserva: " . $id_reserva . "\n" .
|
||||||
|
"Fecha de reserva: " . $fecha_reserva . "\n" .
|
||||||
|
"Fecha de entrada: " . $entrada . "\n" .
|
||||||
|
"Fecha de salida: " . $salida . "\n" .
|
||||||
|
"Tipo de habitación: " . $habitacion . "\n" .
|
||||||
|
"Regimen de alojamiento: " . $regimen . "\n" .
|
||||||
|
"Días Spa: " . $spa . "\n" .
|
||||||
|
"Días Guia: " . $guia . "\n" .
|
||||||
|
"Duración estancia: " . $noches . "\n" .
|
||||||
|
"Coste Total: " . $coste . "\n" .
|
||||||
|
"Nombre: " . $nombre . "\n" .
|
||||||
|
"Correo electrónico: " . $email . "\n" .
|
||||||
|
"Teléfono: " . $telefono . "\n" .
|
||||||
|
"DNI: " . $dni . "\n\n";
|
||||||
|
// Mensaje correo para el hotel
|
||||||
|
// Correo electrónico de destino
|
||||||
|
$destinatario = "appasinxx@gmail.com";
|
||||||
|
// Asunto del correo electrónico
|
||||||
|
$asunto = "Hay una nueva reserva: $id_reserva ";
|
||||||
|
$headers = "Reply-To: " . $email . "\r\n";
|
||||||
|
// Envía el correo electrónico
|
||||||
|
//mail($destinatario, $asunto, $datosReserva,$headers);
|
||||||
|
|
||||||
|
// Ruta del archivo de reserva (dentro del directorio "reservas")
|
||||||
|
$archivoReserva = "reservas/reserva_" . $id_reserva . ".txt";
|
||||||
|
// Crear la ficha de reserva
|
||||||
|
if (file_put_contents($archivoReserva, $datosReserva) !== false) {
|
||||||
|
echo "<p>Reserva confirmada !</p>";
|
||||||
|
echo "<br>";
|
||||||
|
} else {
|
||||||
|
echo "<p>Error al registrar la reserva!</p>";
|
||||||
|
echo "<br>";
|
||||||
|
}
|
||||||
|
// Escribir en listado de reservas
|
||||||
|
$lista_reservas = "listado_reservas.txt";
|
||||||
|
$datos_reserva = $id_reserva . "/_/" . $nombre . "/_/" . $email . "/_/" . $telefono . "/_/" . $entrada . "/_/" . $salida . "/_/" . $fecha_reserva . "/_/" . $noches . "\r\n";
|
||||||
|
file_put_contents($lista_reservas, $datos_reserva, FILE_APPEND | LOCK_EX);
|
||||||
|
// Mensaje cliente confirmación de opciones
|
||||||
|
echo nl2br($info);
|
||||||
|
echo "<br>";
|
||||||
|
echo "<br>";
|
||||||
|
echo "<p>Esta es la información detallada de tu reserva:</p>";
|
||||||
|
echo nl2br($datosReserva);
|
||||||
|
// Recibir DNI cliente
|
||||||
|
// Directorio donde se guardarán los archivos subidos
|
||||||
|
$directorio_subida = "dni_clientes/";
|
||||||
|
// Nombre del archivo y ruta de destino
|
||||||
|
$nombre_archivo = $_FILES["dnifile"]["name"];
|
||||||
|
$nombre_archivo_final = $dni . '_' . $id_reserva . '_' . $nombre_archivo;
|
||||||
|
$ruta_archivo = $directorio_subida . $nombre_archivo_final;
|
||||||
|
// Tamaño máximo permitido (2MB)
|
||||||
|
$tamano_maximo = 2 * 1024 * 1024;
|
||||||
|
// Obtiene la extensión del archivo en minúsculas
|
||||||
|
$extension_archivo = strtolower(pathinfo($_FILES["dnifile"]["name"], PATHINFO_EXTENSION));
|
||||||
|
// Array de extensiones permitidas
|
||||||
|
$extensiones_permitidas = array("jpg", "jpeg", "pdf");
|
||||||
|
// Verifica si el archivo es una extensión permitida y no excede el tamaño máximo
|
||||||
|
if (in_array($extension_archivo, $extensiones_permitidas) && $_FILES["dnifile"]["size"] <= $tamano_maximo) {
|
||||||
|
// Intenta mover el archivo al directorio de destino
|
||||||
|
if (move_uploaded_file($_FILES["dnifile"]["tmp_name"], $ruta_archivo)) {
|
||||||
|
echo "Su DNI ha sido recibido.";
|
||||||
|
} else {
|
||||||
|
echo "Lo siento, hubo un error al subir su DNI.";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "Lo siento, solo se permiten archivos en formato JPG o PDF con un tamaño máximo de 2MB.";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Si no se recibieron datos por POST, mostrar un mensaje de error
|
||||||
|
echo "Error: No se recibieron datos del formulario.";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
123
Practicas/Practicas_PHP/ejercicios/examen/Examen_UF1844_xx.html
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Examen_UF1844</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="estilos.css">
|
||||||
|
<script>
|
||||||
|
function obtener() {
|
||||||
|
var dias = document.getElementById("dias").value;
|
||||||
|
var tipo = document.getElementById("tipo").value;
|
||||||
|
|
||||||
|
var tipoP, riesgo;
|
||||||
|
|
||||||
|
if (tipo == "basico") {
|
||||||
|
tipoP = 45;
|
||||||
|
riesgo = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tipo == "gamamedia") {
|
||||||
|
tipoP = 65;
|
||||||
|
riesgo = 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tipo == "lujo") {
|
||||||
|
tipoP = 85;
|
||||||
|
riesgo = 35;
|
||||||
|
}
|
||||||
|
|
||||||
|
var vehiculo;
|
||||||
|
if (document.getElementById("riesgo").checked) {
|
||||||
|
vehiculo = dias * (tipoP + riesgo);
|
||||||
|
} else {
|
||||||
|
vehiculo = dias * (tipoP + 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
var silla, gps;
|
||||||
|
if (document.getElementById("silla").checked) {
|
||||||
|
silla = 15;
|
||||||
|
} else {
|
||||||
|
silla = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.getElementById("gps").checked) {
|
||||||
|
gps = 5;
|
||||||
|
} else {
|
||||||
|
gps = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var extras = (silla + gps) * dias;
|
||||||
|
|
||||||
|
var total = vehiculo + extras;
|
||||||
|
var totalI = total * 1.21;
|
||||||
|
|
||||||
|
var precioMenor;
|
||||||
|
if (document.getElementById("menor").checked) {
|
||||||
|
precioMenor = totalI * 0.3;
|
||||||
|
} else {
|
||||||
|
precioMenor = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalF = (totalI + precioMenor).toFixed(2);
|
||||||
|
document.getElementById("total").value = totalF;
|
||||||
|
document.getElementById("recargo").value = precioMenor;
|
||||||
|
}
|
||||||
|
|
||||||
|
function faltan() {
|
||||||
|
var dias = document.getElementById("dias").value;
|
||||||
|
var inicio = new Date(document.getElementById("fecha_inicio").value).getTime();
|
||||||
|
var entrega = inicio + (dias * 24 * 60 * 60 * 1000);
|
||||||
|
var entregaF = new Date(entrega);
|
||||||
|
var entregaP = entregaF.toLocaleDateString();
|
||||||
|
|
||||||
|
|
||||||
|
// Calcular días hasta inicio de alquiler
|
||||||
|
var diferenciaMilisegundos = inicio - new Date().getTime();
|
||||||
|
var diasF = Math.ceil(diferenciaMilisegundos / (1000 * 60 * 60 * 24));
|
||||||
|
|
||||||
|
var frase = "Faltan " + diasF + " días para tu alquiler\nTu fecha de entrega del vehículo es el " + entregaP + "\n";
|
||||||
|
|
||||||
|
document.getElementById("info").value = frase;
|
||||||
|
document.getElementById("entrega").value = entregaP;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<form action="recibeformulario_coches.php" method="post" enctype="multipart/form-data">
|
||||||
|
<h1>Alquiler de vehículo</h1>
|
||||||
|
<p>Introduzca número de dias de alquiler
|
||||||
|
<input type="number" name="dias" id="dias" size="3" value="0" required>
|
||||||
|
<p>Elige la fecha de inicio del alquiler <input type="date" name="fecha_inicio" id="fecha_inicio" required></p>
|
||||||
|
<p>Seleccione el tipo de vehículo
|
||||||
|
<!-- Lista de selección -->
|
||||||
|
<select name="tipo" id="tipo">
|
||||||
|
<option value="basico">Básico 45 Euros/día</option>
|
||||||
|
<option value="gamamedia">Gama media 65 Euros/día</option>
|
||||||
|
<option value="lujo">Lujo 85 Euros/día</option>
|
||||||
|
</select></p>
|
||||||
|
<h2>Elementos opcionales</h2>
|
||||||
|
<p>Silla Infantil * 15 Euros por día de alquiler<input type="checkbox" name="silla" id="silla" value="silla"></p>
|
||||||
|
<p>GPS * 5 Euros por día de alquiler <input type="checkbox" name="gps" id="gps" value="gps"></p>
|
||||||
|
<h2>Seguro</h2>
|
||||||
|
<p>** El seguro a terceros es obligatorio y tiene un coste de 10 Euros/día sin IVA</p>
|
||||||
|
<p>Seguro a todo riesgo <input type="checkbox" name="riesgo" id="riesgo" value="riesgo"></p>
|
||||||
|
<p>Conductor menor de 30 años <input type="checkbox" name="menor" id="menor" value="menor"></p>
|
||||||
|
<p>Coste total <input type="text" name="total" id="total" ></p>
|
||||||
|
|
||||||
|
<input type="button" value="Calcular coste total" onclick="obtener();faltan()">
|
||||||
|
<p>*Nombre: <input type="text" name="nombre" id="nombre" placeholder="Nombre y Apellidos" required></p>
|
||||||
|
<p>*Correo electrónico: <input type="email" name="email" placeholder="Escribe tu correo" required></p>
|
||||||
|
<p>*Teléfono: <input type="tel" name="telefono" required></p>
|
||||||
|
<p>Check-in online (opcional):</p>
|
||||||
|
<p>Adjunte fotocopia de DNI <input type="file" name="dni_archivo" id="dni_archivo" accept=".pdf,.jpg" ></p>
|
||||||
|
<p><label for="dni">DNI:</label> <input type="text" id="dni" name="dni" ></p>
|
||||||
|
<textarea rows="2" cols="40" name="info" id="info"></textarea>
|
||||||
|
<input type="hidden" name="entrega" id="entrega" >
|
||||||
|
<input type="hidden" name="recargo" id="recargo" >
|
||||||
|
<input type="reset" name="limpiar" value="Borrar" />
|
||||||
|
<br><input type="submit" value="Enviar la reserva" >
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 255 KiB |
|
After Width: | Height: | Size: 112 KiB |