<?php
ob_start();
?>
<html lang="es">
<head>
	<meta charset="UTF-8">
	<title>Taller</title> <link rel="icon" href="icons/taller.png" type="image/png">
	</head>
<?php
	$alert='';

	session_start();
	
	if(!empty($_SESSION['active'])){
		header('location: sistema/');
	} else {
	
		if(!empty($_POST)){
			if (empty($_POST['usuario']) || empty($_POST['clave'])){
				$alert='Ingrese usuario y Contrase&ntilde;a';
			} else{
				require_once "./conexion.php";
				$user=mysqli_real_escape_string($connection,$_POST['usuario']);
				//$pass=md5(mysqli_real_escape_string($connection,$_POST['clave']));
				$pass=(mysqli_real_escape_string($connection,$_POST['clave']));
				$query= mysqli_query($connection,"select * from uni_user where Nombre='".$user."' and pass='".$pass."'");
				mysqli_close($connection);
				$result=mysqli_num_rows($query);
				
				if($result>0){
					$data = mysqli_fetch_array($query);
					/*if($data['status']==0){
						$alert='<p class="msg_error">Usuario inactivo</p>';
					} 
					else{*/
						
						$_SESSION['active']=true;
						$_SESSION['iduser']= $data['idUser'];
						$_SESSION['nombre']= $data['usuario'];
						$_SESSION['user']= $data['Nombre'];
						$_SESSION['rol']= $data['tipo'];
						$_SESSION['suc']= $data['ubicacion'];

						/*if($_SESSION['rol']==4){
							header("location: especial/");
						} else{*/
							header("location: sistema/");
						/*}*/
						
					//}
					
					
					
				} else {
					$alert='Usuario y/o contraseña incorrectos';
					session_destroy();
				}
			}
		}
	}

?>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Login | Uniformes</title>
	<link rel="stylesheet" type="text/css" href="css/styles.css">
</head> 
<body>
	<section id="container" >
	
		<form action="" method="post" style="width:600px;">
		
			<h3>Iniciar sesión</h3>
			<table border="0">
			  <tr>
			    <td rowspan="4" style="width:200px;"><img src="img/login.png" alt="login"></td>
			    <td>
					<input type="text" name="usuario" placeholder="Usuario">
					
				</td>
		      </tr>
			  <tr>
			    <td><input type="password" name="clave" placeholder="Contraseña"></td>
		      </tr>
			  <tr>
			    <td><div class="alert"> <?php echo (isset($alert) ? $alert : '');?></div></td>
		      </tr>
			  <tr>
			    <td><input type="submit" value="INGRESAR"></td>
		      </tr>
		  </table>


		

			


	  </form>
		
	</section>
	
</body>
</html>