<?php
#########################################################################################
# Gestion du vote des élèves de Pnyx #
# Auteur : V. Blais #
# Création : 2006-04-05 #
# Modification : 2008-08-27 #
# #
# Pnyx - une application Web (PHP/MySQL) d'élections virtuelles conçue pour des élèves #
# du primaire et du secondaire, dans lequel ils sont amenés à faire des propositions #
# en ligne et voter pour leur favorite, sous la supervision d'un enseignant. #
# #
# Copyright (C) <2008 - 2009> #
# <Service national du RÉCIT de l'univers social de la Commission scolaire de la #
# Pointe-de-l'Île> #
# #
# This program is free software; you can redistribute it and/or modify it under the #
# terms of the GNU General Public License as published by the Free Software Foundation. #
# This program is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A #
# PARTICULAR PURPOSE. See the GNU General Public License for more details. #
# You should have received a copy of the GNU General Public License along with this #
# program as the file LICENSE.txt; if not, please see #
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. #
# #
# Service national du RÉCIT de l'univers social #
# http://www.recitus.qc.ca #
# Contact e-mail : steve-hide@address.com #
#########################################################################################
require "entete_php.php";
#gen_variables_session();
#vérifier si l'usager peut accéder à cette page
acces_eleve("ele_vote.php");
#variables pour l'affichage graphique de la page
$titre = "Mon vote";
$requete_sql = "SELECT *
FROM eleve
WHERE eleve_id = $usager
";
$reponse_val = bd_executer_sql($requete_sql);
$ligne_val = mysql_fetch_array($reponse_val);
################################### REQUETES BDD #########################################
if ($periode != "debut" && $periode != "cand" && $periode != "fin_cand"){
if (!session_is_registered("RES")){
session_register("RES");
} else {
session_unregister("RES");
session_register("RES");
}
$requete_sql = "SELECT valide
FROM lien_resp_projet L, groupe G
WHERE G.groupe_id = '" . $ligne_val['groupe_id'] . "'
AND L.resp_id = G.resp_id
AND L.projet_id = $projet
";
$reponse_resp = bd_executer_sql($requete_sql);
$ligne_resp = mysql_fetch_array($reponse_resp);
$requete_sql = "SELECT *
FROM eleve
WHERE projet_id = $projet
AND eleve_id = $usager
AND vote = 1
";
$reponse_elect = bd_executer_sql($requete_sql);
$nb_elect = mysql_num_rows($reponse_elect);
if($nb_elect == 0){
$requete_sql = "SELECT *
FROM election
WHERE projet_id = $projet
ORDER BY nb_votes DESC
";
$reponse_final = bd_executer_sql($requete_sql);
$reponse_res = bd_executer_sql($requete_sql);
$r = 0;
$id = array();
while ($ligne_res = mysql_fetch_array($reponse_res)){
$id[$r] = $ligne_res['fiche_id'];
$r++;
}
$HTTP_SESSION_VARS["RES"]= $id;
}
}
################################### FIN REQUETES BDD #########################################
#affichage graphique
require "entete.php";
$message = $HTTP_SESSION_VARS['SESSION']['message'];
echo "<br /><h3 align=\"center\"><font color='#FF0000'>$message</font></h3>";
$HTTP_SESSION_VARS['SESSION']['message']="";
echo "<h2>".$nom_eleve."</h2>";
if ($periode == "debut" || $periode == "cand" || $periode == "fin_cand"){
?>
<p>La période de vote n'est pas encore commencée, reviens plus tard.</p>
<?
} else {
if ($nb_elect == "0"){
if(isset($HTTP_POST_VARS['type_action'])){
if ($HTTP_POST_VARS['type_action'] == "choix"){
$requete_sql = "SELECT *
FROM election
WHERE finaliste_id = \"$HTTP_POST_VARS[id_final]\"
";
$reponse_final = bd_executer_sql($requete_sql);
$ligne_final = mysql_fetch_array($reponse_final);
$requete_sql = "SELECT *
FROM fiche
WHERE fiche_id = \"$ligne_final[fiche_id]\"
";
$reponse_prop = bd_executer_sql($requete_sql);
$ligne_prop = mysql_fetch_array($reponse_prop);
/*$requete_sql = "SELECT *
FROM fiche
WHERE eleve_id = \"$ligne_prop[eleve_id]\"
";
$reponse_fiche = bd_executer_sql($requete_sql);
$ligne_fiche = mysql_fetch_array($reponse_fiche);*/
$requete_sql = "SELECT *
FROM eleve E, usager U
WHERE E.eleve_id = \"$ligne_prop[eleve_id]\"
AND U.usager_id = E.usager_id
";
$reponse_eleve = bd_executer_sql($requete_sql);
$ligne_eleve = mysql_fetch_array($reponse_eleve);
$requete_sql = "SELECT *
FROM groupe
WHERE groupe_id = \"$ligne_eleve[groupe_id]\"
";
$reponse_grp = bd_executer_sql($requete_sql);
$ligne_grp = mysql_fetch_array($reponse_grp);
$requete_sql = "SELECT E.nom
FROM ecole E, responsable R
WHERE R.resp_id = \"$ligne_grp[resp_id]\"
AND E.ecole_id = R.ecole_id
";
$reponse_ecole = bd_executer_sql($requete_sql);
$ligne_ecole = mysql_fetch_array($reponse_ecole);
?>
<div align='right'><a href='ele_vote.php'>Retourner à la liste des finalistes</a></div>
<br />
<div class="sommaire">
<p>
Tu as choisi de voter pour <strong><?=$ligne_eleve['login']?></strong>. Tu dois d'abord justifier ton choix, ensuite tu pourras voter. N'oublie pas : tu ne peux voter qu'une seule fois et tu ne pourras pas modifier ton choix une fois que tu auras cliqué sur le bouton « Voter ».</p>
</div>
<br />
<div>
<h4><?=$ligne_prop['slogan']?></h4>
<table cellpadding="0" cellspacing="0" width="600" border="0" align="center">
<tr>
<td align="center" width="200" valign="top">
<?
if ($ligne_prop['affiche'] == ""){
$affiche = "images/gen_affiche.jpg";
} else {
$affiche = $ligne_prop['affiche'];
}
list($width) = getimagesize($affiche);
if ($width > 200){
echo "<img src=".$affiche." width='200'/>";
} else {
?>
<img src='<?=$affiche?>' alt="Pancarte"/>
<?
}
?>
<td align="center">
<table cellpadding="0" cellspacing="0" width="95%" align="right">
<tr>
<td width="30%" valign="top">Auteur :</td>
<td width="70%"><?=$ligne_eleve['login']?></td>
</tr>
<tr>
<td valign="top">Niveau : </td>
<td><?=$ligne_prop['niveau']?></td>
</tr>
<tr>
<td valign="top">Catégorie : </td>
<td>
<?
$requete_sql = "SELECT nom
FROM categorie_prop
WHERE cat_id = \"$ligne_prop[categorie]\"
";
$reponse_catNom = mysql_query($requete_sql);
$ligne_catNom = mysql_fetch_array($reponse_catNom);
?>
<?= $ligne_catNom['nom']?>
</td>
</tr>
<tr>
<td valign="top">École : </td>
<td><?=$ligne_ecole['nom']?></td>
</tr>
<tr>
<td valign="top">Niveau scolaire : </td>
<td><?=$ligne_grp['niveau']?></td>
</tr>
<tr>
<td valign="top">Groupe : </td>
<td><?=$ligne_grp['nom']?></td>
</tr>
</table>
</td>
</tr>
<tr><td colspan="2">
<br />
<p><strong>Explication</strong> :
<?=nl2br($ligne_prop['proposition'])?>
</p></td></tr>
</table>
</div>
<form name="form_vote" method="post" action="ele_vote2.php">
<table cellpadding="0" cellspacing="0" width="600" border="0" align="center">
<tr>
<td>
<br />
<p><strong>Justifie ton vote :</strong><br />
<textarea name="texte" cols="60" rows="7" wrap="physical"></textarea>
</p></td>
</tr>
<tr>
<td><p>N'oublie pas tu ne peux voter qu'une seule fois!</p></td>
</tr>
<tr>
<td align="center">
<input type="submit" name="supp" value="Voter" onClick="return val_vote(this.form)"/>
<input type="hidden" name="type_action" value="vote">
<input type="hidden" name="id_final" value="<?= $ligne_final['finaliste_id'] ?>">
</td>
</tr>
</table>
</form>
<?
}
} else if ($periode == "vote"){
if ($ligne_val['valide'] == 1 && $ligne_resp['valide'] == 1){
?>
<div class="sommaire">
<p>Il est maintenant temps pour toi d'exercer ton droit de vote. Fais ton choix, parmi les finalistes, pour la proposition qui te semble la meilleure. Tu devras ensuite justifier ton choix.</p>
</div>
<?
} else if ($ligne_val['valide'] == 0 && $ligne_resp['valide'] == 1){
?>
<div class="sommaire">
<p>Ton inscription n'est pas encore validée. Pour exercer ton droit de vote, ton responsable doit d'abord avoir validé ton inscription. Si ce n'est pas fait, n'hésite pas à lui en parler!</p>
</div>
<?
}
?>
<h3>Liste des finalistes</h3>
<?
$i =0;
while ($ligne_final = mysql_fetch_array($reponse_final)){
$requete_sql = "SELECT *
FROM fiche
WHERE fiche_id = \"$ligne_final[fiche_id]\"
";
$reponse_prop = bd_executer_sql($requete_sql);
$ligne_prop = mysql_fetch_array($reponse_prop);
/*$requete_sql = "SELECT *
FROM fiche
WHERE fiche_id = \"$ligne_final[fiche_id]\"
";
$reponse_app = bd_executer_sql($requete_sql);
$ligne_app = mysql_fetch_array($reponse_app);*/
/*$requete_sql = "SELECT *
FROM fiche
WHERE eleve_id = \"$ligne_prop[eleve_id]\"
";
$reponse_fiche = bd_executer_sql($requete_sql);
$ligne_fiche = mysql_fetch_array($reponse_fiche);*/
$requete_sql = "SELECT *
FROM eleve E, usager U
WHERE E.eleve_id = \"$ligne_prop[eleve_id]\"
AND U.usager_id = E.usager_id
";
$reponse_eleve = bd_executer_sql($requete_sql);
$ligne_eleve = mysql_fetch_array($reponse_eleve);
$requete_sql = "SELECT *
FROM groupe
WHERE groupe_id = \"$ligne_eleve[groupe_id]\"
";
$reponse_grp = bd_executer_sql($requete_sql);
$ligne_grp = mysql_fetch_array($reponse_grp);
$requete_sql = "SELECT E.nom
FROM ecole E, responsable R
WHERE R.resp_id = \"$ligne_grp[resp_id]\"
AND E.ecole_id = R.ecole_id
";
$reponse_ecole = bd_executer_sql($requete_sql);
$ligne_ecole = mysql_fetch_array($reponse_ecole);
?>
<h4><?=$ligne_prop['slogan']?></h4>
<table cellpadding="0" cellspacing="0" width="600" border="0" align="center">
<tr>
<td align="center" width="200" valign="top">
<?
if ($ligne_prop['affiche'] == ""){
$affiche = "images/gen_affiche.jpg";
} else {
$affiche = $ligne_prop['affiche'];
}
list($width) = getimagesize($affiche);
if ($width > 200){
echo "<img src=".$affiche." width='200'/>";
} else {
?>
<img src='<?=$affiche?>' alt="Pancarte"/>
<?
}
?>
</td>
<td width="400" align="center">
<table cellpadding="0" cellspacing="0" width="95%" align="right">
<tr>
<td width="30%" valign="top">Auteur :</td>
<td width="70%"><?=$ligne_eleve['login']?></td>
</tr>
<tr>
<td valign="top">Niveau : </td>
<td><?=$ligne_prop['niveau']?></td>
</tr>
<tr>
<td valign="top">Catégorie : </td>
<td>
<?
$requete_sql = "SELECT nom
FROM categorie_prop
WHERE cat_id = \"$ligne_prop[categorie]\"
";
$reponse_catNom = mysql_query($requete_sql);
$ligne_catNom = mysql_fetch_array($reponse_catNom);
?>
<?= $ligne_catNom['nom']?>
</td>
</tr>
<tr>
<td valign="top">École : </td>
<td><?=$ligne_ecole['nom']?></td>
</tr>
<tr>
<td valign="top">Niveau scolaire : </td>
<td><?=$ligne_grp['niveau']?></td>
</tr>
<tr>
<td valign="top">Groupe : </td>
<td><?=$ligne_grp['nom']?></td>
</tr>
<tr>
<td valign="top">Appréciation : </td>
<td>
<?
if ($ligne_prop['app_moyenne'] < 0.50){
echo "<img src='images/etoile_0.jpg' />";
} else if ($ligne_prop['app_moyenne'] < 0.99){
echo "<img src='images/etoile_0_5.jpg' />";
} else if ($ligne_prop['app_moyenne'] < 1.50){
echo "<img src='images/etoile_1.jpg' />";
} else if ($ligne_prop['app_moyenne'] < 2.00){
echo "<img src='images/etoile_1_5.jpg' />";
} else if ($ligne_prop['app_moyenne'] < 2.50){
echo "<img src='images/etoile_2.jpg' />";
} else if ($ligne_prop['app_moyenne'] < 3.00){
echo "<img src='images/etoile_2_5.jpg' />";
} else if ($ligne_prop['app_moyenne'] < 3.50){
echo "<img src='images/etoile_3.jpg' />";
} else if ($ligne_prop['app_moyenne'] < 4.00){
echo "<img src='images/etoile_3_5.jpg' />";
} else if ($ligne_prop['app_moyenne'] < 4.50){
echo "<img src='images/etoile_4.jpg' />";
} else if ($ligne_prop['app_moyenne'] < 5.00){
echo "<img src='images/etoile_4_5.jpg' />";
} else {
echo "<img src='images/etoile_5.jpg' />";
}
?>
<br /></td>
</tr>
<tr>
<td valign="top"> </td>
<td>
<?
if ($ligne_prop['app_nb'] > 1){
echo " ".$ligne_prop['app_nb']." appréciations";
} else if ($ligne_prop['app_nb'] == 1){
echo " ".$ligne_prop['app_nb']." appréciation";
}
?>
<br />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"><br />
<?
$i++;
if ($ligne_val['valide'] == 1 && $ligne_resp['valide'] ==1){
?>
<form name="form_supp" method="post" action="ele_vote.php">
<div align="center">
<input type="submit" name="supp" value="Consulter"/>
<input type="hidden" name="type_action" value="choix">
<input type="hidden" name="id_final" value="<?= $ligne_final['finaliste_id'] ?>">
</div>
</form>
<?
}
?>
<hr align="center" width="400">
</td>
</tr>
</table>
<?
}
} else if ($periode == "fin_vote"){
?>
<div class="sommaire">
<p> La période de vote est terminée. Il est malheureusement trop tard pour voter!</p>
<?
} else {
?>
<p> Les élections nont pas encore débuté. Les finalistes seront affichés sous peu.</p>
</div>
<?
}
} else {
$ligne_vote = mysql_fetch_array($reponse_elect);
$requete_sql = "SELECT *
FROM election
WHERE fiche_id = \"$ligne_vote[fiche_vote]\"
";
$reponse_final = bd_executer_sql($requete_sql);
$ligne_final = mysql_fetch_array($reponse_final);
$requete_sql = "SELECT *
FROM fiche
WHERE fiche_id = \"$ligne_vote[fiche_vote]\"
";
$reponse_prop = bd_executer_sql($requete_sql);
$ligne_prop = mysql_fetch_array($reponse_prop);
/*$requete_sql = "SELECT *
FROM fiche
WHERE eleve_id = \"$ligne_prop[eleve_id]\"
";
$reponse_fiche = bd_executer_sql($requete_sql);
$ligne_fiche = mysql_fetch_array($reponse_fiche);*/
$requete_sql = "SELECT *
FROM eleve E, usager U
WHERE E.eleve_id = \"$ligne_prop[eleve_id]\"
AND U.usager_id = E.usager_id
";
$reponse_eleve = bd_executer_sql($requete_sql);
$ligne_eleve = mysql_fetch_array($reponse_eleve);
$requete_sql = "SELECT *
FROM groupe
WHERE groupe_id = \"$ligne_eleve[groupe_id]\"
";
$reponse_grp = bd_executer_sql($requete_sql);
$ligne_grp = mysql_fetch_array($reponse_grp);
$requete_sql = "SELECT E.nom
FROM ecole E, responsable R
WHERE R.resp_id = \"$ligne_grp[resp_id]\"
AND E.ecole_id = R.ecole_id
";
$reponse_ecole = bd_executer_sql($requete_sql);
$ligne_ecole = mysql_fetch_array($reponse_ecole);
if ($periode != "vote"){
?>
<p>La proposition pour laquelle tu as voté a reçu <?=$ligne_final['nb_votes']?> vote(s).</p>
<br />
<?
} else {
?>
<p><strong>Tu as voté pour :</strong></p>
<?
}
?>
<h3><?=$ligne_prop['slogan']?></h3>
<table cellpadding="0" cellspacing="0" width="600" border="0" align="center">
<tr>
<td align="center" width="200" valign="top">
<?
if ($ligne_prop['affiche'] == ""){
$affiche = "images/gen_affiche.jpg";
} else {
$affiche = $ligne_prop['affiche'];
}
list($width) = getimagesize($affiche);
if ($width > 200){
echo "<img src=".$affiche." width='200'/>";
} else {
?>
<img src='<?=$affiche?>' alt="Pancarte"/>
<?
}
?>
<td align="center">
<table cellpadding="0" cellspacing="0" width="95%" align="right">
<tr>
<td width="30%" valign="top">Auteur :</td>
<td width="70%"><?=$ligne_eleve['login']?></td>
</tr>
<tr>
<td valign="top">Niveau : </td>
<td><?=$ligne_prop['niveau']?></td>
</tr>
<tr>
<td valign="top">Catégorie : </td>
<td>
<?
$requete_sql = "SELECT nom
FROM categorie_prop
WHERE cat_id = \"$ligne_prop[categorie]\"
";
$reponse_catNom = mysql_query($requete_sql);
$ligne_catNom = mysql_fetch_array($reponse_catNom);
?>
<?= $ligne_catNom['nom']?>
</td>
</tr>
<tr>
<td valign="top">École : </td>
<td><?=$ligne_ecole['nom']?></td>
</tr>
<tr>
<td valign="top">Niveau scolaire : </td>
<td><?=$ligne_grp['niveau']?></td>
</tr>
<tr>
<td valign="top">Groupe : </td>
<td><?=$ligne_grp['nom']?></td>
</tr>
</table>
</td>
</tr>
<tr><td colspan="2">
<strong>Explication :</strong><?=nl2br($ligne_prop['proposition'])?>
</td></tr>
</table>
<br />
<table cellpadding="0" cellspacing="0" width="600" border="0" align="center">
<tr>
<td><strong>Justification :</strong><br />
<p><?=nl2br($ligne_vote['justification'])?></p></td>
</tr>
</table>
</div>
<br />
<?
}
}
?>
</td>
</tr>
</table>
<table align="center" width="665"><tr><td>
<div align="right"><a href="#haut"><img src="images/haut.gif" alt="Retour au haut de la page" width="37" height="17" border="0" /></a></div>
</td></tr></table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?
require "pied_page.php";
?>