first commit

This commit is contained in:
Bildcraft1 2024-10-31 10:47:12 +01:00
commit d975e212f9
35 changed files with 813 additions and 0 deletions

View 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>

View 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"
/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

View 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>

View file

@ -0,0 +1,42 @@
<?php
session_start();
$votes = json_decode(file_get_contents("votes.json"), true);
function checkPost()
{
if (empty($_POST["nome"]) || empty($_POST["code"]) || empty($_POST["film"]) || empty($_POST["voto"])) {
$_SESSION["error"] = true;
header("Location: login.php");
exit();
}
if (trim($_POST["code"]) !== "a123") {
$_SESSION["error"] = true;
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));
}

44
similverifica/index.php Normal file
View file

@ -0,0 +1,44 @@
<?php
include "includes/security.php";
checkPost();
$_SESSION["nome"] = $_POST["nome"];
$_SESSION["code"] = $_POST["code"];
$_SESSION["film"] = $_POST["film"];
$_SESSION["voto"] = $_POST["voto"];
?>
<!DOCTYPE HTML>
<html lang="it">
<head>
<title>Login</title>
<?php require "includes/head.php" ?>
</head>
<body>
<?php if (checkHasVoted()) { ?>
<div class="container">
<h1>Conferma Voto</h1>
<h2>Nome utente: <?php echo $_SESSION["nome"] ?></h2>
<h2>Film: <?php echo $_SESSION["film"] ?></h2>
<h2>Voto: <?php echo $_SESSION["voto"] ?></h2>
<form action="thanks.php" method="post">
<div class="mb-3">
<label for="nome" class="form-label">Vuoi confermare il voto?</label>
<button type="submit" class="btn btn-primary">Invia voto</button>
</div>
</form>
</div>
<?php } else { ?>
<script>
alert("Hai già votato, non puoi votare una seconda volta")
window.location.href = "login.php"
</script>
<?php } ?>
<?php require "includes/footer.php" ?>
</body>
</html>

64
similverifica/login.php Normal file
View file

@ -0,0 +1,64 @@
<?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">
Errore! Riprova
</div>
<?php }
session_destroy();
?>
<form action="index.php" method="post">
<div class="mb-3">
<label for="nome" class="form-label">Nome Utente</label>
<input type="text" class="form-control" id="nome" name="nome">
</div>
<div class="mb-3">
<label for="nome" class="form-label">Codice di accesso</label>
<input type="password" class="form-control" id="code" name="code">
</div>
<div class="mb-3">
<figure class="figure">
<img src="includes/imgs/avengers.jpg" class="figure-img img-fluid rounded" alt="...">
<figcaption class="figure-caption">A caption for the above image.</figcaption>
</figure>
<figure class="figure">
<img src="includes/imgs/walle.jpg" class="figure-img img-fluid rounded" alt="...">
<figcaption class="figure-caption">A caption for the above image.</figcaption>
</figure>
<figure class="figure">
<img src="includes/imgs/napoleon.jpg" class="figure-img img-fluid rounded" alt="...">
<figcaption class="figure-caption">A caption for the above image.</figcaption>
</figure>
</div>
<label for="film">Seleziona il fim da votare:</label>
<select name="film" id="film">
<option value="avengers">avengers</option>
<option value="walle">walle</option>
<option value="napoleon">napoelon</option>
</select>
<input type="number" id="voto" name="voto" min="1" max="5"/>
<button type="submit" class="btn btn-primary">Invia voto</button>
</form>
</div>
<?php require "includes/footer.php" ?>
</body>
</html>

View 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/thanks.php Normal file
View 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/votes.json Normal file
View file

@ -0,0 +1 @@
{"avengers":9,"walle":2,"napoleon":3}