From ebc132e2055973a88ce6936041e3a73132a8a156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20M=C3=A9ndez?= <45081533+FerMdez@users.noreply.github.com> Date: Tue, 4 May 2021 22:26:24 +0200 Subject: [PATCH] Add files via upload --- assets/css/main.css | 6 ++ assets/php/common/film_dao.php | 4 +- assets/php/common/film_dto.php | 1 - assets/php/common/hall.php | 14 +--- assets/php/common/hall_dao.php | 27 +------ assets/php/config.php | 11 ++- assets/php/template.php | 15 ++-- login/includes/formLogin.php | 1 + panel_admin/includes/formFilm.php | 30 ++++++-- panel_admin/manage_films.php | 35 +++------ panel_manager/edit_halls.php | 16 ++++ panel_manager/hello_panel.php | 9 +++ panel_manager/includes/formHall.php | 95 +++++++++++++----------- panel_manager/index.php | 57 ++------------- panel_manager/manage_halls.php | 35 +++++++++ panel_manager/manage_rooms.php | 37 ++++++++++ panel_manager/panel_manager.php | 109 +++++----------------------- panel_manager/validateSession.php | 77 ++++++++++++++++++++ register/includes/formRegister.php | 1 + 19 files changed, 319 insertions(+), 261 deletions(-) create mode 100644 panel_manager/edit_halls.php create mode 100644 panel_manager/hello_panel.php create mode 100644 panel_manager/manage_halls.php create mode 100644 panel_manager/manage_rooms.php create mode 100644 panel_manager/validateSession.php diff --git a/assets/css/main.css b/assets/css/main.css index d468ff4..080b88e 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -556,6 +556,12 @@ textarea { border:#000000; background-color: #791515; } +.file{ + margin-top: 10px; +} +.file input{ + height: 110%; +} /* Footer */ diff --git a/assets/php/common/film_dao.php b/assets/php/common/film_dao.php index 1bb9682..3afc769 100644 --- a/assets/php/common/film_dao.php +++ b/assets/php/common/film_dao.php @@ -14,10 +14,10 @@ //Methods: //Create a new Session. - public function createFilm($id, $tittle, $duration, $language,$description){ + public function createFilm($id, $tittle, $duration, $language, $description){ $sql = sprintf( "INSERT INTO `film`( `id`, `tittle`, `duration`, `language`,`description`) VALUES ( '%d', '%s', '%d', '%s','%s')", - $id, $tittle, $duration, $language,$description); + $id, $tittle, $duration, $language, $description); $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); return $resul; diff --git a/assets/php/common/film_dto.php b/assets/php/common/film_dto.php index 3b24897..b177f38 100644 --- a/assets/php/common/film_dto.php +++ b/assets/php/common/film_dto.php @@ -9,7 +9,6 @@ private $_duration; //Film duration. private $_language; //Film language. private $_description; //Film description. - //Constructor: function __construct($id, $tittle, $duration, $language, $description){ diff --git a/assets/php/common/hall.php b/assets/php/common/hall.php index 9580548..a9f638a 100644 --- a/assets/php/common/hall.php +++ b/assets/php/common/hall.php @@ -1,5 +1,5 @@ searchHall($hall['cinema'], $hall['number'])){ - $bd->createHall($hall['number'], $hall['cinema'], $hall['cols'], $hall['rows']); - return "Se ha creado la sala con exito"; - } else { - return "Esta sala ya existe"; - } - } else { return "Error al conectarse a la base de datos"; } - } - //Getters && Setters: public function setNumber($number){ $this->_number = $number; } public function getNumber(){ return $this->_number; } diff --git a/assets/php/common/hall_dao.php b/assets/php/common/hall_dao.php index da50159..f1276d2 100644 --- a/assets/php/common/hall_dao.php +++ b/assets/php/common/hall_dao.php @@ -1,5 +1,5 @@ mysqli, $sql) or die ('Error BD createhall'); - + return $sql; } - + //Returns a query to get the halls data. public function getAllHalls($cinema){ $sql = sprintf( "SELECT * FROM hall WHERE @@ -41,24 +39,7 @@ return $hall; } - - //Returns the count of the hall searched - public function searchHall($number, $cinema){ - - $sql = sprintf( "SELECT COUNT(*) FROM hall WHERE - idcinema = '%s' AND number = '%s'", - $cinema, $number); - $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); - - $hall = mysqli_fetch_array($resul); - - mysqli_free_result($resul); - - return $hall[0]; - } - - - + //Create a new Hall Data Transfer Object. public function loadHall($number, $idcinema, $numrows, $numcolumns){ return new Hall($number, $idcinema, $numrows, $numcolumns); diff --git a/assets/php/config.php b/assets/php/config.php index fc77f87..ebb1e38 100644 --- a/assets/php/config.php +++ b/assets/php/config.php @@ -7,6 +7,11 @@ define('BD_USER', 'sw'); define('BD_PASS', '_admin_'); + /** + * Temprarl files directory. + */ + define('TMP_DIR', __DIR__.'/img/'); + /** * Utf-8 support settings, location (language and country) and time zone. */ @@ -23,7 +28,7 @@ $prefix = $template->get_prefix(); //Depuración (BORRAR): - //ini_set('display_errors', 1); - //ini_set('display_startup_errors', 1); - //error_reporting(E_ALL); + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + error_reporting(E_ALL); ?> \ No newline at end of file diff --git a/assets/php/template.php b/assets/php/template.php index 9463435..0589493 100644 --- a/assets/php/template.php +++ b/assets/php/template.php @@ -1,6 +1,9 @@ Ver como... "); array_push($menus, "
  • Modificar
  • "); break; @@ -318,8 +321,7 @@ "; } - echo " - \n"; + echo "\n"; break; default: @@ -359,6 +361,7 @@ \n"; break; } + } function print_cinemas(){ diff --git a/login/includes/formLogin.php b/login/includes/formLogin.php index 3e9ac16..7451e19 100644 --- a/login/includes/formLogin.php +++ b/login/includes/formLogin.php @@ -47,6 +47,7 @@ class FormLogin extends Form { $name = $this->test_input($name); $pass = $this->test_input($pass); + $name = strtolower($name); $username = isset($name) ? $name : null ; if (!$username) { $login = false; diff --git a/panel_admin/includes/formFilm.php b/panel_admin/includes/formFilm.php index 4b4fc38..8615afb 100644 --- a/panel_admin/includes/formFilm.php +++ b/panel_admin/includes/formFilm.php @@ -62,10 +62,16 @@ class FormFilm extends Form { } } else { - $this->reply = "
    -

    ERROR


    -

    Ha habido un error en la operacion. Revisa los datos introducidos

    - + $this->reply = "
    +
    +
    +
    +

    ERROR


    +

    Ha habido un error en la operacion. Revisa los datos introducidos

    + +
    +
    +
    "; } @@ -73,7 +79,7 @@ class FormFilm extends Form { } //Process form: - public function processesForm($_id,$_tittle,$_duration,$_language,$_description, $_option) { + public function processesForm($_id, $_tittle, $_duration, $_language, $_description, $_img, $_option) { $this->correct = true; $this->option = $_option; @@ -82,6 +88,20 @@ class FormFilm extends Form { $duration=$this->test_input($_duration); $language=$this->test_input($_language); $description=$this->test_input($_description); + + //Validate promotional film image. + $file_name = $_FILES['file']['name']; + $file_type = $_FILES['file']['type']; + $file_size = $_FILES['file']['size']; + if (strpos($file_type, "jpg") && $file_size < 100000) { + $uploadFile = TMP_DIR . basename($_FILES['file'][$_tittle]); + if (!move_uploaded_file($file_name, $uploadFile)){ + print_r($_FILES); + } + } + else{ + $this->correct =false; + } //Habria que validar todo para que encaje en la base de datos diff --git a/panel_admin/manage_films.php b/panel_admin/manage_films.php index bce68c6..c873c99 100644 --- a/panel_admin/manage_films.php +++ b/panel_admin/manage_films.php @@ -11,28 +11,22 @@ echo'

    Añadir pelicula

    -
    +
    Datos de pelicula -
    -
    -
    -
    -
    -
    -
    - -
    + +
    Imagen promocional:
    +
    @@ -41,7 +35,7 @@ function deleteFilm() { echo'
    -

    Editar pelicula

    +

    Eliminar pelicula

    @@ -71,19 +65,12 @@
    Datos de pelicula - -
    + -
    -
    -
    -
    -
    -
    - -
    + +
    Imagen promocional:
    @@ -99,19 +86,19 @@ // Logic Functions function confirmDelete() { $film = new FormFilm(); - $film->processesForm($_POST['id'],null,null,null,null,"del"); + $film->processesForm($_POST['id'],null,null,null,null,null,"del"); $_SESSION['message'] = $film->getReply(); header('Location: ../panel_admin/index.php?state=mf'); } function confirmEdit() { $film = new FormFilm(); - $film->processesForm($_POST['id'], $_POST['tittle'], $_POST['duration'], $_POST['language'], $_POST['description'], "edit"); + $film->processesForm($_POST['id'], $_POST['tittle'], $_POST['duration'], $_POST['language'], $_POST['description'], $_POST['file'], "edit"); $_SESSION['message']= $film->getReply(); header('Location: ../panel_admin/index.php?state=mf'); } function confirmAdd() { $film = new FormFilm(); - $film->processesForm(null, $_POST['tittle'], $_POST['duration'], $_POST['language'], $_POST['description'], "new"); + $film->processesForm(null, $_POST['tittle'], $_POST['duration'], $_POST['language'], $_POST['description'], $_POST['file'], "new"); $_SESSION['message'] = $film->getReply(); header('Location: ../panel_admin/index.php?state=mf'); } diff --git a/panel_manager/edit_halls.php b/panel_manager/edit_halls.php new file mode 100644 index 0000000..1d681cf --- /dev/null +++ b/panel_manager/edit_halls.php @@ -0,0 +1,16 @@ + Crear una Sala "; + $form->gestiona(); + } + +?> \ No newline at end of file diff --git a/panel_manager/hello_panel.php b/panel_manager/hello_panel.php new file mode 100644 index 0000000..4d3cbbc --- /dev/null +++ b/panel_manager/hello_panel.php @@ -0,0 +1,9 @@ +
    +
    +
    +

    Bienvenido al panel de Gerente

    +
    +

    Espero que este pasando un buen dia

    +

    +
    +
    \ No newline at end of file diff --git a/panel_manager/includes/formHall.php b/panel_manager/includes/formHall.php index 8e6b0bb..ee45443 100644 --- a/panel_manager/includes/formHall.php +++ b/panel_manager/includes/formHall.php @@ -1,6 +1,6 @@ reply = array(); } - public static function generaCampoFormulario($datos, $errores = array(), $option){ - if($option == "new"){ + protected function generaCamposFormulario($datos, $errores = array()){ + $this->option = $_SESSION['option']; + $_SESSION['option'] = ""; + $htmlform = ""; + + + + if($this->option == "new"){ $number = $datos['number'] ?? ''; $rows = $datos['rows'] ?? ''; $cols = $datos['cols'] ?? ''; @@ -25,15 +31,13 @@ class FormHall extends Form { $htmlform .= ' - -
    -
    -
    -
    -
    -

    -
    - +
    +
    +
    +
    +
    +

    + '; } @@ -70,40 +74,45 @@ class FormHall extends Form { } //Process form: - public static function processesForm($data){ - if($data["option"] == "new"){ - Hall::create_hall($data); - $_SESSION['msg'] = "La sala se ha añadido correctamente"; - header( "Location: ../?state=success" ); - }else { - /* TODO - $start = date('H:i:s', strtotime( $start ) ); - - if($option == "new"){ + public function processesForm($datos){ + $this->correct = true; + $bd = new HallDAO('complucine'); + + + if($bd ){ + if($option == "list"){ + $this->halls = $bd->getAllHalls($cinema); + }else { + /* TODO + $start = date('H:i:s', strtotime( $start ) ); - $selectSession = $bd->selectSession($cinema, $hall, $start, $date); - if($selectSession && $selectSession->num_rows >= 1) { - $this->correct = false; - } else{ - $bd->createSession(null, $film, $hall,$cinema, $date, $start, $price, $format); + if($option == "new"){ + + $selectSession = $bd->selectSession($cinema, $hall, $start, $date); + if($selectSession && $selectSession->num_rows >= 1) { + $this->correct = false; + } else{ + $bd->createSession(null, $film, $hall,$cinema, $date, $start, $price, $format); + } + + mysqli_free_result($selectSession); + + } else if ($option == "del"){ + $bd->deleteSession($id); + + } else if ($option == "edit"){ + $bd->editSession($id, $film, $hall, $cinema, $date, $start, $price, $format); } - mysqli_free_result($selectSession); - - } else if ($option == "del"){ - $bd->deleteSession($id); - - } else if ($option == "edit"){ - $bd->editSession($id, $film, $hall, $cinema, $date, $start, $price, $format); - } - - if($repeat > "0"){ - $repeat--; - $date = date('Y-m-d', strtotime( $date. ' +1 day') ); - $this->processesForm($film, $hall, $cinema, $date, $start, $price, $format, $repeat); + if($repeat > "0"){ + $repeat--; + $date = date('Y-m-d', strtotime( $date. ' +1 day') ); + $this->processesForm($film, $hall, $cinema, $date, $start, $price, $format, $repeat); + } + */ } - */ - } + + } else {$this->correct = false;} } } diff --git a/panel_manager/index.php b/panel_manager/index.php index 49d2e4d..1b705cf 100644 --- a/panel_manager/index.php +++ b/panel_manager/index.php @@ -1,56 +1,13 @@
    -
    -
    -

    Esta vista aun no esta implementada.


    -
    -
    -
    '."\n"; - 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 "success": - $panel = Manager_panel::success(); - break; - default: - $panel = Manager_panel::welcome(); - break; - } - } - else{ - $panel = '
    -
    -
    -

    Debes iniciar sesión para ver el Panel de Manager.


    -

    Inicia Sesión en una cuenta con permisos.

    - -
    -
    -
    '."\n"; - } ?>
    - + showPanel(); ?>
    diff --git a/panel_manager/manage_halls.php b/panel_manager/manage_halls.php new file mode 100644 index 0000000..505d1db --- /dev/null +++ b/panel_manager/manage_halls.php @@ -0,0 +1,35 @@ + + + + + + + + + + '; + + + foreach(Hall::getListHalls("1") as $hall){ + $listhalls .=' + + + + + + '; + } + $listhalls.=' + +
    NumeroFilasColumnas
    '. $hall->getNumber().' '. $hall->getNumRows().' '. $hall->getNumCol().'
    + + '; + + echo $listhalls; +?> + + diff --git a/panel_manager/manage_rooms.php b/panel_manager/manage_rooms.php new file mode 100644 index 0000000..b38d4bd --- /dev/null +++ b/panel_manager/manage_rooms.php @@ -0,0 +1,37 @@ + +

    Esta vista esta en desarrollo

    +

    + + + + + + + + "; + foreach($ros as $r){ + echo " + + + + "; + } + echo " +
    SalaOpción
    Sala". $r->getNumber() ."Editar
    \n"; + echo "Añadir +
    +
    "; + } + drawHalls($rooms); +?> + diff --git a/panel_manager/panel_manager.php b/panel_manager/panel_manager.php index e393efb..c48f3b1 100644 --- a/panel_manager/panel_manager.php +++ b/panel_manager/panel_manager.php @@ -1,10 +1,7 @@ state = $panel; @@ -12,91 +9,21 @@ } - static function welcome(){ - $name = strtoupper($_SESSION['nombre']); - - $panel = '
    -

    Bienvenido '.$name.' a tu Panel de Manager.

    -
    -

    Usuario: '.$name.'

    -

    Espero que estes pasando un buen dia

    -
    '."\n"; - - return $panel; - } - - static function success(){ - $panel = '
    -

    Operacion completada.

    -
    -

    '.$_SESSION['msg'].'

    -
    '."\n"; - $_SESSION['msg'] = ""; - - return $panel; - } - - static function manage_halls(){ - $panel = '
    - - - - - - - - - '; - foreach(Hall::getListHalls("1") as $hall){ - $panel .=' - - - - - - '; - } - $panel.=' - -
    NumeroFilasColumnas
    '. $hall->getNumber().' '. $hall->getNumRows().' '. $hall->getNumCol().'
    - -
    '; - return $panel; - } - static function new_hall(){ - $panel = '
    -
    -

    Crear una sala.



    - '. - FormHall::generaCampoFormulario(null, null, "new"); - '. -
    -
    '."\n"; - - return $panel; - } - - static function edit_hall(){ - $panel = '
    -
    -

    Editar una sala.



    -
    -
    '."\n"; - - return $panel; - } - - static function manage_sessions(){ - $name = strtoupper($_SESSION['nombre']); - - $panel = '
    -

    Bienvenido '.$name.' a tu Panel de Manager.

    -
    -

    Usuario: '.$name.'

    -

    Espero que estes pasando un buen dia

    -
    '."\n"; - - return $panel; + function showPanel() { + if($this->login){ + switch($this->state) { + case 'us_u': echo "

    Esta vista no esta implementada

    "; break; + case 'us_r': echo "

    Esta vista no esta implementada

    "; break; + case 'rooms': require_once('manage_halls.php'); break; + case 'sessions': require_once('manage_sessions.php'); break; + case 'edit_session': require_once('edit_sessions.php'); break; + case 'edit_hall': require_once('edit_halls.php'); break; + default: require('hello_panel.php'); break; + } + } + else{ + echo "

    Error no tienes los permisos necesarios de gerente

    "; + } } } ?> \ No newline at end of file diff --git a/panel_manager/validateSession.php b/panel_manager/validateSession.php new file mode 100644 index 0000000..d97aedd --- /dev/null +++ b/panel_manager/validateSession.php @@ -0,0 +1,77 @@ + ERROR DE ACCESO

    " ; + + if(isset($_POST['new'])){ + $session->processesForm($_POST["film"], $_POST["hall"], $_SESSION["cinema"],$_POST["date"],$_POST["start"],$_POST["price"],$_POST["format"],$_POST["repeat"], "new"); + $reply = $session->getReply(); + $_SESSION["cinema"] = ""; + $_SESSION["hall"] = ""; + $_SESSION["date"] = ""; + $_SESSION["start"] = ""; + + } else if (isset($_POST['edit'])){ + $session->processesForm($_POST["film"], $_POST["hall"], $_SESSION["cinema"],$_POST["date"],$_POST["start"],$_POST["price"],$_POST["format"],"0", "edit"); + $reply = $session->getReply(); + $_SESSION["cinema"] = ""; + $_SESSION["hall"] = ""; + $_SESSION["date"] = ""; + $_SESSION["start"] = ""; + + } else if (isset($_POST['del'])){ + $session->processesForm($_POST["film"], $_POST["hall"], $_SESSION["cinema"],$_POST["date"],$_POST["start"],$_POST["price"],$_POST["format"],"0", "del"); + $reply = $session->getReply(); + $_SESSION["cinema"] = ""; + $_SESSION["hall"] = ""; + $_SESSION["date"] = ""; + $_SESSION["start"] = ""; + } + +?> + + + + + print_head(); + ?> + + + print_header(); + ?> + + +
    +
    +
    + + +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + + + print_footer(); + ?> + + + + \ No newline at end of file diff --git a/register/includes/formRegister.php b/register/includes/formRegister.php index 89798b3..d174315 100644 --- a/register/includes/formRegister.php +++ b/register/includes/formRegister.php @@ -49,6 +49,7 @@ class FormRegister extends Form { $pass = $this->test_input($pass); $repass = $this->test_input($repass); + $name = strtolower($name); $username = isset($name) ? $name : null ; if (!$username) { $register = false;