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=' +
+
+ + + + + + +
+
+ Datos +
+
+
+
+
+
+
+ +
+
+
+ Horario +
+
+ + + + +
+
+
+
+ + +
+
+
+ + +
+ + +
+
+
+
+

titulo

+
+
+
iron man
+
+

"Un empresario millonario construye un traje blindado y lo usa para combatir el crimen y el terrorismo."

+
+
+
  • Duración: duracion minutos
  • +
  • Lenguaje: idioma
  • +
    + +
    +
    + +
    +
    + '; + + return $form; + } + +} +?> \ No newline at end of file diff --git a/panel_manager/includes/formHall.php b/panel_manager/includes/formHall.php index ca408b2..868b4cb 100644 --- a/panel_manager/includes/formHall.php +++ b/panel_manager/includes/formHall.php @@ -30,7 +30,7 @@ class FormHall extends Form { $rows = $data['rows'] ?? $this->og_hall->getNumRows() ?? "12"; $cols = $data['cols'] ?? $this->og_hall->getNumCol() ?? "8"; - //Seats_map + //Init Seats_map $seats = 0; $seats_map = array(); for($i = 1;$i <= $rows; $i++){ @@ -145,8 +145,6 @@ class FormHall extends Form { return $html; } - //Methods: - //Process form: protected function procesaFormulario($datos){ $result = array(); @@ -170,29 +168,24 @@ class FormHall extends Form { } } } - + //Check input errors if ($seats == 0 && isset($datos["sumbit"]) ) { $result['seats'] = "
  • No puede haber 0 asientos disponibles.

  • "; } - if ($rows <= 0) { $result['rows'] = "
  • No puede haber 0 o menos filas.

  • "; } - if ($cols <= 0) { $result['cols'] = "
  • No puede haber 0 o menos columnas.

  • "; } - $number = $datos['number'] ?? null; if (empty($number) && isset($datos["sumbit"])) { $result['number'] = "
  • El numero de sala tiene que ser mayor que 0.

  • "; } - if(isset($datos["restart"])){ return $result = "./?state=".$this->option."&number=".$this->og_hall->getNumber().""; } - if (count($result) === 0 && isset($datos["sumbit"]) ) { if($this->option == "new_hall"){ $_SESSION['msg'] = Hall::create_hall($number, $this->cinema, $rows, $cols, $seats, $seats_map); @@ -203,7 +196,6 @@ class FormHall extends Form { return $result = './?state=success'; } } - if (!isset($result['number']) && isset($datos["delete"]) ) { if($this->option == "edit_hall"){ $_SESSION['msg'] = Hall::delete_hall($number, $this->cinema, $rows, $cols, $seats, $seats_map, $this->og_hall->getNumber()); diff --git a/panel_manager/index.php b/panel_manager/index.php index a20bce6..eb23121 100644 --- a/panel_manager/index.php +++ b/panel_manager/index.php @@ -56,18 +56,6 @@ $panel = Manager_panel::edit_hall(); break; case "manage_sessions": - $panel = Manager_panel::manage_sessions(); - break; - case "new_session": - $panel = Manager_panel::new_session(); - break; - case "edit_session": - $panel = Manager_panel::edit_session(); - break; - case "select_film": - $panel = Manager_panel::select_film($template); - break; - case "calendar": $panel = Manager_panel::calendar(); break; case "success": @@ -138,23 +126,11 @@ $panel = Manager_panel::edit_hall(); break; case "manage_sessions": - $panel = Manager_panel::manage_sessions(); - break; - case "new_session": - $panel = Manager_panel::new_session(); - break; - case "edit_session": - $panel = Manager_panel::edit_session(); - break; - case "select_film": - $panel = Manager_panel::select_film($template); + $panel = Manager_panel::calendar(); break; case "success": $panel = Manager_panel::success(); break; - case "calendar": - $panel = Manager_panel::calendar(); - break; default: $panel = Manager_panel::welcome(); break; @@ -194,5 +170,5 @@ - - + + diff --git a/panel_manager/panel_manager.php b/panel_manager/panel_manager.php index 1513c9d..59e421c 100644 --- a/panel_manager/panel_manager.php +++ b/panel_manager/panel_manager.php @@ -1,16 +1,13 @@ Usuario: '.$name.'


    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.'


    Como administrador puedes escoger el cine que gestionar

    Cine: '.$c_name.'

    - -

    Hack para entrar al calendario

    - - -
    - - '; - //Session list - $panel .='
    '; - $sessions = Session::getListSessions($hall,$_SESSION["cinema"],$date); - - if($sessions) { - $panel .=' -
    - - - - - - - - - - '; - - - foreach($sessions as $session){ - $film = Session::getThisSessionFilm($session->getIdfilm()); - $panel .=' - - - - - - - - - - - - - - - - - - - '; - } - $panel.=' - -
    HoraPeliculaFormatoPrecio
    '.date("H:i", strtotime( $session->getStartTime())).' '. str_replace('_', ' ', $film["tittle"]) .' '.$session->getFormat().' '.$session->getSeatPrice().'
    - '; - } else { - $panel.='

    No hay ninguna sesion

    '; - } - $panel.=' - -
    '; - - return $panel; - } - - static function new_session(){ - $formSession = new FormSession("new_session", $_SESSION["cinema"] ); - - $panel = '

    Crear una sesion.



    - '.$formSession->gestiona(); - return $panel; - } - - static function edit_session(){ - $formSession = new FormSession("edit_session", $_SESSION["cinema"] ); - - $panel = '

    Editar una sesion.



    - '.$formSession->gestiona(); - return $panel; - } - - //TODO: estado al modificar sesiones para la seleccion de peliculas usando el template->print films - static function select_film($template){ - if(isset($_POST["select_film"]) && isset($_POST["option"])){ - $_SESSION["option"] = $_POST["option"]; - $panel = '

    Seleccionar Pelicula.



    '; - $panel .= $template->print_fimls(); - $_SESSION["option"] = ""; - } else $panel = self::warning(); - - return $panel; - } - - //Funcion que se envia cuando hay inconsistencia en el panel manager, principalmente por tocar cosas con la ulr + //this function is used as an answer to wrong url parameters accesing a formhall edit. The formsession version has been replaced by other js error replys static function warning(){ $panel = '

    Ha habido un error.

    @@ -328,7 +212,5 @@ return $panel; } - - } ?> diff --git a/panel_manager/sessionCalendar.js b/panel_manager/sessionCalendar.js new file mode 100644 index 0000000..2a319ab --- /dev/null +++ b/panel_manager/sessionCalendar.js @@ -0,0 +1,140 @@ +$(document).ready(function(){ + //Get the data that is going to be used as a filter for events + var selectedFeed = $('#hall_selector').find(':selected').data('feed'); + + var modal = document.getElementById("myModal"); + var btn = document.getElementById("myBtn"); + var span = document.getElementsByClassName("close")[0]; + + var calendar = $('#calendar').fullCalendar({ + editable:true, + header:{ + left:'prev,next today', + center:'title', + right:'month,agendaWeek,agendaDay' + }, + firstDay: 1, + fixedWeekCount: false, + eventSources: [ selectedFeed ], + selectable:true, + selectHelper:true, + timeFormat: 'H:mm', + eventOverlap: function(stillEvent, movingEvent) { + return (stillEvent.start_time > stillEvent.end && stillEvent.end < movingEvent.start_time) + }, + //Add event/session function when u click in any non-event date. Prepares the form to be seen as such + select: function(start, end, allDay) + { + + $(modal).fadeIn(); + + var x = document.getElementById("film_group"); + x.style.display = "none"; + x = document.getElementById("film_list"); + x.style.display = "block"; + + document.getElementById("hall").value = document.getElementById("hall_selector").value; + document.getElementById("startDate").value = $.fullCalendar.formatDate( start, "Y-MM-DD" ); + document.getElementById("endDate").value = $.fullCalendar.formatDate( end, "Y-MM-DD" ); + + document.getElementById("sumbit_new").style.display = "block"; + document.getElementById("edit_inputs").style.display = "none"; + }, + editable:true, + //Edit only the date/hour start of an event/session when u click,drag and drop an event. + eventDrop:function(event) + { + var e = { + "newDate" : $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss"), + "idhall": document.getElementById("hall").value, + "startHour":event.start_time, + "startDate":event.date, + "price": event.seat_price, + "idfilm": event.film.idfilm, + "format": event.format, + }; + console.log(e); + console.log(event); + $.ajax({ + url:"eventsProcess.php?drop=true", + contentType: 'application/json; charset=utf-8', + dataType: "json", + type:"PUT", + data:JSON.stringify(e), + success: function(data) { + alert("El evento se ha desplazado correctamente"); + calendar.fullCalendar('refetchEvents'); + }, + error: function(data) { + alert("Ha habido un error al desplazar el evento"); + }, + }); + }, + //Edit event/session function when u click an event. Prepares the form to be seen as such + eventClick:function(event) + { + $(modal).fadeIn(); + + var x = document.getElementById("film_group"); + x.style.display = "block"; + + x = document.getElementById("film_list"); + x.style.display = "none"; + + document.getElementById("hall").value = document.getElementById("hall_selector").value; + document.getElementById("startDate").value = $.fullCalendar.formatDate( event.start, "Y-MM-DD" ); + document.getElementById("endDate").value = $.fullCalendar.formatDate( event.end, "Y-MM-DD" ); + document.getElementById("price").value = event.seat_price; + document.getElementById("format").value = event.format; + document.getElementById("startHour").value = event.start_time; + + document.getElementById("original_hall").value = document.getElementById("hall_selector").value; + document.getElementById("original_start_time").value = event.start_time; + document.getElementById("original_date").value = $.fullCalendar.formatDate( event.start, "Y-MM-DD" ); + + document.getElementById("film_title").innerHTML = event.film.tittle; + document.getElementById("film_lan").innerHTML = event.film.language; + document.getElementById("film_dur").innerHTML = event.film.duration+" min"; + document.getElementById("film_img").src = "../img/films/"+event.film.img; + document.getElementById("film_desc").innerHTML = event.film.description; + document.getElementById("film_id").value = event.film.idfilm; + document.getElementById("sumbit_new").style.display = "none"; + document.getElementById("edit_inputs").style.display = "grid"; + + }, + + }); + //Once the filter changes, do the changes needed so full calendar research the events with the new hall + $('#hall_selector').change(onSelectChangeFeed); + + function onSelectChangeFeed() { + var feed = $(this).find(':selected').data('feed'); + $('#calendar').fullCalendar('removeEventSource', selectedFeed); + $('#calendar').fullCalendar('addEventSource', feed); + selectedFeed = feed; + }; + + //When u click on the X the form closes. If the user close it because the operation has been complete. Restart the form correctly + span.onclick = function() { + formout(); + } + + function formout(){ + $(modal).fadeOut(100,function(){ + var success = document.getElementById("success"); + if(success){ + calendar.fullCalendar('refetchEvents'); + success.style.display = "none"; + + document.getElementById("session_form").style.display = "block"; + document.getElementById("price").value = ""; + document.getElementById("format").value = ""; + document.getElementById("film_id").value = ""; + document.getElementById("startHour").value =""; + } + $(".form_group").removeClass("has_error"); + $(".help_block").remove(); + }); + } +}); + diff --git a/panel_manager/sessionFormProcess.js b/panel_manager/sessionFormProcess.js new file mode 100644 index 0000000..803febf --- /dev/null +++ b/panel_manager/sessionFormProcess.js @@ -0,0 +1,212 @@ +$(document).ready(function () { + + //New session + $('#sumbit_new').click( function(e) { + $(".form_group").removeClass("has_error"); + $(".help_block").remove(); + + var formData = { + price: $("#price").val(), + format: $("#format").val(), + hall: $("#hall").val(), + startDate: $("#startDate").val(), + endDate: $("#endDate").val(), + startHour: $("#startHour").val(), + idFilm: $("#film_id").val(), + }; + + $.ajax({ + type: "POST", + url:"eventsProcess.php", + contentType: 'application/json; charset=utf-8', + dataType: "json", + data:JSON.stringify(formData), + encode: true, + }).done(function (data) { + console.log(data); + checkErrors(data,"session_form"); + }) + .fail(function (jqXHR, textStatus) { + $("form#session_form").html( + '
    Could not reach server, please try again later. '+textStatus+'
    ' + ); + }); + e.preventDefault(); + }); + //Edit session + $('#sumbit_edit').click( function(e) { + $(".form_group").removeClass("has_error"); + $(".help_block").remove(); + + + var formData = { + price: $("#price").val(), + format: $("#format").val(), + hall: $("#hall").val(), + startDate: $("#startDate").val(), + endDate: $("#endDate").val(), + startHour: $("#startHour").val(), + idFilm: $("#film_id").val(), + og_hall: $("#original_hall").val(), + og_date: $("#original_date").val(), + og_start: $("#original_start_time").val(), + }; + console.log(formData); + + $.ajax({ + type: "PUT", + url:"eventsProcess.php", + contentType: 'application/json; charset=utf-8', + dataType: "json", + data:JSON.stringify(formData), + encode: true, + }).done(function (data) { + console.log(data); + checkErrors(data,"session_form"); + }) + .fail(function (jqXHR, textStatus) { + $("form#session_form").html( + '
    Could not reach server, please try again later. '+textStatus+'
    ' + ); + }); + e.preventDefault(); + }); + //Delete Session + $('#submit_del').click( function(e) { + $(".form_group").removeClass("has_error"); + $(".help_block").remove(); + + + var formData = { + og_hall: $("#original_hall").val(), + og_date: $("#original_date").val(), + og_start: $("#original_start_time").val(), + }; + console.log(formData); + + $.ajax({ + type: "DELETE", + url:"eventsProcess.php", + contentType: 'application/json; charset=utf-8', + dataType: "json", + data:JSON.stringify(formData), + encode: true, + }).done(function (data) { + console.log(data); + checkErrors(data,"session_form") + }) + .fail(function (jqXHR, textStatus) { + $("form#session_form").html( + '
    Could not reach server, please try again later. '+textStatus+'
    ' + ); + }); + e.preventDefault(); + }); + + function checkErrors(data,formname) { + if (!data.success) { + if (data.errors.price) { + $("#price_group").addClass("has_error"); + $("#price_group").append( + '
    ' + data.errors.price + "
    " + ); + } + if (data.errors.format) { + $("#format_group").addClass("has_error"); + $("#format_group").append( + '
    ' + data.errors.format + "
    " + ); + } + if (data.errors.hall) { + $("#hall_group").addClass("has_error"); + $("#hall_group").append( + '
    ' + data.errors.hall + "
    " + ); + } + if (data.errors.startDate) { + $("#date_group").addClass("has_error"); + $("#date_group").append( + '
    ' + data.errors.startDate + "
    " + ); + } + if (data.errors.startDate) { + $("#date_group").addClass("has_error"); + $("#date_group").append( + '
    ' + data.errors.endDate + "
    " + ); + } + if (data.errors.date) { + $("#date_group").addClass("has_error"); + $("#date_group").append( + '
    ' + data.errors.date + "
    " + ); + } + if (data.errors.startHour) { + $("#hour_group").addClass("has_error"); + $("#hour_group").append( + '
    ' + data.errors.startHour + "
    " + ); + } + if (data.errors.idfilm) { + $("#film_msg_group").addClass("has_error"); + $("#film_msg_group").append( + '
    ' + data.errors.idfilm + "
    " + ); + } + if (data.errors.global) { + $("#global_group").addClass("has_error"); + $("#global_group").append( + '
    ' + data.errors.global + "
    " + ); + } + } else { + $("#operation_msg").addClass("has_no_error"); + $("#operation_msg").append( + '
    ' + data.message + "
    " + ); + document.getElementById("session_form").style.display = "none"; + + } + + } + + //Change the view from the film list to a concrete film with some data about it + $('.film_button').bind('click', function(e) { + var id = $(this).attr('id'); + + var x = document.getElementById("film_group"); + x.style.display = "block"; + + var tittle = document.getElementById("title"+id); + document.getElementById("film_title").innerHTML = tittle.innerHTML; + + var lan = document.getElementById("lan"+id); + document.getElementById("film_lan").innerHTML = lan.value; + + var dur = document.getElementById("dur"+id); + document.getElementById("film_dur").innerHTML = dur.innerHTML; + + var img = document.getElementById("img"+id); + document.getElementById("film_img").src = "../img/films/"+img.value; + + var desc = document.getElementById("desc"+id); + document.getElementById("film_desc").innerHTML = desc.value; + + var idf = document.getElementById("id"+id); + document.getElementById("film_id").value = idf.value; + + x = document.getElementById("film_list") + x.style.display = "none"; + + + }); + //Change the view from the concrete film data to a film list with all available films + $('#return').click( function() { + var x = document.getElementById("film_group"); + x.style.display = "none"; + + x = document.getElementById("film_list"); + x.style.display = "block"; + }); + +}); \ No newline at end of file