<?php require_once('Connections/odonto_connection.php');

///// INICIO COMPROBACION DE USUARIO
if(isset($_GET['salir'])){ 
session_start();
session_destroy();}
if (!isset($_SESSION)) {session_start();}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {$_SESSION['PrevUrl'] = $_GET['accesscheck'];}
if (isset($_POST['usuario'])) {$loginUsername=$_POST['usuario'];
  //$password=md5($_POST['textfield2']);
  $password=$_POST['clave'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "pacientes.php";
  $MM_redirectLoginFailed = "index.php?error";
  $MM_redirecttoReferrer = false;
  //mysql_select_db($database_odonto_connection, $odonto_connection);
  $LoginRS__query=sprintf("SELECT user, pass FROM ingreso WHERE user='%s' AND pass='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
  $LoginRS = mysqli_query($odonto_connection,$LoginRS__query) or die(mysql_error());
  $loginFoundUser = mysqli_num_rows($LoginRS);
  if ($loginFoundUser) {$loginStrGroup = "";   //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	  

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];}
    header("Location: " . $MM_redirectLoginSuccess );}
  else {header("Location: ". $MM_redirectLoginFailed ); }} 
 ///// FIN COMPROBACION USUARIO
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Nosotros Viajes y Turismo</title>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
<script type="text/javascript" src="scripts/jquery-1.11.2.min.js" ></script>
<script type="text/javascript" src="scripts/jquery-migrate-1.2.1.js" ></script>
<script type="text/javascript" src="scripts/spin.min.js"></script>
<script type="text/javascript" src="scripts/jquery.spin.js"></script>
<link rel="javascript" type="text/javascript"  href="bootstrap/js/bootstrap.min.js">

</head>

<body>
    <div class="container" style="margin-top:40px">
	<div class="row">
		<div class="col-sm-6 col-md-4 col-md-offset-4">
			<div class="panel xpanel-default">
				<div class="panel-body">
					<form role="form"  action="<?php echo $loginFormAction;?>"  method="post">
						<fieldset>
							<div class="row">
								<div class="center-block">
									<img class="profile-img" src="images/logo.png" alt="">
								</div>
							</div>
							<div class="row">
								<div class="col-sm-12 col-md-10  col-md-offset-1 ">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon">
												<i class="glyphicon glyphicon-user"></i>
											</span> 
											<input class="form-control" placeholder="Usuario" name="usuario" type="text" autofocus required value="">
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon">
													<i class="glyphicon glyphicon-lock"></i>
												</span>
												<input class="form-control" placeholder="Clave" name="clave" type="password" value="" required>
											</div>
										</div>

<?php if(isset($_GET['salir'])){echo "<div class='alert alert-danger' role='alert'>Deslogueo Exitoso !!!</div>";} ?>
<?php if(isset($_GET['error'])){echo "<div class='alert alert-danger' role='alert'>Error en los Datos !!!</div>";} ?>
<?php if(isset($_GET['banned'])){echo "<div class='alert alert-danger' role='alert'>Acceso Denegado !!!</div>";} ?>

										<div class="form-group">
											<input type="submit" class="btn btn-lg btn-primary btn-block" value="Entrar">
										</div>
									</div>
								</div>
							</fieldset>
						</form>
					</div>
                </div>
			</div>
		</div>
	</div>
</body>
</html>
