if ($password == "error") {
            header('Location:error.php');
        } else {
            $pass = $password;
            $pass = $pass . $sal;
            $pass = hash('sha256', $pass, false);
            $teatro = new DBHelper();
            $nombreUsuario = Inputs::usuarioValido($_POST['nombreUsuario']);
            $nombre = Inputs::nombreUsuarioValido($_POST['nombre']);
            $apellidos = Inputs::apellidosValido($_POST['apellidos']);
            $dni = Inputs::dniValido($_POST['dni']);
            $correo = Inputs::correoValido($_POST['correo']);
            $rol = Inputs::validaRol($_POST['rol']);
            //$sal = $teatro->get_sal($nombreUsuario);
            if ($nombreUsuario != "error" and $nombre != "error" and $apellidos != "error" and $dni != "error" and $correo != "error" and $rol != "error") {
                if ($teatro->add_user($nombreUsuario, $nombre, $apellidos, $dni, $correo, $pass, $sal, $rol)) {
                    header('Location:indexx.php');
                } else {
                    echo "El DNI introducido ya existe";
                }
            } else {
                header('Location:error.php');
            }
        }
    }
}
echo "<CENTER><P>\n\t \n\t  <CENTER><FONT  COLOR= 'green'><b><h2>Registro</b></h2> </FONT></CENTER>\n\t  <CENTER>\n\t  <FORM name = 'registro' method='post' enctype='multipart/form-data' ACTION='registro.php?operacion=añadir'>\n\t  <TABLE border='0' width='600' cellspacing='10' >\n\t        \n\t\t\t\n\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green' >Usuario</FONT> </TD>\n\t\t\t<TD><INPUT TYPE='text' title ='Introduzca un nombre de usuario'  required NAME='nombreUsuario' VALUE='' SIZE='50'  MAXLENGTH='30'></TD></TR>\n\n\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green'>Nombre</FONT> </TD>\n\t\t\t<TD><INPUT TYPE='text' title ='Introduzca nombre' NAME='nombre' required VALUE='' SIZE='50'  MAXLENGTH='50'></TD></TR>\n\n\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green'>Apellidos</FONT> </TD>\n\t\t\t<TD><INPUT TYPE='text' NAME='apellidos' VALUE='' SIZE='50'  required MAXLENGTH='50'></TD></TR>\n\n\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green' >DNI</FONT> </TD>\n\t\t\t<TD><INPUT TYPE='text' title ='Introduzca su DNI' NAME='dni' VALUE='' required SIZE='50'  MAXLENGTH='10'></TD></TR>\n\n\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green'>Correo</FONT> </TD>\n\t\t\t<TD><INPUT TYPE='text' title ='Introduzca su email' NAME='correo' VALUE='' required SIZE='50'  MAXLENGTH='50'></TD></TR>\n\n\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green' >Contraseña</FONT> </TD>\n\t\t\t<TD><INPUT TYPE='password' NAME='password' VALUE='' SIZE='50' required  MAXLENGTH='20'></TD></TR>\n\t\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green' >Elija su Rol</FONT> </TD> \n\t\t\t\t<td><select name='rol' >\n\t\t\t\t\t\n\t\t\t\t\t<option  value='admin'>Administrador\n\t\t\t\t\t<option selected value='user'>Cliente\n\t\t\t\t\t</select> \n\t\t\t\t</td></TR>\n\n\n\t\t\t<TR><TD width='150'> <b>Todos los campos son obligatorios</b></TD></TR>\n\t\t\t</BR>\t\t\n\t</TABLE>\n\n\t<INPUT TYPE='SUBMIT' VALUE='Registrarme'>\n\t</FORM>\n\t</CENTER>";
?>
	
		<input type="button" value="Volver" onClick="location='indexx.php'"/>
</BODY>
	  border-width : 1;
	  background-color : #FFFFFF;
	}
   -->
   </style>
</HEAD>

<BODY bgcolor="#C0C0C0" link="green" vlink="green" alink="green">
<BASEFONT face="arial, helvetica">

<TABLE border="0" align="center" cellspacing="3" cellpadding="3" width="1000">
<TR><TH colspan="2" width="100%" bgcolor="green"><FONT size="6" color="white">Teatros</FONT></TH>
</TR></TABLE><P>

<?php 
include 'teatro2.php';
if (isset($_REQUEST['operacion'])) {
    $operacion = $_REQUEST['operacion'];
}
echo "<CENTER><P>\n\t \n\t  <CENTER><FONT  COLOR= 'green'><b><h2>Registro</b></h2> </FONT></CENTER>\n\t  <CENTER>\n\t  <FORM name = 'registro' method='post' enctype='multipart/form-data' ACTION='registro.php?operacion=añadir'>\n\t  <TABLE border='0' width='600' cellspacing='10' >\n\t        \n\t\t\t\n\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green' >Usuario</FONT> </TD>\n\t\t\t<TD><INPUT TYPE='text' title ='Introduzca un nombre de usuario'  required NAME='nombreUsuario' VALUE='' SIZE='50'  MAXLENGTH='30'></TD></TR>\n\n\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green'>Nombre</FONT> </TD>\n\t\t\t<TD><INPUT TYPE='text' title ='Introduzca nombre' NAME='nombre' required VALUE='' SIZE='50'  MAXLENGTH='50'></TD></TR>\n\n\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green'>Apellidos</FONT> </TD>\n\t\t\t<TD><INPUT TYPE='text' NAME='apellidos' VALUE='' SIZE='50'  required MAXLENGTH='50'></TD></TR>\n\n\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green' >DNI</FONT> </TD>\n\t\t\t<TD><INPUT TYPE='text' title ='Introduzca su DNI' NAME='dni' VALUE='' required SIZE='50'  MAXLENGTH='10'></TD></TR>\n\n\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green'>Correo</FONT> </TD>\n\t\t\t<TD><INPUT TYPE='text' title ='Introduzca su email' NAME='correo' VALUE='' required SIZE='50'  MAXLENGTH='50'></TD></TR>\n\n\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green' >Contraseña</FONT> </TD>\n\t\t\t<TD><INPUT TYPE='password' NAME='password' VALUE='' SIZE='50' required  MAXLENGTH='20'></TD></TR>\n\t\t\t\t<TR><TD bgcolor='green' width='150'><FONT  COLOR= 'FFFFFF' bgcolor='green' >Elija su Rol</FONT> </TD> \n\t\t\t\t<td><select name='rol' >\n\t\t\t\t\t\n\t\t\t\t\t<option  value='admin'>Administrador\n\t\t\t\t\t<option selected value='user'>Cliente\n\t\t\t\t\t</select> \n\t\t\t\t</td></TR>\n\n\n\t\t\t<TR><TD width='150'> <b>Todos los campos son obligatorios</b></TD></TR>\n\t\t\t</BR>\t\t\n\t</TABLE>\n\n\t<INPUT TYPE='SUBMIT' VALUE='Registrarme'>\n\t</FORM>\n\t</CENTER>";
if (isset($operacion)) {
    if ($operacion == "añadir") {
        $teatro = new DBHelper();
        $teatro->add_user($_POST['nombreUsuario'], $_POST['nombre'], $_POST['apellidos'], $_POST['dni'], $_POST['correo'], $_POST['password'], $_POST['rol']);
    }
}
?>
	
		<input type="button" value="Volver" onClick="location='indexx.php'"/>
</BODY>
</HTML>