-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidacionReuniones.php
More file actions
54 lines (45 loc) · 1.76 KB
/
Copy pathvalidacionReuniones.php
File metadata and controls
54 lines (45 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
session_start();
require_once("gestionBD.php");
require_once("gestionarIntroducirReuniones.php");
if (isset($_SESSION["formulario"])) {
$nuevaReunion["fecha"] = $_REQUEST["fecha"];
$nuevaReunion["duracion"] = $_REQUEST["duracion"];
$nuevaReunion["lugar"] = $_REQUEST["lugar"];
$_SESSION["formulario"] = $nuevaReunion;
} else
Header("Location: introducirReunion.php");
// Validamos el formulario en servidor
$conexion = crearConexionBD();
$errores = validarReunion($conexion, $nuevaReunion);
if (count($errores) > 0) {
$_SESSION["errores"] = $errores;
Header('Location: introducirReunion.php');
} else if (altaReunion($conexion, $nuevaReunion)) {
unset($_SESSION["formulario"]);
$correcto = "Se ha realizado con éxito";
$_SESSION["correcto"] = $correcto;
Header('Location: introducirReunion.php');
} else {
$errores[] = "No se puede acceder a la base de datos actualmente, disculpe las molestias.";
$_SESSION["errores"] = $errores;
Header('Location: introducirReunion.php');
}
cerrarConexionBD($conexion);
function validarReunion($conexion, $nuevaReunion)
{
$errores = array();
if($nuevaReunion["fecha"] == "0000-00-00"){
$errores[] = "<p>La fecha no puede estar vacía</p>";
}else if (!preg_match("/[0-9]{4}\-[0-9]{2}\-[0-9]{2}/",$nuevaReunion["fecha"])){
$errores[] = "<p>La fecha debe cumplir su formato</p>";
}
if (!preg_match("/[0-9]{2}:[0-5][0-9]/",$nuevaReunion["duracion"]))
$errores[] = "<p>La duración debe rellenarse con el formato adecuado hh:mm</p>";
if ($nuevaReunion["lugar"] == "")
$errores[] = "<p> El lugar de la reunion no puede estar vacío</p>";
else if(strlen($nuevaReunion["lugar"]) >80){
$errores[] = "<p> El lugar de la reunion es demasiado largo</p>";
}
return $errores;
}