Add files via upload

This commit is contained in:
Markines16 2021-04-11 19:55:21 +02:00 committed by GitHub
parent 68860539da
commit 94c7940cc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 147 additions and 75 deletions

View File

@ -2,6 +2,7 @@
require('./includes/room_dto.php');
require('./includes/session_dto.php');
require('../panel_admin/includes/film_dto.php');
include_once('./includes/session_dao.php');
$r1 = new RoomDTO(1,20,20,30); //Esto se deberia cambiar por una llamada a una lista de salas
$r2 = new RoomDTO(2,10,30,30);
@ -11,10 +12,66 @@
$filmList = new ListFilms();
$films = $filmList->getArray();
//DISCLAIMER; sabemos que si se edita la ulr se pueden acceder a datos de una sesion que no pertenece al usuario y que incluso puede hasta editarlas/borrarlas en la base de datos
if(isset($_REQUEST['option']) && $_REQUEST['option'] == 'edit') {
echo "<p> Este es el panel de editar o eliminar una sesion. Deberia tener el formulario de crear una sesion nueva pero con los datos ya situados y quizas que solo aqui aparezca el boton de eliminar </p>";
}
$bd = new sessionDAO('complucine');
if($bd){
$session = ($bd->sessionData($_GET["id"]))->fetch_assoc();
echo "<h2>Editar/Eliminar Sesion</h2>
<form method=\"post\" id=\"new_ses\" action=\"validate.php\">
<div class=\"row\">
<fieldset id=\"datos\">
<legend>Datos</legend>
<input type=\"hidden\" name=\"cinema\" value =\"1\" />
<input type=\"hidden\" name=\"id\" value =\"". $_GET["id"] ." \" />
<div class=\"_price\">
<input type=\"number\" name=\"price\" id=\"price\" value=\"". $session['seat_price'] ."\"min=\"0\" placeholder=\"Precio de la entrada\" required/>
</div>
<select name=\"hall\" class=\"button large\">";
foreach($rooms as $r){
if($r->getid() == $session['idhall']){
echo "<option value=\"". $r->getid() ." \"selected> Sala ". $r->getid() . "</option>";
}else{
echo "<option value=\"". $r->getid() ." \"> Sala ". $r->getid() . "</option>";
}
}
echo "<div class=\"_format\">
<input type=\"text\" name=\"format\" id=\"format\" value=\"". $session['format'] ."\" placeholder=\"Formato\" required/>
</div>
</fieldset>
<fieldset id=\"Horario\">
<legend>Horario</legend>
<div class=\"_start_time\">
<input type=\"time\" name=\"start\" id=\"start_time\" value=\"". $session['start_time'] ."\" placeholder=\"Hora de inicio\" required/>
</div>
<div class=\"_date\">
<input type=\"date\" name=\"date\" id=\"date\" value=\"". $session['date'] ."\"Fecha de inicio\" required/>
</div>
<div class=\"_repeat\">
<br> Introducir un numero para añadir esta sesion a los futuros X dias
<input type=\"number\" name=\"repeat\" id=\"repeat\" title=\"Repetir esta sesion durante X dias\" min=\"0\" max=\"31\" placeholder=\"Repetir X dias\"/>
</div>
</fieldset>
<div class=\"actions\">
<input type=\"submit\" name=\"edit\" value=\"Editar\" class=\"primary\" />
<input type=\"reset\" id=\"reset\" value=\"Limpiar\" />
<input type=\"submit\" name=\"del\" value=\"Eliminar\" class=\"primary\" />
</div>
</div>
</form>
<div>
<div class=\"column side\">
<select name=\"film\" form=\"new_ses\" class=\"button large\">";
foreach($films as $f){
if($f->getId() == $session['idfilm']){
echo "<option value=\"". $f->getId() ." \"selected> " . $f->getId() . "|" . $f->getTittle() ." Idioma: " . $f->getLanguage() . "</option>";
}else{
echo "<option value=\"". $f->getId() ." \"> " . $f->getId() . "|" . $f->getTittle() ." Idioma: " . $f->getLanguage() . "</option>";
}
}
echo "</div>";
}
}
else{
echo "<h2>Crear Sesion</h2>
<form method=\"post\" id=\"new_ses\" action=\"validate.php\">
@ -45,10 +102,14 @@
<div class=\"_date\">
<input type=\"date\" name=\"date\" id=\"date\" value=\"". $_POST['date'] . "\"Fecha de inicio\" required/>
</div>
<div class=\"_repeat\">
<br> Introducir un numero para añadir esta sesion a los futuros X dias
<input type=\"number\" name=\"repeat\" id=\"repeat\" title=\"Repetir esta sesion durante X dias\" min=\"0\" max=\"31\" placeholder=\"Repetir X dias\"/>
</div>
</fieldset>
<div class=\"actions\">
<input type=\"submit\" id=\"submit\" value=\"Añadir\" class=\"primary\" />
<input type=\"reset\" id=\"reset\" value=\"Borrar\" />
<input type=\"submit\" name=\"new\" value=\"Añadir\" class=\"primary\" />
<input type=\"reset\" id=\"reset\" value=\"Limpiar\" />
</div>
</div>
</form>

View File

@ -8,7 +8,7 @@ class FormSession extends Form {
//Atributes:
private $correct; // Indicates if the session is correct.
private $reply; // Validation response
private $option;
//Constructor:
public function __construct() {
parent::__construct('formSession');
@ -22,9 +22,19 @@ class FormSession extends Form {
//Habria que comprobar si realmente se ha validado la respuesta antes de escribir una respuesta correcta
if($this->correct){
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
if($this->option == "new"){
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
<p> Se ha añadido la sesion correctamente en la base de datos.</p>
<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
}else if($this->option == "edit"){
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
<p> Se ha editado la sesion correctamente en la base de datos.</p>
<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
}else if($this->option == "del"){
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
<p> Se ha eliminado la sesion correctamente en la base de datos.</p>
<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
}
} else {
$this->reply = "<h1> ERROR </h1><hr />
<p> Ha habido un error en la operacion. Revisa los datos introducidos o ponte en contacto con el administrador de la base de datos.</p>
@ -35,26 +45,39 @@ class FormSession extends Form {
}
//Process form:
public function processesForm($film, $hall, $cinema, $date, $start, $price, $format) {
public function processesForm($id, $film, $hall, $cinema, $date, $start, $price, $format, $repeat, $option) {
$this->correct = true;
$this->option = $option;
//Habria que validar todo para que encaje en la base de datos
$start = date('H:i:s', strtotime( $start ) );
$date = date('Y-m-d', strtotime( $date ) );
$bd = new sessionDAO('complucine');
if($bd){
$selectSession = $bd->selectSession($cinema, $hall, $start, $date);
if($selectSession && $selectSession->num_rows >= 1) {
$this->correct = false;
} else{
$bd->createSession(null, $film, $hall,$cinema, $date, $start, $price, $format);
if($bd ){
if($option == "new"){
$selectSession = $bd->selectSession($cinema, $hall, $start, $date);
if($selectSession && $selectSession->num_rows >= 1) {
$this->correct = false;
} else{
$bd->createSession(null, $film, $hall,$cinema, $date, $start, $price, $format);
}
mysqli_free_result($selectSession);
} else if ($option == "del"){
$bd->deleteSession($id);
} else if ($option == "edit"){
$bd->editSession($id, $film, $hall, $cinema, $date, $start, $price, $format);
}
mysqli_free_result($selectSession);
}
if($repeat > "0"){
$repeat--;
$date = date('Y-m-d', strtotime( $date. ' +1 day') );
$this->processesForm($film, $hall, $cinema, $date, $start, $price, $format, $repeat);
}
} else {$this->correct = false;}
}
}

View File

@ -15,7 +15,7 @@
public function createRoom($id, $idcinema, $numCol, $numRows){
$sql = sprintf( "INSERT INTO rooms( id, idcinema, numCol, numRows)
VALUES ( '%d', '%d', '%i', '%i')",
VALUES ( '%s', '%s', '%i', '%i')",
$id, $idcinema, $numCol, $numRows );
return $sql;
@ -34,29 +34,6 @@
return new RoomDTO($id, $idcinema, $numCol, $numRows);
}
//Edit Hall.
public function editHall($id, $idcinema, $numCol, $numRows){
$sql = sprintf( "UPDATE `hall`
SET `numrows` = '%i' , `numcolumns` = '%i'
WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';",
$numRows,$numCol,$id, $idcinema );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Delete Hall.
public function deleteHall($id, $idcinema){
$sql = sprintf( "DELETE FROM `hall` WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';",$id,$idcinema);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
}
?>

View File

@ -26,31 +26,7 @@
//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');
return $resul;
}
//Edit Session.
public function editSession($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
$sql = sprintf( "UPDATE `session`
SET `idfilm` = '%d' , `idhall` = '%d', `idcinema` = '%d', `date` = '%s',
`start_time` = '%s', `seat_price` = '%d', `format` = '%s'
WHERE `session`.`id` = '%d';",
$idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Delete Session.
public function deleteSession($id){
$sql = sprintf( "DELETE FROM `session` WHERE `session`.`id` = '%d'",$id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database en sessionData con la id '. $id);
return $resul;
}
@ -70,6 +46,29 @@
return $resul;
}
//Edit Session.
public function editSession($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
$sql = sprintf( "UPDATE `session`
SET `idfilm` = '%d' , `idhall` = '%d', `idcinema` = '%d', `date` = '%s',
`start_time` = '%s', `seat_price` = '%d', `format` = '%s'
WHERE `session`.`id` = '%d';",
$idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Delete Session.
public function deleteSession($id){
$sql = sprintf( "DELETE FROM `session` WHERE `session`.`id` = '%d';",$id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Create a new Session Data Transfer Object.

View File

@ -60,10 +60,10 @@
$fila = ($bd->FilmData($s->getIdfilm()))->fetch_assoc();
echo "
<tr>
<td><a href=\"./?state=edit_session&option=edit\">" . $s->getStartTime() . "</a></td>
<td><a href=\"./?state=edit_session&option=edit\">" .$fila['tittle'] . "</a></td>
<td><a href=\"./?state=edit_session&option=edit\">" . $s->getFormat() . "</a></td>
<td><a href=\"./?state=edit_session&option=edit\">". $s->getSeatPrice() . "</a></td>
<td> <a href=\"./?state=edit_session&option=edit\">" . $s->getStartTime() . "</a></td>
<td> <a href=\"./?state=edit_session&option=edit\">" .$fila['tittle'] . "</a></td>
<td> <a href=\"./?state=edit_session&option=edit\">". $s->getSeatPrice() . "</a></td>
<td> <input type=\"submit\" name=\"submit\" value=\"Editar\" class=\"button\" formaction=\"./?state=edit_session&option=edit&id=". $s->getid() ."\"/> </td>
</tr>";
}
echo "
@ -75,8 +75,9 @@
if($bd){
drawSessions($sessions,$bd);
echo "
<input type=\"submit\" name=\"submit\" value=\"Añadir\" class=\"button large\" formaction=\"./?state=edit_session&option=new\"/>\n";
<input type=\"submit\" name=\"submit\" value=\"Añadir\" class=\"button large\" formaction=\"./?state=edit_session&option=new\">";
}
}
echo " </form>
</div>";

View File

@ -9,11 +9,22 @@
//HTML template:
require_once('../assets/php/template.php');
$template = new Template();
$action ="";
$id = null;
if(isset($_POST['new'])){
$action = "new";
} else if (isset($_POST['edit'])){
$action = "edit";
$id = $_POST["id"];
} else if (isset($_POST['del'])){
$action = "del";
$id = $_POST["id"];
}
//Login form validate:
require_once('./includes/formSession.php');
$session = new FormSession();
$session->processesForm($_POST["film"], $_POST["hall"], $_POST["cinema"],$_POST["date"],$_POST["start"],$_POST["price"],$_POST["format"]);
$session->processesForm($id, $_POST["film"], $_POST["hall"], $_POST["cinema"],$_POST["date"],$_POST["start"],$_POST["price"],$_POST["format"],$_POST["repeat"], $action);
$reply = $session->getReply();
?>