Create poll page
This commit is contained in:
parent
cf61f9dc6f
commit
f807700358
4 changed files with 66 additions and 0 deletions
13
controllers/c_poll.php
Normal file
13
controllers/c_poll.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
if (isset($_GET["id"]) and $_GET["id"]) {
|
||||
$pollId = htmlspecialchars($_GET["id"]);
|
||||
if (isset($_POST["answer"]) and $_POST["answer"])
|
||||
$answer = htmlspecialchars($_POST["answer"]);
|
||||
require_once(PATH_MODELS.$page.'.php');
|
||||
} else
|
||||
$alert = choixAlert("url_non_valide");
|
||||
|
||||
|
||||
//appel de la vue
|
||||
require_once(PATH_VIEWS.$page.'.php');
|
|
@ -9,4 +9,5 @@ define('MESSAGE_ERREUR',"Une erreur s'est produite");
|
|||
|
||||
define('TITRE', 'Le site des sondages');
|
||||
define('POLLS_LIST', 'Liste des sondages');
|
||||
define('ANSWER', 'Votez');
|
||||
define('ERREUR_QUERY', 'Problème d\'accès à la base de données. Contactez l\'administrateur');
|
||||
|
|
24
models/m_poll.php
Normal file
24
models/m_poll.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
require_once("lib/getPDD.php");
|
||||
|
||||
$bdd = getPDO();
|
||||
|
||||
if ($bdd instanceof PDO) {
|
||||
if (isset($answer) and $answer) {
|
||||
$req = $bdd->prepare("UPDATE Reponse SET nbChoisi = nbChoisi+1 WHERE repId = ?");
|
||||
$req->execute(array($answer));
|
||||
$req->closeCursor();
|
||||
}
|
||||
|
||||
$req = $bdd->prepare("SELECT * FROM Sondage WHERE sonId = ?");
|
||||
$req->execute(array($pollId));
|
||||
$poll = $req->fetch();
|
||||
$req->closeCursor();
|
||||
|
||||
$req = $bdd->prepare("SELECT * FROM Reponse WHERE sondId = ?");
|
||||
$req->execute(array($pollId));
|
||||
$answers = $req->fetchAll();
|
||||
$req->closeCursor();
|
||||
} elseif ($bdd instanceof Exception)
|
||||
$alert = choixAlert("query");
|
28
views/v_poll.php
Normal file
28
views/v_poll.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
// En tête de page
|
||||
?>
|
||||
<?php require_once(PATH_VIEWS.'header.php');?>
|
||||
|
||||
<!-- Zone message d'alerte -->
|
||||
<?php require_once(PATH_VIEWS.'alert.php');?>
|
||||
|
||||
<!-- Début de la page -->
|
||||
<?php if (isset($poll) and $poll and isset($answers) and $answers) { ?>
|
||||
<h2><?= $poll["question"] ?></h2>
|
||||
<?php foreach ($answers as $answer) { ?>
|
||||
<p><?= $answer["texte"] ?>: <?= str_repeat("+", $answer["nbChoisi"]) ?></p>
|
||||
<?php } ?>
|
||||
<form method="POST">
|
||||
<?php foreach ($answers as $answer) { ?>
|
||||
<label>
|
||||
<input type="radio" name="answer" value=<?= $answer["repId"] ?>>
|
||||
<?= $answer["texte"] ?>
|
||||
</label>
|
||||
<?php } ?>
|
||||
<input type="submit" value=<?= ANSWER ?>>
|
||||
</form>
|
||||
<?php } ?>
|
||||
<!-- Fin de la page -->
|
||||
|
||||
<!-- Pied de page -->
|
||||
<?php require_once(PATH_VIEWS.'footer.php');
|
Reference in a new issue