1
0
This repository has been archived on 2023-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
dtux__serveur-vote-lalis/vote.resultat.php
Daniel Tartavel df07673a67 first commit
2021-10-14 17:58:21 +02:00

85 lines
2.3 KiB
PHP

<?php
require_once 'session_init.php';
require_once 'config.inc.php';
require_once 'db.class.php';
require_once 'entete.html';
$idVotation = $_GET["id"];
$db = new db();
if ( empty($idVotation))
{
choixVotation('/vote.resultat.php');
}else
{
print(' <br><br>
<!-- lalis Grid Section -->
<section id="content">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h3>VOTE</h3>
<h4>');
$query = 'SELECT *, UNIX_TIMESTAMP(dateFin) as tf FROM liste_votations WHERE id=' . $db->protect($idVotation);
$result = $db->query($query);
$votation = $db->result->fetch_array(MYSQLI_ASSOC);
if ($result === FALSE)
{
print "Votation non trouvée" . EOLH;
}else
{
$now = date('Y-m-d');
if ( time() < $votation['tf'] )
{
echo $votation["libelle"] . "</h4>";
print (' <hr class="star-primary">
</div>
</div>
<div class="row">');
$query='SELECT * FROM liste_votes WHERE idVotation="' .$db->protect( $idVotation) .'"';
$result = $db->query($query);
$votes = $db->result->fetch_all(MYSQLI_ASSOC);
foreach ($votes as $vote)
{
echo "<div><h5>" . $vote["libelle"] . "</h5><br>";
$query='SELECT * FROM liste_candidats WHERE idVotation=' . $idVotation . ' AND idVote=' . $vote["id"];
$result = $db->query($query);
$candidats = $db->result->fetch_all(MYSQLI_ASSOC);
echo "<pre>";
//$resultatCandidats = '';
foreach($candidats as $candidat)
{
$query='SELECT COUNT(*) as n FROM votes WHERE idVotation=' . $db->protect($idVotation) . ' AND idVote=' . $vote["id"] .' AND idCandidat=' . $candidat["id"];
$result = $db->query($query);
$resultat = $db->result->fetch_array(MYSQLI_ASSOC);
echo $candidat["candidat"] . '&nbsp;:' . $resultat["n"] . '<br>';
$resultatCandidats[$candidat['candidat']] = $resultat["n"];
}
array_multisort($resultatCandidats, SORT_DESC, SORT_NUMERIC);
reset($resultatCandidats);
print("<h5>Remporte le vote : " . key($resultatCandidats));
unset($resultatCandidats);
print "</h5></pre>
</div><br>";
}
}else
{
print "Bonjour, vous pourrez consulter les résultats après la clôture du vote le " . formattedate('fr', $votation['tf'] , "Europe/Paris") . "</h4>";
}
}
print (' <div>
</div>
</div>
</div>
</section>');
}
require_once 'footer.html';
?>