<?
include ('logue.php') ;

include ('config.php') ;

// A FAIRE
// préciser les SELECT ...
// unset() les variables $_SESSION ...

// ------------------------- AFFICHAGE PAGE -------------------------

include ('entete2.php') ;

include ('entete.php') ;

include ('ressource.php') ;

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

$Total_energie_consom = $row[fer_energie] + $row[or_energie] + $row[exfer_energie] + $row[exor_energie] + $row[ada_energie] + $row[ura_energie] ;
$Total_energie_reste =  round(($New_central_energie + $New_fission_energie + $Total_energie_consom),0) ;
$Total_energie_prod = round(($New_central_energie + $New_fission_energie),0) ;
$Total_energie_reste2 =  number_format(round(($New_central_energie + $New_fission_energie + $Total_energie_consom),0), 0, ',', ' ') ;
$Total_energie_prod2 = number_format(round(($New_central_energie + $New_fission_energie),0), 0, ',', ' ') ;

echo"<style>
input, textarea {
border:1px solid #7E7E7E;
background-color:#000000;
font-family:'trebuchet ms',sans-serif;
color:white;
}
select, option {
background-color:#000000;
color:white;
}
.button {
border-left:1px solid #EEEEEE; border-right:1px solid #666666; border-top:1px solid #EEEEEE; border-bottom:1px solid #666666; background-color:#111111;text-decoration: none;text-align: center;padding: 3 px;
}
</style>

<STYLE TYPE=text/css>
.Style1 {color: #0000FF}
.Style2 {color: #FF0000}
</STYLE>" ;

echo'<div align="center"><form name="colo" method="post" action="colonies.php" target="_parent">
<table align="center" border="0" cellspacing="0" cellpadding="0"  style="font-family:trebuchet ms,sans-serif; font-size: 9pt ;">
   <tr>
     <td width="100" rowspan="2" valign="middle">
       <div align="center">
         <input name="page" value="flotte" type="hidden" id="page">
         <select name="idcolo" onchange=submit()>';

include ('colo2.php') ; 

if ($row2[chantier_lvl] == 0) 
{
	$chantier_lvl = 0 ;
}
else
{
	$chantier_lvl = $row2[chantier_lvl] ;
}

// ------------------------- DETECTION DES COMBATS -------------------------

// réinitialisation des variables
unset($date_combat) ;
unset($Rapport) ;

$sql_A = "SELECT id, login, idjoueur FROM matgraph_users WHERE login = '$login'" ; $res_A = db_mysql_Query($sql_A) or die('Erreur SQL! <br>' . $sql_A . '<br>'.mysql_error()) ;
while ( $row_A = mysql_fetch_array($res_A) )
{
	$sql = "SELECT * FROM matgraph_mobil WHERE iddepart = '$row_A[id]' AND mission = 'aller' ORDER BY date" ;
	include ('config.php') ;
	$res = db_mysql_Query($sql) ;
	mysql_close() ;
	$num = mysql_num_rows($res) ;
	if ( $num > 0 )
	{
		while ( $row = mysql_fetch_array($res) ) // rassemble les vaisseaux en flotte
		{
			if ( $row[date] != $date_combat[count($date_combat)-1] )
			{
				$date_combat[] = $row[date] ;
				ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $row[date], $thetime) ; 				$time = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]) ; 				$diftemps = time() - $time ;
				if ($diftemps < 0)
				{
					$emintechlaser = ( -$diftemps ) / 60 ;
					if ( floor($emintechlaser) != $emintechlaser ) $esectechlaser = floor( ($emintechlaser - floor( $emintechlaser )) * 60) ;
					if ( $emintechlaser > 60 )
					{
						$ehourtechlaser = floor( $emintechlaser / 60 ) ;
						$emintechlaser = $emintechlaser - ( 60 * $ehourtechlaser ) ;
	
						if ( $ehourtechlaser > 24 )
						{
							$edaytechlaser = floor( $ehourtechlaser / 24) ;
							$ehourtechlaser = $ehourtechlaser - ( 24 * $edaytechlaser ) ;
						}
					}	
					$etimetechlaser = "" ;
					if (!empty($edaytechlaser) ) $etimetechlaser.="$edaytechlaser j " ;
					if (!empty($ehourtechlaser) ) $etimetechlaser.="$ehourtechlaser h " ;
					if ($emintechlaser != 0) $etimetechlaser.= floor($emintechlaser)." mn " ;
					if (!empty($esectechlaser) ) $etimetechlaser.="$esectechlaser s" ;
	
					// Attaquant
					$sql_B = "SELECT planete, login FROM matgraph_users WHERE id = '$row[iddepart]'" ;
					include ('config.php') ;					$res_B = db_mysql_Query($sql_B) or die('Erreur SQL! <br>' . $sql_B . '<br>'.mysql_error()) ;
					mysql_close() ;
					$row_B = mysql_fetch_array($res_B) ;
	
					// Defenseur
					$sql_C = "SELECT planete, login FROM matgraph_users WHERE id = '$row[iddestination]'" ; 					include ('config.php') ;						
					$res_C = db_mysql_Query($sql_C) or die('Erreur SQL! <br>' . $sql_C . '<br>'.mysql_error()) ;
					mysql_close() ;
					$row_C = mysql_fetch_array($res_C) ;

					$Rapport .= '<br><hr><B>MISSION -> ATTAQUE</B><br><br>Votre planète " ' . $row_B[planete] . ' " a envoyé une flotte attaquer la planète " ' . $row_C[planete] . ' " ( ' . $row_C[login] . ' ).<br>'  ;
					$Rapport .= 'Arrivée prévue le ' . $row[date] . ', soit dans environ ' . $etimetechlaser . '.<br>' ;
					$Rapport .= '<br>Votre flotte se compose de :<br>' ;
					$sql_D = "SELECT * FROM matgraph_mobil WHERE iddepart = '$row_A[id]' AND mission = 'aller' AND date = '$row[date]' ORDER BY date" ;
					include ('config.php') ;
					$res_D = db_mysql_Query($sql_D) ;
					mysql_close() ;
					while ( $row_D = mysql_fetch_array($res_D) ) // Description de la flotte
					{
						$sql_E = "SELECT * FROM matgraph_vaisseaux WHERE id = '$row_D[idvaisseau]'" ;
						include ('config.php') ;
						$res_E = db_mysql_Query($sql_E) ;
						mysql_close() ;
						$row_E = mysql_fetch_array($res_E) ;
						$Rapport .= '- ' . $row_E['nom'] . ' ( ' . $row_D['nombre'] . ' )<br>' ;
					}
				}
			}
		}
	}
}

echo '<FONT FACE="Courier New, Courier, mono" style="color: #00CC66;text-align: left;" Size=-1>' ;
echo $Rapport . '<br>' ;
echo '</FONT><DIV id="cligno1" style="font-family:Courier New, Courier, mono;color:#00CC66;text-align:left;"><B>_</B></DIV>' ;

?>

<SCRIPT LANGUAGE="JavaScript" type="text/javascript">function clignotement(_actif)
{	if (document.getElementById(_actif).style.color=="black")		document.getElementById(_actif).style.color="#00CC66" ;	else		document.getElementById(_actif).style.color="black" ;
}// mise en place de l appel régulier de la fonction toutes les 0.5 secondesPeriode = setInterval("clignotement('cligno1')", 500) ;
</script>

