diff --git a/assets/php/includes/session.php b/assets/php/includes/session.php index 82a44b5..b5198ba 100644 --- a/assets/php/includes/session.php +++ b/assets/php/includes/session.php @@ -28,16 +28,7 @@ public static function getListSessions($hall,$cinema,$date){ $bd = new SessionDAO('complucine'); if($bd ) { - if($date) - return $bd->getAllSessions($hall, $cinema, $date, null); - else - return $bd->getAllSessions($hall, $cinema, null, null); - } - } - public static function getListSessionsBetween2Dates($hall,$cinema,$start,$end){ - $bd = new SessionDAO('complucine'); - if($bd ) { - return $bd->getAllSessions($hall, $cinema, $start, $end); + return $bd->getAllSessions($hall, $cinema, $date); } } diff --git a/assets/php/includes/session_dao.php b/assets/php/includes/session_dao.php index f62b4ac..1ce608f 100644 --- a/assets/php/includes/session_dao.php +++ b/assets/php/includes/session_dao.php @@ -62,43 +62,24 @@ } //Returns a query to get all the session's data. - public function getAllSessions($hall, $cinema, $date, $end){ - if($end){ - - $date = $date->format("Y-m-d"); - $end = $end->format("Y-m-d"); - - // su output es date: 2021-05-30 end: 2021-07-11 - $sql = sprintf( "SELECT * FROM session WHERE - idcinema = '%s' AND idhall = '%s' AND date BETWEEN '%s' AND '%s' ORDER BY start_time ASC;", - $cinema, $hall, $date, $end); - } - - - if($date && !$end){ - $date = date('Y-m-d', strtotime( $date ) ); - - $sql = sprintf( "SELECT * FROM session WHERE - idcinema = '%s' AND idhall = '%s' AND date = '%s' ORDER BY start_time ASC;", - $cinema, $hall, $date); - }else{ - $sql = sprintf( "SELECT * FROM session WHERE - idcinema = '%s' AND idhall = '%s' ORDER BY start_time ASC;", - $cinema, $hall); - } + public function getAllSessions($hall, $cinema, $date){ + $date = date('Y-m-d', strtotime( $date ) ); + $sql = sprintf( "SELECT * FROM session WHERE + idcinema = '%s' AND idhall = '%s' AND date = '%s' ORDER BY start_time ASC;", + $cinema, $hall, $date); $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); $sessions = null; - while($fila=$resul->fetch_assoc()){ + while($fila=mysqli_fetch_array($resul)){ $sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]); } mysqli_free_result($resul); return $sessions; } - + public function getSessions_Film_Cinema($idFiml, $idCinema){ $sql = sprintf( "SELECT * FROM session WHERE session.idfilm = '%d' AND session.idcinema = '%d' ", $idFiml, $idCinema); $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); diff --git a/assets/php/template.php b/assets/php/template.php index ce302e1..8e7619a 100644 --- a/assets/php/template.php +++ b/assets/php/template.php @@ -119,8 +119,8 @@ @@ -228,7 +228,7 @@ break; case "user": array_push($menus, "
  • Historial Compras
  • "); - array_push($menus, "
  • Datos Pago
  • "); + //array_push($menus, "
  • Datos Pago
  • "); array_push($menus, "
  • Eliminar Usuario
  • "); break; diff --git a/panel_manager/eventos.php b/panel_manager/eventos.php index 543d156..74fcfaa 100644 --- a/panel_manager/eventos.php +++ b/panel_manager/eventos.php @@ -1,12 +1,17 @@ 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) { - + if ($start) { $startDateTime = $start . ' 00:00:00'; $endDateTime = $end; if ($end) { @@ -48,14 +52,14 @@ switch($_SERVER['REQUEST_METHOD']) { } $result = Evento::buscaEntreFechas(1, $startDateTime, $endDateTime); } else { - // Comprobamos si es una lista de eventos completa $result = Evento::buscaTodosEventos(1); // HACK: normalmente debería de ser App::getSingleton()->idUsuario(); } } + // 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)); @@ -66,17 +70,18 @@ switch($_SERVER['REQUEST_METHOD']) { case 'POST': // 1. Leemos el contenido que nos envían $entityBody = file_get_contents('php://input'); + // 2. Verificamos que nos envían un objeto $dictionary = json_decode($entityBody); if (!is_object($dictionary)) { - //throw new ParametroNoValidoException('El cuerpo de la petición no es valido'); + throw new ParametroNoValidoException('El cuerpo de la petición no es valido'); } // 3. Reprocesamos el cuerpo de la petición como un array PHP $dictionary = json_decode($entityBody, true); $dictionary['userId'] = 1;// HACK: normalmente debería de ser App::getSingleton()->idUsuario(); $e = Evento::creaDesdeDicionario($dictionary); - + error_log("hmmm"); // 4. Guardamos el evento en BD $result = Evento::guardaOActualiza($e); @@ -91,7 +96,6 @@ 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 @@ -99,10 +103,9 @@ switch($_SERVER['REQUEST_METHOD']) { // 3. Verificamos que nos envían un objeto $dictionary = json_decode($entityBody); if (!is_object($dictionary)) { - //throw new ParametroNoValidoException('El cuerpo de la petición no es valido'); + throw new ParametroNoValidoException('El cuerpo de la petición no es valido'); } - - + // 4. Reprocesamos el cuerpo de la petición como un array PHP $dictionary = json_decode($entityBody, true); $e = Evento::buscaPorId($idEvento); @@ -129,6 +132,8 @@ switch($_SERVER['REQUEST_METHOD']) { header('Content-Length: 0'); break; default: - //throw new MetodoNoSoportadoException($_SERVER['REQUEST_METHOD']. ' no está soportado'); + throw new MetodoNoSoportadoException($_SERVER['REQUEST_METHOD']. ' no está soportado'); break; -} \ No newline at end of file + + +} diff --git a/panel_manager/includes/processForm.php b/panel_manager/includes/processForm.php new file mode 100644 index 0000000..f818d41 --- /dev/null +++ b/panel_manager/includes/processForm.php @@ -0,0 +1,65 @@ + "new_hall","number" => $_POST["number"],"cols" => $_POST["cols"],"rows" => $_POST["rows"], "cinema" => $_SESSION["cinema"], "seats" => 0); + //Check what checkboxs are seats or not + for($i = 1;$i<=$data["rows"];$i++){ + for($j=1; $j<=$data["cols"]; $j++){ + if(!empty($_POST['checkbox'.$i.$j.''])){ + $data[$i][$j] = $_POST['checkbox'.$i.$j.'']; + $data["seats"]++; + } else $data[$i][$j] = "-1"; + } + } + FormHall::processesForm($data); + } + + if(isset($_POST['edit_hall'])){ + $data = array("option" => "edit_hall","number" => $_POST["number"],"cols" => $_POST["cols"],"rows" => $_POST["rows"], "cinema" => $_SESSION["cinema"],"seats" => 0); + //Check what checkboxs are seats or not + for($i = 1;$i<=$data["rows"];$i++){ + for($j=1; $j<=$data["cols"]; $j++){ + if(!empty($_POST['checkbox'.$i.$j.''])){ + $data[$i][$j] = $_POST['checkbox'.$i.$j.'']; + $data["seats"]++; + } else $data[$i][$j] = "-1"; + } + } + FormHall::processesForm($data); + } + + if(isset($_POST['delete_hall'])){ + $data = array("option" => "delete_hall","number" => $_POST["number"], "cinema" => $_SESSION["cinema"]); + FormHall::processesForm($data); + } + + if(isset($_POST['new_session'])){ + $data = array("option" => "new_session","film" => $_POST["film"],"hall" => $_POST["hall"],"date" => $_POST["date"],"start" => $_POST["start"] + ,"price" => $_POST["price"],"format" => $_POST["format"],"repeat" => $_POST["repeat"], "cinema" => $_SESSION["cinema"]); + FormSession::processesForm($data); + } + + if(isset($_POST['edit_session'])){ + $data = array("option" => "edit_session","film" => $_POST["film"],"hall" => $_POST["hall"],"date" => $_POST["date"],"start" => $_POST["start"] + ,"price" => $_POST["price"],"format" => $_POST["format"],"repeat" => $_POST["repeat"], "cinema" => $_SESSION["cinema"] + , "origin_hall"=>$_SESSION["or_hall"],"origin_date"=> $_SESSION["or_date"],"origin_start"=> $_SESSION["or_start"]); + + $_SESSION["or_hall"] = ""; + $_SESSION["or_date"] = ""; + $_SESSION["or_start"] = ""; + FormSession::processesForm($data); + } + + if(isset($_POST['delete_session'])){ + $data = array("option" => "delete_session","cinema" => $_SESSION["cinema"], "hall"=> $_POST["origin_hall"] + ,"date"=> $_POST["origin_date"],"start"=> $_POST["origin_start"]); + FormSession::processesForm($data); + } + +?> \ No newline at end of file diff --git a/panel_manager/sessioncalendar.js b/panel_manager/sessioncalendar.js index 998f0cb..6b36044 100644 --- a/panel_manager/sessioncalendar.js +++ b/panel_manager/sessioncalendar.js @@ -1,108 +1,107 @@ $(document).ready(function() { - var calendar = $('#calendar').fullCalendar({ - editable:true, - header:{ - left:'prev,next today', - center:'title', - right:'month,agendaWeek,agendaDay' - }, - events: 'eventos.php', - selectable:true, - selectHelper:true, - timeFormat: 'H:mm', - select: function(start, end, allDay) - { - var title = prompt("Enter Event Title"); - if(title) + var calendar = $('#calendar').fullCalendar({ + editable:true, + header:{ + left:'prev,next today', + center:'title', + right:'' + }, + events: 'eventos.php', + selectable:true, + selectHelper:true, + select: function(start, end, allDay) + { + var title = confirm("¿Estas son las fechas correctas?"); + if(title) + { + + var e = { + "start" : $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss"), + "end" : $.fullCalendar.formatDate(end, "Y-MM-DD HH:mm:ss"), + }; + $.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"); + } + }) + } + }, + editable:true, + eventResize:function(event) { var e = { - "start" : $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss"), - "end" : $.fullCalendar.formatDate(end, "Y-MM-DD HH:mm:ss"), - "title" : title + "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 = { + "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", - type:"POST", + url:"eventos.php?idEvento="+event.id, contentType: 'application/json; charset=utf-8', dataType: "json", + type:"PUT", data:JSON.stringify(e), success:function() { calendar.fullCalendar('refetchEvents'); - alert("Added Successfully"); + alert("Event Updated"); } - }) - } - }, - 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 = { - "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, - contentType: 'application/json; charset=utf-8', - dataType: "json", - type:"PUT", - data:JSON.stringify(e), - success:function() - { - calendar.fullCalendar('refetchEvents'); - alert("Event Updated"); - } - }); - }, - - eventClick:function(event) - { - if(confirm("Are you sure you want to remove it?")) + }); + }, + + eventClick:function(event) { - 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); - } - }) - } - }, - - }); - }); \ No newline at end of file + 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); + } + }) + } + }, + + }); + }); \ No newline at end of file diff --git a/panel_user/includes/formDeleteAccount.php b/panel_user/includes/formDeleteAccount.php index 2176aa8..0bfb15f 100644 --- a/panel_user/includes/formDeleteAccount.php +++ b/panel_user/includes/formDeleteAccount.php @@ -39,7 +39,7 @@ class FormDeleteAccount extends Form {
    - +
    "; diff --git a/purchase/includes/formPurchase.php b/purchase/includes/formPurchase.php index 5e69109..a1377b5 100644 --- a/purchase/includes/formPurchase.php +++ b/purchase/includes/formPurchase.php @@ -41,13 +41,19 @@ class FormPurchase extends Form { $hallDAO = new HallDAO("complucine"); $this->hall = $hallDAO->HallData($this->session->getIdhall()); - + $this->seat = array(); + $this->row = array(); + $this->col = array(); $rows = $this->hall->getNumRows(); $cols = $this->hall->getNumCol(); for($i = 0; $i <= $rows; $i++){ for($j = 0; $j <= $cols; $j++){ $seat = $i.$j; - if(isset($_POST["checkbox".$seat])){ $this->seat = "(Fila) ".$i." - (Columna) ".$j; $this->row = $i; $this->col = $j; } + if(isset($_POST["checkbox".$seat])){ + array_push($this->seat, $i."-".$j); + array_push($this->row, $i); + array_push($this->col, $j); + } } } @@ -89,6 +95,11 @@ class FormPurchase extends Form {

    Vuelva atrás para selecionar otra sesión.

    "; } else { + $seats = ""; + foreach($this->seat as $value){ + $seats .= $value.", "; + } + $html = "
    Resumen de la Compra @@ -96,10 +107,10 @@ class FormPurchase extends Form {

    Película: ".str_replace('_', ' ', strtoupper($this->film->getTittle()))."

    Cine: ".$this->cinema->getName()."

    Sala: ".$this->session->getIdhall()."

    -

    Asiento: ".$this->seat."

    +

    Asiento(s):".$seats."

    Fecha: ".date_format(date_create($this->session->getDate()), 'd-m-Y')."

    Hora: ".$this->session->getStartTime()."

    -

    Precio: ".$this->session->getSeatPrice()."€

    +

    Precio: ".$this->session->getSeatPrice()*count($this->seat)."€

    ".$htmlErroresGlobales."
    Datos Bancarios @@ -124,8 +135,8 @@ class FormPurchase extends Form {
    - - + +
    @@ -168,14 +179,18 @@ class FormPurchase extends Form { if (count($result) === 0) { if(isset($_SESSION["login"]) && $_SESSION["login"] == true){ $purchaseDAO = new PurchaseDAO("complucine"); - if($purchaseDAO->createPurchase(unserialize($_SESSION["user"])->getId(), $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), $datos["row"], $datos["col"], date("Y-m-d H:i:s"))){ - $purchase = new Purchase(unserialize($_SESSION["user"])->getId(), $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), $datos["row"], $datos["col"], strftime("%A %e de %B de %Y a las %H:%M")); + $count = count(unserialize($datos["row"])); + $rows = unserialize($datos["row"]); $cols = unserialize($datos["col"]); + for($i = 0; $i < $count; $i++){ + if($purchaseDAO->createPurchase(unserialize($_SESSION["user"])->getId(), $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), $rows[$i], $cols[$i], date("Y-m-d H:i:s"))){ + $purchase = new Purchase(unserialize($_SESSION["user"])->getId(), $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), $datos["row"], $datos["col"], strftime("%A %e de %B de %Y a las %H:%M")); - $_SESSION["purchase"] = serialize($purchase); - $_SESSION["film_purchase"] = serialize($this->film); - $result = "resume.php"; - } else { - $result[] = "Error al realizar la compra."; + $_SESSION["purchase"] = serialize($purchase); + $_SESSION["film_purchase"] = serialize($this->film); + $result = "resume.php"; + } else { + $result[] = "Error al realizar la compra."; + } } } else { $purchase = new Purchase("null", $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), $datos["row"], $datos["col"], strftime("%A %e de %B de %Y a las %H:%M")); diff --git a/purchase/resume.php b/purchase/resume.php index a3b0b7c..f27eee4 100644 --- a/purchase/resume.php +++ b/purchase/resume.php @@ -18,7 +18,11 @@ $cinemaDAO = new Cinema_DAO("complucine"); $cinema = $cinemaDAO->cinemaData($purchase->getCinemaId()); - $seat = 1; //$_POST[]; + $seatsArray = array_combine(unserialize($purchase->getRow()), unserialize($purchase->getColumn())); + $seats = ""; + foreach($seatsArray as $key=>$value){ + $seats .= $key."-".$value.", "; + } unset($_SESSION["purchase"]); unset($_SESSION["film_purchase"]); @@ -29,16 +33,14 @@

    Película: ".str_replace('_', ' ', strtoupper($film_purchase->getTittle()))."

    Duración: ".$film_purchase->getDuration()." minutos

    Idioma: ".$film_purchase->getLanguage()."

    -

    Precio: ".$session->getSeatPrice()." €

    +

    Precio: ".$session->getSeatPrice()*count(unserialize($purchase->getRow()))." €

    Sesión (Fecha): ".$session->getDate()."

    Sesión (Hora): ".$session->getStartTime()."

    Cine: ".$cinema->getName()."

    Sala: ".$purchase->getHallId()."

    -

    Asiento: ".$seat."

    -

    Asiento (Columna): ".$purchase->getRow()."

    -

    Asiento (Fila): ".$purchase->getColumn()."

    +

    Asiento(s): ".$seats."

    Fecha de la Compra: ".$purchase->getTime()."

    ";