-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidacionPagos.php
More file actions
58 lines (50 loc) · 1.97 KB
/
Copy pathvalidacionPagos.php
File metadata and controls
58 lines (50 loc) · 1.97 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
55
56
57
58
<?php
session_start();
require_once("gestionBD.php");
require_once("gestionarPagos.php");
if (isset($_SESSION["formularioPagos"])) {
$nuevoPago["fecha"] =$_REQUEST["fecha"];
$nuevoPago["descripcion"]= $_REQUEST["descripcion"];
$nuevoPago["idAtleta"]=$_REQUEST["idAtleta"];
$_SESSION["formularioPagos"] = $nuevoPago;
}
else
Header("Location: introducirPago.php");
// Validamos el formulario en servidor
$conexion = crearConexionBD();
$perfil = $_SESSION["Perfil"];
$errores = validarPago($conexion, $nuevoPago);
$nuevoPago["ruta"] = "ficheros/pagos/".$_FILES["file"]["name"];
if (count($errores)>0) {
$_SESSION["errores"] = $errores;
Header('Location: insertar.php');
} else if(alta_Pagos($conexion, $nuevoPago)){
$correcto = "Se ha realizado";
$_SESSION["correcto"] = $correcto;
Header('Location: insertar.php?unset=true');
} else {
$errores[] = "Actualmente no se puede acceder a la base de datos, disculpe las molestias";
$_SESSION["errores"] = $errores;
Header('Location: insertar.php');
}
cerrarConexionBD($conexion);
function validarPago($conexion, $nuevoPago){
$errores=array();
if($nuevoPago["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}/",$nuevoPago["fecha"]))
$errores[] = "<p>La fecha debe cumplir su formato</p>";
if ($nuevoPago["descripcion"] == "")
$errores[] = "<p> La descripción no puede estar vacía</p>";
else if(strlen($nuevoPago["descripcion"]) > 560){
$errores[] = "<p> La descripción es demasiado larga</p>";
}
if(!($_FILES["file"]["type"] == 'application/pdf')){
$errores[] = "<p> El formato del archivo debe ser <b> .pdf </b></p>";
}else{
move_uploaded_file($_FILES["file"]["tmp_name"], "ficheros/pagos/".$_FILES["file"]["name"]);
$nuevoPago["ruta"] = "ficheros/pagos/".$_FILES["file"]["name"];
}
return $errores;
}
?>