-
Notifications
You must be signed in to change notification settings - Fork 0
/
addevento.php
57 lines (45 loc) · 2.17 KB
/
addevento.php
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
<?php
require_once "/usr/local/lib/php/vendor/autoload.php";
include("bd.php");
$loader = new \Twig\Loader\FilesystemLoader('templates');
$twig = new \Twig\Environment($loader);
session_start();
$conexion = new BDGestion();
$identificado = false;
if(isset($_SESSION['identificado'])) {
$identificado = true;
}
if($identificado) {
$usuario = $conexion->cargarUsuario($_SESSION['nameUsuario']);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if(isset($_POST['name']) && isset($_POST['lugar']) && isset($_POST['fecha']) && isset($_POST['etiquetas']) && isset($_POST['contenido'])) {
// Saneamos las entradas
$nombre = htmlspecialchars($_POST['name']);
$lugar = htmlspecialchars($_POST['lugar']);
$fecha = preg_replace("([^0-9/])", "", $_POST['fecha']);
$etiquetasEntrada = htmlspecialchars($_POST['etiquetas']);
$etiquetas = explode(',', $etiquetasEntrada);
$contenido = htmlspecialchars($_POST['contenido']);
if(isset($_FILES['imagen'])){
$file_name = $_FILES['imagen']['name'];
$file_size = $_FILES['imagen']['size'];
$file_tmp = $_FILES['imagen']['tmp_name'];
$file_type = $_FILES['imagen']['type'];
$file_ext = strtolower(end(explode('.',$_FILES['imagen']['name'])));
$extensions= array("jpeg","jpg","png");
if(in_array($file_ext,$extensions) === true && $file_size < 2097152){
move_uploaded_file($file_tmp, 'img/' . $file_name);
$idEvento = $conexion->newEvento($nombre, $lugar, $fecha, $contenido, $file_name);
$conexion->addEtiquetas($idEvento, $etiquetas);
if($idEvento !== -1) {
header("refresh:2;url=evento.php?ev=" . $idEvento);
echo 'Evento creado. Redireccionando...';
}
}
}
exit();
}
}
echo $twig->render('addevento.html', ['identificado' => $identificado, 'usuario' => $usuario]);
?>