finished similverifica atleti
This commit is contained in:
parent
185f31601e
commit
ba05612a57
5 changed files with 74 additions and 12 deletions
|
@ -14,18 +14,36 @@ function createVotesDb()
|
|||
|
||||
if (empty($votes)) {
|
||||
$votes = [
|
||||
"Pellegrini" => 0,
|
||||
"Egonu" => 0,
|
||||
"Vio" => 0,
|
||||
"Totti" => 0,
|
||||
"Tamberi" => 0,
|
||||
"Rossi" => 0
|
||||
"voto_Pellegrini" => 0,
|
||||
"voto_Egonu" => 0,
|
||||
"voto_Vio" => 0,
|
||||
"voto_Totti" => 0,
|
||||
"voto_Tamberi" => 0,
|
||||
"voto_Rossi" => 0
|
||||
];
|
||||
file_put_contents("votes.json", json_encode($votes));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function addVote($votes, $sex)
|
||||
{
|
||||
// Add the vote to the counter
|
||||
if (strcmp($sex, 'M') == 0) {
|
||||
setcookie("votiMaschili", $_COOKIE['votiMaschili'] + 1, time() + 60 * 60 * 24 * 30);
|
||||
} else {
|
||||
setcookie("votiFemminili", $_COOKIE['votiFemminili'] + 1, time() + 60 * 60 * 24 * 30);
|
||||
}
|
||||
|
||||
foreach ($votes as $key => $value) {
|
||||
global $votes;
|
||||
$votes[$key] += $value;
|
||||
}
|
||||
|
||||
file_put_contents("votes.json", json_encode($votes));
|
||||
|
||||
}
|
||||
|
||||
function checkPost()
|
||||
{
|
||||
unset($_SESSION["error"]);
|
||||
|
@ -46,8 +64,8 @@ function checkPost()
|
|||
|
||||
function checkSession()
|
||||
{
|
||||
if (empty($_SESSION["nome"]) || empty($_SESSION["code"]) || empty($_SESSION["film"]) || empty($_SESSION["voto"])) {
|
||||
$_SESSION["error"] = true;
|
||||
if (empty($_SESSION["nome"]) || empty($_SESSION["sesso"])) {
|
||||
$_SESSION["error"] = "Errore interno (Sessione non trovata)";
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ include "includes/security.php";
|
|||
checkPost();
|
||||
|
||||
$_SESSION["nome"] = $_POST["nome"];
|
||||
$_SESSION["sesso"] = $_POST["sesso"];
|
||||
|
||||
if (!isset($_COOKIE["votiFemminili"])) {
|
||||
setcookie("votiFemminili", 0, time() + 60 * 60 * 24 * 30);
|
||||
|
@ -42,7 +43,6 @@ if (!isset($_COOKIE["votiMaschili"])) {
|
|||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Invia voti</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -17,6 +17,8 @@ include "includes/security.php";
|
|||
<div class="container">
|
||||
<h1>Statistiche dei voti</h1>
|
||||
<canvas id="statistiche"></canvas>
|
||||
<canvas id="statistichePC"></canvas>
|
||||
<canvas id='statisicheBrowser'></canvas>
|
||||
</div>
|
||||
|
||||
<?php require "includes/footer.php" ?>
|
||||
|
@ -24,14 +26,55 @@ include "includes/security.php";
|
|||
|
||||
<script>
|
||||
const ctx = document.getElementById('statistiche');
|
||||
const statsPC = document.getElementById('statistichePC');
|
||||
const statsBrowser = document.getElementById('statisicheBrowser');
|
||||
|
||||
new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: ['Avengers', 'Wall-E', 'Napoleon'],
|
||||
labels: ['Pellegrini', 'Egonu', 'Vio'],
|
||||
datasets: [{
|
||||
label: '# of Votes',
|
||||
data: [<?= $votes["avengers"] ?>, <?= $votes["walle"] ?>, <?= $votes["napoleon"] ?>,],
|
||||
data: [<?= $votes["voto_Pellegrini"] ?>, <?= $votes["voto_Egonu"] ?>, <?= $votes["voto_Vio"] ?>,],
|
||||
borderWidth: 1
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
new Chart(statsPC, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: ['Totti', 'Tamberi', 'Rossi'],
|
||||
datasets: [{
|
||||
label: '# of Votes',
|
||||
data: [<?= $votes["voto_Totti"] ?>, <?= $votes["voto_Tamberi"] ?>, <?= $votes["voto_Rossi"] ?>,],
|
||||
borderWidth: 1
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
new Chart(statsBrowser, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: ['Maschi', 'Femmine'],
|
||||
datasets: [{
|
||||
label: '# of Votes',
|
||||
data: [<?= $_COOKIE["votiMaschili"] ?>, <?= $_COOKIE["votiFemminili"] ?>],
|
||||
borderWidth: 1
|
||||
}]
|
||||
},
|
||||
|
|
|
@ -3,7 +3,7 @@ include "includes/security.php";
|
|||
|
||||
checkSession();
|
||||
|
||||
addVote($_SESSION["film"], $_SESSION["voto"]);
|
||||
addVote($_POST, strtoupper($_SESSION['sesso']));
|
||||
|
||||
session_destroy();
|
||||
?>
|
||||
|
|
1
similverifica_votazioni_atleti/votes.json
Normal file
1
similverifica_votazioni_atleti/votes.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"voto_Pellegrini":20,"voto_Egonu":20,"voto_Vio":20,"voto_Totti":16,"voto_Tamberi":17,"voto_Rossi":13}
|
Loading…
Add table
Reference in a new issue