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

	#########################################################################################
	# Gestion des groupes de Pnyx - script bdd												#
	# 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";
	
		# verifier si la session est valide 
		# puis verifier si l'usager dispose des autorisations requises
		# pour la saisie
		verifier_session();
		acces_resp("rsp_groupe.php");
		
	/*$projet = $HTTP_SESSION_VARS[SESSION][projet];
	$usager = $HTTP_SESSION_VARS[SESSION][usager_id];*/
	$date = date("Y-m-d");

	#CHANGER DE GROUPE AFFICHÉ
	if ($HTTP_POST_VARS['type_action'] == "chg_grp"){
		
		$page = "rsp_groupe.php?id_groupe=".$HTTP_POST_VARS['groupe'];		
		header("Location: $page");
	}
	
	#SUPPRIMER UN GROUPE
	if ($HTTP_POST_VARS['type_action'] == "eff_groupe"){
	
		$requete_sql = "SELECT eleve_id FROM eleve
						WHERE groupe_id = \"$HTTP_POST_VARS[id_groupe]\"
  						";
		$reponse_eleve = bd_executer_sql($requete_sql);
			
		while ($ligne_eleve = mysql_fetch_array($reponse_eleve)){
				
				$requete_sql = "SELECT * FROM fiche
								WHERE eleve_id = \"$ligne_eleve[eleve_id]\"
  								";
				$reponse_fiche = bd_executer_sql($requete_sql);
				while ($ligne_fiche = mysql_fetch_array($reponse_fiche)){
			
					/*$requete_sql = "DELETE FROM fiche
									WHERE fiche_id = \"$ligne_fiche[fiche_id]\"
  									";
					$reponse_sup_app = bd_executer_sql($requete_sql);*/
					
					$requete_sql = "DELETE FROM election
							WHERE fiche_id = \"$ligne_fiche[fiche_id]\"
							AND projet_id = $projet
  							";
			$reponse_sup_fiche = bd_executer_sql($requete_sql);
				}
				$requete_sql = "DELETE FROM fiche
								WHERE eleve_id = \"$ligne_eleve[eleve_id]\"
  								";
				$reponse_sup_fiche = bd_executer_sql($requete_sql);
		
				/*$requete_sql = "DELETE FROM fiche
								WHERE eleve_id = \"$ligne_eleve[eleve_id]\"
  								";
				$reponse_sup_prop = bd_executer_sql($requete_sql);*/
				
				$requete_sql = "SELECT * FROM eleve
						WHERE eleve_id = \"$ligne_eleve[eleve_id]\"
						AND projet_id = $projet
  						";
			$reponse_vote = bd_executer_sql($requete_sql);
			$ligne_vote = mysql_fetch_array($reponse_vote);
			
			$requete_sql = "UPDATE election 
							SET nb_votes = nb_votes - 1
							WHERE fiche_id = \"$ligne_vote[fiche_vote]\"
							AND projet_id = $projet
  						";
			$reponse_elect = bd_executer_sql($requete_sql);
				
			/*$requete_sql = "DELETE FROM eleve
							WHERE eleve_id = \"$ligne_vote[eleve_id]\"
  							";
			$reponse_sup_prop = bd_executer_sql($requete_sql);*/
			
			$requete_sql = "DELETE FROM bloc_msg
							WHERE eleve_bloc = \"$ligne_eleve[eleve_id]\"
  							";
			$reponse_sup_prop = bd_executer_sql($requete_sql);
				
				$requete_sql = "DELETE FROM usager
								WHERE usager_id = \"$ligne_eleve[usager_id]\"
  								";
				$reponse_sup_log = bd_executer_sql($requete_sql);
				
				$requete_sql = "DELETE FROM eleve
							WHERE eleve_id = \"$ligne_eleve[eleve_id]\"
  							";
				$reponse_sup_eleve = bd_executer_sql($requete_sql);
			
			}
		$requete_sql = "DELETE FROM groupe
						WHERE groupe_id = \"$HTTP_POST_VARS[id_groupe]\"
  						";
		$reponse_sup_groupe = bd_executer_sql($requete_sql);
			
		
		$requete_sql = "SELECT * FROM groupe
						WHERE resp_id = $usager
						AND projet_id = $projet
  						";
		$reponse_grp = bd_executer_sql($requete_sql);
		$nb_grp = mysql_num_rows($reponse_grp);
		
#		echo $requete_sql;
		
		$requete_sql = "UPDATE lien_resp_projet
    					SET nb_groupe = \"$nb_grp\"
						WHERE resp_id = $usager
						AND projet_id = $projet
  						";
		$reponse_mod_lien = bd_executer_sql($requete_sql);
		
		
		$HTTP_SESSION_VARS['SESSION']['message'] = "Le groupe a été supprimé.";
		
		$page = "rsp_groupe.php";
		
		header("Location: $page");
	}
	
	if ($HTTP_POST_VARS['type_action'] == "inserer"){

		#VÉRIFICATION SI LE NOM DE GROUPE EXISTE DÉJÀ
		$requete_sql = "SELECT * 
						FROM groupe
    					WHERE nom = \"".addslashes($HTTP_POST_VARS["nom"])."\"
  						";
		$reponse_ver = bd_executer_sql($requete_sql);
		$ver = mysql_num_rows($reponse_ver);
		
		#SI OUI
		if ($ver > 0){
			$HTTP_SESSION_VARS['SESSION']['message'] = "Ce nom de groupe a déjà été choisi.";
			$HTTP_SESSION_VARS['SESSION']['onglet'] = 2;
			header("Location: rsp_groupe.php");
		} else {
		
			#VÉRIFICATION SI LE MOT DE PASSE DE GROUPE EXISTE DÉJÀ
				$requete_sql = "SELECT * 
								FROM groupe
								WHERE password = \"$HTTP_POST_VARS[password]\"
								";
				$reponse_ver = bd_executer_sql($requete_sql);
				$ver = mysql_num_rows($reponse_ver);
			
				#SI OUI
				if ($ver > 0){
					$HTTP_SESSION_VARS['SESSION']['message'] = "Ce mot de passe de groupe a déjà été choisi.";
					$HTTP_SESSION_VARS['SESSION']['onglet'] = 2;
					header("Location: rsp_groupe.php");
				} else {
		
				$requete_sql = "INSERT INTO groupe (nom, password, limite, niveau, 
													type, resp_id, projet_id)
								VALUES ( \"".addslashes($HTTP_POST_VARS["nom"])."\", '" . $HTTP_POST_VARS['password'] . "',
										 \"$HTTP_POST_VARS[limite]\", 
										 \"$HTTP_POST_VARS[niveau]\",
										 \"$HTTP_POST_VARS[type]\", $usager, $projet)
								";
				$reponse_ins = bd_executer_sql($requete_sql);
				
				$nouv_groupe = mysql_insert_id();
				
				$requete_sql = "SELECT * 
								FROM lien_resp_projet
								WHERE resp_id = $usager
								AND projet_id = $projet
								";
				$reponse_lien = bd_executer_sql($requete_sql);
				$nb_lien = mysql_num_rows($reponse_lien);
				
				if ($nb_lien >0){
				
					$requete_sql = "SELECT * 
									FROM groupe
									WHERE resp_id = $usager
									AND projet_id = $projet
									";
					$reponse_grp = bd_executer_sql($requete_sql);
					$nb_grp = mysql_num_rows($reponse_grp);
					
					$requete_sql = "UPDATE lien_resp_projet
									SET nb_groupe = $nb_grp
									WHERE resp_id = $usager
									AND projet_id = $projet
									";
					$reponse_proj = bd_executer_sql($requete_sql);
				}
				
				$HTTP_SESSION_VARS['SESSION']['message'] = "Le groupe a été ajouté.";
				
				$page = "rsp_groupe.php?id_groupe=".$nouv_groupe;
				
				header("Location: $page");
		
			}
		}
	}
	
	if ($HTTP_POST_VARS['type_action'] == "act_groupe"){
		$requete_sql = "SELECT * 
						FROM eleve
    					WHERE groupe_id = '" . $HTTP_POST_VARS['id_groupe'] . "'
						AND projet_id = $projet
  						";
		$reponse_grp = bd_executer_sql($requete_sql);
		
		while ($ligne = mysql_fetch_array($reponse_grp)){
			
			$requete_sql = "UPDATE eleve
							SET valide = 1,
								date_valide = \"$date\"
							WHERE eleve_id = '" . $ligne['eleve_id'] . "'
							AND projet_id = $projet
							";
			$reponse_proj = bd_executer_sql($requete_sql);
		}
		
		$HTTP_SESSION_VARS['SESSION']['message'] = "Tous les élèves du groupe sont validés.";
		
		$page = "rsp_groupe.php?id_groupe=".$HTTP_POST_VARS['id_groupe'];
		
		header("Location: $page");
		
	
	}

	
	
	
	
?>

Return current item: Pnyx : des lections virtuelles!