From d8e08b7c3c83c55007b69212b0112129be72bc21 Mon Sep 17 00:00:00 2001 From: Markines16 <80280295+Markines16@users.noreply.github.com> Date: Sat, 5 Jun 2021 14:28:52 +0200 Subject: [PATCH] Full Calendar Add funcional Solo falta que el formulario se reinicie una vez se ha completado la operacion --- panel_manager/eventos.php | 13 +- panel_manager/includes/NewSessionForm.php | 51 ++++--- panel_manager/sessioncalendar.js | 24 +++- panel_manager/sessionforms.js | 163 ++++++++++++++-------- 4 files changed, 167 insertions(+), 84 deletions(-) diff --git a/panel_manager/eventos.php b/panel_manager/eventos.php index 0a72204..b7f7600 100644 --- a/panel_manager/eventos.php +++ b/panel_manager/eventos.php @@ -72,7 +72,6 @@ switch($_SERVER['REQUEST_METHOD']) { $data = []; //Testing hacks $correct_response = 'OperaciĆ³n completada'; - $film = "1"; $entityBody = file_get_contents('php://input'); $dictionary = json_decode($entityBody); @@ -86,6 +85,7 @@ switch($_SERVER['REQUEST_METHOD']) { $startDate = $dictionary->{"startDate"} ?? ""; $endDate = $dictionary->{"endDate"} ?? ""; $startHour = $dictionary->{"startHour"} ?? ""; + $idfilm = $dictionary->{"idFilm"} ?? ""; if (empty($price) || $price <= 0 ) $errors['price'] = 'El precio no puede ser 0.'; @@ -108,9 +108,14 @@ switch($_SERVER['REQUEST_METHOD']) { } 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.'; + while($startDate < $endDate && empty($errors)){ - $msg = Session::create_session($_SESSION["cinema"], $hall, $startHour, $startDate, $film, $price, $format); + $msg = Session::create_session($_SESSION["cinema"], $hall, $startHour, $startDate, $idfilm, $price, $format); if(strcmp($msg,$correct_response)!== 0) $errors['price'] = $msg; @@ -121,11 +126,9 @@ switch($_SERVER['REQUEST_METHOD']) { } if (!empty($errors)) { - error_log("no success"); $data['success'] = false; $data['errors'] = $errors; } else { - error_log("succes"); $data['success'] = true; } diff --git a/panel_manager/includes/NewSessionForm.php b/panel_manager/includes/NewSessionForm.php index f116797..3fc7f7c 100644 --- a/panel_manager/includes/NewSessionForm.php +++ b/panel_manager/includes/NewSessionForm.php @@ -19,17 +19,14 @@ class NewSessionForm {

-
'; +
+ + $form.=' +
Horario @@ -50,27 +47,45 @@ class NewSessionForm {
- +
- - - +
+ +

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
  • +
    +
    -
    +
      '; $parity = "odd"; + $i = 0; foreach($filmslist as $film){ $form .='
      -
    • '. str_replace('_', ' ',$film->getTittle()).'
    • -
    • '.$film->getDuration().' min
    • -
    • + + + + +
    • '. str_replace('_', ' ',$film->getTittle()).'
    • +
    • '.$film->getDuration().' min
    • +
    • '; $parity = ($parity == "odd") ? "even" : "odd"; + $i++; } $form.='
    -
    '; +
    + '; return $form; } diff --git a/panel_manager/sessioncalendar.js b/panel_manager/sessioncalendar.js index 3851744..6fd89f2 100644 --- a/panel_manager/sessioncalendar.js +++ b/panel_manager/sessioncalendar.js @@ -26,11 +26,18 @@ $(document).ready(function(){ 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" ); + /* var e = { "date" : $.fullCalendar.formatDate(allDay,"Y-MM-DD"), @@ -133,14 +140,25 @@ $(document).ready(function(){ // When the user clicks on (x), close the modal span.onclick = function() { - $(modal).fadeOut(); + formout(); } // When the user clicks anywhere outside of the modal, close it window.onclick = function(event) { if (event.target == modal) { - $(modal).fadeOut(); + formout(); } } + + function formout(){ + + var success = document.getElementById("success"); + if(success){ + calendar.fullCalendar('refetchEvents'); + } + + $(modal).fadeOut(); + + } }); diff --git a/panel_manager/sessionforms.js b/panel_manager/sessionforms.js index b72860e..7780818 100644 --- a/panel_manager/sessionforms.js +++ b/panel_manager/sessionforms.js @@ -12,6 +12,7 @@ $(document).ready(function () { startDate: $("#startDate").val(), endDate: $("#endDate").val(), startHour: $("#startHour").val(), + idFilm: $("#film_id").val(), }; $.ajax({ @@ -23,64 +24,7 @@ $(document).ready(function () { encode: true, }).done(function (data) { console.log(data); - - 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.global) { - $("#global_group").addClass("has_error"); - $("#global_group").append( - '
    ' + data.errors.global + "
    " - ); - } - - - } else { - $("form#new_session_form").html( - '
    ' + data.message + "
    " - ); - } - + checkErrors(data,"form#new_session_form"); }) .fail(function (jqXHR, textStatus) { $("form#new_session_form").html( @@ -88,6 +32,109 @@ $(document).ready(function () { ); }); + 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 { + $(formname).html( + '
    ' + data.message + "
    " + ); + } + + } e.preventDefault(); }); + + $('.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"; + + + }); + + $('#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