Add files via upload
This commit is contained in:
		
							
								
								
									
										39
									
								
								root/assets/php/HTMLtemplate.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								root/assets/php/HTMLtemplate.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
<!--
 | 
			
		||||
    Práctica - Sistemas Web | Grupo D
 | 
			
		||||
    CompluCine - FDI-cines
 | 
			
		||||
-->
 | 
			
		||||
<!DOCTYPE HTML>
 | 
			
		||||
<html lang="es">
 | 
			
		||||
    <!-- Head -->
 | 
			
		||||
    <?php
 | 
			
		||||
        $template->print_head();
 | 
			
		||||
    ?>
 | 
			
		||||
    <body>
 | 
			
		||||
        <!-- Header -->
 | 
			
		||||
        <?php
 | 
			
		||||
            $template->print_header();
 | 
			
		||||
        ?>
 | 
			
		||||
 | 
			
		||||
        <!-- Main -->
 | 
			
		||||
        <?php
 | 
			
		||||
            if(!isset($content)) $content = "";
 | 
			
		||||
            $template->print_main($content);
 | 
			
		||||
        ?>
 | 
			
		||||
 | 
			
		||||
        <!-- Section -->
 | 
			
		||||
        <?php
 | 
			
		||||
            $template->print_section($section);
 | 
			
		||||
        ?>
 | 
			
		||||
 | 
			
		||||
        <!-- Footer -->
 | 
			
		||||
        <?php
 | 
			
		||||
            $template->print_footer();
 | 
			
		||||
        ?>
 | 
			
		||||
 | 
			
		||||
        <!-- Scripts -->
 | 
			
		||||
        <?php
 | 
			
		||||
            $template->print_scripts();
 | 
			
		||||
        ?>
 | 
			
		||||
       
 | 
			
		||||
    </body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										138
									
								
								root/assets/php/aplication.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										138
									
								
								root/assets/php/aplication.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,138 @@
 | 
			
		||||
<?php
 | 
			
		||||
require_once('config.php');
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Clase que mantiene el estado global de la aplicación.
 | 
			
		||||
 */
 | 
			
		||||
class Aplicacion {
 | 
			
		||||
	private static $instancia;
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Permite obtener una instancia de <code>Aplicacion</code>.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @return Applicacion Obtiene la única instancia de la <code>Aplicacion</code>
 | 
			
		||||
	 */
 | 
			
		||||
	public static function getSingleton() {
 | 
			
		||||
		if (  !self::$instancia instanceof self) {
 | 
			
		||||
			self::$instancia = new self;
 | 
			
		||||
		}
 | 
			
		||||
		return self::$instancia;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @var array Almacena los datos de configuración de la BD
 | 
			
		||||
	 */
 | 
			
		||||
	private $bdDatosConexion;
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Almacena si la Aplicacion ya ha sido inicializada.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @var boolean
 | 
			
		||||
	 */
 | 
			
		||||
	private $inicializada = false;
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * @var \mysqli Conexión de BD.
 | 
			
		||||
	 */
 | 
			
		||||
	private $conn;
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Evita que se pueda instanciar la clase directamente.
 | 
			
		||||
	 */
 | 
			
		||||
	private function __construct() {}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Evita que se pueda utilizar el operador clone.
 | 
			
		||||
	 */
 | 
			
		||||
	public function __clone() {
 | 
			
		||||
		throw new \Exception('No tiene sentido el clonado.');
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Evita que se pueda utilizar serialize().
 | 
			
		||||
	 */
 | 
			
		||||
	public function __sleep() {
 | 
			
		||||
		throw new \Exception('No tiene sentido el serializar el objeto.');
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Evita que se pueda utilizar unserialize().
 | 
			
		||||
	 */
 | 
			
		||||
	public function __wakeup() {
 | 
			
		||||
		throw new \Exception('No tiene sentido el deserializar el objeto.');
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Inicializa la aplicación.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param array $bdDatosConexion datos de configuración de la BD
 | 
			
		||||
	 */
 | 
			
		||||
	public function init($bdDatosConexion) {
 | 
			
		||||
        if ( ! $this->inicializada ) {
 | 
			
		||||
    	    $this->bdDatosConexion = $bdDatosConexion;
 | 
			
		||||
			if ( $this->is_session_started() === FALSE ) session_start();
 | 
			
		||||
    		$this->inicializada = true;
 | 
			
		||||
        }
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Inicia la sesión, si esta no se había iniciado.
 | 
			
		||||
	 */
 | 
			
		||||
	protected function is_session_started(){
 | 
			
		||||
		if ( php_sapi_name() !== 'cli' ) {
 | 
			
		||||
			if ( version_compare(phpversion(), '5.4.0', '>=') ) {
 | 
			
		||||
				return session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE;
 | 
			
		||||
			} else {
 | 
			
		||||
				return session_id() === '' ? FALSE : TRUE;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return FALSE;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Cierre de la aplicación.
 | 
			
		||||
	 */
 | 
			
		||||
	public function shutdown() {
 | 
			
		||||
	    $this->compruebaInstanciaInicializada();
 | 
			
		||||
	    if ($this->conn !== null) {
 | 
			
		||||
	        $this->conn->close();
 | 
			
		||||
	    }
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Comprueba si la aplicación está inicializada. Si no lo está muestra un mensaje y termina la ejecución.
 | 
			
		||||
	 */
 | 
			
		||||
	private function compruebaInstanciaInicializada() {
 | 
			
		||||
	    if (! $this->inicializada ) {
 | 
			
		||||
	        echo "ERROR 403: app_not_configured.";
 | 
			
		||||
	        exit();
 | 
			
		||||
	    }
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Devuelve una conexión a la BD. Se encarga de que exista como mucho una conexión a la BD por petición.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @return \mysqli Conexión a MySQL.
 | 
			
		||||
	 */
 | 
			
		||||
	public function conexionBd() {
 | 
			
		||||
	    $this->compruebaInstanciaInicializada();
 | 
			
		||||
		if (! $this->conn ) {
 | 
			
		||||
			$bdHost = $this->bdDatosConexion['host'];
 | 
			
		||||
			$bdUser = $this->bdDatosConexion['user'];
 | 
			
		||||
			$bdPass = $this->bdDatosConexion['pass'];
 | 
			
		||||
			$bd = $this->bdDatosConexion['bd'];
 | 
			
		||||
			
 | 
			
		||||
			$this->conn = new \mysqli($bdHost, $bdUser, $bdPass, $bd);
 | 
			
		||||
			if ( $this->conn->connect_errno ) {
 | 
			
		||||
				echo "Error de conexión a la BD: (" . $this->conn->connect_errno . ") " . utf8_encode($this->conn->connect_error);
 | 
			
		||||
				exit();
 | 
			
		||||
			}
 | 
			
		||||
			if ( ! $this->conn->set_charset("utf8mb4")) {
 | 
			
		||||
				echo "Error al configurar la codificación de la BD: (" . $this->conn->errno . ") " . utf8_encode($this->conn->error);
 | 
			
		||||
				exit();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return $this->conn;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								root/assets/php/common/changeCSS-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								root/assets/php/common/changeCSS-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
<?php
 | 
			
		||||
    include('../../../assets/php/config.php');
 | 
			
		||||
 | 
			
		||||
    switch(true){
 | 
			
		||||
        case strpos($_GET["css"], "main.css"): $_SESSION["css"] = "main.css"; break;
 | 
			
		||||
        case strpos($_GET["css"], "highContrast.css"): $_SESSION["css"] = "highContrast.css"; break;
 | 
			
		||||
        default: $_SESSION["css"] = "main.css"; break;
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										6
									
								
								root/assets/php/common/changeCSS.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								root/assets/php/common/changeCSS.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
<?php
 | 
			
		||||
    include('../../../assets/php/config.php');
 | 
			
		||||
 | 
			
		||||
    if($_GET["css"] === "main.css") $_SESSION["css"] = "main.css";
 | 
			
		||||
    else if($_GET["css"] === "highContrast.css") $_SESSION["css"] = "highContrast.css";
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										15
									
								
								root/assets/php/common/checkEmail.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								root/assets/php/common/checkEmail.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
<?php    
 | 
			
		||||
    include('../../../assets/php/config.php');
 | 
			
		||||
    include('../includes/user_dao.php');
 | 
			
		||||
 | 
			
		||||
    $bd = new UserDAO('complucine');
 | 
			
		||||
    if($bd){
 | 
			
		||||
        $user = $bd->selectUserEmail(strtolower($_GET["email"]));
 | 
			
		||||
        if ($user->data_seek(0)) {
 | 
			
		||||
            echo "!avaliable";
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
            echo "avaliable";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										15
									
								
								root/assets/php/common/checkPromo.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								root/assets/php/common/checkPromo.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
<?php    
 | 
			
		||||
    include('../../../assets/php/config.php');
 | 
			
		||||
    include('../includes/promotion_dao.php');
 | 
			
		||||
 | 
			
		||||
    $bd = new Promotion_DAO('complucine');
 | 
			
		||||
    if($bd){
 | 
			
		||||
        $promo = $bd->GetPromotionObj($_GET["code"]);
 | 
			
		||||
        if ($promo && $promo->getActive()) {
 | 
			
		||||
            echo "avaliable";
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
            echo "!avaliable";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										15
									
								
								root/assets/php/common/checkUser.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								root/assets/php/common/checkUser.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
<?php    
 | 
			
		||||
    include('../../../assets/php/config.php');
 | 
			
		||||
    include('../includes/user_dao.php');
 | 
			
		||||
 | 
			
		||||
    $bd = new UserDAO('complucine');
 | 
			
		||||
    if($bd){
 | 
			
		||||
        $user = $bd->selectUserName(strtolower($_GET["user"]));
 | 
			
		||||
        if ($user->data_seek(0)) {
 | 
			
		||||
            echo "!avaliable";
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
            echo "avaliable";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										32
									
								
								root/assets/php/common/cinema.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								root/assets/php/common/cinema.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
<?php
 | 
			
		||||
    
 | 
			
		||||
    class Cinema{
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_id;               //Cinema ID.
 | 
			
		||||
        private $_name;           //Cinema name.
 | 
			
		||||
        private $_direction;         //Cinema direction.
 | 
			
		||||
        private $_phone;         //Cinema phone.
 | 
			
		||||
      
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($id, $name, $direction, $phone){
 | 
			
		||||
            $this->_id = $id;
 | 
			
		||||
            $this->_name = $name;
 | 
			
		||||
            $this->_direction = $direction;
 | 
			
		||||
            $this->_phone = $phone;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
		//Getters && Setters:
 | 
			
		||||
        public function setId($id){	$this->_id = $id; }
 | 
			
		||||
		public function getId(){ return $this->_id; }
 | 
			
		||||
        public function setName($name){	$this->_name = $name; }
 | 
			
		||||
		public function getName(){ return $this->_name; }
 | 
			
		||||
        public function setDirection($direction){ $this->_direction = $direction; }
 | 
			
		||||
		public function getDirection(){ return $this->_direction; }
 | 
			
		||||
        public function setPhone($phone){$this->_phone = $phone; }
 | 
			
		||||
		public function getPhone(){ return $this->_phone; }
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										77
									
								
								root/assets/php/common/cinema_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								root/assets/php/common/cinema_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,77 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('cinema.php');
 | 
			
		||||
 | 
			
		||||
    class Cinema_DAO extends DAO {
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
        //Create a new Session.
 | 
			
		||||
		public function createCinema($id, $name, $direction, $phone){
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `cinema`( `id`, `name`, `direction`, `phone`) 
 | 
			
		||||
								VALUES ( '%d', '%s', '%s', '%s')", 
 | 
			
		||||
									$id, $name, $direction, $phone);
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
	    //Returns a query to get All the films.
 | 
			
		||||
		public function allCinemaData(){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM cinema ");
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$films[] = $this->loadCinema($fila["id"], $fila["name"], $fila["direction"], $fila["phone"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
			return $films;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a  film data .
 | 
			
		||||
		public function GetCinema($name,$direction){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM cinema WHERE cinema.name = '%s'AND cinema.direction='%s'", $name,$direction );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a  film data .
 | 
			
		||||
		public function cinemaData($id){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM cinema WHERE cinema.id = '%d'", $id);
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Deleted film by "id".
 | 
			
		||||
		public function deleteCinema($id){
 | 
			
		||||
			$sql = sprintf( "DELETE FROM cinema WHERE cinema.id = '%d' ;",$id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Edit a film.
 | 
			
		||||
		public function editCinema($id, $name, $direction, $phone){
 | 
			
		||||
			$sql = sprintf( "UPDATE cinema SET name = '%s' , direction = '%s', phone ='%s' 
 | 
			
		||||
								WHERE cinema.id = '%d';", 
 | 
			
		||||
									$name, $direction, $phone, $id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
	    
 | 
			
		||||
		//Create a new film Data Transfer Object.
 | 
			
		||||
		public function loadCinema($id, $name, $direction, $phone){
 | 
			
		||||
			return new Cinema($id, $name, $direction, $phone);
 | 
			
		||||
		}
 | 
			
		||||
	    	
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										39
									
								
								root/assets/php/common/film.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								root/assets/php/common/film.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
<?php
 | 
			
		||||
   
 | 
			
		||||
    class Film{
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_id;               //Film ID.
 | 
			
		||||
        private $_tittle;           //Film tittle.
 | 
			
		||||
        private $_duration;         //Film duration.
 | 
			
		||||
        private $_language;         //Film language.
 | 
			
		||||
        private $_description;      //Film description.
 | 
			
		||||
        private $_img;
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($id, $tittle, $duration, $language, $description, $img){
 | 
			
		||||
            $this->_id = $id;
 | 
			
		||||
            $this->_tittle = $tittle;
 | 
			
		||||
            $this->_duration = $duration;
 | 
			
		||||
            $this->_language = $language;
 | 
			
		||||
            $this->_description = $description;
 | 
			
		||||
            $this->_img = $img;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//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;}
 | 
			
		||||
        public function setImg($img){  $this->_img = $img;}
 | 
			
		||||
		public function getImg(){return   $this->_img;}
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										100
									
								
								root/assets/php/common/film_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								root/assets/php/common/film_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,100 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('film.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, $img){
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `film`( `id`, `tittle`, `duration`, `language`,`description`, `img`) 
 | 
			
		||||
								VALUES ( '%d', '%s', '%d', '%s','%s', '%s')", 
 | 
			
		||||
									$id, $tittle, $duration, $language, $description, $img);
 | 
			
		||||
			
 | 
			
		||||
			$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"], $fila["img"]);
 | 
			
		||||
			}
 | 
			
		||||
			$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,$img){
 | 
			
		||||
			$sql = sprintf( "UPDATE film SET tittle = '%s' , duration = '%d', language ='%s' , description ='%s', img ='%s'
 | 
			
		||||
								WHERE film.id = '%d';", 
 | 
			
		||||
									$tittle, $duration, $language, $description, $img, $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, $img){
 | 
			
		||||
			return new Film( $id, $tittle, $duration, $language,$description, $img);
 | 
			
		||||
		}
 | 
			
		||||
	    	
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										126
									
								
								root/assets/php/common/formUploadFiles.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										126
									
								
								root/assets/php/common/formUploadFiles.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,126 @@
 | 
			
		||||
<?php
 | 
			
		||||
require_once('../assets/php/form.php');
 | 
			
		||||
 | 
			
		||||
class FormUploadFiles extends Form {
 | 
			
		||||
    //Constants:
 | 
			
		||||
    const HTML5_EMAIL_REGEXP = '^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$'; 
 | 
			
		||||
 | 
			
		||||
    public function __construct() {
 | 
			
		||||
        $options = array('enctype' => 'multipart/form-data');
 | 
			
		||||
        parent::__construct('formUploadFiles', $options);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    protected function generaCamposFormulario($datos, $errores = array()) {
 | 
			
		||||
 | 
			
		||||
        // Se generan los mensajes de error si existen.
 | 
			
		||||
        $htmlErroresGlobales = self::generaListaErroresGlobales($errores);
 | 
			
		||||
        $errorFile = self::createMensajeError($errores, 'archivo', 'span', array('class' => 'error'));
 | 
			
		||||
 | 
			
		||||
        foreach($datos as $key => $value){
 | 
			
		||||
            $dats = $key." ".$value."  ";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Se genera el HTML asociado a los campos del formulario y los mensajes de error.
 | 
			
		||||
        $html = '
 | 
			
		||||
                <div class="file">
 | 
			
		||||
                    <label for="file">Imagen:</label><input type="file" name="file" id="file" /><pre>'.$htmlErroresGlobales.'</pre>
 | 
			
		||||
                </div>
 | 
			
		||||
                <input type="submit" id="submit" value="Subir" class="primary" /><pre>'.$errorFile.'</pre>
 | 
			
		||||
                ';
 | 
			
		||||
 | 
			
		||||
        return $html;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function procesaFormulario($datos) {
 | 
			
		||||
        // Solo se pueden definir arrays como constantes en PHP >= 5.6
 | 
			
		||||
        global $ALLOWED_EXTENSIONS;
 | 
			
		||||
        
 | 
			
		||||
        $result = array();
 | 
			
		||||
        $ok = count($_FILES) == 1 && $_FILES['archivo']['error'] == UPLOAD_ERR_OK;
 | 
			
		||||
        
 | 
			
		||||
        if ( $ok ) {
 | 
			
		||||
            $archivo = $_FILES['archivo'];
 | 
			
		||||
            $nombre = $_FILES['archivo']['name'];
 | 
			
		||||
            /* 1.a) Valida el nombre del archivo */
 | 
			
		||||
            $ok = $this->check_file_uploaded_name($nombre) && $this->check_file_uploaded_length($nombre) ;
 | 
			
		||||
            /* 1.b) Sanitiza el nombre del archivo 
 | 
			
		||||
            $ok = sanitize_file_uploaded_name($nombre);
 | 
			
		||||
            */
 | 
			
		||||
            /* 1.c) Utilizar un id de la base de datos como nombre de archivo */
 | 
			
		||||
 | 
			
		||||
            /* 2. comprueba si la extensión está permitida*/
 | 
			
		||||
            $ok = $ok && in_array(pathinfo($nombre, PATHINFO_EXTENSION), $ALLOWED_EXTENSIONS);
 | 
			
		||||
 | 
			
		||||
            /* 3. comprueba el tipo mime del archivo correspode a una imagen image/* */
 | 
			
		||||
            $finfo = finfo_open(FILEINFO_MIME_TYPE);
 | 
			
		||||
            $mimeType = finfo_file($finfo, $_FILES['archivo']['tmp_name']);
 | 
			
		||||
            $ok = preg_match('/image\/*./', $mimeType);
 | 
			
		||||
            finfo_close($finfo);
 | 
			
		||||
 | 
			
		||||
            if ( $ok ) {
 | 
			
		||||
            $tmp_name = $_FILES['archivo']['tmp_name'];
 | 
			
		||||
 | 
			
		||||
            if ( !move_uploaded_file($tmp_name, FILMS_DIR.$nombre) ) {
 | 
			
		||||
                $result[] = 'Error al mover el archivo';
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 4. Si fuese necesario guardar en la base de datos la ruta relativa $nombre del archivo
 | 
			
		||||
            //return "index.php#img=".urlencode('img/'.$nombre);
 | 
			
		||||
            } else {
 | 
			
		||||
                $result["errorFile"] = 'El archivo tiene un nombre o tipo no soportado';
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            $result[] = 'Error al subir el archivo.';
 | 
			
		||||
        }
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Check $_FILES[][name]
 | 
			
		||||
     *
 | 
			
		||||
     * @param (string) $filename - Uploaded file name.
 | 
			
		||||
     * @author Yousef Ismaeil Cliprz
 | 
			
		||||
     * @See http://php.net/manual/es/function.move-uploaded-file.php#111412
 | 
			
		||||
     */
 | 
			
		||||
    protected function check_file_uploaded_name ($filename) {
 | 
			
		||||
        return (bool) ((mb_ereg_match('/^[0-9A-Z-_\.]+$/i',$filename) === 1) ? true : false );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sanitize $_FILES[][name]. Remove anything which isn't a word, whitespace, number
 | 
			
		||||
     * or any of the following caracters -_~,;[]().
 | 
			
		||||
     *
 | 
			
		||||
     * If you don't need to handle multi-byte characters you can use preg_replace
 | 
			
		||||
     * rather than mb_ereg_replace.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param (string) $filename - Uploaded file name.
 | 
			
		||||
     * @author Sean Vieira
 | 
			
		||||
     * @see http://stackoverflow.com/a/2021729
 | 
			
		||||
     */
 | 
			
		||||
    protected function sanitize_file_uploaded_name($filename) {
 | 
			
		||||
        /* Remove anything which isn't a word, whitespace, number
 | 
			
		||||
        * or any of the following caracters -_~,;[]().
 | 
			
		||||
        * If you don't need to handle multi-byte characters
 | 
			
		||||
        * you can use preg_replace rather than mb_ereg_replace
 | 
			
		||||
        * Thanks @Łukasz Rysiak!
 | 
			
		||||
        */
 | 
			
		||||
        $newName = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $filename);
 | 
			
		||||
        // Remove any runs of periods (thanks falstro!)
 | 
			
		||||
        $newName = mb_ereg_replace("([\.]{2,})", '', $newName);
 | 
			
		||||
 | 
			
		||||
        return $newName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Check $_FILES[][name] length.
 | 
			
		||||
     *
 | 
			
		||||
     * @param (string) $filename - Uploaded file name.
 | 
			
		||||
     * @author Yousef Ismaeil Cliprz.
 | 
			
		||||
     * @See http://php.net/manual/es/function.move-uploaded-file.php#111412
 | 
			
		||||
     */
 | 
			
		||||
    protected function check_file_uploaded_length ($filename) {
 | 
			
		||||
        return (bool) ((mb_strlen($filename,'UTF-8') < 250) ? true : false);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										103
									
								
								root/assets/php/common/hall.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								root/assets/php/common/hall.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,103 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once($prefix.'assets/php/common/hall_dao.php');
 | 
			
		||||
	include_once('seat_dao.php');
 | 
			
		||||
	
 | 
			
		||||
    class Hall{
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_number;      //Room number.
 | 
			
		||||
        private $_idcinema;    //Cinema Id
 | 
			
		||||
		private $_numRows;     //Num rows.
 | 
			
		||||
        private $_numCol;      //Num columns.
 | 
			
		||||
		private $_total_seats;
 | 
			
		||||
		private $_seats_map;
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($number, $idcinema, $numRows, $numCol, $total_seats, $seats_map){
 | 
			
		||||
            $this->_number = $number;
 | 
			
		||||
            $this->_idcinema = $idcinema;
 | 
			
		||||
            $this->_numRows = $numRows;
 | 
			
		||||
			$this->_numCol = $numCol;
 | 
			
		||||
			$this->_total_seats = $total_seats;
 | 
			
		||||
			$_seats_map = array();
 | 
			
		||||
			$_seats_map = $seats_map;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
		public static function getListHalls($cinema){
 | 
			
		||||
			$bd = new HallDAO('complucine');
 | 
			
		||||
			if($bd )
 | 
			
		||||
				return $bd->getAllHalls($cinema);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public static function create_hall($number, $cinema, $rows, $cols, $seats, $seats_map){
 | 
			
		||||
			$bd = new HallDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if(!$bd->searchHall($number, $cinema)){
 | 
			
		||||
					$bd->createHall($number, $cinema, $rows, $cols, $seats, $seats_map);
 | 
			
		||||
					Seat::createSeats($number, $cinema, $rows, $cols, $seats_map);
 | 
			
		||||
					return "Se ha creado la sala con exito";
 | 
			
		||||
				} else {
 | 
			
		||||
					return "Esta sala ya existe";
 | 
			
		||||
				}
 | 
			
		||||
			} else { return "Error al conectarse a la base de datos"; }
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static function edit_hall($number, $cinema, $rows, $cols, $seats, $seats_map, $og_number){
 | 
			
		||||
			$bd = new HallDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if($bd->searchHall($og_number, $cinema)){
 | 
			
		||||
					if($og_number == $number){
 | 
			
		||||
						Seat::deleteAllSeats($number, $cinema);
 | 
			
		||||
						$bd->editHall($number, $cinema, $rows, $cols, $seats, $og_number);
 | 
			
		||||
						Seat::createSeats($number, $cinema, $rows, $cols, $seats_map);
 | 
			
		||||
						return "Se ha editado la sala con exito";
 | 
			
		||||
					}else{
 | 
			
		||||
						if(!$bd->searchHall($number, $cinema)){
 | 
			
		||||
							Seat::deleteAllSeats($og_number, $cinema);
 | 
			
		||||
							$bd->editHall($number, $cinema, $rows, $cols, $seats, $og_number);
 | 
			
		||||
							Seat::createSeats($number, $cinema, $rows, $cols, $seats_map);
 | 
			
		||||
							return "Se ha editado la sala con exito";
 | 
			
		||||
						}else
 | 
			
		||||
							return "El nuevo numero de sala ya existe en otra sala";
 | 
			
		||||
					}
 | 
			
		||||
				} else {
 | 
			
		||||
					return "La sala a editar no existe";
 | 
			
		||||
				}
 | 
			
		||||
			} else { return "Error al conectarse a la base de datos"; }
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static function delete_hall($number, $cinema, $rows, $cols, $seats, $seats_map, $og_number){
 | 
			
		||||
			$bd = new HallDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if($bd->searchHall($og_number, $cinema)){
 | 
			
		||||
					$bd->deleteHall($og_number, $cinema);
 | 
			
		||||
					Seat::deleteAllSeats($og_number, $cinema);
 | 
			
		||||
					return "La sala se ha eliminado correctamente";
 | 
			
		||||
				} else {
 | 
			
		||||
					return "La sala a borrar no 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; }
 | 
			
		||||
 | 
			
		||||
        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; }
 | 
			
		||||
 | 
			
		||||
		public function setTotalSeats($totalSeat){ $this->_total_seats = $totalSeat; }
 | 
			
		||||
		public function getTotalSeats(){ return $this->_total_seats; }
 | 
			
		||||
 | 
			
		||||
		public function setSeatsmap($seats_map){ $this->_seats_map = $seats_map; }
 | 
			
		||||
		public function getSeatsmap(){ return $this->_seats_map; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										96
									
								
								root/assets/php/common/hall_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								root/assets/php/common/hall_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,96 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('hall.php');
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
    class HallDAO extends DAO {
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
        //Create a new Hall.
 | 
			
		||||
		public function createHall($number, $cinema, $rows, $cols, $seats, $seats_map){
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `hall`( `number`, `idcinema`, `numrows`, `numcolumns`, `total_seats`) 
 | 
			
		||||
								VALUES ( '%d', '%d', '%d', '%d', '%d')", 
 | 
			
		||||
								$number, $cinema, $rows, $cols, $seats );
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->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 
 | 
			
		||||
							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"], $fila["total_seats"], null);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $hall;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public function searchHall($number, $cinema){
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM hall WHERE 
 | 
			
		||||
							number = '%s' AND idcinema = '%s'", 
 | 
			
		||||
							$number, $cinema);	
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			$hall = false;
 | 
			
		||||
			
 | 
			
		||||
			if($resul){
 | 
			
		||||
				if($resul->num_rows == 1){
 | 
			
		||||
					$fila = $resul->fetch_assoc();
 | 
			
		||||
					$hall = $this->loadHall($fila["number"], $fila["idcinema"], $fila["numrows"], $fila["numcolumns"], $fila["total_seats"], null);
 | 
			
		||||
				}
 | 
			
		||||
				$resul->free();
 | 
			
		||||
			}
 | 
			
		||||
		
 | 
			
		||||
			return $hall;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		//Create a new Hall Data Transfer Object.
 | 
			
		||||
		public function loadHall($number, $idcinema, $numrows, $numcolumns, $total_seats, $seats_map){
 | 
			
		||||
			return new Hall($number, $idcinema, $numrows, $numcolumns, $total_seats, $seats_map);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Edit Hall.
 | 
			
		||||
		public function editHall($number, $cinema, $rows, $cols, $seats, $og_number){
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "UPDATE `hall`
 | 
			
		||||
							SET `number` = '%d' ,`numrows` = '%d' , `numcolumns` = '%d' , `total_seats` = %d
 | 
			
		||||
							WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';", 
 | 
			
		||||
							$number, $rows, $cols, $seats, $og_number, $cinema );
 | 
			
		||||
			
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Delete Hall.
 | 
			
		||||
		public function deleteHall($number, $cinema){
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "DELETE FROM `hall` WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';",$number, $cinema);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										35
									
								
								root/assets/php/common/manager.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								root/assets/php/common/manager.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
<?php
 | 
			
		||||
    
 | 
			
		||||
    class Manager{
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_id;               //Manager ID.
 | 
			
		||||
        private $_username;           //Manager username.
 | 
			
		||||
        private $_email;         //Email.
 | 
			
		||||
        private $_roll;       //Roll
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($id, $idcinema, $username, $email, $roll){
 | 
			
		||||
            $this->_id = $id;
 | 
			
		||||
            $this->_idcinema = $idcinema;
 | 
			
		||||
            $this->_username = $username;
 | 
			
		||||
            $this->_email = $email;
 | 
			
		||||
            $this->_roll = $roll;
 | 
			
		||||
        }
 | 
			
		||||
	
 | 
			
		||||
		//Methods:
 | 
			
		||||
	    
 | 
			
		||||
		//Getters && Setters:
 | 
			
		||||
        public function setId($id){	$this->_id = $id; }
 | 
			
		||||
		public function getId(){ return $this->_id; }
 | 
			
		||||
        public function setIdcinema($idcinema){	$this->_idcinema = $idcinema; }
 | 
			
		||||
		public function getIdcinema(){ return $this->_idcinema; }
 | 
			
		||||
        public function setUsername($username){$this->_username = $username; }
 | 
			
		||||
		public function getUsername(){ return 	$this->_username;}
 | 
			
		||||
        public function setEmail($email){$this->_email = $email;}
 | 
			
		||||
		public function getEmail(){return $this->_email;}
 | 
			
		||||
        public function setRoll($roll){$this->_roll = $roll;}
 | 
			
		||||
		public function getRoll(){return  $this->_roll;}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										77
									
								
								root/assets/php/common/manager_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								root/assets/php/common/manager_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,77 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('manager.php');
 | 
			
		||||
 | 
			
		||||
    class Manager_DAO extends DAO {
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
		
 | 
			
		||||
	    //Returns a query to get All the managers.
 | 
			
		||||
		public function allManagersData(){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM `users` JOIN `manager` ON manager.id = users.id");
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$managers[] = $this->loadManager($fila["id"], $fila["idcinema"], $fila["username"], $fila["email"], $fila["rol"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
			return $managers;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a  manager data .
 | 
			
		||||
		public function GetManager($id){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM `manager` WHERE manager.id = '%d'", $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a  manager data .
 | 
			
		||||
		public function GetManagerCinema($id, $idcinema){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM `manager` WHERE manager.id = '%d' AND manager.idcinema ='%d'", $id, $idcinema );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		 //Create a new Session.
 | 
			
		||||
		 public function createManager($id, $idcinema){
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `manager`( `id`, `idcinema`)
 | 
			
		||||
								VALUES ( '%d', '%d')", 
 | 
			
		||||
									$id, $idcinema);
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
		//Deleted manager by "id".
 | 
			
		||||
		public function deleteManager($id){
 | 
			
		||||
			$sql = sprintf( "DELETE FROM `manager` WHERE manager.id = '%d' ;",$id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Edit manager.
 | 
			
		||||
		public function editManager($id, $idcinema){
 | 
			
		||||
			$sql = sprintf( "UPDATE `manager` SET manager.idcinema = '%d'
 | 
			
		||||
								WHERE manager.id = '%d';", 
 | 
			
		||||
									 $idcinema, $id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
	    
 | 
			
		||||
		//Create a new Manager Data Transfer Object.
 | 
			
		||||
		public function loadManager($id, $idcinema, $username, $email, $rol){
 | 
			
		||||
			return new Manager($id, $idcinema, $username, $email, $rol);
 | 
			
		||||
		}
 | 
			
		||||
	    	
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										36
									
								
								root/assets/php/common/promotion.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								root/assets/php/common/promotion.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
<?php
 | 
			
		||||
    
 | 
			
		||||
    class Promotion{
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_id;               //Cinema ID.
 | 
			
		||||
        private $_tittle;           //Cinema name.
 | 
			
		||||
        private $_description;         //Cinema direction.
 | 
			
		||||
        private $_code;         //Cinema phone.
 | 
			
		||||
        private $_active;
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($id, $tittle, $description, $code, $active){
 | 
			
		||||
            $this->_id = $id;
 | 
			
		||||
            $this->_tittle = $tittle;
 | 
			
		||||
            $this->_description = $description;
 | 
			
		||||
            $this->_code = $code;
 | 
			
		||||
            $this->_active = $active;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//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 setDescription($description){  $this->_description = $description;}
 | 
			
		||||
		public function getDescription(){return  $this->_description;}
 | 
			
		||||
        public function setCode($code){  $this->_code = $code;}
 | 
			
		||||
		public function getCode(){return  $this->_code;}
 | 
			
		||||
        public function setActive($active){  $this->_active = $active;}
 | 
			
		||||
		public function getActive(){return  $this->_active;}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										77
									
								
								root/assets/php/common/promotion_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								root/assets/php/common/promotion_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,77 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('promotion.php');
 | 
			
		||||
 | 
			
		||||
    class Promotion_DAO extends DAO {
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
        //Create a new Session.
 | 
			
		||||
		public function createPromotion($id, $tittle, $description, $code, $active){
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `promotion`( `id`, `tittle`, `description`, `code`, `active`) 
 | 
			
		||||
								VALUES ( '%d', '%s', '%s', '%s', '%s')", 
 | 
			
		||||
									$id, $tittle, $description, $code, $active);
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
	    //Returns a query to get All the films.
 | 
			
		||||
		public function allPromotionData(){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM promotion ");
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$promotions[] = $this->loadPromotion($fila["id"], $fila["tittle"], $fila["description"], $fila["code"], $fila["active"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
			return $promotions;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a  film data .
 | 
			
		||||
		public function GetPromotion($code){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM promotion WHERE promotion.code = '%s'", $code );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a  film data .
 | 
			
		||||
		public function promotionData($id){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM promotion WHERE promotion.id = '%d'", $id);
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Deleted film by "id".
 | 
			
		||||
		public function deletePromotion($id){
 | 
			
		||||
			$sql = sprintf( "DELETE FROM promotion WHERE promotion.id = '%d' ;",$id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Edit a film.
 | 
			
		||||
		public function editPromotion($id, $tittle, $description, $code, $active){
 | 
			
		||||
			$sql = sprintf( "UPDATE promotion SET tittle = '%s' , description = '%s', code ='%s' , active ='%s'
 | 
			
		||||
								WHERE promotion.id = '%d';", 
 | 
			
		||||
									 $tittle, $description, $code, $active, $id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
	    
 | 
			
		||||
		//Create a new film Data Transfer Object.
 | 
			
		||||
		public function loadPromotion($id, $tittle, $description, $code, $active){
 | 
			
		||||
			return new Promotion($id, $tittle, $description, $code, $active);
 | 
			
		||||
		}
 | 
			
		||||
	    	
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										11
									
								
								root/assets/php/common/reRol.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								root/assets/php/common/reRol.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
<?php
 | 
			
		||||
include('../config.php');
 | 
			
		||||
function reRol(){
 | 
			
		||||
    if(isset($_SESSION["lastRol"])){
 | 
			
		||||
        $_SESSION["rol"] = $_SESSION["lastRol"];
 | 
			
		||||
        unset($_SESSION["lastRol"]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
reRol();
 | 
			
		||||
header("Location: /");
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										13
									
								
								root/assets/php/common/resetRol.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								root/assets/php/common/resetRol.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
<?php
 | 
			
		||||
include('../config.php');
 | 
			
		||||
function reRol(){
 | 
			
		||||
    if(isset($_SESSION["lastRol"])){
 | 
			
		||||
        $_SESSION["rol"] = $_SESSION["lastRol"];
 | 
			
		||||
        unset($_SESSION["lastRol"]);
 | 
			
		||||
        unset($_SESSION["cinema"]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
reRol();
 | 
			
		||||
$redirect = ROUTE_APP.'panel_'.$_SESSION['rol'];
 | 
			
		||||
header("Location: {$redirect}");
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										63
									
								
								root/assets/php/common/seat.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								root/assets/php/common/seat.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,63 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once($prefix.'assets/php/common/seat_dao.php');
 | 
			
		||||
 | 
			
		||||
    class Seat{
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_idhall;     
 | 
			
		||||
        private $_idcinema;    
 | 
			
		||||
		private $_numRow;     
 | 
			
		||||
        private $_numCol;      
 | 
			
		||||
		private $_state;      
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($idhall, $idcinema, $numRow, $numCol, $state){
 | 
			
		||||
            $this->_number = $idhall;
 | 
			
		||||
            $this->_idcinema = $idcinema;
 | 
			
		||||
            $this->_numRow = $numRow;
 | 
			
		||||
			$this->_numCol = $numCol;
 | 
			
		||||
			$this->_state = $state;
 | 
			
		||||
        }
 | 
			
		||||
		
 | 
			
		||||
		static public function createSeats($hall, $cinema, $rows, $cols, $seats_map){
 | 
			
		||||
			$bd = new SeatDAO('complucine');
 | 
			
		||||
 | 
			
		||||
			for($i = 1;$i <= $rows;$i++){
 | 
			
		||||
				for($j = 1; $j <= $cols;$j++){
 | 
			
		||||
					$bd->createSeat($hall, $cinema, $i, $j, $seats_map[$i][$j]);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		static public function getSeatsMap($number, $cinema){
 | 
			
		||||
			$bd = new SeatDAO('complucine');
 | 
			
		||||
			if($bd )
 | 
			
		||||
				return $bd->getAllSeats($number, $cinema);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		static public function deleteAllSeats($number, $cinema){
 | 
			
		||||
			$bd = new SeatDAO('complucine');
 | 
			
		||||
			if($bd)
 | 
			
		||||
				return $bd->deletemapSeats($number, $cinema);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//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($numRow){ $this->_numRow = $numRow; }
 | 
			
		||||
		public function getNumRows(){ return $this->_numRow; }
 | 
			
		||||
		
 | 
			
		||||
		public function setNumCol($numCol){ $this->_numCol = $numCol; }
 | 
			
		||||
		public function getNumCol(){ return $this->_numCol; }
 | 
			
		||||
		
 | 
			
		||||
		public function setState($state){ $this->_state = $state; }
 | 
			
		||||
		public function getState(){ return $this->_state; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										58
									
								
								root/assets/php/common/seat_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								root/assets/php/common/seat_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('seat.php');
 | 
			
		||||
	
 | 
			
		||||
    class SeatDAO extends DAO {
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
        //Create a new Hall.
 | 
			
		||||
		public function createSeat($hall, $cinema, $row, $col, $state){
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `seat`( `idhall`, `idcinema`, `numrow`, `numcolum`, `active`) 
 | 
			
		||||
								VALUES ( '%d', '%d', '%d', '%d', '%d')", 
 | 
			
		||||
								$hall, $cinema, $row, $col, $state);
 | 
			
		||||
	
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error BD createSeat');
 | 
			
		||||
			
 | 
			
		||||
			return $sql;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public function getAllSeats($number, $cinema){
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM seat WHERE 
 | 
			
		||||
							idhall = '%s' AND idcinema = '%s'", 
 | 
			
		||||
							$number, $cinema);	
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			
 | 
			
		||||
			$seat_map = null;
 | 
			
		||||
			while($fila=mysqli_fetch_array($resul)){
 | 
			
		||||
				$seat_map[] = $this->loadSeat($fila["idhall"], $fila["idcinema"], $fila["numrow"], $fila["numcolum"], $fila["active"]);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $seat_map;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public function deletemapSeats($hall, $cinema){
 | 
			
		||||
            $sql = sprintf( "DELETE FROM `seat` WHERE 
 | 
			
		||||
							idcinema = '%s' AND idhall = '%s'", 
 | 
			
		||||
							$cinema, $hall);	
 | 
			
		||||
 | 
			
		||||
            $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
            return $resul;
 | 
			
		||||
        }
 | 
			
		||||
			
 | 
			
		||||
		public function loadSeat($idhall, $idcinema, $numRow, $numCol, $state){
 | 
			
		||||
			return new Seat($idhall, $idcinema, $numRow, $numCol, $state);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										118
									
								
								root/assets/php/common/session.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								root/assets/php/common/session.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,118 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once($prefix.'assets/php/common/session_dao.php');
 | 
			
		||||
 | 
			
		||||
    class Session{
 | 
			
		||||
 | 
			
		||||
        private $_id;          
 | 
			
		||||
        private $_idfilm;
 | 
			
		||||
        private $_idhall;
 | 
			
		||||
		private $_idcinema;			
 | 
			
		||||
        private $_date;
 | 
			
		||||
        private $_startTime;
 | 
			
		||||
        private $_seatPrice;
 | 
			
		||||
        private $_format;
 | 
			
		||||
		private $_seats_full;
 | 
			
		||||
		
 | 
			
		||||
        function __construct($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $seats_full){
 | 
			
		||||
            $this->_id = $id;
 | 
			
		||||
            $this->_idfilm = $idfilm;
 | 
			
		||||
            $this->_idhall = $idhall;
 | 
			
		||||
			$this->_idcinema = $idcinema;
 | 
			
		||||
            $this->_date = $date;
 | 
			
		||||
            $this->_startTime = $startTime;
 | 
			
		||||
            $this->_seatPrice = $seatPrice;
 | 
			
		||||
            $this->_format = $format;
 | 
			
		||||
			$this->_seats_full = $seats_full;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		public static function getListSessions($hall,$cinema,$date){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ) {
 | 
			
		||||
				return $bd->getAllSessions($hall, $cinema, $date);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public static function create_session($cinema, $hall, $start, $date, $film, $price, $format,$repeat){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if(!$bd->searchSession($cinema, $hall, $start, $date)){
 | 
			
		||||
					$bd->createSession(null,$film, $hall, $cinema, $date, $start, $price, $format);
 | 
			
		||||
 | 
			
		||||
					if($repeat > "0") {
 | 
			
		||||
						$repeats = $repeat;
 | 
			
		||||
						$repeat = $repeat - 1;
 | 
			
		||||
						$date = date('Y-m-d', strtotime( $date . ' +1 day') );
 | 
			
		||||
						self::create_session($cinema, $hall, $start, $date, $film, $price, $format,$repeat);
 | 
			
		||||
						return "Se han creado las ".$repeat ." sesiones con exito";
 | 
			
		||||
					}
 | 
			
		||||
						
 | 
			
		||||
					else
 | 
			
		||||
						return "Se ha creado la session con exito";
 | 
			
		||||
				} else 
 | 
			
		||||
					return "Esta session ya existe";
 | 
			
		||||
				
 | 
			
		||||
			} else return "Error al conectarse a la base de datos";
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public static function edit_session($cinema, $or_hall, $or_date, $or_start, $hall, $start, $date, $film, $price, $format){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if($bd->searchSession($cinema, $or_hall, $or_start, $or_date)){
 | 
			
		||||
					if(!$bd->searchSession($cinema,$hall,$start,$date)){
 | 
			
		||||
						$origin = array("cinema" => $cinema,"hall" => $or_hall,"start" => $or_start,"date" => $or_date);
 | 
			
		||||
						$bd->editSession($film, $hall, $cinema, $date, $start, $price, $format,$origin);
 | 
			
		||||
						return "Se ha editado la session con exito";			
 | 
			
		||||
					}else	
 | 
			
		||||
						return "Ya existe una sesion con los parametros nuevos";	
 | 
			
		||||
				} else 
 | 
			
		||||
					return "Esta session no existe";
 | 
			
		||||
				
 | 
			
		||||
			} else return "Error al conectarse a la base de datos";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static function delete_session($cinema, $hall, $start, $date){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if($bd->searchSession($cinema, $hall, $start, $date)){
 | 
			
		||||
					$bd->deleteSession($hall, $cinema, $date, $start);
 | 
			
		||||
					return "Se ha eliminado la session con exito";						
 | 
			
		||||
				} else 
 | 
			
		||||
					return "Esta session no existe";
 | 
			
		||||
				
 | 
			
		||||
			} else return "Error al conectarse a la base de datos";
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Esto deberia estar en film.php? seguramente
 | 
			
		||||
		public static function getThisSessionFilm($idfilm){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ) {
 | 
			
		||||
				return $bd->filmTittle($idfilm);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
        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; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										114
									
								
								root/assets/php/common/session_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								root/assets/php/common/session_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,114 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('session.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`, `seats_full`) 
 | 
			
		||||
				VALUES ('%d', '%d', '%d', '%d', '%s', '%s', '%d', '%s', '%d')",
 | 
			
		||||
					$id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, "0");
 | 
			
		||||
			
 | 
			
		||||
			$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);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_fetch_array($resul);
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}	
 | 
			
		||||
		
 | 
			
		||||
		public function filmTittle($idfilm){
 | 
			
		||||
			$sql = sprintf("SELECT * FROM film JOIN  session ON film.id = session.idfilm WHERE session.idfilm = '%d' ", $idfilm );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database en sessionData con la id '. $idfilm);
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_fetch_array($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}	
 | 
			
		||||
		
 | 
			
		||||
		//Returns a session
 | 
			
		||||
		public function searchSession($cinema, $hall, $startTime, $date){
 | 
			
		||||
			$date = date('Y-m-d', strtotime( $date ) ); 
 | 
			
		||||
			$startTime = date('H:i:s', strtotime( $startTime ) );
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "SELECT * 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 = mysqli_fetch_array($resul);
 | 
			
		||||
			
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $session;
 | 
			
		||||
		}
 | 
			
		||||
		//Returns a query to get all the session's data.
 | 
			
		||||
		public function getAllSessions($hall, $cinema, $date){
 | 
			
		||||
			$date = date('Y-m-d', strtotime( $date ) ); 
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM session WHERE 
 | 
			
		||||
							idcinema = '%s' AND idhall = '%s' AND date = '%s' ORDER BY start_time ASC;", 
 | 
			
		||||
							$cinema, $hall, $date);	
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			
 | 
			
		||||
			$sessions = null;
 | 
			
		||||
			
 | 
			
		||||
			while($fila=mysqli_fetch_array($resul)){
 | 
			
		||||
				$sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]);
 | 
			
		||||
			}
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $sessions;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
        public function editSession($idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $origin){
 | 
			
		||||
			$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, $origin["cinema"],$origin["hall"],$origin["date"],$origin["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, $seats_full){
 | 
			
		||||
			return new Session( $id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $seats_full);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										36
									
								
								root/assets/php/common/user.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								root/assets/php/common/user.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
<?php
 | 
			
		||||
    
 | 
			
		||||
    class User {
 | 
			
		||||
 | 
			
		||||
        //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; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										165
									
								
								root/assets/php/common/user_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										165
									
								
								root/assets/php/common/user_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,165 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('user.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);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		//All users
 | 
			
		||||
		public function allUsersNotM(){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM `users` WHERE users.id NOT IN (SELECT id FROM `manager`)");
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$users[] = $this->loadUser($fila['id'], $fila['username'], $fila['email'], $fila['passwd'], $fila['rol']);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
			return $users;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
        //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);
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a query to check if the user name exists.
 | 
			
		||||
		public function selectUser($username, $password){
 | 
			
		||||
			$username = $this->mysqli->real_escape_string($username);
 | 
			
		||||
			$password = $this->mysqli->real_escape_string($password);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql);
 | 
			
		||||
 | 
			
		||||
			$resul->data_seek(0);
 | 
			
		||||
			$user = null;
 | 
			
		||||
			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 get the user's data.
 | 
			
		||||
		public function userData($id){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM users WHERE id = '%d'", $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Search a user by name.
 | 
			
		||||
		public function selectUserName($username){
 | 
			
		||||
			$username = $this->mysqli->real_escape_string($username);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql);
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Search a user by email.
 | 
			
		||||
		public function selectUserEmail($email){
 | 
			
		||||
			$email = $this->mysqli->real_escape_string($email);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM users WHERE email = '%s'", $email );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql);
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Change username by id.
 | 
			
		||||
		public function changeUserName($id, $username){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
			$username = $this->mysqli->real_escape_string($username);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "UPDATE users SET username = '%s' WHERE id = '%d'", $username, $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Change userpass by id.
 | 
			
		||||
		public function changeUserPass($id, $password){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
			$password = $this->mysqli->real_escape_string($password);
 | 
			
		||||
			$password = $this->encryptPass($password);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "UPDATE users SET passwd = '%s' WHERE id = '%d'", $password, $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Change user email by id.
 | 
			
		||||
		public function changeUserEmail($id, $email){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
			$email = $this->mysqli->real_escape_string($email);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "UPDATE users SET email = '%s' WHERE id = '%d'", $email, $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Delete user account by id.
 | 
			
		||||
		public function deleteUserAccount($id){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "DELETE 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 User($id, $username, $email, $password, $rol);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										61
									
								
								root/assets/php/config-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								root/assets/php/config-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
			
		||||
<?php
 | 
			
		||||
    /**
 | 
			
		||||
    * Connection parameters to the DB.
 | 
			
		||||
    */
 | 
			
		||||
    define('BD_HOST', 'localhost');
 | 
			
		||||
    define('BD_NAME', 'complucine');
 | 
			
		||||
    define('BD_USER', 'sw');
 | 
			
		||||
    define('BD_PASS', '_admin_');
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
    * Configuration parameters used to generate URLs and file paths in the application
 | 
			
		||||
    */
 | 
			
		||||
    define('ROUTE_APP', '/'); //Change if it´s necessary.
 | 
			
		||||
    define('RAIZ_APP', __DIR__);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
    * Image files directory.
 | 
			
		||||
    */
 | 
			
		||||
    define('FILMS_DIR', RAIZ_APP.'/img/films/');
 | 
			
		||||
    define('FILMS_DIR_PROTECTED', dirname(RAIZ_APP).'/img/films/tmp/');
 | 
			
		||||
    define('USER_PICS',  ROUTE_APP.'img/users/');
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Allowed extensions for image files.
 | 
			
		||||
     */
 | 
			
		||||
    $ALLOWED_EXTENSIONS = array('gif','jpg','jpe','jpeg','png');
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
    * Utf-8 support settings, location (language and country) and time zone.
 | 
			
		||||
    */
 | 
			
		||||
    ini_set('default_charset', 'UTF-8');
 | 
			
		||||
    setLocale(LC_ALL, 'es_ES.UTF.8');
 | 
			
		||||
    date_default_timezone_set('Europe/Madrid');
 | 
			
		||||
 | 
			
		||||
    //Start session:
 | 
			
		||||
    session_start();
 | 
			
		||||
 | 
			
		||||
    //HTML template:
 | 
			
		||||
    require_once('template.php');
 | 
			
		||||
    $template = new Template();
 | 
			
		||||
    $prefix = $template->get_prefix();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Initialize the application:
 | 
			
		||||
     */
 | 
			
		||||
    include_once($prefix.'assets/php/dao.php');
 | 
			
		||||
    require_once('aplication.php');
 | 
			
		||||
    $app = Aplicacion::getSingleton();
 | 
			
		||||
    $app->init(array('host'=>BD_HOST, 'bd'=>BD_NAME, 'user'=>BD_USER, 'pass'=>BD_PASS));
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @see http://php.net/manual/en/function.register-shutdown-function.php
 | 
			
		||||
     * @see http://php.net/manual/en/language.types.callable.php
 | 
			
		||||
     */
 | 
			
		||||
    register_shutdown_function(array($app, 'shutdown'));
 | 
			
		||||
 | 
			
		||||
    //Depuración (BORRAR):
 | 
			
		||||
    ini_set('display_errors', 1);
 | 
			
		||||
    ini_set('display_startup_errors', 1);
 | 
			
		||||
    error_reporting(E_ALL);
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										56
									
								
								root/assets/php/config.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								root/assets/php/config.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,56 @@
 | 
			
		||||
<?php
 | 
			
		||||
    /**
 | 
			
		||||
    * Connection parameters to the DB.
 | 
			
		||||
    */
 | 
			
		||||
    define('BD_HOST', 'localhost');
 | 
			
		||||
    define('BD_NAME', 'complucine');
 | 
			
		||||
    define('BD_USER', 'sw');
 | 
			
		||||
    define('BD_PASS', '_admin_');
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
    * Configuration parameters used to generate URLs and file paths in the application
 | 
			
		||||
    */
 | 
			
		||||
    define('ROUTE_APP', '/'); //Change if it´s necessary.
 | 
			
		||||
    define('RAIZ_APP', __DIR__);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
    * Image files directory.
 | 
			
		||||
    */
 | 
			
		||||
    define('FILMS_DIR', RAIZ_APP.'/img/films/');
 | 
			
		||||
    define('FILMS_DIR_PROTECTED', dirname(RAIZ_APP).'/img/films/tmp/');
 | 
			
		||||
    define('USER_PICS',  ROUTE_APP.'img/users/');
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Allowed extensions for image files.
 | 
			
		||||
     */
 | 
			
		||||
    $ALLOWED_EXTENSIONS = array('gif','jpg','jpe','jpeg','png');
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
    * Utf-8 support settings, location (language and country) and time zone.
 | 
			
		||||
    */
 | 
			
		||||
    ini_set('default_charset', 'UTF-8');
 | 
			
		||||
    setLocale(LC_ALL, 'es_ES.UTF.8');
 | 
			
		||||
    date_default_timezone_set('Europe/Madrid');
 | 
			
		||||
 | 
			
		||||
    //Start session:
 | 
			
		||||
    session_start();
 | 
			
		||||
 | 
			
		||||
    //HTML template:
 | 
			
		||||
    require_once('template.php');
 | 
			
		||||
    $template = new Template();
 | 
			
		||||
    $prefix = $template->get_prefix();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Initialize the application:
 | 
			
		||||
     */
 | 
			
		||||
    include_once($prefix.'assets/php/dao.php');
 | 
			
		||||
    require_once('aplication.php');
 | 
			
		||||
    $app = Aplicacion::getSingleton();
 | 
			
		||||
    $app->init(array('host'=>BD_HOST, 'bd'=>BD_NAME, 'user'=>BD_USER, 'pass'=>BD_PASS));
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @see http://php.net/manual/en/function.register-shutdown-function.php
 | 
			
		||||
     * @see http://php.net/manual/en/language.types.callable.php
 | 
			
		||||
     */
 | 
			
		||||
    register_shutdown_function(array($app, 'shutdown'));
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										23
									
								
								root/assets/php/dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								root/assets/php/dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
<?php
 | 
			
		||||
    class DAO {
 | 
			
		||||
        //Atributes:
 | 
			
		||||
        public $mysqli;
 | 
			
		||||
 | 
			
		||||
        //Constructor:
 | 
			
		||||
        public function __construct($bd_name){
 | 
			
		||||
            if($bd_name != BD_NAME) {
 | 
			
		||||
                echo "Está intentando acceder a una base de datos que no existe, puede que la aplicación no funcione correctamente.";
 | 
			
		||||
            }
 | 
			
		||||
            $app = Aplicacion::getSingleton();
 | 
			
		||||
            $this->mysqli = $app->conexionBd();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //Destructor (Ya no es necesdario):
 | 
			
		||||
        /*
 | 
			
		||||
        public function __destruct(){
 | 
			
		||||
            $this->mysqli->close();
 | 
			
		||||
        }
 | 
			
		||||
        */
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										387
									
								
								root/assets/php/form.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										387
									
								
								root/assets/php/form.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,387 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Clase base para la gestión de formularios.
 | 
			
		||||
 *
 | 
			
		||||
 * Gestión de token CSRF está basada en: https://www.owasp.org/index.php/PHP_CSRF_Guard
 | 
			
		||||
 */
 | 
			
		||||
abstract class Form {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string Sufijo para el nombre del parámetro de la sesión del usuario donde se almacena el token CSRF.
 | 
			
		||||
     */
 | 
			
		||||
    const CSRF_PARAM = 'csrf';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string Identificador utilizado para construir el atributo "id" de la etiqueta <form> como <code>$tipoFormulario.$formId</code>.
 | 
			
		||||
     */
 | 
			
		||||
    private $formId;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string Valor del parámetro enctype del formulario.
 | 
			
		||||
     */
 | 
			
		||||
    private $enctype;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string Valor del atributo "class" de la etiqueta <form> asociada al formulario. Si este parámetro incluye la cadena "nocsrf" no se generá el token CSRF para este formulario.
 | 
			
		||||
     */
 | 
			
		||||
    private $classAtt;
 | 
			
		||||
 | 
			
		||||
     /**
 | 
			
		||||
     * @var string Parámetro de la petición utilizado para comprobar que el usuario ha enviado el formulario..
 | 
			
		||||
     */
 | 
			
		||||
    private $tipoFormulario;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string URL asociada al atributo "action" de la etiqueta <form> del fomrulario y que procesará el 
 | 
			
		||||
     * envío del formulario.
 | 
			
		||||
     */
 | 
			
		||||
    private $action;
 | 
			
		||||
    private $printed;
 | 
			
		||||
 | 
			
		||||
     /**
 | 
			
		||||
     * @var bool Almacena si la interacción con el formulario va a realizarse a través de AJAX <code>true</code> o
 | 
			
		||||
     * <code>false</code> en otro caso.
 | 
			
		||||
     */
 | 
			
		||||
    private $ajax;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Crea un nuevo formulario.
 | 
			
		||||
     *
 | 
			
		||||
     * Posibles opciones:
 | 
			
		||||
     * <table>
 | 
			
		||||
     *   <thead>
 | 
			
		||||
     *     <tr>
 | 
			
		||||
     *       <th>Opción</th>
 | 
			
		||||
     *       <th>Valor por defecto</th>
 | 
			
		||||
     *       <th>Descripción</th>
 | 
			
		||||
     *     </tr>
 | 
			
		||||
     *   </thead>
 | 
			
		||||
     *   <tbody>
 | 
			
		||||
     *     <tr>
 | 
			
		||||
     *       <td>action</td>
 | 
			
		||||
     *       <td><code>$_SERVER['PHP_SELF']</code></td>       
 | 
			
		||||
     *       <td>URL asociada al atributo "action" de la etiqueta <form> del fomrulario y que procesará el envío del formulario.</td>
 | 
			
		||||
     *     </tr>
 | 
			
		||||
     *     <tr>
 | 
			
		||||
     *        <td>class</td>
 | 
			
		||||
     *        <td>""</td>       
 | 
			
		||||
     *        <td>Valor del atributo "class" de la etiqueta <form> asociada al formulario. Si este parámetro incluye la cadena
 | 
			
		||||
     *        "nocsrf" no se generá el token CSRF para este formulario.</td>
 | 
			
		||||
     *     </tr>
 | 
			
		||||
     *      <tr>
 | 
			
		||||
     *       <td>enctype</td>
 | 
			
		||||
     *       <td>""</td>       
 | 
			
		||||
     *       <td>Valor del parámetro enctype del formulario.</td>
 | 
			
		||||
     *     </tr>
 | 
			
		||||
     *     <tr>
 | 
			
		||||
     *       <td>ajax</td>
 | 
			
		||||
     *       <td><code>false</code></td>       
 | 
			
		||||
     *       <td>Configura si el formulario se gestionará a través de AJAX.</td>
 | 
			
		||||
     *     </tr>
 | 
			
		||||
     *   </tbody>
 | 
			
		||||
     * </table>
 | 
			
		||||
     * @param string $tipoFormulario Parámetro de la petición utilizado para comprobar que el usuario ha enviado el formulario.
 | 
			
		||||
     * @param string $formId (opcional) Identificador utilizado para construir el atributo "id" de la etiqueta <form> como <code>$tipoFormulario.$formId</code>. 
 | 
			
		||||
     *
 | 
			
		||||
     * @param array $opciones (ver más arriba).
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct($tipoFormulario, $opciones = array(), $formId = 1)
 | 
			
		||||
    {
 | 
			
		||||
        $this->tipoFormulario = $tipoFormulario;
 | 
			
		||||
        $this->formId = $tipoFormulario.$formId;
 | 
			
		||||
 | 
			
		||||
        $opcionesPorDefecto = array( 'ajax' => false, 'action' => null, 'class' => null, 'enctype' => null );
 | 
			
		||||
        $opciones = array_merge($opcionesPorDefecto, $opciones);
 | 
			
		||||
 | 
			
		||||
        $this->ajax     = $opciones['ajax'];
 | 
			
		||||
        $this->action   = $opciones['action'];
 | 
			
		||||
        $this->classAtt = $opciones['class'];
 | 
			
		||||
        $this->enctype  = $opciones['enctype'];
 | 
			
		||||
        
 | 
			
		||||
        if ( !$this->action ) {
 | 
			
		||||
            // Cambiar por << $this->action = htmlentities($_SERVER['REQUEST_URI']); >> para mantener los parámetros de la URL.
 | 
			
		||||
            $this->action = htmlentities($_SERVER['PHP_SELF']);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
  
 | 
			
		||||
    /**
 | 
			
		||||
     * Se encarga de orquestar todo el proceso de gestión de un formulario.
 | 
			
		||||
     * 
 | 
			
		||||
     * El proceso es el siguiente:
 | 
			
		||||
     * <ul>
 | 
			
		||||
     *   <li>O bien se quiere mostrar el formulario (petición GET)</li>
 | 
			
		||||
     *   <li>O bien hay que procesar el formulario (petición POST) y hay dos situaciones:
 | 
			
		||||
     *     <ul>
 | 
			
		||||
     *       <li>El formulario se ha procesado correctamente y se devuelve un <code>string</code> en {@see Form::procesaFormulario()}
 | 
			
		||||
     *           que será la URL a la que se rederigirá al usuario. Se redirige al usuario y se termina la ejecución del script.</li>
 | 
			
		||||
     *       <li>El formulario NO se ha procesado correctamente (errores en los datos, datos incorrectos, etc.) y se devuelve
 | 
			
		||||
     *           un <code>array</code> con entradas (campo, mensaje) con errores específicos para un campo o (entero, mensaje) si el mensaje
 | 
			
		||||
     *           es un mensaje que afecta globalmente al formulario. Se vuelve a generar el formulario pasándole el array de errores.</li> 
 | 
			
		||||
     *     </ul>
 | 
			
		||||
     *   </li>
 | 
			
		||||
     * </ul>
 | 
			
		||||
     */
 | 
			
		||||
    public function gestiona()
 | 
			
		||||
    {
 | 
			
		||||
        if ( ! $this->formularioEnviado($_POST) ) {
 | 
			
		||||
            return $this->generaFormulario();
 | 
			
		||||
        } else {
 | 
			
		||||
            // Valida el token CSRF si es necesario (hay un token en la sesión asociada al formulario)
 | 
			
		||||
            $tokenRecibido = $_POST['CSRFToken'] ?? FALSE;
 | 
			
		||||
            $errores = $this->csrfguard_ValidateToken($this->tipoFormulario, $tokenRecibido);
 | 
			
		||||
 | 
			
		||||
            // limpia los tokens CSRF que no han sido utilizados en esta petición
 | 
			
		||||
            self::limpiaCsrfTokens();
 | 
			
		||||
 | 
			
		||||
            // Sin AJAX.
 | 
			
		||||
            /**
 | 
			
		||||
             * $result = $this->procesaFormulario($_POST);
 | 
			
		||||
             * if ( is_array($result) ) {
 | 
			
		||||
             *      return $this->generaFormulario($_POST, $result);
 | 
			
		||||
             * } else {
 | 
			
		||||
             *      header('Location: '.$result);
 | 
			
		||||
             *      exit();
 | 
			
		||||
             * }
 | 
			
		||||
             */
 | 
			
		||||
            
 | 
			
		||||
            // Con AJAX.
 | 
			
		||||
            if ( $errores !== TRUE ) { 
 | 
			
		||||
                if ( ! $this->ajax ) {
 | 
			
		||||
                    return $this->generaFormulario($_POST, $errores);
 | 
			
		||||
                } else {
 | 
			
		||||
                    return $this->generaHtmlErrores($errores);
 | 
			
		||||
                }
 | 
			
		||||
            } else  {
 | 
			
		||||
                $result = $this->procesaFormulario($_POST);
 | 
			
		||||
                if ( is_array($result) ) {
 | 
			
		||||
                    // Error al procesar el formulario, volvemos a mostrarlo
 | 
			
		||||
                    if ( ! $this->ajax ) {
 | 
			
		||||
                        return $this->generaFormulario($_POST, $result);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        return $this->generaHtmlErrores($result);
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    if ( ! $this->ajax ) {
 | 
			
		||||
                        header('Location: '.$result);
 | 
			
		||||
                        exit();
 | 
			
		||||
                    } else {
 | 
			
		||||
                        return $result;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Genera el HTML necesario para presentar los campos del formulario.
 | 
			
		||||
     * 
 | 
			
		||||
     * Si el formulario ya ha sido enviado y hay errores en {@see Form::procesaFormulario()} se llama a este método
 | 
			
		||||
     * nuevamente con los datos que ha introducido el usuario en <code>$datosIniciales</code> y los errores al procesar
 | 
			
		||||
     * el formulario en <code>$errores</code>
 | 
			
		||||
     *
 | 
			
		||||
     * @param string[] $datosIniciales Datos iniciales para los campos del formulario (normalmente <code>$_POST</code>).
 | 
			
		||||
     *
 | 
			
		||||
     * @param string[] $errores (opcional)Lista / Tabla asociativa de errores asociados al formulario.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return string HTML asociado a los campos del formulario.
 | 
			
		||||
     */
 | 
			
		||||
    protected function generaCamposFormulario($datosIniciales, $errores = array())
 | 
			
		||||
    {
 | 
			
		||||
        return '';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Procesa los datos del formulario.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string[] $datos Datos enviado por el usuario (normalmente <code>$_POST</code>).
 | 
			
		||||
     *
 | 
			
		||||
     * @return string|string[] Devuelve el resultado del procesamiento del formulario, normalmente una URL a la que
 | 
			
		||||
     * se desea que se redirija al usuario, o un array con los errores que ha habido durante el procesamiento del formulario.
 | 
			
		||||
     */
 | 
			
		||||
    protected function procesaFormulario($datos)
 | 
			
		||||
    {
 | 
			
		||||
        return array();
 | 
			
		||||
    }
 | 
			
		||||
  
 | 
			
		||||
    /**
 | 
			
		||||
     * Función que verifica si el usuario ha enviado el formulario.
 | 
			
		||||
     * 
 | 
			
		||||
     * Comprueba si existe el parámetro <code>$formId</code> en <code>$params</code>.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string[] $params Array que contiene los datos recibidos en el envío formulario.
 | 
			
		||||
     *
 | 
			
		||||
     * @return boolean Devuelve <code>true</code> si <code>$formId</code> existe como clave en <code>$params</code>
 | 
			
		||||
     */
 | 
			
		||||
    private function formularioEnviado(&$params)
 | 
			
		||||
    {
 | 
			
		||||
        return isset($params['action']) && $params['action'] == $this->tipoFormulario;
 | 
			
		||||
    } 
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Función que genera el HTML necesario para el formulario.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string[] $datos (opcional) Array con los valores por defecto de los campos del formulario.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string[] $errores (opcional) Array con los mensajes de error de validación y/o procesamiento del formulario.
 | 
			
		||||
     *
 | 
			
		||||
     * @return string HTML asociado al formulario.
 | 
			
		||||
     */
 | 
			
		||||
    private function generaFormulario(&$datos = array(), &$errores = array())
 | 
			
		||||
    {
 | 
			
		||||
        $htmlCamposFormularios = $this->generaCamposFormulario($datos, $errores);
 | 
			
		||||
 | 
			
		||||
        $classAtt='';
 | 
			
		||||
        if ( $this->classAtt ) {
 | 
			
		||||
          $classAtt = " class=\"{$this->classAtt}\"";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $enctypeAtt='';
 | 
			
		||||
        if ( $this->enctype ) {
 | 
			
		||||
            $enctypeAtt = " enctype=\"{$this->enctype}\"";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Se genera el token CSRF si el usuario no solicita explícitamente lo contrario.
 | 
			
		||||
        $tokenCSRF = '';
 | 
			
		||||
        if ( ! $this->classAtt || strpos($this->classAtt, 'nocsrf') === false ) {
 | 
			
		||||
            $tokenValue = $this->csrfguard_GenerateToken($this->tipoFormulario);
 | 
			
		||||
            $tokenCSRF = "<input type='hidden' name='CSRFToken' value='$tokenValue' />";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* <<< Permite definir cadena en múltiples líneas.
 | 
			
		||||
         * Revisa https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
 | 
			
		||||
         */
 | 
			
		||||
        $htmlForm = "<form method='POST' action='{$this->action}' id='{$this->formId}'{$classAtt}{$enctypeAtt} >
 | 
			
		||||
                        <input type='hidden' name='action' value='{$this->tipoFormulario}' />
 | 
			
		||||
                        ".$tokenCSRF.$htmlCamposFormularios."
 | 
			
		||||
                    </form>";
 | 
			
		||||
        return $htmlForm;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Genera la lista de mensajes de errores globales (no asociada a un campo) a incluir en el formulario.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string[] $errores (opcional) Array con los mensajes de error de validación y/o procesamiento del formulario.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $classAtt (opcional) Valor del atributo class de la lista de errores.
 | 
			
		||||
     *
 | 
			
		||||
     * @return string El HTML asociado a los mensajes de error.
 | 
			
		||||
     */
 | 
			
		||||
    protected static function generaListaErroresGlobales($errores = array(), $classAtt='')
 | 
			
		||||
    {
 | 
			
		||||
        $html='';
 | 
			
		||||
        $clavesErroresGenerales = array_filter(array_keys($errores), function ($elem) {
 | 
			
		||||
            return is_numeric($elem);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $numErrores = count($clavesErroresGenerales);
 | 
			
		||||
        if ($numErrores > 0) {
 | 
			
		||||
            $html = "<ul class=\"$classAtt\">";
 | 
			
		||||
            if (  $numErrores == 1 ) {
 | 
			
		||||
                $html .= "<li>$errores[0]</li>";
 | 
			
		||||
            } else {
 | 
			
		||||
                foreach($clavesErroresGenerales as $clave) {
 | 
			
		||||
                    $html .= "<li>$errores[$clave]</li>";
 | 
			
		||||
                }
 | 
			
		||||
                $html .= "</li>";
 | 
			
		||||
            }
 | 
			
		||||
            $html .= '</ul>';
 | 
			
		||||
        }
 | 
			
		||||
        return $html;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Crea una etiqueta para mostrar un mensaje de error. Sólo creará el mensaje de error
 | 
			
		||||
     * si existe una clave <code>$idError</code> dentro del array <code>$errores</code>.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param string[] $errores     (opcional) Array con los mensajes de error de validación y/o procesamiento del formulario.
 | 
			
		||||
     * @param string   $idError     (opcional) Clave dentro de <code>$errores</code> del error a mostrar.
 | 
			
		||||
     * @param string   $htmlElement (opcional) Etiqueta HTML a crear para mostrar el error.
 | 
			
		||||
     * @param array    $atts        (opcional) Tabla asociativa con los atributos a añadir a la etiqueta que mostrará el error.
 | 
			
		||||
     */
 | 
			
		||||
    protected static function createMensajeError($errores=array(), $idError='', $htmlElement='span', $atts = array())
 | 
			
		||||
    {
 | 
			
		||||
        $html = '';
 | 
			
		||||
        if (isset($errores[$idError])) {
 | 
			
		||||
            $att = '';
 | 
			
		||||
            foreach($atts as $key => $value) {
 | 
			
		||||
                $att .= "$key=$value";
 | 
			
		||||
            }
 | 
			
		||||
            $html = " <$htmlElement $att>{$errores[$idError]}</$htmlElement>";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $html;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Método para eliminar los tokens CSRF almecenados en la petición anterior que no hayan sido utilizados en la actual.
 | 
			
		||||
     */
 | 
			
		||||
    public static function limpiaCsrfTokens()
 | 
			
		||||
    {
 | 
			
		||||
        foreach(array_keys($_SESSION) as $key) {
 | 
			
		||||
            if (strpos($key, self::CSRF_PARAM) === 0) {
 | 
			
		||||
                unset($_SESSION[$key]);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function csrfguard_GenerateToken($formParameter)
 | 
			
		||||
  {
 | 
			
		||||
    if ( ! session_id() ) {
 | 
			
		||||
      throw new \Exception('La sesión del usuario no está definida.');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    $paramSession = self::CSRF_PARAM.'_'.$formParameter;
 | 
			
		||||
    if (isset($_SESSION[$paramSession])) {
 | 
			
		||||
      $token = $_SESSION[$paramSession];
 | 
			
		||||
    } else {
 | 
			
		||||
      if ( function_exists('hash_algos') && in_array('sha512', hash_algos()) ) {
 | 
			
		||||
        $token = hash('sha512', mt_rand(0, mt_getrandmax()));
 | 
			
		||||
      } else {
 | 
			
		||||
        $token=' ';
 | 
			
		||||
        for ($i=0;$i<128;++$i) {
 | 
			
		||||
          $r=mt_rand(0,35);
 | 
			
		||||
          if ($r<26){
 | 
			
		||||
            $c=chr(ord('a')+$r);
 | 
			
		||||
          } else{ 
 | 
			
		||||
            $c=chr(ord('0')+$r-26);
 | 
			
		||||
          } 
 | 
			
		||||
          $token.=$c;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      $_SESSION[$paramSession]=$token;
 | 
			
		||||
    }
 | 
			
		||||
    return $token;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private function csrfguard_ValidateToken($formParameter, $tokenRecibido)
 | 
			
		||||
  {
 | 
			
		||||
    if ( ! session_id() ) {
 | 
			
		||||
        throw new \Exception('La sesión del usuario no está definida.');
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    $result = TRUE;
 | 
			
		||||
    
 | 
			
		||||
    $paramSession = self::CSRF_PARAM.'_'.$formParameter;
 | 
			
		||||
    if ( isset($_SESSION[$paramSession]) ) {
 | 
			
		||||
        if ( $_SESSION[$paramSession] !== $tokenRecibido ) {
 | 
			
		||||
            $result = array();
 | 
			
		||||
            $result[] = 'Has enviado el formulario dos veces';
 | 
			
		||||
        }
 | 
			
		||||
        $_SESSION[$paramSession] = ' ';
 | 
			
		||||
        unset($_SESSION[$paramSession]);
 | 
			
		||||
    } else {
 | 
			
		||||
        $result = array();
 | 
			
		||||
        $result[] = 'Formulario no válido';
 | 
			
		||||
    }
 | 
			
		||||
        return $result;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
    //Test some form input.
 | 
			
		||||
    protected function test_input($input){
 | 
			
		||||
        return htmlspecialchars(trim(strip_tags($input)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										32
									
								
								root/assets/php/includes/cinema.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								root/assets/php/includes/cinema.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
<?php
 | 
			
		||||
    
 | 
			
		||||
    class Cinema{
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_id;               //Cinema ID.
 | 
			
		||||
        private $_name;           //Cinema name.
 | 
			
		||||
        private $_direction;         //Cinema direction.
 | 
			
		||||
        private $_phone;         //Cinema phone.
 | 
			
		||||
      
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($id, $name, $direction, $phone){
 | 
			
		||||
            $this->_id = $id;
 | 
			
		||||
            $this->_name = $name;
 | 
			
		||||
            $this->_direction = $direction;
 | 
			
		||||
            $this->_phone = $phone;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
		//Getters && Setters:
 | 
			
		||||
        public function setId($id){	$this->_id = $id; }
 | 
			
		||||
		public function getId(){ return $this->_id; }
 | 
			
		||||
        public function setName($name){	$this->_name = $name; }
 | 
			
		||||
		public function getName(){ return $this->_name; }
 | 
			
		||||
        public function setDirection($direction){ $this->_direction = $direction; }
 | 
			
		||||
		public function getDirection(){ return $this->_direction; }
 | 
			
		||||
        public function setPhone($phone){$this->_phone = $phone; }
 | 
			
		||||
		public function getPhone(){ return $this->_phone; }
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										132
									
								
								root/assets/php/includes/cinema_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								root/assets/php/includes/cinema_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,132 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('cinema.php');
 | 
			
		||||
 | 
			
		||||
    class Cinema_DAO extends DAO {
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
        //Create a new Session.
 | 
			
		||||
		public function createCinema($id, $name, $direction, $phone){
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `cinema`( `id`, `name`, `direction`, `phone`) 
 | 
			
		||||
								VALUES ( '%d', '%s', '%s', '%s')", 
 | 
			
		||||
									$id, $name, $direction, $phone);
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
	    //Returns a query to get All the films.
 | 
			
		||||
		public function allCinemaData(){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM cinema ");
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$films[] = $this->loadCinema($fila["id"], $fila["name"], $fila["direction"], $fila["phone"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
			return $films;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a  film data .
 | 
			
		||||
		public function GetCinema($name, $direction){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM cinema WHERE cinema.name = '%s'AND cinema.direction='%s'", $name,$direction );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a  film data .
 | 
			
		||||
		public function cinemaData($id){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM cinema WHERE id = '%d'", $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			$resul->data_seek(0);
 | 
			
		||||
			$film = null;
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$cinema = $this->loadCinema($fila["id"], $fila["name"], $fila["direction"], $fila["phone"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
 | 
			
		||||
			return $cinema;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns if exist a cinema with that id
 | 
			
		||||
		public function existCinema($id){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM cinema WHERE id = '%d'", $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Deleted film by "id".
 | 
			
		||||
		public function deleteCinema($id){
 | 
			
		||||
			$sql = sprintf( "DELETE FROM cinema WHERE cinema.id = '%d' ;",$id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Edit a film.
 | 
			
		||||
		public function editCinema($id, $name, $direction, $phone){
 | 
			
		||||
			$sql = sprintf( "UPDATE cinema SET name = '%s' , direction = '%s', phone ='%s' 
 | 
			
		||||
								WHERE cinema.id = '%d';", 
 | 
			
		||||
									$name, $direction, $phone, $id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Get sessions associated with a cinema.
 | 
			
		||||
		public function getSessions($id){
 | 
			
		||||
			include_once('session_dao.php');
 | 
			
		||||
			$session = new SessionDAO("complucine");
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( " SELECT DISTINCT * FROM session WHERE session.id in 
 | 
			
		||||
								(SELECT session.id FROM session JOIN cinema ON session.idcinema = cinema.id WHERE cinema.id = '%d'); ", $id);
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			$sessions = null;
 | 
			
		||||
			while($fila = $resul->fetch_assoc()){
 | 
			
		||||
				$sessions[] = $session->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
 | 
			
		||||
			return $sessions;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Get films associated with a cinema.
 | 
			
		||||
		public function getFilms($id){
 | 
			
		||||
			include_once('film_dao.php');
 | 
			
		||||
			$film = new Film_DAO("complucine");
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( " SELECT DISTINCT * FROM film WHERE film.id in 
 | 
			
		||||
								(SELECT session.idfilm FROM session JOIN cinema ON session.idcinema = cinema.id WHERE cinema.id = '%d'); ", $id);
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			$films = null;
 | 
			
		||||
			while($fila = $resul->fetch_assoc()){
 | 
			
		||||
				$films[] = $film->loadFilm($fila["id"], $fila["tittle"], $fila["duration"], $fila["language"], $fila["description"], $fila["img"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
 | 
			
		||||
			return $films;
 | 
			
		||||
		}
 | 
			
		||||
	    
 | 
			
		||||
		//Create a new film Data Transfer Object.
 | 
			
		||||
		public function loadCinema($id, $name, $direction, $phone){
 | 
			
		||||
			return new Cinema($id, $name, $direction, $phone);
 | 
			
		||||
		}
 | 
			
		||||
	    	
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										185
									
								
								root/assets/php/includes/event.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										185
									
								
								root/assets/php/includes/event.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,185 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
include_once($prefix.'assets/php/includes/session.php');
 | 
			
		||||
 | 
			
		||||
//Full calendar only accepts Events objects
 | 
			
		||||
class Event implements \JsonSerializable
 | 
			
		||||
{
 | 
			
		||||
    public static function searchAllEvents($idhall, $cinema)
 | 
			
		||||
    {
 | 
			
		||||
        $result = [];
 | 
			
		||||
		$sessions = Session::getListSessions($idhall,$cinema,null);
 | 
			
		||||
		
 | 
			
		||||
		foreach($sessions as $s){
 | 
			
		||||
			$e = new Event();
 | 
			
		||||
			$diccionario = self::session2dictionary($s);
 | 
			
		||||
			$e = $e->dictionary2event($diccionario);
 | 
			
		||||
			$result[] = $e;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
  
 | 
			
		||||
    public static function searchEventsBetween2dates(string $start, string $end = null, $idhall, $cinema)
 | 
			
		||||
    {	
 | 
			
		||||
        
 | 
			
		||||
        $result = [];
 | 
			
		||||
        $sessions = Session::getListSessionsBetween2Dates($idhall,$cinema,$start,$end);
 | 
			
		||||
        if($sessions){
 | 
			
		||||
            foreach($sessions as $s){
 | 
			
		||||
                $e = new Event();
 | 
			
		||||
                $dictionary = self::session2dictionary($s);
 | 
			
		||||
                $e = $e->dictionary2event($dictionary);
 | 
			
		||||
                $result[] = $e;
 | 
			
		||||
            }
 | 
			
		||||
         }
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private $id;
 | 
			
		||||
    private $title;
 | 
			
		||||
    private $start;
 | 
			
		||||
    private $end;
 | 
			
		||||
 | 
			
		||||
	private $idfilm;
 | 
			
		||||
    private $start_time;
 | 
			
		||||
	private $seat_price;
 | 
			
		||||
    private $format;
 | 
			
		||||
    private $seats_full;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private function __construct()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getId()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->id;
 | 
			
		||||
    }
 | 
			
		||||
	
 | 
			
		||||
     public function getIdfilm()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->idfilm;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Return an object that allows Event object to be serialized as json because private atributes cant be serialized
 | 
			
		||||
    public function jsonSerialize()
 | 
			
		||||
    {	
 | 
			
		||||
        $film = Session::getThisSessionFilm($this->idfilm);
 | 
			
		||||
        
 | 
			
		||||
        $undesirable = array(
 | 
			
		||||
            'á','À','Á','Â','Ã','Ä','Å',
 | 
			
		||||
            'ß','Ç',
 | 
			
		||||
            'È','É','Ê','Ë',
 | 
			
		||||
            'Ì','Í','Î','Ï','Ñ',
 | 
			
		||||
            'Ò','Ó','Ô','Õ','Ö',
 | 
			
		||||
            'Ù','Ú','Û','Ü',
 | 
			
		||||
            'ñ'
 | 
			
		||||
        );
 | 
			
		||||
        $good = array(
 | 
			
		||||
            'a','A','A','A','A','A','A',
 | 
			
		||||
            'B','C',
 | 
			
		||||
            'E','E','E','E',
 | 
			
		||||
            'I','I','I','I','N',
 | 
			
		||||
            'O','O','O','O','O',
 | 
			
		||||
            'U','U','U','U',
 | 
			
		||||
            'n'
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $lan = str_replace($undesirable, $good, $film["language"]);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        $o = new \stdClass();
 | 
			
		||||
        $o->id = $this->id;
 | 
			
		||||
        $o->title = $this->title;
 | 
			
		||||
        $o->start = $this->start;
 | 
			
		||||
        $o->end = $this->end;
 | 
			
		||||
        $o->start_time = $this->start_time;
 | 
			
		||||
		$o->seat_price = $this->seat_price;
 | 
			
		||||
        $o->format = $this->format;
 | 
			
		||||
    	$o->film_dur = $film["duration"];
 | 
			
		||||
        $o->film_id = $film["idfilm"];
 | 
			
		||||
        $o->film_lan = $lan;
 | 
			
		||||
        $o->film_img = $film["img"];
 | 
			
		||||
		$o->date = $this->start;
 | 
			
		||||
 | 
			
		||||
        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(),
 | 
			
		||||
			"title" => $tittle,
 | 
			
		||||
			"start" => $start,
 | 
			
		||||
			"end" => $end,
 | 
			
		||||
			"idfilm" => $session->getIdfilm(),
 | 
			
		||||
			"start_time" => $session->getStartTime(),
 | 
			
		||||
			"seat_price" => $session->getSeatPrice(),
 | 
			
		||||
			"format" => $session->getFormat(),
 | 
			
		||||
			"seats_full" => $session->getSeatsFull(),
 | 
			
		||||
		);
 | 
			
		||||
		
 | 
			
		||||
		return $dictionary;
 | 
			
		||||
	}
 | 
			
		||||
    
 | 
			
		||||
    protected function dictionary2event(array $dictionary)
 | 
			
		||||
    {
 | 
			
		||||
        if (array_key_exists('id', $dictionary)) {
 | 
			
		||||
            $id = $dictionary['id'];
 | 
			
		||||
            $this->id =(int)$id;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (array_key_exists('title', $dictionary)) {
 | 
			
		||||
            $title = $dictionary['title'];
 | 
			
		||||
            $this->title = $title;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        if (array_key_exists('start', $dictionary)) {
 | 
			
		||||
            $start = $dictionary['start'];
 | 
			
		||||
            //$start = DateTime::createFromFormat("y-m-d H:i:s", $start);
 | 
			
		||||
            $this->start = $start;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (array_key_exists('end', $dictionary)) {
 | 
			
		||||
            $end = $dictionary['end'] ?? null;
 | 
			
		||||
            $this->end = $end;
 | 
			
		||||
        }
 | 
			
		||||
		
 | 
			
		||||
        
 | 
			
		||||
		if (array_key_exists('idfilm', $dictionary)) {
 | 
			
		||||
            $idfilm = $dictionary['idfilm'] ?? null;
 | 
			
		||||
            $this->idfilm = $idfilm;
 | 
			
		||||
        }
 | 
			
		||||
		
 | 
			
		||||
		if (array_key_exists('start_time', $dictionary)) {
 | 
			
		||||
            $start_time = $dictionary['start_time'] ?? null;
 | 
			
		||||
            $this->start_time = $start_time;
 | 
			
		||||
        }
 | 
			
		||||
		
 | 
			
		||||
		if (array_key_exists('seat_price', $dictionary)) {
 | 
			
		||||
            $seat_price = $dictionary['seat_price'] ?? null;
 | 
			
		||||
            $this->seat_price = $seat_price;
 | 
			
		||||
        }
 | 
			
		||||
		
 | 
			
		||||
		if (array_key_exists('format', $dictionary)) {
 | 
			
		||||
            $format = $dictionary['format'] ?? null;
 | 
			
		||||
            $this->format = $format;
 | 
			
		||||
        }
 | 
			
		||||
		
 | 
			
		||||
		if (array_key_exists('seats_full', $dictionary)) {
 | 
			
		||||
            $seats_full = $dictionary['seats_full'] ?? null;
 | 
			
		||||
            $this->seats_full = $seats_full;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										39
									
								
								root/assets/php/includes/film.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								root/assets/php/includes/film.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
<?php
 | 
			
		||||
   
 | 
			
		||||
    class Film{
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_id;               //Film ID.
 | 
			
		||||
        private $_tittle;           //Film tittle.
 | 
			
		||||
        private $_duration;         //Film duration.
 | 
			
		||||
        private $_language;         //Film language.
 | 
			
		||||
        private $_description;      //Film description.
 | 
			
		||||
        private $_img;              //Film image.
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($id, $tittle, $duration, $language, $description, $img){
 | 
			
		||||
            $this->_id = $id;
 | 
			
		||||
            $this->_tittle = $tittle;
 | 
			
		||||
            $this->_duration = $duration;
 | 
			
		||||
            $this->_language = $language;
 | 
			
		||||
            $this->_description = $description;
 | 
			
		||||
            $this->_img = $img;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//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;}
 | 
			
		||||
        public function setImg($img){  $this->_img = $img;}
 | 
			
		||||
		public function getImg(){return   $this->_img;}
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										151
									
								
								root/assets/php/includes/film_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										151
									
								
								root/assets/php/includes/film_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,151 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('film.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, $img){
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `film`( `id`, `tittle`, `duration`, `language`,`description`, `img`) 
 | 
			
		||||
								VALUES ( '%d', '%s', '%d', '%s','%s', '%s')", 
 | 
			
		||||
									$id, $tittle, $duration, $language, $description, $img);
 | 
			
		||||
			
 | 
			
		||||
			$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 the film's data by ID.
 | 
			
		||||
		public function FilmData($id){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM film WHERE id = '%d'", $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			$resul->data_seek(0);
 | 
			
		||||
			$film = null;
 | 
			
		||||
			while ($fila = $resul->fetch_assoc()) {
 | 
			
		||||
				if($id === $fila['id']){
 | 
			
		||||
					$film = $this->loadFilm($fila["id"], $fila["tittle"], $fila["duration"], $fila["language"], $fila["description"], $fila["img"]);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			//mysqli_free_result($selectUser);
 | 
			
		||||
			$resul->free();
 | 
			
		||||
 | 
			
		||||
			return $film;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns if exist a Film with this id
 | 
			
		||||
		public function existFilm($id){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($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"], $fila["img"]);
 | 
			
		||||
			}
 | 
			
		||||
			$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,$img){
 | 
			
		||||
			$sql = sprintf( "UPDATE film SET tittle = '%s' , duration = '%d', language ='%s' , description ='%s', img ='%s'
 | 
			
		||||
								WHERE film.id = '%d';", 
 | 
			
		||||
									$tittle, $duration, $language, $description, $img, $id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Edit a film.
 | 
			
		||||
		public function editFilmNoImg($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;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Get cinemas associated with a movie.
 | 
			
		||||
		public function getCinemas($id){
 | 
			
		||||
			include_once('cinema_dao.php');
 | 
			
		||||
			$cinema = new Cinema_DAO("complucine");
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( " SELECT DISTINCT * FROM cinema WHERE cinema.id in 
 | 
			
		||||
								(SELECT session.idcinema FROM session JOIN film ON session.idfilm = film.id WHERE film.id = '%d'); ", $id);
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			$cinemas = null;
 | 
			
		||||
			while($fila = $resul->fetch_assoc()){
 | 
			
		||||
				$cinemas[] = $cinema->loadCinema($fila["id"], $fila["name"], $fila["direction"], $fila["phone"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
 | 
			
		||||
			return $cinemas;
 | 
			
		||||
		}
 | 
			
		||||
	    
 | 
			
		||||
		//Create a new film Data Transfer Object.
 | 
			
		||||
		public function loadFilm($id, $tittle, $duration, $language,$description, $img){
 | 
			
		||||
			return new Film( $id, $tittle, $duration, $language,$description, $img);
 | 
			
		||||
		}
 | 
			
		||||
	    	
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										109
									
								
								root/assets/php/includes/hall.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										109
									
								
								root/assets/php/includes/hall.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,109 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('hall_dao.php');
 | 
			
		||||
	include_once('seat_dao.php');
 | 
			
		||||
	
 | 
			
		||||
    class Hall{
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_number;      	//Room number.
 | 
			
		||||
        private $_idcinema;    	//Cinema Id
 | 
			
		||||
		private $_numRows;     	//Num rows.
 | 
			
		||||
        private $_numCol;      	//Num columns.
 | 
			
		||||
		private $_total_seats;	//Toal seats.	
 | 
			
		||||
		private $_seats_map;	//Seat map.
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($number, $idcinema, $numRows, $numCol, $total_seats, $seats_map){
 | 
			
		||||
            $this->_number = $number;
 | 
			
		||||
            $this->_idcinema = $idcinema;
 | 
			
		||||
            $this->_numRows = $numRows;
 | 
			
		||||
			$this->_numCol = $numCol;
 | 
			
		||||
			$this->_total_seats = $total_seats;
 | 
			
		||||
			$_seats_map = array();
 | 
			
		||||
			$_seats_map = $seats_map;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
		public static function getListHalls($cinema){
 | 
			
		||||
			$bd = new HallDAO('complucine');
 | 
			
		||||
			if($bd )
 | 
			
		||||
				return $bd->getAllHalls($cinema);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public static function create_hall($number, $cinema, $rows, $cols, $seats, $seats_map){
 | 
			
		||||
			$bd = new HallDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if(!$bd->searchHall($number, $cinema)){
 | 
			
		||||
					$bd->createHall($number, $cinema, $rows, $cols, $seats, $seats_map);
 | 
			
		||||
					Seat::createSeats($number, $cinema, $rows, $cols, $seats_map);
 | 
			
		||||
					return "Se ha creado la sala con exito";
 | 
			
		||||
				} else {
 | 
			
		||||
					return "Esta sala ya existe";
 | 
			
		||||
				}
 | 
			
		||||
			} else { return "Error al conectarse a la base de datos"; }
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static function edit_hall($number, $cinema, $rows, $cols, $seats, $seats_map, $og_number){
 | 
			
		||||
			$bd = new HallDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if($bd->searchHall($og_number, $cinema)){
 | 
			
		||||
					if($og_number == $number){
 | 
			
		||||
						Seat::deleteAllSeats($number, $cinema);
 | 
			
		||||
						$bd->editHall($number, $cinema, $rows, $cols, $seats, $og_number);
 | 
			
		||||
						Seat::createSeats($number, $cinema, $rows, $cols, $seats_map);
 | 
			
		||||
						return "Se ha editado la sala con exito";
 | 
			
		||||
					}else{
 | 
			
		||||
						if(!$bd->searchHall($number, $cinema)){
 | 
			
		||||
							Seat::deleteAllSeats($og_number, $cinema);
 | 
			
		||||
							$bd->editHall($number, $cinema, $rows, $cols, $seats, $og_number);
 | 
			
		||||
							Seat::createSeats($number, $cinema, $rows, $cols, $seats_map);
 | 
			
		||||
							return "Se ha editado la sala con exito";
 | 
			
		||||
						}else
 | 
			
		||||
							return "El nuevo numero de sala ya existe en otra sala";
 | 
			
		||||
					}
 | 
			
		||||
				} else {
 | 
			
		||||
					return "La sala a editar no existe";
 | 
			
		||||
				}
 | 
			
		||||
			} else { return "Error al conectarse a la base de datos"; }
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static function delete_hall($number, $cinema, $rows, $cols, $seats, $seats_map, $og_number){
 | 
			
		||||
			$bd = new HallDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if($bd->searchHall($og_number, $cinema)){
 | 
			
		||||
					$bd->deleteHall($og_number, $cinema);
 | 
			
		||||
					Seat::deleteAllSeats($og_number, $cinema);
 | 
			
		||||
					return "La sala se ha eliminado correctamente";
 | 
			
		||||
				} else {
 | 
			
		||||
					return "La sala a borrar no existe";
 | 
			
		||||
				}
 | 
			
		||||
			} else { return "Error al conectarse a la base de datos"; }
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public static function search_hall($number,$cinema){
 | 
			
		||||
			$bd = new HallDAO('complucine');
 | 
			
		||||
			if($bd )
 | 
			
		||||
				return $bd->searchHall($number,$cinema);;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//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; }
 | 
			
		||||
 | 
			
		||||
		public function setTotalSeats($totalSeat){ $this->_total_seats = $totalSeat; }
 | 
			
		||||
		public function getTotalSeats(){ return $this->_total_seats; }
 | 
			
		||||
 | 
			
		||||
		public function setSeatsmap($seats_map){ $this->_seats_map = $seats_map; }
 | 
			
		||||
		public function getSeatsmap(){ return $this->_seats_map; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										116
									
								
								root/assets/php/includes/hall_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								root/assets/php/includes/hall_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,116 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('hall.php');
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
    class HallDAO extends DAO {
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
        //Create a new hall taking the new number,cinema, rows, cols, seats and seats map saving in the database
 | 
			
		||||
		public function createHall($number, $cinema, $rows, $cols, $seats, $seats_map){
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `hall`( `number`, `idcinema`, `numrows`, `numcolumns`, `total_seats`) 
 | 
			
		||||
								VALUES ( '%d', '%d', '%d', '%d', '%d')", 
 | 
			
		||||
								$number, $cinema, $rows, $cols, $seats );
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error BD createhall');
 | 
			
		||||
			
 | 
			
		||||
			return $sql;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns the hall's data by ID.
 | 
			
		||||
		public function HallData($id){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM hall WHERE number = '%d'", $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			$resul->data_seek(0);
 | 
			
		||||
			$hall = null;
 | 
			
		||||
			while ($fila = $resul->fetch_assoc()) {
 | 
			
		||||
				$hall = $this->loadHall($fila["number"], $fila["idcinema"], $fila["numrows"], $fila["numcolumns"], $fila["total_seats"], null);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			//mysqli_free_result($selectUser);
 | 
			
		||||
			$resul->free();
 | 
			
		||||
 | 
			
		||||
			return $hall;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//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"], $fila["total_seats"], null);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $hall;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Returns a  hall data taking the number and cinema
 | 
			
		||||
		public function searchHall($number, $cinema){
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM hall WHERE 
 | 
			
		||||
							number = '%s' AND idcinema = '%s'", 
 | 
			
		||||
							$number, $cinema);	
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			$hall = false;
 | 
			
		||||
			
 | 
			
		||||
			if($resul){
 | 
			
		||||
				if($resul->num_rows == 1){
 | 
			
		||||
					$fila = $resul->fetch_assoc();
 | 
			
		||||
					$hall = $this->loadHall($fila["number"], $fila["idcinema"], $fila["numrows"], $fila["numcolumns"], $fila["total_seats"], null);
 | 
			
		||||
				}
 | 
			
		||||
				$resul->free();
 | 
			
		||||
			}
 | 
			
		||||
		
 | 
			
		||||
			return $hall;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		//Create a new Hall Data Transfer Object.
 | 
			
		||||
		public function loadHall($number, $idcinema, $numrows, $numcolumns, $total_seats, $seats_map){
 | 
			
		||||
			return new Hall($number, $idcinema, $numrows, $numcolumns, $total_seats, $seats_map);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Edit a hall taking the new number, rows, cols ans seats with respect to its origin parameter
 | 
			
		||||
		public function editHall($number, $cinema, $rows, $cols, $seats, $og_number){
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "UPDATE `hall`
 | 
			
		||||
							SET `number` = '%d' ,`numrows` = '%d' , `numcolumns` = '%d' , `total_seats` = %d
 | 
			
		||||
							WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';", 
 | 
			
		||||
							$number, $rows, $cols, $seats, $og_number, $cinema );
 | 
			
		||||
			
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Delete a hall whit the primary key
 | 
			
		||||
		public function deleteHall($number, $cinema){
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "DELETE FROM `hall` WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';",$number, $cinema);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										35
									
								
								root/assets/php/includes/manager.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								root/assets/php/includes/manager.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
<?php
 | 
			
		||||
    
 | 
			
		||||
    class Manager{
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_id;               //Manager ID.
 | 
			
		||||
        private $_username;           //Manager username.
 | 
			
		||||
        private $_email;         //Email.
 | 
			
		||||
        private $_roll;       //Roll
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($id, $idcinema, $username, $email, $roll){
 | 
			
		||||
            $this->_id = $id;
 | 
			
		||||
            $this->_idcinema = $idcinema;
 | 
			
		||||
            $this->_username = $username;
 | 
			
		||||
            $this->_email = $email;
 | 
			
		||||
            $this->_roll = $roll;
 | 
			
		||||
        }
 | 
			
		||||
	
 | 
			
		||||
		//Methods:
 | 
			
		||||
	    
 | 
			
		||||
		//Getters && Setters:
 | 
			
		||||
        public function setId($id){	$this->_id = $id; }
 | 
			
		||||
		public function getId(){ return $this->_id; }
 | 
			
		||||
        public function setIdcinema($idcinema){	$this->_idcinema = $idcinema; }
 | 
			
		||||
		public function getIdcinema(){ return $this->_idcinema; }
 | 
			
		||||
        public function setUsername($username){$this->_username = $username; }
 | 
			
		||||
		public function getUsername(){ return 	$this->_username;}
 | 
			
		||||
        public function setEmail($email){$this->_email = $email;}
 | 
			
		||||
		public function getEmail(){return $this->_email;}
 | 
			
		||||
        public function setRoll($roll){$this->_roll = $roll;}
 | 
			
		||||
		public function getRoll(){return  $this->_roll;}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										77
									
								
								root/assets/php/includes/manager_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								root/assets/php/includes/manager_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,77 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('manager.php');
 | 
			
		||||
 | 
			
		||||
    class Manager_DAO extends DAO {
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
		
 | 
			
		||||
	   	//Returns a query to get all the manager's data.
 | 
			
		||||
		public function allManagersData(){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM `users` JOIN `manager` ON manager.id = users.id");
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$managers[] = $this->loadManager($fila["id"], $fila["idcinema"], $fila["username"], $fila["email"], $fila["rol"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
			return $managers;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a  manager data taking the id
 | 
			
		||||
		public function GetManager($id){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM `manager` WHERE manager.id = '%d'", $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a  manager data 
 | 
			
		||||
		public function GetManagerCinema($id, $idcinema){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM `manager` WHERE manager.id = '%d' AND manager.idcinema ='%d'", $id, $idcinema );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		 //Create a new Manager with a new id and id cinema
 | 
			
		||||
		 public function createManager($id, $idcinema){
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `manager`( `id`, `idcinema`)
 | 
			
		||||
								VALUES ( '%d', '%d')", 
 | 
			
		||||
									$id, $idcinema);
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
		//Deleted manager by "id".
 | 
			
		||||
		public function deleteManager($id){
 | 
			
		||||
			$sql = sprintf( "DELETE FROM `manager` WHERE manager.id = '%d' ;",$id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Edit manager by "id" and "idcinema"
 | 
			
		||||
		public function editManager($id, $idcinema){
 | 
			
		||||
			$sql = sprintf( "UPDATE `manager` SET manager.idcinema = '%d'
 | 
			
		||||
								WHERE manager.id = '%d';", 
 | 
			
		||||
									 $idcinema, $id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
	    
 | 
			
		||||
		//Create a new Manager Data Transfer Object.
 | 
			
		||||
		public function loadManager($id, $idcinema, $username, $email, $rol){
 | 
			
		||||
			return new Manager($id, $idcinema, $username, $email, $rol);
 | 
			
		||||
		}
 | 
			
		||||
	    	
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										40
									
								
								root/assets/php/includes/promotion.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								root/assets/php/includes/promotion.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
<?php
 | 
			
		||||
    
 | 
			
		||||
    class Promotion{
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_id;               //Promotion ID.
 | 
			
		||||
        private $_tittle;           //Promotions name.
 | 
			
		||||
        private $_description;      //Promotion description.
 | 
			
		||||
        private $_code;             //Promotion code.
 | 
			
		||||
        private $_active;           //Promotion is active?
 | 
			
		||||
        private $_img;
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($id, $tittle, $description, $code, $active, $img){
 | 
			
		||||
            $this->_id = $id;
 | 
			
		||||
            $this->_tittle = $tittle;
 | 
			
		||||
            $this->_description = $description;
 | 
			
		||||
            $this->_code = $code;
 | 
			
		||||
            $this->_active = $active;
 | 
			
		||||
            $this->_img= $img;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//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 setDescription($description){  $this->_description = $description;}
 | 
			
		||||
		public function getDescription(){return  $this->_description;}
 | 
			
		||||
        public function setCode($code){  $this->_code = $code;}
 | 
			
		||||
		public function getCode(){return  $this->_code;}
 | 
			
		||||
        public function setActive($active){  $this->_active = $active;}
 | 
			
		||||
		public function getActive(){return  $this->_active;}
 | 
			
		||||
        public function setImg($img){  $this->_img = $img;}
 | 
			
		||||
		public function getImg(){return  $this->_img;}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										102
									
								
								root/assets/php/includes/promotion_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								root/assets/php/includes/promotion_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,102 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('promotion.php');
 | 
			
		||||
 | 
			
		||||
    class Promotion_DAO extends DAO {
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
        //Create a new Session.
 | 
			
		||||
		public function createPromotion($id, $tittle, $description, $code, $active, $img){
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `promotion`( `id`, `tittle`, `description`, `code`, `active`, `img`) 
 | 
			
		||||
								VALUES ( '%d', '%s', '%s', '%s', '%s', '%s')", 
 | 
			
		||||
									$id, $tittle, $description, $code, $active, $img);
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
	    //Returns a query to get All the promotion.
 | 
			
		||||
		public function allPromotionData(){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM promotion ");
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$promotions[] = $this->loadPromotion($fila["id"], $fila["tittle"], $fila["description"], $fila["code"], $fila["active"], $fila["img"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
			return $promotions;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a  promotion data  by code.
 | 
			
		||||
		public function GetPromotion($code){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM promotion WHERE promotion.code = '%s'", $code );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a  promotion data  by id.
 | 
			
		||||
		public function promotionData($id){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM promotion WHERE promotion.id = '%d'", $id);
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Deleted promotion by "id".
 | 
			
		||||
		public function deletePromotion($id){
 | 
			
		||||
			$sql = sprintf( "DELETE FROM promotion WHERE promotion.id = '%d' ;",$id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Edit a promotion with new img.
 | 
			
		||||
		public function editPromotion($id, $tittle, $description, $code, $active, $img){
 | 
			
		||||
			$sql = sprintf( "UPDATE promotion SET tittle = '%s' , description = '%s', code ='%s' , active ='%s', img = '%s'
 | 
			
		||||
								WHERE promotion.id = '%d';", 
 | 
			
		||||
									 $tittle, $description, $code, $active, $img, $id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Edit a promotion without new img.
 | 
			
		||||
		public function editPromotionNoImg($id, $tittle, $description, $code, $active){
 | 
			
		||||
			$sql = sprintf( "UPDATE promotion SET tittle = '%s' , description = '%s', code ='%s' , active ='%s'
 | 
			
		||||
								WHERE promotion.id = '%d';", 
 | 
			
		||||
									 $tittle, $description, $code, $active, $id);
 | 
			
		||||
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a  promotion data as object.
 | 
			
		||||
		public function GetPromotionObj($code){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM promotion WHERE promotion.code = '%s'", $code );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			$promo = null;
 | 
			
		||||
			while($fila = $resul->fetch_assoc()){
 | 
			
		||||
				$promo = $this->loadPromotion($fila["id"], $fila["tittle"], $fila["description"], $fila["code"], $fila["active"], $fila["img"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
 | 
			
		||||
			return $promo;
 | 
			
		||||
		}
 | 
			
		||||
	    
 | 
			
		||||
		//Create a new film Data Transfer Object.
 | 
			
		||||
		public function loadPromotion($id, $tittle, $description, $code, $active, $img){
 | 
			
		||||
			return new Promotion($id, $tittle, $description, $code, $active, $img);
 | 
			
		||||
		}
 | 
			
		||||
	    	
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										43
									
								
								root/assets/php/includes/purchase.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								root/assets/php/includes/purchase.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
<?php   
 | 
			
		||||
    class Purchase {
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_idUser;           //User Id.
 | 
			
		||||
        private $_idSession;        //Session Id.
 | 
			
		||||
        private $_idHall;           //Hall Id.
 | 
			
		||||
        private $_idCinema;         //Cinema Id.
 | 
			
		||||
        private $_numRow;           //Number of row seat.
 | 
			
		||||
        private $_numColumn;        //Number of column seat.
 | 
			
		||||
        private $_timePurchase;     //Time of purchase.
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($idUser, $idSession, $idHall, $idCinema, $row, $column, $time){
 | 
			
		||||
            $this->_idUser = $idUser;
 | 
			
		||||
            $this->_idSession = $idSession;
 | 
			
		||||
            $this->_idHall = $idHall;
 | 
			
		||||
            $this->_idCinema = $idCinema;
 | 
			
		||||
            $this->_numRow = $row;
 | 
			
		||||
            $this->_numColumn = $column;
 | 
			
		||||
            $this->_timePurchase = $time;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
		//Getters && Setters:
 | 
			
		||||
        public function setUserId($idUser){	$this->_idUser = $id; }
 | 
			
		||||
		public function getUserId(){ return $this->_idUser; }
 | 
			
		||||
        public function setSessionId($idSession){	$this->_idSession = $idSession; }
 | 
			
		||||
		public function getSessionId(){ return $this->_idSession; }
 | 
			
		||||
        public function setHallId($idHall){	$this->_idHall = $idHall; }
 | 
			
		||||
		public function getHallId(){ return $this->_idHall; }
 | 
			
		||||
        public function setCinemaId($idCinema){	$this->_idCinema = $idCinema; }
 | 
			
		||||
		public function getCinemaId(){ return $this->_idCinema; }
 | 
			
		||||
        public function setRow($row){	$this->_numRow = $row; }
 | 
			
		||||
		public function getRow(){ return $this->_numRow; }
 | 
			
		||||
        public function setColumn($column){	$this->_numColumn = $column; }
 | 
			
		||||
		public function getColumn(){ return $this->_numColumn; }
 | 
			
		||||
        public function setTime($time){	$this->_timePurchase = $time; }
 | 
			
		||||
		public function getTime(){ return $this->_timePurchase; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										46
									
								
								root/assets/php/includes/purchase_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								root/assets/php/includes/purchase_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('purchase.php');
 | 
			
		||||
 | 
			
		||||
    class PurchaseDAO extends DAO {
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
		//Create a new Purchase.
 | 
			
		||||
		public function createPurchase($idUser, $idSession, $idHall, $idCinema, $row, $column, $time){
 | 
			
		||||
			$sql = sprintf( "INSERT INTO purchase( iduser, idsession, idhall, idcinema, numrow, numcolum, time_purchase ) 
 | 
			
		||||
								VALUES ( '%d', '%d', '%d', '%d', '%d', '%d', '%s' )", 
 | 
			
		||||
									$idUser, $idSession, $idHall, $idCinema, $row, $column, $time );
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql);
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//All purchases of one user.
 | 
			
		||||
		public function allPurchasesData($idUser){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM purchase WHERE iduser = '%d' ", $idUser);
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			$purchases = null;
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$purchases[] = $this->loadPurchase($fila["iduser"], $fila["idsession"], $fila["idhall"], $fila["idcinema"], $fila["numrow"], $fila["numcolum"], $fila["time_purchase"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
			return $purchases;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Create a new User Data Transfer Object.
 | 
			
		||||
		public function loadPurchase($idUser, $idSession, $idHall, $idCinema, $row, $column, $time){
 | 
			
		||||
			return new Purchase($idUser, $idSession, $idHall, $idCinema, $row, $column, $time);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										63
									
								
								root/assets/php/includes/seat.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								root/assets/php/includes/seat.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,63 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('seat_dao.php');
 | 
			
		||||
 | 
			
		||||
    class Seat{
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_idhall;     	//Hall id.
 | 
			
		||||
        private $_idcinema;    	//Cinema id.
 | 
			
		||||
		private $_numRow;     	//Number of row.
 | 
			
		||||
        private $_numCol;      	//Number of column.
 | 
			
		||||
		private $_state;      	//State of the seat-
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($idhall, $idcinema, $numRow, $numCol, $state){
 | 
			
		||||
            $this->_number = $idhall;
 | 
			
		||||
            $this->_idcinema = $idcinema;
 | 
			
		||||
            $this->_numRow = $numRow;
 | 
			
		||||
			$this->_numCol = $numCol;
 | 
			
		||||
			$this->_state = $state;
 | 
			
		||||
        }
 | 
			
		||||
		
 | 
			
		||||
		static public function createSeats($hall, $cinema, $rows, $cols, $seats_map){
 | 
			
		||||
			$bd = new SeatDAO('complucine');
 | 
			
		||||
 | 
			
		||||
			for($i = 1;$i <= $rows;$i++){
 | 
			
		||||
				for($j = 1; $j <= $cols;$j++){
 | 
			
		||||
					$bd->createSeat($hall, $cinema, $i, $j, $seats_map[$i][$j]);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		static public function getSeatsMap($number, $cinema){
 | 
			
		||||
			$bd = new SeatDAO('complucine');
 | 
			
		||||
			if($bd )
 | 
			
		||||
				return $bd->getAllSeats($number, $cinema);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		static public function deleteAllSeats($number, $cinema){
 | 
			
		||||
			$bd = new SeatDAO('complucine');
 | 
			
		||||
			if($bd)
 | 
			
		||||
				return $bd->deletemapSeats($number, $cinema);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//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($numRow){ $this->_numRow = $numRow; }
 | 
			
		||||
		public function getNumRows(){ return $this->_numRow; }
 | 
			
		||||
		
 | 
			
		||||
		public function setNumCol($numCol){ $this->_numCol = $numCol; }
 | 
			
		||||
		public function getNumCol(){ return $this->_numCol; }
 | 
			
		||||
		
 | 
			
		||||
		public function setState($state){ $this->_state = $state; }
 | 
			
		||||
		public function getState(){ return $this->_state; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										60
									
								
								root/assets/php/includes/seat_dao-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								root/assets/php/includes/seat_dao-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,60 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('seat.php');
 | 
			
		||||
	
 | 
			
		||||
    class SeatDAO extends DAO {
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
        //Create a new Seat  taking the new hall,cinema,row,col and state saving in the database
 | 
			
		||||
		public function createSeat($hall, $cinema, $row, $col, $state){
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `seat`( `idhall`, `idcinema`, `numrow`, `numcolum`, `active`) 
 | 
			
		||||
								VALUES ( '%d', '%d', '%d', '%d', '%d')", 
 | 
			
		||||
								$hall, $cinema, $row, $col, $state);
 | 
			
		||||
	
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error BD createSeat');
 | 
			
		||||
			
 | 
			
		||||
			return $sql;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Returns a query to get all the seat's data.
 | 
			
		||||
		public function getAllSeats($number, $cinema){
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM seat WHERE 
 | 
			
		||||
							idhall = '%d' AND idcinema = '%d'", 
 | 
			
		||||
							$number, $cinema);	
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			
 | 
			
		||||
			$seat_map = null;
 | 
			
		||||
			while($fila=mysqli_fetch_array($resul)){
 | 
			
		||||
				$seat_map[] = $this->loadSeat($fila["idhall"], $fila["idcinema"], $fila["numrow"], $fila["numcolum"], $fila["active"]);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $seat_map;
 | 
			
		||||
		}
 | 
			
		||||
		//Delete a Seat whit the primary key
 | 
			
		||||
		public function deletemapSeats($hall, $cinema){
 | 
			
		||||
            $sql = sprintf( "DELETE FROM `seat` WHERE 
 | 
			
		||||
							idcinema = '%s' AND idhall = '%s'", 
 | 
			
		||||
							$cinema, $hall);	
 | 
			
		||||
 | 
			
		||||
            $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
            return $resul;
 | 
			
		||||
        }
 | 
			
		||||
		
 | 
			
		||||
		//Create a new Seat Data Transfer Object.
 | 
			
		||||
		public function loadSeat($idhall, $idcinema, $numRow, $numCol, $state){
 | 
			
		||||
			return new Seat($idhall, $idcinema, $numRow, $numCol, $state);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										76
									
								
								root/assets/php/includes/seat_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								root/assets/php/includes/seat_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,76 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('seat.php');
 | 
			
		||||
	
 | 
			
		||||
    class SeatDAO extends DAO {
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
        //Create a new Seat  taking the new hall,cinema,row,col and state saving in the database
 | 
			
		||||
		public function createSeat($hall, $cinema, $row, $col, $state){
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `seat`( `idhall`, `idcinema`, `numrow`, `numcolum`, `active`) 
 | 
			
		||||
								VALUES ( '%d', '%d', '%d', '%d', '%d')", 
 | 
			
		||||
								$hall, $cinema, $row, $col, $state);
 | 
			
		||||
	
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error BD createSeat');
 | 
			
		||||
			
 | 
			
		||||
			return $sql;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Returns a query to get all the seat's data.
 | 
			
		||||
		public function getAllSeats($number, $cinema){
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM seat WHERE 
 | 
			
		||||
							idhall = '%d' AND idcinema = '%d'", 
 | 
			
		||||
							$number, $cinema);	
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			
 | 
			
		||||
			$seat_map = null;
 | 
			
		||||
			while($fila=mysqli_fetch_array($resul)){
 | 
			
		||||
				$seat_map[] = $this->loadSeat($fila["idhall"], $fila["idcinema"], $fila["numrow"], $fila["numcolum"], $fila["active"]);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $seat_map;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Delete a Seat whit the primary key
 | 
			
		||||
		public function deletemapSeats($hall, $cinema){
 | 
			
		||||
            $sql = sprintf( "DELETE FROM `seat` WHERE 
 | 
			
		||||
							idcinema = '%s' AND idhall = '%s'", 
 | 
			
		||||
							$cinema, $hall);	
 | 
			
		||||
 | 
			
		||||
            $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
            return $resul;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Change state of the seat.
 | 
			
		||||
		/*
 | 
			
		||||
		public function changeSeatState($hall, $cinema, $row, $col, $state){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($idHall);
 | 
			
		||||
			$state = $this->mysqli->real_escape_string($state);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "UPDATE seat SET active = '%d' WHERE idhall = '%d' AND idcinema = '%d' AND numrow = '%d' AND numcolum = '%d'", 
 | 
			
		||||
																						$state, $hall, $cinema, $row, $col );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
		*/
 | 
			
		||||
		
 | 
			
		||||
		//Create a new Seat Data Transfer Object.
 | 
			
		||||
		public function loadSeat($idhall, $idcinema, $numRow, $numCol, $state){
 | 
			
		||||
			return new Seat($idhall, $idcinema, $numRow, $numCol, $state);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										136
									
								
								root/assets/php/includes/session-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								root/assets/php/includes/session-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,136 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('session_dao.php');
 | 
			
		||||
 | 
			
		||||
    class Session{
 | 
			
		||||
 | 
			
		||||
        private $_id;          
 | 
			
		||||
        private $_idfilm;
 | 
			
		||||
        private $_idhall;
 | 
			
		||||
		private $_idcinema;			
 | 
			
		||||
        private $_date;
 | 
			
		||||
        private $_startTime;
 | 
			
		||||
        private $_seatPrice;
 | 
			
		||||
        private $_format;
 | 
			
		||||
		private $_seats_full;
 | 
			
		||||
		
 | 
			
		||||
        function __construct($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $seats_full){
 | 
			
		||||
            $this->_id = $id;
 | 
			
		||||
            $this->_idfilm = $idfilm;
 | 
			
		||||
            $this->_idhall = $idhall;
 | 
			
		||||
			$this->_idcinema = $idcinema;
 | 
			
		||||
            $this->_date = $date;
 | 
			
		||||
            $this->_startTime = $startTime;
 | 
			
		||||
            $this->_seatPrice = $seatPrice;
 | 
			
		||||
            $this->_format = $format;
 | 
			
		||||
			$this->_seats_full = $seats_full;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		public static function getListSessions($hall,$cinema,$date){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ) {
 | 
			
		||||
				if($date)
 | 
			
		||||
					return $bd->getAllSessions($hall, $cinema, $date, null);
 | 
			
		||||
				else
 | 
			
		||||
					return $bd->getAllSessions($hall, $cinema, null, null);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		public static function getListSessionsBetween2Dates($hall,$cinema,$start,$end){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ) {
 | 
			
		||||
				return $bd->getAllSessions($hall, $cinema, $start, $end);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public static function create_session($cinema, $hall, $start, $date, $film, $price, $format,$repeat){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if(!$bd->searchSession($cinema, $hall, $start, $date)){
 | 
			
		||||
					$bd->createSession(null,$film, $hall, $cinema, $date, $start, $price, $format);
 | 
			
		||||
 | 
			
		||||
					if($repeat > "0") {
 | 
			
		||||
						$repeats = $repeat;
 | 
			
		||||
						$repeat = $repeat - 1;
 | 
			
		||||
						$date = date('Y-m-d', strtotime( $date . ' +1 day') );
 | 
			
		||||
						self::create_session($cinema, $hall, $start, $date, $film, $price, $format,$repeat);
 | 
			
		||||
						return "Se han creado las ".$repeat ." sesiones con exito";
 | 
			
		||||
					}
 | 
			
		||||
						
 | 
			
		||||
					else
 | 
			
		||||
						return "Se ha creado la session con exito";
 | 
			
		||||
				} else 
 | 
			
		||||
					return "Esta session ya existe";
 | 
			
		||||
				
 | 
			
		||||
			} else return "Error al conectarse a la base de datos";
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public static function edit_session($cinema, $or_hall, $or_date, $or_start, $hall, $start, $date, $film, $price, $format){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if($bd->searchSession($cinema, $or_hall, $or_start, $or_date)){
 | 
			
		||||
					if(!$bd->searchSession($cinema,$hall,$start,$date)){
 | 
			
		||||
						$origin = array("cinema" => $cinema,"hall" => $or_hall,"start" => $or_start,"date" => $or_date);
 | 
			
		||||
						$bd->editSession($film, $hall, $cinema, $date, $start, $price, $format,$origin);
 | 
			
		||||
						return "Se ha editado la session con exito";			
 | 
			
		||||
					}else if($or_hall == $hall && $or_start == $start && $or_date == $date){
 | 
			
		||||
						$origin = array("cinema" => $cinema,"hall" => $or_hall,"start" => $or_start,"date" => $or_date);
 | 
			
		||||
						$bd->editSession($film, $hall, $cinema, $date, $start, $price, $format, $origin);
 | 
			
		||||
						return "Se ha editado la session con exito";
 | 
			
		||||
					}else{
 | 
			
		||||
						return "Ya existe una sesion con los parametros nuevos";	
 | 
			
		||||
					}
 | 
			
		||||
						
 | 
			
		||||
				} else 
 | 
			
		||||
					return "La session a editar no existe";
 | 
			
		||||
				
 | 
			
		||||
			} else return "Error al conectarse a la base de datos";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static function delete_session($cinema, $hall, $start, $date){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if($bd->searchSession($cinema, $hall, $start, $date)){
 | 
			
		||||
					$bd->deleteSession($hall, $cinema, $date, $start);
 | 
			
		||||
					return "Se ha eliminado la session con exito";						
 | 
			
		||||
				} else 
 | 
			
		||||
					return "Esta session no existe";
 | 
			
		||||
				
 | 
			
		||||
			} else return "Error al conectarse a la base de datos";
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Esto deberia estar en film.php? seguramente
 | 
			
		||||
		public static function getThisSessionFilm($idfilm){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ) {
 | 
			
		||||
				return $bd->filmTittle($idfilm);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
        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; }
 | 
			
		||||
 | 
			
		||||
		public function setSeatsFull($bool){ $this->_seats_full = $bool; }
 | 
			
		||||
		public function getSeatsFull(){ return $this->_seats_full; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										129
									
								
								root/assets/php/includes/session.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								root/assets/php/includes/session.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,129 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('session_dao.php');
 | 
			
		||||
 | 
			
		||||
    class Session{
 | 
			
		||||
 | 
			
		||||
        private $_id;          
 | 
			
		||||
        private $_idfilm;
 | 
			
		||||
        private $_idhall;
 | 
			
		||||
		private $_idcinema;			
 | 
			
		||||
        private $_date;
 | 
			
		||||
        private $_startTime;
 | 
			
		||||
        private $_seatPrice;
 | 
			
		||||
        private $_format;
 | 
			
		||||
		private $_seats_full;
 | 
			
		||||
		
 | 
			
		||||
        function __construct($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $seats_full){
 | 
			
		||||
            $this->_id = $id;
 | 
			
		||||
            $this->_idfilm = $idfilm;
 | 
			
		||||
            $this->_idhall = $idhall;
 | 
			
		||||
			$this->_idcinema = $idcinema;
 | 
			
		||||
            $this->_date = $date;
 | 
			
		||||
            $this->_startTime = $startTime;
 | 
			
		||||
            $this->_seatPrice = $seatPrice;
 | 
			
		||||
            $this->_format = $format;
 | 
			
		||||
			$this->_seats_full = $seats_full;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		public static function getListSessions($hall,$cinema,$date){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ) {
 | 
			
		||||
				if($date)
 | 
			
		||||
					return $bd->getAllSessions($hall, $cinema, $date, null);
 | 
			
		||||
				else
 | 
			
		||||
					return $bd->getAllSessions($hall, $cinema, null, null);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public static function getListSessionsBetween2Dates($hall,$cinema,$start,$end){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ) {
 | 
			
		||||
				return $bd->getAllSessions($hall, $cinema, $start, $end);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static function create_session($cinema, $hall, $start, $date, $film, $price, $format){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if(!$bd->searchSessionActivesAtStartTimeAndFilmDuration($cinema, $hall, $start, $date, $film)){
 | 
			
		||||
					$bd->createSession(null,$film, $hall, $cinema, $date, $start, $price, $format);
 | 
			
		||||
					return 'Operación completada';
 | 
			
		||||
				} else 
 | 
			
		||||
					return 'La session del dia '.$date.' coincide con otra';
 | 
			
		||||
 | 
			
		||||
			} else return 'Error al conectarse a la base de datos';
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public static function edit_session($cinema, $or_hall, $or_date, $or_start, $hall, $start, $date, $film, $price, $format){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if($bd->searchSession($cinema, $or_hall, $or_start, $or_date)){
 | 
			
		||||
					if(!$bd->searchSession($cinema,$hall,$start,$date)){
 | 
			
		||||
						$origin = array("cinema" => $cinema,"hall" => $or_hall,"start" => $or_start,"date" => $or_date);
 | 
			
		||||
						$bd->editSession($film, $hall, $cinema, $date, $start, $price, $format, $origin);
 | 
			
		||||
						return "Se ha editado la session con exito";		
 | 
			
		||||
						
 | 
			
		||||
					}else if($or_hall == $hall && $or_start == $start && $or_date == $date){
 | 
			
		||||
						$origin = array("cinema" => $cinema,"hall" => $or_hall,"start" => $or_start,"date" => $or_date);
 | 
			
		||||
						$bd->editSession($film, $hall, $cinema, $date, $start, $price, $format, $origin);
 | 
			
		||||
						return "Se ha editado la session con exito";
 | 
			
		||||
					}else{
 | 
			
		||||
						return "Ya existe una sesion con los parametros nuevos";	
 | 
			
		||||
					}
 | 
			
		||||
				} else 
 | 
			
		||||
					return "La session a editar no existe";
 | 
			
		||||
				
 | 
			
		||||
			} else return "Error al conectarse a la base de datos";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static function delete_session($cinema, $hall, $start, $date){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ){
 | 
			
		||||
				if($bd->searchSession($cinema, $hall, $start, $date)){
 | 
			
		||||
					$bd->deleteSession($hall, $cinema, $date, $start);
 | 
			
		||||
					return "Se ha eliminado la session con exito";						
 | 
			
		||||
				} else 
 | 
			
		||||
					return "Esta session no existe";
 | 
			
		||||
			} else return "Error al conectarse a la base de datos";	
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Esto deberia estar en film.php? seguramente
 | 
			
		||||
		public static function getThisSessionFilm($idfilm){
 | 
			
		||||
			$bd = new SessionDAO('complucine');
 | 
			
		||||
			if($bd ) {
 | 
			
		||||
				$film = $bd->filmTittle($idfilm);
 | 
			
		||||
				$film["tittle"] = str_replace('_', ' ',$film["tittle"]);
 | 
			
		||||
				return $film;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
        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; }
 | 
			
		||||
 | 
			
		||||
		public function setSeatsFull($bool){ $this->_seats_full = $bool; }
 | 
			
		||||
		public function getSeatsFull(){ return $this->_seats_full; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										154
									
								
								root/assets/php/includes/session_dao-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										154
									
								
								root/assets/php/includes/session_dao-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,154 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('session.php');
 | 
			
		||||
	
 | 
			
		||||
    class SessionDAO extends DAO {
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
		//Methods:
 | 
			
		||||
		
 | 
			
		||||
		//Create a new Session  taking the new id,film, hall, cinema, date, start time, seat price and format saving in the database
 | 
			
		||||
		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`, `seats_full`) 
 | 
			
		||||
				VALUES ('%d', '%d', '%d', '%d', '%s', '%s', '%d', '%s', '%d')",
 | 
			
		||||
					$id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, "0");
 | 
			
		||||
			
 | 
			
		||||
			$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);
 | 
			
		||||
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$session = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
 | 
			
		||||
			return $session;
 | 
			
		||||
		}	
 | 
			
		||||
		
 | 
			
		||||
		//Look for a tittle with the id film
 | 
			
		||||
		public function filmTittle($idfilm){
 | 
			
		||||
			$sql = sprintf("SELECT * FROM film JOIN  session ON film.id = session.idfilm WHERE session.idfilm = '%d' ", $idfilm );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database en sessionData con la id '. $idfilm);
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_fetch_array($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}	
 | 
			
		||||
		
 | 
			
		||||
		//Look for a session with the primary key 
 | 
			
		||||
		public function searchSession($cinema, $hall, $startTime, $date){
 | 
			
		||||
			$date = date('Y-m-d', strtotime( $date ) ); 
 | 
			
		||||
			$startTime = date('H:i:s', strtotime( $startTime ) );
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "SELECT * 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 = mysqli_fetch_array($resul);
 | 
			
		||||
			
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $session;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Returns a query to get all the session's data.
 | 
			
		||||
		public function getAllSessions($hall, $cinema, $date, $end){
 | 
			
		||||
			if($end){
 | 
			
		||||
  
 | 
			
		||||
				$date = $date->format("Y-m-d"); 
 | 
			
		||||
				$end = $end->format("Y-m-d");  
 | 
			
		||||
				
 | 
			
		||||
				$sql = sprintf( "SELECT * FROM session WHERE 
 | 
			
		||||
								idcinema = '%s' AND idhall = '%s' AND date BETWEEN '%s' AND '%s' ORDER BY start_time ASC;", 
 | 
			
		||||
								$cinema, $hall, $date, $end);				
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			
 | 
			
		||||
			if($date && !$end){
 | 
			
		||||
				$date = date('Y-m-d', strtotime( $date ) ); 
 | 
			
		||||
				
 | 
			
		||||
				$sql = sprintf( "SELECT * FROM session WHERE 
 | 
			
		||||
								idcinema = '%s' AND idhall = '%s' AND date = '%s' ORDER BY start_time ASC;", 
 | 
			
		||||
								$cinema, $hall, $date);	
 | 
			
		||||
			}else{
 | 
			
		||||
				$sql = sprintf( "SELECT * FROM session WHERE 
 | 
			
		||||
								idcinema = '%s' AND idhall = '%s' ORDER BY start_time ASC;", 
 | 
			
		||||
								$cinema, $hall);	
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			
 | 
			
		||||
			$sessions = null;
 | 
			
		||||
			
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]);
 | 
			
		||||
			}
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $sessions;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Look for a title and cinema
 | 
			
		||||
		public function getSessions_Film_Cinema($idFiml, $idCinema){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM session WHERE session.idfilm = '%d' AND session.idcinema = '%d' ", $idFiml, $idCinema);
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			$sessions = null;
 | 
			
		||||
			while($fila = $resul->fetch_assoc()){
 | 
			
		||||
				$sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
 | 
			
		||||
			return $sessions;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Edit a session taking the new film, hall, date, start time, seat price and format with respect to its origin parameter
 | 
			
		||||
        public function editSession($idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $origin){
 | 
			
		||||
			$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, $origin["cinema"],$origin["hall"],$origin["date"],$origin["start"]);
 | 
			
		||||
 | 
			
		||||
            $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
            return $resul;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Delete a session whit the primary key
 | 
			
		||||
        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, $seats_full){
 | 
			
		||||
			return new Session( $id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $seats_full);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										175
									
								
								root/assets/php/includes/session_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										175
									
								
								root/assets/php/includes/session_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,175 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('session.php');
 | 
			
		||||
	
 | 
			
		||||
    class SessionDAO extends DAO {
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
		
 | 
			
		||||
		//Create a new Session  taking the new id,film, hall, cinema, date, start time, seat price and format saving in the database
 | 
			
		||||
		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`, `seats_full`) 
 | 
			
		||||
				VALUES ('%d', '%d', '%d', '%d', '%s', '%s', '%d', '%s', '%d')",
 | 
			
		||||
					$id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, "0");
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error createSession');
 | 
			
		||||
			
 | 
			
		||||
			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 accessing to the session with id '. $id);
 | 
			
		||||
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$session = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
 | 
			
		||||
			return $session;
 | 
			
		||||
		}	
 | 
			
		||||
		
 | 
			
		||||
		//Look for a film with the id film
 | 
			
		||||
		public function filmTittle($idfilm){
 | 
			
		||||
			$sql = sprintf("SELECT * FROM film JOIN  session ON film.id = session.idfilm WHERE session.idfilm = '%d' ", $idfilm );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error accessing to the film with id '. $idfilm);
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_fetch_array($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}	
 | 
			
		||||
		
 | 
			
		||||
		//Look for a session with the primary key 
 | 
			
		||||
		public function searchSession($cinema, $hall, $startTime, $date){
 | 
			
		||||
			$date = date('Y-m-d', strtotime( $date ) ); 
 | 
			
		||||
			$startTime = date('H:i:s', strtotime( $startTime ) );
 | 
			
		||||
			
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "SELECT * 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 searching for a session');
 | 
			
		||||
			
 | 
			
		||||
			$session = mysqli_fetch_array($resul);
 | 
			
		||||
			
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $session;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		public function searchSessionActivesAtStartTimeAndFilmDuration($cinema, $hall, $startTime, $date, $idfilm){
 | 
			
		||||
			$date = date('Y-m-d', strtotime( $date ) ); 
 | 
			
		||||
			$startTime = date('H:i:s', strtotime( $startTime ) );
 | 
			
		||||
			$sessions = [];
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf("SELECT duration FROM film WHERE id='%s'", $idfilm );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error looking for the film duration of id '. $idfilm);
 | 
			
		||||
			
 | 
			
		||||
			$duration = ($resul->fetch_assoc())["duration"]+10;
 | 
			
		||||
			$endHour = date('H:i:s', strtotime( $startTime . ' +'.$duration.' minute'));
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM session WHERE 
 | 
			
		||||
					idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time BETWEEN '%s' AND '%s' ORDER BY start_time ASC;", 
 | 
			
		||||
					$cinema, $hall, $date, $startTime, $endHour);	
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error looking for sessions between start time and start time + film duration');
 | 
			
		||||
			
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]);
 | 
			
		||||
			}
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
 | 
			
		||||
			return $sessions;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		//Returns a query to get all the session's data.
 | 
			
		||||
		public function getAllSessions($hall, $cinema, $date, $end){
 | 
			
		||||
			if($end){
 | 
			
		||||
 | 
			
		||||
				$sql = sprintf( "SELECT * FROM session WHERE 
 | 
			
		||||
								idcinema = '%s' AND idhall = '%s' AND date BETWEEN '%s' AND '%s' ORDER BY start_time ASC;", 
 | 
			
		||||
								$cinema, $hall, $date, $end);	
 | 
			
		||||
			}else if($date && !$end){
 | 
			
		||||
				$date = date('Y-m-d', strtotime( $date ) ); 
 | 
			
		||||
				
 | 
			
		||||
				$sql = sprintf( "SELECT * FROM session WHERE 
 | 
			
		||||
								idcinema = '%s' AND idhall = '%s' AND date = '%s' ORDER BY start_time ASC;", 
 | 
			
		||||
								$cinema, $hall, $date);	
 | 
			
		||||
			}else{
 | 
			
		||||
				$sql = sprintf( "SELECT * FROM session WHERE 
 | 
			
		||||
								idcinema = '%s' AND idhall = '%s' ORDER BY start_time ASC;", 
 | 
			
		||||
								$cinema, $hall);	
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error geting all sessions');
 | 
			
		||||
			
 | 
			
		||||
			$sessions = null;
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]);
 | 
			
		||||
			}
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $sessions;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Look for a title and cinema
 | 
			
		||||
		public function getSessions_Film_Cinema($idFiml, $idCinema){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM session WHERE session.idfilm = '%d' AND session.idcinema = '%d' ", $idFiml, $idCinema);
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error geting sessions with a idfilm and cinema');
 | 
			
		||||
 | 
			
		||||
			$sessions = null;
 | 
			
		||||
			while($fila = $resul->fetch_assoc()){
 | 
			
		||||
				$sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
 | 
			
		||||
			return $sessions;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Edit a session taking the new film, hall, date, start time, seat price and format with respect to its origin parameter
 | 
			
		||||
        public function editSession($idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $origin){
 | 
			
		||||
			$format = $this->mysqli->real_escape_string($format);
 | 
			
		||||
			$date = date('Y-m-d', strtotime( $date ) ); 
 | 
			
		||||
			$origin["date"] = date('Y-m-d', strtotime( $origin["date"] ) ); 
 | 
			
		||||
			$startTime = date('H:i:s', strtotime( $startTime ) );
 | 
			
		||||
			$origin["start"] = date('H:i:s', strtotime( $origin["start"] ) ); 
 | 
			
		||||
			
 | 
			
		||||
            $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 session.date = '%s' AND start_time = '%s'", 
 | 
			
		||||
                $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $origin["cinema"],$origin["hall"],$origin["date"],$origin["start"]);
 | 
			
		||||
			
 | 
			
		||||
 | 
			
		||||
			mysqli_query($this->mysqli, $sql) or die ('Error editing a session');
 | 
			
		||||
			
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Delete a session whit the primary key
 | 
			
		||||
        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 deleting a session');
 | 
			
		||||
 | 
			
		||||
            return $resul;
 | 
			
		||||
        }
 | 
			
		||||
		
 | 
			
		||||
		//Create a new Session Data Transfer Object.
 | 
			
		||||
		public function loadSession( $id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $seats_full){
 | 
			
		||||
			return new Session( $id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $seats_full);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										35
									
								
								root/assets/php/includes/user.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								root/assets/php/includes/user.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
<?php   
 | 
			
		||||
    class User {
 | 
			
		||||
 | 
			
		||||
        //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.
 | 
			
		||||
 | 
			
		||||
		//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; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										176
									
								
								root/assets/php/includes/user_dao.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										176
									
								
								root/assets/php/includes/user_dao.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,176 @@
 | 
			
		||||
<?php
 | 
			
		||||
	include_once('user.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){
 | 
			
		||||
			/**
 | 
			
		||||
			 *  Por defecto, la función password_hash(), ya genera una contraseña con "SAL", 
 | 
			
		||||
			 * aunque este sería un ejemplo de cómo crear unas opciones mejores que las que vienen por defecto,
 | 
			
		||||
			 * aumentando el coste.
 | 
			
		||||
			 * Más info: https://www.php.net/manual/es/faq.passwords.php#faq.passwords.salt
 | 
			
		||||
			 * */
 | 
			
		||||
			/*
 | 
			
		||||
			$SALAD = [
 | 
			
		||||
				'cost' => 11, //Por defecto password_hash lo pone a 10.
 | 
			
		||||
				'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM), //Hay que tener activado el módulo mcrypt para usar esta función.
 | 
			
		||||
			];
 | 
			
		||||
			*/
 | 
			
		||||
 | 
			
		||||
			$password = password_hash($password, PASSWORD_DEFAULT); //Actualmente en PHP PASSWORD_DEFAULT equivale a PASSWORD_BCRYPT.
 | 
			
		||||
		
 | 
			
		||||
			return $password;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns true if the password and hash match, or false otherwise.
 | 
			
		||||
		public function verifyPass($password, $passwd){
 | 
			
		||||
			return password_verify($password, $passwd);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		//All users
 | 
			
		||||
		public function allUsersNotM(){
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM `users` WHERE users.id NOT IN (SELECT id FROM `manager`)");
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			while($fila=$resul->fetch_assoc()){
 | 
			
		||||
				$users[] = $this->loadUser($fila['id'], $fila['username'], $fila['email'], $fila['passwd'], $fila['rol']);
 | 
			
		||||
			}
 | 
			
		||||
			$resul->free();
 | 
			
		||||
			return $users;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
        //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 ( '%d', '%s', '%s', '%s', '%s')", 
 | 
			
		||||
									$id, $username, $email, $password, $rol );
 | 
			
		||||
			
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql);
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a query to check if the user name exists.
 | 
			
		||||
		public function selectUser($username, $password){
 | 
			
		||||
			$username = $this->mysqli->real_escape_string($username);
 | 
			
		||||
			$password = $this->mysqli->real_escape_string($password);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql);
 | 
			
		||||
 | 
			
		||||
			$user = null;
 | 
			
		||||
			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($resul);
 | 
			
		||||
			//$resul->free();
 | 
			
		||||
 | 
			
		||||
			return $user;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Returns a query to get the user's data.
 | 
			
		||||
		public function userData($id){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM users WHERE id = '%d'", $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Search a user by name.
 | 
			
		||||
		public function selectUserName($username){
 | 
			
		||||
			$username = $this->mysqli->real_escape_string($username);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql);
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Search a user by email.
 | 
			
		||||
		public function selectUserEmail($email){
 | 
			
		||||
			$email = $this->mysqli->real_escape_string($email);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM users WHERE email = '%s'", $email );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql);
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Change username by id.
 | 
			
		||||
		public function changeUserName($id, $username){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
			$username = $this->mysqli->real_escape_string($username);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "UPDATE users SET username = '%s' WHERE id = '%d'", $username, $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Change userpass by id.
 | 
			
		||||
		public function changeUserPass($id, $password){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
			$password = $this->mysqli->real_escape_string($password);
 | 
			
		||||
			$password = $this->encryptPass($password);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "UPDATE users SET passwd = '%s' WHERE id = '%d'", $password, $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Change user email by id.
 | 
			
		||||
		public function changeUserEmail($id, $email){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
			$email = $this->mysqli->real_escape_string($email);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "UPDATE users SET email = '%s' WHERE id = '%d'", $email, $id );
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Delete user account by id.
 | 
			
		||||
		public function deleteUserAccount($id){
 | 
			
		||||
			$id = $this->mysqli->real_escape_string($id);
 | 
			
		||||
 | 
			
		||||
			$sql = sprintf( "DELETE 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 User($id, $username, $email, $password, $rol);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										710
									
								
								root/assets/php/template-FER_SURFACE-2.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										710
									
								
								root/assets/php/template-FER_SURFACE-2.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,710 @@
 | 
			
		||||
<?php
 | 
			
		||||
    class Template {
 | 
			
		||||
 | 
			
		||||
    //Constants:
 | 
			
		||||
    //private const _NUMPAGES = 10; //Constant to page results.
 | 
			
		||||
 | 
			
		||||
    //Attributes:
 | 
			
		||||
    private $page;                  //Page Name.
 | 
			
		||||
    private $prefix;                //Page prefix.
 | 
			
		||||
 | 
			
		||||
    private $session;               //"Iniciar Sesión" (if user isn´t logged in), "Cerrar Sesión" (otherwise).
 | 
			
		||||
    private $session_route;         //"login/" (if user isn´t logged in), "logout/" (otherwise).
 | 
			
		||||
    private $panel;                 //Button to access the user's dashboard (only displayed if logged in).
 | 
			
		||||
    private $user_route;            //Route of the panel (depends on the type of user).
 | 
			
		||||
    private $sessionButtonClass;    //Type of button to login or logout.
 | 
			
		||||
 | 
			
		||||
    //Constructor:
 | 
			
		||||
    function __construct(){
 | 
			
		||||
        $this->page = $_SERVER['PHP_SELF']; //Page that instantiates the template.
 | 
			
		||||
        $this->prefix = '../';              //Default prefix.
 | 
			
		||||
 | 
			
		||||
        $this->set_page_prefix();           //Assigns the name and prefix of the page.
 | 
			
		||||
 | 
			
		||||
        $this->session = 'Iniciar Sesión';  //Default, the session has not started.
 | 
			
		||||
        $this->session_route = 'login/';    //Default, the session has not started.
 | 
			
		||||
        $this->panel = '';                  //Default, the session has not started.
 | 
			
		||||
        $this->user_route = 'panel_user/';  //Default, the type of client is user.
 | 
			
		||||
        $this->sessionButtonClass = '';     //Default, normal button.
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Methods:
 | 
			
		||||
 | 
			
		||||
    //Assigns the name and prefix of the page:
 | 
			
		||||
    private function set_page_prefix() {
 | 
			
		||||
        switch(true){
 | 
			
		||||
            case strpos($this->page, 'panel_user'): $this->page = 'Panel de Usuario'; break;
 | 
			
		||||
            case strpos($this->page, 'panel_manager'): $this->page = 'Panel de Gerente'; break;
 | 
			
		||||
            case strpos($this->page, 'panel_admin'): $this->page = 'Panel de Administrador'; break;
 | 
			
		||||
            case strpos($this->page, 'login'): $this->page = 'Acceso'; break;
 | 
			
		||||
            case strpos($this->page, 'logout'): $this->page = 'Cerrar Sesión'; break;
 | 
			
		||||
            case strpos($this->page, 'register'): $this->page = 'Registro de Usuario'; break;
 | 
			
		||||
            case strpos($this->page, 'showtimes'): $this->page = 'Cartelera'; break;
 | 
			
		||||
            case strpos($this->page, 'purchase'): $this->page = 'Comprar Entrada'; break;
 | 
			
		||||
            case strpos($this->page, 'promotions'): $this->page = 'Promociones'; break;
 | 
			
		||||
            case strpos($this->page, 'cinemas'): $this->page = 'Nuestros Cines'; break;
 | 
			
		||||
            case strpos($this->page, 'about_us'): $this->page = 'Sobre FDI-Cines'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'terms'): $this->page = 'Términos y Condiciones'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'detalles'): $this->page = 'Detalles'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'bocetos'): $this->page = 'Bocetos'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'miembros'): $this->page = 'Miembros'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'planificacion'): $this->page = 'Planificación'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'contacto'): $this->page = 'Contacto'; break;
 | 
			
		||||
            case strpos($this->page, 'assets'): $this->prefix = '../../../'; break;
 | 
			
		||||
            default: $this->page = 'FDI-Cines'; $this->prefix = './'; break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Returns page name:
 | 
			
		||||
    function get_page(){
 | 
			
		||||
        return $this->page;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Returns page prefix:
 | 
			
		||||
    function get_prefix(){
 | 
			
		||||
        return $this->prefix;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic Head:
 | 
			
		||||
    function print_head(){
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
 | 
			
		||||
        if(!isset($_SESSION["css"])) $_SESSION["css"] = "main.css";
 | 
			
		||||
 | 
			
		||||
        $extraCSS = "";
 | 
			
		||||
        if($page === "Comprar Entrada") $extraCSS = "\n<link id='estilo' rel='stylesheet' type='text/css' href='{$prefix}assets/css/seat.css'>";
 | 
			
		||||
 | 
			
		||||
        echo"<head>
 | 
			
		||||
        <title>CompluCine | {$page}</title>
 | 
			
		||||
        <meta charset='utf-8' />
 | 
			
		||||
        <link id='estilo' rel='stylesheet' type='text/css' href='{$prefix}assets/css/{$_SESSION['css']}'>{$extraCSS}
 | 
			
		||||
        <noscript><h1>Esta página requiere JavaScript para su correcto funcionamiento. 
 | 
			
		||||
            Compruebe si JavaScript está deshabilitado en su navegador.</h1></noscript>
 | 
			
		||||
        <meta name='viewport' content='width=device-width, initial-scale=1'>
 | 
			
		||||
        <link rel='icon' href='{$prefix}img/favicon.png' />
 | 
			
		||||
    </head>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic Header:
 | 
			
		||||
    function print_header(){
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
        $session = $this->session;
 | 
			
		||||
        $sessionButtonClass = $this->sessionButtonClass;
 | 
			
		||||
        $session_route = $this->session_route;
 | 
			
		||||
        $user_route = $this->user_route;
 | 
			
		||||
        $panel =$this->panel;
 | 
			
		||||
 | 
			
		||||
        if(isset($_SESSION["rol"])){
 | 
			
		||||
            if($_SESSION["rol"] === "admin") $user_route = 'panel_admin/';
 | 
			
		||||
            else if($_SESSION["rol"] === "manager") $user_route = 'panel_manager/';
 | 
			
		||||
            $panel = "<a href='{$prefix}{$user_route}'><li>Mi Panel</li></a>";
 | 
			
		||||
            $session = 'Cerrar Sesión';
 | 
			
		||||
            $sessionButtonClass = 'danger';
 | 
			
		||||
            $session_route = 'logout/';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(isset($_SESSION["lastRol"]) && ($_SESSION["lastRol"] === "admin" || $_SESSION["lastRol"] === "manager" )){
 | 
			
		||||
            $changeRol = "<a href='{$prefix}assets/php/common/resetRol.php'><li class='danger'>Volver a {$_SESSION["lastRol"]}</li></a>";
 | 
			
		||||
        } else {
 | 
			
		||||
            $changeRol = null;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        echo"<div class='header'>
 | 
			
		||||
            <a href='{$prefix}'><img src='{$prefix}img/favicon2.png' alt='favicon' /> CompluCine</a> | {$page}
 | 
			
		||||
            <div class='menu'>
 | 
			
		||||
                <nav>{$changeRol}
 | 
			
		||||
                    <a href='{$prefix}{$session_route}'><li class={$sessionButtonClass}>{$session}</li></a>
 | 
			
		||||
                    {$panel}
 | 
			
		||||
                    <li>Menú
 | 
			
		||||
                        <ul>
 | 
			
		||||
                            <a href='{$prefix}'><li>Inicio</li></a>
 | 
			
		||||
                            <a href='{$prefix}showtimes/'><li>Cartelera</li></a>
 | 
			
		||||
                            <a href='{$prefix}cinemas/'><li>Nuestros Cines</li></a>
 | 
			
		||||
                            <a href='{$prefix}promotions/'><li>Promociones</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/miembros/'><li>Quiénes somos</li></a>
 | 
			
		||||
                            <a href='{$prefix}contacto/'><li>Contacto</li></a>
 | 
			
		||||
                        </ul>
 | 
			
		||||
                    </li>
 | 
			
		||||
                </nav>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic subHeader:
 | 
			
		||||
    function print_subheader(){
 | 
			
		||||
        //$page = $this->page;
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
 | 
			
		||||
        echo"<div class='header sub'>
 | 
			
		||||
            <div class='menu'>
 | 
			
		||||
                <nav>
 | 
			
		||||
                    <a href='{$prefix}fdicines/about_us/'><li>Sobre FDI-Cines</li></a>
 | 
			
		||||
                    <a href='{$prefix}fdicines/detalles/'><li>Detalles</li></a>
 | 
			
		||||
                    <a href='{$prefix}fdicines/bocetos/'><li>Bocetos</li></a>
 | 
			
		||||
                    <a href='{$prefix}fdicines/miembros/'><li>Miembros</li></a>
 | 
			
		||||
                    <a href='{$prefix}fdicines/planificacion/'><li>Planificación</li></a>
 | 
			
		||||
                </nav>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic Main:
 | 
			
		||||
    function print_main($content = ""){
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
 | 
			
		||||
        /* SubHeader on Main */
 | 
			
		||||
        $sub_header = '';
 | 
			
		||||
        if(strpos($_SERVER['PHP_SELF'], 'fdicines')){
 | 
			
		||||
            $sub_header = "<!-- Sub Header -->
 | 
			
		||||
                <div class='header sub'>
 | 
			
		||||
                    <div class='menu'>
 | 
			
		||||
                        <nav>
 | 
			
		||||
                            <a href='{$prefix}fdicines/about_us/'><li>Sobre FDI-Cines</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/detalles/'><li>Detalles</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/bocetos/'><li>Bocetos</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/miembros/'><li>Miembros</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/planificacion/'><li>Planificación</li></a>
 | 
			
		||||
                        </nav>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </div>\n"; 
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* MAIN */
 | 
			
		||||
        if($prefix === "./"){ 
 | 
			
		||||
            if(isset($_SESSION["nombre"])){
 | 
			
		||||
                $tittle = "<h1>Bienvenido {$_SESSION["nombre"]}</h1>\n";
 | 
			
		||||
            } else {
 | 
			
		||||
                $tittle = "<h1>Bienvenido a CompluCine</h1>\n";
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            $tittle = "<h1>{$page}</h1>\n";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        echo"<main>
 | 
			
		||||
            <div class='image'><a href='{$prefix}'><img src='{$prefix}img/logo_trasparente.png' alt='logo_FDI-Cines' /></a></div>
 | 
			
		||||
            {$sub_header}
 | 
			
		||||
            {$tittle}{$content}
 | 
			
		||||
            <hr />
 | 
			
		||||
        </main>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print panel menu:
 | 
			
		||||
    function print_panelMenu($panel){
 | 
			
		||||
        if($_SESSION["login"]){
 | 
			
		||||
            $prefix = $this->prefix;
 | 
			
		||||
            $menus = array("<a href='./'><li>Panel Principal</li></a>");
 | 
			
		||||
 | 
			
		||||
            switch($panel){
 | 
			
		||||
                case "admin": array_push($menus, "<li>Ver como...
 | 
			
		||||
                                                        <ul>
 | 
			
		||||
                                                            <a href='./?state=un'><li>Usuario</li></a>
 | 
			
		||||
                                                            <a href='./?state=ur'><li>Usuario registrado</li></a>
 | 
			
		||||
                                                            <a href='./?state=ag'><li>Gerente</li></a>
 | 
			
		||||
                                                        </ul>
 | 
			
		||||
                                                    </li>");
 | 
			
		||||
                                array_push($menus, "<li>Modificar
 | 
			
		||||
                                                        <ul>
 | 
			
		||||
                                                            <a href='./?state=mc'><li>Cines</li></a>
 | 
			
		||||
                                                            <a href='./?state=mf'><li>Películas</li></a>
 | 
			
		||||
                                                            <a href='./?state=mp'><li>Promociones</li></a>
 | 
			
		||||
                                                            <a href='./?state=mg'><li>Gerentes</li></a>
 | 
			
		||||
                                                        </ul>
 | 
			
		||||
                                                    </li>");
 | 
			
		||||
                                break;
 | 
			
		||||
 | 
			
		||||
                case "manager": array_push($menus, "<li>Ver como...
 | 
			
		||||
                                                        <ul>
 | 
			
		||||
                                                            <a href='./?state=view_user'><li>Usuario</li></a>
 | 
			
		||||
                                                            <a href='./?state=view_ruser'><li>Usuario registrado</li></a>
 | 
			
		||||
                                                        </ul>
 | 
			
		||||
                                                    </li>");
 | 
			
		||||
                                array_push($menus, "<li>Modificar
 | 
			
		||||
                                                        <ul>
 | 
			
		||||
                                                            <a href='./?state=manage_halls'><li>Salas</li></a>
 | 
			
		||||
                                                            <a href='./?state=manage_sessions'><li>Sesiones</li></a>
 | 
			
		||||
                                                        </ul>
 | 
			
		||||
                                                    </li>");
 | 
			
		||||
                                break;
 | 
			
		||||
 | 
			
		||||
                case "user": array_push($menus, "<a href='./?option=purchases'><li>Historial Compras</li></a>");
 | 
			
		||||
                                //array_push($menus, "<a href='./?option=payment'><li>Datos Pago</li></a>");
 | 
			
		||||
                                    array_push($menus, "<a href='./?option=delete_user'><li>Eliminar Usuario</li></a>");
 | 
			
		||||
                                        break;
 | 
			
		||||
 | 
			
		||||
                default: $menus = array(); break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if($_SESSION["rol"] === $panel){
 | 
			
		||||
                echo"<div class='header sub'>
 | 
			
		||||
                <div class='menu'>
 | 
			
		||||
                    <nav>";
 | 
			
		||||
                    foreach($menus as $value){
 | 
			
		||||
                        echo $value;
 | 
			
		||||
                    }  
 | 
			
		||||
                    echo"</nav>
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
        ";
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print specific page content:
 | 
			
		||||
    function print_section($section){
 | 
			
		||||
        /* Panel menu */
 | 
			
		||||
        $sub_header = '';
 | 
			
		||||
        if(strpos($_SERVER['PHP_SELF'], 'panel')){
 | 
			
		||||
            echo "<!-- Panel Menu -->
 | 
			
		||||
            ";
 | 
			
		||||
            $this->print_panelMenu($_SESSION["rol"]);
 | 
			
		||||
            $this->print_msg();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        echo $section;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print Films Cards:
 | 
			
		||||
    function print_fimls(){
 | 
			
		||||
        $reply = "";
 | 
			
		||||
        //List of the movies:
 | 
			
		||||
        require_once(__DIR__.'/includes/film_dao.php');
 | 
			
		||||
 | 
			
		||||
        $prefix= $this->get_prefix();
 | 
			
		||||
 | 
			
		||||
        $films = new Film_DAO("complucine");
 | 
			
		||||
        $films_array = $films->allFilmData();
 | 
			
		||||
        $ids = array();
 | 
			
		||||
        $tittles = array();
 | 
			
		||||
        $descriptions = array();
 | 
			
		||||
        $times = array();
 | 
			
		||||
        $languages = array();
 | 
			
		||||
        $images = array();
 | 
			
		||||
        if(is_array($films_array)){
 | 
			
		||||
            foreach($films_array as $key => $value){
 | 
			
		||||
                $ids[$key] = $value->getId();
 | 
			
		||||
                $tittles[$key] = $value->getTittle();
 | 
			
		||||
                $descriptions[$key] = $value->getDescription();
 | 
			
		||||
                $times[$key] = $value->getDuration();
 | 
			
		||||
                $languages[$key] = $value->getLanguage();
 | 
			
		||||
                $images[$key] = $value->getImg();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        switch($this->page){
 | 
			
		||||
            case "Cartelera": 
 | 
			
		||||
                if(is_array($films_array)){
 | 
			
		||||
                for($i = 0; $i < count($films_array); $i++){
 | 
			
		||||
                    $tittle = str_replace('_', ' ', $tittles[$i]);
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                    $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$tittles[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <a href='".$prefix."purchase?film=".$ids[$i]."'>
 | 
			
		||||
                                <div class='code showtimes'>
 | 
			
		||||
                                    <div class='image'><img src='".$prefix."img/films/".$images[$i]."' alt='".$tittles[$i]."' /></div>
 | 
			
		||||
                                    <h2>".$tittle."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <div class='blockquote'>
 | 
			
		||||
                                        <p>".$descriptions[$i]."</p>
 | 
			
		||||
                                    </div>
 | 
			
		||||
                                    <li>Duración: ".$times[$i]." minutos</li>
 | 
			
		||||
                                    <li>Lenguaje: ".$languages[$i]."</li>
 | 
			
		||||
                                </div>
 | 
			
		||||
                                </a>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n";
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
            case "Panel de Administrador":
 | 
			
		||||
                $reply .= "<div class='column'>";
 | 
			
		||||
                if(is_array($films_array)){
 | 
			
		||||
                for($i = 0; $i < count($films_array); $i++){
 | 
			
		||||
                    $tittle = str_replace('_', ' ', $tittles[$i]);
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$tittles[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <div class='code showtimes'>
 | 
			
		||||
                                    <div class='image'><img src='".$prefix."img/films/".$images[$i]."' alt='".$tittles[$i]."' /></div>
 | 
			
		||||
                                    <h2>".$tittle."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <form method='post' action='./index.php?state=mf'>
 | 
			
		||||
                                        <input name='id' type='hidden' value='".$ids[$i]."'>
 | 
			
		||||
                                        <input name='tittle' type='hidden' value='".$tittles[$i]."'>
 | 
			
		||||
                                        <input  name='duration' type='hidden' value='".$times[$i]."'>
 | 
			
		||||
                                        <input  name='language' type='hidden' value='".$languages[$i]."'>
 | 
			
		||||
                                        <input name='description' type='hidden' value='".$descriptions[$i]."'>
 | 
			
		||||
                                        <input type='submit' id='submit' value='Editar' name='edit_film' class='primary' />
 | 
			
		||||
                                    </form>
 | 
			
		||||
                                    <form method='post' action='./index.php?state=mf'>
 | 
			
		||||
                                        <input name='id' type='hidden' value='".$ids[$i]."'>
 | 
			
		||||
                                        <input name='tittle' type='hidden' value='".$tittles[$i]."'>
 | 
			
		||||
                                        <input  name='duration' type='hidden' value='".$times[$i]."'>
 | 
			
		||||
                                        <input  name='language' type='hidden' value='".$languages[$i]."'>
 | 
			
		||||
                                        <input name='description' type='hidden' value='".$descriptions[$i]."'>
 | 
			
		||||
                                        <input type='submit' id='submit' value='Eliminar' name='delete_film' class='primary' />
 | 
			
		||||
                                    </form>
 | 
			
		||||
                                </div>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n";                
 | 
			
		||||
                break;
 | 
			
		||||
				
 | 
			
		||||
			case "Panel de Gerente":
 | 
			
		||||
                $reply .= "<div class='column'>";
 | 
			
		||||
                if(is_array($films_array)){
 | 
			
		||||
                for($i = 0; $i < count($films_array); $i++){
 | 
			
		||||
                    $tittle = str_replace('_', ' ', $tittles[$i]);
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$tittles[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <div class='code showtimes'>
 | 
			
		||||
                                    <div class='image'><img src='".$prefix."img/films/".$images[$i]."' alt='".$tittles[$i]."' /></div>
 | 
			
		||||
                                    <h2>".$tittle."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <li>Duración: ".$times[$i]." minutos</li>
 | 
			
		||||
                                    <li>Lenguaje: ".$languages[$i]."</li>
 | 
			
		||||
                                
 | 
			
		||||
								<form method='post' action='./?state=".$_SESSION["option"]."'>
 | 
			
		||||
									<input name='film' type='hidden' value='".$ids[$i]."'>
 | 
			
		||||
									<input name='tittle' type='hidden' value='".$tittles[$i]."'>
 | 
			
		||||
									<input name='duration' type='hidden' value='".$times[$i]."'>
 | 
			
		||||
									<input name='language' type='hidden' value='".$languages[$i]."'>
 | 
			
		||||
									<input name='description' type='hidden' value='".$descriptions[$i]."'>
 | 
			
		||||
									<input name='hall' type='hidden' value='".$_POST["hall"]."'>
 | 
			
		||||
									<input name='date' type='hidden' value='".$_POST["date"]."'>
 | 
			
		||||
									<input name='start' type='hidden' value='".$_POST["start"]."'>	
 | 
			
		||||
									<input name='price' type='hidden' value='".$_POST["price"]."'>
 | 
			
		||||
									<input name='format' type='hidden' value='".$_POST["format"]."'>
 | 
			
		||||
									<input name='or_hall' type='hidden' value='".$_POST["or_hall"]."'>
 | 
			
		||||
									<input name='or_date' type='hidden' value='".$_POST["or_date"]."'>
 | 
			
		||||
									<input name='or_start' type='hidden' value='".$_POST["or_start"]."'>
 | 
			
		||||
									<input type='submit' id='submit' value='Seleccionar' name='select_film' class='primary' />
 | 
			
		||||
								</form>
 | 
			
		||||
								</div>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n"; 
 | 
			
		||||
                break;
 | 
			
		||||
				
 | 
			
		||||
            default: 
 | 
			
		||||
                if(is_array($films_array)){
 | 
			
		||||
                    $reply .='<div class="column left">
 | 
			
		||||
                         <div class="galery">
 | 
			
		||||
                            <h1>Últimos Estrenos</h1><hr />';
 | 
			
		||||
                    $count = 0;
 | 
			
		||||
                    for($i = count($tittles)-4; $i < count($tittles); $i++){
 | 
			
		||||
                        if($count%2===0){
 | 
			
		||||
                            if($count != 0) $reply .= "
 | 
			
		||||
                            </div>";
 | 
			
		||||
                        $reply .= "
 | 
			
		||||
                            <div class='fila'>";
 | 
			
		||||
                        }
 | 
			
		||||
                        $reply .= "
 | 
			
		||||
                                <div class='zoom'>
 | 
			
		||||
                                    <div class='columna'>
 | 
			
		||||
                                        <a href='".$prefix."showtimes/#".$tittles[$i]."'><div class='image'><img src='img/films/".$images[$i]."' alt='".$tittles[$i]."' /></div></a>
 | 
			
		||||
                                    </div>
 | 
			
		||||
                                </div>";
 | 
			
		||||
                        $count++;
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <div class='column right'>
 | 
			
		||||
                        <div class='galery'>";
 | 
			
		||||
                    $count = rand(0, count($tittles)-1);
 | 
			
		||||
                    $title = str_replace('_', ' ', $tittles[$count]); 
 | 
			
		||||
                    $reply .= "
 | 
			
		||||
                            <h1>{$title}</h1><hr />
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <a href='".$prefix."showtimes/#".$tittles[$count]."'><div class='image main'><img src='img/films/".$images[$count]."' alt='".$tittles[$count]."' /></div></a>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>\n";
 | 
			
		||||
                }
 | 
			
		||||
                    break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $reply;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print Cinemas info:
 | 
			
		||||
    function print_cinemas(){
 | 
			
		||||
        $reply = "";
 | 
			
		||||
 | 
			
		||||
        //List of the cinemas:
 | 
			
		||||
        require_once(__DIR__.'/includes/cinema_dao.php');
 | 
			
		||||
 | 
			
		||||
        $prefix= $this->get_prefix();
 | 
			
		||||
 | 
			
		||||
        $cine = new Cinema_DAO("complucine");
 | 
			
		||||
        $cinemas = $cine->allCinemaData();
 | 
			
		||||
        $ids = array();
 | 
			
		||||
        $names = array();
 | 
			
		||||
        $directions = array();
 | 
			
		||||
        $phones = array();
 | 
			
		||||
 | 
			
		||||
        if(!is_array($cinemas)){
 | 
			
		||||
            $reply = "<h2>No hay cines actualmente</h2>";
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
            foreach($cinemas as $key => $value){
 | 
			
		||||
                $ids[$key] = $value->getId();
 | 
			
		||||
                $names[$key] = $value->getName();
 | 
			
		||||
                $directions[$key] = $value->getDirection();
 | 
			
		||||
                $phones[$key] = $value->getPhone();
 | 
			
		||||
            }
 | 
			
		||||
        
 | 
			
		||||
        switch($this->page){
 | 
			
		||||
            case "Nuestros Cines":
 | 
			
		||||
 | 
			
		||||
                for($i = 0; $i < count($cinemas); $i++){
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                    $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$names[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <a href='".$prefix."purchase?cinema=".$ids[$i]."'>
 | 
			
		||||
                                <div class='code cinemas'>
 | 
			
		||||
                                    <h2>".$names[$i]."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <li>Dirección: ".$directions[$i]."</li>
 | 
			
		||||
                                    <li>Teléfono: ".$phones[$i]."</li>
 | 
			
		||||
                                </div>
 | 
			
		||||
                                </a>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n";
 | 
			
		||||
                break;
 | 
			
		||||
            case "Panel de Administrador":
 | 
			
		||||
                    $reply .= "<div class='row'>
 | 
			
		||||
                            <ul class='tablelist col6'> 
 | 
			
		||||
                                <li class='title'>Id</li>
 | 
			
		||||
                                <li class='title'>Nombre</li>
 | 
			
		||||
                                <li class='title'>Dirección</li>
 | 
			
		||||
                                <li class='title'>Teléfono</li>
 | 
			
		||||
                                <li class='title'>Editar</li>
 | 
			
		||||
                                <li class='title'>Eliminar</li>
 | 
			
		||||
                            ";
 | 
			
		||||
                        $parity = "odd";
 | 
			
		||||
                        for($i = 0; $i < count($cinemas); $i++){
 | 
			
		||||
                            $reply .= '
 | 
			
		||||
                                    <div class="'.$parity.'">
 | 
			
		||||
                                    <a class="h2long" href="index.php?state=mc&cinema='.$ids[$i].'">
 | 
			
		||||
                                        <li>'. $ids[$i] .'</li>
 | 
			
		||||
                                        <li>'. $names[$i] .'</li>
 | 
			
		||||
                                        <li>'. $directions[$i] .'</li>
 | 
			
		||||
                                        <li>'. $phones[$i] .'</li>
 | 
			
		||||
                                    </a>
 | 
			
		||||
                                        <li>
 | 
			
		||||
                                            <form method="post" action="index.php?state=mc">
 | 
			
		||||
                                                <input  name="id" type="hidden" value="'.$ids[$i].'">
 | 
			
		||||
                                                <input  name="name" type="hidden" value="'.$names[$i].'">
 | 
			
		||||
                                                <input  name="direction" type="hidden" value="'.$directions[$i].'">
 | 
			
		||||
                                                <input  name="phone" type="hidden" value="'.$phones[$i].'">
 | 
			
		||||
                                                <input type="submit" id="submit" value="Editar" name="edit_cinema" class="primary" />
 | 
			
		||||
                                            </form> 
 | 
			
		||||
                                        </li> 
 | 
			
		||||
                                        <li> 
 | 
			
		||||
                                            <form method="post" action="index.php?state=mc">
 | 
			
		||||
                                                <input  name="id" type="hidden" value="'.$ids[$i].'">
 | 
			
		||||
                                                <input  name="name" type="hidden" value="'.$names[$i].'">
 | 
			
		||||
                                                <input  name="direction" type="hidden" value="'.$directions[$i].'">
 | 
			
		||||
                                                <input  name="phone" type="hidden" value="'.$phones[$i].'">
 | 
			
		||||
                                                <input type="submit" id="submit" value="Eliminar" name="delete_cinema" class="primary" />
 | 
			
		||||
                                            </form> 
 | 
			
		||||
                                        </li> 
 | 
			
		||||
                                </div>
 | 
			
		||||
                                '; 
 | 
			
		||||
                                $parity = ($parity == "odd") ? "even" : "odd";
 | 
			
		||||
                        } 
 | 
			
		||||
                    $reply .=' </div>';
 | 
			
		||||
                break;
 | 
			
		||||
            
 | 
			
		||||
            default:
 | 
			
		||||
                break;
 | 
			
		||||
         }
 | 
			
		||||
        }
 | 
			
		||||
        return $reply;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function print_promotions(){
 | 
			
		||||
        $reply = "";
 | 
			
		||||
 | 
			
		||||
        //List of the cinemas:
 | 
			
		||||
        require_once(__DIR__.'/includes/promotion_dao.php');
 | 
			
		||||
 | 
			
		||||
        $prefix= $this->get_prefix();
 | 
			
		||||
 | 
			
		||||
        $promotion = new Promotion_DAO("complucine");
 | 
			
		||||
        $promotions = $promotion->allPromotionData();
 | 
			
		||||
        $ids = array();
 | 
			
		||||
        $tittles = array();
 | 
			
		||||
        $descriptions = array();
 | 
			
		||||
        $codes = array();
 | 
			
		||||
        $isActive = array();
 | 
			
		||||
 | 
			
		||||
        if(is_array($promotions)){
 | 
			
		||||
            foreach($promotions as $key => $value){
 | 
			
		||||
                $ids[$key] = $value->getId();
 | 
			
		||||
                $tittles[$key] = $value->getTittle();
 | 
			
		||||
                $descriptions[$key] = $value->getDescription();
 | 
			
		||||
                $codes[$key] = $value->getCode();
 | 
			
		||||
                if($value->getActive()){
 | 
			
		||||
                    $isActives[$key] = "ACTIVA";
 | 
			
		||||
                } else {
 | 
			
		||||
                    $isActives[$key] = "CADUCADA";
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        switch($this->page){
 | 
			
		||||
            case "Promociones":
 | 
			
		||||
                for($i = 0; $i < count($promotions); $i++){
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                    $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$tittles[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <div class='code promo'>
 | 
			
		||||
                                    <div class='image'><img src='".$prefix."img/promos/".str_replace(' ', '_', strtolower($tittles[$i])).".jpg' alt='".$tittles[$i]."' /></div>
 | 
			
		||||
                                    <h2>".$tittles[$i]."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <div class='blockquote'>
 | 
			
		||||
                                        <p>".$descriptions[$i]."</p>
 | 
			
		||||
                                    </div>
 | 
			
		||||
                                    <li>Código: ".$codes[$i]."</li>
 | 
			
		||||
                                    <li>Estado: ".$isActives[$i]."</li>
 | 
			
		||||
                                </div>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n";
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $reply;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print session MSG:
 | 
			
		||||
    function print_msg() {
 | 
			
		||||
        if(isset($_SESSION['message'])){
 | 
			
		||||
            echo "<div>".$_SESSION['message']."</div>";
 | 
			
		||||
            unset($_SESSION['message']);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic Footer:
 | 
			
		||||
    function print_footer(){
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
        
 | 
			
		||||
        if(!isset($_SESSION["css"]) || $_SESSION["css"] === "main.css"){
 | 
			
		||||
            $css = "{$prefix}assets/css/highContrast.css";
 | 
			
		||||
            $nameCSS = "Alto Contraste";
 | 
			
		||||
        } else {
 | 
			
		||||
            $css = "{$prefix}assets/css/main.css";
 | 
			
		||||
            $nameCSS = "Contraste Normal";
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        echo"<footer>
 | 
			
		||||
            <div class='footer'>
 | 
			
		||||
                <p>© Práctica Final | Sistemas Web 2021 </p>
 | 
			
		||||
            </div>
 | 
			
		||||
            <span class='go-up'>🔝</span>
 | 
			
		||||
            <a href='{$prefix}fdicines/about_us/'>Sobre FDI-Cines</a> |
 | 
			
		||||
            <a href='{$prefix}fdicines/terms_conditions/'>Términos de uso</a> |
 | 
			
		||||
            <a href='{$prefix}cinemas/'>Nuestros cines</a> |
 | 
			
		||||
            <a href='{$prefix}contacto/'>Contacto</a> |
 | 
			
		||||
            <button id='cssChange' onclick=\"cambiarCSS('$css');\">$nameCSS</button>
 | 
			
		||||
        </footer>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print JS scripts:
 | 
			
		||||
    function print_scripts(){
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
 | 
			
		||||
        echo"<script type='text/javascript' src='{$prefix}assets/js/jquery-3.2.1.min.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/cambiarCSS.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/checkForms.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/goUp.js'></script>
 | 
			
		||||
        ";
 | 
			
		||||
        if($page === "FDI-Cines") echo"<script type='text/javascript' src='{$prefix}assets/js/promotions.js'></script>\n";
 | 
			
		||||
        if($page === "Panel de Usuario") echo"<script type='text/javascript' src='{$prefix}assets/js/deleteConfirm.js'></script>\n";
 | 
			
		||||
        if($page === "Comprar Entrada") echo"<script type='text/javascript' src='{$prefix}assets/js/selectTicket.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/checkPay.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/goBack.js'></script>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										706
									
								
								root/assets/php/template-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										706
									
								
								root/assets/php/template-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,706 @@
 | 
			
		||||
<?php
 | 
			
		||||
    class Template {
 | 
			
		||||
 | 
			
		||||
    //Constants:
 | 
			
		||||
    //private const _NUMPAGES = 10; //Constant to page results.
 | 
			
		||||
 | 
			
		||||
    //Attributes:
 | 
			
		||||
    private $page;                  //Page Name.
 | 
			
		||||
    private $prefix;                //Page prefix.
 | 
			
		||||
 | 
			
		||||
    private $session;               //"Iniciar Sesión" (if user isn´t logged in), "Cerrar Sesión" (otherwise).
 | 
			
		||||
    private $session_route;         //"login/" (if user isn´t logged in), "logout/" (otherwise).
 | 
			
		||||
    private $panel;                 //Button to access the user's dashboard (only displayed if logged in).
 | 
			
		||||
    private $user_route;            //Route of the panel (depends on the type of user).
 | 
			
		||||
    private $sessionButtonClass;    //Type of button to login or logout.
 | 
			
		||||
 | 
			
		||||
    //Constructor:
 | 
			
		||||
    function __construct(){
 | 
			
		||||
        $this->page = $_SERVER['PHP_SELF']; //Page that instantiates the template.
 | 
			
		||||
        $this->prefix = '../';              //Default prefix.
 | 
			
		||||
 | 
			
		||||
        $this->set_page_prefix();           //Assigns the name and prefix of the page.
 | 
			
		||||
 | 
			
		||||
        $this->session = 'Iniciar Sesión';  //Default, the session has not started.
 | 
			
		||||
        $this->session_route = 'login/';    //Default, the session has not started.
 | 
			
		||||
        $this->panel = '';                  //Default, the session has not started.
 | 
			
		||||
        $this->user_route = 'panel_user/';  //Default, the type of client is user.
 | 
			
		||||
        $this->sessionButtonClass = '';     //Default, normal button.
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Methods:
 | 
			
		||||
 | 
			
		||||
    //Assigns the name and prefix of the page:
 | 
			
		||||
    private function set_page_prefix() {
 | 
			
		||||
        switch(true){
 | 
			
		||||
            case strpos($this->page, 'panel_user'): $this->page = 'Panel de Usuario'; break;
 | 
			
		||||
            case strpos($this->page, 'panel_manager'): $this->page = 'Panel de Gerente'; break;
 | 
			
		||||
            case strpos($this->page, 'panel_admin'): $this->page = 'Panel de Administrador'; break;
 | 
			
		||||
            case strpos($this->page, 'login'): $this->page = 'Acceso'; break;
 | 
			
		||||
            case strpos($this->page, 'logout'): $this->page = 'Cerrar Sesión'; break;
 | 
			
		||||
            case strpos($this->page, 'register'): $this->page = 'Registro de Usuario'; break;
 | 
			
		||||
            case strpos($this->page, 'showtimes'): $this->page = 'Cartelera'; break;
 | 
			
		||||
            case strpos($this->page, 'purchase'): $this->page = 'Comprar Entrada'; break;
 | 
			
		||||
            case strpos($this->page, 'promotions'): $this->page = 'Promociones'; break;
 | 
			
		||||
            case strpos($this->page, 'cinemas'): $this->page = 'Nuestros Cines'; break;
 | 
			
		||||
            case strpos($this->page, 'about_us'): $this->page = 'Sobre FDI-Cines'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'terms'): $this->page = 'Términos y Condiciones'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'detalles'): $this->page = 'Detalles'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'bocetos'): $this->page = 'Bocetos'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'miembros'): $this->page = 'Miembros'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'planificacion'): $this->page = 'Planificación'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'contacto'): $this->page = 'Contacto'; break;
 | 
			
		||||
            case strpos($this->page, 'assets'): $this->prefix = '../../../'; break;
 | 
			
		||||
            default: $this->page = 'FDI-Cines'; $this->prefix = './'; break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Returns page name:
 | 
			
		||||
    function get_page(){
 | 
			
		||||
        return $this->page;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Returns page prefix:
 | 
			
		||||
    function get_prefix(){
 | 
			
		||||
        return $this->prefix;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic Head:
 | 
			
		||||
    function print_head(){
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
 | 
			
		||||
        echo"<head>
 | 
			
		||||
        <title>CompluCine | {$page}</title>
 | 
			
		||||
        <meta charset='utf-8' />
 | 
			
		||||
        <link id='estilo' rel='stylesheet' type='text/css' href='{$prefix}assets/css/main.css'>
 | 
			
		||||
        <noscript><h1>Esta página requiere JavaScript para su correcto funcionamiento. 
 | 
			
		||||
            Compruebe si JavaScript está deshabilitado en su navegador.</h1></noscript>
 | 
			
		||||
        <meta name='viewport' content='width=device-width, initial-scale=1'>
 | 
			
		||||
        <link rel='icon' href='{$prefix}img/favicon.png' />
 | 
			
		||||
    </head>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic Header:
 | 
			
		||||
    function print_header(){
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
        $session = $this->session;
 | 
			
		||||
        $sessionButtonClass = $this->sessionButtonClass;
 | 
			
		||||
        $session_route = $this->session_route;
 | 
			
		||||
        $user_route = $this->user_route;
 | 
			
		||||
        $panel =$this->panel;
 | 
			
		||||
 | 
			
		||||
        if(isset($_SESSION["rol"])){
 | 
			
		||||
            if($_SESSION["rol"] === "admin") $user_route = 'panel_admin/';
 | 
			
		||||
            else if($_SESSION["rol"] === "manager") $user_route = 'panel_manager/';
 | 
			
		||||
            $panel = "<a href='{$prefix}{$user_route}'><li>Mi Panel</li></a>";
 | 
			
		||||
            $session = 'Cerrar Sesión';
 | 
			
		||||
            $sessionButtonClass = 'danger';
 | 
			
		||||
            $session_route = 'logout/';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(isset($_SESSION["lastRol"]) && ($_SESSION["lastRol"] === "admin" || $_SESSION["lastRol"] === "manager" )){
 | 
			
		||||
            $changeRol = "<a href='{$prefix}assets/php/common/resetRol.php'><li class='danger'>Volver a {$_SESSION["lastRol"]}</li></a>";
 | 
			
		||||
        } else {
 | 
			
		||||
            $changeRol = null;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        echo"<div class='header'>
 | 
			
		||||
            <a href='{$prefix}'><img src='{$prefix}img/favicon2.png' alt='favicon' /> CompluCine</a> | {$page}
 | 
			
		||||
            <div class='menu'>
 | 
			
		||||
                <nav>{$changeRol}
 | 
			
		||||
                    <a href='{$prefix}{$session_route}'><li class={$sessionButtonClass}>{$session}</li></a>
 | 
			
		||||
                    {$panel}
 | 
			
		||||
                    <li>Menú
 | 
			
		||||
                        <ul>
 | 
			
		||||
                            <a href='{$prefix}'><li>Inicio</li></a>
 | 
			
		||||
                            <a href='{$prefix}showtimes/'><li>Cartelera</li></a>
 | 
			
		||||
                            <a href='{$prefix}promotions/'><li>Promociones</li></a>
 | 
			
		||||
                            <a href='{$prefix}cinemas/'><li>Nuestros Cines</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/miembros/'><li>Quiénes somos</li></a>
 | 
			
		||||
                            <a href='{$prefix}contacto/'><li>Contacto</li></a>
 | 
			
		||||
                        </ul>
 | 
			
		||||
                    </li>
 | 
			
		||||
                </nav>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic subHeader:
 | 
			
		||||
    function print_subheader(){
 | 
			
		||||
        //$page = $this->page;
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
 | 
			
		||||
        echo"<div class='header sub'>
 | 
			
		||||
            <div class='menu'>
 | 
			
		||||
                <nav>
 | 
			
		||||
                    <a href='{$prefix}fdicines/about_us/'><li>Sobre FDI-Cines</li></a>
 | 
			
		||||
                    <a href='{$prefix}fdicines/detalles/'><li>Detalles</li></a>
 | 
			
		||||
                    <a href='{$prefix}fdicines/bocetos/'><li>Bocetos</li></a>
 | 
			
		||||
                    <a href='{$prefix}fdicines/miembros/'><li>Miembros</li></a>
 | 
			
		||||
                    <a href='{$prefix}fdicines/planificacion/'><li>Planificación</li></a>
 | 
			
		||||
                </nav>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic Main:
 | 
			
		||||
    function print_main($content = ""){
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
 | 
			
		||||
        /* SubHeader on Main */
 | 
			
		||||
        $sub_header = '';
 | 
			
		||||
        if(strpos($_SERVER['PHP_SELF'], 'fdicines')){
 | 
			
		||||
            $sub_header = "<!-- Sub Header -->
 | 
			
		||||
                <div class='header sub'>
 | 
			
		||||
                    <div class='menu'>
 | 
			
		||||
                        <nav>
 | 
			
		||||
                            <a href='{$prefix}fdicines/about_us/'><li>Sobre FDI-Cines</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/detalles/'><li>Detalles</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/bocetos/'><li>Bocetos</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/miembros/'><li>Miembros</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/planificacion/'><li>Planificación</li></a>
 | 
			
		||||
                        </nav>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </div>\n"; 
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* MAIN */
 | 
			
		||||
        if($prefix === "./"){ 
 | 
			
		||||
            if(isset($_SESSION["nombre"])){
 | 
			
		||||
                $tittle = "<h1>Bienvenido {$_SESSION["nombre"]}</h1>\n";
 | 
			
		||||
            } else {
 | 
			
		||||
                $tittle = "<h1>Bienvenido a CompluCine</h1>\n";
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            $tittle = "<h1>{$page}</h1>\n";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        echo"<main>
 | 
			
		||||
            <div class='image'><a href='{$prefix}'><img src='{$prefix}img/logo_trasparente.png' alt='logo_FDI-Cines' /></a></div>
 | 
			
		||||
            {$sub_header}
 | 
			
		||||
            {$tittle}{$content}
 | 
			
		||||
            <hr />
 | 
			
		||||
        </main>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print panel menu:
 | 
			
		||||
    function print_panelMenu($panel){
 | 
			
		||||
        if($_SESSION["login"]){
 | 
			
		||||
            $prefix = $this->prefix;
 | 
			
		||||
            $menus = array("<a href='./'><li>Panel Principal</li></a>");
 | 
			
		||||
 | 
			
		||||
            switch($panel){
 | 
			
		||||
                case "admin": array_push($menus, "<li>Ver como...
 | 
			
		||||
                                                        <ul>
 | 
			
		||||
                                                            <a href='./?state=un'><li>Usuario</li></a>
 | 
			
		||||
                                                            <a href='./?state=ur'><li>Usuario registrado</li></a>
 | 
			
		||||
                                                            <a href='./?state=ag'><li>Gerente</li></a>
 | 
			
		||||
                                                        </ul>
 | 
			
		||||
                                                    </li>");
 | 
			
		||||
                                array_push($menus, "<li>Modificar
 | 
			
		||||
                                                        <ul>
 | 
			
		||||
                                                            <a href='./?state=mc'><li>Cines</li></a>
 | 
			
		||||
                                                            <a href='./?state=mf'><li>Películas</li></a>
 | 
			
		||||
                                                            <a href='./?state=mp'><li>Promociones</li></a>
 | 
			
		||||
                                                            <a href='./?state=mg'><li>Gerentes</li></a>
 | 
			
		||||
                                                        </ul>
 | 
			
		||||
                                                    </li>");
 | 
			
		||||
                                break;
 | 
			
		||||
 | 
			
		||||
                case "manager": array_push($menus, "<li>Ver como...
 | 
			
		||||
                                                        <ul>
 | 
			
		||||
                                                            <a href='./?state=view_user'><li>Usuario</li></a>
 | 
			
		||||
                                                            <a href='./?state=view_ruser'><li>Usuario registrado</li></a>
 | 
			
		||||
                                                        </ul>
 | 
			
		||||
                                                    </li>");
 | 
			
		||||
                                array_push($menus, "<li>Modificar
 | 
			
		||||
                                                        <ul>
 | 
			
		||||
                                                            <a href='./?state=manage_halls'><li>Salas</li></a>
 | 
			
		||||
                                                            <a href='./?state=manage_sessions'><li>Sesiones</li></a>
 | 
			
		||||
                                                        </ul>
 | 
			
		||||
                                                    </li>");
 | 
			
		||||
                                break;
 | 
			
		||||
 | 
			
		||||
                case "user": array_push($menus, "<a href='./?option=purchases'><li>Historial Compras</li></a>");
 | 
			
		||||
                                array_push($menus, "<a href='./?option=payment'><li>Datos Pago</li></a>");
 | 
			
		||||
                                    array_push($menus, "<a href='./?option=delete_user'><li>Eliminar Usuario</li></a>");
 | 
			
		||||
                                        break;
 | 
			
		||||
 | 
			
		||||
                default: $menus = array(); break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if($_SESSION["rol"] === $panel){
 | 
			
		||||
                echo"<div class='header sub'>
 | 
			
		||||
                <div class='menu'>
 | 
			
		||||
                    <nav>";
 | 
			
		||||
                    foreach($menus as $value){
 | 
			
		||||
                        echo $value;
 | 
			
		||||
                    }  
 | 
			
		||||
                    echo"</nav>
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
        ";
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print specific page content:
 | 
			
		||||
    function print_section($section){
 | 
			
		||||
        /* Panel menu */
 | 
			
		||||
        $sub_header = '';
 | 
			
		||||
        if(strpos($_SERVER['PHP_SELF'], 'panel')){
 | 
			
		||||
            echo "<!-- Panel Menu -->
 | 
			
		||||
            ";
 | 
			
		||||
            $this->print_panelMenu($_SESSION["rol"]);
 | 
			
		||||
            $this->print_msg();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        echo $section;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print Films Cards:
 | 
			
		||||
    function print_fimls(){
 | 
			
		||||
        $reply = "";
 | 
			
		||||
        //List of the movies:
 | 
			
		||||
        require_once(__DIR__.'/includes/film_dao.php');
 | 
			
		||||
 | 
			
		||||
        $prefix= $this->get_prefix();
 | 
			
		||||
 | 
			
		||||
        $films = new Film_DAO("complucine");
 | 
			
		||||
        $films_array = $films->allFilmData();
 | 
			
		||||
        $ids = array();
 | 
			
		||||
        $tittles = array();
 | 
			
		||||
        $descriptions = array();
 | 
			
		||||
        $times = array();
 | 
			
		||||
        $languages = array();
 | 
			
		||||
        $images = array();
 | 
			
		||||
        if(is_array($films_array)){
 | 
			
		||||
            foreach($films_array as $key => $value){
 | 
			
		||||
                $ids[$key] = $value->getId();
 | 
			
		||||
                $tittles[$key] = $value->getTittle();
 | 
			
		||||
                $descriptions[$key] = $value->getDescription();
 | 
			
		||||
                $times[$key] = $value->getDuration();
 | 
			
		||||
                $languages[$key] = $value->getLanguage();
 | 
			
		||||
                $images[$key] = $value->getImg();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        switch($this->page){
 | 
			
		||||
            case "Cartelera": 
 | 
			
		||||
                if(is_array($films_array)){
 | 
			
		||||
                for($i = 0; $i < count($films_array); $i++){
 | 
			
		||||
                    $tittle = str_replace('_', ' ', $tittles[$i]);
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                    $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$tittles[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <a href='".$prefix."purchase?film=".$ids[$i]."'>
 | 
			
		||||
                                <div class='code showtimes'>
 | 
			
		||||
                                    <div class='image'><img src='".$prefix."img/films/".$images[$i]."' alt='".$tittles[$i]."' /></div>
 | 
			
		||||
                                    <h2>".$tittle."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <div class='blockquote'>
 | 
			
		||||
                                        <p>".$descriptions[$i]."</p>
 | 
			
		||||
                                    </div>
 | 
			
		||||
                                    <li>Duración: ".$times[$i]." minutos</li>
 | 
			
		||||
                                    <li>Lenguaje: ".$languages[$i]."</li>
 | 
			
		||||
                                </div>
 | 
			
		||||
                                </a>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n";
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
            case "Panel de Administrador":
 | 
			
		||||
                $reply .= "<div class='column'>";
 | 
			
		||||
                if(is_array($films_array)){
 | 
			
		||||
                for($i = 0; $i < count($films_array); $i++){
 | 
			
		||||
                    $tittle = str_replace('_', ' ', $tittles[$i]);
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$tittles[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <div class='code showtimes'>
 | 
			
		||||
                                    <div class='image'><img src='".$prefix."img/films/".$images[$i]."' alt='".$tittles[$i]."' /></div>
 | 
			
		||||
                                    <h2>".$tittle."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <form method='post' action='./index.php?state=mf'>
 | 
			
		||||
                                        <input name='id' type='hidden' value='".$ids[$i]."'>
 | 
			
		||||
                                        <input name='tittle' type='hidden' value='".$tittles[$i]."'>
 | 
			
		||||
                                        <input  name='duration' type='hidden' value='".$times[$i]."'>
 | 
			
		||||
                                        <input  name='language' type='hidden' value='".$languages[$i]."'>
 | 
			
		||||
                                        <input name='description' type='hidden' value='".$descriptions[$i]."'>
 | 
			
		||||
                                        <input type='submit' id='submit' value='Editar' name='edit_film' class='primary' />
 | 
			
		||||
                                    </form>
 | 
			
		||||
                                    <form method='post' action='./index.php?state=mf'>
 | 
			
		||||
                                        <input name='id' type='hidden' value='".$ids[$i]."'>
 | 
			
		||||
                                        <input name='tittle' type='hidden' value='".$tittles[$i]."'>
 | 
			
		||||
                                        <input  name='duration' type='hidden' value='".$times[$i]."'>
 | 
			
		||||
                                        <input  name='language' type='hidden' value='".$languages[$i]."'>
 | 
			
		||||
                                        <input name='description' type='hidden' value='".$descriptions[$i]."'>
 | 
			
		||||
                                        <input type='submit' id='submit' value='Eliminar' name='delete_film' class='primary' />
 | 
			
		||||
                                    </form>
 | 
			
		||||
                                </div>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n";                
 | 
			
		||||
                break;
 | 
			
		||||
				
 | 
			
		||||
			case "Panel de Gerente":
 | 
			
		||||
                $reply .= "<div class='column'>";
 | 
			
		||||
                if(is_array($films_array)){
 | 
			
		||||
                for($i = 0; $i < count($films_array); $i++){
 | 
			
		||||
                    $tittle = str_replace('_', ' ', $tittles[$i]);
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$tittles[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <div class='code showtimes'>
 | 
			
		||||
                                    <div class='image'><img src='".$prefix."img/films/".$images[$i]."' alt='".$tittles[$i]."' /></div>
 | 
			
		||||
                                    <h2>".$tittle."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <li>Duración: ".$times[$i]." minutos</li>
 | 
			
		||||
                                    <li>Lenguaje: ".$languages[$i]."</li>
 | 
			
		||||
                                
 | 
			
		||||
								<form method='post' action='./?state=".$_SESSION["option"]."'>
 | 
			
		||||
									<input name='film' type='hidden' value='".$ids[$i]."'>
 | 
			
		||||
									<input name='tittle' type='hidden' value='".$tittles[$i]."'>
 | 
			
		||||
									<input name='duration' type='hidden' value='".$times[$i]."'>
 | 
			
		||||
									<input name='language' type='hidden' value='".$languages[$i]."'>
 | 
			
		||||
									<input name='description' type='hidden' value='".$descriptions[$i]."'>
 | 
			
		||||
									<input name='hall' type='hidden' value='".$_POST["hall"]."'>
 | 
			
		||||
									<input name='date' type='hidden' value='".$_POST["date"]."'>
 | 
			
		||||
									<input name='start' type='hidden' value='".$_POST["start"]."'>	
 | 
			
		||||
									<input name='price' type='hidden' value='".$_POST["price"]."'>
 | 
			
		||||
									<input name='format' type='hidden' value='".$_POST["format"]."'>
 | 
			
		||||
									<input name='or_hall' type='hidden' value='".$_POST["or_hall"]."'>
 | 
			
		||||
									<input name='or_date' type='hidden' value='".$_POST["or_date"]."'>
 | 
			
		||||
									<input name='or_start' type='hidden' value='".$_POST["or_start"]."'>
 | 
			
		||||
									<input type='submit' id='submit' value='Seleccionar' name='select_film' class='primary' />
 | 
			
		||||
								</form>
 | 
			
		||||
								</div>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n"; 
 | 
			
		||||
                break;
 | 
			
		||||
				
 | 
			
		||||
            default: 
 | 
			
		||||
                if(is_array($films_array)){
 | 
			
		||||
                    $reply .='<div class="column left">
 | 
			
		||||
                         <div class="galery">
 | 
			
		||||
                            <h1>Últimos Estrenos</h1><hr />';
 | 
			
		||||
                    $count = 0;
 | 
			
		||||
                    for($i = count($tittles)-4; $i < count($tittles); $i++){
 | 
			
		||||
                        if($count%2===0){
 | 
			
		||||
                            if($count != 0) $reply .= "
 | 
			
		||||
                            </div>";
 | 
			
		||||
                        $reply .= "
 | 
			
		||||
                            <div class='fila'>";
 | 
			
		||||
                        }
 | 
			
		||||
                        $reply .= "
 | 
			
		||||
                                <div class='zoom'>
 | 
			
		||||
                                    <div class='columna'>
 | 
			
		||||
                                        <a href='".$prefix."showtimes/#".$tittles[$i]."'><div class='image'><img src='img/films/".$images[$i]."' alt='".$tittles[$i]."' /></div></a>
 | 
			
		||||
                                    </div>
 | 
			
		||||
                                </div>";
 | 
			
		||||
                        $count++;
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <div class='column right'>
 | 
			
		||||
                        <div class='galery'>";
 | 
			
		||||
                    $count = rand(0, count($tittles)-1);
 | 
			
		||||
                    $title = str_replace('_', ' ', $tittles[$count]); 
 | 
			
		||||
                    $reply .= "
 | 
			
		||||
                            <h1>{$title}</h1><hr />
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <a href='".$prefix."showtimes/#".$tittles[$count]."'><div class='image main'><img src='img/films/".$images[$count]."' alt='".$tittles[$count]."' /></div></a>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>\n";
 | 
			
		||||
                }
 | 
			
		||||
                    break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $reply;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print Cinemas info:
 | 
			
		||||
    function print_cinemas(){
 | 
			
		||||
        $reply = "";
 | 
			
		||||
 | 
			
		||||
        //List of the cinemas:
 | 
			
		||||
        require_once(__DIR__.'/includes/cinema_dao.php');
 | 
			
		||||
 | 
			
		||||
        $prefix= $this->get_prefix();
 | 
			
		||||
 | 
			
		||||
        $cine = new Cinema_DAO("complucine");
 | 
			
		||||
        $cinemas = $cine->allCinemaData();
 | 
			
		||||
        $ids = array();
 | 
			
		||||
        $names = array();
 | 
			
		||||
        $directions = array();
 | 
			
		||||
        $phones = array();
 | 
			
		||||
 | 
			
		||||
        if(!is_array($cinemas)){
 | 
			
		||||
            $reply = "<h2>No hay cines actualmente</h2>";
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
            foreach($cinemas as $key => $value){
 | 
			
		||||
                $ids[$key] = $value->getId();
 | 
			
		||||
                $names[$key] = $value->getName();
 | 
			
		||||
                $directions[$key] = $value->getDirection();
 | 
			
		||||
                $phones[$key] = $value->getPhone();
 | 
			
		||||
            }
 | 
			
		||||
        
 | 
			
		||||
        switch($this->page){
 | 
			
		||||
            case "Nuestros Cines":
 | 
			
		||||
 | 
			
		||||
                for($i = 0; $i < count($cinemas); $i++){
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                    $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$names[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <a href='".$prefix."purchase?cinema=".$ids[$i]."'>
 | 
			
		||||
                                <div class='code cinemas'>
 | 
			
		||||
                                    <h2>".$names[$i]."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <li>Dirección: ".$directions[$i]."</li>
 | 
			
		||||
                                    <li>Teléfono: ".$phones[$i]."</li>
 | 
			
		||||
                                </div>
 | 
			
		||||
                                </a>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n";
 | 
			
		||||
                break;
 | 
			
		||||
            case "Panel de Administrador":
 | 
			
		||||
                    $reply .= "<div class='row'>
 | 
			
		||||
                            <ul class='tablelist col6'> 
 | 
			
		||||
                                <li class='title'>Id</li>
 | 
			
		||||
                                <li class='title'>Nombre</li>
 | 
			
		||||
                                <li class='title'>Dirección</li>
 | 
			
		||||
                                <li class='title'>Teléfono</li>
 | 
			
		||||
                                <li class='title'>Editar</li>
 | 
			
		||||
                                <li class='title'>Eliminar</li>
 | 
			
		||||
                            ";
 | 
			
		||||
                        $parity = "odd";
 | 
			
		||||
                        for($i = 0; $i < count($cinemas); $i++){
 | 
			
		||||
                            $reply .= '
 | 
			
		||||
                                    <div class="'.$parity.'">
 | 
			
		||||
                                    <a class="h2long" href="index.php?state=mc&cinema='.$ids[$i].'">
 | 
			
		||||
                                        <li>'. $ids[$i] .'</li>
 | 
			
		||||
                                        <li>'. $names[$i] .'</li>
 | 
			
		||||
                                        <li>'. $directions[$i] .'</li>
 | 
			
		||||
                                        <li>'. $phones[$i] .'</li>
 | 
			
		||||
                                    </a>
 | 
			
		||||
                                        <li>
 | 
			
		||||
                                            <form method="post" action="index.php?state=mc">
 | 
			
		||||
                                                <input  name="id" type="hidden" value="'.$ids[$i].'">
 | 
			
		||||
                                                <input  name="name" type="hidden" value="'.$names[$i].'">
 | 
			
		||||
                                                <input  name="direction" type="hidden" value="'.$directions[$i].'">
 | 
			
		||||
                                                <input  name="phone" type="hidden" value="'.$phones[$i].'">
 | 
			
		||||
                                                <input type="submit" id="submit" value="Editar" name="edit_cinema" class="primary" />
 | 
			
		||||
                                            </form> 
 | 
			
		||||
                                        </li> 
 | 
			
		||||
                                        <li> 
 | 
			
		||||
                                            <form method="post" action="index.php?state=mc">
 | 
			
		||||
                                                <input  name="id" type="hidden" value="'.$ids[$i].'">
 | 
			
		||||
                                                <input  name="name" type="hidden" value="'.$names[$i].'">
 | 
			
		||||
                                                <input  name="direction" type="hidden" value="'.$directions[$i].'">
 | 
			
		||||
                                                <input  name="phone" type="hidden" value="'.$phones[$i].'">
 | 
			
		||||
                                                <input type="submit" id="submit" value="Eliminar" name="delete_cinema" class="primary" />
 | 
			
		||||
                                            </form> 
 | 
			
		||||
                                        </li> 
 | 
			
		||||
                                </div>
 | 
			
		||||
                                '; 
 | 
			
		||||
                                $parity = ($parity == "odd") ? "even" : "odd";
 | 
			
		||||
                        } 
 | 
			
		||||
                    $reply .=' </div>';
 | 
			
		||||
                break;
 | 
			
		||||
            
 | 
			
		||||
            default:
 | 
			
		||||
                break;
 | 
			
		||||
         }
 | 
			
		||||
        }
 | 
			
		||||
        return $reply;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function print_promotions(){
 | 
			
		||||
        $reply = "";
 | 
			
		||||
 | 
			
		||||
        //List of the cinemas:
 | 
			
		||||
        require_once(__DIR__.'/includes/promotion_dao.php');
 | 
			
		||||
 | 
			
		||||
        $prefix= $this->get_prefix();
 | 
			
		||||
 | 
			
		||||
        $promotion = new Promotion_DAO("complucine");
 | 
			
		||||
        $promotions = $promotion->allPromotionData();
 | 
			
		||||
        $ids = array();
 | 
			
		||||
        $tittles = array();
 | 
			
		||||
        $descriptions = array();
 | 
			
		||||
        $codes = array();
 | 
			
		||||
        $isActive = array();
 | 
			
		||||
 | 
			
		||||
        if(is_array($promotions)){
 | 
			
		||||
            foreach($promotions as $key => $value){
 | 
			
		||||
                $ids[$key] = $value->getId();
 | 
			
		||||
                $tittles[$key] = $value->getTittle();
 | 
			
		||||
                $descriptions[$key] = $value->getDescription();
 | 
			
		||||
                $codes[$key] = $value->getCode();
 | 
			
		||||
                if($value->getActive()){
 | 
			
		||||
                    $isActives[$key] = "ACTIVA";
 | 
			
		||||
                } else {
 | 
			
		||||
                    $isActives[$key] = "CADUCADA";
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        switch($this->page){
 | 
			
		||||
            case "Promociones":
 | 
			
		||||
                for($i = 0; $i < count($promotions); $i++){
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                    $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$tittles[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <div class='code promo'>
 | 
			
		||||
                                    <div class='image'><img src='".$prefix."img/promos/".str_replace(' ', '_', strtolower($tittles[$i])).".jpg' alt='".$tittles[$i]."' /></div>
 | 
			
		||||
                                    <h2>".$tittles[$i]."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <div class='blockquote'>
 | 
			
		||||
                                        <p>".$descriptions[$i]."</p>
 | 
			
		||||
                                    </div>
 | 
			
		||||
                                    <li>Código: ".$codes[$i]."</li>
 | 
			
		||||
                                    <li>Estado: ".$isActives[$i]."</li>
 | 
			
		||||
                                </div>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n";
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $reply;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print session MSG:
 | 
			
		||||
    function print_msg() {
 | 
			
		||||
        if(isset($_SESSION['message'])){
 | 
			
		||||
            echo "<div>".$_SESSION['message']."</div>";
 | 
			
		||||
            unset($_SESSION['message']);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic Footer:
 | 
			
		||||
    function print_footer(){
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
 | 
			
		||||
        /* TODO */
 | 
			
		||||
        if(!isset($_SESSION["css"]) || $_SESSION["css"] === "assets/css/main.css"){
 | 
			
		||||
            $css = "{$prefix}assets/css/highContrast.css";
 | 
			
		||||
            $nameCSS = "Alto Contraste";
 | 
			
		||||
        } else {
 | 
			
		||||
            $css = "{$prefix}assets/css/main.css";
 | 
			
		||||
            $nameCSS = "Contraste Normal";
 | 
			
		||||
        }
 | 
			
		||||
        /****/
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        echo"<footer>
 | 
			
		||||
            <div class='footer'>
 | 
			
		||||
                <p>© Práctica Final | Sistemas Web 2021 </p>
 | 
			
		||||
            </div>
 | 
			
		||||
            <span class='go-up'>🔝</span>
 | 
			
		||||
            <a href='{$prefix}fdicines/about_us/'>Sobre FDI-Cines</a> |
 | 
			
		||||
            <a href='{$prefix}fdicines/terms_conditions/'>Términos de uso</a> |
 | 
			
		||||
            <a href='{$prefix}cinemas/'>Nuestros cines</a> |
 | 
			
		||||
            <a href='{$prefix}contacto/'>Contacto</a> |
 | 
			
		||||
            <button id='css' onclick=\"cambiarCSS('$css');\">$nameCSS</button>
 | 
			
		||||
        </footer>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print JS scripts:
 | 
			
		||||
    function print_scripts(){
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
 | 
			
		||||
        echo"<script type='text/javascript' src='{$prefix}assets/js/jquery-3.2.1.min.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/cambiarCSS.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/checkForms.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/goUp.js'></script>
 | 
			
		||||
        ";
 | 
			
		||||
        if($page === "FDI-Cines") echo"<script type='text/javascript' src='{$prefix}assets/js/promotions.js'></script>\n";
 | 
			
		||||
        if($page === "Panel de Usuario") echo"<script type='text/javascript' src='{$prefix}assets/js/deleteConfirm.js'></script>\n";
 | 
			
		||||
        if($page === "Comprar Entrada") echo"<script type='text/javascript' src='{$prefix}assets/js/selectTicket.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/checkPay.js'></script>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										723
									
								
								root/assets/php/template.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										723
									
								
								root/assets/php/template.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,723 @@
 | 
			
		||||
<?php
 | 
			
		||||
    class Template {
 | 
			
		||||
 | 
			
		||||
    //Constants:
 | 
			
		||||
    //private const _NUMPAGES = 10; //Constant to page results.
 | 
			
		||||
 | 
			
		||||
    //Attributes:
 | 
			
		||||
    private $page;                  //Page Name.
 | 
			
		||||
    private $prefix;                //Page prefix.
 | 
			
		||||
 | 
			
		||||
    private $session;               //"Iniciar Sesión" (if user isn´t logged in), "Cerrar Sesión" (otherwise).
 | 
			
		||||
    private $session_route;         //"login/" (if user isn´t logged in), "logout/" (otherwise).
 | 
			
		||||
    private $panel;                 //Button to access the user's dashboard (only displayed if logged in).
 | 
			
		||||
    private $user_route;            //Route of the panel (depends on the type of user).
 | 
			
		||||
    private $sessionButtonClass;    //Type of button to login or logout.
 | 
			
		||||
 | 
			
		||||
    //Constructor:
 | 
			
		||||
    function __construct(){
 | 
			
		||||
        $this->page = $_SERVER['PHP_SELF']; //Page that instantiates the template.
 | 
			
		||||
        $this->prefix = '../';              //Default prefix.
 | 
			
		||||
 | 
			
		||||
        $this->set_page_prefix();           //Assigns the name and prefix of the page.
 | 
			
		||||
 | 
			
		||||
        $this->session = 'Iniciar Sesión';  //Default, the session has not started.
 | 
			
		||||
        $this->session_route = 'login/';    //Default, the session has not started.
 | 
			
		||||
        $this->panel = '';                  //Default, the session has not started.
 | 
			
		||||
        $this->user_route = 'panel_user/';  //Default, the type of client is user.
 | 
			
		||||
        $this->sessionButtonClass = '';     //Default, normal button.
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Methods:
 | 
			
		||||
 | 
			
		||||
    //Assigns the name and prefix of the page:
 | 
			
		||||
    private function set_page_prefix() {
 | 
			
		||||
        switch(true){
 | 
			
		||||
            case strpos($this->page, 'panel_user'): $this->page = 'Panel de Usuario'; break;
 | 
			
		||||
            case strpos($this->page, 'panel_manager'): $this->page = 'Panel de Gerente'; break;
 | 
			
		||||
            case strpos($this->page, 'panel_admin'): $this->page = 'Panel de Administrador'; break;
 | 
			
		||||
            case strpos($this->page, 'login'): $this->page = 'Acceso'; break;
 | 
			
		||||
            case strpos($this->page, 'logout'): $this->page = 'Cerrar Sesión'; break;
 | 
			
		||||
            case strpos($this->page, 'register'): $this->page = 'Registro de Usuario'; break;
 | 
			
		||||
            case strpos($this->page, 'showtimes'): $this->page = 'Cartelera'; break;
 | 
			
		||||
            case strpos($this->page, 'purchase'): $this->page = 'Comprar Entrada'; break;
 | 
			
		||||
            case strpos($this->page, 'promotions'): $this->page = 'Promociones'; break;
 | 
			
		||||
            case strpos($this->page, 'cinemas'): $this->page = 'Nuestros Cines'; break;
 | 
			
		||||
            case strpos($this->page, 'about_us'): $this->page = 'Sobre FDI-Cines'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'terms'): $this->page = 'Términos y Condiciones'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'detalles'): $this->page = 'Detalles'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'bocetos'): $this->page = 'Bocetos'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'miembros'): $this->page = 'Miembros'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'planificacion'): $this->page = 'Planificación'; $this->prefix = '../../'; break;
 | 
			
		||||
            case strpos($this->page, 'contacto'): $this->page = 'Contacto'; break;
 | 
			
		||||
            case strpos($this->page, 'assets'): $this->prefix = '../../../'; break;
 | 
			
		||||
            default: $this->page = 'FDI-Cines'; $this->prefix = './'; break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Returns page name:
 | 
			
		||||
    function get_page(){
 | 
			
		||||
        return $this->page;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Returns page prefix:
 | 
			
		||||
    function get_prefix(){
 | 
			
		||||
        return $this->prefix;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic Head:
 | 
			
		||||
    function print_head(){
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
 | 
			
		||||
        if(!isset($_SESSION["css"])) $_SESSION["css"] = "main.css";
 | 
			
		||||
 | 
			
		||||
        $extraCSS = "";
 | 
			
		||||
        if($page === "Comprar Entrada") $extraCSS = "\n<link id='estilo' rel='stylesheet' type='text/css' href='{$prefix}assets/css/seat.css'>";
 | 
			
		||||
        if($page === "Panel de Gerente") $extraCSS = "<link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.css' />";
 | 
			
		||||
 | 
			
		||||
        echo"<head>
 | 
			
		||||
        <title>CompluCine | {$page}</title>
 | 
			
		||||
        <meta charset='utf-8' />
 | 
			
		||||
        <link id='estilo' rel='stylesheet' type='text/css' href='{$prefix}assets/css/{$_SESSION['css']}'>{$extraCSS}
 | 
			
		||||
        <noscript><h1>Esta página requiere JavaScript para su correcto funcionamiento. 
 | 
			
		||||
            Compruebe si JavaScript está deshabilitado en su navegador.</h1></noscript>
 | 
			
		||||
        <meta name='viewport' content='width=device-width, initial-scale=1'>
 | 
			
		||||
        <link rel='icon' href='{$prefix}img/favicon.png' />
 | 
			
		||||
    </head>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic Header:
 | 
			
		||||
    function print_header(){
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
        $session = $this->session;
 | 
			
		||||
        $sessionButtonClass = $this->sessionButtonClass;
 | 
			
		||||
        $session_route = $this->session_route;
 | 
			
		||||
        $user_route = $this->user_route;
 | 
			
		||||
        $panel =$this->panel;
 | 
			
		||||
 | 
			
		||||
        if(isset($_SESSION["rol"])){
 | 
			
		||||
            if($_SESSION["rol"] === "admin") $user_route = 'panel_admin/';
 | 
			
		||||
            else if($_SESSION["rol"] === "manager") $user_route = 'panel_manager/';
 | 
			
		||||
            $panel = "<a href='{$prefix}{$user_route}'><li>Mi Panel</li></a>";
 | 
			
		||||
            $session = 'Cerrar Sesión';
 | 
			
		||||
            $sessionButtonClass = 'danger';
 | 
			
		||||
            $session_route = 'logout/';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(isset($_SESSION["lastRol"]) && ($_SESSION["lastRol"] === "admin" || $_SESSION["lastRol"] === "manager" )){
 | 
			
		||||
            $changeRol = "<a href='{$prefix}assets/php/common/resetRol.php'><li class='danger'>Volver a {$_SESSION["lastRol"]}</li></a>";
 | 
			
		||||
        } else {
 | 
			
		||||
            $changeRol = null;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        echo"<div class='header'>
 | 
			
		||||
            <a href='{$prefix}'><img src='{$prefix}img/favicon2.png' alt='favicon' /> CompluCine</a> | {$page}
 | 
			
		||||
            <div class='menu'>
 | 
			
		||||
                <nav>{$changeRol}
 | 
			
		||||
                    <a href='{$prefix}{$session_route}'><li class={$sessionButtonClass}>{$session}</li></a>
 | 
			
		||||
                    {$panel}
 | 
			
		||||
                    <li>Menú
 | 
			
		||||
                        <ul>
 | 
			
		||||
                            <a href='{$prefix}'><li>Inicio</li></a>
 | 
			
		||||
                            <a href='{$prefix}showtimes/'><li>Cartelera</li></a>
 | 
			
		||||
                            <a href='{$prefix}cinemas/'><li>Nuestros Cines</li></a>
 | 
			
		||||
                            <a href='{$prefix}promotions/'><li>Promociones</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/miembros/'><li>Quiénes somos</li></a>
 | 
			
		||||
                            <a href='{$prefix}contacto/'><li>Contacto</li></a>
 | 
			
		||||
                        </ul>
 | 
			
		||||
                    </li>
 | 
			
		||||
                </nav>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic subHeader:
 | 
			
		||||
    function print_subheader(){
 | 
			
		||||
        //$page = $this->page;
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
 | 
			
		||||
        echo"<div class='header sub'>
 | 
			
		||||
            <div class='menu'>
 | 
			
		||||
                <nav>
 | 
			
		||||
                    <a href='{$prefix}fdicines/about_us/'><li>Sobre FDI-Cines</li></a>
 | 
			
		||||
                    <a href='{$prefix}fdicines/detalles/'><li>Detalles</li></a>
 | 
			
		||||
                    <a href='{$prefix}fdicines/bocetos/'><li>Bocetos</li></a>
 | 
			
		||||
                    <a href='{$prefix}fdicines/miembros/'><li>Miembros</li></a>
 | 
			
		||||
                    <a href='{$prefix}fdicines/planificacion/'><li>Planificación</li></a>
 | 
			
		||||
                </nav>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic Main:
 | 
			
		||||
    function print_main($content = ""){
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
 | 
			
		||||
        /* SubHeader on Main */
 | 
			
		||||
        $sub_header = '';
 | 
			
		||||
        if(strpos($_SERVER['PHP_SELF'], 'fdicines')){
 | 
			
		||||
            $sub_header = "<!-- Sub Header -->
 | 
			
		||||
                <div class='header sub'>
 | 
			
		||||
                    <div class='menu'>
 | 
			
		||||
                        <nav>
 | 
			
		||||
                            <a href='{$prefix}fdicines/about_us/'><li>Sobre FDI-Cines</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/detalles/'><li>Detalles</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/bocetos/'><li>Bocetos</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/miembros/'><li>Miembros</li></a>
 | 
			
		||||
                            <a href='{$prefix}fdicines/planificacion/'><li>Planificación</li></a>
 | 
			
		||||
                        </nav>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </div>\n"; 
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* MAIN */
 | 
			
		||||
        if($prefix === "./"){ 
 | 
			
		||||
            if(isset($_SESSION["nombre"])){
 | 
			
		||||
                $tittle = "<h1>Bienvenido {$_SESSION["nombre"]}</h1>\n";
 | 
			
		||||
            } else {
 | 
			
		||||
                $tittle = "<h1>Bienvenido a CompluCine</h1>\n";
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            $tittle = "<h1>{$page}</h1>\n";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        echo"<main>
 | 
			
		||||
            <div class='image'><a href='{$prefix}'><img src='{$prefix}img/logo_trasparente.png' alt='logo_FDI-Cines' /></a></div>
 | 
			
		||||
            {$sub_header}
 | 
			
		||||
            {$tittle}{$content}
 | 
			
		||||
            <hr />
 | 
			
		||||
        </main>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print panel menu:
 | 
			
		||||
    function print_panelMenu($panel){
 | 
			
		||||
        if($_SESSION["login"]){
 | 
			
		||||
            $prefix = $this->prefix;
 | 
			
		||||
            $menus = array("<a href='./'><li>Panel Principal</li></a>");
 | 
			
		||||
 | 
			
		||||
            switch($panel){
 | 
			
		||||
                case "admin": array_push($menus, "<li>Ver como...
 | 
			
		||||
                                                        <ul>
 | 
			
		||||
                                                            <a href='./?state=un'><li>Usuario</li></a>
 | 
			
		||||
                                                            <a href='./?state=ur'><li>Usuario registrado</li></a>
 | 
			
		||||
                                                            <a href='./?state=ag'><li>Gerente</li></a>
 | 
			
		||||
                                                        </ul>
 | 
			
		||||
                                                    </li>");
 | 
			
		||||
                                array_push($menus, "<li>Modificar
 | 
			
		||||
                                                        <ul>
 | 
			
		||||
                                                            <a href='./?state=mc'><li>Cines</li></a>
 | 
			
		||||
                                                            <a href='./?state=mf'><li>Películas</li></a>
 | 
			
		||||
                                                            <a href='./?state=mp'><li>Promociones</li></a>
 | 
			
		||||
                                                            <a href='./?state=mg'><li>Gerentes</li></a>
 | 
			
		||||
                                                        </ul>
 | 
			
		||||
                                                    </li>");
 | 
			
		||||
                                break;
 | 
			
		||||
 | 
			
		||||
                case "manager": array_push($menus, "<li>Ver como...
 | 
			
		||||
                                                        <ul>
 | 
			
		||||
                                                            <a href='./?state=view_user'><li>Usuario</li></a>
 | 
			
		||||
                                                            <a href='./?state=view_ruser'><li>Usuario registrado</li></a>
 | 
			
		||||
                                                        </ul>
 | 
			
		||||
                                                    </li>");
 | 
			
		||||
                                array_push($menus, "<li>Modificar
 | 
			
		||||
                                                        <ul>
 | 
			
		||||
                                                            <a href='./?state=manage_halls'><li>Salas</li></a>
 | 
			
		||||
                                                            <a href='./?state=manage_sessions'><li>Sesiones</li></a>
 | 
			
		||||
                                                        </ul>
 | 
			
		||||
                                                    </li>");
 | 
			
		||||
                                break;
 | 
			
		||||
 | 
			
		||||
                case "user": array_push($menus, "<a href='./?option=purchases'><li>Historial Compras</li></a>");
 | 
			
		||||
                                //array_push($menus, "<a href='./?option=payment'><li>Datos Pago</li></a>");
 | 
			
		||||
                                    array_push($menus, "<a href='./?option=delete_user'><li>Eliminar Usuario</li></a>");
 | 
			
		||||
                                        break;
 | 
			
		||||
 | 
			
		||||
                default: $menus = array(); break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if($_SESSION["rol"] === $panel){
 | 
			
		||||
                echo"<div class='header sub'>
 | 
			
		||||
                <div class='menu'>
 | 
			
		||||
                    <nav>";
 | 
			
		||||
                    foreach($menus as $value){
 | 
			
		||||
                        echo $value;
 | 
			
		||||
                    }  
 | 
			
		||||
                    echo"</nav>
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
        ";
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print specific page content:
 | 
			
		||||
    function print_section($section){
 | 
			
		||||
        /* Panel menu */
 | 
			
		||||
        $sub_header = '';
 | 
			
		||||
        if(strpos($_SERVER['PHP_SELF'], 'panel')){
 | 
			
		||||
            echo "<!-- Panel Menu -->
 | 
			
		||||
            ";
 | 
			
		||||
            $this->print_panelMenu($_SESSION["rol"]);
 | 
			
		||||
            $this->print_msg();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        echo $section;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print Films Cards:
 | 
			
		||||
    function print_fimls(){
 | 
			
		||||
        $reply = "";
 | 
			
		||||
        //List of the movies:
 | 
			
		||||
        require_once(__DIR__.'/includes/film_dao.php');
 | 
			
		||||
 | 
			
		||||
        $prefix= $this->get_prefix();
 | 
			
		||||
 | 
			
		||||
        $films = new Film_DAO("complucine");
 | 
			
		||||
        $films_array = $films->allFilmData();
 | 
			
		||||
        $ids = array();
 | 
			
		||||
        $tittles = array();
 | 
			
		||||
        $descriptions = array();
 | 
			
		||||
        $times = array();
 | 
			
		||||
        $languages = array();
 | 
			
		||||
        $images = array();
 | 
			
		||||
        if(is_array($films_array)){
 | 
			
		||||
            foreach($films_array as $key => $value){
 | 
			
		||||
                $ids[$key] = $value->getId();
 | 
			
		||||
                $tittles[$key] = $value->getTittle();
 | 
			
		||||
                $descriptions[$key] = $value->getDescription();
 | 
			
		||||
                $times[$key] = $value->getDuration();
 | 
			
		||||
                $languages[$key] = $value->getLanguage();
 | 
			
		||||
                $images[$key] = $value->getImg();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        switch($this->page){
 | 
			
		||||
            case "Cartelera": 
 | 
			
		||||
                if(is_array($films_array)){
 | 
			
		||||
                for($i = 0; $i < count($films_array); $i++){
 | 
			
		||||
                    $tittle = str_replace('_', ' ', $tittles[$i]);
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                    $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$tittles[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <a href='".$prefix."purchase?film=".$ids[$i]."'>
 | 
			
		||||
                                <div class='code showtimes'>
 | 
			
		||||
                                    <div class='image'><img src='".$prefix."img/films/".$images[$i]."' alt='".$tittles[$i]."' /></div>
 | 
			
		||||
                                    <h2>".$tittle."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <div class='blockquote'>
 | 
			
		||||
                                        <p>".$descriptions[$i]."</p>
 | 
			
		||||
                                    </div>
 | 
			
		||||
                                    <li>Duración: ".$times[$i]." minutos</li>
 | 
			
		||||
                                    <li>Lenguaje: ".$languages[$i]."</li>
 | 
			
		||||
                                </div>
 | 
			
		||||
                                </a>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n";
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
            case "Panel de Administrador":
 | 
			
		||||
                $reply .= "<div class='column'>";
 | 
			
		||||
                if(is_array($films_array)){
 | 
			
		||||
                for($i = 0; $i < count($films_array); $i++){
 | 
			
		||||
                    $tittle = str_replace('_', ' ', $tittles[$i]);
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$tittles[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <div class='code showtimes'>
 | 
			
		||||
                                    <div class='image'><img src='".$prefix."img/films/".$images[$i]."' alt='".$tittles[$i]."' /></div>
 | 
			
		||||
                                    <h2>".$tittle."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <form method='post' action='./index.php?state=mf'>
 | 
			
		||||
                                        <input name='id' type='hidden' value='".$ids[$i]."'>
 | 
			
		||||
                                        <input name='tittle' type='hidden' value='".$tittles[$i]."'>
 | 
			
		||||
                                        <input  name='duration' type='hidden' value='".$times[$i]."'>
 | 
			
		||||
                                        <input  name='language' type='hidden' value='".$languages[$i]."'>
 | 
			
		||||
                                        <input name='description' type='hidden' value='".$descriptions[$i]."'>
 | 
			
		||||
                                        <input type='submit' id='submit' value='Editar' name='edit_film' class='primary' />
 | 
			
		||||
                                    </form>
 | 
			
		||||
                                    <form method='post' action='./index.php?state=mf'>
 | 
			
		||||
                                        <input name='id' type='hidden' value='".$ids[$i]."'>
 | 
			
		||||
                                        <input name='tittle' type='hidden' value='".$tittles[$i]."'>
 | 
			
		||||
                                        <input  name='duration' type='hidden' value='".$times[$i]."'>
 | 
			
		||||
                                        <input  name='language' type='hidden' value='".$languages[$i]."'>
 | 
			
		||||
                                        <input name='description' type='hidden' value='".$descriptions[$i]."'>
 | 
			
		||||
                                        <input type='submit' id='submit' value='Eliminar' name='delete_film' class='primary' />
 | 
			
		||||
                                    </form>
 | 
			
		||||
                                </div>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n";                
 | 
			
		||||
                break;
 | 
			
		||||
				
 | 
			
		||||
			case "Panel de Gerente":
 | 
			
		||||
                $reply .= "<div class='column'>";
 | 
			
		||||
                if(is_array($films_array)){
 | 
			
		||||
                for($i = 0; $i < count($films_array); $i++){
 | 
			
		||||
                    $tittle = str_replace('_', ' ', $tittles[$i]);
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$tittles[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <div class='code showtimes'>
 | 
			
		||||
                                    <div class='image'><img src='".$prefix."img/films/".$images[$i]."' alt='".$tittles[$i]."' /></div>
 | 
			
		||||
                                    <h2>".$tittle."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <li>Duración: ".$times[$i]." minutos</li>
 | 
			
		||||
                                    <li>Lenguaje: ".$languages[$i]."</li>
 | 
			
		||||
                                
 | 
			
		||||
								<form method='post' action='./?state=".$_SESSION["option"]."'>
 | 
			
		||||
									<input name='film' type='hidden' value='".$ids[$i]."'>
 | 
			
		||||
									<input name='tittle' type='hidden' value='".$tittles[$i]."'>
 | 
			
		||||
									<input name='duration' type='hidden' value='".$times[$i]."'>
 | 
			
		||||
									<input name='language' type='hidden' value='".$languages[$i]."'>
 | 
			
		||||
									<input name='description' type='hidden' value='".$descriptions[$i]."'>
 | 
			
		||||
									<input name='hall' type='hidden' value='".$_POST["hall"]."'>
 | 
			
		||||
									<input name='date' type='hidden' value='".$_POST["date"]."'>
 | 
			
		||||
									<input name='start' type='hidden' value='".$_POST["start"]."'>	
 | 
			
		||||
									<input name='price' type='hidden' value='".$_POST["price"]."'>
 | 
			
		||||
									<input name='format' type='hidden' value='".$_POST["format"]."'>
 | 
			
		||||
									<input name='or_hall' type='hidden' value='".$_POST["or_hall"]."'>
 | 
			
		||||
									<input name='or_date' type='hidden' value='".$_POST["or_date"]."'>
 | 
			
		||||
									<input name='or_start' type='hidden' value='".$_POST["or_start"]."'>
 | 
			
		||||
									<input type='submit' id='submit' value='Seleccionar' name='select_film' class='primary' />
 | 
			
		||||
								</form>
 | 
			
		||||
								</div>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n"; 
 | 
			
		||||
                break;
 | 
			
		||||
				
 | 
			
		||||
            default: 
 | 
			
		||||
                if(is_array($films_array)){
 | 
			
		||||
                    $reply .='<div class="column left">
 | 
			
		||||
                         <div class="galery">
 | 
			
		||||
                            <h1>Últimos Estrenos</h1><hr />';
 | 
			
		||||
                    $count = 0;
 | 
			
		||||
                    for($i = count($tittles)-4; $i < count($tittles); $i++){
 | 
			
		||||
                        if($count%2===0){
 | 
			
		||||
                            if($count != 0) $reply .= "
 | 
			
		||||
                            </div>";
 | 
			
		||||
                        $reply .= "
 | 
			
		||||
                            <div class='fila'>";
 | 
			
		||||
                        }
 | 
			
		||||
                        $reply .= "
 | 
			
		||||
                                <div class='zoom'>
 | 
			
		||||
                                    <div class='columna'>
 | 
			
		||||
                                        <a href='".$prefix."showtimes/#".$tittles[$i]."'><div class='image'><img src='img/films/".$images[$i]."' alt='".$tittles[$i]."' /></div></a>
 | 
			
		||||
                                    </div>
 | 
			
		||||
                                </div>";
 | 
			
		||||
                        $count++;
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <div class='column right'>
 | 
			
		||||
                        <div class='galery'>";
 | 
			
		||||
                    $count = rand(0, count($tittles)-1);
 | 
			
		||||
                    $title = str_replace('_', ' ', $tittles[$count]); 
 | 
			
		||||
                    $reply .= "
 | 
			
		||||
                            <h1>{$title}</h1><hr />
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <a href='".$prefix."showtimes/#".$tittles[$count]."'><div class='image main'><img src='img/films/".$images[$count]."' alt='".$tittles[$count]."' /></div></a>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>\n";
 | 
			
		||||
                }
 | 
			
		||||
                    break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $reply;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print Cinemas info:
 | 
			
		||||
    function print_cinemas(){
 | 
			
		||||
        $reply = "";
 | 
			
		||||
 | 
			
		||||
        //List of the cinemas:
 | 
			
		||||
        require_once(__DIR__.'/includes/cinema_dao.php');
 | 
			
		||||
 | 
			
		||||
        $prefix= $this->get_prefix();
 | 
			
		||||
 | 
			
		||||
        $cine = new Cinema_DAO("complucine");
 | 
			
		||||
        $cinemas = $cine->allCinemaData();
 | 
			
		||||
        $ids = array();
 | 
			
		||||
        $names = array();
 | 
			
		||||
        $directions = array();
 | 
			
		||||
        $phones = array();
 | 
			
		||||
 | 
			
		||||
        if(!is_array($cinemas)){
 | 
			
		||||
            $reply = "<h2>No hay cines actualmente</h2>";
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
            foreach($cinemas as $key => $value){
 | 
			
		||||
                $ids[$key] = $value->getId();
 | 
			
		||||
                $names[$key] = $value->getName();
 | 
			
		||||
                $directions[$key] = $value->getDirection();
 | 
			
		||||
                $phones[$key] = $value->getPhone();
 | 
			
		||||
            }
 | 
			
		||||
        
 | 
			
		||||
        switch($this->page){
 | 
			
		||||
            case "Nuestros Cines":
 | 
			
		||||
 | 
			
		||||
                for($i = 0; $i < count($cinemas); $i++){
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                    $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$names[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <a href='".$prefix."purchase?cinema=".$ids[$i]."'>
 | 
			
		||||
                                <div class='code cinemas'>
 | 
			
		||||
                                    <h2>".$names[$i]."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <section class='column left'>
 | 
			
		||||
                                        <img src='../img/sala1.jpg' alt='".$names[$i]."' />
 | 
			
		||||
                                    </section>
 | 
			
		||||
                                    <section class='column right'>
 | 
			
		||||
                                        <section class='blockquote'>
 | 
			
		||||
                                            <li>Dirección: ".$directions[$i]."</li>
 | 
			
		||||
                                            <li>Teléfono: ".$phones[$i]."</li>
 | 
			
		||||
                                        </section>
 | 
			
		||||
                                    </section>
 | 
			
		||||
                                </div>
 | 
			
		||||
                                </a>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n";
 | 
			
		||||
                break;
 | 
			
		||||
            case "Panel de Administrador":
 | 
			
		||||
                    $reply .= "<div class='row'>
 | 
			
		||||
                            <ul class='tablelist col6'> 
 | 
			
		||||
                                <li class='title'>Id</li>
 | 
			
		||||
                                <li class='title'>Nombre</li>
 | 
			
		||||
                                <li class='title'>Dirección</li>
 | 
			
		||||
                                <li class='title'>Teléfono</li>
 | 
			
		||||
                                <li class='title'>Editar</li>
 | 
			
		||||
                                <li class='title'>Eliminar</li>
 | 
			
		||||
                            ";
 | 
			
		||||
                        $parity = "odd";
 | 
			
		||||
                        for($i = 0; $i < count($cinemas); $i++){
 | 
			
		||||
                            $reply .= '
 | 
			
		||||
                                    <div class="'.$parity.'">
 | 
			
		||||
                                    <a class="h2long" href="index.php?state=mc&cinema='.$ids[$i].'">
 | 
			
		||||
                                        <li>'. $ids[$i] .'</li>
 | 
			
		||||
                                        <li>'. $names[$i] .'</li>
 | 
			
		||||
                                        <li>'. $directions[$i] .'</li>
 | 
			
		||||
                                        <li>'. $phones[$i] .'</li>
 | 
			
		||||
                                    </a>
 | 
			
		||||
                                        <li>
 | 
			
		||||
                                            <form method="post" action="index.php?state=mc">
 | 
			
		||||
                                                <input  name="id" type="hidden" value="'.$ids[$i].'">
 | 
			
		||||
                                                <input  name="name" type="hidden" value="'.$names[$i].'">
 | 
			
		||||
                                                <input  name="direction" type="hidden" value="'.$directions[$i].'">
 | 
			
		||||
                                                <input  name="phone" type="hidden" value="'.$phones[$i].'">
 | 
			
		||||
                                                <input type="submit" id="submit" value="Editar" name="edit_cinema" class="primary" />
 | 
			
		||||
                                            </form> 
 | 
			
		||||
                                        </li> 
 | 
			
		||||
                                        <li> 
 | 
			
		||||
                                            <form method="post" action="index.php?state=mc">
 | 
			
		||||
                                                <input  name="id" type="hidden" value="'.$ids[$i].'">
 | 
			
		||||
                                                <input  name="name" type="hidden" value="'.$names[$i].'">
 | 
			
		||||
                                                <input  name="direction" type="hidden" value="'.$directions[$i].'">
 | 
			
		||||
                                                <input  name="phone" type="hidden" value="'.$phones[$i].'">
 | 
			
		||||
                                                <input type="submit" id="submit" value="Eliminar" name="delete_cinema" class="primary" />
 | 
			
		||||
                                            </form> 
 | 
			
		||||
                                        </li> 
 | 
			
		||||
                                </div>
 | 
			
		||||
                                '; 
 | 
			
		||||
                                $parity = ($parity == "odd") ? "even" : "odd";
 | 
			
		||||
                        } 
 | 
			
		||||
                    $reply .=' </div>';
 | 
			
		||||
                break;
 | 
			
		||||
            
 | 
			
		||||
            default:
 | 
			
		||||
                break;
 | 
			
		||||
         }
 | 
			
		||||
        }
 | 
			
		||||
        return $reply;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function print_promotions(){
 | 
			
		||||
        $reply = "";
 | 
			
		||||
 | 
			
		||||
        //List of the cinemas:
 | 
			
		||||
        require_once(__DIR__.'/includes/promotion_dao.php');
 | 
			
		||||
 | 
			
		||||
        $prefix= $this->get_prefix();
 | 
			
		||||
 | 
			
		||||
        $promotion = new Promotion_DAO("complucine");
 | 
			
		||||
        $promotions = $promotion->allPromotionData();
 | 
			
		||||
        $ids = array();
 | 
			
		||||
        $tittles = array();
 | 
			
		||||
        $descriptions = array();
 | 
			
		||||
        $codes = array();
 | 
			
		||||
        $isActive = array();
 | 
			
		||||
 | 
			
		||||
        if(is_array($promotions)){
 | 
			
		||||
            foreach($promotions as $key => $value){
 | 
			
		||||
                $ids[$key] = $value->getId();
 | 
			
		||||
                $tittles[$key] = $value->getTittle();
 | 
			
		||||
                $descriptions[$key] = $value->getDescription();
 | 
			
		||||
                $codes[$key] = $value->getCode();
 | 
			
		||||
                if($value->getActive()){
 | 
			
		||||
                    $isActives[$key] = "ACTIVA";
 | 
			
		||||
                } else {
 | 
			
		||||
                    $isActives[$key] = "CADUCADA";
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        switch($this->page){
 | 
			
		||||
            case "Promociones":
 | 
			
		||||
                for($i = 0; $i < count($promotions); $i++){
 | 
			
		||||
                    if($i%2 === 0){
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                        $reply .= "<div class='column side'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        if($i != 0) $reply .= "</div>
 | 
			
		||||
                    ";
 | 
			
		||||
                    $reply .= "<div class='column middle'>
 | 
			
		||||
                        ";
 | 
			
		||||
                    }
 | 
			
		||||
                    $reply .= "<section id='".$tittles[$i]."'>
 | 
			
		||||
                            <div class='zoom'>
 | 
			
		||||
                                <div class='code promo'>
 | 
			
		||||
                                    <div class='image'><img src='".$prefix."img/promos/".str_replace(' ', '_', strtolower($tittles[$i])).".jpg' alt='".$tittles[$i]."' /></div>
 | 
			
		||||
                                    <h2>".$tittles[$i]."</h2>
 | 
			
		||||
                                    <hr />
 | 
			
		||||
                                    <div class='blockquote'>
 | 
			
		||||
                                        <p>".$descriptions[$i]."</p>
 | 
			
		||||
                                    </div>
 | 
			
		||||
                                    <li>Código: ".$codes[$i]."</li>
 | 
			
		||||
                                    <li>Estado: ".$isActives[$i]."</li>
 | 
			
		||||
                                </div>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </section>
 | 
			
		||||
                    ";
 | 
			
		||||
                }
 | 
			
		||||
                $reply .= "</div>\n";
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $reply;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print session MSG:
 | 
			
		||||
    function print_msg() {
 | 
			
		||||
        if(isset($_SESSION['message'])){
 | 
			
		||||
            echo "<div>".$_SESSION['message']."</div>";
 | 
			
		||||
            unset($_SESSION['message']);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print generic Footer:
 | 
			
		||||
    function print_footer(){
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
        
 | 
			
		||||
        if(!isset($_SESSION["css"]) || $_SESSION["css"] === "main.css"){
 | 
			
		||||
            $css = "{$prefix}assets/css/highContrast.css";
 | 
			
		||||
            $nameCSS = "Alto Contraste";
 | 
			
		||||
        } else {
 | 
			
		||||
            $css = "{$prefix}assets/css/main.css";
 | 
			
		||||
            $nameCSS = "Contraste Normal";
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        echo"<footer>
 | 
			
		||||
            <div class='footer'>
 | 
			
		||||
                <p>© Práctica Final | Sistemas Web 2021 </p>
 | 
			
		||||
            </div>
 | 
			
		||||
            <span class='go-up'>🔝</span>
 | 
			
		||||
            <a href='{$prefix}fdicines/about_us/'>Sobre FDI-Cines</a> |
 | 
			
		||||
            <a href='{$prefix}fdicines/terms_conditions/'>Términos de uso</a> |
 | 
			
		||||
            <a href='{$prefix}cinemas/'>Nuestros cines</a> |
 | 
			
		||||
            <a href='{$prefix}contacto/'>Contacto</a> |
 | 
			
		||||
            <button id='cssChange' onclick=\"cambiarCSS('$css');\">$nameCSS</button>
 | 
			
		||||
        </footer>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Print JS scripts:
 | 
			
		||||
    function print_scripts(){
 | 
			
		||||
        $prefix = $this->prefix;
 | 
			
		||||
        $page = $this->page;
 | 
			
		||||
 | 
			
		||||
        echo"<script type='text/javascript' src='{$prefix}assets/js/jquery-3.2.1.min.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/cambiarCSS.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/checkForms.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/goUp.js'></script>
 | 
			
		||||
        ";
 | 
			
		||||
        if($page === "FDI-Cines") echo"<script type='text/javascript' src='{$prefix}assets/js/promotions.js'></script>\n";
 | 
			
		||||
        if($page === "Panel de Usuario") echo"<script type='text/javascript' src='{$prefix}assets/js/deleteConfirm.js'></script>\n";
 | 
			
		||||
        if($page === "Comprar Entrada") echo"<script type='text/javascript' src='{$prefix}assets/js/selectTicket.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/checkPay.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/goBack.js'></script>\n";
 | 
			
		||||
        if($page === "Panel de Gerente") echo"<script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.min.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/sessionCalendar.js'></script>
 | 
			
		||||
        <script type='text/javascript' src='{$prefix}assets/js/sessionFormProcess.js'></script>\n";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
		Reference in New Issue
	
	Block a user