<?php
#########################################################################################
# Gestion des propositions de Pnyx - script bdd #
# Auteur : V. Blais #
# Création : 2006-04-05 #
# Modification : 2008-08-11 #
# #
# 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 ($HTTP_POST_VARS['type_action'] == "creer"){
$requete_sql = "SELECT * FROM fiche WHERE eleve_id = \"$usager\"";
$reponse_fiche = bd_executer_sql($requete_sql);
$nb_fiche = mysql_num_rows($reponse_fiche);
$titre = addslashes($HTTP_POST_VARS['titre']);
$texte = addslashes($HTTP_POST_VARS['texte']);
if($HTTP_POST_VARS['choixSourceT'] == "oui"){
$sourceT = addslashes($HTTP_POST_VARS['sourceT']);
}
else{
$sourceT = "Aucune";
}
if($titre != "" && $texte != "" && $sourceT != ""){
if($nb_fiche < 1){
$requete_sql = "INSERT INTO fiche (niveau, slogan, proposition, categorie,
projet_id, eleve_id, source)
VALUES ( \"$HTTP_POST_VARS[niveau]\", \"$titre\",
\"$texte\", \"$HTTP_POST_VARS[cat]\",
$projet, $usager, \"$sourceT\")
";
}
else{
$ligne_fiche = mysql_fetch_array($reponse_fiche);
$requete_sql = "UPDATE fiche
SET niveau = \"$HTTP_POST_VARS[niveau]\",
slogan = \"$titre\",
proposition = \"$texte\",
categorie = \"$HTTP_POST_VARS[cat]\",
projet_id = $projet,
source = \"$sourceT\"
WHERE fiche_id = \"$ligne_fiche[fiche_id]\"";
}
$reponse_ins = bd_executer_sql($requete_sql);
$requete_sql = "SELECT fiche_id
FROM fiche
WHERE eleve_id = $usager
";
$reponse_ficheID = bd_executer_sql($requete_sql);
$ligne_ficheID = mysql_fetch_array($reponse_ficheID);
$requete_sql = "UPDATE `eleve`
SET `fiche_id` = '" . $ligne_ficheID['fiche_id'] . "'
WHERE `eleve_id` = $usager
LIMIT 1 ;
";
$reponse_ins = bd_executer_sql($requete_sql);
$prop = mysql_insert_id();
$HTTP_SESSION_VARS['SESSION']['message'] = "Ta proposition a été créée.";
$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
header("Location: ele_fiche.php");
}
else{
$HTTP_SESSION_VARS['SESSION']['message'] = "Tu ne peut pas créée une proposition aux champs vides.";
$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
header("Location: ele_fiche.php");
}
}
if ($HTTP_POST_VARS['type_action'] == "sup"){
$requete_sql = "SELECT * FROM fiche WHERE fiche_id = \"$HTTP_POST_VARS[id_prop]\"";
$reponse_fiche = bd_executer_sql($requete_sql);
$ligne_fiche = mysql_fetch_array($reponse_fiche);
if($ligne_fiche['affiche'] == ""){
$requete_sql = "DELETE FROM fiche
WHERE fiche_id = \"$HTTP_POST_VARS[id_prop]\"
";
}
else{
$requete_sql = "UPDATE fiche
SET slogan = '',
proposition = '',
source = '',
niveau = '',
categorie = ''
WHERE fiche_id = \"$HTTP_POST_VARS[id_prop]\"
";
}
$reponse_mod_nouv = bd_executer_sql($requete_sql);
$HTTP_SESSION_VARS['SESSION']['message'] = "Ta proposition a été supprimée.";
$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
header("Location: ele_fiche.php");
}
# phpinfo();
if ($HTTP_POST_VARS['type_action'] == "tel_aff"){
if ($_FILES['affiche']["type"] != "image/gif" && $_FILES['affiche']["type"] != "image/pjpeg" && $_FILES['affiche']["type"] != "image/jpeg" && $_FILES['affiche']["type"] != "image/png"){
$HTTP_SESSION_VARS['SESSION']['message'] = "Ta pancarte doit être enregistrée sous un format jpeg, gif ou png.";
$HTTP_SESSION_VARS['SESSION']['onglet'] = 2;
header("Location: ele_fiche.php");
} else {
// ********************************************
// Update: 07 mars 2007
// Ajout : Redimension de l image en 400x300
// Auteur: Sébastien Tremblay
// ********************************************
$size = getimagesize($_FILES['affiche']["tmp_name"]);
$width = $size[0];
$height = $size[1];
$ImageFinale = null;
if ($_FILES['affiche']["type"] == "image/gif")
$extension = ".gif";
else if (($_FILES['affiche']["type"] == "image/pjpeg") || ($_FILES['affiche']["type"] == "image/jpeg"))
$extension = ".jpg";
else if ($_FILES['affiche']["type"] == "image/png")
$extension = ".png";
else
{
$HTTP_SESSION_VARS['SESSION']['message'] = "Format incorrect.";
$HTTP_SESSION_VARS['SESSION']['onglet'] = 2;
header("Location: ele_fiche.php");
exit;
}
$nom_fichier = $usager . $extension;
$chemin = "pancartes/projet_".$projet;
$link = $chemin . "/" . $nom_fichier;
if($width >= $height){
$newWidth = 400;
$newHeight = ($height * $newWidth)/$width;
}
else{
$newHeight = 300;
$newWidth = ($width * $newHeight)/$height;
}
$ImageFinale = imagecreatetruecolor($newWidth, $newHeight);
if ($extension == ".gif")
$source = imagecreatefromgif($_FILES['affiche']["tmp_name"]);
else if ($extension == ".png")
$source = imagecreatefrompng($_FILES['affiche']["tmp_name"]);
else
$source = imagecreatefromjpeg($_FILES['affiche']["tmp_name"]);
imagecopyresized($ImageFinale, $source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
if (!imagejpeg($ImageFinale, $link, 100))
{
$HTTP_SESSION_VARS['SESSION']['message'] = "Il y a eu une erreur lors du téléchargement, recommence.";
$HTTP_SESSION_VARS['SESSION']['onglet'] = 2;
header("Location: ele_fiche.php");
}
else{
$requete_sql = "SELECT * FROM fiche WHERE eleve_id = \"$usager\"";
$reponse_fiche = bd_executer_sql($requete_sql);
$nb_fiche = mysql_num_rows($reponse_fiche);
if($nb_fiche < 1){
$requete_sql = "INSERT INTO fiche (affiche, projet_id, eleve_id, aff_source)
VALUES ('" . $link . "', '" . $projet . "', '" . $usager . "', '" . addslashes($HTTP_POST_VARS['sourceA']) . "')
";
}
else{
$requete_sql = "UPDATE fiche
SET affiche = '" . $link . "',
aff_source = '" . addslashes($HTTP_POST_VARS['sourceA']) . "'
WHERE fiche_id = '" . $HTTP_POST_VARS['id_fiche'] . "'
";
}
$reponse_mod_nouv = bd_executer_sql($requete_sql);
$HTTP_SESSION_VARS['SESSION']['message'] = "Ta pancarte électorale a été téléchargée.";
$HTTP_SESSION_VARS['SESSION']['onglet'] = 2;
header("Location: ele_fiche.php");
}
// **************** Fin Update ****************
}
}
if($HTTP_POST_VARS['type_action'] == "source_aff"){
$requete_sql = "UPDATE fiche
SET aff_source = '" . addslashes($HTTP_POST_VARS['sourceA']) . "'
WHERE fiche_id = '" . $HTTP_POST_VARS['id_fiche'] . "'
";
$reponse_mod_aff_source = bd_executer_sql($requete_sql);
$HTTP_SESSION_VARS['SESSION']['message'] = "La source de ta pancarte électorale à été mise à jour.";
$HTTP_SESSION_VARS['SESSION']['onglet'] =2;
header("Location: ele_fiche.php");
}
if ($HTTP_POST_VARS['type_action'] == "eff_aff"){
########### DELETE FILE DS RÉPERTOIRE PANCARTE ###########
/*
$requete_sql = "SELECT *
FROM projet
WHERE projet_id = $projet
";
$reponse_projet = bd_executer_sql($requete_sql);
$ligne = mysql_fetch_array($reponse_projet);
$nom = str_replace(" ", "_",$ligne[nom]);
$fichier = "pancartes/".$projet."_".$nom."/".$usager.".jpg";
*/
$fichier = "pancartes/projet_".$projet."/".$usager.".jpg";
if (is_file($fichier)) {
unlink($fichier);
} else {
# $fichier = "pancartes/".$projet."_".$nom."/".$usager.".gif";
$fichier = "pancartes/projet_".$projet."/".$usager.".gif";
if (is_file($fichier)) unlink($fichier);
}
$requete_sql = "SELECT * FROM fiche WHERE eleve_id = \"$usager\"";
$reponse_fiche = bd_executer_sql($requete_sql);
$ligne_fiche = mysql_fetch_array($reponse_fiche);
if($ligne_fiche['slogan'] != ""){
$requete_sql = "UPDATE fiche
SET affiche = \"\",
aff_source = \"\"
WHERE fiche_id = \"$HTTP_POST_VARS[id_fiche]\"
";
}
else{
$requete_sql = "DELETE FROM fiche
WHERE fiche_id = \"$HTTP_POST_VARS[id_fiche]\"
";
}
$reponse_mod_nouv = bd_executer_sql($requete_sql);
$HTTP_SESSION_VARS['SESSION']['message'] = "Ta pancarte électorale a été supprimée.";
$HTTP_SESSION_VARS['SESSION']['onglet'] = 2;
header("Location: ele_fiche.php");
}
if ($HTTP_POST_VARS['type_action'] == "soumettre"){
$date = date("Y-m-d");
$requete_sql = "UPDATE fiche
SET date_soumis = \"$date\",
desactive = 0
WHERE eleve_id = $usager
";
$reponse_date = bd_executer_sql($requete_sql);
$HTTP_SESSION_VARS['SESSION']['message']="Ta fiche a été soumise!";
$HTTP_SESSION_VARS['SESSION']['onglet'] = 3;
header("Location: ele_fiche.php");
}
?>