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

echo '<SCRIPT LANGUAGE="JavaScript" type="text/javascript" SRC="Js_module/Infobulle.js"></SCRIPT>' ;
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: #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=\"720\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#000000\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">
    <tr style =\"background-color:#222222;\">
      <td align=\"center\"><b>Centre commercial</b></td>
    </tr>";

$tauxfer=2;
$tauxcristal=3;
$tauxnaq=4;
$taux=0.85;

$pas_assez = 0;

$action = htmlentities ($_POST["action"]);
$ada = (int)$_POST["ada"];
$ada1 = (int)$_POST["ada1"];
$fer = (int)$_POST["fer"];
$fer1 = (int)$_POST["fer1"];
$ura = (int)$_POST["ura"];
$ura1 = (int)$_POST["ura1"];

if($action=="achat"){
  $or_necessaire=($ada/$tauxnaq + $ura/$tauxcristal + $fer/$tauxfer);
  $taux=$or_necessaire*(1-$taux);
  $or_necessaire+=$taux;
  if ($newwor_ressource < $or_necessaire ) 
    $pas_assez = 1;
  $new_fer = $newwfer_ressource + $fer ;
  $new_or = $newwor_ressource - $or_necessaire ;
  $new_ada = $newwada_ressource + $ada ;
  $new_ura = $newwura_ressource + $ura ;
}
if($action=="vente"){
$ada = $ada1;
$fer = $fer1;
$ura = $ura1;

  $or_necessaire=($ada/$tauxnaq + $ura/$tauxcristal + $fer/$tauxfer);
  $taux=$or_necessaire*(1-$taux);
  $or_necessaire-=$taux;
  if ($newwfer_ressource < $fer || $newwada_ressource < $ada || $newwura_ressource < $ura  ) 
    $pas_assez = 1;
  $new_fer = $newwfer_ressource - $fer ;
  $new_or = $newwor_ressource + $or_necessaire ;
  $new_ada = $newwada_ressource - $ada ;
  $new_ura = $newwura_ressource - $ura ;
}
if ($action=="achat" || $action=="vente") {
  if ($pas_assez == 1){
    echo "Vous n'avez pas assez de ressources disponibles !";
  }else{
    $sql = "UPDATE matgraph_users set fer_ressource = $new_fer, or_ressource = $new_or, ada_ressource = $new_ada, ura_ressource = $new_ura WHERE id = '$planete'";
    db_mysql_Query($sql) or die('Erreur SQL!<br>'.$sql.'<br>'.mysql_error());
    echo 'Transfert terminé !<script language="javascript" type="text/javascript">
<!--
window.location.replace("carrouf.php");
-->
</script>';
  }
exit;
}







if (1 || $row[labo_lvl] >= 5 ) {
    echo"<tr>
      <td align=\"left\"><br>
      La money d'echange par défaut est l'OR. Tout achat/vente en fait donc intervenir.<br>
      Le taux officiel est de : 1 or = $tauxfer fer = $tauxcristal cristal = $tauxnaq naquadah<br>
      Nous fournissons les conteneurs ainsi que l'énergie nécessaire, en contre partie, notre
      taux d'echange est de ".(100-$taux*100)."%.
      
      </td>
    </tr>";
    
/*------------------------------Achat---------------------------*/
    echo"
    <tr style =\"background-color:#222222;\">
      <td align=\"center\"><b>Achat</b></td>
    </tr>";
    echo"<tr>
      <td align=\"center\"><br>";
      
echo "     <form name=\"form1\" method=\"post\" action=\"carrouf.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>
      <td height=\"39\"><div align=\"left\">Fer : 
        <input name=\"fer\" type=\"text\" id=\"fer\" value=\"0\" onKeyUp=\"coutachat();\" onChange=\"coutachat();\"> 
      </td>
      <td height=\"42\">Cristal : 
        <input name=\"ada\" type=\"text\" id=\"ada\" value=\"0\" onKeyUp=\"coutachat();\" onChange=\"coutachat();\"> 
      </td>
      <td height=\"42\">Naquadah : 
      <input name=\"ura\" type=\"text\" id=\"ura\" value=\"0\" onKeyUp=\"coutachat();\" onChange=\"coutachat();\"> 
    </tr>
    <tr style =\"background-color:#111111;\">
    <TD colspan=\"2\"><div name=\"achat\" id=\"achat\">Cout : 0 or</div></TD>
      <td  height=\"40\"><div align=\"right\">
      <input name=\"action\" type=\"hidden\" id=\"action\" value=\"achat\">
        <input type=\"submit\" name=\"Submit\" value=\"Acheter ces ressources\">
      </div></td>
    </tr>
  </table>
</form>";
      
      echo "</td>
    </tr>";
    
/*------------------------------Vente---------------------------*/
    echo"
    <tr style =\"background-color:#222222;\">
      <td align=\"center\"><b>Vente</b></td>
    </tr>";
    echo"<tr>
      <td align=\"center\"><br>";
      
echo "     <form name=\"form1\" method=\"post\" action=\"carrouf.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>
      <td height=\"39\"><div align=\"left\">Fer : 
        <input name=\"fer1\" type=\"text\" id=\"fer1\" value=\"0\" onKeyUp=\"coutvente();\" onChange=\"coutvente();\"> <a href=\"javascript:Maxi($newwfer_ressource,'fer1');coutvente();\"> Max </a>
      </td>
      <td height=\"42\">Cristal : 
        <input name=\"ada1\" type=\"text\" id=\"ada1\" value=\"0\" onKeyUp=\"coutvente();\" onChange=\"coutvente();\"> <a href=\"javascript:Maxi($newwada_ressource,'ada1');coutvente();\"> Max </a>
      </td>
      <td height=\"42\">Naquadah : 
      <input name=\"ura1\" type=\"text\" id=\"ura1\" value=\"0\" onKeyUp=\"coutvente();\" onChange=\"coutvente();\"> <a href=\"javascript:Maxi($newwura_ressource,'ura1');coutvente();\"> Max </a></td>
    </tr>
    <tr style =\"background-color:#111111;\">
    <TD colspan=\"2\"><div name=\"vente\" id=\"vente\">Gain : 0 or</div></TD>
      <td  height=\"40\"><div align=\"right\">
      <input name=\"action\" type=\"hidden\" id=\"action\" value=\"vente\">
        <input type=\"submit\" name=\"Submit\" value=\"Vendre ces ressources\">
      </div></td>
    </tr>
  </table>
</form>";
      
      echo "</td>
    </tr>";
    
    
    
    
    
    /*-------------------SCRIPT DE CALCUL-------------------------*/
    
    echo "<script type='text/javascript'>
function Maxi(maximum,input) {
  document.getElementsByName(input)[0].value = Math.round(maximum);
}
function coutachat() {
var total = 0; 
total+= Math.round(document.getElementById('fer').value)/$tauxfer;
total+= Math.round(document.getElementById('ura').value)/$tauxcristal;
total+= Math.round(document.getElementById('ada').value)/$tauxnaq;
couttrans=Math.round(total*".(1-$taux).");
total=Math.round(total+couttrans);
couleur=\"#009900\";
if (total > $newwor_ressource ) {
couleur=\"#FF0000\";
} 
if (total == 0 ) {
document.getElementById('achat').innerHTML = \"Cout : 0</font> or\";
} else{
  document.getElementById('achat').innerHTML = \"Cout : <font color=\"+couleur+\">\"+total+\"</font> or (dont \"+couttrans+\" or de taxe)\";
}
}
function coutvente() {
var total = 0; 
total+= Math.round(document.getElementById('fer1').value)/$tauxfer;
total+= Math.round(document.getElementById('ura1').value)/$tauxcristal;
total+= Math.round(document.getElementById('ada1').value)/$tauxnaq;
couttrans=Math.round(total*".(1-$taux).");
total=Math.round(total-couttrans);
couleur=\"#009900\";
if (total == 0 ) {
document.getElementById('vente').innerHTML = \"Gain : 0</font> or\";
} else{
  document.getElementById('vente').innerHTML = \"Gain : <font color=\"+couleur+\">\"+total+\"</font> or (dont \"+couttrans+\" or de taxe)\";
}
}
</script>";
 }else{
    echo"<tr>
      <td align=\"center\"><br>Vous devez disposer de la porte des étoiles pour utiliser
      un centre commercial...</td>
    </tr>"; 
    }


?>




