<?php
		session_start();
		include_once('php_conexion.php'); 
		
		if(!empty($_POST['user']) and !empty($_POST['password'])){
			$usuario=limpiar($conexion, $_POST['user']);
			$contra=limpiar($conexion,$_POST['password']);
			$can=mysqli_query($conexion,"SELECT * FROM usuarios WHERE (usu='".$usuario."' or ced='".$usuario."') and con='".$contra."'");
			if($dato=mysqli_fetch_array($can)){
				$_SESSION['username']=$dato['usu'];
				$_SESSION['tipo_usu']=$dato['tipo'];
				$_SESSION['id_usu']=$dato['id'];
 				
				///////////////////////////////
				if($_SESSION['tipo_usu']=='a' or $_SESSION['tipo_usu']=='s'){
					if($dato['estado']=='s'){
						header('location:administrador.php');
					}
				}elseif($_SESSION['tipo_usu']=='e'){
					if($dato['estado']=='s'){
						header('location:asistente.php');
					}
				}
			}
		}
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="author" content="jhp">
	<meta name="viewport" content="width=device-width,initial-scale=1">
	<title>Formulario de Ingreso</title>
	<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="css/my-login.css">
</head>
<body class="my-login-page">
	<section class="h-100">
		<div class="container h-100">
			<div class="row justify-content-md-center h-100">
				<div class="card-wrapper">
					<div class="brand">
						<img src="img/LOGOUMSOmd.png">
					</div>
					<div class="card fat">
						<div class="card-body">
							<h4 class="card-title">Iniciar sesion</h4>
							<form method="POST">
							 
								<div class="form-group">
									<label for="Usuario">Usuario</label>

									<input id="user" type="text" class="form-control" name="user" value="" required autofocus>
								</div>

								<div class="form-group">
									<label for="password">Contraseña</label>
									<input id="password" type="password" class="form-control" name="password" required data-eye>
								</div>

								<div class="form-group">
									<label>
										<input type="checkbox" name="remember"> Recordarme
										<a href="forgot.php" class="float-right">
											Se te olvidó tu contraseña?
										</a>
									</label>
								</div>

								<div class="form-group no-margin">
									<button type="submit" class="btn btn-primary btn-block">
										Iniciar
									</button>
								</div>
								<div class="margin-top20 text-center">
										No tienes una cuenta? <a href="register.php">Crea una</a>
								</div>
								<?php
									$act="1";
									if(!empty($_POST['user']) and !empty($_POST['password'])){
										$usuario=limpiar($conexion, $_POST['user']);
										$contra=limpiar($conexion, $_POST['password']);
										$can=mysqli_query($conexion, "SELECT * FROM usuarios WHERE (usu='".$usuario."' or ced='".$usuario."') and con='".$contra."'");
										if(!$dato=mysqli_fetch_array($can)){
											if($act=="1"){
												echo '<div class="alert alert-danger" align="center"><strong>Usuario y/o Contraseña Incorrecta</strong><button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button></div>';
											}else{
												$act="0";
											}
										}else{
											if($dato['estado']=='n'){
												echo '<div class="alert alert-danger" align="center"><strong>Consulte con el Administrador</strong><button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button></div>';
											}
										}
									}else{
										
									}
								?>
							</form>
						</div>
					</div>
					<div class="footer">
						Copyright &copy; 2018 &mdash; Todos los derechos reservados por UMSO PERU SAC | by <a href="mailto:josehuinapp@gmail.com">J.H.P.</a>
					</div>
				</div>
			</div>
		</div>
	</section>

	<script src="js/jquery.min.js"></script>
	<script src="bootstrap/js/bootstrap.min.js"></script>
	<script src="js/my-login.js"></script>
</body>
</html>