Liste des candidats
'); foreach($candidatsList as $line) { - print("" . $line["candidat"] . ""); print(nl2br($line["libelle"]) . EOLH); + print("" . $line["candidat"] . "
"); } } candidatsForm($path, $idVotation, $idVote); diff --git a/include/config.inc.php b/include/config.inc.php index 828e80f..0566462 100644 --- a/include/config.inc.php +++ b/include/config.inc.php @@ -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"; diff --git a/include/db.class.php b/include/db.class.php index 50487ac..12c5a3d 100644 --- a/include/db.class.php +++ b/include/db.class.php @@ -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"] . ""; + $listeAdherents = listeAdherents(); + print ('
+ + +
" . $vote["libelle"] . "
"; + $query='SELECT * FROM liste_candidats WHERE idVotation=' . $idVotation . ' AND idVote=' . $vote["id"]; + $result = $this->query($query); + $candidats = $this->result->fetch_all(MYSQLI_ASSOC); + echo "
"; + //$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 : ' . $blanc . '
'; + 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"] . ' :' . $resultat["n"] . '
'; + $resultatCandidats[$candidat['candidat']] = $resultat["n"]; + $total += $resultat["n"]; + } + array_multisort($resultatCandidats, SORT_DESC, SORT_NUMERIC); + reset($resultatCandidats); + if ($total != 0) + { + if ($total >= $blanc) + { + print("Remporte le vote : " . key($resultatCandidats)); + unset($resultatCandidats); + print("
"); + }else + { + print("Aucun candidat n'emporte le vote, car il y a plus de 50% de votes blancs.
"); + } + listeVotants($idVotation, $vote["id"], $listeAdherents); + }else + { + print("Aucun votant, le vote est annulé.
"); + } + print("
" . EOLH); + break; + default: + break; + } + } + }else + { + print "Bonjour, vous pourrez consulter les résultats à partir du " . formattedate('fr', $votation['tf'] , "Europe/Paris") . ""; + } } } + 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"; diff --git a/include/fonctions.inc.php b/include/fonctions.inc.php index f864efb..144ca1c 100644 --- a/include/fonctions.inc.php +++ b/include/fonctions.inc.php @@ -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; diff --git a/vote.form.php b/vote.form.php index 06c5d3d..6bce81c 100644 --- a/vote.form.php +++ b/vote.form.php @@ -5,14 +5,15 @@ require_once 'config.inc.php'; require_once 'db.class.php'; require_once "log.php"; require_once 'entete.php'; +require_once 'fonctions.inc.php'; -$idVotant = trim(base64_decode(urldecode($_GET["id"])), " \n\r"); -$idVotation = $_GET["v"]; +$idVotant = trim(base64_decode(urldecode(getpost("id")), " \n\r")); +$idVotation = getpost("v"); $dolibarr = new dbDolibarr(); $query = "SELECT * FROM llx_adherent as a LEFT JOIN llx_adherent_type as t ON a.fk_adherent_type=t.rowid WHERE a.login='" . $dolibarr->protect($idVotant) . "' AND (DATE(a.datefin)>=CURDATE() OR t.subscription=0) AND t.vote=1"; -print $query . EOLH; +//print $query . EOLH; $result = $dolibarr->query($query); //print_r($dolibarr); $votant = $dolibarr->result->fetch_array(); @@ -46,7 +47,7 @@ if ($dolibarr->result->num_rows == 0) { if ( time() >= $votation['td'] AND time() <= $votation['tf'] ) { - $query = "SELECT * FROM votes WHERE idVotant='" . $db->protect($idVotant) ."'"; + $query = "SELECT * FROM votes WHERE idVotant='" . $db->protect($idVotant) ."' AND idVotation=" . $idVotation; $db->query($query); if ($db->result->num_rows == 0) { @@ -70,8 +71,9 @@ if ($dolibarr->result->num_rows == 0) echo "
"; foreach($candidats as $candidat) { - echo ' ' . $candidat["candidat"] . 'diff --git a/vote.php b/vote.php index 2807006..8575c7e 100644 --- a/vote.php +++ b/vote.php @@ -8,6 +8,30 @@ if (array_key_exists("id", $_GET)) $idVotant = $_GET["id"]; if (array_key_exists("v", $_GET)) $votation = $_GET["v"]; if (array_key_exists("vote", $_GET)) $vote = $_GET["vote"]; +function voter($idVotant, $votation, $vote) +{ + foreach ($vote as $key => $value) + { + $result = $db->vote($votation, $idVotant, $key, $value ); + if ($result == '') + { + $idVote = array_search($key, array_column($listeVotes, 'id')); + echo '
'; echo nl2br($candidat["libelle"]) . EOLH; + echo ' ' . $candidat["candidat"] . '
'; + } echo ' Vote blanc
'; print "
' . $listeVotes[$idVote]['libelle'] . ' : vote pris en compte
' .EOLH; + log_write($idVotant . ' a voté'); + }else + { + print ('ERREUR: vote non pris en compte
') . EOLH; + if (strpos($result, 'Duplicate') !== false) + { + print ("L'erreur est normale si vous avez essayé de recharger la page");
+ }
+ print("Adressez-vous aux responsables de l'association, ils ont déjà été averti de l'erreur
" . EOLH);
+ log_error( "vote non pris en compte : idVotant=$idVotant, id_Votation=$votation, key=$key, value=$value");
+ }
+ //echo "$key => $value";
+ }
+}
+
$db = new db();
print('
@@ -23,26 +47,18 @@ $query = 'SELECT * FROM liste_votes WHERE idVotation="' . $db->protect( $votatio
$result = $db->query($query);
$listeVotes = $db->result->fetch_all(MYSQLI_ASSOC);
-foreach ($vote as $key => $value)
-{
- $result = $db->vote($votation, $idVotant, $key, $value );
+voter($idVotant, $votation, $vote);
- if ($result == '')
+$query = "SELECT idprocurant FROM procurations WHERE idvotant='" . $db->protect(idVotant) . "' AND idvotation=" . $db->protect(idVotation);
+$result = $db->query($query);
+$listProcurants = $db->result->fetch_all(MYSQLI_ASSOC);
+
+if (count($listProcurants) != 0)
+{
+ foreach($listProcurants as $procurant)
{
- $idVote = array_search($key, array_column($listeVotes, 'id'));
- echo '' . $listeVotes[$idVote]['libelle'] . ' : vote pris en compte
' .EOLH;
- log_write($idVotant . ' a voté');
- }else
- {
- print ('ERREUR: vote non pris en compte
') . EOLH;
- if (strpos($result, 'Duplicate') !== false)
- {
- print ("L'erreur est normale si vous avez essayé de recharger la page");
- }
- print("Adressez-vous aux responsables de l'association, ils ont déjà été averti de l'erreur
" . EOLH);
- log_error( "vote non pris en compte : idVotant=$idVotant, id_Votation=$votation, key=$key, value=$value");
+ voter($procurant, $votation, $vote);
}
- //echo "$key => $value";
}
$db->close();
print('
Adressez-vous aux responsables de l'association, ils ont déjà été averti de l'erreur
" . EOLH); - log_error( "vote non pris en compte : idVotant=$idVotant, id_Votation=$votation, key=$key, value=$value"); + voter($procurant, $votation, $vote); } - //echo "$key => $value"; } $db->close(); print('VOTE
'); - - $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"] . "
"; - $listeAdherents = listeAdherents(); - print ('- - -
" . $vote["libelle"] . "
"; - $query='SELECT * FROM liste_candidats WHERE idVotation=' . $idVotation . ' AND idVote=' . $vote["id"]; - $result = $db->query($query); - $candidats = $db->result->fetch_all(MYSQLI_ASSOC); - echo "
"; - //$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 . '
'; - 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"] . '
'; - $resultatCandidats[$candidat['candidat']] = $resultat["n"]; - $total += $resultat["n"]; - } - array_multisort($resultatCandidats, SORT_DESC, SORT_NUMERIC); - reset($resultatCandidats); - if ($total >= $blanc) - { - print("Remporte le vote : " . key($resultatCandidats)); - unset($resultatCandidats); - print("
"); - }else - { - print("Aucun candidat n'emporte le vote, car il y a plus de 50% de votes blancs.
"); - } - listeVotants($idVotation, $vote["id"], $listeAdherents); - print("
" . EOLH); - break; - default: - break; - } - } - }else - { - print "Bonjour, vous pourrez consulter les résultats à partir du " . formattedate('fr', $votation['tf'] , "Europe/Paris") . ""; - } - } - - print ('