<?php

/**
* galaxy.php
*
* @version 1.5 modifié par patu29
* @copyright 2008 by Chlorel for XNova
*/

define('INSIDE' , true);
define('INSTALL' , false);
require_once dirname(__FILE__) .'/common.php';

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;
$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'];
} else {
// Si j'arrive ici ...
// C'est qu'il y a vraiment eu un bug
$galaxy = 1;
$system = 1;
}

$planetcount = 0;
$lunacount = 0;

echo InsertGalaxyScripts ( $CurrentPlanet );


// echo ShowGalaxyFooter ( $galaxy, $system, $CurrentMIP, $CurrentRC, $CurrentSP);

if ($mode == 2) {
$CurrentPlanetID = $_GET['current'];
echo ShowGalaxyMISelector ( $galaxy, $system, $planet, $CurrentPlanetID, $CurrentMIP );
}

echo "<table width=569><tbody>";
echo ShowGalaxySelector ( $galaxy, $system );
echo ShowGalaxyFooter ( $galaxy, $system, $CurrentMIP, $CurrentRC, $CurrentSP);
// $page .= ShowGalaxyTitles ( $galaxy, $system );
// $page .= ShowGalaxyRows ( $galaxy, $system );
// $page .= ShowGalaxyFooter ( $galaxy, $system, $CurrentMIP, $CurrentRC, $CurrentSP);

echo "</center></tbody></table></div>";


echo "

<div id=\"raum_3\" style=\"z-index: 0; position: absolute; top: 110px; height: 0px;\"><img src=\"images/galaxy/espace.gif\" height=\"400\" width=\"400\"></div>
";

$e = 0; $f = 1; $g = 1;
/*
$pos = "376;437;447;410;450;138;533;498;344;372;187;450;601;351;655;200;206;230;651
;483; ​440;287;336;202;276;300;624;400;496;240;424;400;";
*/

$position = array(
"376;437; 447;410; 420;323; 533;498; 344;372; 187;450; 130;340; 555;400; 206;230; 351;483; ​440;300; 336;202; 276;300; 113;192; 496;240; 424;400;");

$randomquote = mt_rand(0,count($position)-1);

$pos = " . $position[$randomquote] . ";



$count = 1;
while($count < 16)
{
$missiontime = explode(";", $pos);
$pos1 = $missiontime[ $e ] +50;
$pos2 = $missiontime[ $f ];

echo "<div id=\"$e\" style=\"z-index: 6; position: absolute; left: ".$pos1."px; top: ".$pos2."px; width: 10px; height: 10px; visibility: visible;\">";
$leer = '';$img = '';

// gestion base galaxie
$query = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '$galaxy' AND `system` = '$system' AND planet = '$count' AND planet_type = '1';", 'planets');
while($row = mysql_fetch_assoc($query)){
$leer = $row['planet'];
$img = $row['image'];
$metal2 = $row['metal'];
$cristal2 = $row['crystal'];
$deut2 = $row['deuterium'];

// gestion base utilisateur
$query1 = doquery("SELECT ally_id, ally_name, username, authlevel, onlinetime, id,bana FROM {{table}} WHERE `id` = '".$row['id_owner']."';", 'users');
while($row1 = mysql_fetch_assoc($query1)){

if ($row1['ally_id'] == '0'){$ally = '';} else {
$ally = " Alliance: <a href=alliance.php?mode=ainfo&a=".$row1['ally_id'].">".$row1['ally_name']."</a><br />";}

if ($row1['authlevel'] == 3)
{$username = "<font color=blue>".$row1['username']."</font>";
$planetname = "<font color=blue>".$row['name']."</font>";


} elseif ($row1['urlaubs_modus'] == 1)
{$username = "<font color=skyblue>".$row1['username']."</font>";
$planetname = "<font color=skyblue>".$row['name']."</font>";

} elseif ($row1['onlinetime'] < (time()-60 * 60 * 24 * 7) AND
$row1['onlinetime'] > (time()-60 * 60 * 24 * 28))
{$username = "<font color=#aaaaaa>".$row1['username']."(i)</font>";
$planetname = "<font color=#aaaaaa>".$row['name']."</font>";

} elseif ($row1['onlinetime'] < (time()-60 * 60 * 24 * 28))
{$username = "<font color=#cccccc>".$row1['username']."(Ii)</font>";
$planetname = "<font color=#cccccc>".$row['name']."</font>";

} elseif ($row1['bana'] == 1)
{$username = "<font color=line-through>".$row1['username']."</font>";
$planet_name = "<font color=line-through>".$row['name']."</font>";

} else {$username = "<font color=limegreen>".$row1['username']."</font>";
$planetname = "<font color=limegreen>".$row['name']."</font>";
}

if ($row1['id'] != $user['id'])
{$buddy ="<a href=buddy.php?a=".$row['id_owner']."&u=".$row['id_owner']."><font color=red>Liste amis</a><br></font>";} else {$buddy ='';}

if ($row1['id'] != $user['id'])
{$mail ="<a href=messages.php?mode=write&id=".$row['id_owner']."><font color=yellow>Message</a><br></font>";} else {$mail ='';}
}
// gestion base Lune
$query2 = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '$galaxy' AND `system` = '$system' AND planet = '$g' Limit 1;", 'galaxy');
while($row2 = mysql_fetch_assoc($query2)){

if ($row2['id_luna'] != '0'){$mond = "<font color=yellow>Lune: Oui</font><br><a href=fleet.php?galaxy=$galaxy&system=$system&planet=$count&planettype=3&target_mission=9><font color=red>Detruire Lune</font></a><br>";}else{$mond = "<font color=yellow>Lune: Non</font><br>";}
if ($row2['id_luna'] != '0'){$mond1 = 1;}else{$mond1 = 0;}


if ($row2['metal'] != '0'){
if ($row2['crystal'] != '0'){

}else {

$galaxy = $row2['galaxy'];

}
}

// gestion base debris
$query3 = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '$galaxy' AND `system` = '$system' AND planet = '$g' Limit 1;", 'galaxy');
while($row3 = mysql_fetch_assoc($query3)){
if ($row3['metal'] != '0'){$debris = 1;}else{$debris = 0;}
if ($row3['crystal'] != '0'){$debris = 1;}else{$debris = 0;}
$metal1 = $row3['metal'];
$crystal1 = $row3['crystal'];
}
}

// Affichage fenetre information planete
echo"<th width=30><a style=\"cursor: crosshair;\" onmouseover='return overlib(\" <table width=250><tr><td class=c colspan=2>Planete: ".$row['name']." [".$row['galaxy'].":".$row['system'].":".$row['planet']."]</td></tr><tr><th width=80><img src=images/galaxy/sp".$g.".png height=48 width=48 /></th><th align=left>Pos. ".$row['planet']."<br>Name: ".$row['name']."<br> Proprio: <a href=stat.php?who=player&start=".$row['id_owner']." title=Statistique alt=Statistik> $username </a><br>$mond $tr $ally $buddy $mail<hr><font color=green>Statistique Planete:</font><br> Metal: $metal2<br>Cristal: $cristal2 <br>Deutrium: $deut2<hr><a href=fleet.php?galaxy=$galaxy&system=$system&planet=$count&planettype=1&target_mission=4>Espionner</a><br><a href=fleet.php?galaxy=$galaxy&system=$system&planet=$count&planettype=1&target_mission=3>Transporter</a><br><a href=fleet.php?galaxy=$galaxy&system=$system&planet=$count&planettype=1&target_mission=1>Attaquer</a><br><a href=galaxy.php?mode=2&galaxy=$galaxy&system=$system&planet=$count&current=1><font color=red>Bombarder</font></a></br><a href=phalanx.php?mode=0#><font color=yellow>Phalanger<br>(Etre sur la lune)</font></a></th></tr> </table>\",STICKY, MOUSEOFF, DELAY, 750, CENTER, OFFSETX, -40, OFFSETY, -40 );' onmouseout='return nd();'>";}

// Affichage fenetre colonisation planete
if ($leer ==''){

echo"<th width=30><a style=\"cursor: crosshair;\" onmouseover='return overlib(\" <table width=250><tr><td class=c colspan=2><center>Cette planete est libre<br>Position: [$galaxy : $system : $count]</center></td></tr> <th align=left>$tr <hr><a href=fleet.php?galaxy=1&system=1&planet=4&planettype=1&target_mission=7>Coloniser</a></th></tr> </table>\",STICKY, MOUSEOFF, DELAY, 750, CENTER, OFFSETX, -40, OFFSETY, -40 );' onmouseout='return nd();'>

";}

//Affichage planete avec Lune et debris + gestion fenetre selection planete
if ($img != '') {

echo "$username <a href=# onclick='java script:doit(6, $galaxy, $system, $g, 1, {$user["spio_anz"]});'><img src=images/galaxy/sp".$g.".png height=\"48\" width=\"48\">($planetname)</a><table width=\"100\" height=\"50\"><tr><td><p><a href=# onclick='java script:doit(6, $galaxy, $system, $g, 3, {$user["spio_anz"]});'><img src=images/galaxy/mond".$mond1.".png><p></a></td><td><a style=\"cursor: crosshair;\" onmouseover='return overlib(\" <table width=150><tr><td class=c colspan=2><br> Metal: $metal1<br>Cristal: $crystal1</th></tr><a href=fleet.php?galaxy=$galaxy&system=$system&planet=$count&planettype=2&target_mission=8>Recycler</a></th></tr> </table>\",STICKY, MOUSEOFF, DELAY, 150, CENTER, OFFSETX, -20, OFFSETY, -50 );' onmouseout='return nd();'><img src=images/galaxy/debris.gif></td></tr></table></div>";

} else {

//Affichage message Libre sous planete libre
echo"<a href=fleet.php?galaxy=$galaxy&system=$system&planet=$count&planettype=1&target_mission=7><img src=images/galaxy/sp".$g.".png height=\"48\" width=\"48\">(Libre)</a></th></div>";}

//Affichage Etendues infini + gestion fenetre selection
echo "<div id=\"99\" style=\"z-index: 7; position: absolute; left: 10px; top: 120px; width: 10px; height: 10px; visibility: visible;\">
<th width=30><a style=\"cursor: crosshair;\" onmouseover='return overlib(\" <table width=250><tr><td class=c colspan=2><center>Etendues infinies</center></td></tr> <th align=left>$tr <hr><a href=fleet.php?galaxy=1&system=1&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/nebuleuse.png height=\"100\" width=\"100\"></a></th></div>";


$e++;$e++; $f++; $f++; $g++;
$count++;
}


display ($page, $lang[''], false, '', false);

// -----------------------------------------------------------------------------------------------------------
// History version
// 1.0 - Created by Perberos
// 1.1 - Modified by -MoF- (UGamela germany)
// 1.2 - 1er Nettoyage Chlorel ...
// 1.3 - 2eme Nettoyage Chlorel ... Mise en fonction et debuging complet
// 1.4 - 3eme Passage en francais et debug position par Patu29
// 1.5 - 4eme Passage par patu29 ... integration Lune et Debris et modification complete des infos planete et structure affichage





?>
