<?php
include ('logue.php'); 
include ('entete2.php');
include ('entete.php');
include ('ressource.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 ) {

$sql2 = "SELECT ptremorqueur,gdremorqueur FROM matgraph_users WHERE id='$planete' ";
$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2); 

$total_place = (($row2[ptremorqueur] * 2500) + ($row2[gdremorqueur] *20000));
$total_place2 = number_format($total_place, 0, ',', ' ');

$sql2 = "SELECT robo_lvl,chantier_lvl,hangarfer_lvl,hangarfer_evolution,hangaror_lvl,hangaror_evolution,hangarada_lvl,hangarada_evolution,hangaror_lvl,hangarura_lvl,hangarura_evolution,labo_lvl,labo_evolution,fer_energie,or_energie,ada_energie,ura_energie,exfer_energie,exor_energie,central_energie FROM matgraph_users WHERE id='$planete' ";
$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2); 
$Total_energie_consom = $row2[fer_energie] + $row2[or_energie] + $row2[exfer_energie] + $row2[exor_energie] + $row2[ada_energie] + $row2[ura_energie] ;
$Total_energie_reste =  round(($New_central_energie + $New_fission_energie + $Total_energie_consom),0);
$Total_energie_prod = round(($New_central_energie + $New_fission_energie),0);
$Total_energie_reste2 =  number_format(round(($New_central_energie + $New_fission_energie + $Total_energie_consom),0), 0, ',', ' ');
$Total_energie_prod2 = number_format(round(($New_central_energie + $New_fission_energie),0), 0, ',', ' ');

$sql = "SELECT pts FROM matgraph_users WHERE id='$dataid[id]' ";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 

$pts = floor(($row[pts] / 1000)) ;

$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 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 Maxfer(maximum) {
	var total = Math.round('$total_place');
	total-= Math.round(document.getElementById('fer').value);
	total-= Math.round(document.getElementById('or').value);
	total-= Math.round(document.getElementById('ada').value);
	total-= Math.round(document.getElementById('ura').value);
	
  if((total - Math.round(maximum)) < 0)
  {
  	document.getElementsByName('fer')[0].value = total;
  }
  else
  {
  	document.getElementsByName('fer')[0].value = Math.round(maximum);
  }
}
function Maxor(maximum) {
	var total = Math.round('$total_place');
	total-= Math.round(document.getElementById('fer').value);
	total-= Math.round(document.getElementById('or').value);
	total-= Math.round(document.getElementById('ada').value);
	total-= Math.round(document.getElementById('ura').value);
	
  if((total - Math.round(maximum)) < 0)
  {
  	document.getElementsByName('or')[0].value = total;
  }
  else
  {
  document.getElementsByName('or')[0].value = Math.round(maximum);
  }
}
function Maxada(maximum) {
	var total = Math.round('$total_place');
	total-= Math.round(document.getElementById('fer').value);
	total-= Math.round(document.getElementById('or').value);
	total-= Math.round(document.getElementById('ada').value);
	total-= Math.round(document.getElementById('ura').value);
	
  if((total - Math.round(maximum)) < 0)
  {
  	document.getElementsByName('ada')[0].value = total;
  }
  else
  {
  document.getElementsByName('ada')[0].value = Math.round(maximum);
  }
}
function Maxura(maximum) {
	var total = Math.round('$total_place');
	total-= Math.round(document.getElementById('fer').value);
	total-= Math.round(document.getElementById('or').value);
	total-= Math.round(document.getElementById('ada').value);
	total-= Math.round(document.getElementById('ura').value);
	
  if((total - Math.round(maximum)) < 0)
  {
  	document.getElementsByName('ura')[0].value = total;
  }
  else
  {
  document.getElementsByName('ura')[0].value = Math.round(maximum);
  }
}
</script>
<script language=\"javascript\">

function restefret()
{
	var total = Math.round('$total_place');
	total-= Math.round(document.getElementById('fer').value);
	total-= Math.round(document.getElementById('or').value);
	total-= Math.round(document.getElementById('ada').value);
	total-= Math.round(document.getElementById('ura').value);
	
	if (total < 0 )
	{
	  alert (' Vous ne disposez pas de la place nécessaire. ');
	  document.getElementById('restefret_ligne').innerHTML = total;
	  document.getElementById('fret').value= total;
	}
	else
	{
	  document.getElementById('restefret_ligne').innerHTML = total;
	  document.getElementById('fret').value= total;
	}
}
</script>
<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'); 
echo"<div align=\"center\">
<table width=\"618\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
    <tr>
      <td colspan=\"3\" align=\"center\"><b>Mission transport :</b>
<br><br>
La mission <b>\"Transport\"</b> consiste à envoyer des ressources sur une planète avec qui vous avez un pacte total ou commercial. 
<br>Vous disposez, actuellement, assez de remorqueurs pour envoyer $total_place2 de ressources.
<input name=\"fret\" value=\"$total_place\" type=\"hidden\" id=\"fret\">
<br>
<table width=\"450\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
  <tr align=\"center\">
    <td align=\"right\" width=\"65%\">Vous pouvez encore transporter : </td>
    <td align=\"left\" width=\"35%\"><b><div name=\"restefret_ligne\" id=\"restefret_ligne\">$total_place</div></b></td>
  </tr></table>
  </td>
    </tr>
  </table><br><br>Vous possédez $eppz E.P.P.Z . Un E.P.P.Z contient 60 000 d'energies.<br><br>
<form name=\"form1\" method=\"post\" action=\"transport_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=\"174\"><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>
    <tr>
      <td rowspan=\"2\">Ressources : </td>
      <td height=\"39\"><div align=\"left\">Fer : 
        <input name=\"fer\" type=\"text\" id=\"fer\" value=\"0\" onChange=\"restefret();\">  <a href=\"javascript:Maxfer($newwfer_ressource);restefret();\"> Max </a>
      </div></td>
      <td>Or : 
      <input name=\"or\" type=\"text\" id=\"or\" value=\"0\" onChange=\"restefret();\"> <a href=\"javascript:Maxor($newwor_ressource);restefret();\"> Max </a></td>
    </tr>
    <tr>
      <td height=\"42\"><div align=\"left\">Cristal : 
        <input name=\"ada\" type=\"text\" id=\"ada\" value=\"0\" onChange=\"restefret();\"> <a href=\"javascript:Maxada($newwada_ressource);restefret();\"> Max </a>
      </div></td>
      <td height=\"42\">Naquadah : 
      <input name=\"ura\" type=\"text\" id=\"ura\" value=\"0\" onChange=\"restefret();\"> <a href=\"javascript:Maxura($newwura_ressource);restefret();\"> Max </a></td>
    </tr>
    <tr style =\"background-color:#111111;\">
      <td colspan=\"3\" height=\"40\"><div align=\"center\">
        <input type=\"submit\" name=\"Submit\" value=\"Activer la porte des étoiles\">
      </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)
		{
			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>";
		}
		if($i == 2)
		{
			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>";
		}
		if($i == 3)
		{
			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>";
		}
		if($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>";
		}
		if($i == 5)
		{
			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>";
		}
		if($i == 6)
		{
			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>";
		}
		if($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>";
		}
		if($i == 8)
		{
			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>";
		}
		if($i == 9)
		{
			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>";
		}
		if($i == 10)
		{
			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>";
		}
		if($i == 11)
		{
			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>";
		}
		if($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>
			";
		}
		
	$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>
<table width=\"618\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
    <tr>
      <td colspan=\"3\" align=\"center\"><br>En entrant les coordonnées d’une planète et en activant la porte des étoiles, un vortex se crée et vos remorqueurs traversent la porte des étoiles.</td>
    </tr>
  </table>";

}
else {
$Total_energie_consom = $row2[fer_energie] + $row2[or_energie] + $row2[exfer_energie] + $row2[exor_energie] + $row2[ada_energie] + $row2[ura_energie] ;
$Total_energie_reste =  round(($New_central_energie + $New_fission_energie + $Total_energie_consom),0);
$Total_energie_prod = round(($New_central_energie + $New_fission_energie),0);
$Total_energie_reste2 =  number_format(round(($New_central_energie + $New_fission_energie + $Total_energie_consom),0), 0, ',', ' ');
$Total_energie_prod2 = number_format(round(($New_central_energie + $New_fission_energie),0), 0, ',', ' ');
echo"
<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=\"colonies.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=\"espio1\" type=\"hidden\" id=\"page\">
         <select name=\"idcolo\" onchange=submit()>";
include ('colo2.php'); 
echo"<br><br>Vous n'avez pas de porte des étoiles sur cette planete."; } 
?>