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

$galaxi = htmlentities ($_POST["galaxi"]);
$system = htmlentities ($_POST["system"]);
$position = htmlentities ($_POST["position"]);


$sql = "SELECT 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];

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

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

$form = "<div align=\"center\"><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=\"espio1_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 à espionner</div></td>
    </tr>
    <tr style =\"background-color:#111111;\">
      <td width=\"203\"><div align=\"center\">Galaxie</div></td>
      <td width=\"203\"><div align=\"center\">Systeme Solaire </div></td>
      <td width=\"204\"><div align=\"center\">Position </div></td>
    </tr>
    <tr>
      <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 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>
<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;}

$sql = "SELECT malp FROM matgraph_users WHERE id='$planete'";
$res = mysql_query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res);
if ($row[malp] < 1) {
 
echo"<br><br>Vous devez disposez d'un M.A.L.P pour remplir cette mission."; 
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\">$New_Besoin_energie2 d'energie sont necessaire pour aller à ces coordonnées. Vous devez vous procurer des eppz.";
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;
}
$req = "SELECT pts,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;}

if($idlogin != 1){
include('limite_pts.php');
if($New_pts < $limite_pts || $row[pts] < $limite_pts)
{
	if($New_pts > $row[pts]*3.0001)
	{
		echo"<br><br>Message de la salle de contrôle :
		<br><br>La planète selectionnée appartient à un joueur faible.";
		echo"$form";
		exit;
	}
	
	
	if($New_pts < $row[pts]/3.0001)
	{
	echo"<br><br>Message de la salle de contrôle :
	<br><br>La planète selectionnée appartient à un joueur fort.";
	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 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 ) {

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

/////////////////////
/////////////
////////
///
//




$sql = "SELECT 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 ('chantiercalcul.php');
include ('centredefcalcul.php');
include ('centrespecalcul.php');

include ('entete2.php');
include ('ressourceapercu.php');

$sqlinfo = "SELECT * FROM matgraph_users WHERE id=$id_espionner";
$resinfo = mysql_query($sqlinfo)or die('erreur sql<br>'.$sqlinfo.'<br>'.mysql_error());
$rowinfo = mysql_fetch_array($resinfo); 

$fer = number_format(floor($rowinfo[fer_ressource]), 0, ',', ' ');
$or = number_format(floor($rowinfo[or_ressource]), 0, ',', ' ');
$ada = number_format(floor($rowinfo[ada_ressource]), 0, ',', ' ');
$ura = number_format(floor($rowinfo[ura_ressource]), 0, ',', ' ');
$ressource = "<table width=\"618\"  border=\"1\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td>Ressource en Fer </td>
    <td>Ressource en Or </td>
    <td>Ressource en Cristal </td>
    <td>Ressource en Naquadah </td>
  </tr>
  <tr>
    <td>$fer</td>
    <td>$or</td>
    <td>$ada</td>
    <td>$ura</td>
  </tr>";
  
if($rowinfo[fer_lvl] > 0) {
$fer = "<br>Mine de fer ($rowinfo[fer_lvl])"; }
if($rowinfo[exfer_lvl] > 0) {
$exfer = "<br>Centre d'extraction de fer ($rowinfo[exfer_lvl])"; }
if($rowinfo[or_lvl] > 0) {
$or = "<br>Mine d'or ($rowinfo[or_lvl])"; }
if($rowinfo[exor_lvl] > 0) {
$exor = "<br>Centre d'extraction d'or ($rowinfo[exor_lvl])"; }
if($rowinfo[ada_lvl] > 0) {
$ada = "<br>Mine de Cristal ($rowinfo[ada_lvl])"; }
if($rowinfo[ura_lvl] > 0) {
$ura = "<br>Mine de Naquadah ($rowinfo[ura_lvl])"; }
if($rowinfo[central_lvl] > 0) {
$central = "<br>Centrale d'énergie thermique ($rowinfo[central_lvl])"; }
if($rowinfo[fission_lvl] > 0) {
$fission = "<br>Centrale énergétique au Naquadah ($rowinfo[fission_lvl])"; }
if($rowinfo[robo_lvl] > 0) {
$robo = "<br>Usine Robotique ($rowinfo[robo_lvl])"; }
if($rowinfo[mili_lvl] > 0) {
$mili = "<br>Caserne Militaire ($rowinfo[mili_lvl])"; }
if($rowinfo[chantier_lvl] > 0) {
$chantier = "<br>Chantier spatial ($rowinfo[chantier_lvl])"; }
if($rowinfo[defense_lvl] > 0) {
$defense = "<br>Centre Militaire de Defense Interplanétaire ($rowinfo[defense_lvl])"; }
if($rowinfo[labo_lvl] > 0) {
$labo = "<br>Centre de recherches scientifiques ($rowinfo[labo_lvl])"; }
if($rowinfo[terri_lvl] > 0) {
$terri = "<br>Aménagement du territoire ($rowinfo[terri_lvl])"; }
if($rowinfo[silo_lvl] > 0) {
$silo = "<br>Tour de Babel ($rowinfo[silo_lvl])"; }

$batimentsdebut = "<tr>
    <td colspan=\"4\">&nbsp;</td>
  </tr>
  <tr>
    <td colspan=\"4\"><b><u>Bâtiments :<br></b></u>";

$batimentsfin = "</td>
  </tr>";
$batiments ="";
if (!empty($batimentsdebut) )
  $batiments.="$batimentsdebut";
if (!empty($fer) )
  $batiments.="$fer";
if (!empty($exfer) )
  $batiments.="$exfer";
if (!empty($or) )
  $batiments.="$or";
if (!empty($exor) )
  $batiments.="$exor";
if (!empty($ada) )
  $batiments.="$ada";
if (!empty($ura) )
  $batiments.="$ura";
if (!empty($central) )
  $batiments.="$central";
if (!empty($fission) )
  $batiments.="$fission";
if (!empty($robo) )
  $batiments.="$robo";
if (!empty($mili) )
  $batiments.="$mili";
if (!empty($chantier) )
  $batiments.="$chantier";
if (!empty($defense) )
  $batiments.="$defense";
if (!empty($labo) )
  $batiments.="$labo";
if (!empty($terri) )
  $batiments.="$terri";
if (!empty($silo) )
  $batiments.="$silo";
if (!empty($batimentsfin) )
  $batiments.="$batimentsfin";
$flotte ="";  
$flottedebut = "<tr>
    <td colspan=\"4\">&nbsp;</td>
  </tr>
  <tr>
    <td colspan=\"4\"><b><u>Flotte :</b></u>";
$flotte.= "$flottedebut";
$req = "SELECT * FROM matgraph_vaisseaux WHERE iduser = '$id_espionner2' ORDER by id ASC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
  $i=1;
  While ( $row = mysql_fetch_array($res) ) {
$sql2 = "SELECT nbre FROM matgraph_nbrevaisseaux WHERE vaisseau='$row[id]' AND planete='$id_espionner'";
$res2 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2); 
	if($row[chantier_lvl] == 1){$infra="Infrastructure du X-301";}
      if($row[chantier_lvl] == 2){$infra="Infrastructure du Cargo Teltak";}
      if($row[chantier_lvl] == 4){$infra="Infrastructure de la Navette Bedrosienne";}
      if($row[chantier_lvl] == 5){$infra="Infrastructure du Prométhé";}
      if($row[chantier_lvl] == 7){$infra="Infrastructure du Vaisseau Amiral Goa'ulds";}
      if($row[chantier_lvl] == 10){$infra="Infrastructure du Vaisseau mére Asgaard";}
if($row2[nbre] > 0){
$i = "<br><br><b>$row[nom] ( $row2[nbre] )</b>
<br>Type d'infrastructure : $infra
<br>Puissance de feux : $row[arme]
<br>Boucliers : $row[bouclier]
<br>Coque : $row[coque]
<br>Vitesse : $row[vitesse]
<br>Fret : $row[place]"; 
$flotte.= "$i";}
$i++;}
}
$req = "SELECT * FROM matgraph_nbrevaisseaux WHERE planete = '$id_espionner' AND nbre != '0' ORDER by id ASC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num == 0 ) {
$flottevide = " il n'y a pas de flotte à quai sur la planète espionnée.";
$flotte.= "$flottevide"; }

$flottefin = "</td>
  </tr>";
$flotte.= "$flottefin";


$defense ="";  
$defensedebut = "<tr>
    <td colspan=\"4\">&nbsp;</td>
  </tr>
  <tr>
    <td colspan=\"4\"><b><u>Défense :<br></b></u>";
$defense.= "$defensedebut";

if($rowinfo[defcombat] > 0) {
$combat = "<br>Tourelles de Combat ($rowinfo[defcombat])"; }
if($rowinfo[deflasersimple] > 0) {
$lasersimple = "<br>Tourelles laser simple ($rowinfo[deflasersimple])"; }
if($rowinfo[deflaserdouble] > 0) {
$laserdouble = "<br>Tourelle laser à double rayon ($rowinfo[deflaserdouble])"; }
if($rowinfo[defelec] > 0) {
$elec = "<br>Tour électromagnétique ($rowinfo[defelec])"; }
if($rowinfo[defions] > 0) {
$ions = "<br>Mini Satellite à ions ($rowinfo[defions])"; }
if($rowinfo[defplasma] > 0) {
$plasma = "<br>Tour à plasma ($rowinfo[defplasma])"; }
if($rowinfo[defnaqua] > 0) {
$naqua = "<br>Tourelle de Naquadah ($rowinfo[defnaqua])"; }
if($rowinfo[defanciens] > 0) {
$anciens = "<br>Satellite des Anciens ($rowinfo[defanciens])"; }

if (!empty($combat) )
  $defense.="$combat";
if (!empty($lasersimple) )
  $defense.="$lasersimple";
if (!empty($laserdouble) )
  $defense.="$laserdouble";
if (!empty($elec) )
  $defense.="$elec";
if (!empty($ions) )
  $defense.="$ions";
if (!empty($plasma) )
  $defense.="$plasma";
if (!empty($naqua) )
  $defense.="$naqua";
if (!empty($anciens) )
  $defense.="$anciens";

if((empty($combat) ) AND (empty($lasersimple) ) AND (empty($laserdouble) ) AND (empty($elec) ) AND (empty($ions) ) AND (empty($plasma) ) AND (empty($naqua) ) AND (empty($anciens) )) { 
$defensevide = " Aucune defense présente sur cette planète.";
$defense.= "$defensevide"; }

$defensefin = "</td>
  </tr>";
$defense.= "$defensefin";

$technologies ="";  
$technologiesdebut = "<tr>
    <td colspan=\"4\">&nbsp;</td>
  </tr>
  <tr>
    <td colspan=\"4\"><b><u>Technologies :<br></b></u>";
$technologies.= "$technologiesdebut";

if($rowinfo[techinfra_lvl] > 0) {
$techinfra_lvl = "<br>Technologie d'infrastructure des Vaisseaux ($rowinfo[techinfra_lvl])"; }
if (!empty($techinfra_lvl) )
  $technologies.="$techinfra_lvl";
  
if($rowinfo[techenergie_lvl] > 0) {
$techenergie_lvl = "<br>Technologie de maîtrise de l'Energie ($rowinfo[techenergie_lvl])"; }
if (!empty($techenergie_lvl) )
  $technologies.="$techenergie_lvl";

if($rowinfo[techlaser_lvl] > 0) {
$techlaser_lvl = "<br>Technologie de Laser ($rowinfo[techlaser_lvl])"; }
if (!empty($techlaser_lvl) )
  $technologies.="$techlaser_lvl";
  
if($rowinfo[techions_lvl] > 0) {
$techions_lvl = "<br>Technologie d'ions ($rowinfo[techions_lvl])"; }
if (!empty($techions_lvl) )
  $technologies.="$techions_lvl";

if($rowinfo[techplasma_lvl] > 0) {
$techplasma_lvl = "<br>Technologie de plasma ($rowinfo[techplasma_lvl])"; }
if (!empty($techplasma_lvl) )
  $technologies.="$techplasma_lvl";
  
if($rowinfo[techordi_lvl] > 0) {
$techordi_lvl = "<br>Technologie Salle de contrôle ($rowinfo[techordi_lvl])"; }
if (!empty($techordi_lvl) )
  $technologies.="$techordi_lvl";
  
if($rowinfo[techcombustion_lvl] > 0) {
$techcombustion_lvl = "<br>Réacteur à combustion ($rowinfo[techcombustion_lvl])"; }
if (!empty($techcombustion_lvl) )
  $technologies.="$techcombustion_lvl";
  
if($rowinfo[techAsgaards_lvl] > 0) {
$techAsgaards_lvl = "<br>Réacteurs Asgards ($rowinfo[techAsgaards_lvl])"; }
if (!empty($techAsgaards_lvl) )
  $technologies.="$techAsgaards_lvl";
  
if($rowinfo[techhyperespace_lvl] > 0) {
$techhyperespace_lvl = "<br>Technologie des Réacteur hyperespace ($rowinfo[techhyperespace_lvl])"; }
if (!empty($techhyperespace_lvl) )
  $technologies.="$techhyperespace_lvl";
  
if($rowinfo[techespio1_lvl] > 0) {
$techespio1_lvl = "<br>Technologie Espionnage de Type 1 ($rowinfo[techespio1_lvl])"; }
if (!empty($techespio1_lvl) )
  $technologies.="$techespio1_lvl";
  
if($rowinfo[techespio2_lvl] > 0) {
$techespio2_lvl = "<br>Technologie Espionnage de Type 2 ($rowinfo[techespio2_lvl])"; }
if (!empty($techespio2_lvl) )
  $technologies.="$techespio2_lvl";
  
if($rowinfo[techArmement_lvl] > 0) {
$techArmement_lvl = "<br>Technologie de l'Armement ($rowinfo[techArmement_lvl])"; }
if (!empty($techArmement_lvl) )
  $technologies.="$techArmement_lvl";
  
if($rowinfo[techBouclier_lvl] > 0) {
$techBouclier_lvl = "<br>Technologie Bouclier de protection ($rowinfo[techBouclier_lvl])"; }
if (!empty($techBouclier_lvl) )
  $technologies.="$techBouclier_lvl";
  
if($rowinfo[techcoque_lvl] > 0) {
$techcoque_lvl = "<br>Technologie de renforcement de la coque ($rowinfo[techcoque_lvl])"; }
if (!empty($techcoque_lvl) )
  $technologies.="$techcoque_lvl";
  
if($rowinfo[techproAsgaard_lvl] > 0) {
$techproAsgaard_lvl = "<br>Technologie Asgard ($rowinfo[techproAsgaard_lvl])"; }
if (!empty($techproAsgaard_lvl) )
  $technologies.="$techproAsgaard_lvl";
  
if($rowinfo[techproAncien_lvl] > 0) {
$techproAncien_lvl = "<br>Technologie \"Les Anciens\" ($rowinfo[techproAncien_lvl])"; }
if (!empty($techproAncien_lvl) )
  $technologies.="$techproAncien_lvl";
  
if($rowinfo[technaqua_lvl] > 0) {
$technaqua_lvl = "<br>Technologie de Naquadah ($rowinfo[technaqua_lvl])"; }
if (!empty($technaqua_lvl) )
  $technologies.="$technaqua_lvl";
 
if($rowinfo[techanti_lvl] > 0) {
$techanti_lvl = "<br>Technologie Champs Anti-gravité ($rowinfo[techanti_lvl])"; }
if (!empty($techanti_lvl) )
  $technologies.="$techanti_lvl";
  

if((empty($techinfra_lvl) ) AND (empty($techenergie_lvl) ) AND (empty($techlaser_lvl) ) AND (empty($techions_lvl) ) AND (empty($techplasma_lvl) ) AND (empty($techordi_lvl) ) AND (empty($techcombustion_lvl) ) AND (empty($techAsgaards_lvl) ) AND (empty($techhyperespace_lvl) ) AND (empty($techespio1_lvl) ) AND (empty($techespio2_lvl) ) AND (empty($techArmement_lvl) ) AND (empty($techBouclier_lvl) ) AND (empty($techcoque_lvl) ) AND (empty($techproAsgaard_lvl) ) AND (empty($techproAncien_lvl) ) AND (empty($technaqua_lvl) ) AND (empty($techanti_lvl) )) { 
$technologiesvide = " Aucune technologie présente sur cette planète.";
$technologies.= "$technologiesvide"; }

$technologiesfin = "</td>
  </tr>";
$technologies.= "$technologiesfin";

$militaires = "<tr>
    <td colspan=\"4\">&nbsp;</td>
  </tr>
  <tr>
    <td colspan=\"4\"><b><u>Militaires :<br></b></u>
	". number_format(floor($rowinfo[mili_nbre]), 0, ',', ' ') ."
	</td>
  </tr>";

$sql3 = "SELECT techespio1_lvl FROM matgraph_users WHERE id=$idlogin";
$res3 = mysql_query($sql3)or die('erreur sql<br>'.$sql3.'<br>'.mysql_error());
$row3 = mysql_fetch_array($res3);   

$sql99 = "SELECT techespio1_lvl FROM matgraph_users WHERE id=$id_espionner2";
$res99 = mysql_query($sql99)or die('erreur sql<br>'.$sql99.'<br>'.mysql_error());
$row99 = mysql_fetch_array($res99);  


$y = rand(1,100);	
if($y < 11) {
$x = 1; }
else {
$x= 0; }

$Dif_espio2 = $row3[techespio1_lvl] - $row99[techespio1_lvl] + $x;


$sujet = "$rowinfo[planete] ($rowinfo[login]) [$galaxi:$system:$position]" ;
if ($Dif_espio2 > 3) {
$msg = "";
if (!empty($ressource) )
$msg.="$ressource";
$msg.="$flotte";
$msg.="$defense";
$msg.="$batiments";
$msg.="$militaires";
$msg.="$technologies";
$msg.="</table>";
$msg2 = addslashes($msg);
$requete = "INSERT INTO  matgraph_espio1 VALUES ('', 'OUI', now(), '$idlogin', '$planete', '".addslashes($sujet)."', '".addslashes($msg2)."')";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }

if ($Dif_espio2 == 3) {
$msg = "";
if (!empty($ressource) )
$msg.="$ressource";
$msg.="$flotte";
$msg.="$defense";
$msg.="$batiments";
$msg.="$militaires";
$msg.="</table>";
$msg2 = addslashes($msg);
$requete = "INSERT INTO  matgraph_espio1 VALUES ('', 'OUI', now(), '$idlogin', '$planete', '".addslashes($sujet)."', '".addslashes($msg2)."')";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }

if ($Dif_espio2 == 2) {
$msg = "";
if (!empty($ressource) )
$msg.="$ressource";
$msg.="$flotte";
$msg.="$defense";
$msg.="</table>";
$msg2 = addslashes($msg);
$requete = "INSERT INTO  matgraph_espio1 VALUES ('', 'oui', now(), '$idlogin', '$planete', '".addslashes($sujet)."', '".addslashes($msg2)."')";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }

if ($Dif_espio2 == 1) {
$msg = "";
if (!empty($ressource) )
$msg.="$ressource";
$msg.="$flotte";
$msg.="</table>";
$msg2 = addslashes($msg);
$requete = "INSERT INTO  matgraph_espio1 VALUES ('', 'oui', now(), '$idlogin', '$planete', '".addslashes($sujet)."', '".addslashes($msg2)."')";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }

if ($Dif_espio2 == 0) {
$msg = "";
if (!empty($ressource) )
$msg.="$ressource";
$msg.="</table>";
$msg2 = addslashes($msg);
$requete = "INSERT INTO  matgraph_espio1 VALUES ('', 'oui', now(), '$idlogin', '$planete', '".addslashes($sujet)."', '".addslashes($msg2)."')";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }

if ($Dif_espio2 < 0 AND $Dif_espio2 >= "-2") {
$msg = "";
if (!empty($ressource) )
$msg.="$ressource";
$msg.="</table>";
$msg2 = addslashes($msg);
$requete = "INSERT INTO  matgraph_espio1 VALUES ('', 'oui', now(), '$idlogin', '$planete', '".addslashes($sujet)."', '".addslashes($msg2)."')";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }

if ($Dif_espio2 < "-2") {
$msg = "";
if (!empty($ressource) )
$msg.="Votre niveau d'espionnage est trop faible.";
$msg.="</table>";
$msg2 = addslashes($msg);
$requete = "INSERT INTO  matgraph_espio1 VALUES ('', 'oui', now(), '$idlogin', '$planete', '".addslashes($sujet)."', '".addslashes($msg2)."')";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }

$sql4 = "SELECT malp FROM matgraph_users WHERE id='$planete'";
$res4 = mysql_query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
$row4 = mysql_fetch_array($res4);   
$malp = $row4[malp] - 1 ;
$requete = "UPDATE matgraph_users SET malp=$malp WHERE id='$planete'";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

$sql4 = "SELECT 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);  

$title = "<font color=\"FF0000\">ACTIVATION NON PROGRAMMEE DE LA PORTE DES ETOILES</font><br>";
$topic = "Salle de contrôle :<br><br>
Un M.A.L.P a traversé la porte des étoiles et a été détruit. Cependant il est possible qu’il ait transmis des informations à sa planète d’origine en [$row4[galaxi]:$row4[system]:$row4[position]] a propos de votre planete $rowinfo[planete] [$rowinfo[galaxi]:$rowinfo[system]:$rowinfo[position]]";

$requete = "INSERT INTO  matgraph_contreespio VALUES ('',now(), 'non', '$id_espionner2', '$id_espionner', '".addslashes($title)."', '".addslashes($topic)."')";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

$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());

echo"Rapport du M.AL.P sur la planète [$galaxi:$system:$position]<br><br>";
echo "$msg";


exit;

?>