<?php
	session_start();
	require_once 'conf/link.php';
	//echo '='.$_SESSION['user'].'=';
	$error = '';
	if (!isset($_SESSION['user']))
	{
		if((!empty($_POST['user'])) AND (!empty($_POST['pass'])))
		{
			$hash = password_hash($_POST['pass'], PASSWORD_DEFAULT);

			$sql = 'SELECT * FROM usuarios WHERE user="' .$_POST['user']. '" LIMIT 1';
			
			$result = mysqli_query($conexion, $sql);
			if ($row = mysqli_fetch_array($result))
			{
				if(password_verify($_POST['pass'], $row['hash']))
				{
							$_SESSION['user']	= $user['user'];

							//$_SESSION['acceso'] = $user['acceso'];
							$_SESSION['nombre'] = $user['nombre'];
							$_SESSION['apellido'] = $user['apellido'];
							//$_SESSION['fechacreacion'] = $user['fechacreacion'];
							//$_SESSION['avatar']	= $user['imagen'];
							header("Location: hdnews.php");
				}
				else	{
					$error = 'Contraseña Incorrecta! ';
				}
			}
			else	{
				$error = 'Usuario no existe!';
			}
		}
	}
	else	{
		$error = "Ingrese su nombre de usuario y contraseña";
	}
?>




<html>
	<head>
		<title>Nethost ADS Server - Login</title>
		<style type='text/css'>
		*
		{
			font-family: sans-serif;
			letter-spacing: -1;
			color: #222222;
		}
		
		body
		{
			margin: 0;
			background: radial-gradient(#fff, #888);
		}
		td, input
		{
			font-size: 17px;
		}
		a
		{
			font-size: 14px;
			text-decoration: none;
			color: #579ECF;
		}
		a:hover
		{
			text-decoration: underline;
		}
		#wrapper
		{
			background-color: #FFF;
			margin: 80px auto auto auto;
			text-align: center;
			border: 1px solid #000;
			width: 400px;
		}
		#title
		{
			padding: 10px 0 20px 0;
			font-size: 16px;
			text-align: center;
		}
		.label
		{
			font-size: 14px;
			text-align: right;
		}
		.input
		{
			font-size: 14px;
		}
		.forget
		{
			font-size: 14px;
			text-align: left;
			padding: 20px 0 0 20px;
		}
		.button
		{
			text-align: center;
		}
		</style>
	</head>
	<body onLoad="document.login.user.focus();">
		<div id='wrapper'>
		<form name='login' id='login' method='post' action='login.php'>
				<table style='border-spacing: 0; border-collapse: collapse;'>
					<tr>
						<td colspan='2' width='400'>
							<img src='images/login_header.png' width='396' alt='Signage manager - Nethost.cl' />
						</td>
					</tr>
					<tr>
						<td colspan='2'>
							<div id='title'>Iniciar Sesion</div>
						</td>
					</tr>
					<tr>
						<td width='100' class='label'>
							Usuario : 
						</td>
						<td width='200' class='input'>
							<input type='text' class='input' name='user' id='user' size='30'>
						</td>
					</tr>
					<tr>
						<td width='100' class='label'>
							Contraseña : 
						</td>
						<td width='200' class='input'>
							<input class='input' type='password' name='pass' id='pass' size='30'>
						</td>
					</tr>
					<tr>
						<td colspan='2' class='forget'>
							<a href='logout.php'>Olvidé mi contraseña</a>
						</td>
					</tr>
					<tr>
						<td colspan='2' class='button'>
							<input type='submit' value='Ingresar'>
						</td>
					</tr>
					<?php
						if($error != '')
						{
							echo $error;
						}
						else{
							echo '<br/>';
						}
					?>
				</table>
			</form>
		
		</div>
	</body>
</html>