diff --git a/connect.php b/connect.php index 6332568..a68da12 100644 --- a/connect.php +++ b/connect.php @@ -21,11 +21,15 @@ session_start(); +// Credenziali database $host = 'localhost'; $user = 'vincenzopadula'; $database = 'my_vincenzopadula'; $psw = ''; +// Password di amministratore +define("ADMIN_PW", "abcd"); + define("PREFIX", "tombola_k_"); $dbh = mysqli_connect($host, $user, $psw, $database); @@ -68,4 +72,25 @@ function is_a_username($username = null) { if($username == null || $username == "") return false; return preg_match("/^[a-zA-Z0-9_.-]{2,20}$/", $username); } + +function adminLogin($msg = "Password di amministratore") { + // La password è stata inserita? + if(! isset($_POST['admin_pw'])) { + echo "
$msg
\n". + "\n"; + return false; + } + + if($_POST['admin_pw'] != ADMIN_PW) { + echo "Password errata.
\n". + "\n"; + return false; + } + + return true; +} ?> diff --git a/reset.php b/reset.php new file mode 100644 index 0000000..a14e297 --- /dev/null +++ b/reset.php @@ -0,0 +1,40 @@ +. +*/ + +$title = "Reset"; +include("page_header.php"); + +if(adminLogin("Reset del database")) { + + // Reset delle tabelle + $query = "TRUNCATE ".PREFIX."avere; TRUNCATE ".PREFIX."estrarre; TRUNCATE ".PREFIX."server; TRUNCATE ".PREFIX."utente; TRUNCATE ".PREFIX."vincere;"; + $result = mysqli_multi_query($dbh, $query); + if($result) { + echo "Il database è ora vuoto.
"; + } else { + echo "La query ha restituito un errore.
"; + } + + echo ""; +} + +include("page_footer.php"); +?> diff --git a/stats.php b/stats.php new file mode 100644 index 0000000..adbd2c7 --- /dev/null +++ b/stats.php @@ -0,0 +1,65 @@ +. +*/ + +$title = "Statistiche"; +include("page_header.php"); + +if(adminLogin("Statistiche di gioco")) { + + // Partite non ancora iniziate + $query = "select count(*) n from ".PREFIX."server where accessibile is true"; + $result = mysqli_query($dbh, $query); + if(mysqli_num_rows($result) == 1) { + $notYetStarted = (mysqli_fetch_array($result))["n"]; + } else die("Errore query."); + + // Partite in corso + $query = "select count(*) n from ".PREFIX."server where accessibile is false and terminato is null and offlimits is null"; + $result = mysqli_query($dbh, $query); + if(mysqli_num_rows($result) == 1) { + $running = (mysqli_fetch_array($result))["n"]; + } else die("Errore query."); + + // Partite terminate + $query = "select count(*) n from ".PREFIX."server where terminato is not null;"; + $result = mysqli_query($dbh, $query); + if(mysqli_num_rows($result) == 1) { + $ended = (mysqli_fetch_array($result))["n"]; + } else die("Errore query."); + + // Partite mai giocate + $query = "select count(*) n from ".PREFIX."server where terminato is null and offlimits is not null;"; + $result = mysqli_query($dbh, $query); + if(mysqli_num_rows($result) == 1) { + $neverPlayed = (mysqli_fetch_array($result))["n"]; + } else die("Errore query."); + + echo "Partite non ancora iniziate: | $notYetStarted |
Partite in corso: | $running |
Partite terminate: | $ended |
Partite mai giocate: | $neverPlayed |