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

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=\"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'); 

$req3 = "SELECT id,idjoueur,idespionner,planeteespionner FROM matgraph_espio2 WHERE idjoueur = $idlogin AND jour=1 ORDER BY id ASC";
$res3 = db_mysql_Query($req3) or die('Erreur SQL! <br>'.$req3.'<br>'.mysql_error());
$num3 = mysql_num_rows($res3);
if ( $num3 > 0 ) {
  While ( $row3 = mysql_fetch_array($res3) ) {

echo"<br><br>-----------------------------------------------------------------------------------------------------------------------------";
$idlogin4 = $idlogin;
$planete = $row3[planeteespionner];
$idlogin = $row3[idespionner];
$dataid['id'] = $idlogin ;
$sql4 = "SELECT login,planete,galaxi,system,position FROM matgraph_users WHERE id='$row3[idespionner]' ";
$res4 = db_mysql_Query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
$row4 = mysql_fetch_array($res4); 

$chancereperer = 0;
$req5 = "SELECT chancereperer FROM matgraph_espio2 WHERE idespionner = $idlogin AND idjoueur = $row3[idjoueur] ORDER BY id ASC";
$res5 = db_mysql_Query($req5) or die('Erreur SQL! <br>'.$req5.'<br>'.mysql_error());
$num5 = mysql_num_rows($res5);
if ( $num5 > 0 ) {
  While ( $row5 = mysql_fetch_array($res5) ) {
$chancereperer+= $row5[chancereperer] ;  
}}
//
$techrare = 0;
$req = "SELECT id,techrare FROM matgraph_espio2 WHERE idespionner = $idlogin AND idjoueur = $row3[idjoueur] ORDER BY id ASC";
$res = db_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) ) {
$techrare+= $row[techrare] ;  
}}

$techrare2 = $techrare + rand(0,20);
if($techrare2 >= 100) {
$techrare = "Technologie rare décourte : Pas fini dsl...";
//tech rare detecter
$sql = "UPDATE matgraph_users techrare = '100' SET WHERE id='$row[id]' ";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
}
else {
$techrare = "Chan de découvrir la technologie rare : $techrare %";
}
echo"<div align=\"center\">Pseudo : $row4[login], Planète : $row4[planete] [$row4[galaxi]:$row4[system]:$row4[position]] , Chance d'etre découvert :  $chancereperer %";
echo"<br><br><table width=\"618\"  border=\"1\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td>Jour (n&deg;)</td>
    <td>Nombre de connections </td>
    <td>Vaisseaux Construits </td>
    <td>Defenses construites </td>
    <td>Machines specialis&eacute;s construites</td>
    <td>Batiments &eacute;volu&eacute;s</td>
    <td>Technologies &eacute;volu&eacute;es</td>
  </tr>";

$req = "SELECT * FROM matgraph_espio2 WHERE idespionner = $idlogin AND idjoueur = $idlogin4 ORDER BY jour ASC";
$res = db_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) ) {

echo"<tr>
    <td>$row[jour]</td>
    <td>$row[nbreconnect]</td>
    <td>$row[nbrevaisseaux]</td>
    <td>$row[nbredef]</td>
    <td>$row[nbrespe]</td>
    <td>$row[nbrebat]</td>
    <td>$row[nbretech]</td>
  </tr>";
}}
echo"</table>";
echo"<br><table width=\"618\"  border=\"1\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td>Rapport d'espionnage</td>
    <td>Rapport de contre-espionnage </td>
    <td>Message de joueur</td>
	<td>Message de l'alliance</td>
    <td>Autre message </td>
  </tr>";
  
$req = "SELECT * FROM matgraph_espio2 WHERE idespionner = $idlogin AND idjoueur = $idlogin4 ORDER BY jour ASC";
$res = db_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) ) {
  
echo"<tr>
    <td>$row[rapportespio]</td>
    <td>$row[contreespio]</td>
    <td>$row[mp]</td>
	<td>$row[msgally]</td>
    <td>$row[autremsg]</td>
  </tr>";
}}
echo"</table>";

$req = "SELECT * FROM matgraph_espio2 WHERE idespionner = $idlogin AND idjoueur = $row3[idjoueur]";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$row = mysql_fetch_array($res);

$id_espionner = $planete ;
$id_espionner2 = $idlogin ;
include ('ressource.php');
include ('calcullabo.php');
include ('chantiercalcul.php');
include ('centredefcalcul.php');
include ('centrespecalcul.php');

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

$sqlinfo = "SELECT * FROM matgraph_users WHERE id=$id_espionner";
$resinfo = db_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 = "<br><br><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 = db_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 = db_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 = db_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";


$sql33 = "SELECT techespio1_lvl FROM matgraph_users WHERE id=$idlogin";
$res33 = db_mysql_Query($sql33)or die('erreur sql<br>'.$sql33.'<br>'.mysql_error());
$row33 = mysql_fetch_array($res33);   

$sql99 = "SELECT techespio1_lvl FROM matgraph_users WHERE id=$id_espionner2";
$res99 = db_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 = $row33[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.="$technologies";
$msg.="</table>";
$msg2 = addslashes($msg);}

if ($Dif_espio2 == 3) {
$msg = "";
if (!empty($ressource) )
$msg.="$ressource";
$msg.="$flotte";
$msg.="$defense";
$msg.="$batiments";
$msg.="</table>";
$msg2 = addslashes($msg);}

if ($Dif_espio2 == 2) {
$msg = "";
if (!empty($ressource) )
$msg.="$ressource";
$msg.="$flotte";
$msg.="$defense";
$msg.="</table>";
$msg2 = addslashes($msg);}

if ($Dif_espio2 == 1) {
$msg = "";
if (!empty($ressource) )
$msg.="$ressource";
$msg.="$flotte";
$msg.="</table>";
$msg2 = addslashes($msg);}

if ($Dif_espio2 == 0) {
$msg = "";
if (!empty($ressource) )
$msg.="$ressource";
$msg.="</table>";
$msg2 = addslashes($msg);}

if ($Dif_espio2 < 0 AND $Dif_espio2 >= "-2") {
$msg = "";
if (!empty($ressource) )
$msg.="$ressource";
$msg.="</table>";
$msg2 = addslashes($msg);}

if ($Dif_espio2 < "-2") {
$msg = "";
if (!empty($ressource) )
$msg.="Votre niveau d'espionnage est trop faible.";
$msg.="</table>";
$msg2 = addslashes($msg);}

echo "$msg";

}}
?>