1
0

added saisie votes et candidats

This commit is contained in:
Daniel Tartavel 2022-09-25 23:06:35 +02:00
parent 461cd822c3
commit c699108e65
4 changed files with 102 additions and 20 deletions

View File

@ -0,0 +1,46 @@
<?php
require_once '../session_init.php';
require_once 'config.inc.php';
require_once 'db.class.php';
require_once 'fonctions.inc.php';
$path = $_SERVER["PHP_SELF"];
$db = new db();
$idVotation = getpost("idVotation");
$idVote = getpost("idVote");
$candidat = getpost("candidat");
if (!empty($idCandidat))
{
$query = "INSERT INTO liste_candidats VALUES (0, " . $idVotation . ", " . $idVote . ",'" . $candidat . "')";
$db->query($query);
header("Location: " . $$base_url . "/" . $path , TRUE, 301);
return;
}else
{
require_once 'entete.php';
print('<br><br>
<!-- lalis Grid Section -->
<section id="content">
<div class="container">') . EOL;
print(' <div class="row">
<div class="col-lg-12 text-center">');
if (empty($idVotation))
{
choixVotation($path, 0, false);
}elseif (empty($idVote))
{
choixVote($path, $idVotation);
}
print(' </div>
</div>
</div>
</section>');
require_once("footer.html");
}
$db->close();
?>;

View File

@ -7,8 +7,6 @@ require_once 'fonctions.inc.php';
$path = $_SERVER["PHP_SELF"]; $path = $_SERVER["PHP_SELF"];
$db = new db(); $db = new db();
$idVotation = getpost("id"); $idVotation = getpost("id");
$method = getpost("method"); $method = getpost("method");
$libelle = getpost("libelle"); $libelle = getpost("libelle");

View File

@ -113,20 +113,44 @@ class dbcore
} }
} }
function queryVotationName($db, $idVotation) :string function queryVoteName($idVote)
{
$query = "SELECT libelle FROM liste_votes where id='" . $idVote . "'";
$this->query($query);
$voteLine = $this->result->fetch_assoc();
return $voteLine["libelle"];
}
function queryVotationName($idVotation) :string
{ {
$query = "SELECT libelle FROM liste_votations WHERE id='" . $idVotation . "'"; $query = "SELECT libelle FROM liste_votations WHERE id='" . $idVotation . "'";
$db->query($query); $this->query($query);
$votationLine = $db->result->fetch_assoc(); $votationLine = $this->result->fetch_assoc();
return $votationLine["libelle"]; return $votationLine["libelle"];
} }
function queryVotes($db, $idVotation) function queryVotes($idVotation)
{ {
$query = "SELECT * FROM liste_votes LEFT JOIN methods ON liste_votes.methode=methods.id WHERE idVotation='" . $idVotation . "'"; $query = "SELECT * FROM liste_votes LEFT JOIN methods ON liste_votes.methode=methods.id WHERE idVotation='" . $idVotation . "'";
$db->query($query); $this->query($query);
$votes = $db->result->fetch_all(); $votes = $this->result->fetch_all();
return $votes; return $votes;
} }
function queryCandidatsList($idVotation, $idVote)
{
$query = "SELECT * FROM liste_candidats WHERE idVotation='" . $idVotation . "' AND idVote='" . $idVote . "'";
$this->query($query);
$candidats = $this->result->fetch_all();
return $candidats;
}
} }
function queryCandidatName($idCandidat)
{
$query = "SELECT libelle FROM liste_candidats where id='" . $idCandidat . "'";
$this->query($query);
$line = $this->result->fetch_assoc();
return $line["candidat"];
}
?> ?>

View File

@ -44,6 +44,32 @@ function mb_ucfirst($str)
return $char . $str; return $char . $str;
} }
function choixVote($path, $idVotation, $confirm=false)
{
global $base_url, $action;
$db = new db();
$query = "SELECT * FROM liste_votes WHERE idVotation=" . $idVotation;
$result = $db->query($query);
$votes = $db->result->fetch_all(MYSQLI_ASSOC);
print ('<form method="get" action="' . $path . '">');
print "<pre>";
print '<input type="hidden" name="idVotation" value="' . $idVotation . '"/>';
foreach($votes as $key => $value )
{
print '<input type="radio" name="idVote" value="' . $value["id"] . '"/> ' . $value["candidat"] . '<br>';
}
// TODO confirmation du choix par javascript si $confirm = true
print '</pre><br>
<div>
<input type="submit" value="Envoyer"/>
<input type="submit" formaction="index.php" value="' . _("Annuler") . '"/>
</div>
</form>';
$db->close();
}
function choixVotation($path, $methode = 2, $confirm = true) //2 = toutes les votations 0 = votations en cours 1 = votations cloturées function choixVotation($path, $methode = 2, $confirm = true) //2 = toutes les votations 0 = votations en cours 1 = votations cloturées
{ {
global $base_url, $action; global $base_url, $action;
@ -57,18 +83,6 @@ function choixVotation($path, $methode = 2, $confirm = true) //2 = toutes les v
$result = $db->query($query); $result = $db->query($query);
$votations = $db->result->fetch_all(MYSQLI_ASSOC); $votations = $db->result->fetch_all(MYSQLI_ASSOC);
/*if ($db->result->num_rows == 1)
{
$redirect = '<META HTTP-EQUIV=Refresh CONTENT="0; URL=' . $base_url . $path . '?id=' . $votations["0"]["id"];
if( !empty($action))
{
$redirect .= '&action=' . $action;
}
$redirect .= '">';
//echo $redirect;
header( 'Location: ' . $base_url . '/gestionsite/modifVotation.php?id=' . $votations["0"]["id"]) . $redirect;
}*/
print ('<form method="get" action="' . $path . '">'); print ('<form method="get" action="' . $path . '">');
print "<pre>"; print "<pre>";
print '<input type="hidden" name="action" value="' . $action . '"/>'; print '<input type="hidden" name="action" value="' . $action . '"/>';