From bef1bb80389c1b3f4e894d16c585d84ba52e39f6 Mon Sep 17 00:00:00 2001 From: Markines16 <80280295+Markines16@users.noreply.github.com> Date: Sun, 6 Jun 2021 01:01:34 +0200 Subject: [PATCH] Editar al clicar funcional --- panel_manager/Evento.php | 59 +++------ panel_manager/eventos.php | 90 +++++++++++-- panel_manager/includes/EditSessionForm.php | 99 +++++++++++++++ panel_manager/includes/NewSessionForm.php | 18 ++- panel_manager/processSession.php | 57 +++++++++ panel_manager/sessioncalendar.js | 109 ++++++---------- panel_manager/sessionforms.js | 140 +++++++++++++++------ 7 files changed, 411 insertions(+), 161 deletions(-) create mode 100644 panel_manager/includes/EditSessionForm.php create mode 100644 panel_manager/processSession.php diff --git a/panel_manager/Evento.php b/panel_manager/Evento.php index e6e444e..37c84c1 100644 --- a/panel_manager/Evento.php +++ b/panel_manager/Evento.php @@ -56,6 +56,7 @@ class Evento implements \JsonSerializable while($fila = $rs->fetch_assoc()) { $result = new Evento(); $result->asignaDesdeDiccionario($fila); + } $rs->free(); } else { @@ -282,7 +283,7 @@ class Evento implements \JsonSerializable /** * @param array[string] Nombre de las propiedades de la clase. */ - const PROPERTIES = ['id', 'userId', 'title', 'start', 'end', 'idfilm']; + const PROPERTIES = ['id', 'userId', 'title', 'start', 'end', 'idfilm', 'start_time', 'seat_price', 'format', 'seats_full']; //'idfilm','idhall','idcinema','date', 'start_time', 'seat_price', 'format', 'seats_full']; private $id; @@ -292,16 +293,10 @@ class Evento implements \JsonSerializable private $end; private $idfilm; - - - /* - private $idhall; - private $idcinema; - private $date; private $start_time; private $seat_price; private $format; - private $seats_full;*/ + private $seats_full; private function __construct() @@ -313,6 +308,11 @@ class Evento implements \JsonSerializable return $this->id; } + public function getIdfilm() + { + return $this->idfilm; + } + public function getUserId() { return $this->userId; @@ -391,13 +391,19 @@ class Evento implements \JsonSerializable * @return Devuelve un objeto con propiedades públicas y que represente el estado de este evento. */ public function jsonSerialize() - { + { $o = new \stdClass(); $o->id = $this->id; $o->userId = $this->userId; $o->title = $this->title; $o->start = $this->start->format(self::MYSQL_DATE_TIME_FORMAT); $o->end = $this->end->format(self::MYSQL_DATE_TIME_FORMAT); + $o->start_time = $this->start_time; + $o->seat_price = $this->seat_price; + $o->format = $this->format; + $o->film = Session::getThisSessionFilm($this->idfilm); + + return $o; } @@ -419,13 +425,10 @@ class Evento implements \JsonSerializable "start" => $start, "end" => $end, "idfilm" => $session->getIdfilm(), - /*"idcinema" => $session->getIdcinema(), - "idhall" => $session->getIdhall(), - "date" => $session->getDate(), "start_time" => $session->getStartTime(), "seat_price" => $session->getSeatPrice(), "format" => $session->getFormat(), - "seats_full" => $session->getSeatsFull(),*/ + "seats_full" => $session->getSeatsFull(), ); return $dictionary; @@ -545,34 +548,6 @@ class Evento implements \JsonSerializable } } - /* - if (array_key_exists('idhall', $diccionario)) { - $idhall = $diccionario['idhall'] ?? null; - if (empty($idhall)) { - // throw new \BadMethodCallException('$diccionario[\'end\'] no puede ser una cadena vacía o nulo'); - } else { - $this->idhall = $idhall; - } - } - - if (array_key_exists('idcinema', $diccionario)) { - $idcinema = $diccionario['idcinema'] ?? null; - if (empty($idcinema)) { - // throw new \BadMethodCallException('$diccionario[\'end\'] no puede ser una cadena vacía o nulo'); - } else { - $this->idcinema = $idcinema; - } - } - - if (array_key_exists('date', $diccionario)) { - $date = $diccionario['date'] ?? null; - if (empty($date)) { - // throw new \BadMethodCallException('$diccionario[\'end\'] no puede ser una cadena vacía o nulo'); - } else { - $this->date = $date; - } - } - if (array_key_exists('start_time', $diccionario)) { $start_time = $diccionario['start_time'] ?? null; if (empty($start_time)) { @@ -607,7 +582,7 @@ class Evento implements \JsonSerializable } else { $this->seats_full = $seats_full; } - }*/ + } self::compruebaConsistenciaFechas($this->start, $this->end); diff --git a/panel_manager/eventos.php b/panel_manager/eventos.php index b7f7600..1c724e4 100644 --- a/panel_manager/eventos.php +++ b/panel_manager/eventos.php @@ -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 diff --git a/panel_manager/includes/EditSessionForm.php b/panel_manager/includes/EditSessionForm.php new file mode 100644 index 0000000..53518db --- /dev/null +++ b/panel_manager/includes/EditSessionForm.php @@ -0,0 +1,99 @@ +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/NewSessionForm.php b/panel_manager/includes/NewSessionForm.php index 9cc0566..6dfa5ba 100644 --- a/panel_manager/includes/NewSessionForm.php +++ b/panel_manager/includes/NewSessionForm.php @@ -10,7 +10,13 @@ class NewSessionForm { $form='
    -
    + + + + + + +
    Datos @@ -47,11 +53,14 @@ class NewSessionForm {
    - + +
    + + +
    -

    titulo


    @@ -86,7 +95,8 @@ class NewSessionForm { $form.='
    - '; + + '; return $form; } diff --git a/panel_manager/processSession.php b/panel_manager/processSession.php new file mode 100644 index 0000000..1772f2e --- /dev/null +++ b/panel_manager/processSession.php @@ -0,0 +1,57 @@ += $end){ + $errors['date'] = 'La fecha inicial no puede ser antes o el mismo dia que la final.'; + } +} + +if (empty($_POST['startHour'])) { + $errors['startHour'] = 'Es necesario escoger el horario de la sesion.'; +} + + +if (!empty($errors)){ + error_log("creamos una sesion, wahoo"); + Session::create_session("1", $_POST['hall'], $_POST['startHour'], $_POST['startDate'], + "1",$_POST['price'], $_POST['format'],"0"); + + + $data['success'] = false; + $data['errors'] = $errors; +} else { + $data['success'] = true; + $data['message'] = 'Success!'; +} + +echo json_encode($data); \ No newline at end of file diff --git a/panel_manager/sessioncalendar.js b/panel_manager/sessioncalendar.js index 735dc0b..234932b 100644 --- a/panel_manager/sessioncalendar.js +++ b/panel_manager/sessioncalendar.js @@ -23,8 +23,10 @@ $(document).ready(function(){ selectable:true, selectHelper:true, timeFormat: 'H:mm', + select: function(start, end, allDay) { + $(modal).fadeIn(); var x = document.getElementById("film_group"); @@ -33,58 +35,14 @@ $(document).ready(function(){ 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"), - "start" : $.fullCalendar.formatDate(start, "HH:mm"), - "end" : $.fullCalendar.formatDate(end, "HH:mm") - }; - - $.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"); - } - })*/ + document.getElementById("sumbit_new").style.display = "block"; + document.getElementById("edit_inputs").style.display = "none"; }, 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 = { @@ -95,7 +53,7 @@ $(document).ready(function(){ "title" : event.title }; $.ajax({ - url:"eventos.php?idEvento="+event.id, + url:"eventos.php?idEvento="+event.id+"resize=true", contentType: 'application/json; charset=utf-8', dataType: "json", type:"PUT", @@ -107,27 +65,37 @@ $(document).ready(function(){ } }); }, - + eventClick:function(event) - { - 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); - } - }) - } + { + $(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"; + }, }); @@ -158,14 +126,17 @@ $(document).ready(function(){ var success = document.getElementById("success"); if(success){ calendar.fullCalendar('refetchEvents'); + calendar.fullCalendar('reren'); success.style.display = "none"; - - document.getElementById("new_session_form").style.display = "block"; + + 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/sessionforms.js b/panel_manager/sessionforms.js index 4abd038..47f3bb4 100644 --- a/panel_manager/sessionforms.js +++ b/panel_manager/sessionforms.js @@ -1,37 +1,106 @@ $(document).ready(function () { - $("form#new_session_form").on('submit', function(e){ + //New form session + $('#sumbit_new').click( function(e) { + $(".form_group").removeClass("has_error"); + $(".help_block").remove(); - $(".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:"eventos.php", - contentType: 'application/json; charset=utf-8', - dataType: "json", - data:JSON.stringify(formData), - encode: true, - }).done(function (data) { - console.log(data); - checkErrors(data,"new_session_form"); - }) - .fail(function (jqXHR, textStatus) { - $("form#new_session_form").html( - '
    Could not reach server, please try again later. '+textStatus+'
    ' - ); + 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:"eventos.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:"eventos.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(); + }); + /* + $('#sumbit_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(), + }; + + $.ajax({ + type: "DELETE", + url:"eventos.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) { @@ -89,18 +158,16 @@ $(document).ready(function () { ); } } else { - $("#operation_msg").addClass("has_no_error"); $("#operation_msg").append( '
    ' + data.message + "
    " ); - document.getElementById(formname).style.display = "none"; + document.getElementById("session_form").style.display = "none"; - } - } - e.preventDefault(); - }); + + } + $('.film_button').bind('click', function(e) { var id = $(this).attr('id'); @@ -116,7 +183,6 @@ $(document).ready(function () { 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;