From a57751e699d7f45228c5149371ecb5e452d047ea Mon Sep 17 00:00:00 2001 From: Markines16 <80280295+Markines16@users.noreply.github.com> Date: Sun, 6 Jun 2021 13:35:19 +0200 Subject: [PATCH] FC funcional entero --- panel_manager/eventsProcess.php | 261 +++++++++++++++++++++++++ panel_manager/includes/SessionForm.php | 105 ++++++++++ panel_manager/includes/formHall.php | 12 +- panel_manager/index.php | 30 +-- panel_manager/panel_manager.php | 138 +------------ panel_manager/sessionCalendar.js | 140 +++++++++++++ panel_manager/sessionFormProcess.js | 212 ++++++++++++++++++++ 7 files changed, 733 insertions(+), 165 deletions(-) create mode 100644 panel_manager/eventsProcess.php create mode 100644 panel_manager/includes/SessionForm.php create mode 100644 panel_manager/sessionCalendar.js create mode 100644 panel_manager/sessionFormProcess.js diff --git a/panel_manager/eventsProcess.php b/panel_manager/eventsProcess.php new file mode 100644 index 0000000..9fb4f59 --- /dev/null +++ b/panel_manager/eventsProcess.php @@ -0,0 +1,261 @@ + 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) { + + $startDateTime = $start . ' 00:00:00'; + $endDateTime = $end; + if ($end) { + $endDateTime = $end. ' 00:00:00'; + } + $result = Event::searchEventsBetween2dates($startDateTime, $endDateTime, $hall,$cinema); + } else { + // Comprobamos si es una lista de eventos completa + $result = Event::searchAllEvents($hall,$cinema); + } + + // 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));; + + echo $json; + break; + // Add Session + case 'POST': + error_log("POST"); + $errors = []; + $data = []; + + //Correct reply to verify the session has been correctly added + $correct_response = 'Operación completada'; + + //Check if the body is ok + $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"} ?? ""; + + //Check errors in inputs + 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.'; + + //Create as many sessions as the diference between start and end date tell us. 1 session per day + while($startDate < $endDate && empty($errors)){ + $msg = Session::create_session($_SESSION["cinema"], $hall, $startHour, $startDate, $idfilm, $price, $format); + + if(strcmp($msg,$correct_response)!== 0) + $errors['global'] = $msg; + else + $data['message'] = $msg; + + $startDate = date('Y-m-d H:i:s', strtotime( $startDate . ' +1 day')); + } + + if (!empty($errors)) { + $data['success'] = false; + $data['errors'] = $errors; + } else { + $data['success'] = true; + } + + echo json_encode($data); + + break; + //Edit session + case 'PUT': + //Correct reply to verify the session has been correctly edited + $correct_response = 'Se ha editado la session con exito'; + + $errors = []; + $data = []; + + //Check if the body is ok + $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'; + + //Check if the user is droping an event in a new date + if(isset($_GET["drop"]) && $_GET["drop"]){ + $or_hall = $dictionary->{"idhall"} ?? ""; + $or_date = $dictionary->{"startDate"} ?? ""; + $or_start = $dictionary->{"startHour"} ?? ""; + $price = $dictionary->{"price"} ?? ""; + $idfilm = $dictionary->{"idfilm"} ?? ""; + $format = $dictionary->{"format"} ?? ""; + + $new_date = $dictionary->{"newDate"} ?? ""; + + $msg = Session::edit_session($_SESSION["cinema"], $or_hall, $or_date, $or_start, $or_hall, $new_date, $new_date, $idfilm, $price, $format); + + if(strcmp($msg,$correct_response)!== 0) + http_response_code(400); + else + http_response_code(200); + }else{ + //Edit session from a form + $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"} ?? ""; + + //Check errors in inputs + 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; + //Delete a session + case 'DELETE': + $errors = []; + $data = []; + + //Correct reply to verify the session has been correctly edited + $correct_response = 'Se ha eliminado la session con exito'; + + //Check if the body is ok + $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'; + + $or_hall = $dictionary->{"og_hall"} ?? ""; + $or_date = $dictionary->{"og_date"} ?? ""; + $or_start = $dictionary->{"og_start"} ?? ""; + + //Check errors in inputs + if(empty($or_hall)) + $errors['global'] = 'El nº de sala a borrar no existe'; + if(empty($or_date)) + $errors['global'] = 'La fecha de donde borrar no existe'; + if(empty($or_start)) + $errors['global'] = 'La hora de donde borrar no existe'; + + if(empty($errors)){ + $msg = Session::delete_session($_SESSION["cinema"], $or_hall, $or_start, $or_date); + + 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; + default: + break; +} \ No newline at end of file diff --git a/panel_manager/includes/SessionForm.php b/panel_manager/includes/SessionForm.php new file mode 100644 index 0000000..f1781ef --- /dev/null +++ b/panel_manager/includes/SessionForm.php @@ -0,0 +1,105 @@ +allFilmData(); + + $form=' +
Cine: '.$c_name.'
Dirección: '.$c_dir.'
-Hack para entrar al calendario
'."\n"; return $panel; } + // Admin welcome panel allows to change the cinema linked to the admin-like-manager static function welcomeAdmin() { $cinemaList = new Cinema_DAO('complucine'); $cinemas = $cinemaList->allCinemaData(); @@ -64,8 +61,6 @@
Usuario: '.$name.'
Cine: '.$c_name.'
- -Hack para entrar al calendario