<?php

				/**************************galaxy.php*************************************/
				/*  						@version 1.9 								 */
				/*	          			 By Kiwille pour Uniguerre  					 */	
				/*************************************************************************/

/*
*	1.0 à 1.2: ??? (Chlorel)
*	1.3: Compatibilité du fichier avec le jeu Uniguerre et des fichiers XNova (Kiwille)
*   1.4: Corrections de quelques bugs (Kiwille)
*	1.5: Corrections de quelques bugs (Kiwille)
*   1.6: Correction de nombreux bugs et améliorations de la vue galactique, comme l'envoi de sondes par exemple.(Kiwille)
*	1.7: Correction sur l'apostrophe dans le nom d'alliance (Kiwille)
*   1.8: Correction de compatibilité galaxie/phalange (Kiwille)
*   1.9: Correction de compatibilité galaxie/liste d'ami (Kiwille)
*/				
				
/*****************************************************************************************************************************/				
define('INSIDE' , true);
define('INSTALL' , false);
require_once dirname(__FILE__) .'/common.php';

//Inclure la langue par défaut.
includeLang('galaxy');

/*****************************************************************************************************************************/

$CurrentPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '". $user['current_planet'] ."';", 'planets', true);
$lunarow       = doquery("SELECT * FROM {{table}} WHERE `id` = '". $user['current_luna'] ."';", 'lunas', true);
$galaxyrow     = doquery("SELECT * FROM {{table}} WHERE `id_planet` = '". $CurrentPlanet['id'] ."';", 'galaxy', true);

$dpath         = (!$user["dpath"]) ? DEFAULT_SKINPATH : $user["dpath"];
$fleetmax      = $user['computer_tech'] + 1;
if ($fleetmax > 11)
    $fleetmax = 11; 
	
$CurrentPlID   = $CurrentPlanet['id'];
$CurrentMIP    = $CurrentPlanet['interplanetary_misil'];
$CurrentRC     = $CurrentPlanet['recycler'];
$CurrentSP     = $CurrentPlanet['spy_sonde'];
$HavePhalanx   = $CurrentPlanet['phalanx'];
$CurrentSystem = $CurrentPlanet['system'];
$CurrentGalaxy = $CurrentPlanet['galaxy'];
$CanDestroy    = $CurrentPlanet[$resource[213]] + $CurrentPlanet[$resource[214]];

$maxfleet       = doquery("SELECT * FROM {{table}} WHERE `fleet_owner` = '". $user['id'] ."';", 'fleets');
$maxfleet_count = mysql_num_rows($maxfleet);

CheckPlanetUsedFields($CurrentPlanet);
CheckPlanetUsedFields($lunarow);

// Imperatif, dans quel mode suis-je (pour savoir dans quel etat j'ere)
if (!isset($mode)) {
	if (isset($_GET['mode'])) {
		$mode          = intval($_GET['mode']);
	} else {
		// ca ca sent l'appel sans parametres a plein nez
		$mode          = 0;
	}
}

if ($mode == 0) {
	// On vient du menu
	// Y a pas de parametres de passé
	// On met ce qu'il faut pour commencer là ou l'on se trouve

	$galaxy        = $CurrentPlanet['galaxy'];
	$system        = $CurrentPlanet['system'];
	$planet        = $CurrentPlanet['planet'];
} elseif ($mode == 1) {
	// On vient du selecteur de galaxie
	// Il nous poste :
	// $_POST['galaxy']      => Galaxie affichée dans la case a saisir
	// $_POST['galaxyLeft']  => <- A ete cliqué
	// $_POST['galaxyRight'] => -> A ete cliqué
	// $_POST['system']      => Systeme affiché dans la case a saisir
	// $_POST['systemLeft']  => <- A ete cliqué
	// $_POST['systemRight'] => -> A ete cliqué

	if ($_POST["galaxyLeft"]) {
		if ($_POST["galaxy"] < 1) {
			$_POST["galaxy"] = 1;
			$galaxy          = 1;
		} elseif ($_POST["galaxy"] == 1) {
			$_POST["galaxy"] = 1;
			$galaxy          = 1;
		} else {
			$galaxy = $_POST["galaxy"] - 1;
		}
	} elseif ($_POST["galaxyRight"]) {
		if ($_POST["galaxy"]      > MAX_GALAXY_IN_WORLD OR
			$_POST["galaxyRight"] > MAX_GALAXY_IN_WORLD) {
			$_POST["galaxy"]      = MAX_GALAXY_IN_WORLD;
			$_POST["galaxyRight"] = MAX_GALAXY_IN_WORLD;
			$galaxy               = MAX_GALAXY_IN_WORLD;
		} elseif ($_POST["galaxy"] == MAX_GALAXY_IN_WORLD) {
			$_POST["galaxy"]      = MAX_GALAXY_IN_WORLD;
			$galaxy               = MAX_GALAXY_IN_WORLD;
		} else {
			$galaxy = $_POST["galaxy"] + 1;
		}
	} else {
		$galaxy = $_POST["galaxy"];
	}

	if ($_POST["systemLeft"]) {
		if ($_POST["system"] < 1) {
			$_POST["system"] = 1;
			$system          = 1;
		} elseif ($_POST["system"] == 1) {
			$_POST["system"] = 1;
			$system          = 1;
		} else {
			$system = $_POST["system"] - 1;
		}
	} elseif ($_POST["systemRight"]) {
		if ($_POST["system"]      > MAX_SYSTEM_IN_GALAXY OR
			$_POST["systemRight"] > MAX_SYSTEM_IN_GALAXY) {
			$_POST["system"]      = MAX_SYSTEM_IN_GALAXY;
			$system               = MAX_SYSTEM_IN_GALAXY;
		} elseif ($_POST["system"] == MAX_SYSTEM_IN_GALAXY) {
			$_POST["system"]      = MAX_SYSTEM_IN_GALAXY;
			$system               = MAX_SYSTEM_IN_GALAXY;
		} else {
			$system = $_POST["system"] + 1;
		}
	} else {
		$system = $_POST["system"];
	}
} elseif ($mode == 2) {
	// Mais c'est qu'il mordrait !
	// A t'on idée de vouloir lancer des MIP sur ce pauvre bonhomme !!

	$galaxy        = $_GET['galaxy'];
	$system        = $_GET['system'];
	$planet        = $_GET['planet'];
} elseif ($mode == 3) {
	// Appel depuis un menu avec uniquement galaxy et system de passé !
	$galaxy        = $_GET['galaxy'];
	$system        = $_GET['system'];
} elseif ($mode == 6) {
	// On garde la page à partir on veut sonder (c'est mieux!)!
	$galaxy        = $_GET['g'];
	$system        = $_GET['s'];
	$planet 	   = $_GET['p'];
} else {
	// Si j'arrive ici ...
	// C'est qu'il y a vraiment eu un bug
	$galaxy        = 1;
	$system        = 1;
}

$planetcount = 0;
$lunacount   = 0;

$page  = InsertGalaxyScripts ( $CurrentPlanet );

$page .= "<body style=\"overflow: auto;\" onUnload=\"\">";

$page .= InsertGalaxyScripts ( $CurrentPlanet );
$page .= ShowGalaxySelector ( $galaxy, $system );
if ($mode == 0 ) { //affichage de la légende (seulement sur la 1ere page!)
	$page .= GalaxyLegendPopup ();
}
if ($mode == 2) // affichage tableau d'envoi de MIP
{
	$CurrentPlanetID = $_GET['current'];
	$page .= ShowGalaxyMISelector ( $galaxy, $system, $planet, $CurrentPlanetID, $CurrentMIP );
}
if ($mode == 6)	// affichage signalant l'envoi de sondes
{
	// ce que l'on récupère du lien lorsqu'on clique sur "Espionner"
	$Mode   = $_GET['mode'];
	$Galaxy = $_GET['g'];
	$System = $_GET['s'];
	$Planet = $_GET['p'];
	$TypePl = $_GET['t'];

	// Cadre liste de flottes ...
	$missiontype = array(
		1 => $lang['type_mission'][1],
		2 => $lang['type_mission'][2],
		3 => $lang['type_mission'][3],
		4 => $lang['type_mission'][4],
		5 => $lang['type_mission'][5],
		6 => $lang['type_mission'][6],
		7 => $lang['type_mission'][7],
		8 => $lang['type_mission'][8],
		9 => $lang['type_mission'][9],
		15 => $lang['type_mission'][15]
		);

	// Protection administrateur
	$Protect_admin       = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '".$Galaxy."' AND `system` = '".$System."' AND `planet` = '".$Planet."';", 'planets');
	$Protection_planete_admin = mysql_fetch_array ($Protect_admin);	
	if ($Protection_planete_admin['id_level'] != 3)    
	{ 
		// Empeche aussi les joueurs en Mode Vacances de sonder.
		if ($user['urlaubs_modus'] == 0) 
		{
				$TargetPlanet  = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '". $galaxy ."' AND `system` = '".$system ."' AND `planet` = '". $planet ."';", 'planets', true);
				if ($TargetPlanet['id_owner'] == '') $HeDBRec = $MyDBRec;
				elseif ($TargetPlanet['id_owner'] != '') $HeDBRec = doquery("SELECT * FROM {{table}} WHERE `id` = '". $TargetPlanet['id_owner'] ."';", 'users', true);
				
				$VacationMode = $HeDBRec['urlaubs_modus'];
				
				if ($VacationMode == 1) { // Oh le joueur est en MV ! Pas le droit de sonder!
					$page .= "<center>";
						$page .= "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">";
						$page .= "	<tr><th>";
						$page .= "		<font color=\"red\"><b>Ce joueur est en mode vacances!</b></font>";
						$page .= "	</th></tr>";
						$page .= "</table>";
				}else{ // sinon c'est ok !
					$QrySelectGalaxy  = "SELECT * FROM {{table}} ";
					$QrySelectGalaxy .= "WHERE ";
					$QrySelectGalaxy .= "`galaxy` = '".$Galaxy."' AND ";
					$QrySelectGalaxy .= "`system` = '".$System."' AND ";
					$QrySelectGalaxy .= "`planet` = '".$Planet."' ";
					$QrySelectGalaxy .= "LIMIT 1;";
					$TargetGalaxy     = doquery( $QrySelectGalaxy, 'galaxy', true);
					$SondesDefini     = doquery("SELECT * FROM {{table}} WHERE `id` = '".$user['id']."'", 'users');
					$Nombre_sondes    = mysql_fetch_array ($SondesDefini);
					$SondeNeeded      = $Nombre_sondes['spio_anz'];
					$SondeSpeed       = $pricelist[210]['speed'] + (($pricelist[210]['speed'] * $user['combustion_tech']) * 0.1);

					$SondeCount    = $planetrow[$resource[210]];
						
						if ($SondeCount > $SondeNeeded) {
							$FleetCount = $SondeNeeded;
						} else {
							$FleetCount = $SondeCount;
						}
						$FleetArray[210] = $FleetCount;
				

					
						foreach ($FleetArray as $Ship => $Count) {
							$ShipCount       += $Count;
						}
						
					if ($ShipCount>0) { // Il envoie des sondes quand le nombre est sup. à 0.
						$page .= "<center>";
						$page .= "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">";
						$page .= "<tr><th>";
						foreach ($FleetArray as $Ship => $Count) { // P'tit message d'envoie des sondes
								$page			 .= "<font color=\"lime\">Vous avez envoy&eacute; ". pretty_number($Count) ." ".$lang['tech'][$Ship].".</font>";
								$FleetSubQRY     .= "`".$resource[$Ship] . "` = `" . $resource[$Ship] . "` - " . $Count . " , ";
								$ShipArray       .= $Ship.",".$Count.";";
								$ShipCount       += $Count;
						}
						$distance      = GetTargetDistance  ( $planetrow['galaxy'], $Galaxy, $planetrow['system'], $System, $planetrow['planet'], $Planet );
						$SpeedFactor   = $game_config['fleet_speed'] / 2500;
						$GenFleetSpeed = 10; // a 100%
						$duration      = GetMissionDuration ( $GenFleetSpeed, $SondeSpeed, $distance, $SpeedFactor );
					
						
						$page .= "</th></tr>";
						$page .= "</table>";
				
						$QryInsertFleet  = "INSERT INTO {{table}} SET ";
						$QryInsertFleet .= "`fleet_owner` = '". $user['id'] ."', ";
						$QryInsertFleet .= "`fleet_mission` = '". $Mode ."', ";
						$QryInsertFleet .= "`fleet_amount` = '". $ShipCount ."', ";
						$QryInsertFleet .= "`fleet_array` = '". $ShipArray ."', ";
						$QryInsertFleet .= "`fleet_start_time` = '". ($duration + time()) ."', ";
						$QryInsertFleet .= "`fleet_start_galaxy` = '". $planetrow['galaxy'] ."', ";
						$QryInsertFleet .= "`fleet_start_system` = '". $planetrow['system'] ."', ";
						$QryInsertFleet .= "`fleet_start_planet` = '". $planetrow['planet'] ."', ";
						$QryInsertFleet .= "`fleet_start_type` = '". $planetrow['planet_type'] ."', ";
						$QryInsertFleet .= "`fleet_end_time` = '". (($duration * 2) + time()) ."', ";
						$QryInsertFleet .= "`fleet_end_galaxy` = '". $Galaxy ."', ";
						$QryInsertFleet .= "`fleet_end_system` = '". $System ."', ";
						$QryInsertFleet .= "`fleet_end_planet` = '". $Planet ."', ";
						$QryInsertFleet .= "`fleet_end_type` = '". $TypePl ."', ";
						$QryInsertFleet .= "`start_time` = '". time() ."';";
						doquery( $QryInsertFleet, 'fleets');

						$QryUpdatePlanet  = "UPDATE {{table}} SET ";
						$QryUpdatePlanet .= $FleetSubQRY;
						$QryUpdatePlanet .= "`planet_type` = '".$planetrow['planet_type']."' ";
						$QryUpdatePlanet .= "WHERE ";
						$QryUpdatePlanet .= "`id` = '". $planetrow['id'] ."'";
						doquery ($QryUpdatePlanet, "planets");
					}
					else {
						$page .= "<center>";
						$page .= "	<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">";
						$page .= "		<tr><th>";
						$page .= "			<font color=\"red\"><b>Vous n'avez pas de sondes sur votre plan&egrave;te!</b></font>";
						$page .= "		</th></tr>";
						$page .= "	</table>";
					}
				}
		
		}else{
		// Message ou le joueur est en MV
			$page .= "<center>";
			$page .= "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">";
			$page .= "	<tr><th>";
			$page .= "		<font color=\"red\"><b>Vous êtes en mode vacances!</b></font>";
			$page .= "	</th></tr>";
			$page .= "</table>";
		}
	}
	else{
		// Message ou le joueur tente d'attaquer une planète admin!
			$page .= "<center>";
			$page .= "	<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">";
			$page .= "		<tr><th>";
			$page .= "			<font color=\"red\"><b>Cette administrateur est sous protection sp&eacute;ciale.</b></font>";
			$page .= "		</th></tr>";
			$page .= "	</table>";
	}
	
	
}

$page .=  ShowGalaxyFooter ( $galaxy, $system,  $CurrentMIP, $CurrentRC, $CurrentSP);
$page .= "<table width=569><tbody>";
$page .= "</tbody></table></div>";

//image de fond de chaque galaxie, rien que pour faire jolie !
$page .= "<div id=\"raum_3\"><center><img src=\"images/galaxy/espace.gif\" height=\"86%\" width=\"90%\" /></center></div>";


	$query = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '$galaxy' AND `system` = '$system' AND planet >= '1' AND planet <= '16' AND planet_type =  '1' ORDER BY planet;", 'planets');
	$id = 1;
	while($row = mysql_fetch_assoc($query))
	{		
		while ($id != $row['planet'])
		{
			$PlaneteOccupee[$id -1] = "Libre";
			$PlaneteID[$id-1] = $galaxy.':'.$system.':'.$id;
			$Owner[$id-1] = -1;
			$PlaneteImage[$id-1] = '';
			$id++;
		}
		$PlaneteOccupee[$id-1] = $row['name'];
		$PlaneteID[$id-1] = $galaxy.':'.$system.':'.$id;
		$Owner[$id-1] = $row['id_owner'];
		$PlaneteImage[$id-1] = $row['image'];
		$id++;

		
	}
	
	// Nécessaire pour forcer l'affichage des planètes non colonisées si la dernière planète n'a pas la dernière position
	
	// Exemple : 
	// Si la position de la dernière planète renvoyée est [1:2:9], la première boucle While s'arrêtera après la planète 1:2:9
	// car il n'y aura plus aucune planète habitée après donc inexistant dans la base de données.
	// Comme on souhaite afficher les 15 planètes, il faut faire une boucle jusqu'à ce qu'on a atteigne la valeur 15 pour id et comme ces planètes
	// n'existent pas, il faut qu'elles soient considérés comme Libre pour être colonisé.
	while ($id <= 15)
	{
		$PlaneteOccupee[$id - 1] = "Libre";
		$PlaneteID[$id - 1] = $galaxy.':'.$system.':'.$id;
		$Owner[$id - 1] = -1;
		$PlaneteImage[$id - 1] = '';
		$id++;
	}
	
	$query1 = doquery("SELECT * FROM {{table}} ORDER BY id;", 'users');
	
	while($row = mysql_fetch_assoc($query1))
	{	
		$id = 1;
		while ($id <= 16)
		{
			if ($Owner[$id - 1] != -1 && $Owner[$id - 1] == $row['id'])
			{
			
				// pseudo (+ la couleur à laquelle on doit mettre son pseudo)?
					  if ($row['authlevel'] == 3 OR $row['authlevel'] == 2) 
						 {$UserName[$id - 1] = "<font color=#FF0000>".$row['username']."</font>"; // couleur pseudo admin/operateur
				} elseif ($row['id'] == $user['id']) 
						 {$UserName[$id - 1] = "<font color=#FF33CC>".$row['username']. "</font>"; // couleur du joueur lui meme	
				} elseif ($row['urlaubs_modus'] == 1) 
						 {$UserName[$id - 1] = "<font color=#0066FF>".$row['username']. "</font>"; // couleur pseudo MV		
				} elseif ($row['onlinetime'] < (time()-60 * 60 * 24 * 7))
						 {$UserName[$id - 1] = "<font color=#FFFF00>".$row['username']."</font>"; // couleur pseudo inactif	7 j
				} elseif ($row['onlinetime'] < (time()-60 * 60 * 24 * 28))
						 {$UserName[$id - 1] = "<font color=#999999>".$row['username']."</font>"; // couleur pseudo inactif	28 j		 
				} elseif ($row['ally_id'] == $user['ally_id'] AND $row['ally_id'] != 0 )
						 {$UserName[$id - 1] = "<font color=#FF66FF>".$row['username']."</font>"; // couleur joueur de meme alliance
				} else
						 {$UserName[$id - 1] = "<font color=#44FF00>".$row['username']." </font>"; // ben le joueur est un joueur normal!
				} 
							
				// Une alliance?
				if ($row['ally_id'] == 0) { // --> NON 
					$Alliance[$id - 1] = ''; 
				} else {  					// --> OUI
					$Alliance[$id - 1] = "Alliance: <a href=alliance.php?mode=ainfo&a=".$row['ally_id'].">".$row['ally_name']."</a><br />";
				}
				
				if ($row['id'] != $user['id']) // Ajouter un joueur à sa liste d'ami / Envoyer un message à un joueur ?
				{	//--> On l'affiche s'il la planète est habité
					$buddy[$id - 1] = "<a href=buddy.php?a=2&u=".$row['id'].">Liste amis</a><br>";
					$mail[$id - 1] = "<a href=messages.php?mode=write&id=".$row['id'].">Envoyer un message</a><br>";
				}
				else
				{	//-->Sinon rien !
					$buddy[$id - 1] = '';
					$mail[$id - 1] = '';
				}
				$id++;
			}
			else
			{
				$id++;
			}
		}
	}
	
	$query2 = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '$galaxy' AND `system` = '$system' ORDER BY planet;", 'galaxy');

	while($row = mysql_fetch_assoc($query2))
	{	
		$id = 1;
		while ($id <= 16)
		{
		
			if ($PlaneteID[$id - 1] == $row['galaxy'].':'.$row['system'].':'.$row['planet'])
			{
				if ($row['id_luna'] != '0') // Le joueur a une lune?
				{  // Cas ou il y a une belle lune !
					$PresenceLune[$id - 1] = "<font color=yellow>Lune : Oui</font><br><a href=fleet.php?galaxy=$galaxy&system=$system&planet=$id&planettype=3&target_mission=9><font color=red>Destruction de lune</font></a><br>";
					$LuneExistante[$id - 1] = 1;
				}
				else // Cas ou il n'y a pas de lune !
				{
					$PresenceLune[$id - 1] = "<font color=yellow>Lune : non</font><br>";
					$LuneExistante[$id - 1] = 0;
				}
				
				if ($row['metal'] != 0 || $row['crystal'] != 0)
				{
						$galaxy = $row['galaxy']; 
						
					//A propos de débris à présent...
					$rec['recycleur'] = ( $row['crystal'] + $row['metal'] ) / 20000;  // calcul du nombre de recycleurs à envoyer
					$rec['recycleur'] = ((int) $rec['recycleur'] ) + 1; // On prends la partie entiere du calcul et on lui ajoute 1, pour tout recycler
					if (($rec['recycleur']) <= 5000) 					// choix de la couleur de 'Nb Recycleur' (vert, jaune, orange ou rouge?)
					{ 		$color = "<font color=green>"; 
							$fcolor	= "</font>";
					} elseif ($rec['recycleur']>5000 && $rec['recycleur']<30000) 
					{  		$color = "<font color=yellow>";
							$fcolor	= "</font>";
					} elseif ($rec['recycleur']>30000 && $rec['recycleur']<100000) 
					{  		$color = "<font color=#FF6600>";
							$fcolor	= "</font>";
					} else {  		
							$color = "<font color=red>";
							$fcolor	= "</font>";
					}							// Fin de choix "la couleur de  'Nb Recycleur'
					
					if ($rec['recycleur'] != 0 ) {
						 $Ressource[$id - 1] = "<table width=100%><tr><td class=c><center><img src=images/galaxy/debris.gif /> | <a href=quickfleet.php?mode=8&g=".$row['galaxy']."&s=".$row['system']."&p=".$row['planet']."&t=2>".$color."Recycler les d&eacute;bris".$fcolor."</center></a><center><hr></center>M&eacute;tal: ".number_format($row['metal'],0,'','.')."<br>Cristal: ".pretty_number($row['crystal'])."<br>".$color."Nb Recycleur: ".pretty_number($rec['recycleur'])."".$fcolor."</td></tr></table></font><br>";
					} else {
						$Ressource[$id - 1] = '';
					}
				}	 
				$id++;
			}
			else
			{
				$id++;
			}
		}
	}
		
		
$e = 0; $f = 1;


$hasard = ( $system % 5 ) + ($system % 4) + ($galaxy % 7);
$hasard = ((int) $hasard);
	// Ici on fixe la position des 15 planètes sur la carte du jeu. ( horizontal;verticale ) + l'affichage du soleil !
			//pos  :   01       02       03        04       05       06      07       08       09        10      11      12        13        14       15   16(au cas ou)
switch ($hasard)
{
case '0':	$pos  = "175;175; 220;220; 275;290; 180;400; 430;257; 320;430; 600;180; 590;380; 520;510; 300;585; 650;260; 670;570; 710;405; 785;235; 800;550; 549;525;"; 
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
case '1':	$pos  = "180;180; 250;220; 300;300; 170;450; 461;277; 350;470; 575;163; 570;360; 500;500; 300;585; 650;260; 670;570; 700;400; 800;245; 800;540; 549;525;"; 
			$page .= "<div id=\"99\" style=\" position: absolute; left: 80px; top: 150px; width: 20px; height: 10px;\">";
			break;
case '2': 	$pos  = "170;170; 150;260; 280;320; 170;450; 461;277; 350;470; 575;163; 570;360; 510;510; 300;585; 650;260; 670;570; 720;395; 770;250; 790;530; 549;525;";
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
case '3': 	$pos  = "165;180; 240;200; 175;300; 170;450; 461;277; 350;470; 575;163; 570;360; 505;505; 300;585; 650;260; 670;570; 730;390; 805;200; 795;540; 549;525;";
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
case '4': 	$pos  = "180;165; 245;225; 190;310; 140;400; 461;277; 350;470; 575;163; 570;360; 500;500; 300;585; 650;260; 670;570; 740;395; 800;200; 795;530; 549;525;";
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
case '5': 	$pos  = "180;170; 250;220; 110;280; 160;400; 421;277; 320;460; 575;163; 570;360; 495;500; 300;585; 650;260; 670;570; 755;402; 770;165; 800;550; 549;525;";
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
case '6': 	$pos  = "180;175; 230;210; 305;305; 165;450; 461;277; 350;470; 575;163; 570;360; 500;490; 300;585; 650;260; 670;570; 745;405; 780;180; 795;550; 549;525;";
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
case '7': 	$pos  = "160;185; 225;220; 300;300; 175;430; 461;277; 350;470; 575;163; 570;360; 490;500; 300;585; 650;260; 670;570; 735;400; 804;205; 790;550; 549;525;";
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
case '8': 	$pos  = "185;180; 225;210; 120;280; 170;400; 461;277; 350;470; 575;163; 570;360; 500;500; 300;585; 650;260; 670;570; 725;400; 805;225; 790;555; 549;525;";
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
case '9': 	$pos  = "180;185; 230;225; 300;300; 165;420; 461;277; 350;470; 575;163; 570;360; 500;500; 300;585; 650;260; 670;570; 745;410; 802;205; 800;555; 549;525;";
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
case '10': 	$pos  = "185;185; 170;250; 300;170; 160;440; 461;277; 350;470; 575;163; 570;360; 500;500; 300;585; 650;260; 670;570; 735;410; 805;215; 800;560; 549;525;";
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
case '11': 	$pos  = "175;185; 155;280; 290;180; 200;400; 381;277; 300;570; 560;180; 490;360; 370;470; 470;585; 650;260; 620;470; 725;380; 795;245; 750;580; 549;525;";
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
case '12': 	$pos  = "170;185; 220;220; 285;295; 170;450; 461;277; 350;470; 575;163; 570;360; 500;500; 300;585; 650;260; 670;570; 750;405; 810;205; 755;585; 549;525;";
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
case '13': 	$pos  = "185;170; 240;210; 305;300; 170;450; 461;277; 350;470; 575;163; 570;360; 500;500; 300;585; 650;260; 670;570; 750;405; 802;265; 745;545; 549;525;";
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
default : 	$pos  = "180;180; 250;220; 300;300; 170;450; 461;277; 350;470; 575;163; 570;360; 500;500; 300;585; 650;260; 670;570; 750;400; 800;225; 800;550; 549;525;";
			$page .= "<div id=\"99\" style=\" position: absolute; left: 100px; top: 160px; width: 20px; height: 10px;\">";
			break;
}

$page .= "<th width=30><a style=\"cursor: crosshair;\" onmouseover='return overlib(\" <table width=250><tr><td class=c colspan=2><center>Trou Noir</center></td></tr> <th align=left><img src=images/galaxy/BlackHole.gif height=80 width=100><hr><a href=fleet.php?galaxy=$galaxy&system=$system&planet=16;planettype=1&target_mission=15>Explorer</a></th></tr>  </table>\",STICKY, MOUSEOFF, DELAY, 750, CENTER, OFFSETX, -40, OFFSETY, -40 );' onmouseout='return nd();'><img src=images/galaxy/BlackHole.gif height=\"60\" width=\"80\"><font color=#E5E5E5>Trou Noir</a></th>";
$page .= "</div>";

$count = 0;
while($count < 15)
{
	$missiontime = explode(";", $pos);
	$pos1 = $missiontime[ $e ];
	$pos2 = $missiontime[ $f ];
	
	
	$nb = $count + 1;
	
	if ($nb != 16) {
		// ici se détermine le classement du joueur, puis on l'affiche dans la petite fenetre.
		$DonStats = doquery("SELECT * FROM {{table}} WHERE `id_owner`=".$Owner[$count]." && `total_rank`!=0;",'statpoints');
		$Points = mysql_fetch_array($DonStats);
			if ($Points['total_rank'] != 0) {
				$AffichPoints  = "Points: ".pretty_number($Points['total_points'])."<br>";
				$AffichPoints .= "Rang: ".$Points['total_rank']."e";
			} else { // là il y a un probleme si on arrive ici ^^
				$AffichPoints= "Impossible de le classer";
			}
	}
	
	if ($Ressource[$count] != '') {
		$imagedebris = "<SPAN style=\"position: absolute; z-index: 10; left: ".($pos1+18)."px; top: ".($pos2+6)."px;\"><img src=images/galaxy/debris.gif /></SPAN>";
	} else {
		$imagedebris = '';
	}
	
	$page .= $imagedebris;
	$page .= "<div id=\"$e\" style=\" position: absolute; left: ".$pos1."px; top: ".$pos2."px; width: 10px; height: 10px; visibility: visible;\">";
	
	$diff_systeme = pow($CurrentPlanet['phalanx'],2) - 1;
	$systeme_bas  = $CurrentPlanet['system'] - $diff_systeme ;
	$systeme_haut = $CurrentPlanet['system'] + $diff_systeme ;
	
	//On peut phalanger uniquement si on est sur une lune, dans la meme galaxie et dans un intervalle de systeme donné par le niveau de la phalange!
	if ($CurrentPlanet['planet_type'] == 3 && $galaxy == $CurrentPlanet['galaxy'] && $systeme_bas <= $system && $systeme_haut >= $system)
		$Phalanger[$nb] = "<a href=phalanx.php?galaxy=".$galaxy."&system=".$system."&planet=".$nb."><font color=yellow>Phalanger [port&eacute;e: ".$diff_systeme." syst.]</font></a>";
	else  // On ne peut pas phalanger si on n'est pas sur la lune ( si on est sur la planète)...
		$Phalanger[$nb] = "<font color=red>Phalanger<br>";
	
	// On transforme les apostrophe dans les noms d'alliance ( en cause un probleme de compatibilité )
	$Nom_Alliance= str_replace( "'" , "&apos;" , $Alliance[$count] );
	
			
				// Planète libre ou occupée? (+images)
				if ($PlaneteOccupee[$count] != "Libre" && $PlaneteOccupee[$count] != "") {   //--> Zut c'est occupée!
					$page .= "<th width=30><a style=\"cursor: crosshair;\" onmouseover='return overlib(\" <table width=250><tr><td class=c colspan=2><font color=#33CCCC>Plan&egrave;te ".$PlaneteOccupee[$count]." [".$PlaneteID[$count]."]</font><br><a Href=descplanet.php?g=".$galaxy."&s=".$system."&p=".$nb.">Voir sa description</a></td></tr><tr><th width=80><img src=images/galaxy/planeten/s_".$PlaneteImage[$count].".png height=48 width=48 /></th><th>Joueur : ".$UserName[$count]."<br>".$Nom_Alliance."<hr><a href=stat.php?who=player&start=".$Owner[$count]." title=Statistique alt=Statistique>".$AffichPoints."</a><hr>".$PresenceLune[$count]."<hr>".$Ressource[$count]."".$buddy[$count]."".$mail[$count]."<hr><a href=galaxy.php?mode=6&g=".$galaxy."&s=".$system."&p=".$nb."&t=1>Espionner</a><br /><a href=fleet.php?galaxy=$galaxy&system=$system&planet=".$nb."&planettype=1&target_mission=3>Transporter</a><br/><a href=fleet.php?galaxy=$galaxy&system=$system&planet=".$nb."&planettype=1&target_mission=1>Attaquer</a><br /><a href=galaxy.php?mode=2&galaxy=$galaxy&system=$system&planet=".$nb."&current=1>Bombarder</a><br>".$Phalanger[$nb]."</th></tr>  </table>\",STICKY, MOUSEOFF, DELAY, 750, CENTER, OFFSETX, -150, OFFSETY, -150 );' onmouseout='return nd();'>";
				}else{   //--> Ah c'est libre!
					$page .= "<th width=30><a style=\"cursor: crosshair;\" onmouseover='return overlib(\" <table width=250><tr><td class=c colspan=2><center><font color=#33CCCC>Planète</font><br>Position : ".$PlaneteID[$count]."</center></td></tr> <th align=left>D&eacute;couverte d une plan&egrave;te inhabit&eacute;e.<br> La coloniser?<hr><a href=fleet.php?galaxy=$galaxy&system=$system&planet=".$nb."&planettype=1&target_mission=7 title=Coloniser>Coloniser</a><hr>".$Ressource[$count]."</th></tr>  </table>\",STICKY, MOUSEOFF, DELAY, 750, CENTER, OFFSETX, -40, OFFSETY, -40 );' onmouseout='return nd();'>";
				}
				
				if ($PlaneteImage[$count] != ''){	// images des lunes et des planètes
					if ($LuneExistante[$count]) {	// --> Affichage de la planète et de la Lune existante
							$page .= "<div style=\"filter:alpha(opacity=90); -moz-opacity:0.9; -khtml-opacity: 0.9; opacity: 0.9; \">".$nb."</div><img src=images/galaxy/planeten/s_".$PlaneteImage[$count].".png height=\"48\" width=\"48\" /><img src=images/galaxy/lune.png height=\"20\" width=\"20\" />".$UserName[$count]."</th></div>";
					}else{	// --> Image de la planète seulement !
						$page .= "<div style=\"filter:alpha(opacity=90); -moz-opacity:0.9; -khtml-opacity: 0.9; opacity: 0.9; \">".$nb."</div><img src=images/galaxy/planeten/s_".$PlaneteImage[$count].".png height=\"48\" width=\"48\" />".$UserName[$count]."</th></div>";
					}
				}else{	//Planètes libres (images de planètes avec une opacité)
					$page .= "<div style=\"filter:alpha(opacity=90); -moz-opacity:0.9; -khtml-opacity: 0.9; opacity: 0.9; \">".$nb."<img src=images/galaxy/sp".($count+1).".png height=\"48\" width=\"48\"></div><div style=\"filter:alpha(opacity=90); -moz-opacity:0.9; -khtml-opacity: 0.9; opacity: 0.9; \"><font color=#E5E5E5>Libre</font></a></div></th></div>";
				}
				
				$page .= "</a>";
			
			/*******************************************************************************************************************/
			
	$count++;
	$e = $e + 2;
	$f = $f + 2;
}

$page .= "<div id=\"99\" style=\"  left: 600px; top: 20px; width: 1000px; height: 10px;\"></div>";	

display ($page, $lang[''], false, '', false);

?>