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

	#########################################################################################
	# Inscription d'élèves de Pnyx - scripts bdd											#
	# Auteur : V. Blais																		#
	# Création : 2006-05-02																	#
	# Modification : 2008-07-01																#
	# 																						#
	# 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";
	
		# ou verifier si la session est valide 
		# puis verifier si l'usager dispose des autorisations requises
		# pour la saisie
		verifier_session();
		acces_resp("insc_eleve.php");
		
	/*$projet = $HTTP_SESSION_VARS['SESSION']['projet'];
	$niveau = $HTTP_SESSION_VARS['SESSION']['niveau'];*/
	
		$requete_sql = "SELECT *
    				FROM groupe
					WHERE groupe_id = \"$HTTP_POST_VARS[id_groupe]\"
  					";
		$reponse_mdpg = bd_executer_sql($requete_sql);
		$ver = mysql_num_rows($reponse_mdpg);
		$ligne_groupe = mysql_fetch_array($reponse_mdpg);
			
			$requete_sql = "SELECT *
    					FROM usager
						WHERE login = \"".addslashes($HTTP_POST_VARS["login"])."\"
  						";
			$reponse_log = bd_executer_sql($requete_sql);
			$ver = mysql_num_rows($reponse_log);
			
#			echo $requete_sql;
#			echo $ver;

			if ($ver > 0){
				$HTTP_SESSION_VARS['SESSION']['message'] = "Le nom d'utilisateur (pseudonyme) est déjà pris.";
				
				$page = "insc_eleve.php?id_groupe=".$ligne_groupe['groupe_id'];
				header("Location: $page");
			} else {
				$requete_sql = "SELECT *
    							FROM eleve
								WHERE groupe_id = \"$ligne_groupe[groupe_id]\"
  								";
				$reponse_log = bd_executer_sql($requete_sql);
				$ver = mysql_num_rows($reponse_log);
				
				if ($ver == $ligne_groupe['limite'] && $ver != 0){
					$HTTP_SESSION_VARS['SESSION']['message'] = "Le nombre maximal d'élèves pour ce groupe est atteint.";
				
					$page = "insc_eleve.php?id_groupe=".$ligne_groupe['groupe_id'];
					header("Location: $page");
				} else {
		
				$requete_sql = "INSERT INTO usager (login, password, type)
    							VALUES ( \"".addslashes($HTTP_POST_VARS["login"])."\", '" . sha1($HTTP_POST_VARS['password']) . "',
								 	\"eleve\")
  								";
				$reponse_log = bd_executer_sql($requete_sql);
#				echo $requete_sql."<br>";
		
				$idu = mysql_insert_id();
				
				$cand = 0;
				
				if ($HTTP_SESSION_VARS['SESSION']['periode'] == "cand" || $HTTP_SESSION_VARS['SESSION']['periode'] == "debut"){
					$cand = 1;
				}
				$date = date("Y-m-d");
				
				if($niveau == "admin"){
					$requete_sql = "SELECT valide
    								FROM lien_resp_projet
									WHERE resp_id = $ligne_groupe[resp_id]
									AND projet_id = $projet
  							";
					$reponse_val = bd_executer_sql($requete_sql);
					$ligne_val = mysql_fetch_array($reponse_val);
					
					if ($ligne_val['valide'] == 1){
					
						$valide = 1;
					} else {
						$valide = 0;
					}
					
				} else if($niveau == "resp"){
					
					$idr = $HTTP_SESSION_VARS['SESSION']['usager_id'];
					$requete_sql = "SELECT valide
    								FROM lien_resp_projet
									WHERE resp_id = $idr
									AND projet_id = $projet
  							";
					$reponse_val = bd_executer_sql($requete_sql);
					$ligne_val = mysql_fetch_array($reponse_val);
					
					if ($ligne_val['valide'] == 1){
					
						$valide = 1;
					} else {
						$valide = 0;
					}
				}
				
				$requete_sql = "INSERT INTO eleve (nom, prenom, sexe, groupe_id, usager_id, 
									valide, date_valide, candidat, projet_id)
    							VALUES ( \"$HTTP_POST_VARS[nom]\", \"$HTTP_POST_VARS[prenom]\",
								 	\"$HTTP_POST_VARS[sexe]\", \"$ligne_groupe[groupe_id]\", $idu,
								 	\"$valide\", \"$date\", \"$cand\", $projet)
  								";
				$reponse_ins = bd_executer_sql($requete_sql);
#				echo $requete_sql;

				$ide = mysql_insert_id();
				
				$HTTP_SESSION_VARS['SESSION']['message'] = "L'élève ".$HTTP_POST_VARS['prenom']." ".$HTTP_POST_VARS['nom']." est maintenant inscrit dans ce groupe.";
				$page = "insc_eleve.php?insc=y";
				header("Location: $page");
			}
	}
	
?>
Return current item: Pnyx : des lections virtuelles!