Add files via upload
This commit is contained in:
616
panel_manager/Evento.php
Normal file
616
panel_manager/Evento.php
Normal file
@ -0,0 +1,616 @@
|
||||
<?php
|
||||
|
||||
include_once($prefix.'assets/php/includes/session.php');
|
||||
|
||||
/**
|
||||
* Representa un evento de calendario.
|
||||
*/
|
||||
class Evento implements \JsonSerializable
|
||||
{
|
||||
|
||||
/**
|
||||
* Busca todos los eventos de un usuario con id $userId.
|
||||
*
|
||||
* @param int $userId Id del usuario a buscar.
|
||||
*
|
||||
* @return array[Evento] Lista de eventos del usuario con id $userId.
|
||||
*/
|
||||
public static function buscaTodosEventos(int $userId, $idhall, $cinema)
|
||||
{
|
||||
if (!$userId) {
|
||||
// throw new \BadMethodCallException('$userId no puede ser nulo.');
|
||||
}
|
||||
|
||||
$result = [];
|
||||
$sessions = Session::getListSessions($idhall,$cinema,null);
|
||||
|
||||
foreach($sessions as $s){
|
||||
$e = new Evento();
|
||||
$diccionario = self::session2dictionary($s);
|
||||
$e = $e->asignaDesdeDiccionario($diccionario);
|
||||
$result[] = $e;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Busca un evento con id $idEvento.
|
||||
*
|
||||
* @param int $idEvento Id del evento a buscar.
|
||||
*
|
||||
* @return Evento Evento encontrado.
|
||||
*/
|
||||
public static function buscaPorId(int $idEvento, $idhall, $cinema)
|
||||
{
|
||||
if (!$idEvento) {
|
||||
throw new \BadMethodCallException('$idEvento no puede ser nulo.');
|
||||
}
|
||||
|
||||
$result = null;
|
||||
$app = App::getSingleton();
|
||||
$conn = $app->conexionBd();
|
||||
$query = sprintf("SELECT E.id, E.title, E.userId, E.startDate AS start, E.endDate AS end FROM Eventos E WHERE E.id = %d", $idEvento);
|
||||
$rs = $conn->query($query);
|
||||
if ($rs && $rs->num_rows == 1) {
|
||||
while($fila = $rs->fetch_assoc()) {
|
||||
$result = new Evento();
|
||||
$result->asignaDesdeDiccionario($fila);
|
||||
}
|
||||
$rs->free();
|
||||
} else {
|
||||
if ($conn->affected_rows == 0) {
|
||||
throw new EventoNoEncontradoException("No se ha encontrado el evento: ".$idEvento);
|
||||
}
|
||||
throw new DataAccessException("Se esperaba 1 evento y se han obtenido: ".$rs->num_rows);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Busca los eventos de un usuario con id $userId en el rango de fechas $start y $end (si se proporciona).
|
||||
*
|
||||
* @param int $userId Id del usuario para el que se buscarán los eventos.
|
||||
* @param string $start Fecha a partir de la cual se buscarán eventos (@link MYSQL_DATE_TIME_FORMAT)
|
||||
* @param string|null $end Fecha hasta la que se buscarán eventos (@link MYSQL_DATE_TIME_FORMAT)
|
||||
*
|
||||
* @return array[Evento] Lista de eventos encontrados.
|
||||
*/
|
||||
public static function buscaEntreFechas(int $userId, string $start, string $end = null, $idhall, $cinema)
|
||||
{
|
||||
if (!$userId) {
|
||||
//throw new \BadMethodCallException('$userId no puede ser nulo.');
|
||||
}
|
||||
|
||||
$startDate = \DateTime::createFromFormat(self::MYSQL_DATE_TIME_FORMAT, $start);
|
||||
if (!$startDate) {
|
||||
// throw new \BadMethodCallException('$diccionario[\'start\'] no sigue el formato válido: '.self::MYSQL_DATE_TIME_FORMAT);
|
||||
}
|
||||
|
||||
$endDate = null;
|
||||
if ($end) {
|
||||
$endDate = \DateTime::createFromFormat(self::MYSQL_DATE_TIME_FORMAT, $end);
|
||||
if (!$endDate) {
|
||||
// throw new \BadMethodCallException('$diccionario[\'end\'] no sigue el formato válido: '.self::MYSQL_DATE_TIME_FORMAT);
|
||||
}
|
||||
}
|
||||
|
||||
if ($endDate) {
|
||||
|
||||
}
|
||||
|
||||
$result = [];
|
||||
|
||||
$sessions = Session::getListSessionsBetween2Dates($idhall,$cinema,$startDate,$endDate);
|
||||
|
||||
foreach($sessions as $s){
|
||||
$e = new Evento();
|
||||
$diccionario = self::session2dictionary($s);
|
||||
$e = $e->asignaDesdeDiccionario($diccionario);
|
||||
$result[] = $e;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Guarda o actualiza un evento $evento en la BD.
|
||||
*
|
||||
* @param Evento $evento Evento a guardar o actualizar.
|
||||
*/
|
||||
public static function guardaOActualiza(Evento $evento)
|
||||
{
|
||||
if (!$evento) {
|
||||
throw new \BadMethodCallException('$evento no puede ser nulo.');
|
||||
}
|
||||
$result = false;
|
||||
$app = App::getSingleton();
|
||||
$conn = $app->conexionBd();
|
||||
if (!$evento->id) {
|
||||
$query = sprintf("INSERT INTO Eventos (userId, title, startDate, endDate) VALUES (%d, '%s', '%s', '%s')"
|
||||
, $evento->userId
|
||||
, $conn->real_escape_string($evento->title)
|
||||
, $evento->start->format(self::MYSQL_DATE_TIME_FORMAT)
|
||||
, $evento->end->format(self::MYSQL_DATE_TIME_FORMAT));
|
||||
|
||||
$result = $conn->query($query);
|
||||
if ($result) {
|
||||
$evento->id = $conn->insert_id;
|
||||
$result = $evento;
|
||||
} else {
|
||||
throw new DataAccessException("No se ha podido guardar el evento");
|
||||
}
|
||||
} else {
|
||||
$query = sprintf("UPDATE Eventos E SET userId=%d, title='%s', startDate='%s', endDate='%s' WHERE E.id = %d"
|
||||
, $evento->userId
|
||||
, $conn->real_escape_string($evento->title)
|
||||
, $evento->start->format(self::MYSQL_DATE_TIME_FORMAT)
|
||||
, $evento->end->format(self::MYSQL_DATE_TIME_FORMAT)
|
||||
, $evento->id);
|
||||
$result = $conn->query($query);
|
||||
if ($result) {
|
||||
$result = $evento;
|
||||
} else {
|
||||
throw new DataAccessException("Se han actualizado más de 1 fila cuando sólo se esperaba 1 actualización: ".$conn->affected_rows);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Borra un evento id $idEvento.
|
||||
*
|
||||
* @param int $idEvento Id del evento a borrar.
|
||||
*
|
||||
*/
|
||||
public static function borraPorId(int $idEvento)
|
||||
{
|
||||
if (!$idEvento) {
|
||||
throw new \BadMethodCallException('$idEvento no puede ser nulo.');
|
||||
}
|
||||
$result = false;
|
||||
$app = App::getSingleton();
|
||||
$conn = $app->conexionBd();
|
||||
$query = sprintf('DELETE FROM Eventos WHERE id=%d', $idEvento);
|
||||
$result = $conn->query($query);
|
||||
if ($result && $conn->affected_rows == 1) {
|
||||
$result = true;
|
||||
} else {
|
||||
if ($conn->affected_rows == 0) {
|
||||
throw new EventoNoEncontradoException("No se ha encontrado el evento: ".$idEvento);
|
||||
}
|
||||
throw new DataAccessException("Se esperaba borrar 1 fila y se han borrado: ".$conn->affected_rows);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crear un evento asociado a un usuario $userId y un título $title.
|
||||
* El comienzo es la fecha y hora actual del sistema y el fin es una hora más tarde.
|
||||
*
|
||||
* @param int $userId Id del propietario del evento.
|
||||
* @param string $title Título del evento.
|
||||
*
|
||||
*/
|
||||
public static function creaSimple(int $userId, string $title)
|
||||
{
|
||||
$start = new \DateTime();
|
||||
$end = $start->add(new \DateInterval('PT1H'));
|
||||
return self::creaDetallado($userId, $title, $start, $end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crear un evento asociado a un usuario $userId, un título $title y una fecha y hora de comienzo.
|
||||
* El fin es una hora más tarde de la hora de comienzo.
|
||||
*
|
||||
* @param int $userId Id del propietario del evento.
|
||||
* @param string $title Título del evento.
|
||||
* @param DateTime $start Fecha y horas de comienzo.
|
||||
*/
|
||||
public static function creaComenzandoEn(int $userId, string $title, \DateTime $start)
|
||||
{
|
||||
if (empty($start)) {
|
||||
throw new \BadMethodCallException('$start debe ser un timestamp valido no nulo');
|
||||
}
|
||||
|
||||
$end = $start->add(new \DateInterval('PT1H'));
|
||||
return self::creaDetallado($userId, $title, $start, $end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crear un evento asociado a un usuario $userId, un título $title y una fecha y hora de comienzo y fin.
|
||||
*
|
||||
* @param int $userId Id del propietario del evento.
|
||||
* @param string $title Título del evento.
|
||||
* @param DateTime $start Fecha y horas de comienzo.
|
||||
* @param DateTime $end Fecha y horas de fin.
|
||||
*/
|
||||
public static function creaDetallado(int $userId, string $title, \DateTime $start, \DateTime $end)
|
||||
{
|
||||
$e = new Evento();
|
||||
$e->setUserId($userId);
|
||||
$e->setTitle($title);
|
||||
$e->setStart($start);
|
||||
$e->setEnd($end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crear un evento un evento a partir de un diccionario PHP.
|
||||
* Como por ejemplo array("userId" => (int)1, "title" => "Descripcion"
|
||||
* , "start" => "2019-04-29 00:00:00", "end" => "2019-04-30 00:00:00")
|
||||
*
|
||||
* @param array $diccionario Array / map / diccionario PHP con los datos del evento a crear.
|
||||
*
|
||||
* @return Evento Devuelve el evento creado.
|
||||
*/
|
||||
public static function creaDesdeDicionario(array $diccionario)
|
||||
{
|
||||
$e = new Evento();
|
||||
$e->asignaDesdeDiccionario($diccionario, ['userId', 'title', 'start', 'end']);
|
||||
return $e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprueba si $start y $end son fechas y además $start es anterior a $end.
|
||||
*/
|
||||
private static function compruebaConsistenciaFechas(\DateTime $start, \DateTime $end)
|
||||
{
|
||||
if (!$start) {
|
||||
throw new \BadMethodCallException('$start no puede ser nula');
|
||||
}
|
||||
|
||||
if (!$end) {
|
||||
throw new \BadMethodCallException('$end no puede ser nula');
|
||||
}
|
||||
|
||||
if ($start >= $end) {
|
||||
throw new \BadMethodCallException('La fecha de comienzo $start '.$start->format("Y-m-d H:i:s").' no puede ser posterior a la de fin $end '.$end->format("Y-m-d H:i:s"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int Longitud máxima del título de un evento.
|
||||
*/
|
||||
const TITLE_MAX_SIZE = 255;
|
||||
|
||||
/**
|
||||
* @param string Formato de fecha y hora compatible con MySQL.
|
||||
*/
|
||||
const MYSQL_DATE_TIME_FORMAT= 'Y-m-d H:i:s';
|
||||
|
||||
/**
|
||||
* @param array[string] Nombre de las propiedades de la clase.
|
||||
*/
|
||||
const PROPERTIES = ['id', 'userId', 'title', 'start', 'end', 'idfilm'];
|
||||
//'idfilm','idhall','idcinema','date', 'start_time', 'seat_price', 'format', 'seats_full'];
|
||||
|
||||
private $id;
|
||||
private $userId;
|
||||
private $title;
|
||||
private $start;
|
||||
private $end;
|
||||
|
||||
private $idfilm;
|
||||
|
||||
|
||||
/*
|
||||
private $idhall;
|
||||
private $idcinema;
|
||||
private $date;
|
||||
private $start_time;
|
||||
private $seat_price;
|
||||
private $format;
|
||||
private $seats_full;*/
|
||||
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getUserId()
|
||||
{
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
public function setUserId(int $userId)
|
||||
{
|
||||
if (is_null($userId)) {
|
||||
throw new \BadMethodCallException('$userId no puede ser una cadena vacía o nulo');
|
||||
}
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setTitle(string $title)
|
||||
{
|
||||
if (is_null($title)) {
|
||||
throw new \BadMethodCallException('$title no puede ser una cadena vacía o nulo');
|
||||
}
|
||||
|
||||
if (mb_strlen($title) > self::TITLE_MAX_SIZE) {
|
||||
throw new \BadMethodCallException('$title debe tener como longitud máxima: '.self::TITLE_MAX_SIZE);
|
||||
}
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function getStart()
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
public function setStart(\DateTime $start)
|
||||
{
|
||||
if (empty($start)) {
|
||||
throw new \BadMethodCallException('$start debe ser un timestamp valido no nulo');
|
||||
}
|
||||
if (! is_null($this->end) ) {
|
||||
self::compruebaConsistenciaFechas($start, $this->end);
|
||||
}
|
||||
$this->start = $start;
|
||||
}
|
||||
|
||||
public function getEnd()
|
||||
{
|
||||
if (empty($end)) {
|
||||
throw new \BadMethodCallException('$end debe ser un timestamp valido no nulo');
|
||||
}
|
||||
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
public function setEnd(\DateTime $end)
|
||||
{
|
||||
if (empty($end)) {
|
||||
throw new \BadMethodCallException('$end debe ser un timestamp valido no nulo');
|
||||
}
|
||||
|
||||
self::compruebaConsistenciaFechas($this->start, $end);
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
public function __get($property)
|
||||
{
|
||||
if (property_exists($this, $property)) {
|
||||
return $this->$property;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Método utilizado por la función de PHP json_encode para serializar un objeto que no tiene atributos públicos.
|
||||
*
|
||||
* @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);
|
||||
return $o;
|
||||
}
|
||||
|
||||
public static function session2dictionary($session){
|
||||
$extraDurationBetweenFilms = 10;
|
||||
|
||||
$film = Session::getThisSessionFilm($session->getIdfilm());
|
||||
$dur = $film["duration"]+$extraDurationBetweenFilms;
|
||||
|
||||
$tittle = str_replace('_', ' ', $film["tittle"]) ;
|
||||
$start = $session->getDate()." ".$session->getStartTime();
|
||||
|
||||
$end = date('Y-m-d H:i:s', strtotime( $start . ' +'.$dur.' minute'));
|
||||
|
||||
$dictionary = array(
|
||||
"id" => $session->getId(),
|
||||
"userId" => "80",
|
||||
"title" => $tittle,
|
||||
"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(),*/
|
||||
);
|
||||
|
||||
return $dictionary;
|
||||
}
|
||||
/**
|
||||
* Actualiza este evento a partir de un diccionario PHP. No todas las propiedades tienen que actualizarse.
|
||||
* Por ejemplo el array("title" => "Nueva descripcion", "end" => "2019-04-30 00:00:00") sólo actualiza las
|
||||
* propiedades "title" y "end".
|
||||
*
|
||||
* @param array $diccionario Array / map / diccionario PHP con los datos del evento a actualizar.
|
||||
* @param array[string] $propiedadesAIgnorar Nombre de propiedades que se ignorarán, y no se actualizarán, si se
|
||||
* encuentran en $diccionario.
|
||||
*
|
||||
*/
|
||||
public function actualizaDesdeDiccionario(array $diccionario, array $propiedadesAIgnorar = [])
|
||||
{
|
||||
$propiedadesAIgnorar[] = 'id';
|
||||
|
||||
foreach($propiedadesAIgnorar as $prop) {
|
||||
if( isset($diccionario[$prop]) ) {
|
||||
unset($diccionario[$prop]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->asignaDesdeDiccionario($diccionario);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualiza este evento a partir de un diccionario PHP. No todas las propiedades tienen que actualizarse, aunque son
|
||||
* obligatorias las propiedades cuyo nombre se incluyan en $propiedadesRequeridas.
|
||||
*
|
||||
* @param array $diccionario Array / map / diccionario PHP con los datos del evento a actualizar.
|
||||
* @param array[string] $propiedadesRequeridas Nombre de propiedades que se requieren actualizar. Si no existen en
|
||||
* $diccionario, se lanza BadMethodCallException.
|
||||
*
|
||||
*/
|
||||
protected function asignaDesdeDiccionario(array $diccionario, array $propiedadesRequeridas = [])
|
||||
{
|
||||
foreach($diccionario as $key => $val) {
|
||||
if (!in_array($key, self::PROPERTIES)) {
|
||||
throw new \BadMethodCallException('Propiedad no esperada en $diccionario: '.$key);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($propiedadesRequeridas as $prop) {
|
||||
if( ! isset($diccionario[$prop]) ) {
|
||||
throw new \BadMethodCallException('El array $diccionario debe tener las propiedades: '.implode(',', $propiedadesRequeridas));
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('id', $diccionario)) {
|
||||
$id = $diccionario['id'];
|
||||
if (empty($id)) {
|
||||
throw new \BadMethodCallException('$diccionario[\'id\'] no puede ser una cadena vacía o nulo');
|
||||
} else if (! ctype_digit($id)) {
|
||||
throw new \BadMethodCallException('$diccionario[\'id\'] tiene que ser un número entero');
|
||||
} else {
|
||||
$this->id =(int)$id;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('userId', $diccionario)) {
|
||||
$userId = $diccionario['userId'];
|
||||
if (empty($userId)) {
|
||||
throw new \BadMethodCallException('$diccionario[\'userId\'] no puede ser una cadena vacía o nulo');
|
||||
} else if (!is_int($userId) && ! ctype_digit($userId)) {
|
||||
throw new \BadMethodCallException('$diccionario[\'userId\'] tiene que ser un número entero: '.$userId);
|
||||
} else {
|
||||
$this->setUserId((int)$userId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (array_key_exists('title', $diccionario)) {
|
||||
$title = $diccionario['title'];
|
||||
if (is_null($title)) {
|
||||
throw new \BadMethodCallException('$diccionario[\'title\'] no puede ser una cadena vacía o nulo');
|
||||
} else {
|
||||
$this->setTitle($title);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (array_key_exists('start', $diccionario)) {
|
||||
$start = $diccionario['start'];
|
||||
if (empty($start)) {
|
||||
throw new \BadMethodCallException('$diccionario[\'start\'] no puede ser una cadena vacía o nulo');
|
||||
} else {
|
||||
$startDate = \DateTime::createFromFormat(self::MYSQL_DATE_TIME_FORMAT, $start);
|
||||
if (!$startDate) {
|
||||
throw new \BadMethodCallException('$diccionario[\'start\']: '.$diccionario['start'].' no sigue el formato válido: '.self::MYSQL_DATE_TIME_FORMAT);
|
||||
}
|
||||
$this->start = $startDate;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (array_key_exists('end', $diccionario)) {
|
||||
$end = $diccionario['end'] ?? null;
|
||||
if (empty($end)) {
|
||||
throw new \BadMethodCallException('$diccionario[\'end\'] no puede ser una cadena vacía o nulo');
|
||||
} else {
|
||||
$endDate = \DateTime::createFromFormat(self::MYSQL_DATE_TIME_FORMAT, $end);
|
||||
if (!$endDate) {
|
||||
throw new \BadMethodCallException('$diccionario[\'end\']: '.$diccionario['end'].' no sigue el formato válido: '.self::MYSQL_DATE_TIME_FORMAT);
|
||||
}
|
||||
$this->end = $endDate;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('idfilm', $diccionario)) {
|
||||
$idfilm = $diccionario['idfilm'] ?? null;
|
||||
if (empty($idfilm)) {
|
||||
// throw new \BadMethodCallException('$diccionario[\'end\'] no puede ser una cadena vacía o nulo');
|
||||
} else {
|
||||
$this->idfilm = $idfilm;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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)) {
|
||||
// throw new \BadMethodCallException('$diccionario[\'end\'] no puede ser una cadena vacía o nulo');
|
||||
} else {
|
||||
$this->start_time = $start_time;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('seat_price', $diccionario)) {
|
||||
$seat_price = $diccionario['seat_price'] ?? null;
|
||||
if (empty($seat_price)) {
|
||||
// throw new \BadMethodCallException('$diccionario[\'end\'] no puede ser una cadena vacía o nulo');
|
||||
} else {
|
||||
$this->seat_price = $seat_price;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('format', $diccionario)) {
|
||||
$format = $diccionario['format'] ?? null;
|
||||
if (empty($format)) {
|
||||
// throw new \BadMethodCallException('$diccionario[\'end\'] no puede ser una cadena vacía o nulo');
|
||||
} else {
|
||||
$this->format = $format;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('seats_full', $diccionario)) {
|
||||
$seats_full = $diccionario['seats_full'] ?? null;
|
||||
if (empty($seats_full)) {
|
||||
// throw new \BadMethodCallException('$diccionario[\'end\'] no puede ser una cadena vacía o nulo');
|
||||
} else {
|
||||
$this->seats_full = $seats_full;
|
||||
}
|
||||
}*/
|
||||
|
||||
self::compruebaConsistenciaFechas($this->start, $this->end);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
138
panel_manager/eventos-FER_SURFACE.php
Normal file
138
panel_manager/eventos-FER_SURFACE.php
Normal file
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
require_once('../assets/php/config.php');
|
||||
require_once('./Evento.php');
|
||||
|
||||
// Procesamos la cabecera Content-Type
|
||||
$contentType= $_SERVER['CONTENT_TYPE'] ?? 'application/json';
|
||||
$contentType = strtolower(str_replace(' ', '', $contentType));
|
||||
|
||||
// Verificamos corresponde con uno de los tipos soportados
|
||||
$acceptedContentTypes = array('application/json;charset=utf-8', 'application/json');
|
||||
$found = false;
|
||||
foreach ($acceptedContentTypes as $acceptedContentType) {
|
||||
if (substr($contentType, 0, strlen($acceptedContentType)) === $acceptedContentType) {
|
||||
$found=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
// throw new ContentTypeNoSoportadoException('Este servicio REST sólo soporta el content-type application/json');
|
||||
}
|
||||
|
||||
$result = null;
|
||||
|
||||
/**
|
||||
* Las API REST usan la semántica de los métoods HTTP para gestionar las diferentes peticiones:
|
||||
* https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods
|
||||
*/
|
||||
switch($_SERVER['REQUEST_METHOD']) {
|
||||
// Consulta de datos
|
||||
case 'GET':
|
||||
$hall = $_GET["hall"];
|
||||
$cinema = $_SESSION["cinema"];
|
||||
// Comprobamos si es una consulta de un evento concreto -> eventos.php?idEvento=XXXXX
|
||||
$idEvento = filter_input(INPUT_GET, 'idEvento', FILTER_VALIDATE_INT);
|
||||
if ($idEvento) {
|
||||
|
||||
$result = [];
|
||||
$result[] = Evento::buscaPorId((int)$idEvento,$hall,$cinema);
|
||||
} else {
|
||||
// Comprobamos si es una lista de eventos entre dos fechas -> 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 = Evento::buscaEntreFechas(1, $startDateTime, $endDateTime, $hall,$cinema);
|
||||
} else {
|
||||
|
||||
// Comprobamos si es una lista de eventos completa
|
||||
$result = Evento::buscaTodosEventos(1, $hall,$cinema); // 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));
|
||||
|
||||
echo $json;
|
||||
break;
|
||||
// Añadir un nuevo evento
|
||||
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');
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// 4. Guardamos el evento en BD
|
||||
$result = Evento::guardaOActualiza($e);
|
||||
|
||||
// 5. Generamos un objecto como salida.
|
||||
$json = json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
|
||||
|
||||
http_response_code(201); // 201 Created
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Content-Length: ' . mb_strlen($json));
|
||||
|
||||
echo $json;
|
||||
|
||||
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
|
||||
$entityBody = file_get_contents('php://input');
|
||||
// 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');
|
||||
}
|
||||
|
||||
|
||||
// 4. Reprocesamos el cuerpo de la petición como un array PHP
|
||||
$dictionary = json_decode($entityBody, true);
|
||||
$e = Evento::buscaPorId($idEvento);
|
||||
$e->actualizaDesdeDiccionario($dictionary, ['id', 'userId']);
|
||||
$result = Evento::guardaOActualiza($e);
|
||||
|
||||
// 5. Generamos un objecto como salida.
|
||||
$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;
|
||||
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
|
||||
Evento::borraPorId($idEvento);
|
||||
|
||||
http_response_code(204); // 204 No content (como resultado)
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Content-Length: 0');
|
||||
break;
|
||||
default:
|
||||
//throw new MetodoNoSoportadoException($_SERVER['REQUEST_METHOD']. ' no está soportado');
|
||||
break;
|
||||
}
|
179
panel_manager/eventos.php
Normal file
179
panel_manager/eventos.php
Normal file
@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
require_once('../assets/php/config.php');
|
||||
require_once('./Evento.php');
|
||||
include_once($prefix.'assets/php/includes/session.php');
|
||||
|
||||
// Procesamos la cabecera Content-Type
|
||||
$contentType= $_SERVER['CONTENT_TYPE'] ?? 'application/json';
|
||||
$contentType = strtolower(str_replace(' ', '', $contentType));
|
||||
|
||||
// Verificamos corresponde con uno de los tipos soportados
|
||||
$acceptedContentTypes = array('application/json;charset=utf-8', 'application/json');
|
||||
$found = false;
|
||||
foreach ($acceptedContentTypes as $acceptedContentType) {
|
||||
if (substr($contentType, 0, strlen($acceptedContentType)) === $acceptedContentType) {
|
||||
$found=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
// throw new ContentTypeNoSoportadoException('Este servicio REST sólo soporta el content-type application/json');
|
||||
}
|
||||
|
||||
$result = null;
|
||||
|
||||
/**
|
||||
* Las API REST usan la semántica de los métoods HTTP para gestionar las diferentes peticiones:
|
||||
* https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods
|
||||
*/
|
||||
switch($_SERVER['REQUEST_METHOD']) {
|
||||
// Consulta de datos
|
||||
case 'GET':
|
||||
$hall = $_GET["hall"];
|
||||
$cinema = $_SESSION["cinema"];
|
||||
// Comprobamos si es una consulta de un evento concreto -> eventos.php?idEvento=XXXXX
|
||||
$idEvento = filter_input(INPUT_GET, 'idEvento', FILTER_VALIDATE_INT);
|
||||
if ($idEvento) {
|
||||
|
||||
$result = [];
|
||||
$result[] = Evento::buscaPorId((int)$idEvento,$hall,$cinema);
|
||||
} else {
|
||||
// Comprobamos si es una lista de eventos entre dos fechas -> 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 = Evento::buscaEntreFechas(1, $startDateTime, $endDateTime, $hall,$cinema);
|
||||
} else {
|
||||
|
||||
// Comprobamos si es una lista de eventos completa
|
||||
$result = Evento::buscaTodosEventos(1, $hall,$cinema); // 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));
|
||||
|
||||
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');
|
||||
$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"} ?? "";
|
||||
|
||||
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.';
|
||||
|
||||
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, $idfilm, $price, $format);
|
||||
|
||||
if(strcmp($msg,$correct_response)!== 0)
|
||||
$errors['price'] = $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;
|
||||
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
|
||||
$entityBody = file_get_contents('php://input');
|
||||
// 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');
|
||||
}
|
||||
|
||||
|
||||
// 4. Reprocesamos el cuerpo de la petición como un array PHP
|
||||
$dictionary = json_decode($entityBody, true);
|
||||
$e = Evento::buscaPorId($idEvento);
|
||||
$e->actualizaDesdeDiccionario($dictionary, ['id', 'userId']);
|
||||
$result = Evento::guardaOActualiza($e);
|
||||
|
||||
// 5. Generamos un objecto como salida.
|
||||
$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;
|
||||
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
|
||||
Evento::borraPorId($idEvento);
|
||||
|
||||
http_response_code(204); // 204 No content (como resultado)
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Content-Length: 0');
|
||||
break;
|
||||
default:
|
||||
//throw new MetodoNoSoportadoException($_SERVER['REQUEST_METHOD']. ' no está soportado');
|
||||
break;
|
||||
}
|
258
panel_manager/eventsProcess.php
Normal file
258
panel_manager/eventsProcess.php
Normal file
@ -0,0 +1,258 @@
|
||||
<?php
|
||||
require_once('../assets/php/config.php');
|
||||
include_once($prefix.'assets/php/includes/event.php');
|
||||
include_once($prefix.'assets/php/includes/session.php');
|
||||
|
||||
$contentType= $_SERVER['CONTENT_TYPE'] ?? 'application/json';
|
||||
$contentType = strtolower(str_replace(' ', '', $contentType));
|
||||
|
||||
// Verify the content type is supported
|
||||
$acceptedContentTypes = array('application/json;charset=utf-8', 'application/json');
|
||||
$found = false;
|
||||
foreach ($acceptedContentTypes as $acceptedContentType) {
|
||||
if (substr($contentType, 0, strlen($acceptedContentType)) === $acceptedContentType) {
|
||||
$found=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch($_SERVER['REQUEST_METHOD']) {
|
||||
// Get Events
|
||||
case 'GET':
|
||||
|
||||
$hall = $_GET["hall"];
|
||||
$cinema = $_SESSION["cinema"];
|
||||
|
||||
$start = $_GET["start"];
|
||||
$end = $_GET["end"];
|
||||
|
||||
if ($start) {
|
||||
$result = Event::searchEventsBetween2dates($start, $end, $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':
|
||||
|
||||
$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;
|
||||
}
|
95
panel_manager/includes/NewSessionForm.php
Normal file
95
panel_manager/includes/NewSessionForm.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
require_once($prefix.'assets/php/includes/film_dao.php');
|
||||
|
||||
class NewSessionForm {
|
||||
|
||||
public static function getForm(){
|
||||
$films = new Film_DAO("complucine");
|
||||
$filmslist = $films->allFilmData();
|
||||
|
||||
$form='
|
||||
<div id="operation_msg" class="operation_msg"> </div>
|
||||
<form id="new_session_form" name="new_session_form" action="eventos.php.php" method="POST">
|
||||
<div id="global_group" class="form_group"></div>
|
||||
<fieldset>
|
||||
<legend>Datos</legend>
|
||||
<div id="price_group" class="form_group">
|
||||
<input type="number" step="0.01" id="price" name="price" value="" min="0" placeholder="Precio de la entrada" /> <br>
|
||||
</div>
|
||||
<div id="format_group" class="form_group">
|
||||
<input type="text" id="format" name="format" value="" placeholder="Formato de pelicula" /> <br>
|
||||
</div>
|
||||
<div id="hall_group" class="form_group">
|
||||
<select id="hall" name="hall" class="button large">>';
|
||||
foreach(Hall::getListHalls($_SESSION["cinema"]) as $hll){
|
||||
$form.= '
|
||||
<option value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
|
||||
}
|
||||
$form.=' </select>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Horario</legend>
|
||||
<div id="date_group" class="form_group">
|
||||
<div class="two-inputs-line">
|
||||
<label> Fecha inicio </label>
|
||||
<label> Fecha final </label>
|
||||
<input type="date" id="startDate" name="startDate" value=""/>
|
||||
<input type="date" id="endDate" name="endDate" value=""/>
|
||||
</div>
|
||||
</div>
|
||||
<div id="hour_group" class="form_group">
|
||||
<div class="one-input-line">
|
||||
<label> Hora sesion </label>
|
||||
<input type="time" id="startHour" name="startHour" value=""/>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<input type="reset" id="reset" value="Limpiar Campos" >
|
||||
<input type="submit" id="submit" name="sumbit" class="primary" value="Crear" />
|
||||
<div id="film_msg_group" class="form_group"> </div>
|
||||
<div id="film_group" class="form_group">
|
||||
<div class="code showtimes">
|
||||
<input type="hidden" id="film_id" name="film_id" value=""/>
|
||||
<h2 id="film_title"> titulo </h2>
|
||||
<hr />
|
||||
<div class="img_desc">
|
||||
<div class="image"> <img src="../img/films/iron_man.jpg" alt="iron man" id="film_img" /> </div>
|
||||
<div class="blockquote">
|
||||
<p id="film_desc">"Un empresario millonario construye un traje blindado y lo usa para combatir el crimen y el terrorismo."</p>
|
||||
</div>
|
||||
</div>
|
||||
<li id="film_dur"> Duración: duracion minutos</li>
|
||||
<li id="film_lan"> Lenguaje: idioma </li>
|
||||
</div>
|
||||
<button type="button" class="button large" id="return"> Cambiar pelicula </button>
|
||||
</div>
|
||||
<div class="film_list" id="film_list">
|
||||
<ul class="tablelist col3">';
|
||||
$parity = "odd";
|
||||
$i = 0;
|
||||
foreach($filmslist as $film){
|
||||
$form .='<div class="'.$parity.'">
|
||||
<input type="hidden" value="'.$film->getId().'" id="id'.$i.'"/>
|
||||
<input type="hidden" value="'.$film->getImg().'" id="img'.$i.'"/>
|
||||
<input type="hidden" value="'.$film->getLanguage().'" id="lan'.$i.'"/>
|
||||
<input type="hidden" value="'.$film->getDescription().'" id="desc'.$i.'"/>
|
||||
<li value="'.$film->getTittle().'"id="title'.$i.'"> '. str_replace('_', ' ',$film->getTittle()).'</li>
|
||||
<li id="dur'.$i.'"> '.$film->getDuration().' min</li>
|
||||
<li> <button type="button" class="film_button" id="'.$i.'"> Seleccionar </button> </li>
|
||||
</div>
|
||||
';
|
||||
$parity = ($parity == "odd") ? "even" : "odd";
|
||||
$i++;
|
||||
}
|
||||
$form.='
|
||||
</ul>
|
||||
</div>
|
||||
</form>';
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
103
panel_manager/includes/SessionForm.php
Normal file
103
panel_manager/includes/SessionForm.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
require_once($prefix.'assets/php/includes/film_dao.php');
|
||||
|
||||
class SessionForm {
|
||||
|
||||
public static function getForm(){
|
||||
$films = new Film_DAO("complucine");
|
||||
$filmslist = $films->allFilmData();
|
||||
|
||||
$form='
|
||||
<div id="operation_msg" class="operation_msg"> </div>
|
||||
<form id="session_form" name="session_form" action="eventos.php" method="POST">
|
||||
|
||||
<input type="hidden" id="film_id" name="film_id" value=""/>
|
||||
<input type="hidden" id="original_hall" name="film_id" value=""/>
|
||||
<input type="hidden" id="original_date" name="film_id" value=""/>
|
||||
<input type="hidden" id="original_start_time" name="film_id" value=""/>
|
||||
|
||||
<div id="global_group" class="form_group"></div>
|
||||
<fieldset>
|
||||
<legend>Datos</legend>
|
||||
<div id="price_group" class="form_group">
|
||||
<input type="number" step="0.01" id="price" name="price" value="" min="0" placeholder="Precio de la entrada" /> <br>
|
||||
</div>
|
||||
<div id="format_group" class="form_group">
|
||||
<input type="text" id="format" name="format" value="" placeholder="Formato de pelicula" /> <br>
|
||||
</div>
|
||||
<div id="hall_group" class="form_group">
|
||||
<select id="hall" name="hall" class="button large">>';
|
||||
foreach(Hall::getListHalls($_SESSION["cinema"]) as $hll){
|
||||
$form.= '
|
||||
<option value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
|
||||
}
|
||||
$form.=' </select>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Horario</legend>
|
||||
<div id="date_group" class="form_group">
|
||||
<div class="two-inputs-line">
|
||||
<label> Fecha inicio </label>
|
||||
<label> Fecha final </label>
|
||||
<input type="date" id="startDate" name="startDate" value=""/>
|
||||
<input type="date" id="endDate" name="endDate" value=""/>
|
||||
</div>
|
||||
</div>
|
||||
<div id="hour_group" class="form_group">
|
||||
<div class="one-input-line">
|
||||
<label> Hora sesion </label>
|
||||
<input type="time" id="startHour" name="startHour" value=""/>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<input type="reset" id="reset" value="Limpiar Campos" >
|
||||
<input type="submit" id="sumbit_new" name="sumbit_new" class="sumbit" value="Añadir" />
|
||||
<div class="two-inputs-line" id="edit_inputs">
|
||||
<input type="submit" id="sumbit_edit" name="sumbit_edit" class="sumbit" value="Editar" />
|
||||
<input type="submit" id="submit_del" name="submit_del" class="black button" value="Borrar" />
|
||||
</div>
|
||||
<div id="film_msg_group" class="form_group"> </div>
|
||||
<div id="film_group" class="form_group">
|
||||
<div class="code showtimes">
|
||||
<h2 id="film_title"> titulo </h2>
|
||||
<hr />
|
||||
<div class="img_desc">
|
||||
<div class="image"> <img src="../img/films/iron_man.jpg" alt="iron man" id="film_img" /> </div>
|
||||
<div class="blockquote">
|
||||
<li id="film_dur"> Duración: duracion minutos</li>
|
||||
<li id="film_lan"> Lenguaje: idioma </li>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="button large" id="return"> Cambiar pelicula </button>
|
||||
</div>
|
||||
<div class="film_list" id="film_list">
|
||||
<ul class="tablelist col3">';
|
||||
$parity = "odd";
|
||||
$i = 0;
|
||||
foreach($filmslist as $film){
|
||||
$form .='<div class="'.$parity.'">
|
||||
<input type="hidden" value="'.$film->getId().'" id="id'.$i.'"/>
|
||||
<input type="hidden" value="'.$film->getImg().'" id="img'.$i.'"/>
|
||||
<input type="hidden" value="'.$film->getLanguage().'" id="lan'.$i.'"/>
|
||||
<li value="'.$film->getTittle().'"id="title'.$i.'"> '. str_replace('_', ' ',$film->getTittle()).'</li>
|
||||
<li id="dur'.$i.'"> '.$film->getDuration().' min</li>
|
||||
<li> <button type="button" class="film_button" id="'.$i.'"> Seleccionar </button> </li>
|
||||
</div>
|
||||
';
|
||||
$parity = ($parity == "odd") ? "even" : "odd";
|
||||
$i++;
|
||||
}
|
||||
$form.='
|
||||
</ul>
|
||||
</div>
|
||||
</form>
|
||||
';
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
220
panel_manager/includes/formHall-FER_SURFACE.php
Normal file
220
panel_manager/includes/formHall-FER_SURFACE.php
Normal file
@ -0,0 +1,220 @@
|
||||
<?php
|
||||
include_once($prefix.'assets/php/includes/hall.php');
|
||||
include_once($prefix.'assets/php/includes/seat.php');
|
||||
include_once($prefix.'assets/php/form.php');
|
||||
|
||||
class FormHall extends Form {
|
||||
|
||||
private $option;
|
||||
private $cinema;
|
||||
private $og_hall;
|
||||
|
||||
//Constructor:
|
||||
public function __construct($option, $cinema, $hall) {
|
||||
|
||||
$this->option = $option;
|
||||
$this->cinema = $cinema;
|
||||
if($hall)
|
||||
$this->og_hall = $hall;
|
||||
|
||||
if($option == "edit_hall")
|
||||
$options = array("action" => "./?state=".$option."&number=".$hall->getNumber()."&editing");
|
||||
else
|
||||
$options = array("action" => "./?state=".$option."&number=".$hall->getNumber()."");
|
||||
parent::__construct('formHall',$options);
|
||||
}
|
||||
|
||||
protected function generaCamposFormulario($data, $errores = array()){
|
||||
//Prepare the data
|
||||
$number = $data['number'] ?? $this->og_hall->getNumber() ?? "";
|
||||
$rows = $data['rows'] ?? $this->og_hall->getNumRows() ?? "12";
|
||||
$cols = $data['cols'] ?? $this->og_hall->getNumCol() ?? "8";
|
||||
|
||||
//Seats_map
|
||||
$seats = 0;
|
||||
$seats_map = array();
|
||||
for($i = 1;$i <= $rows; $i++){
|
||||
for($j = 1; $j <= $cols; $j++){
|
||||
$seats_map[$i][$j] = "-1";
|
||||
}
|
||||
}
|
||||
$alltozero = $_POST["alltozero"] ?? 0;
|
||||
//Show the original seats_map once u click restart or the first time u enter this form from manage_halls's form
|
||||
if($this->option == "edit_hall" && !isset($_GET["editing"])){
|
||||
$rows = $this->og_hall->getNumRows();
|
||||
$cols = $this->og_hall->getNumCol();
|
||||
$seat_list = Seat::getSeatsMap($this->og_hall->getNumber(), $this->cinema);
|
||||
if($seat_list){
|
||||
foreach($seat_list as $seat){
|
||||
$seats_map[$seat->getNumRows()][$seat->getNumCol()] = $seat->getState();
|
||||
if($seat->getState()>=0){
|
||||
$seats++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}//Show the checkbox seats_map updated and everything to selected if alltoone was pressed
|
||||
else if(!$alltozero){
|
||||
$alltoone = $_POST["alltoone"] ?? 0;
|
||||
for($i = 1;$i <= $rows; $i++){
|
||||
for($j = 1; $j <= $cols; $j++){
|
||||
if($alltoone || isset($data["checkbox".$i.$j])) {
|
||||
$seats_map[$i][$j] = $data["checkbox".$i.$j] ?? "0";
|
||||
$seats++;
|
||||
if($seats_map[$i][$j] == "-1"){
|
||||
$seats_map[$i][$j] = "0";
|
||||
}
|
||||
}else
|
||||
$seats_map[$i][$j] = "-1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$htmlErroresGlobales = self::generaListaErroresGlobales($errores);
|
||||
$errorNumber = self::createMensajeError($errores, 'number', 'span', array('class' => 'error'));
|
||||
$errorSeats = self::createMensajeError($errores, 'seats', 'span', array('class' => 'error'));
|
||||
$errorRows = self::createMensajeError($errores, 'rows', 'span', array('class' => 'error'));
|
||||
$errorCols = self::createMensajeError($errores, 'cols', 'span', array('class' => 'error'));
|
||||
|
||||
$html = '
|
||||
<div class="column left">'.$htmlErroresGlobales.'
|
||||
<fieldset>
|
||||
<legend>Mapa de Asientos</legend>
|
||||
'.$errorSeats.' '.$errorRows.' '.$errorCols.'
|
||||
<label> Filas: </label> <input type="number" name="rows" min="1" id="rows" value="'.$rows.'" /> <br>
|
||||
<label> Columnas: </label> <input type="number" name="cols" min="1" id="cols" value="'.$cols.'"/> <br>
|
||||
<label> Asientos totales:'.$seats.' </label> <input type="hidden" name="seats" id="seats" value="'.$seats.'"readonly/> <br>
|
||||
<input type="submit" name="filter" value="Actualizar mapa de la sala" class="button large" />
|
||||
';
|
||||
if($this->option == "edit_hall")
|
||||
$html .= ' <input type="submit" id="restart" name="restart" value="Restaurar mapa original" class="black button" />';
|
||||
$html .='
|
||||
</fieldset><br>
|
||||
'.$errorNumber.'
|
||||
<label> Numero de sala: </label>
|
||||
<input type="number" name="number" id="number" value="'.$number.'" placeholder="Numero de la Sala" /><br>
|
||||
';
|
||||
if($this->option == "new_hall")
|
||||
$html .='<input type="submit" id="submit" name="sumbit" value="Crear Sala" class="primary" />
|
||||
';
|
||||
if($this->option == "edit_hall"){
|
||||
$html .='<input type="submit" id="submit" name="sumbit" value="Editar Sala" class="primary" />
|
||||
<input type="submit" id="submit" name="delete" onclick="return confirm(\'Seguro que quieres borrar esta sala?\')" value="Eliminar Sala" class="black button" />
|
||||
';
|
||||
}
|
||||
if(!$errorCols && !$errorRows){
|
||||
$html .='</div>
|
||||
<div class="column right">
|
||||
<input type="submit" name="alltoone" value="Activar todos los asientos" class="button large" />
|
||||
<input type="submit" name="alltozero" value="Desactivar todos los asientos" class="button large" />
|
||||
<h3 class="table_title"> Pantalla </h3>
|
||||
<table class="seat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
';
|
||||
for($j = 1; $j<=$cols; $j++){
|
||||
$html .= '<th>'.$j.'</th>
|
||||
';
|
||||
}
|
||||
$html .= '</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
for($i = 1;$i<=$rows;$i++){
|
||||
$html .= '
|
||||
<tr>
|
||||
<td>'.$i.'</td>
|
||||
';
|
||||
for($j=1; $j<=$cols; $j++){
|
||||
if($seats_map[$i][$j]>=0){
|
||||
$html .= '<td> <input type="checkbox" class="check_box" name="checkbox'.$i.$j.'" value="'.$seats_map[$i][$j].'" id="checkbox'.$i.$j.'" checked> <label for="checkbox'.$i.$j.'"> </td>
|
||||
';}
|
||||
else {
|
||||
$html .= '<td> <input type="checkbox" class="check_box" name="checkbox'.$i.$j.'" value="'.$seats_map[$i][$j].'" id="checkbox'.$i.$j.'" > <label for="checkbox'.$i.$j.'"> </td>
|
||||
';}
|
||||
}
|
||||
$html .='</tr>';
|
||||
}
|
||||
|
||||
$html .= '
|
||||
</tbody>
|
||||
</table>
|
||||
</div>';
|
||||
} else
|
||||
$html .='</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
//Methods:
|
||||
|
||||
//Process form:
|
||||
protected function procesaFormulario($datos){
|
||||
$result = array();
|
||||
|
||||
$rows = $datos['rows'];
|
||||
$cols = $datos['cols'];
|
||||
|
||||
//Prepare the seat_map
|
||||
$seats_map = array();
|
||||
$seats = 0;
|
||||
for($i = 1;$i <= $rows; $i++){
|
||||
for($j = 1; $j <= $cols; $j++){
|
||||
if(isset($datos["checkbox".$i.$j])){
|
||||
$seats_map[$i][$j] = $datos["checkbox".$i.$j];
|
||||
$seats++;
|
||||
if($seats_map[$i][$j] == "-1"){
|
||||
$seats_map[$i][$j] = "0";
|
||||
}
|
||||
}else{
|
||||
$seats_map[$i][$j] = "-1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($seats == 0 && isset($datos["sumbit"]) ) {
|
||||
$result['seats'] = "<li> No puede haber 0 asientos disponibles. </li> <br>";
|
||||
}
|
||||
|
||||
if ($rows <= 0) {
|
||||
$result['rows'] = "<li> No puede haber 0 o menos filas. </li> <br>";
|
||||
}
|
||||
|
||||
if ($cols <= 0) {
|
||||
$result['cols'] = "<li> No puede haber 0 o menos columnas. </li> <br>";
|
||||
}
|
||||
|
||||
|
||||
$number = $datos['number'] ?? null;
|
||||
if (empty($number) && isset($datos["sumbit"])) {
|
||||
$result['number'] = "<li> El numero de sala tiene que ser mayor que 0. </li> <br>";
|
||||
}
|
||||
|
||||
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);
|
||||
return $result = './?state=success';
|
||||
}
|
||||
if($this->option == "edit_hall"){
|
||||
$_SESSION['msg'] = Hall::edit_hall($number,$this->cinema, $rows, $cols, $seats, $seats_map, $this->og_hall->getNumber());
|
||||
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());
|
||||
return $result = './?state=success';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
226
panel_manager/includes/formHall.php
Normal file
226
panel_manager/includes/formHall.php
Normal file
@ -0,0 +1,226 @@
|
||||
<?php
|
||||
include_once($prefix.'assets/php/includes/hall.php');
|
||||
include_once($prefix.'assets/php/includes/seat.php');
|
||||
include_once($prefix.'assets/php/form.php');
|
||||
|
||||
class FormHall extends Form {
|
||||
|
||||
private $option;
|
||||
private $cinema;
|
||||
private $og_hall;
|
||||
|
||||
//Constructor:
|
||||
public function __construct($option, $cinema, $hall) {
|
||||
|
||||
$this->option = $option;
|
||||
$this->cinema = $cinema;
|
||||
if($hall)
|
||||
$this->og_hall = $hall;
|
||||
|
||||
if($option == "edit_hall" && $hall)
|
||||
$options = array("action" => "./?state=".$option."&number=".$hall->getNumber()."&editing=true");
|
||||
else
|
||||
$options = array("action" => "./?state=".$option."&editing=false");
|
||||
parent::__construct('formHall',$options);
|
||||
}
|
||||
|
||||
protected function generaCamposFormulario($data, $errores = array()){
|
||||
//Prepare the data
|
||||
$number = $data['number'] ?? $this->og_hall->getNumber() ?? "";
|
||||
$rows = $data['rows'] ?? $this->og_hall->getNumRows() ?? "12";
|
||||
$cols = $data['cols'] ?? $this->og_hall->getNumCol() ?? "8";
|
||||
|
||||
//Init Seats_map
|
||||
$seats = 0;
|
||||
$seats_map = array();
|
||||
for($i = 1;$i <= $rows; $i++){
|
||||
for($j = 1; $j <= $cols; $j++){
|
||||
$seats_map[$i][$j] = "-1";
|
||||
}
|
||||
}
|
||||
$alltozero = $_POST["alltozero"] ?? 0;
|
||||
//Show the original seats_map once u click restart or the first time u enter this form from manage_halls's form
|
||||
if($this->option == "edit_hall" && !isset($_GET["editing"])){
|
||||
$rows = $this->og_hall->getNumRows();
|
||||
$cols = $this->og_hall->getNumCol();
|
||||
$seat_list = Seat::getSeatsMap($this->og_hall->getNumber(), $this->cinema);
|
||||
if($seat_list){
|
||||
foreach($seat_list as $seat){
|
||||
$seats_map[$seat->getNumRows()][$seat->getNumCol()] = $seat->getState();
|
||||
if($seat->getState()>=0){
|
||||
$seats++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}//Show the checkbox seats_map updated and everything to selected if alltoone was pressed
|
||||
else if(!$alltozero){
|
||||
$alltoone = $_POST["alltoone"] ?? 0;
|
||||
for($i = 1;$i <= $rows; $i++){
|
||||
for($j = 1; $j <= $cols; $j++){
|
||||
if($alltoone || isset($data["checkbox".$i.$j])) {
|
||||
$seats_map[$i][$j] = $data["checkbox".$i.$j] ?? "0";
|
||||
$seats++;
|
||||
if($seats_map[$i][$j] == "-1"){
|
||||
$seats_map[$i][$j] = "0";
|
||||
}
|
||||
}else
|
||||
$seats_map[$i][$j] = "-1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$htmlErroresGlobales = self::generaListaErroresGlobales($errores);
|
||||
$errorNumber = self::createMensajeError($errores, 'number', 'span', array('class' => 'error'));
|
||||
$errorSeats = self::createMensajeError($errores, 'seats', 'span', array('class' => 'error'));
|
||||
$errorRows = self::createMensajeError($errores, 'rows', 'span', array('class' => 'error'));
|
||||
$errorCols = self::createMensajeError($errores, 'cols', 'span', array('class' => 'error'));
|
||||
|
||||
$html = '
|
||||
<div class="column left">'.$htmlErroresGlobales.'
|
||||
<fieldset>
|
||||
<legend>Mapa de Asientos</legend>
|
||||
'.$errorSeats.' '.$errorRows.' '.$errorCols.'
|
||||
<label> Filas: </label> <input type="number" name="rows" min="1" id="rows" value="'.$rows.'" /> <br>
|
||||
<label> Columnas: </label> <input type="number" name="cols" min="1" id="cols" value="'.$cols.'"/> <br>
|
||||
<label> Asientos totales:'.$seats.' </label> <input type="hidden" name="seats" id="seats" value="'.$seats.'"readonly/> <br>
|
||||
<input type="submit" name="filter" value="Actualizar mapa de la sala" class="button large" />
|
||||
';
|
||||
$html .='
|
||||
</fieldset><br>
|
||||
'.$errorNumber.'
|
||||
<label> Numero de sala: </label>
|
||||
<input type="number" name="number" id="number" value="'.$number.'" placeholder="Numero de la Sala" /><br>
|
||||
';
|
||||
if($this->option == "new_hall")
|
||||
$html .='<input type="submit" id="submit" name="sumbit" value="Crear Sala" class="primary" />
|
||||
';
|
||||
if($this->option == "edit_hall"){
|
||||
$html .='<input type="submit" id="submit" name="sumbit" value="Editar Sala" class="primary" />
|
||||
<input type="submit" id="submit" name="delete" onclick="return confirm(\'Seguro que quieres borrar esta sala?\')" value="Eliminar Sala" class="black button" />
|
||||
';
|
||||
}
|
||||
if(!$errorCols && !$errorRows){
|
||||
$html .='</div>
|
||||
<div class="column right">
|
||||
<input type="submit" name="alltoone" value="Activar todos los asientos" class="button large" />
|
||||
<input type="submit" name="alltozero" value="Desactivar todos los asientos" class="button large" />
|
||||
<h3 class="table_title"> Pantalla </h3>
|
||||
<table class="seat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
';
|
||||
for($j = 1; $j<=$cols; $j++){
|
||||
$html .= '<th>'.$j.'</th>
|
||||
';
|
||||
}
|
||||
$html .= '</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
for($i = 1;$i<=$rows;$i++){
|
||||
$html .= '
|
||||
<tr>
|
||||
<td>'.$i.'</td>
|
||||
';
|
||||
for($j=1; $j<=$cols; $j++){
|
||||
if($seats_map[$i][$j]>=0){
|
||||
$html .= '<td> <input type="checkbox" class="check_box" name="checkbox'.$i.$j.'" value="'.$seats_map[$i][$j].'" id="checkbox'.$i.$j.'" checked> <label for="checkbox'.$i.$j.'"> </td>
|
||||
';}
|
||||
else {
|
||||
$html .= '<td> <input type="checkbox" class="check_box" name="checkbox'.$i.$j.'" value="'.$seats_map[$i][$j].'" id="checkbox'.$i.$j.'" > <label for="checkbox'.$i.$j.'"> </td>
|
||||
';}
|
||||
}
|
||||
$html .='</tr>';
|
||||
}
|
||||
|
||||
$html .= '
|
||||
</tbody>
|
||||
</table>
|
||||
</div>';
|
||||
} else
|
||||
$html .='</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
//Process form:
|
||||
protected function procesaFormulario($datos){
|
||||
$result = array();
|
||||
|
||||
$rows = $datos['rows'];
|
||||
$cols = $datos['cols'];
|
||||
|
||||
//Prepare the seat_map
|
||||
$seats_map = array();
|
||||
$seats = 0;
|
||||
for($i = 1;$i <= $rows; $i++){
|
||||
for($j = 1; $j <= $cols; $j++){
|
||||
if(isset($datos["checkbox".$i.$j])){
|
||||
$seats_map[$i][$j] = $datos["checkbox".$i.$j];
|
||||
$seats++;
|
||||
if($seats_map[$i][$j] == "-1"){
|
||||
$seats_map[$i][$j] = "0";
|
||||
}
|
||||
}else{
|
||||
$seats_map[$i][$j] = "-1";
|
||||
}
|
||||
}
|
||||
}
|
||||
//Check input errors
|
||||
if ($seats == 0 && isset($datos["sumbit"]) ) {
|
||||
$result['seats'] = "<li> No puede haber 0 asientos disponibles. </li> <br>";
|
||||
}
|
||||
if ($rows <= 0) {
|
||||
$result['rows'] = "<li> No puede haber 0 o menos filas. </li> <br>";
|
||||
}
|
||||
if ($cols <= 0) {
|
||||
$result['cols'] = "<li> No puede haber 0 o menos columnas. </li> <br>";
|
||||
}
|
||||
|
||||
$number = $datos['number'] ?? null;
|
||||
if (empty($number) && isset($datos["sumbit"])) {
|
||||
$result['number'] = "<li> El numero de sala tiene que ser mayor que 0. </li> <br>";
|
||||
}
|
||||
else if (count($result) === 0 && isset($datos["sumbit"]) ) {
|
||||
if($this->option == "new_hall"){
|
||||
$msg = Hall::create_hall($number, $this->cinema, $rows, $cols, $seats, $seats_map);
|
||||
FormHall::prepare_message( $msg );
|
||||
}
|
||||
else if($this->option == "edit_hall"){
|
||||
if($this->og_hall)
|
||||
$msg = Hall::edit_hall($number,$this->cinema, $rows, $cols, $seats, $seats_map, $this->og_hall->getNumber());
|
||||
else
|
||||
$msg = "La sala que intentas editar ya no existe";
|
||||
|
||||
FormHall::prepare_message( $msg );
|
||||
}
|
||||
}
|
||||
else if (!isset($result['number']) && isset($datos["delete"]) ) {
|
||||
if($this->option == "edit_hall"){
|
||||
$msg = Hall::delete_hall($number, $this->cinema, $rows, $cols, $seats, $seats_map, $this->og_hall->getNumber());
|
||||
FormHall::prepare_message( $msg );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function prepare_message( $msg ){
|
||||
$_SESSION['message'] = "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<div class='code info'>
|
||||
<h1> Operacion Completada </h1><hr />
|
||||
<p>".$msg."</p>
|
||||
<a href='./index.php?state=manage_halls'><button>Cerrar Mensaje</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class='column side'></div>
|
||||
</div>
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
170
panel_manager/includes/formSession.php
Normal file
170
panel_manager/includes/formSession.php
Normal file
@ -0,0 +1,170 @@
|
||||
<?php
|
||||
require_once($prefix.'assets/php/includes/session_dao.php');
|
||||
require_once($prefix.'assets/php/includes/session.php');
|
||||
require_once($prefix.'assets/php/form.php');
|
||||
|
||||
//Receive data from froms and prepare the correct response
|
||||
class FormSession extends Form {
|
||||
|
||||
private $option;
|
||||
private $cinema;
|
||||
private $formID;
|
||||
|
||||
//Constructor:
|
||||
public function __construct($option, $cinema) {
|
||||
$this->option = $option;
|
||||
$this->cinema = $cinema;
|
||||
$this->formID = 'formSession1';
|
||||
|
||||
$options = array("action" => "./?state=".$option);
|
||||
parent::__construct('formSession',$options);
|
||||
}
|
||||
|
||||
//TODO Edit session no funciona correctamente con el seleccionar una pelicula distinta, hay que guardar la id de la sesion de alguna forma y usarla o guardar en la sesion
|
||||
protected function generaCamposFormulario($data, $errores = array()){
|
||||
|
||||
$hall = $data['hall'] ?? $_POST["hall"] ?? "";
|
||||
$date = $data['date'] ?? $_POST["date"] ?? "";
|
||||
$start = $data['start'] ?? $_POST["start"] ?? "";
|
||||
$price = $data['price'] ?? $_POST["price"] ?? "";
|
||||
$format = $data['format'] ?? $_POST["format"] ?? "";
|
||||
|
||||
$or_hall = $data["or_hall"] ?? $hall;
|
||||
$or_date = $data["or_date"] ?? $date;
|
||||
$or_start = $data["or_start"] ?? $start;
|
||||
|
||||
$film = $data['film'] ?? $_POST["film"] ?? "";
|
||||
$tittle = $data['tittle'] ?? $_POST["tittle"] ?? "";
|
||||
$duration = $data['duration'] ?? $_POST["duration"] ?? "";
|
||||
$language = $data['language'] ?? $_POST["language"] ?? "";
|
||||
$description = $data['description'] ?? $_POST["description"] ?? "";
|
||||
|
||||
$htmlErroresGlobales = self::generaListaErroresGlobales($errores);
|
||||
$errorPrice = self::createMensajeError($errores, 'price', 'span', array('class' => 'error'));
|
||||
$errorFormat = self::createMensajeError($errores, 'format', 'span', array('class' => 'error'));
|
||||
$errorDate = self::createMensajeError($errores, 'date', 'span', array('class' => 'error'));
|
||||
$errorStart = self::createMensajeError($errores, 'start', 'span', array('class' => 'error'));
|
||||
|
||||
$html = '
|
||||
<div class="column left">'.$htmlErroresGlobales.'
|
||||
<fieldset>
|
||||
<legend>Datos</legend>
|
||||
'.$errorPrice.'
|
||||
<input type="number" step="0.01" name="price" value="'.$price.'" min="0" placeholder="Precio de la entrada" /> <br>'
|
||||
.$errorFormat.'
|
||||
<input type="text" name="format" value="'.$format.'" placeholder="Formato de pelicula" /> <br>
|
||||
<input type="hidden" name="film" value="'.$film.'"/>
|
||||
<input type="hidden" name="option" value="'.$this->option.'"/>
|
||||
<select name="hall" class="button large">';
|
||||
foreach(Hall::getListHalls($this->cinema) as $hll){
|
||||
if($hll->getNumber() == $hall){
|
||||
$html.= '
|
||||
<option value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> ';
|
||||
}else{
|
||||
$html.= '
|
||||
<option value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
|
||||
}
|
||||
}
|
||||
$html.= '
|
||||
</select>
|
||||
<input type="hidden" name="or_hall" value="'.$or_hall.'"/>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Horario</legend>
|
||||
'.$errorStart.'
|
||||
<input type="time" name="start" value="'.$start.'" placeholder="Hora de inicio"/> <br>
|
||||
<input type="hidden" name="or_start" value="'.$or_start.'"/>
|
||||
'.$errorDate.'
|
||||
<input type="date" name="date" value="'.$date.'" placeholder="Fecha de inicio" /> <br>
|
||||
<input type="hidden" name="or_date" value="'.$or_date.'"/>
|
||||
</fieldset>
|
||||
';
|
||||
if($film){
|
||||
if($this->option == "new_session")
|
||||
$html .= '<input type="number" name="repeat" value="" min="0" title="Añadir esta sesion durante los proximos X dias" min="0" max="31" placeholder="Añadir X dias"/> <br>
|
||||
<input type="submit" id="submit" name="sumbit" class="primary" value="Crear" /> <br>';
|
||||
|
||||
if($this->option == "edit_session"){
|
||||
$html .= '<input type="submit" id="submit" name="sumbit" class="primary" value="Editar" /><br>
|
||||
<input type="submit" name="delete" class="black button" onclick="return confirm(\'Seguro que quieres borrar esta sesion?\')" value="Borrar" /><br>';
|
||||
}
|
||||
}
|
||||
$html .= "
|
||||
<input type='reset' id='reset' value='Limpiar Campos' >
|
||||
</form>
|
||||
</div>
|
||||
<div class='column side'>";
|
||||
if($film){
|
||||
$html .= "<section id='".$tittle."'>
|
||||
<div class='code showtimes'>
|
||||
<div class='image'><img src='../img/films/".$tittle.".jpg' alt='".$tittle."' /></div>
|
||||
<h2>".str_replace('_', ' ',$tittle)."</h2>
|
||||
<hr />
|
||||
<div class='blockquote'>
|
||||
<p>".$description."</p>
|
||||
</div>
|
||||
<li>Duración: ".$duration." minutos</li>
|
||||
<li>Duración: ".$language." minutos</li>
|
||||
</div>
|
||||
</section>
|
||||
";
|
||||
}
|
||||
$html .= '<input type="submit" name="select_film" form="'.$this->formID.'" formaction="?state=select_film" class="button large" Value="Seleccionar una Pelicula" /><br>
|
||||
</div>
|
||||
';
|
||||
return $html;
|
||||
}
|
||||
//Methods:
|
||||
|
||||
//Process form:
|
||||
protected function procesaFormulario($data){
|
||||
$result = array();
|
||||
|
||||
$film = $data['film'] ;
|
||||
$hall = $data['hall'] ;
|
||||
$date = $data['date'] ;
|
||||
$start = $data['start'];
|
||||
$price = $data['price'] ;
|
||||
$format = $data['format'] ;
|
||||
$repeat = $data['repeat'] ?? 0;
|
||||
$or_hall = $data["or_hall"] ;
|
||||
$or_date = $data["or_date"] ;
|
||||
$or_start = $data["or_start"] ;
|
||||
|
||||
if (($price <= 0 || empty($price))&& isset($data["sumbit"]) ) {
|
||||
$result['price'] = "<li> No puede haber 0 o menos euros. </li> <br>";
|
||||
}
|
||||
|
||||
if ((empty($format))&& isset($data["sumbit"]) ) {
|
||||
$result['format'] = "<li> El formato no puede estar vacio. </li> <br>";
|
||||
}
|
||||
|
||||
if ((empty($date))&& isset($data["sumbit"]) ) {
|
||||
$result['date'] = "<li> No hay una fecha seleccionada. </li> <br>";
|
||||
}
|
||||
|
||||
if ((empty($start))&& isset($data["sumbit"]) ) {
|
||||
$result['start'] = "<li> No hay una hora inicial seleccionada. </li> <br>";
|
||||
}
|
||||
|
||||
if (count($result) === 0 && isset($data["sumbit"]) ) {
|
||||
if($this->option == "new_session"){
|
||||
$_SESSION['msg'] = Session::create_session($this->cinema, $hall, $start, $date, $film, $price, $format,$repeat);
|
||||
$result = './?state=success';
|
||||
}
|
||||
if($this->option == "edit_session"){
|
||||
$_SESSION['msg'] = Session::edit_session($this->cinema, $or_hall, $or_date, $or_start, $hall, $start, $date, $film, $price, $format);
|
||||
$result = './?state=success';
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($result['hall']) && !isset($result['start']) && !isset($result['date']) && isset($data["delete"])) {
|
||||
$_SESSION['msg'] = Session::delete_session($this->cinema, $or_hall, $or_start, $or_date);
|
||||
$result = './?state=success';
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
65
panel_manager/includes/processForm.php
Normal file
65
panel_manager/includes/processForm.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
//General Config File:
|
||||
require_once('../../assets/php/config.php');
|
||||
|
||||
$prefix ="../../";
|
||||
include_once('formHall.php');
|
||||
include_once('formSession.php');
|
||||
|
||||
if(isset($_POST['new_hall'])){
|
||||
$data = array("option" => "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);
|
||||
}
|
||||
|
||||
?>
|
197
panel_manager/index-FER_SURFACE.php
Normal file
197
panel_manager/index-FER_SURFACE.php
Normal file
@ -0,0 +1,197 @@
|
||||
<?php
|
||||
//General Config File:
|
||||
require_once('../assets/php/config.php');
|
||||
//Controller file:
|
||||
require_once('panel_manager.php');
|
||||
require_once('../assets/php/includes/manager_dao.php');
|
||||
require_once('../assets/php/includes/manager.php');
|
||||
require_once('../assets/php/includes/user.php');
|
||||
|
||||
if($_SESSION["login"] && isset($_SESSION["lastRol"]) && ($_SESSION["lastRol"] === "admin" || $_SESSION["rol"] === "manager")) {
|
||||
$manager = new Manager(null, null, null, null, null);
|
||||
if(isset($_POST['changecinema']))$_SESSION['cinema'] = $_POST['cinema'];
|
||||
|
||||
|
||||
$state = isset($_GET['state']) ? $_GET['state'] : '';
|
||||
switch($state){
|
||||
case "view_user":
|
||||
$_SESSION["rol"] = null;
|
||||
|
||||
$panel .= "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<div class='code info'>
|
||||
<h1> ¡ATENCIÓN! </h1><hr />
|
||||
<p>Está viendo la web como un Usuario NO Registrado.</p>
|
||||
<a href=''><button>Cerrar Mensaje</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class='column side'></div>
|
||||
</div>
|
||||
";
|
||||
break;
|
||||
case "view_ruser":
|
||||
$_SESSION["rol"] = "user";
|
||||
unset($_SESSION["cinema"]);
|
||||
$panel .= "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<div class='code info'>
|
||||
<h1> ¡ATENCIÓN! </h1><hr />
|
||||
<p>Está viendo la web como un Usuario Registrado.</p>
|
||||
<a href=''><button>Cerrar Mensaje</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class='column side'></div>
|
||||
</div>
|
||||
";
|
||||
break;
|
||||
case "manage_halls":
|
||||
$panel = Manager_panel::manage_halls();
|
||||
break;
|
||||
case "new_hall":
|
||||
$panel = Manager_panel::new_hall();
|
||||
break;
|
||||
case "edit_hall":
|
||||
$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":
|
||||
$panel = Manager_panel::success();
|
||||
break;
|
||||
default:
|
||||
$panel = Manager_panel::welcomeAdmin($manager);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if($_SESSION["login"] && $_SESSION["rol"] === "manager"){
|
||||
|
||||
if(!isset($_SESSION['cinema'])){
|
||||
$bd = new Manager_DAO('complucine');
|
||||
if($bd){
|
||||
$user = unserialize($_SESSION["user"]);
|
||||
$manager = $bd->GetManager($user->getId());
|
||||
$manager = $manager->fetch_assoc();
|
||||
|
||||
$_SESSION['cinema'] = $manager["idcinema"];
|
||||
}
|
||||
}
|
||||
|
||||
$state = isset($_GET['state']) ? $_GET['state'] : '';
|
||||
|
||||
switch($state){
|
||||
case "view_user":
|
||||
$_SESSION["lastRol"] = $_SESSION["rol"];
|
||||
$_SESSION["rol"] = null;
|
||||
unset($_SESSION["cinema"]);
|
||||
$panel = "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<div class='code info'>
|
||||
<h1> ¡ATENCIÓN! </h1><hr />
|
||||
<p>Está viendo la web como un Usuario NO Registrado.</p>
|
||||
<a href=''><button>Cerrar Mensaje</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class='column side'></div>
|
||||
</div>
|
||||
";
|
||||
break;
|
||||
case "view_ruser":
|
||||
$_SESSION["lastRol"] = $_SESSION["rol"];
|
||||
$_SESSION["rol"] = "user";
|
||||
unset($_SESSION["cinema"]);
|
||||
$panel = "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<div class='code info'>
|
||||
<h1> ¡ATENCIÓN! </h1><hr />
|
||||
<p>Está viendo la web como un Usuario Registrado.</p>
|
||||
<a href=''><button>Cerrar Mensaje</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class='column side'></div>
|
||||
</div>
|
||||
";
|
||||
break;
|
||||
case "manage_halls":
|
||||
$panel = Manager_panel::manage_halls();
|
||||
break;
|
||||
case "new_hall":
|
||||
$panel = Manager_panel::new_hall();
|
||||
break;
|
||||
case "edit_hall":
|
||||
$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 "success":
|
||||
$panel = Manager_panel::success();
|
||||
break;
|
||||
case "calendar":
|
||||
$panel = Manager_panel::calendar();
|
||||
break;
|
||||
default:
|
||||
$panel = Manager_panel::welcome();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$panel = '<div class="column side"></div>
|
||||
<div class="column middle">
|
||||
<div class="code info">
|
||||
<h1>Debes iniciar sesión para ver el Panel de Manager.</h1><hr />
|
||||
<p>Inicia Sesión con una cuenta de Gerente.</p>
|
||||
<a href="'.$prefix.'login/" ><button class="button large">Iniciar Sesión</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column side"></div>'."\n";
|
||||
}
|
||||
|
||||
//Specific page content:
|
||||
$section = '<!-- Manager Panel -->
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/css/manager.css">
|
||||
<section id="manager_panel">
|
||||
<!-- Contents -->
|
||||
<div class="row">
|
||||
'.$panel.'
|
||||
</div>
|
||||
</section>';
|
||||
|
||||
//General page content:
|
||||
require RAIZ_APP.'/HTMLtemplate.php';
|
||||
?>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.css" />
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.min.js"></script>
|
||||
<script src="./sessioncalendar.js"></script>
|
159
panel_manager/index.php
Normal file
159
panel_manager/index.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
//General Config File:
|
||||
require_once('../assets/php/config.php');
|
||||
//Controller file:
|
||||
require_once('panel_manager.php');
|
||||
require_once('../assets/php/includes/manager_dao.php');
|
||||
require_once('../assets/php/includes/manager.php');
|
||||
require_once('../assets/php/includes/user.php');
|
||||
|
||||
if($_SESSION["login"] && isset($_SESSION["lastRol"]) && ($_SESSION["lastRol"] === "admin" || $_SESSION["rol"] === "manager")) {
|
||||
$manager = new Manager(null, null, null, null, null);
|
||||
if(isset($_POST['changecinema']))$_SESSION['cinema'] = $_POST['cinema'];
|
||||
|
||||
|
||||
$state = isset($_GET['state']) ? $_GET['state'] : '';
|
||||
switch($state){
|
||||
case "view_user":
|
||||
$_SESSION["rol"] = null;
|
||||
|
||||
$panel .= "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<div class='code info'>
|
||||
<h1> ¡ATENCIÓN! </h1><hr />
|
||||
<p>Está viendo la web como un Usuario NO Registrado.</p>
|
||||
<a href='".$prefix."'><button>Cerrar Mensaje</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class='column side'></div>
|
||||
</div>
|
||||
";
|
||||
break;
|
||||
case "view_ruser":
|
||||
$_SESSION["rol"] = "user";
|
||||
unset($_SESSION["cinema"]);
|
||||
$panel .= "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<div class='code info'>
|
||||
<h1> ¡ATENCIÓN! </h1><hr />
|
||||
<p>Está viendo la web como un Usuario Registrado.</p>
|
||||
<a href='".$prefix."'><button>Cerrar Mensaje</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class='column side'></div>
|
||||
</div>
|
||||
";
|
||||
break;
|
||||
case "manage_halls":
|
||||
$panel = Manager_panel::manage_halls();
|
||||
break;
|
||||
case "new_hall":
|
||||
$panel = Manager_panel::new_hall();
|
||||
break;
|
||||
case "edit_hall":
|
||||
$panel = Manager_panel::edit_hall();
|
||||
break;
|
||||
case "manage_sessions":
|
||||
$panel = Manager_panel::calendar();
|
||||
break;
|
||||
default:
|
||||
$panel = Manager_panel::welcomeAdmin($manager);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if($_SESSION["login"] && $_SESSION["rol"] === "manager"){
|
||||
|
||||
if(!isset($_SESSION['cinema'])){
|
||||
$bd = new Manager_DAO('complucine');
|
||||
if($bd){
|
||||
$user = unserialize($_SESSION["user"]);
|
||||
$manager = $bd->GetManager($user->getId());
|
||||
$manager = $manager->fetch_assoc();
|
||||
|
||||
$_SESSION['cinema'] = $manager["idcinema"];
|
||||
}
|
||||
}
|
||||
|
||||
$state = isset($_GET['state']) ? $_GET['state'] : '';
|
||||
|
||||
switch($state){
|
||||
case "view_user":
|
||||
$_SESSION["lastRol"] = $_SESSION["rol"];
|
||||
$_SESSION["rol"] = null;
|
||||
unset($_SESSION["cinema"]);
|
||||
$panel = "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<div class='code info'>
|
||||
<h1> ¡ATENCIÓN! </h1><hr />
|
||||
<p>Está viendo la web como un Usuario NO Registrado.</p>
|
||||
<a href='".$prefix."'><button>Cerrar Mensaje</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class='column side'></div>
|
||||
</div>
|
||||
";
|
||||
break;
|
||||
case "view_ruser":
|
||||
$_SESSION["lastRol"] = $_SESSION["rol"];
|
||||
$_SESSION["rol"] = "user";
|
||||
unset($_SESSION["cinema"]);
|
||||
$panel = "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<div class='code info'>
|
||||
<h1> ¡ATENCIÓN! </h1><hr />
|
||||
<p>Está viendo la web como un Usuario Registrado.</p>
|
||||
<a href='".$prefix."'><button>Cerrar Mensaje</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class='column side'></div>
|
||||
</div>
|
||||
";
|
||||
break;
|
||||
case "manage_halls":
|
||||
$panel = Manager_panel::manage_halls();
|
||||
break;
|
||||
case "new_hall":
|
||||
$panel = Manager_panel::new_hall();
|
||||
break;
|
||||
case "edit_hall":
|
||||
$panel = Manager_panel::edit_hall();
|
||||
break;
|
||||
case "manage_sessions":
|
||||
$panel = Manager_panel::calendar();
|
||||
break;
|
||||
default:
|
||||
$panel = Manager_panel::welcome();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$panel = '<div class="column side"></div>
|
||||
<div class="column middle">
|
||||
<div class="code info">
|
||||
<h1>Debes iniciar sesión para ver el Panel de Manager.</h1><hr />
|
||||
<p>Inicia Sesión con una cuenta de Gerente.</p>
|
||||
<a href="'.$prefix.'login/" ><button class="button large">Iniciar Sesión</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column side"></div>'."\n";
|
||||
}
|
||||
|
||||
//Specific page content:
|
||||
$section = '<!-- Manager Panel -->
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/css/manager.css">
|
||||
<section id="manager_panel">
|
||||
<!-- Contents -->
|
||||
<div class="row">
|
||||
'.$panel.'
|
||||
</div>
|
||||
</section>';
|
||||
|
||||
//General page content:
|
||||
require RAIZ_APP.'/HTMLtemplate.php';
|
||||
?>
|
334
panel_manager/panel_manager-FER_SURFACE.php
Normal file
334
panel_manager/panel_manager-FER_SURFACE.php
Normal file
@ -0,0 +1,334 @@
|
||||
<?php
|
||||
include_once($prefix.'assets/php/includes/hall.php');
|
||||
include_once($prefix.'assets/php/includes/session.php');
|
||||
require_once($prefix.'assets/php/includes/manager.php');
|
||||
require_once($prefix.'assets/php/includes/cinema_dao.php');
|
||||
include_once('./includes/formHall.php');
|
||||
include_once('./includes/formSession.php');
|
||||
|
||||
|
||||
class Manager_panel {
|
||||
|
||||
function __construct(){}
|
||||
|
||||
static function welcome(){
|
||||
$bd = new Cinema_DAO('complucine');
|
||||
if($bd){
|
||||
|
||||
$cinema = $bd->cinemaData($_SESSION["cinema"]);
|
||||
$c_name = $cinema->getName();
|
||||
$c_dir = $cinema->getDirection();
|
||||
}
|
||||
$name = strtoupper($_SESSION["nombre"]);
|
||||
$userPic = USER_PICS.strtolower($name).".jpg";
|
||||
|
||||
$panel= '<div class="code welcome">
|
||||
<h1>Bienvenido '.$name.' a tu Panel de Manager.</h1>
|
||||
<hr />
|
||||
<img src='.$userPic.' alt="user_profile_picture"/>
|
||||
<h3>'.strftime("%A %e de %B de %Y | %H:%M").'</h3>
|
||||
<p>Usuario: '.$name.'</p> <br>
|
||||
<p>Cine: '.$c_name.'</p>
|
||||
<p>Dirección: '.$c_dir.'</p>
|
||||
<a href="?state=calendar"> <p> Hack para entrar al calendario <p> </a>
|
||||
</div>'."\n";
|
||||
|
||||
return $panel;
|
||||
}
|
||||
|
||||
static function welcomeAdmin() {
|
||||
$cinemaList = new Cinema_DAO('complucine');
|
||||
$cinemas = $cinemaList->allCinemaData();
|
||||
|
||||
$bd = new Cinema_DAO('complucine');
|
||||
|
||||
$c_name = "Aun no se ha escogido un cine";
|
||||
|
||||
if($bd && $_SESSION["cinema"] ){
|
||||
|
||||
$cinema = $bd->cinemaData($_SESSION["cinema"]);
|
||||
$c_name = $cinema->getName();
|
||||
$cinema = $cinema->getId();
|
||||
}
|
||||
|
||||
$name = strtoupper($_SESSION["nombre"]);
|
||||
$userPic = USER_PICS.strtolower($name).".jpg";
|
||||
|
||||
$panel= '<div class="code welcome">
|
||||
<h1>Bienvenido '.$name.' a tu Panel de Manager.</h1>
|
||||
<hr />
|
||||
<div class="column side"> </div>
|
||||
<div class="column middle">
|
||||
<img src='.$userPic.' alt="user_profile_picture"/>
|
||||
<h3>'.strftime("%A %e de %B de %Y | %H:%M").'</h3>
|
||||
<p>Usuario: '.$name.'</p> <br>
|
||||
<h3>Como administrador puedes escoger el cine que gestionar</h3>
|
||||
<p>Cine: '.$c_name.'</p>
|
||||
|
||||
<a href="?state=calendar"> <p> Hack para entrar al calendario <p> </a>
|
||||
|
||||
<form method="post" id="changecinema" action="index.php">
|
||||
<select name="cinema" class="button large">
|
||||
';
|
||||
foreach($cinemas as $c){
|
||||
if($c->getId() == $cinema){
|
||||
$panel .= "<option value=\"". $c->getId() ." \"selected> " . $c->getName() ."</option>
|
||||
";
|
||||
}else{
|
||||
$panel .= "<option value=\"". $c->getId() ." \"> " . $c->getName() . "</option>
|
||||
";
|
||||
}
|
||||
}
|
||||
$panel .= ' <input type="submit" id="submit" name="changecinema" value="Cambiar" class="primary" />
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
<div class="column side"> </div>
|
||||
';
|
||||
|
||||
return $panel;
|
||||
}
|
||||
static function calendar(){
|
||||
$formSession = new FormSession("new_session", $_SESSION["cinema"] );
|
||||
$hall = $_POST['hall'] ?? $_GET['hall'] ?? "1";
|
||||
$halls = Hall::getListHalls($_SESSION["cinema"]);
|
||||
|
||||
if($halls){
|
||||
$panel ='
|
||||
<div class="row">
|
||||
<div class="column side"></div>
|
||||
<div class="column middle">
|
||||
<br>
|
||||
<select id="hall_selector" class="button large">';
|
||||
foreach(Hall::getListHalls($_SESSION["cinema"]) as $hll){
|
||||
if($hll->getNumber() == $hall){
|
||||
$panel.= '
|
||||
<option data-feed="./eventos.php?hall='.$hll->getNumber().'" value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> ';
|
||||
}else{
|
||||
$panel.= '
|
||||
<option data-feed="./eventos.php?hall='.$hll->getNumber().'" value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
|
||||
}
|
||||
}
|
||||
$panel.='
|
||||
</select>
|
||||
</div>
|
||||
<div class="column side"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div id="myModal" class="modal">
|
||||
|
||||
<div class="modal-content">
|
||||
<span class="close">×</span>
|
||||
'.$formSession->gestiona().'
|
||||
</div>
|
||||
</div>
|
||||
<div id="calendar"></div>
|
||||
</div>';
|
||||
}else{
|
||||
$panel ='<div class="row">
|
||||
<h3> No hay ninguna sala en este cine </h3>
|
||||
<a href=."/?state=new_hall"> Añadir Sala </a>
|
||||
</div>';
|
||||
}
|
||||
|
||||
|
||||
return $panel;
|
||||
}
|
||||
static function success(){
|
||||
$panel = '<div class="code info">
|
||||
<h1>Operacion completada.</h1>
|
||||
<hr />
|
||||
<p>'.$_SESSION['msg'].'</p>
|
||||
</div>'."\n";
|
||||
$_SESSION['msg'] = "";
|
||||
|
||||
return $panel;
|
||||
}
|
||||
|
||||
static function manage_halls(){
|
||||
|
||||
$panel = '<div class="column side"></div>
|
||||
<div class="column middle">';
|
||||
$listhall = Hall::getListHalls($_SESSION["cinema"]);
|
||||
if(!$listhall){
|
||||
$panel .= "<h2> No hay ninguna sala en este cine";
|
||||
}else{
|
||||
$panel .= '
|
||||
<ul class="tablelist col3">
|
||||
<li class="title"> Sala </li>
|
||||
<li class="title"> Asientos </li>
|
||||
<li class="title"> Sesión </li>
|
||||
';
|
||||
$parity = "odd";
|
||||
foreach($listhall as $hall){
|
||||
$panel .='<div class="'.$parity.'">
|
||||
<a class="h2long" href="?state=edit_hall&number='. $hall->getNumber().'">
|
||||
<li> '. $hall->getNumber().'</li>
|
||||
<li> '.$hall->getTotalSeats().' </li>
|
||||
</a>
|
||||
<a href="?state=calendar&hall='. $hall->getNumber().'">
|
||||
<li> Sesiones </li>
|
||||
</a>
|
||||
</div>
|
||||
';
|
||||
$parity = ($parity == "odd") ? "even" : "odd";
|
||||
}
|
||||
$panel.='
|
||||
</ul>';
|
||||
}
|
||||
$panel.='
|
||||
<form method="post" action="./?state=new_hall">
|
||||
<input type="submit" name="new_hall" value="Añadir Sala" class="button large" />
|
||||
</form>
|
||||
</div>
|
||||
<div class="column side"></div>';
|
||||
return $panel;
|
||||
}
|
||||
|
||||
static function new_hall(){
|
||||
|
||||
$formHall = new FormHall("new_hall",$_SESSION["cinema"],new Hall(null, null, null, null, null, null));
|
||||
|
||||
$panel = '<h1>Crear una sala.</h1><hr/></br>
|
||||
'.$formHall->gestiona();
|
||||
return $panel;
|
||||
}
|
||||
|
||||
static function edit_hall(){
|
||||
$hall = Hall::search_hall($_GET["number"], $_SESSION["cinema"]);
|
||||
|
||||
if($hall || isset($_POST["restart"]) || isset($_POST["filter"]) || isset($_POST["sumbit"]) ){
|
||||
|
||||
$formHall = new FormHall("edit_hall",$_SESSION["cinema"], $hall);
|
||||
$panel = '<h1>Editar una sala.</h1><hr/></br>
|
||||
'.$formHall->gestiona();
|
||||
return $panel;
|
||||
} else{
|
||||
return Manager_panel::warning();
|
||||
}
|
||||
}
|
||||
|
||||
static function manage_sessions(){
|
||||
//Base filtering values
|
||||
$date = $_POST['date'] ?? $_GET['date'] ?? date("Y-m-d");
|
||||
$hall = $_POST['hall'] ?? $_GET['hall'] ?? "1";
|
||||
|
||||
//Session filter
|
||||
$panel='<div class = "column left">
|
||||
<form method="post" id="filter" action="./?state=manage_sessions">
|
||||
<input type="date" name="date" value="'.$date.'" min="2021-01-01" max="2031-12-31">
|
||||
<select name="hall" class="button large">';
|
||||
|
||||
foreach(Hall::getListHalls($_SESSION["cinema"]) as $hll){
|
||||
if($hll->getNumber() == $hall){
|
||||
$panel.= '
|
||||
<option value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> ';
|
||||
}else{
|
||||
$panel.= '
|
||||
<option value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
|
||||
}
|
||||
}
|
||||
$panel.='
|
||||
</select>
|
||||
<input type="submit" name="filter" value="Filtrar" class="button large"/>
|
||||
</form>
|
||||
</div>
|
||||
';
|
||||
//Session list
|
||||
$panel .=' <div class = "column right">';
|
||||
$sessions = Session::getListSessions($hall,$_SESSION["cinema"],$date);
|
||||
|
||||
if($sessions) {
|
||||
$panel .='
|
||||
<form method="post" action="./?state=edit_session">
|
||||
<table class="alt">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Hora</th>
|
||||
<th>Pelicula</th>
|
||||
<th>Formato</th>
|
||||
<th>Precio</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
|
||||
|
||||
foreach($sessions as $session){
|
||||
$film = Session::getThisSessionFilm($session->getIdfilm());
|
||||
$panel .='
|
||||
<tr>
|
||||
<td> '.date("H:i", strtotime( $session->getStartTime())).' </td>
|
||||
<td> '. str_replace('_', ' ', $film["tittle"]) .' </td>
|
||||
<td> '.$session->getFormat().' </td>
|
||||
<td> '.$session->getSeatPrice().' </td>
|
||||
<form method="post" action="./?state=edit_session">
|
||||
<input name="film" type="hidden" value="'.$session->getIdfilm().'">
|
||||
<input name="tittle" type="hidden" value="'.$film["tittle"].'">
|
||||
<input name="duration" type="hidden" value="'.$film["duration"].'">
|
||||
<input name="language" type="hidden" value="'.$film["language"].'">
|
||||
<input name="description" type="hidden" value="'.$film["description"].'">
|
||||
<input name="hall" type="hidden" value="'.$session->getIdhall().'">
|
||||
<input name="date" type="hidden" value="'.$session->getDate().'">
|
||||
<input name="start" type="hidden" value="'.$session->getStartTime().'">
|
||||
<input name="price" type="hidden" value="'.$session->getSeatPrice().'">
|
||||
<input name="format" type="hidden" value="'.$session->getFormat().'">
|
||||
<td> <input type="submit" id="submit" name ="edit_session" value="Editar" class="primary" /> </td>
|
||||
</form>
|
||||
</tr>';
|
||||
}
|
||||
$panel.='
|
||||
</tbody>
|
||||
</table>
|
||||
</form>';
|
||||
} else {
|
||||
$panel.=' <h3> No hay ninguna sesion </h3>';
|
||||
}
|
||||
$panel.='
|
||||
<input type="submit" name="new_session" form="filter" value="Añadir" class="button large" formaction="./?state=new_session">
|
||||
</div>';
|
||||
|
||||
return $panel;
|
||||
}
|
||||
|
||||
static function new_session(){
|
||||
$formSession = new FormSession("new_session", $_SESSION["cinema"] );
|
||||
|
||||
$panel = '<h1>Crear una sesion.</h1> <hr/> </br>
|
||||
'.$formSession->gestiona();
|
||||
return $panel;
|
||||
}
|
||||
|
||||
static function edit_session(){
|
||||
$formSession = new FormSession("edit_session", $_SESSION["cinema"] );
|
||||
|
||||
$panel = '<h1>Editar una sesion.</h1><hr/></br>
|
||||
'.$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 = '<h1>Seleccionar Pelicula.</h1><hr /></br>';
|
||||
$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
|
||||
static function warning(){
|
||||
$panel = '<div class="code info">
|
||||
<h1>Ha habido un error.</h1>
|
||||
<hr />
|
||||
<p> >.< </p>
|
||||
</div>'."\n";
|
||||
|
||||
return $panel;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
223
panel_manager/panel_manager.php
Normal file
223
panel_manager/panel_manager.php
Normal file
@ -0,0 +1,223 @@
|
||||
<?php
|
||||
include_once($prefix.'assets/php/includes/hall.php');
|
||||
include_once($prefix.'assets/php/includes/session.php');
|
||||
require_once($prefix.'assets/php/includes/cinema_dao.php');
|
||||
include_once('./includes/formHall.php');
|
||||
include_once('./includes/SessionForm.php');
|
||||
|
||||
class Manager_panel {
|
||||
function __construct(){}
|
||||
|
||||
static function welcome(){
|
||||
$bd = new Cinema_DAO('complucine');
|
||||
if($bd){
|
||||
|
||||
$cinema = $bd->cinemaData($_SESSION["cinema"]);
|
||||
$c_name = $cinema->getName();
|
||||
$c_dir = $cinema->getDirection();
|
||||
}
|
||||
$name = strtoupper($_SESSION["nombre"]);
|
||||
$userPic = USER_PICS.strtolower($name).".jpg";
|
||||
|
||||
$panel= '<div class="code welcome">
|
||||
<h1>Bienvenido '.$name.' a tu Panel de Manager.</h1>
|
||||
<hr />
|
||||
<img src='.$userPic.' alt="user_profile_picture"/>
|
||||
<h3>'.strftime("%A %e de %B de %Y | %H:%M").'</h3>
|
||||
<p>Usuario: '.$name.'</p> <br>
|
||||
<p>Cine: '.$c_name.'</p>
|
||||
<p>Dirección: '.$c_dir.'</p>
|
||||
</div>'."\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();
|
||||
|
||||
$bd = new Cinema_DAO('complucine');
|
||||
|
||||
$c_name = "Aun no se ha escogido un cine";
|
||||
|
||||
if($bd && $_SESSION["cinema"] ){
|
||||
|
||||
$cinema = $bd->cinemaData($_SESSION["cinema"]);
|
||||
$c_name = $cinema->getName();
|
||||
$cinema = $cinema->getId();
|
||||
}
|
||||
|
||||
$name = strtoupper($_SESSION["nombre"]);
|
||||
$userPic = USER_PICS.strtolower($name).".jpg";
|
||||
|
||||
$panel= '<div class="code welcome">
|
||||
<h1>Bienvenido '.$name.' a tu Panel de Manager.</h1>
|
||||
<hr />
|
||||
<div class="column side"> </div>
|
||||
<div class="column middle">
|
||||
<img src='.$userPic.' alt="user_profile_picture"/>
|
||||
<h3>'.strftime("%A %e de %B de %Y | %H:%M").'</h3>
|
||||
<p>Usuario: '.$name.'</p> <br>
|
||||
<h3>Como administrador puedes escoger el cine que gestionar</h3>
|
||||
<p>Cine: '.$c_name.'</p>
|
||||
|
||||
<form method="post" id="changecinema" action="index.php">
|
||||
<select name="cinema" class="button large">
|
||||
';
|
||||
foreach($cinemas as $c){
|
||||
if($c->getId() == $cinema){
|
||||
$panel .= "<option value=\"". $c->getId() ." \"selected> " . $c->getName() ."</option>
|
||||
";
|
||||
}else{
|
||||
$panel .= "<option value=\"". $c->getId() ." \"> " . $c->getName() . "</option>
|
||||
";
|
||||
}
|
||||
}
|
||||
$panel .= ' <input type="submit" id="submit" name="changecinema" value="Cambiar" class="primary" />
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
<div class="column side"> </div>
|
||||
';
|
||||
|
||||
return $panel;
|
||||
}
|
||||
//Manage the sessions using full calendar js events and a pop up form which is constantly edited with more js
|
||||
static function calendar(){
|
||||
if(isset($_SESSION["cinema"])){
|
||||
$hall = $_POST['hall'] ?? $_GET['hall'] ?? "1";
|
||||
$halls = Hall::getListHalls($_SESSION["cinema"]);
|
||||
|
||||
if($halls){
|
||||
$panel ='
|
||||
<div class="row">
|
||||
<div class="column side"></div>
|
||||
<div class="column middle">
|
||||
<br>
|
||||
<select id="hall_selector" class="button large">';
|
||||
foreach(Hall::getListHalls($_SESSION["cinema"]) as $hll){
|
||||
if($hll->getNumber() == $hall){
|
||||
$panel.= '
|
||||
<option data-feed="./eventsProcess.php?hall='.$hll->getNumber().'" value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> ';
|
||||
}else{
|
||||
$panel.= '
|
||||
<option data-feed="./eventsProcess.php?hall='.$hll->getNumber().'" value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
|
||||
}
|
||||
}
|
||||
$panel.='
|
||||
</select>
|
||||
</div>
|
||||
<div class="column side"></div>
|
||||
</div>
|
||||
<div class="row fc-container">
|
||||
<div id="calendar"></div>
|
||||
<div id="myModal" class="modal">
|
||||
|
||||
<div class="modal-content">
|
||||
<span class="close">×</span> <br> <br>
|
||||
'.SessionForm::getForm().'
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
}else{
|
||||
$panel ='<div class="row">
|
||||
<h3> No hay ninguna sala en este cine </h3>
|
||||
<a href=."/?state=new_hall"> Añadir Sala </a>
|
||||
</div>';
|
||||
}
|
||||
}else{
|
||||
$panel = '<div class="code info">
|
||||
<h1>Aun no se ha seleccionado un cine.</h1>
|
||||
<hr />
|
||||
<p> >.< </p>
|
||||
<p> Selecciona un cine en el panel principal </p>
|
||||
</div>'."\n";
|
||||
}
|
||||
return $panel;
|
||||
|
||||
}
|
||||
|
||||
static function manage_halls(){
|
||||
if(isset($_SESSION["cinema"])){
|
||||
$panel = '<div class="column side"></div>
|
||||
<div class="column middle">';
|
||||
$listhall = Hall::getListHalls($_SESSION["cinema"]);
|
||||
if(!$listhall){
|
||||
$panel .= "<h2> No hay ninguna sala en este cine";
|
||||
}else{
|
||||
$panel .= '
|
||||
<ul class="tablelist col3">
|
||||
<li class="title"> Sala </li>
|
||||
<li class="title"> Asientos </li>
|
||||
<li class="title"> Sesión </li>
|
||||
';
|
||||
$parity = "odd";
|
||||
foreach($listhall as $hall){
|
||||
$panel .='<div class="'.$parity.'">
|
||||
<a class="h2long" href="?state=edit_hall&number='. $hall->getNumber().'">
|
||||
<li> '. $hall->getNumber().'</li>
|
||||
<li> '.$hall->getTotalSeats().' </li>
|
||||
</a>
|
||||
<a href="?state=manage_sessions&hall='. $hall->getNumber().'">
|
||||
<li> Sesiones </li>
|
||||
</a>
|
||||
</div>
|
||||
';
|
||||
$parity = ($parity == "odd") ? "even" : "odd";
|
||||
}
|
||||
$panel.='
|
||||
</ul>';
|
||||
}
|
||||
$panel.='
|
||||
<form method="post" action="./?state=new_hall">
|
||||
<input type="submit" name="new_hall" value="Añadir Sala" class="button large" />
|
||||
</form>
|
||||
</div>
|
||||
<div class="column side"></div>';
|
||||
}else{
|
||||
$panel = '<div class="code info">
|
||||
<h1>Aun no se ha seleccionado un cine.</h1>
|
||||
<hr />
|
||||
<p> >.< </p>
|
||||
<p> Selecciona un cine en el panel principal </p>
|
||||
</div>'."\n";
|
||||
}
|
||||
return $panel;
|
||||
}
|
||||
|
||||
static function new_hall(){
|
||||
|
||||
$formHall = new FormHall("new_hall",$_SESSION["cinema"],new Hall(null, null, null, null, null, null));
|
||||
|
||||
$panel = '<h1>Crear una sala.</h1><hr/></br>
|
||||
'.$formHall->gestiona();
|
||||
return $panel;
|
||||
}
|
||||
|
||||
static function edit_hall(){
|
||||
$hall = Hall::search_hall($_GET["number"], $_SESSION["cinema"]);
|
||||
|
||||
if($hall || isset($_POST["restart"]) || isset($_POST["filter"]) || isset($_POST["sumbit"]) ){
|
||||
|
||||
$formHall = new FormHall("edit_hall",$_SESSION["cinema"], $hall);
|
||||
$panel = '<h1>Editar una sala.</h1><hr/></br>
|
||||
'.$formHall->gestiona();
|
||||
return $panel;
|
||||
} else{
|
||||
return Manager_panel::warning();
|
||||
}
|
||||
}
|
||||
|
||||
//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 = '<div class="code info">
|
||||
<h1>Ha habido un error.</h1>
|
||||
<hr />
|
||||
<p> >.< </p>
|
||||
</div>'."\n";
|
||||
|
||||
return $panel;
|
||||
}
|
||||
}
|
||||
?>
|
57
panel_manager/processSession.php
Normal file
57
panel_manager/processSession.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
|
||||
$errors = [];
|
||||
$data = [];
|
||||
|
||||
if (empty($_POST['price']) || $_POST['price'] <= 0 ) {
|
||||
$errors['price'] = 'El precio no puede ser 0.';
|
||||
}
|
||||
|
||||
if (empty($_POST['format'])) {
|
||||
$errors['format'] = 'El formato no puede estar vacio. Ej: 3D, 2D, voz original';
|
||||
}
|
||||
|
||||
if (empty($_POST['hall']) || $_POST['hall']<=0 ) {
|
||||
$errors['hall'] = 'La sala no puede ser 0 o menor';
|
||||
}
|
||||
|
||||
if (empty($_POST['startDate'])) {
|
||||
$errors['startDate'] = 'Las sesiones tienen que empezar algun dia.';
|
||||
}
|
||||
|
||||
if (empty($_POST['endDate'])) {
|
||||
$errors['endDate'] = 'Las sesiones tienen que teminar algun dia.';
|
||||
}
|
||||
|
||||
if (!empty($_POST['startDate']) && !empty($_POST['endDate'])) {
|
||||
$start = strtotime($_POST['startDate']);
|
||||
$end = strtotime($_POST['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($_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);
|
138
panel_manager/sessioncalendar-FER_SURFACE.js
Normal file
138
panel_manager/sessioncalendar-FER_SURFACE.js
Normal file
@ -0,0 +1,138 @@
|
||||
|
||||
$(document).ready(function(){
|
||||
|
||||
var selectedFeed = $('#hall_selector').find(':selected').data('feed');
|
||||
var modal = document.getElementById("myModal");
|
||||
|
||||
// Get the button that opens the modal
|
||||
var btn = document.getElementById("myBtn");
|
||||
|
||||
// Get the <span> element that closes the modal
|
||||
var span = document.getElementsByClassName("close")[0];
|
||||
|
||||
var calendar = $('#calendar').fullCalendar({
|
||||
editable:true,
|
||||
header:{
|
||||
left:'prev,next today',
|
||||
center:'title',
|
||||
right:'month,agendaWeek,agendaDay'
|
||||
},
|
||||
eventSources: [ selectedFeed ],
|
||||
selectable:true,
|
||||
selectHelper:true,
|
||||
timeFormat: 'H:mm',
|
||||
select: function(start, end, allDay)
|
||||
{
|
||||
modal.style.display = "block";
|
||||
/*
|
||||
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");
|
||||
}
|
||||
})*/
|
||||
},
|
||||
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?"))
|
||||
{
|
||||
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);
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
$('#hall_selector').change(onSelectChangeFeed);
|
||||
|
||||
function onSelectChangeFeed() {
|
||||
var feed = $(this).find(':selected').data('feed');
|
||||
$('#calendar').fullCalendar('removeEventSource', selectedFeed);
|
||||
$('#calendar').fullCalendar('addEventSource', feed);
|
||||
selectedFeed = feed;
|
||||
};
|
||||
|
||||
// When the user clicks on <span> (x), close the modal
|
||||
span.onclick = function() {
|
||||
modal.style.display = "none";
|
||||
}
|
||||
|
||||
// When the user clicks anywhere outside of the modal, close it
|
||||
window.onclick = function(event) {
|
||||
if (event.target == modal) {
|
||||
modal.style.display = "none";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
172
panel_manager/sessioncalendar.js
Normal file
172
panel_manager/sessioncalendar.js
Normal file
@ -0,0 +1,172 @@
|
||||
|
||||
$(document).ready(function(){
|
||||
|
||||
var selectedFeed = $('#hall_selector').find(':selected').data('feed');
|
||||
var modal = document.getElementById("myModal");
|
||||
|
||||
// Get the button that opens the modal
|
||||
var btn = document.getElementById("myBtn");
|
||||
|
||||
// Get the <span> element that closes the modal
|
||||
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',
|
||||
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"),
|
||||
"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");
|
||||
}
|
||||
})*/
|
||||
},
|
||||
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?"))
|
||||
{
|
||||
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);
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
$('#hall_selector').change(onSelectChangeFeed);
|
||||
|
||||
function onSelectChangeFeed() {
|
||||
var feed = $(this).find(':selected').data('feed');
|
||||
$('#calendar').fullCalendar('removeEventSource', selectedFeed);
|
||||
$('#calendar').fullCalendar('addEventSource', feed);
|
||||
selectedFeed = feed;
|
||||
};
|
||||
|
||||
// When the user clicks on <span> (x), close the modal
|
||||
span.onclick = function() {
|
||||
formout();
|
||||
}
|
||||
|
||||
// When the user clicks anywhere outside of the modal, close it
|
||||
window.onclick = function(event) {
|
||||
if (event.target == modal) {
|
||||
formout();
|
||||
}
|
||||
}
|
||||
|
||||
function formout(){
|
||||
$(modal).fadeOut(100,function(){
|
||||
var success = document.getElementById("success");
|
||||
if(success){
|
||||
calendar.fullCalendar('refetchEvents');
|
||||
success.style.display = "none";
|
||||
|
||||
document.getElementById("new_session_form").style.display = "block";
|
||||
document.getElementById("price").value = "";
|
||||
document.getElementById("format").value = "";
|
||||
document.getElementById("film_id").value = "";
|
||||
document.getElementById("startHour").value ="";
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
144
panel_manager/sessionforms.js
Normal file
144
panel_manager/sessionforms.js
Normal file
@ -0,0 +1,144 @@
|
||||
$(document).ready(function () {
|
||||
|
||||
$("form#new_session_form").on('submit', 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:"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(
|
||||
'<div class="alert alert-danger">Could not reach server, please try again later. '+textStatus+'</div>'
|
||||
);
|
||||
});
|
||||
|
||||
function checkErrors(data,formname) {
|
||||
if (!data.success) {
|
||||
if (data.errors.price) {
|
||||
$("#price_group").addClass("has_error");
|
||||
$("#price_group").append(
|
||||
'<div class="help_block">' + data.errors.price + "</div>"
|
||||
);
|
||||
}
|
||||
if (data.errors.format) {
|
||||
$("#format_group").addClass("has_error");
|
||||
$("#format_group").append(
|
||||
'<div class="help_block">' + data.errors.format + "</div>"
|
||||
);
|
||||
}
|
||||
if (data.errors.hall) {
|
||||
$("#hall_group").addClass("has_error");
|
||||
$("#hall_group").append(
|
||||
'<div class="help_block">' + data.errors.hall + "</div>"
|
||||
);
|
||||
}
|
||||
if (data.errors.startDate) {
|
||||
$("#date_group").addClass("has_error");
|
||||
$("#date_group").append(
|
||||
'<div class="help_block">' + data.errors.startDate + "</div>"
|
||||
);
|
||||
}
|
||||
if (data.errors.startDate) {
|
||||
$("#date_group").addClass("has_error");
|
||||
$("#date_group").append(
|
||||
'<div class="help_block">' + data.errors.endDate + "</div>"
|
||||
);
|
||||
}
|
||||
if (data.errors.date) {
|
||||
$("#date_group").addClass("has_error");
|
||||
$("#date_group").append(
|
||||
'<div class="help_block">' + data.errors.date + "</div>"
|
||||
);
|
||||
}
|
||||
if (data.errors.startHour) {
|
||||
$("#hour_group").addClass("has_error");
|
||||
$("#hour_group").append(
|
||||
'<div class="help_block">' + data.errors.startHour + "</div>"
|
||||
);
|
||||
}
|
||||
if (data.errors.idfilm) {
|
||||
$("#film_msg_group").addClass("has_error");
|
||||
$("#film_msg_group").append(
|
||||
'<div class="help_block">' + data.errors.idfilm + "</div>"
|
||||
);
|
||||
}
|
||||
if (data.errors.global) {
|
||||
$("#global_group").addClass("has_error");
|
||||
$("#global_group").append(
|
||||
'<div class="help_block">' + data.errors.global + "</div>"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
||||
$("#operation_msg").addClass("has_no_error");
|
||||
$("#operation_msg").append(
|
||||
'<div class="alert alert-success" id="success">' + data.message + "</div>"
|
||||
);
|
||||
document.getElementById(formname).style.display = "none";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
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";
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user