<?php
include ('config.php');

$login = $_SESSION["login"];
$sqlid = "SELECT id FROM matgraph_users WHERE login='$login' AND id = idjoueur ORDER BY ID ASC limit 1";
$reqid = db_mysql_Query($sqlid) or die('Erreur SQL !<br>'.$sqlid.'<br>'.mysql_error());
$dataid = mysql_fetch_array($reqid);
$idlogin = $dataid['id'] ;


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

$sql = "SELECT place,placepris FROM matgraph_users WHERE id='$planete'";
$req = db_mysql_Query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
$data = mysql_fetch_array($req);
if (($data['placepris'] + 1 ) <= $data['place']) {
$place = 1 ;}
else {
$place = -1 ; }

$reqpts = "SELECT pts_flotte,pts_bats,pts_def,pts_tech FROM matgraph_users WHERE idjoueur='$idlogin'";
$respts = db_mysql_Query($reqpts)or die('erreur sql<br>'.$reqpts.'<br>'.mysql_error());
$rowpts = mysql_fetch_array($respts); 

if($rowpts[pts_def] < 0 OR $rowpts[pts_flotte] < 0) {
if($rowpts[pts_def] < 0) {
$New_pts = $rowpts[pts_flotte] + $rowpts[pts_bats] + $rowpts[pts_tech]; }
else {
$New_pts = $rowpts[pts_bats] + $rowpts[pts_def] + $rowpts[pts_tech]; } }
else {
$New_pts = $rowpts[pts_flotte] + $rowpts[pts_bats] + $rowpts[pts_def] + $rowpts[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());


echo"<style type=\"text/css\">
<!--
A { color:#ffffff; text-decoration:none; }
A:hover { color:#ffffff;text-decoration:underline;}
-->
</style>";

?>