<?php require_once('Connections/poblets.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $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;
}
}
?>
<?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['ususario'])) {
  $loginUsername=$_POST['ususario'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "Nivel";
  $MM_redirectLoginSuccess = "admin/admin.php";
  $MM_redirectLoginFailed = "registro.php?login=0";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_poblets, $poblets);
  	
  $LoginRS__query=sprintf("SELECT `user`, pass, Nivel FROM users WHERE `user`=%s AND pass=%s",
  GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $poblets) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    $loginStrGroup  = mysql_result($LoginRS,0,'Nivel');
    
    //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>Portal de castellar-Oliveral</title>
<link href="index.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="container">
<div id="top_header"><a href="index.php"><img src="img/logo.png" alt="Poblets" width="102" height="25" /></a></div>
<div id="header"></div>
<table id="sub_header" width="100%" cellpadding="2" cellspacing="0">
<tr>
<?php include("menutop.php"); ?>
</tr>
</table>
<span id="menuizcont">
<?php include("menu.php"); ?> 
</span>
<span id="dercont">
<table id="notder" width="100%" border="0" cellspacing="3" cellpadding="0">
  <tr>
    <th scope="col" class="cabeceranoticias">REGISTRO DE USUARIO EN CMSPOBLETS</th>
    </tr>
  <tr>
    <td><p>Gracias por registrarte en CMSPoblets.Les mantendremos informados de las últimas novedades de la página web.</p>
      <p>Puede ponerse en contacto con nosotros en el correo:correodelaasociacion@avv26.com</p></td>
  </tr>
</table>
</span>
<div id="footer">
 <div align="center">Portal de la pedanía Castellar-Oliveral. CMSPoblets, creado por Javier Julián Olmos.
  </div>
</div>
</div>

</body>
</html>