<?php
include ('logue.php'); 
include ('entete2.php');
include ('entete.php');
include ('ressource.php');

$sql = "SELECT mili_lvl,ptremorqueur,gdremorqueur,labo_lvl,malp,chantier_lvl,hangarfer_lvl,hangarfer_evolution,hangaror_lvl,hangaror_evolution,hangarada_lvl,hangarada_evolution,hangaror_lvl,hangarura_lvl,hangarura_evolution,deflasersimple,deflaserdouble,defelec,defions,defplasma,defnaqua,defanciens,defense_lvl,defense_evolution,defcombat,robo_lvl,labo_lvl,labo_evolution,fer_energie,or_energie,ada_energie,ura_energie,exfer_energie,exor_energie,central_energie  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); 

$sql2 = "SELECT pts,techenergie_lvl,techenergie_evolution,techlaser_lvl,techlaser_evolution,techions_lvl,techions_evolution,techplasma_lvl,techplasma_evolution,techordi_lvl,techordi_evolution,techcombustion_lvl,techcombustion_evolution,techAsgaards_lvl,techAsgaards_evolution,techhyperespace_lvl,techhyperespace_evolution,techespio1_lvl,techespio1_evolution,techespio2_lvl,techespio2_evolution,techArmement_lvl,techArmement_evolution,techBouclier_lvl,techBouclier_evolution,techcoque_lvl,techcoque_evolution,robo_lvl,labo_lvl,labo_evolution,fer_energie,or_energie,ada_energie,ura_energie,exfer_energie,exor_energie,central_energie,techproAsgaard_lvl,techproAsgaard_evolution,techproAncien_lvl,techproAncien_evolution,techinfra_lvl,techinfra_evolution,technaqua_lvl,technaqua_evolution  FROM matgraph_users WHERE id='$dataid[id]' ";
$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2); 

echo "<script type='text/javascript'>
function Coordauto(galaxi, system, position) {
  document.getElementsByName('galaxi')[0].value = galaxi;
  document.getElementsByName('system')[0].value = system;
  document.getElementsByName('position')[0].value = position;
}
function Maxgdremorqueur(maximum) {
  document.getElementsByName('nombre_gdremorqueur')[0].value = Math.round(maximum);
}
function Maxptremorqueur(maximum) {
  document.getElementsByName('nombre_ptremorqueur')[0].value = Math.round(maximum);
}
function Maxmalp(maximum) {
  document.getElementsByName('nombre_malp')[0].value = Math.round(maximum);
}
function Maxmili(maximum) {
  document.getElementsByName('nombre_mili')[0].value = Math.round(maximum);
}
function Maxeppz(maximum) {
  document.getElementsByName('nombre_eppz')[0].value = Math.round(maximum - 1);
}</script>";

// mili
if ($row[mili_lvl] =="0") {
$mili_lvl = "0";
}
else {
$mili_lvl = $row[mili_lvl];
}
// chantier
if ($row[chantier_lvl] =="0") {
$chantier_lvl = "0";
}
else {
$chantier_lvl = $row[chantier_lvl];
}
// labo
if ($row[labo_lvl] =="0") {
$labo_lvl = "0";
}
else {
$labo_lvl = $row[labo_lvl];
}
// techenergie
if ($row2[techenergie_lvl] =="0") {
$techenergie_lvl = "0";
}
else {
$techenergie_lvl = $row2[techenergie_lvl];
}
// techlaser
if ($row2[techlaser_lvl] =="0") {
$techlaser_lvl = "0";
}
else {
$techlaser_lvl = $row2[techlaser_lvl];
}
// techions
if ($row2[techions_lvl] =="0") {
$techions_lvl = "0";
}
else {
$techions_lvl = $row2[techions_lvl];
}
// techplasma
if ($row2[techplasma_lvl] =="0") {
$techplasma_lvl = "0";
}
else {
$techplasma_lvl = $row2[techplasma_lvl];
}
// techordi
if ($row2[techordi_lvl] =="0") {
$techordi_lvl = "0";
}
else {
$techordi_lvl = $row2[techordi_lvl];
}
// techcombustion
if ($row2[techcombustion_lvl] =="0") {
$techcombustion_lvl = "0";
}
else {
$techcombustion_lvl = $row2[techcombustion_lvl];
}
// techAsgaards
if ($row2[techAsgaards_lvl] =="0") {
$techAsgaards_lvl = "0";
}
else {
$techAsgaards_lvl = $row2[techAsgaards_lvl];
}
// techhyperespace
if ($row2[techhyperespace_lvl] =="0") {
$techhyperespace_lvl = "0";
}
else {
$techhyperespace_lvl = $row2[techhyperespace_lvl];
}
// techespio1
if ($row2[techespio1_lvl] =="0") {
$techespio1_lvl = "0";
}
else {
$techespio1_lvl = $row2[techespio1_lvl];
}
// techespio2
if ($row2[techespio2_lvl] =="0") {
$techespio2_lvl = "0";
}
else {
$techespio2_lvl = $row2[techespio2_lvl];
}
// techArmement
if ($row2[techArmement_lvl] =="0") {
$techArmement_lvl = "0";
}
else {
$techArmement_lvl = $row2[techArmement_lvl];
}
// techBouclier
if ($row2[techBouclier_lvl] =="0") {
$techBouclier_lvl = "0";
}
else {
$techBouclier_lvl = $row2[techBouclier_lvl];
}
// techcoque
if ($row2[techcoque_lvl] =="0") {
$techcoque_lvl = "0";
}
else {
$techcoque_lvl = $row2[techcoque_lvl];
}
// techproAsgaard
if ($row2[techproAsgaard_lvl] =="0") {
$techproAsgaard_lvl = "0";
}
else {
$techproAsgaard_lvl = $row2[techproAsgaard_lvl];
}
// techproAncien
if ($row2[techproAncien_lvl] =="0") {
$techproAncien_lvl = "0";
}
else {
$techproAncien_lvl = $row2[techproAncien_lvl];
}
// techinfra
if ($row2[techinfra_lvl] =="0") {
$techinfra_lvl = "0";
}
else {
$techinfra_lvl = $row2[techinfra_lvl];
}
// technaqua
if ($row2[technaqua_lvl] =="0") {
$technaqua_lvl = "0";
}
else {
$technaqua_lvl = $row2[technaqua_lvl];
}

$sql = "SELECT galaxi,system,position,eppz,place,placepris,planete 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); 
$placelibre = $row[place]-$row[placepris];

$eppz = floor($row[eppz]) + 1 ;
$seppz = number_format(($row[eppz] * 60000), 0, ',', ' ');

echo"<script language=\"javascript\">
function couteppz() {

  var Besoin_energie = 0;

  if ( Math.round( document.getElementById('galaxi').value ) != $row[galaxi] ) {

    Dif_galaxi = Math.abs ( Math.round(document.getElementById('galaxi').value) - $row[galaxi] ) ;

    Besoin_energie = Dif_galaxi*30000;

  }
  else {

    if ( Math.round(document.getElementById('system').value) != $row[system] ) {

      Dif_system = Math.abs ( Math.round(document.getElementById('system').value) - $row[system] );

      if (Dif_system > 50)
        Besoin_energie = 30000;	

      else if (Dif_system > 20)
        Besoin_energie = 20000;	
	
      else if (Dif_system > 10)
        Besoin_energie = 10000;
	
      else if (Dif_system > 5)
        Besoin_energie = 5000;	
	
      else
        Besoin_energie = 2000;
    }
    else {

      if ( Math.round(document.getElementById('position').value) != $row[position] )
        Besoin_energie = 1000;

    }

  }

  startnb = Besoin_energie.toString();

  imax = Math.ceil( startnb.length / 3);
  endnb = '';
  nombre = new Array();

  for( i = 1; i <= imax; i++) {

    j = startnb.length - ( i * 3 );
    if ( j < 0 ) {
       h = 3 +  j;
       j = 0;
    }
    else {
       h =3;
    }

    nombre[i] = startnb.substr( j , h );

  }

  for( i-=1;  i > 0;  i--) {

    if ( i > 0 )
       endnb+=' ';

    endnb+= nombre[i];

  }

  document.getElementById('couteppz_ligne').innerHTML = endnb;
}

</script>
<style>
input {
border:1px solid #7E7E7E;
background-color:#000000;
font-family:'trebuchet ms',sans-serif;
color:white;
}
textarea {
border:1px solid #7E7E7E;
background-color:#000000;
font-family:'trebuchet ms',sans-serif;
color:white;
}
select, option {
background-color:#000000;
color:white;
}
</style>
<STYLE TYPE=text/css>
.Style1 {color: #0000FF}
.Style2 {color: #FF0000}
</STYLE>";
echo"<div align=\"center\"><form name=\"colo\" method=\"post\" action=\"colonie.php\" target=\"_parent\">
<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
   <tr>
     <td width=\"100\" rowspan=\"2\" valign=\"middle\">
       <div align=\"center\">
         <input name=\"page\" value=\"" . $PHP_SELF . "\" type=\"hidden\" id=\"page\">
         <select name=\"idcolo\" onchange=submit()>";
include ('colo2.php'); 

$sql = "SELECT labo_lvl 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); 
if ($row[labo_lvl] >= 5 ) {

$sql = "SELECT ptremorqueur,gdremorqueur,malp,mili_nbre  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); 

$mili_nbre = number_format((floor($row[mili_nbre])), 0, ',', ' ');
echo"<div align=\"center\">
  <table width=\"618\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
    <tr>
      <td colspan=\"3\" align=\"center\"><b>Mission Baser :</b> <br>
          <br>
        La mission <b>\"Baser\"</b> consiste à transférer un ou plusieurs vaisseaux (capable de passer la porte des étoiles) ou hommes vers une autre planète (une de vos colonies ou une planète alliée).
<br>Une fois de l'autre côté de la porte des étoiles, les troupes et/ou le matériel envoyés sont opérationnels sur leur nouvelle planète. 
</td>
    </tr>
  </table>
  <p>Vous poss&eacute;dez $eppz E.P.P.Z . Un E.P.P.Z contient 60 000 d'energies.</p>
  <form name=\"form1\" method=\"post\" action=\"baser_envoi.php\" target=\"_parent\">
    <table width=\"618\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#000000\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">
      <tr style =\"background-color:#222222;\">
      <td colspan=\"3\"><div align=\"center\">Entrez les coordonn&eacute;es de la planète pour envoyer les ressources : </div></td>
    </tr>
    <tr>
      <td width=\"305\"><div align=\"center\">Galaxie</div></td>
      <td width=\"211\"><div align=\"center\">Systeme Solaire </div></td>
      <td width=\"225\"><div align=\"center\">Position </div></td>
    </tr>
    <tr style =\"background-color:#111111;\">
      <td><div align=\"center\">
        <input name=\"galaxi\" id=\"galaxi\" type=\"text\" value=\"$galaxi\" onChange=\"couteppz();\">
      </div></td>
      <td><div align=\"center\">
        <input name=\"system\" id=\"system\" type=\"text\" value=\"$system\" onChange=\"couteppz();\">
      </div></td>
      <td><div align=\"center\">
        <input name=\"position\" id=\"position\" type=\"text\" value=\"$position\" onChange=\"couteppz();\">
      </div></td>
    </tr>";
if($eppz > "1") {
echo"<tr>
        <td width=\"305\" height=\"29\"><div align=\"left\">Nombre d'E.P.P.Z : 
              
      </div></td>
        <td align=\"right\">
            <input name=\"nombre_eppz\" type=\"text\" id=\"nombre_eppz\" value=\"0\"></td>
		  <td align=\"left\"><a href=\"javascript:Maxeppz($eppz);\"> Max </a></td>
      </tr>"; }
if($row[mili_nbre] > "0") {
echo"<tr style =\"background-color:#111111;\">
        <td width=\"305\" height=\"29\"><div align=\"left\">Nombre de militaire : 
              
      </div></td>
        <td align=\"right\"><input name=\"nombre_mili\" type=\"text\" id=\"nombre_mili\" value=\"0\"></td>
		  <td align=\"left\"><a href=\"javascript:Maxmili($row[mili_nbre]);\"> Max </a></td>
      </tr>"; }
if ($row[malp] > "0") {  
echo"<tr>
        <td height=\"29\"><div align=\"left\">Nombre de M.A.L.P :
        </div></td>
        <td align=\"right\"><input name=\"nombre_malp\" type=\"text\" id=\"nombre_malp\" value=\"0\"></td>
		 <td align=\"left\"><a href=\"javascript:Maxmalp($row[malp]);\"> Max </a></td>
      </tr>"; }
if ($row[ptremorqueur] > "0") {
echo"<tr style =\"background-color:#111111;\">
        <td height=\"29\"><div align=\"left\">Nombre de Petit Remorqueur :
		</div></td>
        <td align=\"right\"><input name=\"nombre_ptremorqueur\" type=\"text\" id=\"nombre_ptremorqueur\" value=\"0\"></td>
		  <td align=\"left\"><a href=\"javascript:Maxptremorqueur($row[ptremorqueur]);\"> Max </a></td>
	  </tr>"; }
if ($row[gdremorqueur] > "0") {
echo"<tr>
        <td height=\"31\"><div align=\"left\">Nombre de Grand Remorqueur :
		</div></td>
        <td align=\"right\"><input name=\"nombre_gdremorqueur\" type=\"text\" id=\"nombre_gdremorqueur\" value=\"0\"></td>
		  <td align=\"left\"><a href=\"javascript:Maxgdremorqueur($row[gdremorqueur]);\"> Max </a></td>
	  </tr>"; }
echo"<tr style =\"background-color:#111111;\">
        <td height=\"40\" colspan=\"3\"><div align=\"center\">
            <input type=\"submit\" name=\"Submit\" value=\"Envoyer\">
        </div></td>
      </tr>
    </table>
  </form>
</div>";


	$reqra = "SELECT planete,galaxi,system,position FROM matgraph_users WHERE idjoueur='$idlogin' ORDER BY id ASC";
	$resra = db_mysql_Query($reqra) or die('Erreur SQL! <br>'.$reqra.'<br>'.mysql_error());
	$numra = mysql_num_rows($resra);
	$i=1;
	echo"<div align=\"center\"><br><table width=\"618\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">
  <tr style =\"background-color:#222222;\">
	<td  colspan=\"3\" align=\"center\">Raccourcis :</td>
	</tr>";

	While ( $rowra = mysql_fetch_array($resra) )	{
		if($i==1 || $i==7)
			echo"<tr>
				<td align=\"center\"><a href=\"javascript:Coordauto($rowra[galaxi],$rowra[system],$rowra[position]);couteppz();\"> $rowra[planete] ($rowra[galaxi] : $rowra[system] : $rowra[position])</a></td>";
		elseif ($i==3 || $i==6 || $i==9 || $i==12)
		  echo"<td align=\"center\"><a href=\"javascript:Coordauto($rowra[galaxi],$rowra[system],$rowra[position]);couteppz();\"> $rowra[planete] ($rowra[galaxi] : $rowra[system] : $rowra[position])</a></td>
			</tr>";
    elseif($i == 4)
			echo"<tr style =\"background-color:#111111;\">
			<td align=\"center\"><a href=\"javascript:Coordauto($rowra[galaxi],$rowra[system],$rowra[position]);couteppz();\"> $rowra[planete] ($rowra[galaxi] : $rowra[system] : $rowra[position])</a></td>";
		elseif($i==10)
			echo"<tr style =\"background-color:#111111;\"><td>&nbsp;</td>
				<td align=\"center\"><a href=\"javascript:Coordauto($rowra[galaxi],$rowra[system],$rowra[position]);couteppz();\"> $rowra[planete] ($rowra[galaxi] : $rowra[system] : $rowra[position])</a></td>
        <td>&nbsp;</td></tr>";
		else		
		  echo"<td align=\"center\"><a href=\"javascript:Coordauto($rowra[galaxi],$rowra[system],$rowra[position]);couteppz();\"> $rowra[planete] ($rowra[galaxi] : $rowra[system] : $rowra[position])</a></td>";
	$i++;
	}
	echo"</tr>
			</table><br><br>";

echo"<table width=\"618\"  border=\"1\" cellspacing=\"0\" cellpadding=\"0\">
    <tr>
      <td align=\"center\">La somme de vos E.P.P.Z fait $seppz .
	  <br>Votre consomation d'energie est de : <b><font color=\"FF0000\"><div name=\"couteppz_ligne\" id=\"couteppz_ligne\">0</div></font></b></td>
    </tr>
  </table><br><br>
<table width=\"618\"  border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
  <tr>
    <td>En entrant les coordonn&eacute;es d&rsquo;une plan&egrave;te et en activant la porte des &eacute;toiles, un vortex se cr&eacute;e et vos unit&eacute;s traverse la porte des &eacute;toiles. Une fois de l&rsquo;autre c&ocirc;t&eacute;, elles s&rsquo;ajouteront aux unit&eacute;s d&eacute;j&agrave; en place.</td>
  </tr>
</table>
<br><br><table width=\"341\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#000000\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">
  <tr style =\"background-color:#222222;\">
    <td width=\"151\"><div align=\"left\"><strong>Type : </strong></div></td>
    <td width=\"184\"><div align=\"center\"><strong>Nombre : </strong></div></td>
  </tr>";
if($eppz > "1") {
echo"<tr style =\"background-color:#111111;\">
    <td><div align=\"left\">E.P.P.Z</div></td>
    <td><div align=\"center\">$eppz</div></td>
  </tr>"; }
if($row[mili_nbre] > "0") {
echo"<tr>
    <td><div align=\"left\">Militaire</div></td>
    <td><div align=\"center\">$mili_nbre</div></td>
  </tr>"; }
if ($row[malp] > "0") {  
echo"<tr style =\"background-color:#111111;\">
    <td><div align=\"left\">M.A.L.P</div></td>
    <td><div align=\"center\">$row[malp]</div></td>
  </tr>"; }
if ($row[ptremorqueur] > "0") {
echo"<tr>
    <td><div align=\"left\">Petits Remorqueurs</div></td>
    <td><div align=\"center\">$row[ptremorqueur]</div></td>
  </tr>"; }
if ($row[gdremorqueur] > "0") {
echo"<tr style =\"background-color:#111111;\">
    <td><div align=\"left\">Grands Remorqueurs</div></td>
    <td><div align=\"center\">$row[gdremorqueur]</div></td>
  </tr>
</table>";}

}
else {
echo"<br><br>Vous n'avez pas de porte des étoiles sur cette planete."; } 
?>
