1
0
This commit is contained in:
2022-10-19 15:51:41 +02:00
parent e89dcf2cc7
commit 7422d5c89b
9 changed files with 173 additions and 119 deletions

View File

@ -14,6 +14,7 @@ define( "DATE_MYSQL", "Y-m-d H:i:s" );
//environment variables
$admin = "dtux@free.fr";
$dolibarrAdmin = "dtartavel";
$webmaster = "contact@lalis.fr";
$site = "Lalis";
$dossier = "/sftp";

View File

@ -79,12 +79,13 @@ class dbcore
function vote($idVotation, $idVotant, $idVote, $idCandidat)
{
$flag = 0;
$query='SELECT IF(identifiant="' . $idVotant . '" AND idVotation="' . $idVotation .'" AND INSTR(idVote, "' . $idVote .'"),TRUE,FALSE) as r FROM liste_votants';
/*$query='SELECT IF(identifiant="' . $idVotant . '" AND idVotation="' . $idVotation .'" AND INSTR(idVote, "' . $idVote .'"),TRUE,FALSE) as r FROM liste_votants';
$this->query($query);
if ( ($r = $this->result->fetch_array(MYSQLI_ASSOC)))
{
{*/
$query='SELECT IF ( id="' . $idVotation .'",TRUE,FALSE) as r FROM liste_votations';
$this->query($query);
echo "resultat " . $r . EOLH;
if ( ($r = $this->result->fetch_array(MYSQLI_ASSOC)))
{
$query='SELECT IF( idVotation="' . $idVotation .'" AND id="' . $idVote .'",TRUE,FALSE) as r FROM liste_votes';
@ -98,21 +99,118 @@ class dbcore
$query='INSERT INTO votes (idVotant, idVotation, idVote, idCandidat) VALUES ("' . $this->protect($idVotant) .'", "' . $this->protect($idVotation) .'", "' . $this->protect($idVote) .'", "'. $this->protect($idCandidat) .'")';
$error = $this->query($query);
return $error;
}else
{
$error = "Le candidat n'existe pas" . EOLH;
}
}else
{
$error= "La votation ou le vote n'existe pas" . EOLH;
}
}
}
return 'Error ';
//}
return $error;
}
function resultat()
function resultats($idVotation)
{
for($i=1;i>$n;$n++)
$query = 'SELECT *, UNIX_TIMESTAMP(DATE_ADD(dateFin, INTERVAL 1 DAY)) as tf FROM liste_votations WHERE id = ' . $this->protect($idVotation);
$result = $this->query($query);
$votation = $this->result->fetch_array(MYSQLI_ASSOC);
if ($result === FALSE)
{
$query='SELECT idVotant, COUNT(value) as resultat FROM lalis_vote WHERE value="' . $value . '" AND idVote="' . $i . '" ';
print "Votation non trouvée" . EOLH;
}else
{
$now = date('Y-m-d');
if ( time() > $votation['tf'] )
{
echo $votation["libelle"] . "</h4>";
$listeAdherents = listeAdherents();
print (' <hr class="star-primary">
</div>
</div>
<div class="row">');
$query='SELECT * FROM liste_votes WHERE idVotation="' .$this->protect( $idVotation) .'"';
$result = $this->query($query);
$votes = $this->result->fetch_all(MYSQLI_ASSOC);
foreach ($votes as $vote)
{
switch ($vote["methode"])
{
case 1:
$total = 0;
echo "<div><h5>" . $vote["libelle"] . "</h5><br>";
$query='SELECT * FROM liste_candidats WHERE idVotation=' . $idVotation . ' AND idVote=' . $vote["id"];
$result = $this->query($query);
$candidats = $this->result->fetch_all(MYSQLI_ASSOC);
echo "<pre>";
//$resultatCandidats = '';
$query='SELECT COUNT(*) as n FROM votes WHERE idVotation=' . $this->protect($idVotation) . ' AND idVote=' . $vote["id"] .' AND idCandidat=0';
$result = $this->query($query);
$resultat = $this->result->fetch_array(MYSQLI_ASSOC);
$blanc = $resultat["n"];
echo 'Votes blancs&nbsp;: ' . $blanc . '<br>';
foreach($candidats as $candidat)
{
$query='SELECT COUNT(*) as n FROM votes WHERE idVotation=' . $this->protect($idVotation) . ' AND idVote=' . $vote["id"] .' AND idCandidat=' . $candidat["id"];
$result = $this->query($query);
$resultat = $this->result->fetch_array(MYSQLI_ASSOC);
echo $candidat["candidat"] . '&nbsp;:' . $resultat["n"] . '<br>';
$resultatCandidats[$candidat['candidat']] = $resultat["n"];
$total += $resultat["n"];
}
array_multisort($resultatCandidats, SORT_DESC, SORT_NUMERIC);
reset($resultatCandidats);
if ($total != 0)
{
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>");
}
listeVotants($idVotation, $vote["id"], $listeAdherents);
}else
{
print("<h5>Aucun votant, le vote est annulé.</h5>");
}
print("</pre></div><br>" . EOLH);
break;
default:
break;
}
}
}else
{
print "Bonjour, vous pourrez consulter les résultats à partir du " . formattedate('fr', $votation['tf'] , "Europe/Paris") . "</h4>";
}
}
}
function liste_votants($idVotation)
{
$query = 'SELECT DISTINCT idVotant FROM liste_votes WHERE idVotation=' . $idVotation;
$this->query($query);
$votants = $this->result->fetch_all(MYSQLI_ASSOC);
$doliDB = new dbDolibarr();
foreach($votants as $votant)
{
$query ="SELECT login, firstname, lastname FROM llx_adherent WHERE login='" . $votant . "'";
$dolibarr->query($query);
$r = mysqli_fetch_array();
$listeVotants[$votant]["nom"] = $r["lastname"];
$listeVotants[$votant]["prenom"] = $r["firstname"];
}
return $listeVotants;
}
function queryVotationList()
{
$query = "SELECT * FROM liste_votations";

View File

@ -248,7 +248,7 @@ function listeVotants($idVotation, $idVote, $listeAdherents)
{
$nv = 0;
$text = '';
$db = new db();
$db->open();
$query = "SELECT DISTINCT idVotant FROM votes WHERE idVotation=" . $idVotation . ' AND idVote=' . $idVote;