Commit 83f0b2d0 authored by diesys's avatar diesys 🎈

provando a risolvere il problema partite duplicate....

parent d6187c47
<?php
session_start();
// usando $_SESSION per prevenire il reinvio dei moduli $_POST
if (!isset($_SESSION)) {
session_start();
}
// if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// if ($_GET['refresh'] == 'true') {
// unset($_POST, $_SESSION, $_GET);
// header("Location: ".$_SERVER['PHP_SELF']);
// exit;
// }
// if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// $_SESSION['postdata'] = $_POST;
// unset($_POST['torneo'], $_SESSION['torneo']);
// header("Location: ".$_SERVER['PHP_SELF']);
// exit;
// }
$valid_passwords = array ("uova" => "frittata");
$valid_users = array_keys($valid_passwords);
......@@ -14,8 +30,12 @@
header('HTTP/1.0 401 Unauthorized');
die ("Not authorized");
}
// usando $_SESSION per prevenire il reinvio dei moduli $_POST
// if (isset($_GET['refresh'])) {
// header("Location: ".$_SERVER['PHP_SELF']);
// exit;
// }
?>
?>
......@@ -58,34 +78,40 @@
<h2 class="titleSection">Aggiungi partita</h2>
<center>
<form action="./admin.php" method="post">
<input type="hidden" name="torneo" value="singolo">
<div class="input-group input-padding">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">singolo</span>
</div>
<select class="custom-select" name="giocatore1" required>
<option value="" disabled selected>Giocatore 1</option>
<?php echo shell_exec('./tornelo.py -g singolo --web 2>&1'); ?>
</select>
<!-- <form action="./admin.php" method="post">
<input type="submit" name="refresh" value="FALSE">
</form> -->
<form action="./admin.php" method="post">
<input type="hidden" name="torneo" value="singolo">
<input type="hidden" name="refresh" value="false">
<div class="input-group input-padding">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">singolo</span>
</div>
<select class="custom-select" name="giocatore1" required>
<option value="" disabled selected>Giocatore 1</option>
<?php echo shell_exec('./tornelo.py -g singolo --web 2>&1'); ?>
</select>
<select class="custom-select" name="giocatore2" required>
<option value="" disabled selected>Giocatore 1</option>
<?php echo shell_exec('./tornelo.py -g singolo --web 2>&1'); ?>
</select>
<select class="custom-select col-2" id="inputGroupSelect02" name="esito" required>
<option disabled selected value="">esito</option>
<option value="1">1</option>
<option value="0">2</option>
</select>
<div class="input-group-append">
<button class="btn btn-outline-secondary bg-danger text-white bigFontButton" type="submit">
<ion-icon size="large" name="ios-add"></ion-icon>
</button>
</div>
</div>
<select class="custom-select" name="giocatore2" required>
<option value="" disabled selected>Giocatore 1</option>
<?php echo shell_exec('./tornelo.py -g singolo --web 2>&1'); ?>
</select>
<select class="custom-select col-2" id="inputGroupSelect02" name="esito" required>
<option disabled selected value="">esito</option>
<option value="1">1</option>
<option value="0">2</option>
</select>
<div class="input-group-append">
<button class="btn btn-outline-secondary bg-danger text-white bigFontButton btn-submit" type="submit">
<ion-icon size="large" name="ios-add"></ion-icon>
</button>
</div>
</div>
</form>
<form action="./admin.php" method="post">
......@@ -111,7 +137,7 @@
</select>
<div class="input-group-append">
<button class="btn btn-outline-secondary bg-danger text-white bigFontButton" type="submit">
<button class="btn btn-outline-secondary bg-danger text-white bigFontButton btn-submit" type="submit">
<ion-icon size="large" name="ios-add"></ion-icon>
</button>
</div>
......@@ -121,23 +147,40 @@
<?php
if(isset($_POST["giocatore1"]) and isset($_POST["giocatore2"]) and isset($_POST["torneo"]) and isset($_POST["esito"])) {
$torneo = $_POST["torneo"]; $g1 = $_POST["giocatore1"]; $g2 = $_POST["giocatore2"]; $esito = $_POST["esito"];
$_SESSION = $_POST;
$torneo = $_SESSION["torneo"]; $g1 = $_SESSION["giocatore1"]; $g2 = $_SESSION["giocatore2"]; $esito = $_SESSION["esito"];
// $_SESSION['refresh'] = $_POST['refresh'];
if ($g1==$g2 and $g1!=""){
?>
<div class="alert alert-danger" role="alert"> Un giocatore non può giocare contro se stesso.</div>
<?php } elseif ($torneo and $g1 and $g2 and $esito> -1){ ?>
<div class="alert alert-success" role="alert">
<div class="alert alert-success" role="alert">
<?php
if( isset($_SESSION)) {
echo "<strong>".$g1."</strong> vs <strong>".$g2."</strong> (".$esito.")<br/><ion-icon name='md-checkmark-circle-outline'></ion-icon> inserito nel torneo ".$torneo."!";
echo shell_exec("./tornelo.py -u $torneo \"$g1\" \"$g2\" $esito --web 2>&1"); echo "</div>";
// si assicura che all'aggiornamento della pagina non re-inserisca la partita
session_destroy();
}
// if( !isset($_POST['refresh']) ) {
// if( isset($_GET['refresh']) ) {
if( $_POST['refresh'] == 'false' ) {
}}?>
echo "<strong>".$g1."</strong> vs <strong>".$g2."</strong> (".$esito.")<br/><ion-icon name='md-checkmark-circle-outline'></ion-icon> sta per essere inserito nel torneo ".$torneo."!";
echo shell_exec("./tornelo.py -u $torneo \"$g1\" \"$g2\" $esito --web 2>&1");
// prevents duplicate form submit
// $_GET['refresh'] = intval($_GET['refresh']) + 1;
// echo "<div>".$_GET['refresh']. "</div>";
}}}?>
<!-- prevents duplicate form submit -->
<form action="./admin.php" method="post">
<input type="hidden" name="refresh" value="true">
<button class="btn btn-success" type="submit">Clicca qui per confermare</button>
</form>
<?php
echo "</div>";
?>
<h2 style="display:none" class="titleSection">Aggiungi giocatore</h2>
<form style="display:none" action="./admin.php" method="post">
......@@ -149,15 +192,15 @@
<option value="doppio">doppio</option>
</select>
<input type="text" class="form-control" name="nome" required placeholder="Nome">
<button class="btn btn-outline-secondary bg-danger text-white bigFontButton" type="submit">
<button class="btn btn-outline-secondary bg-danger text-white bigFontButton btn-submit" type="submit">
<ion-icon size="large" name="ios-add"></ion-icon>
</button>
</div>
</form>
<?php
if(isset($_POST["torneo"]) and isset($_POST["nome"])){
$torneo = $_POST["torneo"];
$nome = $_POST["nome"];
if(isset($_SESSION["torneo"]) and isset($_SESSION["nome"])){
$torneo = $_SESSION["torneo"];
$nome = $_SESSION["nome"];
$out = shell_exec("./tornelo.py -a $torneo $nome --web 2>&1");
if ($out ==""){ ?>
......@@ -236,6 +279,8 @@
<!-- ion-icons -->
<script src="https://unpkg.com/ionicons@4.5.5/dist/ionicons.js"></script>
<!-- <script src="js/jquery-3.4.1.min.js"></script> -->
<!-- <script src="js/script.js"></script> -->
</body>
</html>
This diff is collapsed.
// $(".btn-submit").on('click', function (event) {
// window.location.search += '?refresh=true';
// console.log('append');
// });
\ No newline at end of file
TODO
https://getbootstrap.com/docs/4.0/components/modal/
usare una modale per chiedere conferma e poi eseguire i comandi cosi si aggira pure il problema delle partite duplicate a causa della "memoria" di _POST (https://en.wikipedia.org/wiki/Post/Redirect/Get)
dannato php di merda
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment