Location: PHPKode > projects > Pnyx : des lections virtuelles! > pnyx1.0.1/adm_projet2.php
<?php

	#########################################################################################
	# Gestion des projets de Pnyx - scripts bdd												#
	# Auteur : V. Blais																		#
	# Création : 2006-04-05																	#
	# Modification : 2008-08-12																#
	# 																						#
	# 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";
	
	#ARCHIVER LE PROJET EN COURS
	if ($HTTP_POST_VARS['type_action'] == "archiver"){
		
		$requete_sql = "UPDATE projet
    					SET statut = \"archive\"
						WHERE projet_id = $projet
  						";
		$reponse_archivage = bd_executer_sql($requete_sql);
		
		$requete_sql = "UPDATE lien_resp_projet
    					SET valide = 0,
						date_valide = 0000-00-00
						WHERE projet_id = $projet
  						";
		$reponse_archivage = bd_executer_sql($requete_sql);
		
		$HTTP_SESSION_VARS['SESSION']['projet'] = 0;
		$HTTP_SESSION_VARS['SESSION']['periode'] = "Aucun";
		$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
		$HTTP_SESSION_VARS['SESSION']['message'] = "Le projet a été archivé.";
		
		header("Location: adm_projet.php");
	
	}
	
	#VOIR UN PROJET ARCHIVÉ
	if ($HTTP_POST_VARS['type_action'] == "voir_arch"){
		$HTTP_SESSION_VARS['SESSION']['projet_admin'] = $HTTP_POST_VARS['id_projet'];
		header("Location: adm_enregistrement.php");
	
	}
	
	#CREER UN NOUVEAU PROJET
	if ($HTTP_POST_VARS['type_action'] == "inserer"){

		$requete_sql = "INSERT INTO projet (nom, statut, periode)
    					VALUES ( \"$HTTP_POST_VARS[nom]\",\"actif\", \"debut\")
  						";
		$reponse_ins = bd_executer_sql($requete_sql);
		
		if(isset($_POST['niveau_int'])){
			$nivInt = "1";
		} else {
			$nivInt = "0";
		}	
		mysql_query("UPDATE `projet` SET `international` = '" . $nivInt . "' ;");
		
		if(isset($_POST['niveau_nat'])){
			$nivNat = "1";
		} else {
			$nivNat = "0";
		}	
		mysql_query("UPDATE `projet` SET `national` = '" . $nivNat . "' ;");
		
		if(isset($_POST['niveau_loc'])){
			$nivLoc = "1";
		} else {
			$nivLoc = "0";
		}	
		mysql_query("UPDATE `projet` SET `local` = '" . $nivLoc . "' ;");
		
		if(isset($_POST['niveau_1cyclePrim'])){
			$niv1Prim = "1";
		} else {
			$niv1Prim = "0";
		}	
		mysql_query("UPDATE `projet` SET `cycle1p` = '" . $niv1Prim . "' ;");
		
		if(isset($_POST['niveau_2cyclePrim'])){
			$niv2Prim = "1";
		} else {
			$niv2Prim = "0";
		}	
		mysql_query("UPDATE `projet` SET `cycle2p` = '" . $niv2Prim . "' ;");
		
		if(isset($_POST['niveau_3cyclePrim'])){
			$niv3Prim = "1";
		} else {
			$niv3Prim = "0";
		}	
		mysql_query("UPDATE `projet` SET `cycle3p` = '" . $niv3Prim . "' ;");
		
		if(isset($_POST['niveau_1cycleSec'])){
			$niv1Sec = "1";
		} else {
			$niv1Sec = "0";
		}	
		mysql_query("UPDATE `projet` SET `cycle1s` = '" . $niv1Sec . "' ;");
		
		if(isset($_POST['niveau_2cycleSec'])){
			$niv2Sec = "1";
		} else {
			$niv2Sec = "0";
		}	
		mysql_query("UPDATE `projet` SET `cycle2s` = '" . $niv2Sec . "' ;");
		
		if(isset($_POST['groupe_classe'])){
			$grpClasse = "1";
		} else {
			$grpClasse = "0";
		}	
		mysql_query("UPDATE `projet` SET `classe_reg = '" . $grpClasse . "' ;");

		if(isset($_POST['groupe_conseil'])){
			$grpConseil = "1";
		} else {
			$grpConseil = "0";
		}	
		mysql_query("UPDATE `projet` SET `conseil` = '" . $grpConseil . "' ;");

		if(isset($_POST['groupe_parasco'])){
			$grpParasco = "1";
		} else {
			$grpParasco = "0";
		}	
		mysql_query("UPDATE `projet` SET `parasco` = '" . $grpParasco . "' ;");
		
		if(isset($_POST['groupe_autre'])){
			$grpAutre = "1";
		} else {
			$grpAutre = "0";
		}	
		mysql_query("UPDATE `projet` SET `autre` = '" . $grpAutre . "' ;");

		$requete_sql = mysql_query("SELECT COUNT(*)
									AS nbCat
									FROM categorie_prop
									");
		$nbCat = mysql_fetch_array($requete_sql);
		$nbCatF = $nbCat['nbCat'];
		for($i=1; $i<=$nbCatF; $i++){
			$quelCat = "catProp_" . $i;
			if($HTTP_POST_VARS[$quelCat] == 1){
				mysql_query("UPDATE categorie_prop
							 SET actif = '1'
							 WHERE cat_id = " . $i . "");
			}else{
				mysql_query("UPDATE categorie_prop
							 SET actif = '0'
							 WHERE cat_id = " . $i . "");
			}
		}
		
		$requete_sql = mysql_query("SELECT projet_id FROM projet WHERE statut = \"actif\"");
				
		$nouv_projet = mysql_fetch_array($requete_sql);
		$HTTP_SESSION_VARS['SESSION']['projet'] = $nouv_projet['projet_id'];
		$HTTP_SESSION_VARS['SESSION']['periode'] = "debut";
		$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
		
		$dir = "pancartes/projet_".$nouv_projet['projet_id'];
		
		mkdir($dir, 0410);
		chmod($dir, 0777);
		
		$requete_sql = "INSERT INTO nouvelles (texte, projet_id)
    					VALUES ( \"<p>Aucune nouvelle.</p>\", '" . $nouv_projet['projet_id'] . "')
  						";
		$reponse_ins = bd_executer_sql($requete_sql);
		
		$requete_sql = "INSERT INTO dates_importantes (texte, projet_id)
    					VALUES ( \"<p>Aucune date.</p>\", '" . $nouv_projet['projet_id'] . "')
  						";
		$reponse_ins = bd_executer_sql($requete_sql);
		
		#CRÉATION DES COMPTE ENSEIGNANTS NON-VALIDÉS POUR LE NOUVEAU PROJET
		$requete_sql = "SELECT resp_id 
    					FROM responsable
  						";
		$reponse_resp = bd_executer_sql($requete_sql);
		
		while ($ligne_resp = mysql_fetch_array($reponse_resp)){
			
			$requete_sql = "INSERT INTO lien_resp_projet (resp_id, projet_id, valide, date_valide, nb_groupe)
    					VALUES ( \"$ligne_resp[resp_id]\", '" . $nouv_projet['projet_id'] . "', \"0\", \"0000-00-00\", \"0\")
  						";
			$reponse_ins = bd_executer_sql($requete_sql);
		}		
		$HTTP_SESSION_VARS['SESSION']['message'] = "Le projet a été ajouté.";
		
		header("Location: adm_projet.php");
	
	}
	
	#SUPPRIMER UN PROJET
	if ($HTTP_POST_VARS['type_action'] == "supprimer" || $HTTP_POST_VARS['type_action'] == "nouveau"){
	
		$requete_sql = "DELETE FROM dates_periodes
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_sup_dates = bd_executer_sql($requete_sql);
		
		$requete_sql = "DELETE FROM dates_importantes
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_sup_dates_imp = bd_executer_sql($requete_sql);
		
		$requete_sql = "DELETE FROM fiche
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_sup_fiche = bd_executer_sql($requete_sql);
		
		$requete_sql = "DELETE FROM bloc_msg
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_sup_app = bd_executer_sql($requete_sql);
		
		$requete_sql = "DELETE FROM msg_resp
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_sup_app = bd_executer_sql($requete_sql);
		
		$requete_sql = "DELETE FROM msg_fil
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_sup_app = bd_executer_sql($requete_sql);
		
		$requete_sql = "DELETE FROM fil_discussion
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_sup_app = bd_executer_sql($requete_sql);
		
		$requete_sql = "DELETE FROM election
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_sup_elect = bd_executer_sql($requete_sql);
		
		$requete_sql = "SELECT usager_id FROM eleve
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_log = bd_executer_sql($requete_sql);
		while ($ligne_log = mysql_fetch_array($reponse_log)){
		
			$requete_sql = "DELETE FROM usager
							WHERE usager_id = \"$ligne_log[usager_id]\"
  							";
			$reponse_sup_log = bd_executer_sql($requete_sql);
		}
		$requete_sql = "DELETE FROM eleve
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_sup_eleve = bd_executer_sql($requete_sql);
		
		$requete_sql = "DELETE FROM groupe
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_sup_groupe = bd_executer_sql($requete_sql);
		
		$requete_sql = "DELETE FROM lien_resp_projet
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_sup_resp = bd_executer_sql($requete_sql);
		
		$requete_sql = "DELETE FROM nouvelles
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_sup_nouv = bd_executer_sql($requete_sql);
		
		$requete_sql = "SELECT * FROM projet
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_projet = bd_executer_sql($requete_sql);
		$ligne = mysql_fetch_array($reponse_projet);
		
		$dir = "pancartes/projet_".$ligne[projet_id];
		
		rmdir($dir);
		
		$requete_sql = "DELETE FROM projet
						WHERE projet_id = \"$HTTP_POST_VARS[id_projet]\"
  						";
		$reponse_sup_projet = bd_executer_sql($requete_sql);
		
		$HTTP_SESSION_VARS['SESSION']['message'] = "Le projet a été supprimé.";
		$HTTP_SESSION_VARS['SESSION']['onglet'] = 5;
		
		header("Location: adm_projet.php");
	
	}
	
	#MODIFIER LES NOUVELLES DU PROJET EN COURS
	if ($HTTP_POST_VARS['type_action'] == "mod_nouv"){
		$texteN = addslashes($HTTP_POST_VARS['texteN']);
		$requete_sql = "UPDATE nouvelles
    					SET texte = \"$texteN\"
						WHERE nouvelle_id = \"$HTTP_POST_VARS[id_nouv]\"
  						";
		$reponse_mod_nouv = bd_executer_sql($requete_sql);
		
		$HTTP_SESSION_VARS['SESSION']['message'] = "Les nouvelles ont été modifiées.";
		$HTTP_SESSION_VARS['SESSION']['onglet'] = 3;
		
		header("Location: adm_projet.php");
	
	}
	
	#MODIFIER LES DATES IMPORTANTES DU PROJET EN COURS
	if ($HTTP_POST_VARS['type_action'] == "mod_dates"){
		$texteD = addslashes($HTTP_POST_VARS['texteD']);
		$requete_sql = "UPDATE dates_importantes
    					SET texte = \"$texteD\"
						WHERE date_id = \"$HTTP_POST_VARS[id_date]\"
  						";
		$reponse_mod_date = bd_executer_sql($requete_sql);
		
		$HTTP_SESSION_VARS['SESSION']['message'] = "Les dates importantes ont été modifiées.";
		$HTTP_SESSION_VARS['SESSION']['onglet'] = 4;
		
		header("Location: adm_projet.php");
	}

	#ACTIVER LA PERIODE DE CANDIDATURE
	if ($HTTP_POST_VARS['type_action'] == "act_cand"){
		
		$requete_sql = "INSERT INTO dates_periodes (periode, date, projet_id)
    					VALUES ( \"debut_candidature\", \"$date\", \"$projet\")
  						";
		$reponse_mod_statut_cand = bd_executer_sql($requete_sql);
			
		$requete_sql = "UPDATE projet
    					SET periode = \"cand\"
						WHERE projet_id = \"$projet\"
  						";
		$reponse_mod_statut_proj = bd_executer_sql($requete_sql);
			
		$HTTP_SESSION_VARS['SESSION']['message'] = "La période de candidature est activée.";
		$HTTP_SESSION_VARS['SESSION']['periode'] = "cand";
		$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
			
		header("Location: adm_projet.php");
	}
	
	#TERMINER LA PERIODE DE CANDIDATURE
	if ($HTTP_POST_VARS['type_action'] == "end_cand"){
			
		$requete_sql = "INSERT INTO dates_periodes (periode, date, projet_id)
    					VALUES ( \"fin_candidature\", \"$date\", \"$projet\")
  						";
		$reponse_mod_statut_cand = bd_executer_sql($requete_sql);
			
		$requete_sql = "UPDATE projet
    					SET periode = \"fin_cand\"
						WHERE projet_id = \"$projet\"
  						";
		$reponse_mod_statut_proj = bd_executer_sql($requete_sql);
			
		$HTTP_SESSION_VARS['SESSION']['message'] = "La période de candidature est terminée.";
		$HTTP_SESSION_VARS['SESSION']['periode'] = "fin_cand";
		$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
			
		header("Location: adm_projet.php");
	}  
	
	#DESACTIVER LA PERIODE DE CANDIDATURE
	if ($HTTP_POST_VARS['type_action'] == "desact_cand"){
			
		$requete_sql = "DELETE FROM dates_periodes
    					WHERE date_id = \"$HTTP_POST_VARS[id_date]\"
  						";
		$reponse_mod_statut_cand = bd_executer_sql($requete_sql);
			
		$requete_sql = "UPDATE projet
    					SET periode = \"debut\"
						WHERE projet_id = \"$projet\"
  						";
		$reponse_mod_statut_proj = bd_executer_sql($requete_sql);
			
		$HTTP_SESSION_VARS['SESSION']['message'] = "La période de candidature est désactivée.";
		$HTTP_SESSION_VARS['SESSION']['periode'] = "debut";
		$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
			
		header("Location: adm_projet.php");
	} 
	
	#REACTIVER LA PERIODE DE CANDIDATURE
	if ($HTTP_POST_VARS['type_action'] == "react_cand"){
			
		$requete_sql = "DELETE FROM dates_periodes
    					WHERE date_id = \"$HTTP_POST_VARS[id_date]\"
  						";
		$reponse_mod_statut_cand = bd_executer_sql($requete_sql);
			
		$requete_sql = "UPDATE projet
    					SET periode = \"cand\"
						WHERE projet_id = \"$projet\"
  						";
		$reponse_mod_statut_proj = bd_executer_sql($requete_sql);
			
		$HTTP_SESSION_VARS['SESSION']['message'] = "La période de candidature est réactivée.";
		$HTTP_SESSION_VARS['SESSION']['periode'] = "cand";
		$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
			
		header("Location: adm_projet.php");
	}
	
	#ACTIVER LA PERIODE DE VOTE
	if ($HTTP_POST_VARS['type_action'] == "act_vote"){
		
		$requete_sql = "INSERT INTO dates_periodes (periode, date, projet_id)
    					VALUES ( \"debut_vote\", \"$date\", \"$projet\")
  						";
		$reponse_mod_statut_cand = bd_executer_sql($requete_sql);
			
		$requete_sql = "UPDATE projet
    					SET periode = \"vote\"
						WHERE projet_id = \"$projet\"
  						";
		$reponse_mod_statut_proj = bd_executer_sql($requete_sql);
			
		$HTTP_SESSION_VARS['SESSION']['message'] = "La période de vote est activée.";
		$HTTP_SESSION_VARS['SESSION']['periode'] = "vote";
		$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
			
		header("Location: adm_projet.php");
	} 
	
	#TERMINER LA PERIODE DE VOTE
	if ($HTTP_POST_VARS['type_action'] == "end_vote"){
			
		$requete_sql = "INSERT INTO dates_periodes (periode, date, projet_id)
    					VALUES ( \"fin_vote\", \"$date\", \"$projet\")
  						";
		$reponse_mod_statut_cand = bd_executer_sql($requete_sql);
			
		$requete_sql = "UPDATE projet
    					SET periode = \"fin_vote\"
						WHERE projet_id = \"$projet\"
  						";
		$reponse_mod_statut_proj = bd_executer_sql($requete_sql);
			
		$HTTP_SESSION_VARS['SESSION']['message'] = "La période de vote est terminée.";
		$HTTP_SESSION_VARS['SESSION']['periode'] = "fin_vote";
		$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
			
		header("Location: adm_projet.php");
	}  
	
	#DESACTIVER LA PERIODE DE VOTE
	if ($HTTP_POST_VARS['type_action'] == "desact_vote"){
			
		$requete_sql = "DELETE FROM dates_periodes
    					WHERE date_id = \"$HTTP_POST_VARS[id_date]\"
  						";
		$reponse_mod_statut_cand = bd_executer_sql($requete_sql);
		
		$requete_sql = "UPDATE eleve
    					SET vote = \"0\",
						fiche_vote = \"0\",
						justification = \"\"
						WHERE projet_id = \"$projet\"
  						";
		$reponse_mod_statut_cand = bd_executer_sql($requete_sql);
		
		$requete_sql = "UPDATE election
    					SET nb_votes = \"0\"
						WHERE projet_id = \"$projet\"
  						";
		$reponse_mod_statut_proj = bd_executer_sql($requete_sql);
			
		$requete_sql = "UPDATE projet
    					SET periode = \"fin_cand\"
						WHERE projet_id = \"$projet\"
  						";
		$reponse_mod_statut_proj = bd_executer_sql($requete_sql);
			
		$HTTP_SESSION_VARS['SESSION']['message'] = "La période de vote est désactivée.";
		$HTTP_SESSION_VARS['SESSION']['periode'] = "fin_cand";
		$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
			
		header("Location: adm_projet.php");
	} 
	
	#REACTIVER LA PERIODE DE VOTE
	if ($HTTP_POST_VARS['type_action'] == "react_vote"){
			
		$requete_sql = "DELETE FROM dates_periodes
    					WHERE date_id = \"$HTTP_POST_VARS[id_date]\"
  						";
		$reponse_mod_statut_cand = bd_executer_sql($requete_sql);
			
		$requete_sql = "UPDATE projet
    					SET periode = \"vote\"
						WHERE projet_id = \"$projet\"
  						";
		$reponse_mod_statut_proj = bd_executer_sql($requete_sql);
			
		$HTTP_SESSION_VARS['SESSION']['message'] = "La période de vote est réactivée.";
		$HTTP_SESSION_VARS['SESSION']['periode'] = "vote";
		$HTTP_SESSION_VARS['SESSION']['onglet'] = 1;
			
		header("Location: adm_projet.php");
	}
	
	
?>
Return current item: Pnyx : des lections virtuelles!