100 lines
2.9 KiB
PHP
100 lines
2.9 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(DATE_ADD(dateFin, INTERVAL 1 DAY)) 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)
|
|
{
|
|
$total = 0;
|
|
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 = '';
|
|
|
|
$query='SELECT COUNT(*) as n FROM votes WHERE idVotation=' . $db->protect($idVotation) . ' AND idVote=' . $vote["id"] .' AND idCandidat=0';
|
|
$result = $db->query($query);
|
|
$resultat = $db->result->fetch_array(MYSQLI_ASSOC);
|
|
$blanc = $resultat["n"];
|
|
echo 'Votes blancs : ' . $blanc . '<br>';
|
|
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"] . ' :' . $resultat["n"] . '<br>';
|
|
$resultatCandidats[$candidat['candidat']] = $resultat["n"];
|
|
$total += $resultat["n"];
|
|
}
|
|
array_multisort($resultatCandidats, SORT_DESC, SORT_NUMERIC);
|
|
reset($resultatCandidats);
|
|
if ($total >= $blanc)
|
|
{
|
|
print("<h5>Remporte le vote : " . key($resultatCandidats));
|
|
unset($resultatCandidats);
|
|
print("</h5>");
|
|
}else
|
|
{
|
|
print("<h5>Aucun candidat n'emporte le vote, car il y a plus de 50% de votes blancs.</h5>");
|
|
}
|
|
|
|
print("</pre></div><br>");
|
|
}
|
|
}else
|
|
{
|
|
print "Bonjour, vous pourrez consulter les résultats à partir du " . formattedate('fr', $votation['tf'] , "Europe/Paris") . "</h4>";
|
|
}
|
|
}
|
|
|
|
|
|
print (' <div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>');
|
|
|
|
}
|
|
|
|
require_once 'footer.html';
|
|
?>
|