Editar al clicar funcional
This commit is contained in:
@ -59,18 +59,17 @@ switch($_SERVER['REQUEST_METHOD']) {
|
||||
}
|
||||
// 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));
|
||||
|
||||
header('Content-Length: ' . mb_strlen($json));;
|
||||
|
||||
echo $json;
|
||||
break;
|
||||
// Añadir un nuevo evento
|
||||
case 'POST':
|
||||
$errors = [];
|
||||
$data = [];
|
||||
//Testing hacks
|
||||
|
||||
$correct_response = 'Operación completada';
|
||||
|
||||
$entityBody = file_get_contents('php://input');
|
||||
@ -103,14 +102,12 @@ switch($_SERVER['REQUEST_METHOD']) {
|
||||
$start = date('Y-m-d', $start);
|
||||
$end = date('Y-m-d', $end);
|
||||
|
||||
if($start >= $end)
|
||||
if($start > $end)
|
||||
$errors['date'] = 'La fecha inicial no puede ser antes o el mismo dia que la final.';
|
||||
}
|
||||
if (empty($startHour))
|
||||
$errors['startHour'] = 'Es necesario escoger el horario de la sesion.';
|
||||
|
||||
error_log("El valor de idfilm: ".$idfilm);
|
||||
|
||||
if (!is_numeric($idfilm) && $idfilm <= 0 )
|
||||
$errors['idfilm'] = 'No se ha seleccionado una pelicula.';
|
||||
|
||||
@ -118,7 +115,7 @@ switch($_SERVER['REQUEST_METHOD']) {
|
||||
$msg = Session::create_session($_SESSION["cinema"], $hall, $startHour, $startDate, $idfilm, $price, $format);
|
||||
|
||||
if(strcmp($msg,$correct_response)!== 0)
|
||||
$errors['price'] = $msg;
|
||||
$errors['global'] = $msg;
|
||||
else
|
||||
$data['message'] = $msg;
|
||||
|
||||
@ -136,7 +133,7 @@ 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
|
||||
@ -162,8 +159,83 @@ switch($_SERVER['REQUEST_METHOD']) {
|
||||
header('Content-Length: ' . mb_strlen($json));
|
||||
|
||||
echo $json;
|
||||
*/
|
||||
//If the user want to move a session
|
||||
if(isset($_GET["resize"]) && $_GET["resize"]){
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
$errors = [];
|
||||
$data = [];
|
||||
|
||||
$correct_response = 'Se ha editado la session con exito';
|
||||
|
||||
$entityBody = file_get_contents('php://input');
|
||||
$dictionary = json_decode($entityBody);
|
||||
|
||||
if (!is_object($dictionary))
|
||||
$errors['global'] = 'El cuerpo de la petición no es valido';
|
||||
|
||||
$price = $dictionary->{"price"} ?? "";
|
||||
$format = $dictionary->{"format"} ?? "";
|
||||
$hall = $dictionary->{"hall"} ?? "";
|
||||
$startDate = $dictionary->{"startDate"} ?? "";
|
||||
|
||||
|
||||
|
||||
$endDate = $dictionary->{"endDate"} ?? "";
|
||||
$startHour = $dictionary->{"startHour"} ?? "";
|
||||
$idfilm = $dictionary->{"idFilm"} ?? "";
|
||||
|
||||
$or_hall = $dictionary->{"og_hall"} ?? "";
|
||||
$or_date = $dictionary->{"og_date"} ?? "";
|
||||
$or_start = $dictionary->{"og_start"} ?? "";
|
||||
|
||||
if (empty($price) || $price <= 0 )
|
||||
$errors['price'] = 'El precio no puede ser 0.';
|
||||
if (empty($format))
|
||||
$errors['format'] = 'El formato no puede estar vacio. Ej: 3D, 2D, voz original';
|
||||
if (empty($hall) || $hall<=0 )
|
||||
$errors['hall'] = 'La sala no puede ser 0 o menor';
|
||||
if (empty($startDate))
|
||||
$errors['startDate'] = 'Las sesiones tienen que empezar algun dia.';
|
||||
else if (empty($endDate))
|
||||
$errors['endDate'] = 'Las sesiones tienen que teminar algun dia.';
|
||||
else {
|
||||
$start = strtotime($startDate);
|
||||
$end = strtotime($endDate);
|
||||
$start = date('Y-m-d', $start);
|
||||
$end = date('Y-m-d', $end);
|
||||
if($start > $end)
|
||||
$errors['date'] = 'La fecha inicial no puede ser antes o el mismo dia que la final.';
|
||||
}
|
||||
if (empty($startHour))
|
||||
$errors['startHour'] = 'Es necesario escoger el horario de la sesion.';
|
||||
|
||||
if (!is_numeric($idfilm) && $idfilm <= 0 )
|
||||
$errors['idfilm'] = 'No se ha seleccionado una pelicula.';
|
||||
if(empty($errors)){
|
||||
$msg = Session::edit_session($_SESSION["cinema"], $or_hall, $or_date, $or_start, $hall, $startHour, $startDate, $idfilm, $price, $format);
|
||||
|
||||
if(strcmp($msg,$correct_response)!== 0)
|
||||
$errors['global'] = $msg;
|
||||
else
|
||||
$data['message'] = $msg;
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$data['success'] = false;
|
||||
$data['errors'] = $errors;
|
||||
} else {
|
||||
$data['success'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($data);
|
||||
break;
|
||||
case 'DELETE':
|
||||
|
||||
// 1. Comprobamos si es una consulta de un evento concreto -> eventos.php?idEvento=XXXXX
|
||||
$idEvento = filter_input(INPUT_GET, 'idEvento', FILTER_VALIDATE_INT);
|
||||
// 2. Borramos el evento
|
||||
|
Reference in New Issue
Block a user