<?php
session_name( "PMUSICAwebsite" );
	$v1="user_id";
	$v2="user_nick";
	$v3="user_auth";
	$v4="user_usaCorreo";
	$v5="user_level";
	$v6="user_idg";
	session_register($v1,$v2,$v3,$v4,$v5, $v6);
session_start();

if ( !isset( $user_auth ) || empty( $user_auth ) )
{
  $user_auth = false;

  if ( ! ( empty( $ulogin ) || empty( $upass ) ) )
    checkUser( $ulogin, $upass, true );
}
if ( isset( $db_login ) && isset( $db_pass ) )
 checkUser( $db_login, $db_pass, $db_autolog );

function checkUser( $user, $pass, $rem )
{
  global $conexion, $id, $user_auth, $user_nick, $user_id, $user_usaCorreo, $user_level, $user_idg;
  $dev = false;

  $consulta = "SELECT id, pass, level, usaCorreo, idg FROM users WHERE nick = '$user' AND pass='$pass'";
	$res = mysql_query( $consulta, $conexion ) OR die("No puedo realizar la consulta");
	if (  mysql_num_rows($res) > 0 )
	{
 	  $user_id = mysql_result( $res, 0, "id" );
	  $user_nick = $user;
	  $user_auth = true;
	  $user_usaCorreo = mysql_result( $res, 0, "usaCorreo" );
	  $user_level = mysql_result( $res, 0, "level" );
	  $user_idg = mysql_result( $res, 0, "idg" );
	  mysql_query( "UPDATE users SET ultimaEntrada=NOW() WHERE id=$user_id", $conexion ) OR die("No puedo actualizar tu ficha");
	  if ( $rem )
	  {
	    setcookie( "ulogin", "$user", time()+2592000 );
	    setcookie( "upass", "$pass", time()+2592000 );
	  }
	  $dev = true;
	}
	mysql_free_result($res);
 return $dev;
}


// ***********
function getNumNews()
{
  global $conexion;
  $res = mysql_query( "SELECT COUNT(*) num FROM news", $conexion ) OR die("No puedo realizar la consulta");
  $dev = mysql_result( $res, 0, "num" );
  mysql_free_result($res);
 return $dev;
}
?>