Add files via upload

This commit is contained in:
Fernando Méndez 2021-04-28 21:46:10 +02:00 committed by GitHub
parent 12a56f33bf
commit 9756959978
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 641 additions and 31 deletions

View File

@ -0,0 +1,103 @@
<?php
include_once('film_dto.php');
$template = new Template();
$prefix = $template->get_prefix();
include_once($prefix.'assets/php/dao.php');
class Film_DAO extends DAO {
//Constructor:
function __construct($bd_name){
parent::__construct($bd_name);
}
//Methods:
//Create a new Session.
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);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Returns a film data .
public function GetFilm($tittle,$language){
$sql = sprintf( "SELECT * FROM film WHERE film.tittle = '%s'AND film.language='%s'", $tittle,$language );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Returns a query to get the film's data.
public function FilmData($id){
$sql = sprintf( "SELECT * FROM film WHERE id = '%d'", $id );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Returns a query to get All the films.
public function allFilmData(){
$sql = sprintf( "SELECT * FROM film ");
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
while($fila=$resul->fetch_assoc()){
$films[] = $this->loadFilm($fila["id"], $fila["tittle"], $fila["duration"], $fila["language"], $fila["description"]);
}
$resul->free();
return $films;
}
//Returns a query to get all films tittles.
public function tittleFilmData(){
$sql = sprintf( "SELECT DISTINCT tittle FROM film ");
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Returns a query to get all films descriptions.
public function descriptionFilmData(){
$sql = sprintf( "SELECT description FROM film ");
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
/*
public function addFilm($films) {
$resul = mysqli_query($this->mysqli, $this->createFilm($film.getId(), $film.getTittle(), $film.getDuration(), $film.getLanguage(), $film.getDescription())) or die ('Error into query database');
return $resul;
}
*/
//Deleted film by "id".
public function deleteFilm($id){
$sql = sprintf( "DELETE FROM film WHERE film.id = '%d' ;",$id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Edit a film.
public function editFilm($id, $tittle, $duration, $language,$description){
$sql = sprintf( "UPDATE film SET tittle = '%s' , duration = '%d', language ='%s' , description ='%s'
WHERE film.id = '%d';",
$tittle, $duration, $language, $description, $id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Create a new film Data Transfer Object.
public function loadFilm($id, $tittle, $duration, $language,$description){
return new Film_DTO( $id, $tittle, $duration, $language,$description);
}
}
?>

View File

@ -0,0 +1,37 @@
<?php
include_once('film_dto_interface.php');
class Film_DTO implements FilmDTO {
//Attributes:
private $_id; //Film ID.
private $_tittle; //Film tittle.
private $_duration; //Film duration.
private $_language; //Film language.
private $_description; //Film description.
//Constructor:
function __construct($id, $tittle, $duration, $language, $description){
$this->_id = $id;
$this->_tittle = $tittle;
$this->_duration = $duration;
$this->_language = $language;
$this->_description = $description;
}
//Methods:
//Getters && Setters:
public function setId($id){ $this->_id = $id; }
public function getId(){ return $this->_id; }
public function setTittle($tittle) {$this->_tittle = $tittle; }
public function getTittle(){return $this->_tittle;}
public function setDuration($duration){$this->_duration = $duration; }
public function getDuration() {return $this->_duration;}
public function setLanguage($language) {$this->_language = $language; }
public function getLanguage(){return $this->_language;}
public function setDescription($description){ $this->_description = $description;}
public function getDescription(){return $this->_description;}
}
?>

View File

@ -0,0 +1,14 @@
<?php
interface FilmDTO {
public function setId($id);
public function getId();
public function setTittle($tittle);
public function getTittle();
public function setDuration($duration);
public function getDuration();
public function setLanguage($language);
public function getLanguage();
public function setDescription($description);
public function getDescription();
}
?>

View File

@ -0,0 +1,73 @@
<?php
require_once('../assets/php/dao.php');
include_once('hall_dto.php');
class HallDAO extends DAO {
//Constructor:
function __construct($bd_name){
parent::__construct($bd_name);
}
//Methods:
//Create a new Hall.
public function createHall($number, $idcinema, $numCol, $numRows){
$sql = sprintf( "INSERT INTO `hall`( `number`, `idcinema`, `numrows`, `numcolumns`)
VALUES ( '%d', '%d', '%i', '%i')",
$number, $idcinema, $numRows, $numCol );
return $sql;
}
//Returns a query to get the halls data.
public function getAllHalls($cinema){
$sql = sprintf( "SELECT * FROM hall WHERE
idcinema = '%s'",
$cinema);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
$hall = null;
while($fila=mysqli_fetch_array($resul)){
$hall[] = $this->loadHall($fila["number"], $fila["idcinema"], $fila["numrows"], $fila["numcolumns"]);
}
mysqli_free_result($resul);
return $hall;
}
//Create a new Hall Data Transfer Object.
public function loadHall($number, $idcinema, $numrows, $numcolumns){
return new HallDTO($number, $idcinema, $numrows, $numcolumns);
}
//Edit Hall.
public function editHall($id, $idcinema, $numCol, $numRows){
$sql = sprintf( "UPDATE `hall`
SET `numrows` = '%i' , `numcolumns` = '%i'
WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';",
$numRows,$numCol,$id, $idcinema );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Delete Hall.
public function deleteHall($id, $idcinema){
$sql = sprintf( "DELETE FROM `hall` WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';",$id,$idcinema);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
}
?>

View File

@ -0,0 +1,38 @@
<?php
include_once('hall_dto_interface.php');
class HallDTO implements HallsDTO {
//Attributes:
private $_number; //Room number.
private $_idcinema; //Cinema Id
private $_numRows; //Num rows.
private $_numCol; //Num columns.
//Constructor:
function __construct($number, $idcinema, $numRows, $numCol){
$this->_number = $number;
$this->_idcinema = $idcinema;
$this->_numRows = $numRows;
$this->_numCol = $numCol;
}
//Methods:
//Getters && Setters:
public function setNumber($number){ $this->_number = $number; }
public function getNumber(){ return $this->_number; }
public function setIdcinema($idcinema){ $this->_idcinema = $idcinema; }
public function getIdcinema(){ return $this->_idcinema; }
public function setNumRows($numRows){ $this->_numRows = $numRows; }
public function getNumRows(){ return $this->_numRows; }
public function setNumCol($numCol){ $this->_numCol = $numCol; }
public function getNumCol(){ return $this->_numCol; }
}
?>

View File

@ -0,0 +1,12 @@
<?php
interface HallsDTO {
public function setNumber($number);
public function getNumber();
public function setIdcinema($idcinema);
public function getIdcinema();
public function setNumCol($numCol);
public function getNumCol();
public function setNumRows($numRows);
public function getNumRows();
}
?>

View File

@ -0,0 +1,106 @@
<?php
require_once('../assets/php/dao.php');
include_once('session_dto.php');
class SessionDAO extends DAO {
//Constructor:
function __construct($bd_name){
parent::__construct($bd_name);
}
//Methods:
public function createSession($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
$format = $this->mysqli->real_escape_string($format);
$date = date('Y-m-d', strtotime( $date ) );
$startTime = date('H:i:s', strtotime( $startTime ) );
$sql = sprintf( "INSERT INTO `session` (`id`, `idfilm`, `idhall`, `idcinema`, `date`, `start_time`, `seat_price`, `format`)
VALUES ('%d', '%d', '%d', '%d', '%s', '%s', '%d', '%s')",
$id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $sql;
}
//Returns a query to get the session's data.
public function sessionData($id){
$sql = sprintf( "SELECT * FROM `session` WHERE id = '%d'", $id );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database en sessionData con la id '. $id);
return $resul;
}
//Returns the count of the session searched
public function searchSession($cinema, $hall, $startTime, $date){
$date = date('Y-m-d', strtotime( $date ) );
$startTime = date('H:i:s', strtotime( $startTime ) );
$sql = sprintf( "SELECT COUNT(*) FROM session WHERE
idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'",
$cinema, $hall, $date, $startTime);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
$session = null;
$session = mysqli_fetch_array($resul);
mysqli_free_result($resul);
return $session[0];
}
//Returns a query to get all the session's data.
public function getAllSessionsFromACinemaHallDate($cinema, $hall, $date){
$date = date('Y-m-d', strtotime( $date ) );
$sql = sprintf( "SELECT * FROM session WHERE
idcinema = '%s' AND idhall = '%s' AND date = '%s'",
$cinema, $hall, $date);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
$sessions = null;
while($fila=mysqli_fetch_array($resul)){
$sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"]);
}
mysqli_free_result($resul);
return $sessions;
}
public function editSession($idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
$format = $this->mysqli->real_escape_string($format);
$date = date('Y-m-d', strtotime( $date ) );
$startTime = date('H:i:s', strtotime( $startTime ) );
$sql = sprintf( "UPDATE `session`
SET `idfilm` = '%d' , `idhall` = '%d', `idcinema` = '%d', `date` = '%s',
`start_time` = '%s', `seat_price` = '%d', `format` = '%s'
WHERE
idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'",
$idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $_SESSION["cinema"],$_SESSION["hall"],$_SESSION["date"],$_SESSION["start"]);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
public function deleteSession($hall, $cinema, $date, $startTime){
$sql = sprintf( "DELETE FROM `session` WHERE
idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'",
$cinema, $hall, $date, $startTime);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Create a new Session Data Transfer Object.
public function loadSession( $id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
return new SessionDTO( $id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format);
}
}
?>

View File

@ -0,0 +1,56 @@
<?php
include_once('session_dto_interface.php');
class SessionDTO implements SessionsDTO {
//Attributes:
private $_id;
private $_idfilm;
private $_idhall;
private $_idcinema;
private $_date;
private $_startTime;
private $_seatPrice;
private $_format;
//Constructor:
function __construct($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
$this->_id = $id;
$this->_idfilm = $idfilm;
$this->_idhall = $idhall;
$this->_idcinema = $idcinema;
$this->_date = $date;
$this->_startTime = $startTime;
$this->_seatPrice = $seatPrice;
$this->_format = $format;
}
//Methods:
//Getters && Setters:
public function setId($id){ $this->_id = $id; }
public function getId(){ return $this->_id; }
public function setIdfilm($idfilm){ $this->_idfilm = $idfilm; }
public function getIdfilm(){ return $this->_idfilm; }
public function setIdhall($idhall){ $this->_idhall = $idhall; }
public function getIdhall(){ return $this->_idhall; }
public function setIdcinema($cinema){ $this->_idcinema = $idcinema; }
public function getIdcinema(){ return $this->_idcinema; }
public function setDate($date){ $this->_date = $date; }
public function getDate(){ return $this->_date; }
public function setStartTime($startTime){ $this->_startTime = $startTime; }
public function getStartTime(){ return $this->_startTime; }
public function setSeatPrice($seatPrice){ $this->_seatPrice = $seatPrice; }
public function getSeatPrice(){ return $this->_seatPrice; }
public function setFormat($format){ $this->_format = $format; }
public function getFormat(){ return $this->_format; }
}
?>

View File

@ -0,0 +1,20 @@
<?php
interface SessionsDTO {
public function setId($id);
public function getId();
public function setIdfilm($idfilm);
public function getIdfilm();
public function setIdhall($film);
public function getIdhall();
public function setIdcinema($cinema);
public function getIdcinema();
public function setDate($date);
public function getDate();
public function setStartTime($startTime);
public function getStartTime();
public function setSeatPrice($seatPrice);
public function getSeatPrice();
public function setFormat($format);
public function getFormat();
}
?>

View File

@ -0,0 +1,95 @@
<?php
require_once('../assets/php/dao.php');
include_once('user_dto.php');
class UserDAO extends DAO {
//Constants:
private const _USER = "user";
private const _MANAGER = "manager";
private const _ADMIN = "admin";
//Attributes:
//Constructor:
function __construct($bd_name){
parent::__construct($bd_name);
}
//Methods:
//Encrypt password with SHA254.
private function encryptPass($password){
//$password = hash('sha256', $password);
$password = password_hash($password, PASSWORD_DEFAULT);
return $password;
}
//Returns true if the password and hash match, or false otherwise.
public function verifyPass($password, $passwd){
return password_verify($password, $passwd);
}
//Create a new User.
public function createUser($id, $username, $email, $password, $rol){
$password = $this->encryptPass($password);
$sql = sprintf( "INSERT INTO users( id, username, email, passwd, rol)
VALUES ( '%s', '%s', '%s', '%s', '%s')",
$id, $username, $email, $password, $rol );
$resul = mysqli_query($this->mysqli, $sql) /*or die ('Error into query database')*/;
return $resul;
}
//Returns a query to check if the user name exists.
public function selectUser($username, $password){
$username = $this->mysqli->real_escape_string($username);
$sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
$resul->data_seek(0);
while ($fila = $resul->fetch_assoc()) {
if($username === $fila['username'] && $this->verifyPass($password, $fila['passwd'])){
$user = $this->loadUser($fila['id'], $fila['username'], $fila['email'], $fila['passwd'], $fila['rol']);
}
}
//mysqli_free_result($selectUser);
$resul->free();
return $user;
}
//Returns a query to check if the user pass matches.
public function selectPass($username, $password){
$username = $this->mysqli->real_escape_string($username);
$password = $this->mysqli->real_escape_string($password);
$password = $this->encryptPass($password);
$sql = sprintf( "SELECT * FROM users WHERE username = '%s' AND passwd = '%s'", $username, $password);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
//return $this->mysqli->query($sql);
return $resul;
}
//Returns a query to get the user's data.
public function userData($id){
$sql = sprintf( "SELECT * FROM users WHERE id = '%d'", $id );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Create a new User Data Transfer Object.
public function loadUser($id, $username, $email, $password, $rol){
return new UserDTO($id, $username, $email, $password, $rol);
}
}
?>

View File

@ -0,0 +1,37 @@
<?php
include_once('users_dto_interface.php');
class UserDTO implements UsersInterface {
//Attributes:
private $_id; //User Id.
private $_username; //User name.
private $_email; //User email.
private $_password; //User password.
private $_rol; //Type of user: user | manager | admin. --> Será eliminado en la siguiente práctica para usar el modelo relacional de nuestra BD.
//Constructor:
function __construct($id, $username, $email, $password, $rol){
$this->_id = $id;
$this->_username = $username;
$this->_email = $email;
$this->_password = $password;
$this->_rol = $rol;
}
//Methods:
//Getters && Setters:
public function setId($id){ $this->_id = $id; }
public function getId(){ return $this->_id; }
public function setName($username){ $this->_username = $username; }
public function getName(){ return $this->_username; }
public function setEmail($email){ $this->_email = $email; }
public function getEmail(){ return $this->_email; }
public function setPass($passwd){ $this->_password = $passwd; }
public function getPass(){ return $this->_password; }
public function setRol($rol){ $this->_rol = $rol; }
public function getRol(){ return $this->_rol; }
}
?>

View File

@ -0,0 +1,14 @@
<?php
interface UsersInterface {
public function setId($id);
public function getId();
public function setName($username);
public function getName();
public function setEmail($email);
public function getEmail();
public function setPass($passwd);
public function getPass();
public function setRol($rol);
public function getRol();
}
?>

View File

@ -2,10 +2,10 @@
// TO-DO: Completar
class DAO {
//Constants:
private const _SERVERNAME = "localhost";
private const _USERNAME = "sw";
private const _PASSWORD = "_admin_";
private const _BD = "complucine";
private const _SERVERNAME = BD_HOST;
private const _USERNAME = BD_USER;
private const _PASSWORD = BD_PASS;
private const _BD = BD_NAME;
//Atributes:
public $mysqli;

View File

@ -1,10 +1,10 @@
<!DOCTYPE HTML>
<?php
//General Config File:
require_once('./assets/php/config.php');
//General Config File:
require_once(__DIR__.'/assets/php/config.php');
//List of the tittles of the movies:
require_once($prefix.'panel_admin/includes/film_dao.php');
require_once($prefix.'assets/php/common/film_dao.php');
$films = new Film_DAO("complucine");
$films_array = $films->allFilmData();
$tittles = array();

View File

@ -1,6 +1,6 @@
<?php
include_once('user_dao.php');
include_once($prefix.'assets/php/common/user_dao.php');
include_once($prefix.'assets/php/form.php');
class FormLogin extends Form {

View File

@ -1,7 +1,8 @@
<?php
include_once('../assets/php/config.php');
include_once('film_dao.php');
include_once('film_dto.php');
include_once('../assets/php/common/film_dao.php');
include_once('../assets/php/common/film_dto.php');
include_once('../assets/php/form.php');
class FormFilm extends Form {

View File

@ -3,7 +3,7 @@
//General Config File:
include_once('../assets/php/config.php');
require_once('../panel_admin/panelAdmin.php');
require_once($prefix.'panel_admin/panelAdmin.php');
$login=false;
if(isset($_SESSION["login"]) && $_SESSION["rol"] == "admin") $login = true;

View File

@ -1,6 +1,10 @@
<?php
include_once('./includes/film_dto.php');
include_once('./includes/formFilm.php');
//General Config File:
include_once('../assets/php/config.php');
include_once('../assets/php/common/film_dto.php');
include_once(__DIR__.'/includes/formFilm.php');
/*$f1 = new FilmDTO(1000,"Los vengadores",183,"español","");
$f2 = new FilmDTO(2001,"Mecernarios",140,"español","");
$f3 = new FilmDTO(3022,"Monster hunter",104,"español","");

View File

@ -1,5 +1,5 @@
<?php
require_once('../assets/php/dao.php');
require_once($prefix.'assets/php/dao.php');
include_once('./includes/formFilm.php');
if(isset($_POST['edit_film'])) {

View File

@ -1,6 +1,6 @@
<?php
include_once('./includes/film_dto.php');
include_once('./includes/formFilm.php');
include_once($prefix.'assets/php/common/film_dto.php');
include_once($prefix.'assets/php/common/formFilm.php');
if(isset($_POST['add_film'])) {
$film = new FormFilm();

View File

@ -1,15 +1,15 @@
<?php
//General Config File:
require_once('../assets/php/config.php');
require_once($prefix.'assets/php/config.php');
include_once('./includes/formHall.php');
require_once('./includes/hall_dto.php');
require_once($prefix.'assets/php/common/hall_dto.php');
require_once('./includes/session_dto.php');
include_once('./includes/session_dao.php');
require_once($prefix.'assets/php/common/session_dto.php');
include_once($prefix.'assets/php/common/session_dao.php');
require_once('../panel_admin/includes/film_dto.php');
include_once('../panel_admin/includes/film_dao.php');
require_once($prefix.'assets/php/common/film_dto.php');
include_once($prefix.'assets/php/common/film_dao.php');
$formHall = new FormHall();
$formHall->processesForm(null, $_SESSION["cinema"], null, null, "list");

View File

@ -1,5 +1,5 @@
<?php
include_once('hall_dao.php');
include_once('../assets/php/common/hall_dao.php');
include_once('../assets/php/form.php');
class FormHall extends Form {

View File

@ -1,5 +1,5 @@
<?php
include_once('session_dao.php');
include_once('../assets/php/common/session_dao.php');
include_once('../assets/php/form.php');
//Receive data from froms and prepare the correct response

View File

@ -1,5 +1,5 @@
<?php
require('./includes/hall_dto.php');
require('../assets/php/common/hall_dto.php');
$r1 = new HallDTO(0,20,20,30);
$r2 = new HallDTO(1,10,30,30);

View File

@ -2,14 +2,14 @@
//General Config File:
require_once('../assets/php/config.php');
include_once('./includes/hall_dto.php');
include_once('../assets/php/common/hall_dto.php');
include_once('./includes/formHall.php');
include_once('./includes/session_dto.php');
include_once('../assets/php/common/session_dto.php');
include_once('./includes/formSession.php');
include_once('../panel_admin/includes/film_dto.php');
include_once('../panel_admin/includes/film_dao.php');
include_once('../assets/php/common/film_dto.php');
include_once('../assets/php/common/film_dao.php');
$formSession = new FormSession();
$formHall = new FormHall();

View File

@ -1,6 +1,6 @@
<?php
include_once($prefix.'login/includes/user_dao.php');
include_once($prefix.'assets/php/common/user_dao.php');
include_once($prefix.'assets/php/form.php');
class FormRegister extends Form {

View File

@ -4,7 +4,7 @@
require_once('../assets/php/config.php');
//List of the tittles and descriptions of the movies:
require_once($prefix.'panel_admin/includes/film_dao.php');
require_once($prefix.'assets/php/common/film_dao.php');
$loadFilms = new Film_DAO("complucine");
$films = $loadFilms->allFilmData();
$titles = array();