45 lines
1.8 KiB
PHP
45 lines
1.8 KiB
PHP
<?php
|
|
if(!defined('INDEX')) { header('Location: ../'); exit; }
|
|
$page = 'bourse';
|
|
$titre = 'Bourse';
|
|
|
|
if ($queryPlanetes[0]['id'] != $queryPlanete['id']) {
|
|
$template->assign('message','Vous devez être sur votre planète mère pour utilisez la bourse.');
|
|
$template->assign('couleur','red');
|
|
$template->display('game/erreur.tpl');
|
|
exit;
|
|
}
|
|
else {
|
|
$a = gpc('a');
|
|
$nb = gpc('a'.$a, 'post');
|
|
if (!empty($a) && is_numeric($nb) && $nb < 1000) {
|
|
$bdd->connexion();
|
|
$bdd->escape($a);
|
|
$bdd->escape($nb);
|
|
$action = $bdd->unique_query("SELECT FLOOR(B.metal/SUM(A.nombre)) AS metal, FLOOR(B.cristal/SUM(A.nombre)) AS cristal FROM $table_bourse B JOIN $table_bourse_actions A ON B.id = A.id_action WHERE B.id = $a GROUP BY A.id_action;");
|
|
$bdd->deconnexion();
|
|
$metal -= $action['metal']*$nb;
|
|
$cristal -= $action['cristal']*$nb;
|
|
if ($metal < 0 || $cristal < 0) {
|
|
$template->assign('message','Vous n\'avez pas assez de ressource pour acheter ces actions.');
|
|
$template->assign('couleur','red');
|
|
$template->display('game/erreur.tpl');
|
|
exit;
|
|
}
|
|
$bdd->connexion();
|
|
$bdd->query("UPDATE $table_planete SET metal = $metal, cristal = $cristal WHERE id = $idPlan;");
|
|
$bdd->query("INSERT INTO $table_bourse_actions (id_user, id_action, nombre) VALUES ($id_user, $a, $nb);");
|
|
$bdd->deconnexion();
|
|
header('Location: ?p=bourse');
|
|
exit;
|
|
}
|
|
else {
|
|
$bdd->connexion();
|
|
$bourse = $bdd->query("SELECT B.id, B.nom, SUM(U.nombre) AS nbactions, FLOOR(SUM(A.nombre)/B.metal) AS metal, FLOOR(SUM(A.nombre)/B.cristal) AS cristal, B.last_nombre, FLOOR(((SUM(A.nombre)/B.last_nombre)-1)*100) AS evolution FROM $table_bourse B INNER JOIN $table_bourse_actions A ON B.id = A.id_action INNER JOIN $table_bourse_actions U ON B.id = U.id_action AND U.id_user = $id_user GROUP BY A.id_action;");
|
|
$bdd->deconnexion();
|
|
}
|
|
|
|
|
|
$template->assign('bourse', $bourse);
|
|
}
|
|
?>
|