Add files via upload

This commit is contained in:
Fernando Méndez
2021-06-03 11:26:35 +02:00
committed by GitHub
parent d56c04f076
commit 8a65fdb574
9 changed files with 224 additions and 166 deletions

View File

@ -1,12 +1,17 @@
<?php
require_once __DIR__.'/includes/config.php';
require_once('../assets/php/config.php');
require_once('./Evento.php');
use es\ucm\fdi\aw\eventos\Evento;
use es\ucm\fdi\aw\Aplicacion as App;
use es\ucm\fdi\aw\http\ContentTypeNoSoportadoException;
use es\ucm\fdi\aw\http\ParametroNoValidoException;
// Procesamos la cabecera Content-Type
$contentType= $_SERVER['CONTENT_TYPE'] ?? 'application/json';
$contentType = strtolower(str_replace(' ', '', $contentType));
// Verificamos corresponde con uno de los tipos soportados
$acceptedContentTypes = array('application/json;charset=utf-8', 'application/json');
$found = false;
@ -18,7 +23,7 @@ foreach ($acceptedContentTypes as $acceptedContentType) {
}
if (!$found) {
// throw new ContentTypeNoSoportadoException('Este servicio REST sólo soporta el content-type application/json');
throw new ContentTypeNoSoportadoException('Este servicio REST sólo soporta el content-type application/json');
}
$result = null;
@ -39,8 +44,7 @@ switch($_SERVER['REQUEST_METHOD']) {
// Comprobamos si es una lista de eventos entre dos fechas -> eventos.php?start=XXXXX&end=YYYYY
$start = filter_input(INPUT_GET, 'start', FILTER_VALIDATE_REGEXP, array("options" => array("regexp"=>"/\d{4}-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3[0-1]))/")));
$end = filter_input(INPUT_GET, 'end', FILTER_VALIDATE_REGEXP, array("options" => array("default" => null, "regexp"=>"/\d{4}-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3[0-1]))/")));
if ($start) {
if ($start) {
$startDateTime = $start . ' 00:00:00';
$endDateTime = $end;
if ($end) {
@ -48,14 +52,14 @@ switch($_SERVER['REQUEST_METHOD']) {
}
$result = Evento::buscaEntreFechas(1, $startDateTime, $endDateTime);
} else {
// Comprobamos si es una lista de eventos completa
$result = Evento::buscaTodosEventos(1); // HACK: normalmente debería de ser App::getSingleton()->idUsuario();
}
}
// Generamos un array de eventos en formato JSON
$json = json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
http_response_code(200); // 200 OK
header('Content-Type: application/json; charset=utf-8');
header('Content-Length: ' . mb_strlen($json));
@ -66,17 +70,18 @@ switch($_SERVER['REQUEST_METHOD']) {
case 'POST':
// 1. Leemos el contenido que nos envían
$entityBody = file_get_contents('php://input');
// 2. Verificamos que nos envían un objeto
$dictionary = json_decode($entityBody);
if (!is_object($dictionary)) {
//throw new ParametroNoValidoException('El cuerpo de la petición no es valido');
throw new ParametroNoValidoException('El cuerpo de la petición no es valido');
}
// 3. Reprocesamos el cuerpo de la petición como un array PHP
$dictionary = json_decode($entityBody, true);
$dictionary['userId'] = 1;// HACK: normalmente debería de ser App::getSingleton()->idUsuario();
$e = Evento::creaDesdeDicionario($dictionary);
error_log("hmmm");
// 4. Guardamos el evento en BD
$result = Evento::guardaOActualiza($e);
@ -91,7 +96,6 @@ switch($_SERVER['REQUEST_METHOD']) {
break;
case 'PUT':
error_log("PUT");
// 1. Comprobamos si es una consulta de un evento concreto -> eventos.php?idEvento=XXXXX
$idEvento = filter_input(INPUT_GET, 'idEvento', FILTER_VALIDATE_INT);
// 2. Leemos el contenido que nos envían
@ -99,10 +103,9 @@ switch($_SERVER['REQUEST_METHOD']) {
// 3. Verificamos que nos envían un objeto
$dictionary = json_decode($entityBody);
if (!is_object($dictionary)) {
//throw new ParametroNoValidoException('El cuerpo de la petición no es valido');
throw new ParametroNoValidoException('El cuerpo de la petición no es valido');
}
// 4. Reprocesamos el cuerpo de la petición como un array PHP
$dictionary = json_decode($entityBody, true);
$e = Evento::buscaPorId($idEvento);
@ -129,6 +132,8 @@ switch($_SERVER['REQUEST_METHOD']) {
header('Content-Length: 0');
break;
default:
//throw new MetodoNoSoportadoException($_SERVER['REQUEST_METHOD']. ' no está soportado');
throw new MetodoNoSoportadoException($_SERVER['REQUEST_METHOD']. ' no está soportado');
break;
}
}

View File

@ -0,0 +1,65 @@
<?php
//General Config File:
require_once('../../assets/php/config.php');
$prefix ="../../";
include_once('formHall.php');
include_once('formSession.php');
if(isset($_POST['new_hall'])){
$data = array("option" => "new_hall","number" => $_POST["number"],"cols" => $_POST["cols"],"rows" => $_POST["rows"], "cinema" => $_SESSION["cinema"], "seats" => 0);
//Check what checkboxs are seats or not
for($i = 1;$i<=$data["rows"];$i++){
for($j=1; $j<=$data["cols"]; $j++){
if(!empty($_POST['checkbox'.$i.$j.''])){
$data[$i][$j] = $_POST['checkbox'.$i.$j.''];
$data["seats"]++;
} else $data[$i][$j] = "-1";
}
}
FormHall::processesForm($data);
}
if(isset($_POST['edit_hall'])){
$data = array("option" => "edit_hall","number" => $_POST["number"],"cols" => $_POST["cols"],"rows" => $_POST["rows"], "cinema" => $_SESSION["cinema"],"seats" => 0);
//Check what checkboxs are seats or not
for($i = 1;$i<=$data["rows"];$i++){
for($j=1; $j<=$data["cols"]; $j++){
if(!empty($_POST['checkbox'.$i.$j.''])){
$data[$i][$j] = $_POST['checkbox'.$i.$j.''];
$data["seats"]++;
} else $data[$i][$j] = "-1";
}
}
FormHall::processesForm($data);
}
if(isset($_POST['delete_hall'])){
$data = array("option" => "delete_hall","number" => $_POST["number"], "cinema" => $_SESSION["cinema"]);
FormHall::processesForm($data);
}
if(isset($_POST['new_session'])){
$data = array("option" => "new_session","film" => $_POST["film"],"hall" => $_POST["hall"],"date" => $_POST["date"],"start" => $_POST["start"]
,"price" => $_POST["price"],"format" => $_POST["format"],"repeat" => $_POST["repeat"], "cinema" => $_SESSION["cinema"]);
FormSession::processesForm($data);
}
if(isset($_POST['edit_session'])){
$data = array("option" => "edit_session","film" => $_POST["film"],"hall" => $_POST["hall"],"date" => $_POST["date"],"start" => $_POST["start"]
,"price" => $_POST["price"],"format" => $_POST["format"],"repeat" => $_POST["repeat"], "cinema" => $_SESSION["cinema"]
, "origin_hall"=>$_SESSION["or_hall"],"origin_date"=> $_SESSION["or_date"],"origin_start"=> $_SESSION["or_start"]);
$_SESSION["or_hall"] = "";
$_SESSION["or_date"] = "";
$_SESSION["or_start"] = "";
FormSession::processesForm($data);
}
if(isset($_POST['delete_session'])){
$data = array("option" => "delete_session","cinema" => $_SESSION["cinema"], "hall"=> $_POST["origin_hall"]
,"date"=> $_POST["origin_date"],"start"=> $_POST["origin_start"]);
FormSession::processesForm($data);
}
?>

View File

@ -1,108 +1,107 @@
$(document).ready(function() {
var calendar = $('#calendar').fullCalendar({
editable:true,
header:{
left:'prev,next today',
center:'title',
right:'month,agendaWeek,agendaDay'
},
events: 'eventos.php',
selectable:true,
selectHelper:true,
timeFormat: 'H:mm',
select: function(start, end, allDay)
{
var title = prompt("Enter Event Title");
if(title)
var calendar = $('#calendar').fullCalendar({
editable:true,
header:{
left:'prev,next today',
center:'title',
right:''
},
events: 'eventos.php',
selectable:true,
selectHelper:true,
select: function(start, end, allDay)
{
var title = confirm("¿Estas son las fechas correctas?");
if(title)
{
var e = {
"start" : $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss"),
"end" : $.fullCalendar.formatDate(end, "Y-MM-DD HH:mm:ss"),
};
$.ajax({
url:"eventos.php",
type:"POST",
contentType: 'application/json; charset=utf-8',
dataType: "json",
data:JSON.stringify(e),
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Added Successfully");
}
})
}
},
editable:true,
eventResize:function(event)
{
var e = {
"start" : $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss"),
"end" : $.fullCalendar.formatDate(end, "Y-MM-DD HH:mm:ss"),
"title" : title
"id" : event.id,
"userId": event.userId,
"start" : $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss"),
"end" : $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss"),
"title" : event.title
};
$.ajax({
url:"eventos.php?idEvento="+event.id,
type:"PUT",
contentType: 'application/json; charset=utf-8',
dataType:"json",
data:JSON.stringify(e),
success:function(){
calendar.fullCalendar('refetchEvents');
alert('Event Update');
}
})
},
eventDrop:function(event)
{
var e = {
"id" : event.id,
"userId": event.userId,
"start" : $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss"),
"end" : $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss"),
"title" : event.title
};
$.ajax({
url:"eventos.php",
type:"POST",
url:"eventos.php?idEvento="+event.id,
contentType: 'application/json; charset=utf-8',
dataType: "json",
type:"PUT",
data:JSON.stringify(e),
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Added Successfully");
alert("Event Updated");
}
})
}
},
editable:true,
eventResize:function(event)
{
var e = {
"id" : event.id,
"userId": event.userId,
"start" : $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss"),
"end" : $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss"),
"title" : event.title
};
$.ajax({
url:"eventos.php?idEvento="+event.id,
type:"PUT",
contentType: 'application/json; charset=utf-8',
dataType:"json",
data:JSON.stringify(e),
success:function(){
calendar.fullCalendar('refetchEvents');
alert('Event Update');
}
})
},
eventDrop:function(event)
{
var e = {
"id" : event.id,
"userId": event.userId,
"start" : $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss"),
"end" : $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss"),
"title" : event.title
};
$.ajax({
url:"eventos.php?idEvento="+event.id,
contentType: 'application/json; charset=utf-8',
dataType: "json",
type:"PUT",
data:JSON.stringify(e),
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Event Updated");
}
});
},
eventClick:function(event)
{
if(confirm("Are you sure you want to remove it?"))
});
},
eventClick:function(event)
{
var id = event.id;
$.ajax({
url:"eventos.php?idEvento="+id,
contentType: 'application/json; charset=utf-8',
dataType: "json",
type:"DELETE",
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Event Removed");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
})
}
},
});
});
if(confirm("Are you sure you want to remove it?"))
{
var id = event.id;
$.ajax({
url:"eventos.php?idEvento="+id,
contentType: 'application/json; charset=utf-8',
dataType: "json",
type:"DELETE",
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Event Removed");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
})
}
},
});
});