<?
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 = db_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 = db_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 * FROM matgraph_mp WHERE $liste_id ORDER BY id DESC";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_mp = $num ;
$req = "SELECT * FROM matgraph_mp WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_mplu = $num ;

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

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

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

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

//msgcombat
$req = "SELECT * FROM matgraph_bataille WHERE $liste_id ORDER BY id DESC";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$total_msgcombat = $num ;

$req = "SELECT * FROM matgraph_bataille WHERE $liste_id AND lu='non' ORDER BY id DESC";
$res = db_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;
}
input2 {
border:1px solid #7E7E7E;
background-color:#000000;
font-family:'trebuchet ms',sans-serif;
color:white;
}
textarea {
border:1px solid #7E7E7E;
background-color:#000000;
font-family:'trebuchet ms',sans-serif;
color:white;
}
select, option {
background-color:#000000;
color:white;
}
</style>
<STYLE TYPE=text/css>
.Style1 {color: #0000FF}
.Style2 {color: #FF0000}
</STYLE>";
echo"<div align=\"center\"><form name=\"colo\" method=\"post\" action=\"colonie.php\" target=\"_parent\">
<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
   <tr>
     <td width=\"100\" rowspan=\"2\" valign=\"middle\">
       <div align=\"center\">
         <input name=\"page\" value=\"" . $PHP_SELF . "\" type=\"hidden\" id=\"page\">
         <select name=\"idcolo\" onchange=submit()>";
include ('colo2.php');
echo"<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 colspan=\"2\"><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 colspan=\"2\"><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 colspan=\"2\"><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\">0 / $total_espio1</div></td>
  </tr>
  <tr>
    <td><div align=\"center\"><a href=\"mp_lire_contreespio.php\" target=\"_parent\">Rapports de contre-espionnages </a></div></td>
    <td colspan=\"2\"><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 colspan=\"2\"><div align=\"center\">$total_msglu / $total_msg</div></td>
  </tr>
  <tr>
    <td height=\"21\"><div align=\"center\"><b>Date :</b> </div></td>
    <td width=\"311\" colspan=\"2\" height=\"21\"><div align=\"center\"><b>Sujet :</b> </div></td>
  </tr>";
if(isset($_GET['page'])){
	$page=$_GET['page'];
	$limit = (($limite_mp*$page)-1) .",". (($limite_mp*($page+'1'))-1);
}else{
	$page=0;
	$limit = "0,". ($limite_mp-1);
}
$req = "SELECT * FROM matgraph_espio1 WHERE $liste_id ORDER BY id DESC LIMIT ".$limit;
$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) ) {
$lire = "lire" ;
  $liree = $id.$row[id];
echo"<tr";
// gère le quadrillage du tableau
			if (($i/2) == ceil($i/2))
			{
				echo' style ="background-color:#111111;"' ;
			}
			$i++;
	echo">
    <td><div align=\"center\">$row[date]</div></td>
    <form name=\"$liree\" id=\"$liree\" method=\"post\" action=\"mp_lire_popup.php\" target=\"_blank\" width=\"618\">
	<input type=\"hidden\" name=\"id\" value=\"$row[id]\">
	<input type=\"hidden\" name=\"type\" value=\"espio\">
	<td width=\"311\" align=\"center\"><a href=\"#\" target=\"_parent\" Onclick=\"document.getElementById('$liree').submit()\"><font color=\"9966CC\">$row[sujet]</font></a>
	</td>
	</form>
    <form name=\"suprimer\" method=\"post\" action=\"mp_del2.php\" target=\"_parent\"><input type=\"hidden\" name=\"id\" value=\"$row[id]\">
	<td width=\"25\" height=\"21\" align=\"center\">
          <input type=\"image\" src=\"imgs/del.gif\" width=\"25\"></td>
  </tr></form>";
}}else{
	echo "<tr><td colspan='2'><center>Vous n'avez pas de message personnel...</center></td></tr>";
}
$count=$total_espio1;
        if ($page > 1){
            $end2 = $page - 1;
            echo "<a href=\"mp_lire_mp.php?page=" . $end2 . "\">&lt;</a>&nbsp;";
        } 

        $nb_page = intval($count / $limite_mp);
        $nb_page2 = $count % $limite_mp;
        if ($nb_page2 > 0) $nb_page++;
        $i = 1;

        while ($i <= $nb_page && $nb_page <> 1){
            if (($i == ($page-1)) || ($i == $page) || ($i == ($page + 1)) || ($i == 1) || ($i == 2) || ($i == 3) || ($i == $nb_page) || ($i == ($nb_page-1)) || ($i == ($nb_page-2)))
            {
                if ((($page + 1) <= ($nb_page - 4)) && ($i == ($nb_page - 2)) && $nb_page != 6)echo "...&nbsp;";
                if ($i <> $page){
                    echo "<a href=\"mp_lire_mp.php?page=" . $i . "\">" . $i . "</a>";
                }else{
                    echo "<b>[" . $i . "]</b>";
                } 
                if ($nb_page != $i){
                    echo"&nbsp;";
                } 
                if ((($page - 1) >= 5) && ($i == 3) && $nb_page != 6){
                    echo "...&nbsp;";
                } 
            } 
            $i++;
        } 
        $end = $start + $limite_mp;
        if (($count > $end) && $page < $nb_page){
            $end = $page + 1;
            echo"&nbsp;<a href=\"mp_lire_mp.php?page=" . $end . "\">&gt;</a>";
        } 
        echo "<br />";
echo"<br><br>
  <tr>  	<form action=\"mp_del_all.php\" method=\"post\" name=\"form1\" target=\"_parent\">
	 <input type=\"hidden\" name=\"categorie\" value=\"espio\">
    <td height=\"21\"><div align=\"right\"><input type=\"submit\" name=\"Submit2\" value=\"Vider\" Style=\"border:1px solid #7E7E7E;\"></div></td></form>
			<form action=\"mp_lire.php\" method=\"post\" name=\"form1\" target=\"_parent\">
	<td width=\"166\" colspan=\"2\" height=\"21\"><div align=\"left\"><input type=\"submit\" name=\"Submit2\" value=\"Fermer\" Style=\"border:1px solid #7E7E7E;\"></div></td>
  </tr></form>

</table>";
?>