<?php
//include("../db.php");

$continuar = 0;
$log_error = '';

if (session_is_registered("clave_audio")) {
	$continuar = 1;
} else {
	if (isset($_REQUEST['u']))
	{
		$conn = db_connect();
		if($conn) {
		
			$usu = strtoupper($_REQUEST['u']);
			$pass = crypt($_REQUEST['p'], substr($usu,0,2));

			$sqliden = "SELECT id, nombre FROM users WHERE username = '" . $usu . "' AND password = '" . $pass . "'";
			$result = mysql_query($sqliden, $conn);
			if (mysql_num_rows($result)) {
				$row = mysql_fetch_array($result);
				session_register("clave_audio");
				$_SESSION['clave_audio.u_name'] = $row['nombre'];
				$_SESSION['clave_audio.u_id'] = $row['id'];
				$continuar = 1;
			} else {
				$log_error = '<br><font size="1" face="Georgia" color="#ff0000"><b>El nombre del usuario o la contrase&ntilde;a no es correcto. Int&eacute;ntalo de nuevo.</b></font>';
			}
		} else {
			$log_error = '<br><font size="1" face="Georgia" color="#ff0000"><b>En este momento no hay conexi&oacute;n con la base de datos. Int&eacute;ntelo m&aacute;s tarde.</b></font>';
		}
	}
}

if (!$continuar) { // hay que identificar al usuario
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>gesti&oacute;n clave audio</title>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<?php include("top.htm"); ?>
<table id="top" width="708" height="103" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td colspan="2"><img src="_imgs/d.gif" width="708" height="120"></td>
	</tr>
<tr>
	<td colspan="2">
		<form name="acceso" method="post" action="index.php">
		<div align="center">
		<table width="398" cellspacing="0" cellpadding="0">
				<tr>
					<td><img src="_imgs/d.gif" width="130" height="1"></td>
					<td><img src="_imgs/d.gif" width="238" height="1"></td></tr>
				<tr>
					<td></td>
					<td width="238"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Est&aacute; accediendo a una zona de acceso<br>restringido a los empleados de Clave Audio.</font><?php echo $log_error; ?></td></tr>
				<tr>
					<td colspan="2"><img src="_imgs/d.gif" width="200" height="10"></td></tr>
				<tr>
					<td><div align="right" class="e1"><font face="Verdana, Arial, Helvetica, sans-serif" font size="1"><b>usuario:&nbsp;</b></font></div></td>
					<td><input type="text" name="u"></td></tr>
				<tr>
					<td colspan="2"><img src="_imgs/d.gif" width="200" height="10"></td>
				</tr>
				<tr>
					<td><div align="right" class="e1"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>password:&nbsp;</b></font></div></td>
					<td><input type="password" name="p" myProperty="ejemplo"></td></tr>
				<tr>
					<td colspan="2"><img src="_imgs/d.gif" width="200" height="10"></td></tr>
				<tr>
					<td></td><td><input type="submit" name="Submit" value="Entrar"></td></tr>
		  </table>
	    </div>
		</form>
	</td>
  </tr>
	<tr>
		<td colspan="2"><img src="_imgs/d.gif" width="708" height="50"></td></tr>
	<tr>
		<td colspan="2"><img src="_imgs/mancha.jpg" width="900" height="42"></td>
	</tr>
</table>
	
<SCRIPT LANGUAGE="JavaScript">
	document.acceso.u.focus();
</SCRIPT>
</body>
</html>
<?php
}
?>