77 lines
1.8 KiB
PHP
77 lines
1.8 KiB
PHP
<?php
|
|
|
|
function champs_cartes($nom, $titre) {
|
|
|
|
$nbCartes = 1;
|
|
|
|
if (isset($_POST[$nom])) {
|
|
$nbCartes = (int) $_POST[$nom];
|
|
}
|
|
|
|
echo '<select id="' . $nom . '" name="' . $nom . '">';
|
|
for ($i = 1; $i <= 5; $i++) {
|
|
echo '<option value="' . $i . '"';
|
|
if ($i == $nbCartes) {
|
|
echo ' selected';
|
|
}
|
|
echo '>' . $i . '</option>';
|
|
}
|
|
echo '</select>';
|
|
|
|
echo '<label for="' . $nom . '">' . $titre . '</label><br/>';
|
|
|
|
if (isset($_POST[$nom])) {
|
|
return (int) $_POST[$nom];
|
|
}
|
|
|
|
return (int) 0;
|
|
}
|
|
|
|
function afficher_formulaire() {
|
|
$total = 0;
|
|
|
|
echo '<form class="formulaire_partie" method="post" action="#">';
|
|
|
|
$total += champs_cartes('nbCartesVertes', 'Nombre de cartes vertes');
|
|
$total += champs_cartes('nbCartesOranges', 'Nombre de cartes oranges');
|
|
$total += champs_cartes('nbCartesNoires', 'Nombre de cartes noires');
|
|
|
|
|
|
if($total > 0) {
|
|
echo '<div>Total : ' . $total . '</div>';
|
|
if ($total > 10) {
|
|
echo '<div> Trop de cartes !!!!!!</div>';
|
|
} else {
|
|
echo '<input type="submit" name="creerPartie" value="Créer une partie" />';
|
|
}
|
|
}
|
|
|
|
echo '<input type="submit" name="validerCartes" value="Valider le nombre de cartes" />';
|
|
echo '</form>';
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
<div class="panneau_details">
|
|
|
|
<h2>Créer une partie</h2>
|
|
|
|
<?php
|
|
if (isset($_POST['creerPartie'])) {
|
|
$total = (int)$_POST['nbCartesVertes'] + (int)$_POST['nbCartesOranges'] + (int)$_POST['nbCartesNoires'];
|
|
if ($total <= 10) {
|
|
$res = creerPartie($_POST['nbCartesVertes'], $_POST['nbCartesOranges'], $_POST['nbCartesNoires']);
|
|
if($res === false){
|
|
echo "<div>Erreur lors de la création de la partie. Veuillez contacter l'administrateur</div>";
|
|
} else {
|
|
echo '<div>Partie en cours de création ...</div>';
|
|
}
|
|
} else {
|
|
afficher_formulaire();
|
|
}
|
|
} else {
|
|
afficher_formulaire();
|
|
}
|
|
?>
|
|
</div>
|