<?php
#########################################################################################
# Fonctions AJAX de Pnyx #
# Auteur : B. Leblanc #
# Création : 2008 #
# Modification : 2008 #
# #
# 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 #
#########################################################################################
//$_POST = array_map(utf8_decode, $_POST);
require "constantes.php";
//header('Content-Type: text/html; charset=ISO-8859-1');
$connection = mysql_connect($HOTE,$USAGER,$MOTPASSE) or die("Impossible de se connecter : " . mysql_error());
// Sélectionne une base de données MySQL, si cela n'est pas possible alors fin de l'exécution du code
if (!mysql_select_db($BD)){
die("Impossible d'accéder à la base de données : " . mysql_error());
}
$html = "";
if($_POST['type'] == 'CS'){
if(isset($_POST['ajouter'])){
if($_POST['idChoix'] == "toute"){
if($_POST['choix'] == "toute"){
mysql_query("UPDATE `ecole` SET `actif` = '1'");
}
else{
mysql_query("UPDATE `ecole` SET `actif` = '1' WHERE `comscol_id` = '" . $_POST['choix'] . "' ;");
}
}else{
mysql_query("UPDATE `ecole` SET `actif` = '1' WHERE `ecole_id` = '" . $_POST['idChoix'] . "' LIMIT 1 ;");
}
}
if(isset($_POST['supprimer'])){
if($_POST['idChoix'] == "toute"){
mysql_query("UPDATE `ecole` SET `actif` = '0'");
}else{
mysql_query("UPDATE `ecole` SET `actif` = '0' WHERE `ecole_id` = '" . $_POST['idChoix'] . "' LIMIT 1 ;");
}
}
if($_POST['choix'] != "toute"){
$requete_sql = "SELECT nom, ecole_id
FROM ecole
WHERE comscol_id = '" . $_POST['choix'] . "'
AND actif = '0'
ORDER BY nom
";
}
else{
$requete_sql = "SELECT nom, ecole_id
FROM ecole
WHERE actif = '0'
ORDER BY nom
";
}
$reponse_ecoleCSG = mysql_query($requete_sql);
$requete_sql = "SELECT nom, ecole_id
FROM ecole
WHERE actif = '1'
ORDER BY nom
";
$reponse_ecoleCSD = mysql_query($requete_sql);
$html .= "<br /><table id=\"tabEcole\">";
$html .= "<tr>";
$html .= "<td rowspan=\"3\">";
$html .= "<select size=\"10\" name=\"listeEcoleG\" id=\"listeEcoleG\">";
while($ligne_ecoleCSG = mysql_fetch_array($reponse_ecoleCSG)){
$html .= "<option value='" . $ligne_ecoleCSG['ecole_id'] . "'>" . utf8_encode($ligne_ecoleCSG['nom']) . "</option>";
}
$html .= "<option value=\"toute\">Toutes ces écoles</option>";
$html .= "</select>";
$html .= "</td>";
$html .= "<td></td>";
$html .= "<td rowspan=\"3\">";
$html .= "<select size=\"10\" name=\"listeEcoleD\" id=\"listeEcoleD\">";
while($ligne_ecoleCSD = mysql_fetch_array($reponse_ecoleCSD)){
if($ligne_ecoleCSD['nom'] != 'autre'){
$html .= "<option value='" . $ligne_ecoleCSD['ecole_id'] . "'>" . utf8_encode($ligne_ecoleCSD['nom']) . "</option>";
}
}
$html .= "<option value=\"toute\">Toutes ces écoles</option>";
$html .= "</select>";
$html .= "</td>";
$html .= "</tr>";
$html .= "<tr>";
$html .= "<td>";
$html .= "<input type=\"button\" value=\"ajouter\" id=\"boutonEcole\" onclick=\"ajouterEcole('listeCS', 'listeEcoleG', '" . $_POST['type'] . "')\" /><br />";
$html .= "<input type=\"button\" value=\"supprimer\" id=\"boutonEcole\" onclick=\"supprimerEcole('listeCS', 'listeEcoleD', '" . $_POST['type'] . "')\" />";
$html .= "</td>";
$html .= "</tr>";
$html .= "<tr>";
$html .= "<td>";
$html .= "</td>";
$html .= "</tr>";
$html .= "</table>";
$html .= "En supprimant une école d'un projet, il ne sera plus possible de la choisir lors de l'inscription. Toutefois, ceux déjà inscrits avec cet école peuvent continuer à participer au projet.";
}
mysql_close($connection);
echo $html;
?>