<?php require_once('Connections/login.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_Recordset1 = "-1";
if (isset($_GET['username'])) {
  $colname_Recordset1 = $_GET['username'];
}
mysql_select_db($database_login, $login);
$query_Recordset1 = sprintf("SELECT * FROM usuario WHERE username = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $login) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['contrasena'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "sigein.html";
  $MM_redirectLoginFailed = "sesion.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_login, $login);
  
  $LoginRS__query=sprintf("SELECT username, contrasena FROM usuario WHERE username=%s AND contrasena=%s AND intEstado=1",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $login) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //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 );
  }
}
?>
<!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=UTF-8" />
<title>Sistema de Gestión de Incidencias</title>
<link href="css/estilos_login.css" rel="stylesheet" type="text/css" />
<style type="text/css">
a:link {
	color: #330099;
}
a:visited {
	color: #FF0000;
}
a:hover {
	color: #330099;
}
a:active {
	color: #F90F01;
}
</style>
</head>

<body>

<div class="container">
  <div class="header"><a href="#"><img src="imagenes/83ad8-bancobajio.jpeg" alt="Insertar logotipo aquí" name="Insert_logo" width="961" height="154" id="Insert_logo" style="background-color: #C6D580; display:block;" /></a> 
  
  <?php include("includes/cabecera.php"); ?>
  <!-- end .header --></div>
  <div class="content">
    
  
    <form action="<?php echo $loginFormAction; ?>" method="POST" name="form1">
    
    <table align="center"class="tab_login">
  <tr>
    <td width="100">&nbsp;</td>
    <td width="181">&nbsp;</td>
  </tr>
  <tr>
    <td>Usuario:</td>
    <td><label for="contrasena"></label>
      <input type="text" name="username" id="textfield2" /></td>
  </tr>
  <tr>
    <td>Contraseña:</td>
    <td><label for="textfield3"></label>
      <input type="password" name="contrasena" id="textfield3" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><div align="center"><a href="index.html">Inicio</a></div></td>
    <td><input type="submit" name="button" id="button" value="Ingresar" />
      <input type="reset" name="button2" id="button2" value="Restablecer" /></td>
  </tr>
</table>
    
    </form>
    
 
    
    <!-- end .content --></div>
  <div class="footer">
     <?php include("includes/pie.php"); ?>
    <!-- end .footer --></div>
  <!-- end .container --></div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
