<?php
#########################################################################################
# Fiche de candidature des élèves de Pnyx - scripts bdd #
# Auteur : V. Blais #
# Création : 2006-04-05 #
# Modification : 2008-07-03 #
# #
# 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";
if (isset($HTTP_POST_VARS['type_action'])){
if ($HTTP_POST_VARS['type_action'] == "ins_fin"){
$requete_sql = "INSERT INTO election (fiche_id, projet_id)
VALUES ('" . $HTTP_POST_VARS['id_prop'] . "', $projet)";
$reponse_msg = bd_executer_sql($requete_sql);
# echo $requete_sql;
$HTTP_SESSION_VARS['SESSION']['message'] = "La proposition a été ajoutée à la liste des finalistes potentiels.";
$page = "gen_fiche.php?id_prop=".$HTTP_POST_VARS['id_prop']."";
header("Location: $page");
}
}
if(isset($HTTP_GET_VARS['type_action'])){
if ($HTTP_GET_VARS['type_action'] == "app"){
$vote = "n";
foreach($HTTP_SESSION_VARS['SESSION']['app'] as $id){
if ($HTTP_GET_VARS['id_prop'] == $id){
$vote = "y";
}
}
if ($vote == "n"){
$requete_sql = "SELECT * FROM fiche
WHERE fiche_id = '" . $HTTP_GET_VARS['id_prop'] . "'
";
$reponse_app = bd_executer_sql($requete_sql);
$ligne_app = mysql_fetch_array($reponse_app);
$nb_votes = $ligne_app['app_nb'] + 1;
$note_total = $ligne_app['app_total'] + $HTTP_GET_VARS['app'];
$moyenne = $note_total/ $nb_votes;
$requete_sql = "UPDATE fiche
SET app_total = \"$note_total\",
app_nb = \"$nb_votes\",
app_moyenne = \"$moyenne\"
WHERE fiche_id = '" . $HTTP_GET_VARS['id_prop'] . "'
";
$reponse_app = bd_executer_sql($requete_sql);
# echo $requete_sql;
$i = count($HTTP_SESSION_VARS['SESSION']['app']);
$HTTP_SESSION_VARS['SESSION']['app'][$i] = $HTTP_GET_VARS['id_prop'];
$HTTP_SESSION_VARS['SESSION']['message'] = "Votre appéciation est ajoutée. Merci!";
$page = "gen_fiche.php?id_prop=".$HTTP_GET_VARS['id_prop']."";
header("Location: $page");
} else {
$HTTP_SESSION_VARS['SESSION']['message'] = "Vous avez déjà fait part de votre appréciation pour cette fiche!";
$page = "gen_fiche.php?id_prop=".$HTTP_GET_VARS['id_prop']."";
header("Location: $page");
}
}
}
if (isset($HTTP_POST_VARS['type_action'])){
if ($HTTP_POST_VARS['type_action'] == "msg"){
if ($niveau == "general"){
header("Location: index.php");
}
if ($niveau == "resp"){
$id = $HTTP_SESSION_VARS['SESSION']['usager_id'];
$type = "resp";
}
if ($niveau == "eleve"){
$id = $HTTP_SESSION_VARS['SESSION']['usager_id'];
$type = "eleve";
}
if ($niveau == "admin"){
$id = 0;
$type = "admin";
}
$time = date("H:i:s");
$temps = $date." ".$time;
$texte = addslashes($HTTP_POST_VARS['texte']);
$requete_sql = "INSERT INTO fil_discussion (date_creation, date_last_msg,
last_auteur, type_auteur, last_destinataire, titre, projet_id)
VALUES ( \" $temps\", \"$temps\", \"$id\", \"$type\", \"$HTTP_POST_VARS[id_eleve]\",
\"".addslashes($HTTP_POST_VARS["titre"])."\", $projet)";
$reponse_fil = bd_executer_sql($requete_sql);
$id_fil = mysql_insert_id();
$requete_sql = "INSERT INTO msg_fil (fil_id, auteur, type_auteur, destinataire, date, titre, texte, projet_id)
VALUES ( \" $id_fil\", \"$id\", \"$type\", \"$HTTP_POST_VARS[id_eleve]\",
\"$temps\", \"".addslashes($HTTP_POST_VARS["titre"])."\", \"$texte\", $projet)";
$reponse_msg = bd_executer_sql($requete_sql);
$HTTP_SESSION_VARS['SESSION']['message'] = "Le message est envoyé.";
$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
$page = "gen_fiche.php?id_prop=".$HTTP_POST_VARS['id_prop']."";
header("Location: $page");
}
}
if ($HTTP_GET_VARS['type_action'] == "aff_fiche"){
if (!session_is_registered("RETOUR")){
session_register("RETOUR");
}
if ($periode == "vote"){
$HTTP_SESSION_VARS["RETOUR"] = "<a href='gen_rech_prog.php'>Retour à la liste des finalistes</a>";
} else if ($periode == "fin_vote"){
$HTTP_SESSION_VARS["RETOUR"] = "<a href='gen_rech_prog.php'>Retour à la liste des résultats</a>";
} else {
$HTTP_SESSION_VARS["RETOUR"] = "<a href='gen_rech_prog.php'>Retour à la page de recherche</a>";
}
$page = "gen_fiche.php?id_prop=".$HTTP_GET_VARS['id_prop'];
header("Location: $page");
}
?>