Comprobado toda la logica/seguridad.
En teoria falta actualizar la estructura a como me dijo oscar esta mañana? algo asi
This commit is contained in:
		@@ -5,8 +5,8 @@ include_once('../assets/php/form.php');
 | 
			
		||||
class FormHall extends Form {
 | 
			
		||||
 | 
			
		||||
    //Atributes:
 | 
			
		||||
    private $correct;  // Indicates if the session is correct.
 | 
			
		||||
    private $reply; // Validation response
 | 
			
		||||
    private $correct;  
 | 
			
		||||
    private $reply; 
 | 
			
		||||
	private $option;
 | 
			
		||||
	private $halls;
 | 
			
		||||
	
 | 
			
		||||
@@ -20,7 +20,8 @@ class FormHall extends Form {
 | 
			
		||||
 | 
			
		||||
    //Returns validation response:
 | 
			
		||||
    public function getReply() {
 | 
			
		||||
		//Habria que comprobar si realmente se ha validado la respuesta antes de escribir una respuesta correcta
 | 
			
		||||
		
 | 
			
		||||
		echo "<p> se va a devolver una respuesta </p>";
 | 
			
		||||
		if($this->correct){
 | 
			
		||||
			if($this->option == "new"){
 | 
			
		||||
				$this->reply = "<h1> Operacion realizada con exito </h1><hr />
 | 
			
		||||
@@ -35,6 +36,7 @@ class FormHall extends Form {
 | 
			
		||||
						<p> Se ha eliminado la sala correctamente en la base de datos.</p>
 | 
			
		||||
						<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
 | 
			
		||||
			}else if($this->option == "list"){
 | 
			
		||||
								echo "<p> se va a devolver la lista </p>";
 | 
			
		||||
								$this->reply = $this->halls;
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
@@ -56,7 +58,7 @@ class FormHall extends Form {
 | 
			
		||||
			if($option == "list"){
 | 
			
		||||
				$this->halls = $bd->getAllHalls($cinema);
 | 
			
		||||
			}else {
 | 
			
		||||
				/*
 | 
			
		||||
				/* TODO
 | 
			
		||||
				$start = date('H:i:s', strtotime( $start ) );
 | 
			
		||||
				
 | 
			
		||||
				if($option == "new"){
 | 
			
		||||
 
 | 
			
		||||
@@ -2,25 +2,22 @@
 | 
			
		||||
include_once('session_dao.php');
 | 
			
		||||
include_once('../assets/php/form.php');
 | 
			
		||||
 | 
			
		||||
//Receive data from froms and prepare the correct response
 | 
			
		||||
class FormSession extends Form {
 | 
			
		||||
 | 
			
		||||
    //Atributes:
 | 
			
		||||
    private $correct;  // Indicates if the session is correct.
 | 
			
		||||
    private $reply; // Validation response
 | 
			
		||||
	//Atributes
 | 
			
		||||
    private $correct;
 | 
			
		||||
    private $reply; 
 | 
			
		||||
	private $option;
 | 
			
		||||
	private $sessions;
 | 
			
		||||
	
 | 
			
		||||
    //Constructor:
 | 
			
		||||
//Constructor:	
 | 
			
		||||
    public function __construct() {
 | 
			
		||||
        parent::__construct('formSession');
 | 
			
		||||
        $this->reply = array();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Methods:
 | 
			
		||||
 | 
			
		||||
    //Returns validation response:
 | 
			
		||||
	
 | 
			
		||||
	//Methods:
 | 
			
		||||
    public function getReply() {
 | 
			
		||||
		//Habria que comprobar si realmente se ha validado la respuesta antes de escribir una respuesta correcta
 | 
			
		||||
		if($this->correct){
 | 
			
		||||
			if($this->option == "new"){
 | 
			
		||||
				$this->reply = "<h1> Operacion realizada con exito </h1><hr />
 | 
			
		||||
@@ -45,46 +42,39 @@ class FormSession extends Form {
 | 
			
		||||
        return $this->reply;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Process form:
 | 
			
		||||
    public function processesForm($id, $film, $hall, $cinema, $date, $start, $price, $format, $repeat, $option) {
 | 
			
		||||
		$this->option = $option;
 | 
			
		||||
		$this->correct = true;
 | 
			
		||||
 | 
			
		||||
		$bd = new sessionDAO('complucine');
 | 
			
		||||
		
 | 
			
		||||
		$date = date('Y-m-d', strtotime( $date ) ); 
 | 
			
		||||
		
 | 
			
		||||
				
 | 
			
		||||
		if($bd ){
 | 
			
		||||
			if($option == "list"){
 | 
			
		||||
				$this->sessions = $bd->getAllSessionsFromDateHallAndCinema($cinema, $hall, $date);
 | 
			
		||||
				$this->sessions = $bd->getAllSessionsFromACinemaHallDate($cinema, $hall, $date);
 | 
			
		||||
				
 | 
			
		||||
			}else {
 | 
			
		||||
				
 | 
			
		||||
				$start = date('H:i:s', strtotime( $start ) );
 | 
			
		||||
				
 | 
			
		||||
				if($option == "new"){
 | 
			
		||||
					
 | 
			
		||||
					$selectSession = $bd->selectSession($cinema, $hall, $start, $date);
 | 
			
		||||
					if($selectSession && $selectSession->num_rows >= 1)	{
 | 
			
		||||
					$searchSession = $bd->searchSession($cinema, $hall, $start, $date);
 | 
			
		||||
					if($searchSession)	{
 | 
			
		||||
						$this->correct = false;
 | 
			
		||||
					} else{	
 | 
			
		||||
						$bd->createSession(null, $film, $hall,$cinema, $date, $start, $price, $format);
 | 
			
		||||
					}
 | 
			
		||||
					
 | 
			
		||||
				mysqli_free_result($selectSession);
 | 
			
		||||
				
 | 
			
		||||
				} else if ($option == "del"){
 | 
			
		||||
					$bd->deleteSession($id);
 | 
			
		||||
					
 | 
			
		||||
				} else if ($option == "edit"){
 | 
			
		||||
					$bd->editSession($id, $film, $hall, $cinema, $date, $start, $price, $format);
 | 
			
		||||
		
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
				if($repeat > "0"){
 | 
			
		||||
					$repeat--;
 | 
			
		||||
					$date = date('Y-m-d', strtotime( $date. ' +1 day') );
 | 
			
		||||
					$this->processesForm($film, $hall, $cinema, $date, $start, $price, $format, $repeat);
 | 
			
		||||
					$this->processesForm($id, $film, $hall, $cinema, $date, $start, $price, $format, $repeat, $option);
 | 
			
		||||
				}		
 | 
			
		||||
			}		
 | 
			
		||||
			
 | 
			
		||||
		} else {$this->correct = false;}	
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,16 +3,16 @@
 | 
			
		||||
	include_once('session_dto.php');
 | 
			
		||||
 | 
			
		||||
    class SessionDAO extends DAO {
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($bd_name){
 | 
			
		||||
			parent::__construct($bd_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		//Methods:
 | 
			
		||||
 | 
			
		||||
        //Create a new Session.
 | 
			
		||||
		
 | 
			
		||||
		public function createSession($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
 | 
			
		||||
			$format = $this->mysqli->real_escape_string($format);	
 | 
			
		||||
			$date = date('Y-m-d', strtotime( $date ) ); 
 | 
			
		||||
			$startTime = date('H:i:s', strtotime( $startTime ) );
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "INSERT INTO `session` (`id`, `idfilm`, `idhall`, `idcinema`, `date`, `start_time`, `seat_price`, `format`) 
 | 
			
		||||
				VALUES ('%d', '%d', '%d', '%d', '%s', '%s', '%d', '%s')",
 | 
			
		||||
@@ -29,25 +29,30 @@
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database en sessionData con la id '. $id);
 | 
			
		||||
 | 
			
		||||
			return $resul;
 | 
			
		||||
		}
 | 
			
		||||
		}	
 | 
			
		||||
		
 | 
			
		||||
		//Returns a query to check if the session in this cinema, hall and scheudle exists.
 | 
			
		||||
		public function selectSession($cinema, $hall, $start, $date){
 | 
			
		||||
			if($start == null){	
 | 
			
		||||
				$sql = sprintf( "SELECT * FROM session WHERE 
 | 
			
		||||
							idcinema = '%s' AND idhall = '%s' AND date = '%s'", 
 | 
			
		||||
							$cinema, $hall, $date);			
 | 
			
		||||
			}else{
 | 
			
		||||
				$sql = sprintf( "SELECT * FROM session WHERE 
 | 
			
		||||
		//Returns the count of the session searched
 | 
			
		||||
		public function searchSession($cinema, $hall, $startTime, $date){
 | 
			
		||||
			$date = date('Y-m-d', strtotime( $date ) ); 
 | 
			
		||||
			$startTime = date('H:i:s', strtotime( $startTime ) );
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "SELECT COUNT(*) FROM session WHERE 
 | 
			
		||||
							idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'", 
 | 
			
		||||
							$cinema, $hall, $date, $start);	
 | 
			
		||||
			}
 | 
			
		||||
							$cinema, $hall, $date, $startTime);	
 | 
			
		||||
			$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
 | 
			
		||||
			return $resul;
 | 
			
		||||
			
 | 
			
		||||
			$session = null;
 | 
			
		||||
			$session = mysqli_fetch_array($resul);
 | 
			
		||||
			
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $session[0];
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		public function getAllSessionsFromDateHallAndCinema($cinema, $hall, $date){
 | 
			
		||||
		//Returns a query to get all the session's data.
 | 
			
		||||
		public function getAllSessionsFromACinemaHallDate($cinema, $hall, $date){
 | 
			
		||||
			$date = date('Y-m-d', strtotime( $date ) ); 
 | 
			
		||||
			
 | 
			
		||||
			$sql = sprintf( "SELECT * FROM session WHERE 
 | 
			
		||||
							idcinema = '%s' AND idhall = '%s' AND date = '%s'", 
 | 
			
		||||
							$cinema, $hall, $date);	
 | 
			
		||||
@@ -58,15 +63,16 @@
 | 
			
		||||
			while($fila=mysqli_fetch_array($resul)){
 | 
			
		||||
				$sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"]);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			mysqli_free_result($resul);
 | 
			
		||||
			
 | 
			
		||||
			return $sessions;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Edit Session.
 | 
			
		||||
        public function editSession($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( "UPDATE `session`
 | 
			
		||||
                             SET `idfilm` = '%d' , `idhall` = '%d', `idcinema` = '%d', `date` = '%s',
 | 
			
		||||
                                  `start_time` = '%s', `seat_price` = '%d', `format` = '%s'
 | 
			
		||||
@@ -78,7 +84,6 @@
 | 
			
		||||
            return $resul;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //Delete Session.
 | 
			
		||||
        public function deleteSession($id){
 | 
			
		||||
 | 
			
		||||
            $sql = sprintf( "DELETE FROM `session` WHERE `session`.`id` = '%d';",$id);
 | 
			
		||||
@@ -88,7 +93,6 @@
 | 
			
		||||
            return $resul;
 | 
			
		||||
        }
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		//Create a new Session Data Transfer Object.
 | 
			
		||||
		public function loadSession( $id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
 | 
			
		||||
			return new SessionDTO( $id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format);
 | 
			
		||||
 
 | 
			
		||||
@@ -4,14 +4,14 @@
 | 
			
		||||
    class SessionDTO  implements SessionsDTO {
 | 
			
		||||
 | 
			
		||||
        //Attributes:
 | 
			
		||||
        private $_id;           //Session Id.
 | 
			
		||||
        private $_idfilm;       //Film Id  -> deberia ser un objeto tipo pelicula? para poder sacar el nombre de la pelicula en cuestion
 | 
			
		||||
        private $_idhall;       //Hall id  -> deberia ser un objeto tipo room/hall/sala de cine por lo mismo
 | 
			
		||||
        private $_id;          
 | 
			
		||||
        private $_idfilm;
 | 
			
		||||
        private $_idhall;
 | 
			
		||||
		private $_idcinema;			
 | 
			
		||||
        private $_date;         //Session date.
 | 
			
		||||
        private $_startTime;    //Session start time.
 | 
			
		||||
        private $_seatPrice;    //Seat price.
 | 
			
		||||
        private $_format;       //Type of film: 3D | 4D | normal | subtitle | mute.
 | 
			
		||||
        private $_date;
 | 
			
		||||
        private $_startTime;
 | 
			
		||||
        private $_seatPrice;
 | 
			
		||||
        private $_format;
 | 
			
		||||
 | 
			
		||||
		//Constructor:
 | 
			
		||||
        function __construct($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,8 @@
 | 
			
		||||
		public function getIdfilm();
 | 
			
		||||
        public function setIdhall($film);
 | 
			
		||||
		public function getIdhall();
 | 
			
		||||
		public function setIdcinema($cinema);
 | 
			
		||||
		public function getIdcinema();
 | 
			
		||||
		public function setDate($date);
 | 
			
		||||
		public function getDate();
 | 
			
		||||
		public function setStartTime($startTime);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user