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

////////////////
// affichage barre ressource/style css
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: #B0C4DE}
.Style2 {color: #FF0000}
.Style3 {color: #00CC00}
</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'); 
//
////////////////

////////////////
// info niveau de production augmenté ou baissé
if($row[techrare_moinsressource] == "1") {
	$marche = 0.75 ; 
	echo"*Suite a un avertissement votre production est baissé de 25%.<br><br>";
} else {
	if($row[techrare_plusressource] == "1") {
		$marche = 1.5 ; 
		echo"*La technologie rare \"Production des Anciens\" vous permet de produit 50% plus vite vos matiére premiéres.<br><br>";
	} else {
		$marche = 1 ; 
	}
}
//
////////////////

////////////////
//calcul des productions des mines

if ($row[fer_lvl] == "0") {
	$new9fer_ressource = 0;
} else {
	$new9fer_ressource = number_format(floor($marche * 100 * ( bcpow( 1.18, $row[fer_lvl],3))), 0, ',', ' ');
	$new9fer_ressource2 = floor($marche * 100 * ( bcpow( 1.18, $row[fer_lvl],3)));
}
if ($row[exfer_lvl] == "0") {
	$newexfer_ressource = 0;
} else {
	$newexfer_ressource = number_format(floor($marche * 500 * ( bcpow( 1.2, $row[exfer_lvl],3))), 0, ',', ' ');
	$newexfer_ressource2 = floor($marche * 500 * ( bcpow( 1.2, $row[exfer_lvl],3)));
}
if ($row[or_lvl] == "0") {
	$new9or_ressource = 0;
	$new9or_ressource2 = 0;
} else {
	$new9or_ressource = number_format(floor($marche * 90 * ( bcpow( 1.15, $row[or_lvl],3))), 0, ',', ' ');
	$new9or_ressource2 = floor($marche * 90 * ( bcpow( 1.15, $row[or_lvl],3)));
}
if ($row[exor_lvl] == "0") {
	$newexor_ressource = 0;
	$newexor_ressource2 = 0;
} else {
	$newexor_ressource = number_format(floor($marche * 500 * ( bcpow( 1.25, $row[exor_lvl],3))), 0, ',', ' ');
	$newexor_ressource2 = floor($marche * 500 * ( bcpow( 1.25, $row[exor_lvl],3)));
}
if ($row[ada_lvl] == "0") {
	$newada_ressource = 0;
	$newada_ressource2 = 0;
} else {
	$newada_ressource = number_format(floor($marche * 100 * ( bcpow( 1.2, $row[ada_lvl],3))), 0, ',', ' ');
	$newada_ressource2 = floor($marche * 100 * ( bcpow( 1.2, $row[ada_lvl],3)));
}
if ($row[ura_lvl] == "0") {
	$newura_ressource = 0;
	$newura_ressource2 = 0;
} else {
	$newura_ressource = number_format($marche * floor(100 * ( bcpow( 1.2, $row[ura_lvl],3))), 0, ',', ' ');
	$newura_ressource2 = floor($marche * 100 * ( bcpow( 1.2, $row[ura_lvl],3)));
}
//
////////////////

////////////////
// calcul total extracteur/mine
$total_fer = number_format($new9fer_ressource2 + $newexfer_ressource2 + 20, 0, ',', ' ');
$total_or = number_format($new9or_ressource2 +  $newexor_ressource2 + 10 , 0, ',', ' ');
//
////////////////

////////////////
// calcul capacité hangars
$hangar_fer = floor(100000 *(bcpow(1.7, $row[hangarfer_lvl],3)));
$hangar_or = floor(100000 *(bcpow(1.7, $row[hangaror_lvl],3)));
$hangar_ada = floor(100000 *(bcpow(1.7, $row[hangarada_lvl],3)));
$hangar_ura = floor(100000 *(bcpow(1.7, $row[hangarura_lvl],3)));
$hangar_fer2 = number_format(floor(100000 *(bcpow(1.7, $row[hangarfer_lvl],3))), 0, ',', ' ');
$hangar_or2 = number_format(floor(100000 *(bcpow(1.7, $row[hangaror_lvl],3))), 0, ',', ' ');
$hangar_ada2 = number_format(floor(100000 *(bcpow(1.7, $row[hangarada_lvl],3))), 0, ',', ' ');
$hangar_ura2 = number_format(floor(100000 *(bcpow(1.7, $row[hangarura_lvl],3))), 0, ',', ' ');
//
////////////////

////////////////
// calcul energie consommé/ energie distribué
$fer_energie = number_format($row[fer_energie], 0, ',', ' ');
$exfer_energie = number_format($row[exfer_energie], 0, ',', ' ');
$or_energie = number_format($row[or_energie], 0, ',', ' ');
$exor_energie = number_format($row[exor_energie], 0, ',', ' ');
$ada_energie = number_format($row[ada_energie], 0, ',', ' ');
$ura_energie = number_format($row[ura_energie], 0, ',', ' ');
$central_energie = number_format($New_central_energie, 0, ',', ' ');
$fission_energie = number_format($New_fission_energie, 0, ',', ' ');
//
////////////////

$coutfission2 = - floor($coutfission);
$total_ura = $coutfission2 + $newura_ressource2 + 2;
$total_ada = $newada_ressource2 + 5 ;

////////////////
// affichage formulaire maj production
echo"<form name=\"form1\" method=\"post\" action=\"prod_action.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><b>Production par heure :</b></td>
    <td><div align=\"center\"><p class=\"Style1\">Fer</div></p></td>
    <td><div align=\"center\"><p class=\"Style1\">Or</div></p></td>
    <td><div align=\"center\"><p class=\"Style1\">Cristal</div></p></td>
    <td><div align=\"center\"><p class=\"Style1\">Naquadah</div></p></td>
    <td><div align=\"center\"><p class=\"Style1\">Energie</div></p></td>
    <td><div align=\"center\"><p class=\"Style1\">On // Off </div></p></td>
  </tr>
  <tr>
    <td><p class=\"Style1\">Production de Base</p></td>
    <td><div align=\"center\">20</div></td>
    <td><div align=\"center\">10</div></td>
    <td><div align=\"center\">5</div></td>
    <td><div align=\"center\">2</div></td>
    <td><div align=\"center\">0</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
  </tr>
  <tr style =\"background-color:#111111;\">
    <td><p class=\"Style1\">Mine de Fer ($row[fer_lvl]) </p></td>
    <td><div align=\"center\">$new9fer_ressource</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">$fer_energie</div></td>
    <td><div align=\"center\"><select name=\"fer\" id=\"fer\">";
if($row[fer_on] == "1" || $row[fer_on] == "1.5"  || $row[fer_on] == "0.75" ) {
	echo"<option value=\"$marche\" selected>Marche</option>
    <option value=\"0\">Arret</option>"; 
} else {
	echo"<option value=\"$marche\">Marche</option>
    <option value=\"0\" selected>Arret</option>"; 
}
  echo"</select></div></td>
  </tr>";
if ($row[exfer_lvl] !== "0") {
 echo"<tr>
    <td><p class=\"Style1\">Centre d'extraction de Fer ($row[exfer_lvl]) </p></td>
    <td><div align=\"center\">$newexfer_ressource</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">$exfer_energie</div></td>
    <td><div align=\"center\"><select name=\"exfer\" id=\"exfer\">";
	if($row[exfer_on] == "1" || $row[exfer_on] == "1.5"  || $row[exfer_on] == "0.75" ) {
		echo"<option value=\"$marche\" selected>Marche</option>
   		 <option value=\"0\">Arret</option>"; 
	} else {
		echo"<option value=\"$marche\">Marche</option>
    	<option value=\"0\" selected>Arret</option>"; 
	}
  echo"</select></div></td>
  </tr>"; 
}
  echo"<tr style =\"background-color:#111111;\">
    <td><p class=\"Style1\">Mine d'Or ($row[or_lvl]) </p></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">$new9or_ressource</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">$or_energie</div></td>
    <td><div align=\"center\"><select name=\"or\" id=\"or\">";
if($row[or_on] == "1" || $row[or_on] == "1.5"  || $row[or_on] == "0.75" ) {
	echo"<option value=\"$marche\" selected>Marche</option>
    <option value=\"0\">Arret</option>"; 
} else {
	echo"<option value=\"$marche\">Marche</option>
    <option value=\"0\" selected>Arret</option>"; 
}
 echo"</select></div></td>
  </tr>";
if ($row[exor_lvl] !== "0") {
 echo"<tr>
    <td><p class=\"Style1\">Centre d'extraction d'Or ($row[exor_lvl]) </p></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">$newexor_ressource</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">$exor_energie</div></td>
    <td><div align=\"center\"><select name=\"exor\" id=\"exor\">";
	if($row[exor_on] == "1" || $row[exor_on] == "1.5"  || $row[exor_on] == "0.75" ) {
		echo"<option value=\"$marche\" selected>Marche</option>
    	<option value=\"0\">Arret</option>"; 
	} else {
		echo"<option value=\"$marche\">Marche</option>
    	<option value=\"0\" selected>Arret</option>"; 
	}
  echo"</select></div></td>
  </tr>"; 
}
  echo"<tr style =\"background-color:#111111;\">
    <td><p class=\"Style1\">Mine de cristal ($row[ada_lvl]) </p></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">$newada_ressource</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">$ada_energie</div></td>
    <td><div align=\"center\"><select name=\"ada\" id=\"ada\">";
if($row[ada_on] == "1" || $row[ada_on] == "1.5"  || $row[ada_on] == "0.75" ) {
	echo"<option value=\"$marche\" selected>Marche</option>
    <option value=\"0\">Arret</option>"; 
}else {
	echo"<option value=\"$marche\">Marche</option>
    <option value=\"0\" selected>Arret</option>"; 
}
  echo"</select></div></td>
  </tr>
  <tr>
    <td><p class=\"Style1\">Mine de Naquadah ($row[ura_lvl]) </p></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">$newura_ressource</div></td>
    <td><div align=\"center\">$ura_energie</div></td>
    <td><div align=\"center\"><select name=\"ura\" id=\"ura\">";
if($row[ura_on] == "1" || $row[ura_on] == "1.5"  || $row[ura_on] == "0.75" ) {
	echo"<option value=\"$marche\" selected>Marche</option>
    <option value=\"0\">Arret</option>"; 
} else {
	echo"<option value=\"$marche\">Marche</option>
    <option value=\"0\" selected>Arret</option>"; 
}
  echo"</select></div></td>
  </tr>
  <tr style =\"background-color:#111111;\">
    <td><p class=\"Style1\"> Centrale d'&eacute;nergie thermique ($row[central_lvl]) </p></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">$central_energie</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
  </tr>";
if ($row[fission_lvl] !== "0") {
 echo"<tr>
    <td><p class=\"Style1\">Centrale &eacute;nergitique au Naquadah ($row[fission_lvl]) </p></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
    <td><div align=\"center\">$coutfission2</div></td>
    <td><div align=\"center\">$fission_energie</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
  </tr>"; }
  echo"<tr>
    <td colspan=\"7\"><div align=\"center\">&nbsp;</div></td>
  </tr>
  <tr style =\"background-color:#111111;\">
    <td><p class=\"Style1\">Total de la production :</p></td>
    <td><div align=\"center\">$total_fer</div></td>
    <td><div align=\"center\">$total_or</div></td>
    <td><div align=\"center\">$total_ada</div></td>
    <td><div align=\"center\">$total_ura</div></td>
    <td><div align=\"center\">$Total_energie_reste2</div></td>
    <td><div align=\"center\">&nbsp;</div></td>
  </tr>
  <tr>
    <td><p class=\"Style1\">Capacit&eacute; de stockage du mat&eacute;riel : </p></td>
    <td valign=\"middle\" align=\"center\">";
if($hangar_fer > $newwfer_ressource) {
	echo"<p class=\"Style3\">";
} else {
	echo"<p class=\"Style2\">"; 
}
echo"$hangar_fer2</p></td>
    <td valign=\"middle\" align=\"center\">";

if($hangar_or > $newwor_ressource) {
	echo"<p class=\"Style3\">";
} else {
	echo"<p class=\"Style2\">"; 
}
echo"$hangar_or2</p></td>
   <td valign=\"middle\" align=\"center\">";
   
if($hangar_ada > $newwada_ressource) {
	echo"<p class=\"Style3\">";
} else {
	echo"<p class=\"Style2\">"; 
}
echo"$hangar_ada2</p></td>
    <td valign=\"middle\" align=\"center\">";
	
if($hangar_ura > $newwura_ressource) {
	echo"<p class=\"Style3\">"; 
} else {
	echo"<p class=\"Style2\">"; 
}

echo"$hangar_ura2</p></td>
    <td valign=\"middle\" align=\"center\"><p class=\"Style3\">Illimit&eacute;</p></td>
    <td valign=\"middle\" align=\"center\">&nbsp;</td>
  </tr>
    <tr>
    <td valign=\"middle\" align=\"center\" colspan=\"7\"><input type=\"submit\" name=\"Submit\" value=\"Mettre à jour\"></td>
  </tr>
</table></form>";
//
//////////////////

////////////////
// calcul production militaire/eppz
$prodmili = number_format((2.5 * ( bcpow( 2, $row[mili_lvl],3))), 0, ',', ' ');
$capacite_soldat = number_format(round((10000 * ( bcpow( 2, $row[mili_lvl],3))),0), 0, ',', ' ');
$prodeppz = (10 + $row[mili_lvl]);
//
////////////////

////////////////
// affichage tableau militaire/eppz
echo"<br><br>
<table width=\"659\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  <tr style =\"background-color:#222222;\">
    <td width=\"196\"><div align=\"center\"> </div></td>
    <td width=\"266\"><div align=\"center\">Production : </div></td>
    <td width=\"189\"><div align=\"center\">Limite sur cette planète : </div></td>
  </tr>
  <tr>
  <td><div align=\"center\">Militaire : </div></td>
    <td><div align=\"center\">$prodmili / heure</div></td>
    <td><div align=\"center\">$capacite_soldat</div></td>
  </tr>
  <tr style =\"background-color:#111111;\">
  <td><div align=\"center\">E.P.P.Z. : </div></td>
    <td><div align=\"center\">$prodeppz / semaine </div></td>
    <td><div align=\"center\"><font color=\"00CC00\">Illimit&eacute;</font></div></td>
  </tr>
</table>";
//
////////////////

////////////////
// maj production/avertissement
$sql4 = "SELECT id,login FROM matgraph_avertissement WHERE date < now() ";
$res4 = db_mysql_Query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
$num4 = mysql_num_rows($res4);
if ( $num4 > 0 ) {
	  While ( $row4 = mysql_fetch_array($res4) ) {  
	
	$req2 = "SELECT idjoueur,fer_on,or_on,exfer_on,exor_on,ada_on,ura_on FROM matgraph_users WHERE login = '".addslashes($row4['login'])."' ORDER by id ASC";
	$res2 = db_mysql_Query($req2) or die('Erreur SQL!1 <br>'.$req2.'<br>'.mysql_error());
	$num2 = mysql_num_rows($res2);
	if ( $num2 > 0 ) {
	  While ( $row2 = mysql_fetch_array($res2) ) {
	  	$fer_on = 0;
			$or_on = 0;
			$exfer_on = 0;
			$exor_on = 0;
	  	$ada_on = 0;
	  	$ura_on = 0;
	  	if($row2['fer_on'] != 0)
	  	{
	  		$fer_on = 1;
	  	}
	  	if($row2['or_on'] != 0)
	  	{
	  		$or_on = 1;
	  	}
	  	if($row2['exfer_on'] != 0)
	  	{
	  		$exfer_on = 1;
	  	}
	  	if($row2['exor_on'] != 0)
	  	{
	  		$exor_on = 1;
	  	}
	  	if($row2['ada_on'] != 0)
	  	{
	  		$ada_on = 1;
	  	}
	  	if($row2['ura_on'] != 0)
	  	{
	  		$ura_on = 1;
	  	}
	  	
	  	$requete = "UPDATE matgraph_users SET fer_on=$fer_on,or_on=$or_on,exfer_on=$exfer_on,exor_on=$exor_on,ada_on=$ada_on,ura_on=ura_on,techrare_moinsressource=0 WHERE idjoueur='$row2[idjoueur]'";
		$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
		}  
	}
	
	
	$sql5 = "DELETE FROM matgraph_avertissement WHERE id = $row4[id]";
	$res5 = db_mysql_Query($sql5)or die('erreur sql<br>'.$sql5.'<br>'.mysql_error());
	
	}
}
//
////////////////
?>