<?php
include ('config.php');
require_once ('include/general.php');
/*
if($idlogin !== '1') {
echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("index.php");
-->
</script>';
exit; }*/

$login = $_SESSION["login"];
/*
function get_ip() {
    if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    elseif(isset($_SERVER['HTTP_CLIENT_IP'])) {
        $ip  = $_SERVER['HTTP_CLIENT_IP'];
    }
    else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}
$ip = get_ip();
if($_SESSION['ip'] != $ip) {

	session_destroy();
	echo '<script language="javascript" type="text/javascript">
	<!--
	window.location.replace("http://www.sg-univers.com/");
	-->
	</script>'; 
	exit;
}
*/
$sql2 = "SELECT * FROM matgraph_users WHERE login='$login' AND id = idjoueur ORDER BY ID ASC limit 1";
$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2); 
$dataid['id'] = $row2['id'] ;
$idlogin = $dataid['id'] ;


$req3 = "SELECT planete FROM matgraph_idjoueur WHERE idjoueur='$idlogin'";
$res3 = db_mysql_Query($req3)or die('erreur sql<br>'.$req3.'<br>'.mysql_error());
$row3 = mysql_fetch_array($res3); 
$planete = $row3['planete'];

if($planete == $idlogin)
{
	$row = $row2;
}
else
{
	$sql = "SELECT * FROM matgraph_users WHERE id='$planete' ";
	$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
	$row = mysql_fetch_array($res); 
}

$pnom = $row[planete];
$pgalaxi = $row[galaxi];
$psystem  = $row[system];
$pposition = $row[position];

if (($row['placepris'] + 1 ) <= $row['place']) {
$place = 1 ;}
else {
$place = -1 ; }


if($row2[vacance] !== "0000-00-00 00:00:00") {

ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $row2[vacance], $thetime);
$time = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);

$diftemps = time() - $time;
$difheure = round($diftemps / 3600,1);

if($difheure >= 48) {
	$requete = "UPDATE matgraph_users SET date = now() WHERE idjoueur='$idlogin'";
	$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
	
	$requete = "UPDATE matgraph_users SET vacance = '0000-00-00 00:00:00' WHERE id='$idlogin'";
	$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
	
	$requete = "INSERT INTO matgraph_vacance VALUES ('', '$idlogin',now() )";
	$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
}
else
{

	 echo '<script language=javascript> alert ("Vous etes en mode \"pause\" \n Il reste '.round(48-$difheure).' heure(s) à attendre (fin du mode pause : '.date("d/m/Y H:i",$time+48*3600).')  ");</script>';
	echo '<script language="javascript" type="text/javascript">
	<!--
	window.location.replace("http://www.sg-univers.com/");
	-->
	</script>';
	
	exit;
	}

}


if($row2[pts_def] < 0 OR $row2[pts_flotte] < 0) {
if($row2[pts_def] < 0) {
$New_pts = $row2[pts_flotte] + $row2[pts_bats] + $row2[pts_tech]; }
else {
$New_pts = $row2[pts_bats] + $row2[pts_def] + $row2[pts_tech]; } }
else {
$New_pts = $row2[pts_flotte] + $row2[pts_bats] + $row2[pts_def] + $row2[pts_tech]; }

$requete = "UPDATE matgraph_users SET pts=$New_pts WHERE id='$idlogin'";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());


//pour pour rester sur la meme page lords du changement de colo
$PHP_SELF = $_SERVER['PHP_SELF'] ;
?>
