196 lines
6.5 KiB
PHP
196 lines
6.5 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
// Si la session n'existe plus
|
|
if (empty($_SESSION['reference'])) {
|
|
header('Location: index.php?$disconnect=true');
|
|
}
|
|
|
|
include("inc/config.inc.php");
|
|
include("inc/connect.inc.php");
|
|
include("inc/fonctions.inc.php");
|
|
// On regarde si il y a une AGO, AGE et vote CS
|
|
if (checkago()) {$ago = true;} else {$ago = false;}
|
|
if (checkage()) {$age = true;} else {$age = false;}
|
|
if (checkcs()) {$cs = true;} else {$cs = false;}
|
|
if ($ago) {
|
|
$resolution_ago_nb = $_SESSION['resolution_ago_nb'];
|
|
}
|
|
if ($age) {
|
|
$resolution_age_nb = $_SESSION['resolution_age_nb'];
|
|
}
|
|
if (isset($_POST['confirm'])) {
|
|
// On crée une clé unique pour vérifier plus tard le vote
|
|
$cle = bin2hex(openssl_random_pseudo_bytes(10));
|
|
// TODO : Il faut vérifier si la clé n'existe pas déjà
|
|
$_SESSION['cle'] = $cle;
|
|
|
|
if ($ago) {
|
|
for ($i = 1; $i <= $_SESSION['resolution_ago_nb']; $i++) {
|
|
echo $_SESSION['resolution_ago_'.$i];
|
|
}
|
|
}
|
|
if ($age) {
|
|
for ($i = 1; $i <= $_SESSION['resolution_age_nb']; $i++) {
|
|
echo $_SESSION['resolution_age_'.$i];
|
|
}
|
|
}
|
|
// On insère les résultats dans la bdd
|
|
// La requête $sql est compliquée à écrire puisqu'il faut la construire en fonction du nombre de résolutions
|
|
$sql = "INSERT INTO resultats (";
|
|
if ($ago) {
|
|
for ($i = 1; $i <= $_SESSION['resolution_ago_nb']; $i++) {
|
|
$sql .= 'resolution_ago_'.$i.',';
|
|
}
|
|
}
|
|
if ($age) {
|
|
for ($i = 1; $i <= $_SESSION['resolution_age_nb']; $i++) {
|
|
$sql .= 'resolution_age_'.$i.',';
|
|
}
|
|
}
|
|
if ($cs) {
|
|
$sql .= "vote_cs,";
|
|
}
|
|
$sql .= "cle) VALUES (";
|
|
|
|
if ($ago) {
|
|
for ($i = 1; $i <= $_SESSION['resolution_ago_nb']; $i++) {
|
|
$sql .= ':resolution_ago_'.$i.',';
|
|
}
|
|
}
|
|
if ($age) {
|
|
for ($i = 1; $i <= $_SESSION['resolution_age_nb']; $i++) {
|
|
$sql .= ':resolution_age_'.$i.',';
|
|
}
|
|
}
|
|
if ($cs) {
|
|
$sql .= ":vote_cs,";
|
|
}
|
|
$sql .= ":cle)";
|
|
echo $sql;
|
|
$stmt = $bdd->prepare($sql);
|
|
if ($ago) {
|
|
for ($i = 1; $i <= $_SESSION['resolution_ago_nb']; $i++) {
|
|
$stmt->bindParam(':resolution_ago_'.$i, $_SESSION['resolution_ago_'.$i]);
|
|
}
|
|
}
|
|
if ($age) {
|
|
for ($i = 1; $i <= $_SESSION['resolution_age_nb']; $i++) {
|
|
$stmt->bindParam(':resolution_age_'.$i, $_SESSION['resolution_age_'.$i]);
|
|
}
|
|
}
|
|
if ($cs) {
|
|
$stmt->bindParam(':vote_cs', $_SESSION['vote_cs']);
|
|
}
|
|
$stmt->bindParam(':cle', $cle);
|
|
$stmt->execute();
|
|
|
|
// On passe le booleen à true pour marquer que cette référence à déjà voté
|
|
$sql ="
|
|
UPDATE clients
|
|
SET vote = 1
|
|
WHERE reference = :ref
|
|
";
|
|
$stmt = $bdd->prepare($sql);
|
|
$stmt->bindParam(':ref', $_SESSION['reference'], PDO::PARAM_STR);
|
|
// Exécution de la requête
|
|
$stmt->execute();
|
|
$stmt = null;
|
|
|
|
header('Location: merci.php');
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<?php include("theme/_head.php"); ?>
|
|
</head>
|
|
<body>
|
|
<!--[if lt IE 9]>
|
|
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
|
|
<![endif]-->
|
|
<?php
|
|
include("theme/header.php");
|
|
include("inc/config.inc.php");
|
|
include("inc/connect.inc.php");
|
|
?>
|
|
<section id="pagefinal">
|
|
<p class="bold">En dernière étape, merci maintenant de vérifier et de confirmer votre vote.</p>
|
|
<?php if ($ago) { ?>
|
|
<h3>Résolutions d'Assemblée Générale Ordinaire</h3>
|
|
<?php
|
|
$sql = "SELECT option_name, option_value FROM admin WHERE option_name = :option";
|
|
$stmt = $bdd->prepare($sql);
|
|
// On boucle pour chaque résolution avec création du formulaire
|
|
for ($i = 1; $i <= $resolution_ago_nb; $i++) {
|
|
// On selectionne la résolution
|
|
$option = 'resolution_ago_'.$i;
|
|
$stmt->bindParam(':option', $option, PDO::PARAM_STR);
|
|
$stmt->execute();
|
|
$results = $stmt->fetch();
|
|
$resolution_ago_txt = $results['option_value'];
|
|
?>
|
|
<h4>Résolution n°<?php echo $i; ?></h4>
|
|
<p><?php echo $resolution_ago_txt; ?></p>
|
|
<p class="formvote">Votre vote : <span class="bold">
|
|
<?php echo $_SESSION['resolution_ago_'.$i]; ?>
|
|
</span>
|
|
</p>
|
|
<?php } ?>
|
|
<hr />
|
|
<?php } ?>
|
|
|
|
<?php if ($age) { ?>
|
|
<h3>Résolutions d'Assemblée Générale Extraordinaire</h3>
|
|
<?php
|
|
$sql = "SELECT option_name, option_value FROM admin WHERE option_name = :option";
|
|
$stmt = $bdd->prepare($sql);
|
|
// On boucle pour chaque résolution avec création du formulaire
|
|
for ($i = 1; $i <= $resolution_age_nb; $i++) {
|
|
// On selectionne la résolution
|
|
$option = 'resolution_age_'.$i;
|
|
$stmt->bindParam(':option', $option, PDO::PARAM_STR);
|
|
$stmt->execute();
|
|
$results = $stmt->fetch();
|
|
$resolution_age_txt = $results['option_value'];
|
|
?>
|
|
<h4>Résolution n°<?php echo $i; ?></h4>
|
|
<p><?php echo $resolution_age_txt; ?></p>
|
|
<p class="formvote">Votre vote : <span class="bold">
|
|
<?php echo $_SESSION['resolution_age_'.$i]; ?>
|
|
</span>
|
|
</p>
|
|
<?php } ?>
|
|
<hr />
|
|
<?php } ?>
|
|
|
|
<?php if ($cs) { ?>
|
|
<h4>Élection des membres du Conseil de Surveillance</h4>
|
|
<p class="formvote">Votre vote : <span class="bold">
|
|
<?php
|
|
// On remplace par point virgule, c'est plus joli :)
|
|
$vote_cs = str_replace(",", " ; ", $_SESSION['vote_cs']);
|
|
// On vire le dernier ;, c'est encore plus joli :D
|
|
$vote_cs = rtrim($vote_cs, ";");
|
|
echo $vote_cs;
|
|
?>
|
|
</span>
|
|
</p>
|
|
<hr />
|
|
<?php } ?>
|
|
<form id='confirmation_vote' method="post" action="finalisation.php" data-parsley-validate>
|
|
<p class="formvote">
|
|
<input type="checkbox" name="confirm" value="confirm" id="confirm" required data-parsley-required /><label for="confirm">Mon vote est correct.</label><br />
|
|
<input type="submit" value="Confirmez">
|
|
</p>
|
|
</form>
|
|
</section>
|
|
<?php include("theme/footer.php"); ?>
|
|
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
|
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.10.2.min.js"><\/script>')</script>
|
|
<script src="js/vendor/parsley.min.js"></script>
|
|
<script src="js/vendor/parsley-fr.js"></script>
|
|
<script src="js/main.js"></script>
|
|
</body>
|
|
</html>
|