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


$sql2 = "SELECT hangarfer_lvl,hangarfer_evolution,hangaror_lvl,hangaror_evolution,hangarada_lvl,hangarada_evolution,hangaror_lvl,hangarura_lvl,hangarura_evolution FROM matgraph_users WHERE id='$planete' ";
$res2 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2);

// La variable de condition
$liste_id = "(0";

$reqtmpid = "SELECT id FROM matgraph_users WHERE idjoueur = $idlogin";
$restmpid = mysql_query($reqtmpid) or die('Erreur SQL! <br>'.$reqtmpid.'<br>'.mysql_error());
while( $rowtmpid = mysql_fetch_array($restmpid) ) {
	$liste_id = $liste_id." OR receveur = $rowtmpid[id]";
}
$liste_id = $liste_id.")";

//mp
$req = "SELECT id FROM matgraph_mp WHERE $liste_id ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_mp = $num ;
$req = "SELECT id FROM matgraph_mp WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_mplu = $num ;

//espio
$req = "SELECT id FROM matgraph_espio1 WHERE $liste_id ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_espio1 = $num ;
$req = "SELECT id FROM matgraph_espio1 WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_espio1lu = $num ;

//contreespio
$req = "SELECT id FROM matgraph_contreespio WHERE $liste_id ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_contreespio = $num ;
$req = "SELECT id FROM matgraph_contreespio WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_contreespiolu = $num ;

//msg
$req = "SELECT id FROM matgraph_msg WHERE $liste_id ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_msg = $num ;
$req = "SELECT id FROM matgraph_msg WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_msglu = $num ;

//msgally
$req = "SELECT id FROM matgraph_msgally WHERE $liste_id ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_msgally = $num ;
$req = "SELECT id FROM matgraph_msgally WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_msgallylu = $num ;
/*
//total_mp_admin
$req = "SELECT id FROM matgraph_mp ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_mp_admin = $num;
*/
//msgcombat
$req = "SELECT id FROM matgraph_bataille WHERE $liste_id ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_msgcombat = $num ;

$req = "SELECT id FROM matgraph_bataille WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_msgcombatlu = $num ;


echo"<style>
input {
border:0px 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"<a href='mp_envoi_friend.php'>Envoyer un MP à un ami ou des amis</a><br><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><div align=\"center\"><strong>Genre</strong></div></td>
    <td><div align=\"center\"><strong>Non lu / Total </strong></div></td>
  </tr>
  <tr>
    <td><div align=\"center\"><a href=\"mp_lire_mp.php\" target=\"_parent\">Messages de joueurs</a> </div></td>
    <td><div align=\"center\">$total_mplu / $total_mp</div></td>
  </tr>
  <tr style =\"background-color:#222222;\">
    <td><div align=\"center\"><a href=\"mp_lire_msgally.php\" target=\"_parent\">Message de l'alliance </a></div></td>
    <td><div align=\"center\">$total_msgallylu / $total_msgally</div></td>
  </tr>
  <tr>
    <td><div align=\"center\"><a href=\"mp_lire_combat.php\" target=\"_parent\">Rapports de bataille </a></div></td>
    <td colspan=\"2\"><div align=\"center\">$total_msgcombatlu / $total_msgcombat</div></td>
  </tr>
  <tr style =\"background-color:#222222;\">
    <td><div align=\"center\"><a href=\"mp_lire_espio.php\" target=\"_parent\">Rapports d'espionnages </a></div></td>
    <td colspan=\"2\"><div align=\"center\">$total_espio1lu / $total_espio1</div></td>
  </tr>
  <tr>
    <td><div align=\"center\"><a href=\"mp_lire_contreespio.php\" target=\"_parent\">Rapports de contre-espionnage </a></div></td>
    <td><div align=\"center\">$total_contreespiolu / $total_contreespio</div></td>
  </tr>
  <tr style =\"background-color:#222222;\">
    <td><div align=\"center\"><a href=\"mp_lire_msg.php\" target=\"_parent\">Autres messages </a></div></td>
    <td><div align=\"center\">$total_msglu / $total_msg</div></td>
  </tr>";
if($idlogin == "1" OR $idlogin == "176") {
/*
echo"<tr>
    <td><div align=\"center\"><a href=\"mp_lire_mp_admin.php\" target=\"_parent\">Control Admin MP</a></div></td>
    <td><div align=\"center\">$total_mp_admin</div></td>
  </tr>"; */
echo"<tr>
    <td><div align=\"center\"><a href=\"whoisonline.php\" target=\"_parent\">Who is online</a></div></td>
    <td><div align=\"center\">.</div></td>
  </tr>"; }
 echo"<tr>
    <td colspan=\"2\">";


$req = "SELECT * FROM matgraph_mp WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
echo"<div align=\"center\"> Nouveaux messages de joueurs : </div><br>";
While ( $row = mysql_fetch_array($res) ) {
$sql2 = "SELECT login FROM matgraph_users WHERE id='$row[envoyeur]' ";
$res2 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2);
$sql3 = "SELECT planete,galaxi,system,position FROM matgraph_users WHERE id='$row[planete_envoyeur]' ";
$res3 = mysql_query($sql3)or die('erreur sql<br>'.$sql3.'<br>'.mysql_error());
$row3 = mysql_fetch_array($res3);

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


  echo"<br><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=\"2\"><font color=\"3399FF\">De : $row2[login] depuis : $row3[planete] [$row3[galaxi]:$row3[system]:$row3[position]] pour $row4[planete] [$row4[galaxi]:$row4[system]:$row4[position]]</font></td>
    <form name=\"suprimer\" method=\"post\" action=\"mp_del.php\" target=\"_parent\"><td width=\"25\" colspan=\"-1\" align=\"right\">
           <input type=\"hidden\" name=\"id\" value=\"$row[id]\">
          <input type=\"image\" src=\"imgs/del.gif\" width=\"25\">
                  </td></form>
  </tr>
  <tr>
    <td>Envoyer le : </td>
    <td colspan=\"2\">$row[date]</td>
  </tr>
  <tr style =\"background-color:#111111;\">
    <td width=\"85\">Sujet : </td>
    <td colspan=\"2\"> ".htmlentities($row[sujet])." </td>
  </tr>
  <tr>
    <td rowspan=\"2\" valign=\"top\">Message : </td>
    <td colspan=\"2\" valign=\"top\">".htmlentities($row[message])."</td>
  </tr>
  <form name=\"rep\" method=\"post\" action=\"mp_repondre\" target=\"_parent\"><tr style =\"background-color:#111111;\">
    <td width=\"500\">
	    <div align=\"center\" valign=\"middle\">
		  <input type=\"hidden\" name=\"Ex_envoyeur\" value=\"$row[envoyeur]\">
		  <input type=\"hidden\" name=\"Ex_planete_envoyeur\" value=\"$row[planete_envoyeur]\">
	      <input type=\"hidden\" name=\"Ex_sujet\" value=\"".htmlentities(addslashes($row[sujet]))."\">
	      <input type=\"hidden\" name=\"Ex_msg\" value=\"".htmlentities(addslashes($row[message]))."\">
		  <input type=\"hidden\" name=\"Ex_date\" value=\"$row[date]\">
            <input type=\"submit\" name=\"Submit\" value=\"R&eacute;pondre\" Style=\"border:1px solid #7E7E7E;\">
        </div>
    </td>
    <td>&nbsp;</td>
  </tr></form>
</table>";

if ($row[lu] =="non") {
$requete = "UPDATE matgraph_mp SET lu='oui' WHERE id='$row[id]'";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }
}
$req2 = "SELECT id FROM matgraph_espio2 WHERE planeteespionner = $planete";
$res2 = mysql_query($req2) or die('Erreur SQL! <br>'.$req2.'<br>'.mysql_error());
$num2 = mysql_num_rows($res2);
if ( $num2 > 0 ) {
include('espio2_nbremp.php'); }
}

$req = "SELECT * FROM matgraph_msgally WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
echo"<br><div align=\"center\"> Nouveaux messages de l'alliance : </div><br>";
While ( $row = mysql_fetch_array($res) ) {
echo"<br><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 width=\"587\"><div align=\"center\"> ".htmlentities($row[sujet])."</div></td>
    <form name=\"suprimer\" method=\"post\" action=\"mp_del7.php\" target=\"_parent\"><td width=\"25\" colspan=\"-1\" align=\"right\">
           <input type=\"hidden\" name=\"id\" value=\"$row[id]\">
          <input type=\"image\" src=\"imgs/del.gif\" width=\"25\">
                  </td></form>
  </tr>
  <tr style =\"background-color:#111111;\">
    <td colspan=\"2\"><div align=\"center\">".htmlentities($row[msg])."</div></td>
  </tr>
</table>";
if ($row[lu] =="non") {
$requete = "UPDATE matgraph_msgally SET lu='oui' WHERE id='$row[id]'";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }
}
$req2 = "SELECT id FROM matgraph_espio2 WHERE planeteespionner = $planete";
$res2 = mysql_query($req2) or die('Erreur SQL! <br>'.$req2.'<br>'.mysql_error());
$num2 = mysql_num_rows($res2);
if ( $num2 > 0 ) {
include('espio2_nbremsgally.php'); }
}

$req = "SELECT * FROM matgraph_bataille WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
echo"<br><div align=\"left\"> Rapports de bataille : </div><br>";
While ( $row = mysql_fetch_array($res) ) {
echo"<br><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 width=\"587\"><div align=\"center\"><font color=\"";
	if($row[win] == "1") { echo"00CC00";} else {echo"FF0000";} echo"\">$row[sujet]</font></div></td>
    <form name=\"suprimer\" method=\"post\" action=\"mp_del8.php\" target=\"_parent\"><td width=\"25\" colspan=\"-1\" align=\"right\">
           <input type=\"hidden\" name=\"id\" value=\"$row[id]\">
          <input type=\"image\" src=\"imgs/del.gif\" width=\"25\">
                  </td></form>
  </tr>
  <tr style =\"background-color:#111111;\">
    <td colspan=\"2\"><div align=\"center\">";echo ' <br> ' . html_entity_decode ($row[message], ENT_QUOTES) . '</FONT>' ; echo"</div></td>
  </tr>
</table>";
if ($row[lu] =="non") {
$requete = "UPDATE matgraph_bataille SET lu='oui' WHERE id='$row[id]'";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }
}
$req2 = "SELECT id FROM matgraph_espio2 WHERE planeteespionner = $planete";
$res2 = mysql_query($req2) or die('Erreur SQL! <br>'.$req2.'<br>'.mysql_error());
$num2 = mysql_num_rows($res2);
if ( $num2 > 0 ) {
include('espio2_nbremsgally.php'); }
}

$req = "SELECT * FROM matgraph_contreespio WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
echo"<br><div align=\"center\"> Nouveaux rapports de contre-espionnage : </div><br>";
While ( $row = mysql_fetch_array($res) ) {
echo"<br><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 width=\"587\"><div align=\"center\">$row[sujet]  Du $row[date]</div></td>
    <form name=\"suprimer\" method=\"post\" action=\"mp_del3.php\" target=\"_parent\"><td width=\"25\" colspan=\"-1\" align=\"right\">
           <input type=\"hidden\" name=\"id\" value=\"$row[id]\">
          <input type=\"image\" src=\"imgs/del.gif\" width=\"25\">
                  </td></form>
  </tr>
  <tr style =\"background-color:#111111;\">
    <td colspan=\"2\"><div align=\"center\">$row[message]</div></td>
  </tr>
 </table>";
if ($row[lu] =="non") {
$requete = "UPDATE matgraph_contreespio SET lu='oui' WHERE id='$row[id]'";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }
}

}

$req = "SELECT * FROM matgraph_espio1 WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
	echo"<br><div align=\"center\"> Nouveaux rapports d'espionnage : </div><br>";
	While ( $row = mysql_fetch_array($res) ) {
	echo"<br><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 width=\"587\"><div align=\"center\">$row[sujet]  Du $row[date]</div></td>
	    <form name=\"suprimer\" method=\"post\" action=\"mp_del2.php\" target=\"_parent\"><td width=\"25\" colspan=\"-1\" align=\"right\">
	           <input type=\"hidden\" name=\"id\" value=\"$row[id]\">
	          <input type=\"image\" src=\"imgs/del.gif\" width=\"25\">
	                  </td></form>
	  </tr>
	  <tr style =\"background-color:#111111;\">
	    <td colspan=\"2\"><div align=\"center\">$row[message]</div></td>
	  </tr>
	 </table>";
	if ($row[lu] == 'non') 
	{
		$requete = "UPDATE matgraph_espio1 SET lu='oui' WHERE id='$row[id]'";
		$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }
	}
}

$req = "SELECT * FROM matgraph_msg WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
echo"<br><div align=\"center\"> Autres nouveaux messages : </div><br>";
While ( $row = mysql_fetch_array($res) ) {
echo"<br><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 width=\"587\"><div align=\"center\"> $row[sujet]</div></td>
    <form name=\"suprimer\" method=\"post\" action=\"mp_del4.php\" target=\"_parent\"><td width=\"25\" colspan=\"-1\" align=\"right\">
           <input type=\"hidden\" name=\"id\" value=\"$row[id]\">
          <input type=\"image\" src=\"imgs/del.gif\" width=\"25\">
                  </td></form>
  </tr>
  <tr style =\"background-color:#111111;\">
    <td colspan=\"2\"><div align=\"center\">$row[msg]</div></td>
  </tr>
</table>";
if ($row[lu] =="non") {
$requete = "UPDATE matgraph_msg SET lu='oui' WHERE id='$row[id]'";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }
}
$req2 = "SELECT id FROM matgraph_espio2 WHERE planeteespionner = $planete";
$res2 = mysql_query($req2) or die('Erreur SQL! <br>'.$req2.'<br>'.mysql_error());
$num2 = mysql_num_rows($res2);
if ( $num2 > 0 ) {
include('espio2_nbremsg.php'); }
}

mysql_close($connect);

echo'<br><br><br>';
include 'zap.php';
?>