The exercise I am doing is to make an interface of a theater which contains 5 rows and 5 seats or chairs. the user can make a series of actions between which they are Book, Release and Buy ("R", "L" and "V").
Well the problem is this: when choosing the action either "R", "V" or "L", the arrangement is modified but only the first time, the second time it restarts again, what I want is that for each action you choose, those new actions or states that this user adds are saved.
The way in which you are going to modify and create the fix should only be with PHP and without using global variables since in the exercise I am doing this is specified. Your opinions would be very helpful thanks.
Code:
styles.min.css
input,input:hover{color:#fff!important}td,th{padding:8px;border-bottom:1px solid #fff}body{font-family:Arial,Helvetica,sans-serif}table{font-family:"Lucida Sans Unicode","Lucida Grande",Sans-Serif;font-size:12px;width:280px}th{font-size:13px;font-weight:400;background:#b9c9fe;border-top:4px solid #aabcfe;color:#039}td{background:#e8edff;color:#669;border-top:1px solid transparent}tr:hover td{background:#d0dafd;color:#339}select:invalid{box-shadow:0 0 5px 1px red}select:focus:invalid{outline:0}input{border-radius:4px;font-size:15px;margin:10px;display:inline-block;padding:10px 20px;background:#4299ef;box-shadow:0 15px 20px -10px transparent,inset 0 -2px 0 0 rgba(0,0,0,.2),inset 0 -16px 25px 0 #3273b3;transition:all .3s ease-in-out}input:hover{text-decoration:none;box-shadow:0 0 0 0 transparent,inset 0 -1px 0 0 rgba(0,0,0,.1),inset 0 10px 15px 5px #377dc3}
index.php
<?php
include_once 'interfaz.php';
include_once 'transaccion.php';
$listaEstados = array
(
array("L", "L", "L", "L", "L"),
array("L", "L", "L", "L", "L"),
array("L", "L", "L", "L", "L"),
array("L", "L", "L", "L", "L"),
array("L", "L", "L", "L", "L"),
);
$listaAcciones = array
(
"R" => "Reservar",
"V" => "Comprar",
"L" => "Liberar",
);
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="estilos.min.css">
<title>Ejercicio 4</title>
</head>
<body>
<br>
<br>
<table align="center">
<form method="post">
<tr>
<td>
<label for="fila">Fila:</label>
<select name="fila" id="fila" required>
<?php echo interfaz::Filas($listaEstados); ?>
</select>
</td>
<tr>
<td>
<label for="puesto">Puesto:</label>
<select name="puesto" id="puesto" required>
<?php echo interfaz::Puestos($listaEstados); ?>
</select>
</td>
</tr>
<tr>
<td>
<label for="acciones">Accion:</label>
<select name="accion" id="accion" required>
<?php echo interfaz::Acciones($listaAcciones); ?>
</select>
</td>
</tr>
<tr>
<td>
<input name="submit" type="submit" value="Enviar">
<input name="reset" type="reset" value="Actualizar">
</td>
</tr>
</tr>
</form>
</table>
</body>
</html>
interface.php
<?php
class interfaz {
public function mostrarInterfaz($listaEstados){
$interfaz = '
<table border="4" align="center">
<tbody>
<tr>
<th colspan="6">TEATRO</th>
</tr>
<tr>
<th></th>';
foreach ($listaEstados as $indice => $valor) {
$interfaz .= '<th>' . ($indice + 1) . '</th>';
}
foreach ($listaEstados as $indice1 => $valor) {
$interfaz .= '<tr><th>' . ($indice1 + 1) . '</th>';
foreach ($listaEstados as $indice2 => $valor) {
$interfaz .= '<td align="center">' . $listaEstados[$indice1][$indice2] . '</td>';
}
}
$interfaz .= '</tr></tr></tbody></thead></table>';
return $interfaz;
}
public function Filas($listaEstados){
$fila = '<option value="">Seleccione ...</option>';
foreach ($listaEstados as $indice => $valor) {
$fila .= '<option value="' . $indice . '">' . ($indice + 1) . '</option>';
}
return $fila;
}
public function Puestos($listaEstados){
$puesto = '<option value="">Seleccione ...</option>';
foreach ($listaEstados as $indice => $valor) {
$puesto .= '<option value="' . $indice . '">' . ($indice + 1) . '</option>';
}
return $puesto;
}
public function Acciones($listaAcciones){
$accion = '<option value="">Seleccione ...</option>';
foreach ($listaAcciones as $indice => $valor) {
$accion .= '<option value="' . $indice . '">' . $valor . '</option>';
}
return $accion;
}
}
transaction.php
<?php
class transaccion {
public function cambiarEstado($listaEstados, $fila, $puesto, $accion){
if ($listaEstados[$fila][$puesto] == "L") {
if ($accion == "V" || $accion == "R") {
$listaEstados[$fila][$puesto] = $accion;
} else if ($accion == "L") {
echo "<script>
alert('Este puesto no se puede volver a liberar');
</script>";
}
} else if ($listaEstados[$fila][$puesto] == "R") {
if ($accion == "V" || $accion == "L") {
$listaEstados[$fila][$puesto] = $accion;
} else if ($accion == "R") {
echo "<script>
alert('Este puesto no se puede volver a reservar');
</script>";
}
} else if ($listaEstados[$fila][$puesto] == "V") {
echo "<script>
alert('Este puesto ya está vendido');
</script>";
if ($accion == "R") {
echo "<script>
alert('Este puesto no se puede reservar');
</script>";
} else if ($accion == "L") {
echo "<script>
alert('Este puesto no se puede liberar');
</script>";
} else if ($accion == "V") {
echo "<script>
alert('Este puesto no se puede volver a vender');
</script>";
}
}
echo interfaz::mostrarInterfaz($listaEstados);
}
}