second commit
This commit is contained in:
parent
d975e212f9
commit
12d8e33009
9 changed files with 266 additions and 0 deletions
8
similverifica_votazioni_atleti/includes/footer.php
Normal file
8
similverifica_votazioni_atleti/includes/footer.php
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
|
||||||
|
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script>
|
||||||
|
Fancybox.bind("[data-fancybox]", {
|
||||||
|
// Your custom options
|
||||||
|
});
|
||||||
|
</script>
|
7
similverifica_votazioni_atleti/includes/head.php
Normal file
7
similverifica_votazioni_atleti/includes/head.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||||
|
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0/dist/fancybox/fancybox.umd.js"></script>
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0/dist/fancybox/fancybox.css"
|
||||||
|
/>
|
32
similverifica_votazioni_atleti/includes/navbar.php
Normal file
32
similverifica_votazioni_atleti/includes/navbar.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<nav class="navbar navbar-expand-lg bg-light">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<a class="navbar-brand" href="#">Facebook 2</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
|
||||||
|
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link active" aria-current="page" href="home.php">Home</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="amici.php">Amici</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="foto.php">Foto</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item d-flex me-2">
|
||||||
|
<a class="nav-link" href="logout.php">Logout</a>
|
||||||
|
</li>
|
||||||
|
<?php
|
||||||
|
if (isset($_SESSION['admin']) && $_SESSION['admin']) {
|
||||||
|
echo '<li class="nav-item">
|
||||||
|
<a class="nav-link" href="upload.php">Admin</a>
|
||||||
|
</li>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
42
similverifica_votazioni_atleti/includes/security.php
Normal file
42
similverifica_votazioni_atleti/includes/security.php
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
function checkPost()
|
||||||
|
{
|
||||||
|
unset($_SESSION["error"]);
|
||||||
|
|
||||||
|
if (empty($_POST["nome"]) || empty($_POST["eta"]) || empty($_POST["sesso"])) {
|
||||||
|
$_SESSION["error"] = "Dati mancanti";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_POST["eta"] < 18) {
|
||||||
|
$_SESSION["error"] = "Devi avere 18 anni per entrare";
|
||||||
|
}
|
||||||
|
|
||||||
|
header("Location: login.php");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkSession()
|
||||||
|
{
|
||||||
|
if (empty($_SESSION["nome"]) || empty($_SESSION["code"]) || empty($_SESSION["film"]) || empty($_SESSION["voto"])) {
|
||||||
|
$_SESSION["error"] = true;
|
||||||
|
header("Location: login.php");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkHasVoted()
|
||||||
|
{
|
||||||
|
if (isset($_COOKIE["hasVoted"]) && $_COOKIE["hasVoted"]) {
|
||||||
|
$_SESSION["error"] = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addVote($film, $vote)
|
||||||
|
{
|
||||||
|
global $votes;
|
||||||
|
$votes[$film] += $vote;
|
||||||
|
file_put_contents("votes.json", json_encode($votes));
|
||||||
|
}
|
45
similverifica_votazioni_atleti/index.php
Normal file
45
similverifica_votazioni_atleti/index.php
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
include "includes/security.php";
|
||||||
|
|
||||||
|
checkPost();
|
||||||
|
?>
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html lang="it">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Login</title>
|
||||||
|
<?php require "includes/head.php" ?>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Vota Atleti</h1>
|
||||||
|
<h2>Ciao <?php echo $_SESSION["nome"] ?></h2>
|
||||||
|
<form action="thanks.php" method="post">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="atleta" class="form-label">Atleta</label>
|
||||||
|
<select class="form-select" name="atleta" id="atleta">
|
||||||
|
<option value="1">Usain Bolt</option>
|
||||||
|
<option value="2">Michael Phelps</option>
|
||||||
|
<option value="3">Simone Biles</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="voto" class="form-label">Voto</label>
|
||||||
|
<select class="form-select" name="voto" id="voto">
|
||||||
|
<option value="1">1</option>
|
||||||
|
<option value="2">2</option>
|
||||||
|
<option value="3">3</option>
|
||||||
|
<option value="4">4</option>
|
||||||
|
<option value="5">5</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary">Invia voto</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php require "includes/footer.php" ?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
48
similverifica_votazioni_atleti/login.php
Normal file
48
similverifica_votazioni_atleti/login.php
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?php require "includes/security.php" ?>
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html lang="it">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Login</title>
|
||||||
|
<?php require "includes/head.php" ?>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h1>Login</h1>
|
||||||
|
<h3><a href="statistics.php">Statistiche</a></h3>
|
||||||
|
<?php
|
||||||
|
if (isset($_SESSION["error"])) {
|
||||||
|
?>
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
<?php echo $_SESSION["error"] ?>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
session_destroy();
|
||||||
|
?>
|
||||||
|
<form action="index.php" method="post">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="nome" class="form-label">Nome</label>
|
||||||
|
<input type="text" class="form-control" id="nome" name="nome">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="eta" class="form-label">Età</label>
|
||||||
|
<input type="number" class="form-control" id="eta" name="eta"/>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="sesso" class="form-label">Sesso</label>
|
||||||
|
<select class="form-select" name="sesso" id="sesso">
|
||||||
|
<option value="m">M</option>
|
||||||
|
<option value="f">F</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary">Invia voto</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php require "includes/footer.php" ?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
49
similverifica_votazioni_atleti/statistics.php
Normal file
49
similverifica_votazioni_atleti/statistics.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
global $votes;
|
||||||
|
include "includes/security.php";
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html lang="it">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Login</title>
|
||||||
|
<?php require "includes/head.php" ?>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h1>Statistiche dei voti</h1>
|
||||||
|
<canvas id="statistiche"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php require "includes/footer.php" ?>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const ctx = document.getElementById('statistiche');
|
||||||
|
|
||||||
|
new Chart(ctx, {
|
||||||
|
type: 'bar',
|
||||||
|
data: {
|
||||||
|
labels: ['Avengers', 'Wall-E', 'Napoleon'],
|
||||||
|
datasets: [{
|
||||||
|
label: '# of Votes',
|
||||||
|
data: [<?= $votes["avengers"] ?>, <?= $votes["walle"] ?>, <?= $votes["napoleon"] ?>,],
|
||||||
|
borderWidth: 1
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
scales: {
|
||||||
|
y: {
|
||||||
|
beginAtZero: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
34
similverifica_votazioni_atleti/thanks.php
Normal file
34
similverifica_votazioni_atleti/thanks.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
include "includes/security.php";
|
||||||
|
|
||||||
|
checkSession();
|
||||||
|
|
||||||
|
if (!isset($_COOKIE["hasVoted"])) {
|
||||||
|
setcookie("hasVoted", true, time() + 60, "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
addVote($_SESSION["film"], $_SESSION["voto"]);
|
||||||
|
|
||||||
|
session_destroy();
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html lang="it">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Login</title>
|
||||||
|
<?php require "includes/head.php" ?>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h1>Grazie per aver votato</h1>
|
||||||
|
<h2>Per controllare i voti controlla la pagina <a href="statistics.php">statistiche</a></h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php require "includes/footer.php" ?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
1
similverifica_votazioni_atleti/votes.json
Normal file
1
similverifica_votazioni_atleti/votes.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{}
|
Loading…
Add table
Reference in a new issue