<?php
include ('logue.php'); 
include ('entete2.php');
include ('entete.php');
include ('ressource.php');
$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 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2); 

$sqlsecu = "SELECT labo_lvl FROM matgraph_users WHERE id='$planete' ";
$ressecu = mysql_query($sqlsecu)or die('erreur sql<br>'.$sqlsecu.'<br>'.mysql_error());
$rowsecu = mysql_fetch_array($ressecu); 
if ($rowsecu[labo_lvl] < 5 ) {
	echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("transport.php");
-->
</script>';
exit;
}

if( isset($_SESSION['date_secu_envoi']) ) {
	if ( $_SESSION['date_secu_envoi'] > time() ) {
		echo" <br><br> Par raison de sécurité vous ne pouvez pas utilisé ce service plus d'une fois toutes les 5 secondes. <br>";
		exit;
	} else {
		$_SESSION['date_secu_envoi'] = time() + 5 ; 
	}
} else {
	$_SESSION['date_secu_envoi'] = time() + 5 ; 
}


$galaxi = htmlentities ($_POST["galaxi"]);
$system = htmlentities ($_POST["system"]);
$position = htmlentities ($_POST["position"]);
$fer = htmlentities ($_POST["fer"]);
$or = htmlentities ($_POST["or"]);
$ada = htmlentities ($_POST["ada"]);
$ura = htmlentities ($_POST["ura"]);


$sql = "SELECT ptremorqueur,gdremorqueur,galaxi,system,position,eppz,place,placepris,planete FROM matgraph_users WHERE id='$planete' ";
$res = mysql_query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 
$placelibre = $row[place]-$row[placepris];

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

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


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 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'); 

$form = "
<table width=\"618\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
    <tr>
      <td colspan=\"3\" align=\"center\">
<div align=\"center\"><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>
<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 = mysql_query($reqra) or die('Erreur SQL! <br>'.$reqra.'<br>'.mysql_error());
	$numra = mysql_num_rows($resra);
	$i=1;
	$form.="<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)
		{
			$form.="<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)
		{
			$form.="<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)
		{
			$form.="<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)
		{
			$form.="<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)
		{
			$form.="<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)
		{
			$form.="<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)
		{
			$form.="<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)
		{
			$form.="<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)
		{
			$form.="<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)
		{
			$form.="<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)
		{
			$form.="<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)
		{
			$form.="<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++;
	}
	
	$form.="</tr>
			</table><br><br>";
$form.="<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>";

$Test_errorgalaxi = preg_match('!^[0-9]*$!', $galaxi) ;
$Test_errorsystem = preg_match('!^[0-9]*$!', $system) ;
$Test_errorposition = preg_match('!^[0-9]*$!', $position) ;
if ( $system > 100 OR $system < 1 OR  $position > 10 OR $position < 1 OR $Test_errorgalaxi == 0 OR $Test_errorgalaxi == FALSE OR $Test_errorsystem == 0 OR $Test_errorsystem == FALSE OR $Test_errorposition == 0 OR $Test_errorposition == FALSE) {
echo"<br><br>Message de la salle de contrôle :
<br><br>La porte des étoiles ne s'est pas activée, les coordonnées saisies ne correspondent à aucune planète.
"; 
echo"$form";
exit;}

$req = "SELECT id FROM matgraph_users WHERE galaxi='$galaxi' AND system='$system' AND position='$position'";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num == "0" ) {
echo"<br><br>Message de la salle de contrôle :
<br><br>Cette planète est inhabitée.";
echo"$form";
exit;}

if ($newwfer_ressource < $fer || $newwor_ressource < $or || $newwada_ressource < $ada || $newwura_ressource < $ura) {
echo"<br><br>Message de la salle de contrôle :
<br><br>Vous n'avez pas assez de ressource à envoyer.Veuillez en selectionner moins.
"; 
echo"$form";
exit;}

if($fer < 0 OR $fer =="")
{
	$fer=0;
}
if($or < 0 OR $or =="")
{
	$or=0;
}
if($ada < 0 OR $ada =="")
{
	$ada=0;
}
if($ura < 0 OR $ura =="")
{
	$ura=0;
}
$fer=0+$fer;
$or=0+$or;
$ada=0+$ada;
$ura=0+$ura;

$total_ressource =  $fer + $or + $ada + $ura;
$sql2 = "SELECT ptremorqueur,gdremorqueur FROM matgraph_users WHERE id='$planete' ";
$res2 = 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, ',', ' ');

if ($total_ressource > $total_place) {
echo"<br><br>Message de la salle de contrôle :
<br><br>Vous n'avez pas assez de remorqueur pour envoyer toutes ces ressources.Veuillez en selectionner moins.
"; 
echo"$form";
exit;}

$req = "SELECT idjoueur FROM matgraph_users WHERE galaxi='$galaxi' AND system='$system' AND position='$position'";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 
$req = "SELECT vacance FROM matgraph_users WHERE id=$row[idjoueur]";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 
if($row[vacance] != "0000-00-00 00:00:00") {
echo"<br><br>Message de la salle de contrôle :
<br><br>Ce joueur est en mode vacance."; 
echo"$form";
exit;}

$req = "SELECT id,idjoueur FROM matgraph_users WHERE galaxi='$galaxi' AND system='$system' AND position='$position'";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 

$req = "SELECT id FROM matgraph_commerce WHERE joueur1='$row[idjoueur]' AND joueur2='$idlogin' AND type='Commercial'";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$req2 = "SELECT id FROM matgraph_commerce WHERE joueur1='$row[idjoueur]' AND joueur2='$idlogin' AND type='Total'";
$res2 = mysql_query($req2) or die('Erreur SQL! <br>'.$req2.'<br>'.mysql_error());
$num2 = mysql_num_rows($res2);

$req = "SELECT id,idjoueur FROM matgraph_users WHERE galaxi='$galaxi' AND system='$system' AND position='$position'";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 
if ( $row[idjoueur] == $idlogin ) { }
else {
if ( $num == "0" AND $num2 == "0" ) {
echo"<br><br>Message de la salle de contrôle :
<br><br>Vous n'avez pas l'autorisation d'envoyer des ressources sur cette planete.Veuillez en demmander une avec une mission d'exploration.
"; 
echo"$form";
exit;}}


$sql2 = "SELECT galaxi,system,position,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 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2); 
$systempla = $row2[system];
if ($system == $systempla AND $galaxi == $row2[galaxi]) {
$Besoin_energie = 100; }
if ($system != $systempla AND $galaxi == $row2[galaxi]) {
$Dif_system = $system - $systempla; }
if($Dif_system<0) { $Dif_system = -1*$Dif_system; }

	if ($Dif_system < 101) {
	$Besoin_energie = 3000; }	
	
	if ($Dif_system < 51) {
	$Besoin_energie = 2000; }	
	
	if ($Dif_system < 21) {
	$Besoin_energie = 1000; }
	
	if ($Dif_system < 11) {
	$Besoin_energie = 500; }	
	
	if ($Dif_system < 6) {
	$Besoin_energie = 200; }


if ($galaxi != $row2[galaxi]) 
{
	$Dif_galaxi = ($galaxi - $row2[galaxi]);
	
	if($Dif_galaxi < 0) 
	{ 
		$Dif_galaxi = -1*$Dif_galaxi; 
	}
	
	$Besoin_energie = 3000*$Dif_galaxi;
}
$New_Besoin_energie = $Besoin_energie*10;
$sqlenergie = "SELECT eppz,fer_energie,or_energie,ada_energie,ura_energie FROM matgraph_users WHERE id='$planete' ";
$resenergie = mysql_query($sqlenergie)or die('erreur sql<br>'.$sqlenergie.'<br>'.mysql_error());
$rowenergie = mysql_fetch_array($resenergie); 
$eppz = 60000*$rowenergie[eppz];

$New_Besoin_energie2 = number_format($New_Besoin_energie, 0, ',', ' ');
if($eppz < $New_Besoin_energie) {
echo"<div align=\"center\">$Besoin_energie2 d'energie sont necessaire pour aller à ces coordonnées.";
echo"$form";
exit; }

$req = "SELECT id,idjoueur FROM matgraph_users WHERE galaxi='$galaxi' AND system='$system' AND position='$position'";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 

if($row[id] == $planete) {

echo"<br><br>Message de la salle de contrôle :
<br><br>La porte n'arrive pas à s'ouvrir.
"; 
echo"$form";
exit;}

$req = "SELECT login FROM matgraph_users WHERE galaxi='$galaxi' AND system='$system' AND position='$position'";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num == "0" ) {

echo"<br><br>Message de la salle de contrôle :
<br><br>La planète explorée est inhabitée. Votre M.A.L.P est revenu à la base.
"; 
echo"$form";
exit;}

$req = "SELECT labo_lvl,idjoueur FROM matgraph_users WHERE galaxi='$galaxi' AND system='$system' AND position='$position'";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$row = mysql_fetch_array($res);

if ( $row['labo_lvl'] < 4) {
echo"<br><br>Message de la salle de contrôle :
<br><br>Il n'y a pas encore de porte des étoiles sur cette planète.";
echo"$form";
exit;
}

if($row['idjoueur'] != $idlogin)
{
	$req = "SELECT ip FROM matgraph_ip WHERE idlogin='$row[idjoueur]'"; 
	$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
	$row = mysql_fetch_array($res); 
	
	$req2 = "SELECT ip FROM matgraph_ip WHERE idlogin='$idlogin'"; 
	$res2 = mysql_query($req2) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
	$row2 = mysql_fetch_array($res2); 
	
	if ( $row['ip'] == $row2['ip']) {
		echo"
		<br>
		<br>Message de la salle de contrôle :
		<br>
		<br><font color=\"FF0000\">/!\ ATTENTION /!\ : Detection de multi-comptes !</font> 
		<br>Rappel : Il est interdit de possèder plusieurs comptes, 
		<br>si vous etes plusieurs a jouer sur le meme pc, vous devez le signaler sur le forum et vous n'avez pas le droit de commercer ensemble. "; 
		echo"$form";
		//premier ordre
		$req = "SELECT id FROM matgraph_multi WHERE joueur2='$id_espionner2' AND joueur1='$idlogin' limit 1";
		$res = 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) ) {
  			$requete = "UPDATE matgraph_multi SET alerte_multi = alerte_multi + 1, lien_multi = lien_multi + 2  WHERE id='$row[id]'";
			$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
	  		}
		exit;
		}

		//second ordre
		$req = "SELECT id FROM matgraph_multi WHERE joueur1='$id_espionner2' AND joueur2='$idlogin' limit 1";
		$res = 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) ) {
			$requete = "UPDATE matgraph_multieSET alerte_multi = alerte_multi + 1, lien_multi = lien_multi + 2  WHERE id='$row[id]'";
  			$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
  			}
		exit;
		}

		//créer
		$requete = "INSERT INTO matgraph_multi VALUES ('', '$idlogin', '$row[idlogin]', '0', '0', '0', '0', '1', '0', '0', '0', now(), '2')";
		$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
		$requete = "INSERT INTO matgraph_multiencours VALUES ('', '".mysql_insert_id()."')";
		$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
//}
		exit;
	}
}
/////////////////////
/////////////
////////
///
//


$sql = "SELECT login,planete,id,idjoueur FROM `matgraph_users` WHERE `galaxi` = '$galaxi' AND `system` = '$system' AND `position` = '$position'";
$res = mysql_query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res);
$id_espionner = $row[id] ;
$id_espionner2 = $row[idjoueur] ;
$planete = $row[id] ;
$dataid['id'] = $row[idjoueur] ;
$idlogin = $dataid['id'] ;
//include ('ressource2.php');
//include ('calcullabo.php');

include ('entete2.php');
//include ('ressource2.php');

//$sql = "SELECT fer_ressource,or_ressource,ada_ressource,ura_ressource FROM matgraph_users WHERE id=$planete";
//$res = mysql_query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
//$row = mysql_fetch_array($res);

//////////////////////////////////////////////////////////////////////////////////
$sql2 = "SELECT idjoueur FROM matgraph_users WHERE id='$planete'";
$res2 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2);
$idenvoyeur = $row2[idjoueur];
$sql2 = "SELECT idjoueur,pts FROM matgraph_users WHERE id='$idenvoyeur'";
$res2 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2);
$id_envoyeur = $row2[idjoueur];
$pts_envoyeur = $row2[pts];
//////////////////////////////////////////////////////////////////////////////////

$requete = "UPDATE matgraph_users SET fer_ressource=fer_ressource - $fer, or_ressource=or_ressource - $or, ada_ressource=ada_ressource - $ada, ura_ressource=ura_ressource - $ura WHERE id='$planete'";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

//$sql = "SELECT idjoueur,pts,fer_ressource,or_ressource,ada_ressource,ura_ressource FROM matgraph_users WHERE id='$id_espionner'";
//$res = mysql_query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
//$row = mysql_fetch_array($res); 

//////////////////////////////////////////////////////////////////////////////////
$sql2 = "SELECT idjoueur,pts FROM matgraph_users WHERE id='$id_espionner2'";
$res2 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2);
$pts_destinataire = $row2[pts];
$id_destinataire = $row2[idjoueur];
//////////////////////////////////////////////////////////////////////////////////

$requete = "UPDATE matgraph_users SET fer_ressource=fer_ressource + $fer, or_ressource=or_ressource + $or, ada_ressource=ada_ressource + $ada, ura_ressource=ura_ressource + $ura WHERE id='$id_espionner'";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

$sql = "SELECT login,planete,idjoueur FROM matgraph_users WHERE id='$id_espionner'";
$res = mysql_query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 

$sql4 = "SELECT login,planete,galaxi,system,position FROM matgraph_users WHERE id=$planete";
$res4 = mysql_query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
$row4 = mysql_fetch_array($res4); 

$fer2 = number_format($fer , 0, ',', ' ');
$or2 = number_format($or , 0, ',', ' ');
$ada2 = number_format($ada , 0, ',', ' ');
$ura2 = number_format($ura , 0, ',', ' ');

//////////////////////////////////////////////////////////////////////////////////
$cristal = $ada;
$naquadah = $ura;
if ( $id_envoyeur != $id_destinataire ) {
	include('sgu_systeme_push.php');
	Pushing_Systeme($id_envoyeur,$pts_envoyeur,$id_destinataire,$pts_destinataire,$fer,$or,$cristal,$naquadah,0,0,0,0,0);
}
//////////////////////////////////////////////////////////////////////////////////

$New_eppz = (($eppzff - $New_Besoin_energie) / 60000);
$requete = "UPDATE matgraph_users SET eppz='".$New_eppz."' WHERE id='$planete'";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());


$sujet= "<font color=\"00CC00\">Arrivée de ressources de la part de $row4[login] [$row4[galaxi]:$row4[system]:$row4[position]]</font>";
$topic = "Salle de contrôle :<br>Des ressources sont arriver de la part de $row4[login] de la planete $row4[planete] [$row4[galaxi]:$row4[system]:$row4[position]] pour votre planete $row[planete] [$galaxi:$system:$position]
<br>Ressources :
<br>Fer : $fer2
<br>Or : $or2
<br>Cristal : $ada2
<br>Naquadah : $ura2";
$msg = addslashes($topic);
$requete = "INSERT INTO  matgraph_msg VALUES ('', now(), 'non', '$row[idjoueur]', '".addslashes($sujet)."', '".addslashes($topic)."')";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

/////////////
$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 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2); 

echo"Les ressources sont bien arrivées sur la planète [$galaxi:$system:$position].<br><br>";
echo "Rappel des ressources :
<br>Fer : $fer2
<br>Or : $or2
<br>Cristal : $ada2
<br>Naquadah : $ura2";

/*if($idlogin != 1)
{
	exit;
}*/

//$id_espionner2
//$idlogin

if($idlogin = $id_espionner2)
{
	exit;
}

//premier ordre
$req = "SELECT id FROM matgraph_multi WHERE joueur2='$id_espionner2' AND joueur1='$idlogin' limit 1";
$res = 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) ) {
  	$ressources_echanges = ($fer + 2*$or + 3*$ada + 4*$ura)/1000;
  	$requete = "UPDATE matgraph_multi SET ressources1 = ressources1 + '$ressources_echanges' , envoi1 = envoi1 + 1  WHERE id='$row[id]'";
		$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
  }
exit;
}

//second ordre
$req = "SELECT id FROM matgraph_multi WHERE joueur1='$id_espionner2' AND joueur2='$idlogin' limit 1";
$res = 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) ) {
  	$ressources_echanges = ($fer + 2*$or + 3*$ada + 4*$ura)/1000;
  	$requete = "UPDATE matgraph_multi SET ressources2 = ressources2 + '$ressources_echanges' , envoi2 = envoi2 + 1  WHERE id='$row[id]'";
  	$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
  }
exit;
}

//créer
$ressources_echanges = ($fer + 2*$or + 3*$ada + 4*$ura)/1000;
$requete = "INSERT INTO matgraph_multi VALUES ('', '$idlogin', '$id_espionner2', '$ressources_echanges', '0', '1', '0', '0', '0', '0', '0', now(), '0')";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
$requete = "INSERT INTO matgraph_multiencours VALUES ('', '".mysql_insert_id()."')";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

	

?>
