Add files via upload

This commit is contained in:
Fernando Méndez 2021-05-08 15:17:51 +02:00 committed by GitHub
parent 3e48951b90
commit 8b4ed63f9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 186 additions and 67 deletions

View File

@ -1,3 +1,124 @@
<?php <?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;
session_start();
$this->inicializada = true;
}
}
/**
* 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;
}
}

View File

@ -31,4 +31,17 @@
require_once('template.php'); require_once('template.php');
$template = new Template(); $template = new Template();
$prefix = $template->get_prefix(); $prefix = $template->get_prefix();
/**
* Initialize the application:
*/
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'));
?> ?>

View File

@ -1,37 +1,24 @@
<?php <?php
// TO-DO: Completar
class DAO { class DAO {
//Constants:
private const _SERVERNAME = BD_HOST;
private const _USERNAME = BD_USER;
private const _PASSWORD = BD_PASS;
private const _BD = BD_NAME;
//Atributes: //Atributes:
public $mysqli; public $mysqli;
//Constructor: //Constructor:
public function __construct($bd_name){ public function __construct($bd_name){
if($bd_name == null) $bd_name = self::_BD; if($bd_name != BD_NAME) {
try{ echo "Está intentando acceder a una base de datos que no existe, puede que la aplicación no funcione correctamente";
if (!$this->mysqli) {
$this->mysqli = new mysqli(self::_SERVERNAME, self::_USERNAME,
self::_PASSWORD, $bd_name);
}
// echo "Conexión a la BD, satisfactoria.";
} catch (Exception $e){
echo "Error de conexión a la BD: ". mysqli_connect_error();
exit();
} }
$app = Aplicacion::getSingleton();
/* ... */ $this->mysqli = $app->conexionBd();
} }
//Destructor: //Destructor (Ya no es necesdario):
/*
public function __destruct(){ public function __destruct(){
$this->mysqli->close(); $this->mysqli->close();
} }
*/
//Methods:
} }
?> ?>

View File

@ -2,7 +2,7 @@
class Template { class Template {
//Constants: //Constants:
private const _NUMPAGES = 10; //private const _NUMPAGES = 10; //Constant to page results.
//Attributes: //Attributes:
public $page; //Page Name. public $page; //Page Name.
@ -403,6 +403,7 @@
} }
//Print Cinemas info:
function print_cinemas(){ function print_cinemas(){
//List of the cinemas: //List of the cinemas:
require_once(__DIR__.'/common/cinema_dao.php'); require_once(__DIR__.'/common/cinema_dao.php');
@ -423,6 +424,7 @@
$phones[$key] = $value->getPhone(); $phones[$key] = $value->getPhone();
} }
} }
switch($this->page){ switch($this->page){
case "Panel de Administrador": case "Panel de Administrador":
echo "<div class='row'> echo "<div class='row'>
@ -439,46 +441,47 @@
</thead> </thead>
<tbody> <tbody>
"; ";
if(is_array($cinemas)){ if(is_array($cinemas)){
for($i = 0; $i < count($cinemas); $i++){ for($i = 0; $i < count($cinemas); $i++){
echo '<tr> echo '<tr>
<td>'. $ids[$i] .'</td> <td>'. $ids[$i] .'</td>
<td>'. $names[$i] .'</td> <td>'. $names[$i] .'</td>
<td>'. $directions[$i] .'</td> <td>'. $directions[$i] .'</td>
<td>'. $phones[$i] .'</td> <td>'. $phones[$i] .'</td>
<td> <td>
<form method="post" action="index.php?state=mc"> <form method="post" action="index.php?state=mc">
<input name="id" type="hidden" value="'.$ids[$i].'"> <input name="id" type="hidden" value="'.$ids[$i].'">
<input name="name" type="hidden" value="'.$names[$i].'"> <input name="name" type="hidden" value="'.$names[$i].'">
<input name="direction" type="hidden" value="'.$directions[$i].'"> <input name="direction" type="hidden" value="'.$directions[$i].'">
<input name="phone" type="hidden" value="'.$phones[$i].'"> <input name="phone" type="hidden" value="'.$phones[$i].'">
<input type="submit" id="submit" value="Editar" name="edit_cinema" class="primary" /> <input type="submit" id="submit" value="Editar" name="edit_cinema" class="primary" />
</form> </form>
</td> </td>
<td> <td>
<form method="post" action="index.php?state=mc"> <form method="post" action="index.php?state=mc">
<input name="id" type="hidden" value="'.$ids[$i].'"> <input name="id" type="hidden" value="'.$ids[$i].'">
<input name="name" type="hidden" value="'.$names[$i].'"> <input name="name" type="hidden" value="'.$names[$i].'">
<input name="direction" type="hidden" value="'.$directions[$i].'"> <input name="direction" type="hidden" value="'.$directions[$i].'">
<input name="phone" type="hidden" value="'.$phones[$i].'"> <input name="phone" type="hidden" value="'.$phones[$i].'">
<input type="submit" id="submit" value="Eliminar" name="delete_cinema" class="primary" /> <input type="submit" id="submit" value="Eliminar" name="delete_cinema" class="primary" />
</form> </form>
</td> </td>
</tr> </tr>
'; ';
} }
} }
echo'</tbody> echo'</tbody>
</table> </table>
</div> </div>
<div class="column side"></div> <div class="column side"></div>
'; ';
break; break;
default: break;
} }
} }
//Print session MSG: //Print session MSG:
function print_msg() { function print_msg() {
if(isset($_SESSION['message'])){ if(isset($_SESSION['message'])){

View File

@ -113,7 +113,7 @@ class FormFilm extends Form {
if(!empty($tittle)&&$duration>0&&!empty($language)&&!empty($description)){ if(!empty($tittle)&&$duration>0&&!empty($language)&&!empty($description)){
// comprobar si existe una pelicula con el mismo titulo e idioma // comprobar si existe una pelicula con el mismo titulo e idioma
$exist = $bd-> GetFilm($tittle,$language); $exist = $bd-> GetFilm($tittle,$language);
if( mysqli_num_rows($exist) != 0){ if(mysqli_num_rows($exist) != 0){
$this->correct =false; $this->correct =false;
} }
else{ else{

View File

@ -34,9 +34,6 @@
}; };
break; break;
case 'mf': require_once('manage_films.php'); case 'mf': require_once('manage_films.php');
//echo $_SERVER['DOCUMENT_ROOT']."/../img";
echo TMP_DIR;
//echo $_SERVER['PHP_SELF'];
if(isset($_POST['edit_film'])) { if(isset($_POST['edit_film'])) {
editFilm(); editFilm();
} }

View File

@ -1,9 +1,7 @@
<!DOCTYPE HTML> <!DOCTYPE HTML>
<?php <?php
//ini_set('display_errors', 0);
//error_reporting(E_ERROR | E_WARNING | E_PARSE);
//General Config File: //General Config File:
require_once('../assets/php/config.php'); require_once('../assets/php/config.php');
//Controller file: //Controller file:
include_once('panel_manager.php'); include_once('panel_manager.php');

View File

@ -1,6 +1,6 @@
<?php <?php
include_once('../assets/php/common/hall.php'); include_once($prefix.'assets/php/common/hall.php');
include_once('../assets/php/common/session.php'); include_once($prefix.'assets/php/common/session.php');
include_once('./includes/formHall.php'); include_once('./includes/formHall.php');
include_once('./includes/formSession.php'); include_once('./includes/formSession.php');