<?php
include ('logue.php'); 
include ('entete2.php');
include ('entete.php');
include ('ressource.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: #B0C4DE}
.Style2 {color: #FF0000}
.Style3 {color: #00CC00}
</STYLE>";
echo"<div align=\"center\"><form name=\"colo\" method=\"post\" action=\"colonie.php\" target=\"principal\">
<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');  

$sql = "SELECT techrare_moinsressource,techrare_plusressource,fer_on,or_on,exfer_on,exor_on,ada_on,ura_on,fer_energie,or_energie,exfer_energie,exor_energie,ada_energie,ura_energie FROM matgraph_users WHERE id='$planete' ";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 

if($row[techrare_moinsressource] == "1") {
	$max = 0.75 ; 
}
else {
	if($row[techrare_plusressource] == "1") {
		$max = 1.5 ;
	}
	else {
		$max = 1 ;
	}
}

$fer = $_POST["fer"];
$exfer = $_POST["exfer"];
$or = $_POST["or"];
$exor = $_POST["exor"];
$ada = $_POST["ada"];
$ura = $_POST["ura"];

if ( $exfer == NULL ) {
$exfer = 1; }
if ( $exor == NULL) {
$exor = 1; }

if(is_numeric($fer) && is_numeric($or) && is_numeric($ada) && is_numeric($ura) && is_numeric($exfer) && is_numeric($exor)) {
	if( $fer > $max || $or > $max || $ada > $max || $ura > $max || $exfer > $max || $exor > $max) {
		echo '<script language="javascript" type="text/javascript">
		<!--
		window.location.replace("prod.php");
		-->
		</script>';
		exit;
	}
} else {
	echo '<script language="javascript" type="text/javascript">
	<!--
	window.location.replace("prod.php");
	-->
	</script>';
	exit;
}

if($row[fer_on] == "0") {
if($Total_energie_reste >= (-1*$row[fer_energie])) {
$requete = "UPDATE matgraph_users SET fer_on='$fer' WHERE id='$planete'";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }}
else {
$requete = "UPDATE matgraph_users SET fer_on='$fer' WHERE id='$planete'";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }

if($row[or_on] == "0") {
if($Total_energie_reste >= (-1*$row[or_energie])) {
$requete = "UPDATE matgraph_users SET or_on='$or' WHERE id='$planete'";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }}
else {
$requete = "UPDATE matgraph_users SET or_on='$or' WHERE id='$planete'";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }

if($row[exfer_on] == "0") {
if($Total_energie_reste >= (-1*$row[exfer_energie])) {
$requete = "UPDATE matgraph_users SET exfer_on='$exfer' WHERE id='$planete'";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }}
else {
$requete = "UPDATE matgraph_users SET exfer_on='$exfer' WHERE id='$planete'";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }

if($row[exor_on] == "0") {
if($Total_energie_reste >= (-1*$row[exor_energie])) {
$requete = "UPDATE matgraph_users SET exor_on='$exor' WHERE id='$planete'";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }}
else {
$requete = "UPDATE matgraph_users SET exor_on='$exor' WHERE id='$planete'";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }

if($row[ada_on] == "0") {
if($Total_energie_reste >= (-1*$row[ada_energie])) {
$requete = "UPDATE matgraph_users SET ada_on='$ada' WHERE id='$planete'";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }}
else {
$requete = "UPDATE matgraph_users SET ada_on='$ada' WHERE id='$planete'";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }

if($row[ura_on] == "0") {
if($Total_energie_reste >= (-1*$row[ura_energie])) {
$requete = "UPDATE matgraph_users SET ura_on='$ura' WHERE id='$planete'";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }}
else {
$requete = "UPDATE matgraph_users SET ura_on='$ura' WHERE id='$planete'";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); }


echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("prod.php");
-->
</script>';
?>