include 'teatro2.php';
include 'inputs.php';
$teatro = new DBHelper();
$user = Inputs::usuarioValido($_SESSION['usuario']);
if ($user == "error") {
    header('Location:errorLogueado.php');
}
$datos = $teatro->buscar_user($user);
foreach ($datos as $row) {
    $row2 = $row["rol"];
}
if (isset($_REQUEST['operacion'])) {
    $operacion = $_REQUEST['operacion'];
}
if (isset($_REQUEST['id'])) {
    $id = Inputs::numeroValido($_REQUEST['id']);
    if ($id == "error") {
        header('Location:errorLogueado.php');
    }
}
if (isset($operacion)) {
    if ($operacion == "introducir") {
        header('Location:nuevoTeatro.php');
    } else {
        if ($operacion == "borrar") {
            $teatro = new DBHelper();
            $teatro->del_teatro($id);
            header('Location:index2.php');
        } else {
            if ($operacion == "buscar") {
                $busqueda = Inputs::nombreObraValido($_POST['busqueda']);
    $operacion = $_REQUEST['operacion'];
}
if (isset($_REQUEST['editarVal'])) {
    $editar = Inputs::numeroBoolValido($_REQUEST['editarVal']);
    if ($editar == "error") {
        header('Location:errorLogueado.php');
    }
}
if (isset($_REQUEST['fecha'])) {
    $fecha = Inputs::fechaValido($_REQUEST['fecha']);
    if ($fecha == "error") {
        header('Location:errorLogueado.php');
    }
}
if (isset($_REQUEST['t'])) {
    $t = Inputs::numeroValido($_REQUEST['t']);
    if ($t == "error") {
        header('Location:errorLogueado.php');
    }
}
if (isset($operacion)) {
    if ($operacion == "guardar") {
        $teatro = new DBHelper();
        $comentario = Inputs::comentarioValido($_POST['comentario']);
        echo $comentario;
        if ($comentario == 'error') {
            header('Location:errorLogueado.php');
        } else {
            $datosTeatro = $teatro->consulta($t);
            //consulta recibe el id del teatro
            foreach ($datosTeatro as $doc) {
    $operacion = $_REQUEST['operacion'];
}
if (isset($_REQUEST['i'])) {
    $i = Inputs::numeroValido($_REQUEST['i']);
    if ($i == "error") {
        header('Location:errorLogueado.php');
    }
}
if (isset($_REQUEST['j'])) {
    $j = Inputs::numeroValido($_REQUEST['j']);
    if ($j == "error") {
        header('Location:errorLogueado.php');
    }
}
if (isset($_REQUEST['bus'])) {
    $bus = Inputs::numeroValido($_REQUEST['bus']);
    if ($bus == "error") {
        header('Location:errorLogueado.php');
    }
}
if (isset($_REQUEST['dia'])) {
    $dia = Inputs::fechaValido($_REQUEST['dia']);
    if ($dia == "error") {
        header('Location:errorLogueado.php');
    }
}
if (isset($_REQUEST['sesion'])) {
    $sesion = Inputs::sesionValido($_REQUEST['sesion']);
    if ($sesion == "error") {
        header('Location:errorLogueado.php');
    }
if (isset($_REQUEST['operacion'])) {
    $operacion = $_REQUEST['operacion'];
}
if (isset($operacion)) {
    if ($operacion == "añadir") {
        $teatro = new DBHelper();
        $num_obras = $teatro->nume_obras();
        $id_obra = (string) $num_obras;
        $nombreObra = Inputs::nombreObraValido($_POST['nombreObra']);
        $nombreTeatro = Inputs::nombreTeatroValido($_POST['nombreTeatro']);
        $descripcion = Inputs::descripcionValido($_POST['descripcion']);
        $sesion1 = Inputs::sesionValido($_POST['sesion1']);
        $sesion2 = Inputs::sesionValido($_POST['sesion2']);
        $sesion3 = Inputs::sesionValido($_POST['sesion3']);
        $filas = Inputs::numeroValido($_POST['filas']);
        $asientos = Inputs::numeroValido($_POST['asientos']);
        if ($nombreObra != "error" and $asientos != "error" and $nombreTeatro != "error" and $descripcion != "error" and $sesion1 != "error" and $sesion2 != "error" and $sesion3 != "error" and $filas != "error") {
            $teatro->add_teatro($id_obra, $nombreObra, $nombreTeatro, $descripcion, $sesion1, $sesion2, $sesion3, $filas, $asientos);
            header('Location:index2.php');
        } else {
            header('Location:errorLogueado.php');
        }
    }
}
echo "<CENTER><P>\n\t  <TABLE border='0' width='600'>\n\t  <TR>\n\t     <TD valign=top align=CENTER colspan=2>";
if ($row2 == 'user') {
    echo "<FORM name='form1' METHOD='POST' ACTION='index2.php?operacion=buscar'>\n\t\t\t\t<input type='hidden' name='token' value='{$token}' />\n\t     \t    <b>Buscar teatro </b>";
    if (!isset($busqueda)) {
        $busqueda = "";
    }
    echo "<INPUT TYPE='TEXT' NAME='busqueda' value='{$busqueda}' size='20'> ";