<?php include "conexion.inc" ?>
<?php
	session_start();
	$mensaje = "";
	if(isset($_POST["login"]))
	{
		// variables
		$cV01 = $_POST['usuario'];
		$cV02 = $_POST['pass'];
		// conexión
		$servername = $svr_servidor;
		$conectioninfo = array("Database"=>$svr_base, "UID"=>$svr_usuario, "PWD"=>$svr_contrasena, "CharacterSet"=>"UTF-8");
		$conexion = sqlsrv_connect($servername, $conectioninfo);
		if ($conexion == false)
		{
			$mensaje = "Existe un error al intentar conectarse con el servidor...";
		}
		else
		{
			// codigo SQL
			$sql = "SELECT ISNULL(TIPOEMPLEADO, 0) AS TIPOEMPLEADO, CONVERT(NVARCHAR(254), NOMVENDEDOR) AS NOMVENDEDOR, PASSWORDWEB FROM VENDEDORES WHERE (NOMVENDEDOR = '".$cV01."') AND (PASSWORDWEB = '".$cV02."')";
			$pa1 = array();
			$op1 = array("scrollable" => SQLSRV_CURSOR_KEYSET);
			$re1 = sqlsrv_query($conexion, $sql, $pa1, $op1);
			if (sqlsrv_num_rows($re1) != 0)
			{
				while($fila = sqlsrv_fetch_array($re1))
				{
					$_SESSION["mLogin"] = $fila['NOMVENDEDOR'];
					$_SESSION["mNombre"] = $fila['NOMVENDEDOR'];
					$_SESSION["mImagen"] = "../Config/Usuarios/Usuario.jpg";
					$_SESSION["mIP"] = $_SERVER['HTTP_FORWARDED'];
					$_SESSION["mEmpleado"] = $fila['TIPOEMPLEADO'];
				}
				header('Location: principal.php');
			}
			else
			{
				$mensaje = "Usuario o password incorrecto";
			}
			sqlsrv_free_stmt($re1);
		}
		sqlsrv_close($conexion);
	}
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<!-- Meta, title, CSS, favicons, etc. -->
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- Bootstrap -->
		<link href="../Config/vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
		<!-- Font Awesome -->
		<link href="../Config/vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
		<!-- NProgress -->
		<link href="../Config/vendors/nprogress/nprogress.css" rel="stylesheet">
		<!-- Animate.css -->
		<link href="../Config/vendors/animate.css/animate.min.css" rel="stylesheet">
		<!-- Custom Theme Style -->
		<link href="../Config/build/css/custom.min.css" rel="stylesheet">
	</head>
	<body class="login">
		<div>
			<a class="hiddenanchor" id="signin"></a>
			<div class="login_wrapper">
				<div class="animate form login_form">
					<section class="login_content">
						<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
							<h1>Login</h1>
							<div>
								<input type="text" class="form-control" placeholder="Username" name="usuario" required="" />
							</div>
							<div>
								<input type="password" class="form-control" placeholder="Password" name="pass" required="" />
							</div>
							<div>
								<button type="submit" name="login">Login</button>
							</div>
							<div class="clearfix"></div>
							<h3 style="color:#FF0000";>
								<?php
									echo $mensaje;
								?>
							</h3>
						</form>
					</section>
				</div>
			</div>
		</div>
	</body>
</html>