<?	
include ('logue.php'); 
include ('entete_login.php');
include ('entete.php');


//////////////////////////////////////////////////// POINTS FLOTTE //////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	$req = "SELECT vaisseau, planete, nbre FROM matgraph_nbrevaisseaux WHERE user = '$idlogin'" ;
	$res = db_mysql_Query($req) or die('Erreur SQL! <br>' . $req . '<br>' . mysql_error()) ;
	$num = mysql_num_rows($res) ;
	if ( $num > 0 )
	{
		While ( $row = mysql_fetch_array($res) )
		{
			// Calcul le score des vaisseaux non mobilisés
			$sql2 = "SELECT fer, orr, ada, ura FROM matgraph_vaisseaux WHERE id = '$row[vaisseau]'" ;
			$res2 = db_mysql_Query($sql2) or die('Erreur SQL! <br>' . $sql2 . '<br>' . mysql_error()) ;
			$row2 = mysql_fetch_array($res2) ;
			$Score_vaisseau += ( ( $row2['fer'] + $row2['orr'] + $row2['ada'] + $row2['ura'] ) * $row['nbre'] ) ;

			// Calcul le score des vaisseaux mobilisés
			$sql_6 = "SELECT nombre FROM matgraph_mobil WHERE iddepart = '$row[planete]' AND idvaisseau = '$row[vaisseau]' " ;
			$res_6 = db_mysql_Query($sql_6) or die('erreur sql<br>' . $sql_6 . '<br>' . mysql_error()) ;
			While ($row_6 = mysql_fetch_array($res_6) )
			{
				$Score_vaisseau += ( ( $row2['fer'] + $row2['orr'] + $row2['ada'] + $row2['ura'] ) * $row_6['nombre'] ) ;
			}
		}
	}
	//compte miltaire
	$req = "SELECT mili_nbre FROM matgraph_users WHERE idjoueur = '$idlogin'" ;
	$res = db_mysql_Query($req) or die('Erreur SQL! <br>' . $req . '<br>' . mysql_error()) ;
	$num = mysql_num_rows($res) ;
	if ( $num > 0 )
	{
		While ( $row = mysql_fetch_array($res) )
		{
		$Score_soldats += ($row[mili_nbre]/5) ; // 5.000 mili = 1 pt donc 1000 pt dans la db
		}
	}
	
//////compte spe
	//malp
	$req = "SELECT malp FROM matgraph_users WHERE idjoueur = '$idlogin'" ;
	$res = db_mysql_Query($req) or die('Erreur SQL! <br>' . $req . '<br>' . mysql_error()) ;
	$num = mysql_num_rows($res) ;
	if ( $num > 0 )
	{
		While ( $row = mysql_fetch_array($res) )
		{
		$Score_spe += ($row[malp]*1000) ; 
		}
	}
	//ptremorqueur
	$req = "SELECT ptremorqueur FROM matgraph_users WHERE idjoueur = '$idlogin'" ;
	$res = db_mysql_Query($req) or die('Erreur SQL! <br>' . $req . '<br>' . mysql_error()) ;
	$num = mysql_num_rows($res) ;
	if ( $num > 0 )
	{
		While ( $row = mysql_fetch_array($res) )
		{
		$Score_spe += ($row[ptremorqueur]*3500) ; 
		}
	}
	//gdremorqueur
	$req = "SELECT gdremorqueur FROM matgraph_users WHERE idjoueur = '$idlogin'" ;
	$res = db_mysql_Query($req) or die('Erreur SQL! <br>' . $req . '<br>' . mysql_error()) ;
	$num = mysql_num_rows($res) ;
	if ( $num > 0 )
	{
		While ( $row = mysql_fetch_array($res) )
		{
		$Score_spe += ($row[gdremorqueur]*9000) ; 
		}
	}
	
	
	
//Maj pts
	$pts_flotte = $Score_vaisseau + $Score_soldats + $Score_spe;
	$req_UPDATE = "UPDATE matgraph_users SET pts_flotte = '$pts_flotte' WHERE id = '$idlogin'" ;
	$maj=db_mysql_Query($req_UPDATE) or die('Erreur SQL! <br>' . $req_UPDATE . '<br>' . mysql_error()) ;
	
	
//////////////////////////////////////////////////// POINTS DEFFENSE //////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	

	$req = "SELECT defcombat,deflasersimple,deflaserdouble,defelec,defions,defplasma,defnaqua,defanciens FROM matgraph_users WHERE idjoueur = '$idlogin'" ;
	$res = db_mysql_Query($req) or die('Erreur SQL! <br>' . $req . '<br>' . mysql_error()) ;
	$num = mysql_num_rows($res) ;
	if ( $num > 0 )
	{
		$Score_def = 0;
		While ( $row = mysql_fetch_array($res) )
		{
		$Score_def += ($row[defcombat]*500) ;
		$Score_def += ($row[deflasersimple]*1780) ;
		$Score_def += ($row[deflaserdouble]*4740) ;
		$Score_def += ($row[defelec]*10500) ;
		$Score_def += ($row[defions]*3500000) ;
		$Score_def += ($row[defplasma]*9500000) ;
		$Score_def += ($row[defnaqua]*18000000) ;
		$Score_def += ($row[defanciens]*20500000) ;
		}
	}
	$Score_def = $Score_def;
	//Maj pts
	$req_UPDATE = "UPDATE matgraph_users SET pts_def = '$Score_def' WHERE id = '$idlogin'" ;
	$maj=db_mysql_Query($req_UPDATE) or die('Erreur SQL! <br>' . $req_UPDATE . '<br>' . mysql_error()) ;
	
/////////////////////////////


?>