<?php
#########################################################################################
# Page d'inscription de Pnyx - scripts bdd #
# Auteur : V. Blais #
# Création : 2006-04-05 #
# Modification : 2008-08-26 #
# #
# 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";
############################# CHOIX DU TYPE D'INSCRIPTION #########################################
if ($HTTP_POST_VARS['type_action'] == "choix"){
session_register("INSC");
if ($HTTP_POST_VARS['type_insc'] == "eleve"){
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_eleve";
} else if ($HTTP_POST_VARS['type_insc'] == "resp"){
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_resp1";
}
header("Location: gen_inscription.php");
}
if ($HTTP_POST_VARS['type_action'] == "annuler"){
session_unregister("INSC");
header("Location: gen_inscription.php");
}
############################# INSCRIPTION D'UN RESPONSABLE #########################################
#PARTIE 1 - MÉMORISATION DES INFORMATIONS SCOLAIRES
if ($HTTP_POST_VARS['type_action'] == "choix_ecoler"){
$HTTP_SESSION_VARS['INSC']['ecole'] = stripslashes($HTTP_POST_VARS['ecole']);
$HTTP_SESSION_VARS['INSC']['com_scol'] = stripslashes($HTTP_POST_VARS['com_scol']);
$HTTP_SESSION_VARS['INSC']['region'] = stripslashes($HTTP_POST_VARS['region']);
if(isset($HTTP_SESSION_VARS['INSC']['corr'])){
if ($HTTP_SESSION_VARS['INSC']['corr'] == "y"){
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_resp_conf";
$HTTP_SESSION_VARS['INSC']['corr'] = "";
}
} else {
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_resp2";
}
header("Location: gen_inscription.php");
}
if ($HTTP_POST_VARS['type_action'] == "corr1"){
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_resp1";
$HTTP_SESSION_VARS['INSC']['corr'] = "y";
header("Location: gen_inscription.php");
}
#PARTIE 2 - MÉMORISATION DES INFORMATIONS PERSONNELLES
if ($HTTP_POST_VARS['type_action'] == "infos_persr"){
$HTTP_SESSION_VARS['INSC']['prenom'] = stripslashes($HTTP_POST_VARS['prenom']);
$HTTP_SESSION_VARS['INSC']['nom'] = stripslashes($HTTP_POST_VARS['nom']);
$HTTP_SESSION_VARS['INSC']['fonction'] = stripslashes($HTTP_POST_VARS['fonction']);
$HTTP_SESSION_VARS['INSC']['password'] = stripslashes($HTTP_POST_VARS['password']);
$HTTP_SESSION_VARS['INSC']['pass_conf'] = stripslashes($HTTP_POST_VARS['pass_conf']);
#VÉRIFICATION SI LE LOGIN EXISTE DÉJÀ
$requete_sql = "SELECT *
FROM usager
WHERE login = \"$HTTP_POST_VARS[login]\"
";
$reponse_log = bd_executer_sql($requete_sql);
$ver = mysql_num_rows($reponse_log);
#SI OUI
if ($ver > 0){
$HTTP_SESSION_VARS['SESSION']['message'] = "Le nom d'utilisateur que vous avez choisi existe déjà.<br>
Vérifiez que vous avez entré votre courriel correctement.<br>
Si le problème persiste veuillez contacter les responsables du site par <a href='contact.php'>courriel</a>";
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_resp2";
$HTTP_SESSION_VARS['INSC']['login'] = "";
header("Location: gen_inscription.php");
#SI NON TOUT EST OK
} else {
$HTTP_SESSION_VARS['INSC']['login'] = $HTTP_POST_VARS['login'];
if(isset($HTTP_SESSION_VARS['INSC']['corr'])){
if ($HTTP_SESSION_VARS['INSC']['corr'] == "y"){
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_resp_conf";
$HTTP_SESSION_VARS['INSC']['corr'] = "";
}
} else {
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_resp3";
}
header("Location: gen_inscription.php");
}
}
if ($HTTP_POST_VARS['type_action'] == "corr2"){
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_resp2";
$HTTP_SESSION_VARS['INSC']['corr'] = "y";
header("Location: gen_inscription.php");
}
#PARTIE 3 - MÉMORISATION DES INFORMATIONS DU GROUPE
if ($HTTP_POST_VARS['type_action'] == "choix_groupe"){
#VÉRIFICATION SI LE NOM DE GROUPE EXISTE DÉJÀ
$requete_sql = "SELECT *
FROM groupe
WHERE nom = \"$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.";
header("Location: gen_inscription.php");
#SI NON
} 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.";
header("Location: gen_inscription.php");
#SI NON
} else {
#VÉRIFICATION SI LE MOT DE PASSE DE GROUPE ET LE MÊME QUE LE RESPONSABLE
#SI OUI
if($HTTP_SESSION_VARS['INSC']['password'] == $HTTP_POST_VARS['password']){
$HTTP_SESSION_VARS['SESSION']['message'] = "Ce mot de passe de groupe est le même que votre mot de passe de compte.";
header("Location: gen_inscription.php");
#SI NON
} else {
$HTTP_SESSION_VARS['INSC']['nom_groupe'] = stripslashes($HTTP_POST_VARS['nom']);
$HTTP_SESSION_VARS['INSC']['pass_groupe'] = stripslashes($HTTP_POST_VARS['password']);
if(isset($HTTP_SESSION_VARS['INSC']['corr'])){
if ($HTTP_SESSION_VARS['INSC']['corr'] == "y"){
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_resp_conf";
$HTTP_SESSION_VARS['INSC']['corr'] = "";
}
} else {
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_resp4";
}
header("Location: gen_inscription.php");
}
}
}
}
if ($HTTP_POST_VARS['type_action'] == "corr3"){
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_resp3";
$HTTP_SESSION_VARS['INSC']['corr'] = "y";
header("Location: gen_inscription.php");
}
#PARTIE 4 - MÉMORISATION DES PARAMETRES DU GROUPE
if ($HTTP_POST_VARS['type_action'] == "infos_groupe"){
$HTTP_SESSION_VARS['INSC']['niveau'] = stripslashes($HTTP_POST_VARS['niveau']);
$HTTP_SESSION_VARS['INSC']['type'] = stripslashes($HTTP_POST_VARS['type']);
$HTTP_SESSION_VARS['INSC']['limite'] = stripslashes($HTTP_POST_VARS['limite']);
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_resp_conf";
if(isset($HTTP_SESSION_VARS['INSC']['corr'])){
if ($HTTP_SESSION_VARS['INSC']['corr'] == "y"){
$HTTP_SESSION_VARS['INSC']['corr'] = "";
}
}
header("Location: gen_inscription.php");
}
if ($HTTP_POST_VARS['type_action'] == "corr4"){
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_resp4";
$HTTP_SESSION_VARS['INSC']['corr'] = "y";
header("Location: gen_inscription.php");
}
#PARTIE 5 - CONFIRMATION DE L'INSCRIPTION ET ENTRÉE DES DONNÉES DANS LA BDD
if ($HTTP_POST_VARS['type_action'] == "form_resp_conf"){
#SI LES INFORMATIONS ONT ÉTÉ CONFIRMÉES INSERTION DANS LA BASE DE DONNÉES
if ($HTTP_POST_VARS['valide'] == "y"){
$ecole = $HTTP_SESSION_VARS['INSC']['ecole'];
$cs = $HTTP_SESSION_VARS['INSC']['com_scol'];
$region = $HTTP_SESSION_VARS['INSC']['region'];
$login = $HTTP_SESSION_VARS['INSC']['login'];
$prenom = $HTTP_SESSION_VARS['INSC']['prenom'];
$nom = $HTTP_SESSION_VARS['INSC']['nom'];
$fonction = $HTTP_SESSION_VARS['INSC']['fonction'];
$password = sha1($HTTP_SESSION_VARS['INSC']['password']);
$nom_groupe = addslashes($HTTP_SESSION_VARS['INSC']['nom_groupe']);
$pass_groupe = $HTTP_SESSION_VARS['INSC']['pass_groupe'];
$niveau = $HTTP_SESSION_VARS['INSC']['niveau'];
$type = $HTTP_SESSION_VARS['INSC']['type'];
$limite = $HTTP_SESSION_VARS['INSC']['limite'];
#CRÉATION D'UN USAGER
$requete_sql = "INSERT INTO usager (login, password, type)
VALUES ( \"$login\", \"$password\", \"resp\")
";
$reponse_log = bd_executer_sql($requete_sql);
# echo $requete_sql;
$idu = mysql_insert_id();
#CRÉATION D'UN RESPONSABLE
if ($ecole != "Autre"){
$requete_sql = "SELECT ecole_id
FROM ecole
WHERE ecole_id = \"$ecole\"
AND comscol_id = \"$cs\"
";
$reponse_ver = bd_executer_sql($requete_sql);
$ligne = mysql_fetch_array($reponse_ver);
$ecole_id = $ligne['ecole_id'];
} else {
$ecole_id = "0";
}
$requete_sql = "INSERT INTO responsable (nom, prenom, fonction, ecole_id, usager_id, nouveau)
VALUES ( \"$nom\", \"$prenom\", \"$fonction\", \"$ecole_id\", $idu, \"1\")
";
$reponse_ins = bd_executer_sql($requete_sql);
# echo $requete_sql;
$idr = mysql_insert_id();
$requete_sql = "INSERT INTO lien_resp_projet (resp_id, projet_id, valide, date_valide, nb_groupe)
VALUES ( $idr, $projet, \"0\", \"0000-00-00\", \"1\")
";
$reponse_ins = bd_executer_sql($requete_sql);
#CRÉATION D'UN GROUPE
$requete_sql = "INSERT INTO groupe (nom, password, niveau, type, limite, projet_id, resp_id)
VALUES ( \"$nom_groupe\", \"$pass_groupe\", \"$niveau\", \"$type\",
\"$limite\", $projet, $idr)
";
$reponse_grp = bd_executer_sql($requete_sql);
# echo $requete_sql;
$idg = mysql_insert_id();
$requete_sql = "SELECT nom
FROM projet
WHERE statut = \"actif\";
";
$reponse_prj = bd_executer_sql($requete_sql);
$ligne_prj = mysql_fetch_array($reponse_prj);
$requete_sql = "SELECT courriel_admin, titre
FROM site_parametres";
$reponse_param = mysql_query($requete_sql);
$ligne_param = mysql_fetch_array($reponse_param);
$requete_sql = "SELECT nom
FROM ecole
WHERE ecole_id = '" . $ecole . "'";
$reponse_ecole = mysql_query($requete_sql);
$ligne_ecole = mysql_fetch_array($reponse_ecole);
$requete_sql = "SELECT nom
FROM commission_scolaire
WHERE comscol_id = '" . $cs . "'";
$reponse_cs = mysql_query($requete_sql);
$ligne_cs = mysql_fetch_array($reponse_cs);
$requete_sql = "SELECT nom
FROM region
WHERE region_id = '" . $region . "'";
$reponse_region = mysql_query($requete_sql);
$ligne_region = mysql_fetch_array($reponse_region);
$ecole = $ligne_ecole['nom'];
$cs = $ligne_cs['nom'];
$region = $ligne_region['nom'];
#ENVOI D'UN EMAIL A L'ADMINISTRATEUR NOTIFIANT L'INSCRIPTION
$dest = $ligne_param['courriel_admin'];
$sujet = "ADMIN " . $ligne_param['titre'] . " - Inscription d'un responsable";
$body = "Bonjour,\n\nLe responsable ".$prenom." ". $nom." (email: ".$login.") de l'école ".$ecole." (commission scolaire: ".$cs.", région: ".$region." ) s'est inscrit au projet ". $ligne_prj['nom']." de '" . $ligne_param['titre'] . "'. \n\n";
$headers = 'From: ADMIN - ' . $ligne_param['titre'] . ' <' . $ligne_param['courriel_admin'] . '>' . "\r\n";
mail($dest, $sujet, $body, $headers);
#INITIALISATION DES VARIABLES DE SESSION
$HTTP_SESSION_VARS['SESSION']["niveau"] = "resp";
$HTTP_SESSION_VARS['SESSION']["nom_complet"] = $prenom." ".$nom;
$HTTP_SESSION_VARS['SESSION']["usager_id"] = $idr;
session_unregister("INSC");
header("Location: rsp_compte.php");
} else if ($HTTP_POST_VARS['valide'] == "n"){
session_unregister("INSC");
header("Location: gen_inscription.php");
}
}
############################# INSCRIPTION D'UN ÉLÈVE #########################################
#PARTIE 1 - MÉMORISATION DES DONNÉES ET VÉRIFICATION
if ($HTTP_POST_VARS['type_action'] == "eleve"){
$requete_sql = "SELECT *
FROM groupe
WHERE password = '" . $HTTP_POST_VARS['pass_groupe'] . "'
AND projet_id = $projet
";
$reponse_mdpg = bd_executer_sql($requete_sql);
$ver = mysql_num_rows($reponse_mdpg);
$ligne_groupe = mysql_fetch_array($reponse_mdpg);
$requete_sql = "SELECT *
FROM responsable
WHERE resp_id = \"$ligne_groupe[resp_id]\"
";
$reponse_resp = bd_executer_sql($requete_sql);
# echo $requete_sql;
$ligne_resp = mysql_fetch_array($reponse_resp);
$HTTP_SESSION_VARS['INSC']['pass_groupe'] = $HTTP_POST_VARS['pass_groupe'];
$HTTP_SESSION_VARS['INSC']['id_groupe'] = $ligne_groupe['groupe_id'];
$HTTP_SESSION_VARS['INSC']['groupe'] = $ligne_groupe['nom'];
$HTTP_SESSION_VARS['INSC']['resp'] = $ligne_resp['prenom']." ".$ligne_resp['nom'];
$HTTP_SESSION_VARS['INSC']['login'] = $HTTP_POST_VARS['login'];
$HTTP_SESSION_VARS['INSC']['password'] = $HTTP_POST_VARS['password'];
$HTTP_SESSION_VARS['INSC']['conf_pass'] = $HTTP_POST_VARS['conf_pass'];
$HTTP_SESSION_VARS['INSC']['nom'] = $HTTP_POST_VARS['nom'];
$HTTP_SESSION_VARS['INSC']['prenom'] = $HTTP_POST_VARS['prenom'];
$HTTP_SESSION_VARS['INSC']['sexe'] = $HTTP_POST_VARS['sexe'];
#VÉRIFICATION SI LE MOT DE PASSE GROUPE EXISTE
if ($ver == 0){
$HTTP_SESSION_VARS['SESSION']['message'] = "Ton mot de passe de groupe n'est pas valide.";
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_eleveREC";
$HTTP_SESSION_VARS['INSC']['groupe'] = "";
header("Location: gen_inscription.php");
# gen_variables_session();
#VÉRIFICATION SI LE NOM D'USAGER EXISTE DÉJÀ
} else {
$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);
#SI OUI
if ($ver > 0){
$HTTP_SESSION_VARS['SESSION']['message'] = "Le nom d'utilisateur (pseudonyme) que tu as choisi est déjà pris. Choisis-en un autre.";
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_eleveREC";
$HTTP_SESSION_VARS['INSC']['login'] = "";
header("Location: gen_inscription.php");
#SI NON TOUT EST OK
} 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['INSC']['type_action'] = "form_eleveNo";
header("Location: gen_inscription.php");
} else{
$HTTP_SESSION_VARS['INSC']['type_action'] = "form_eleve2";
header("Location: gen_inscription.php");
}
}
}
}
#PARTIE 2 - CONFIRMATION DE L'INSCRIPTION ET ENTRÉE DES DONNÉES DANS LA BDD
if ($HTTP_POST_VARS['type_action'] == "form_eleve2"){
#SI LES INFORMATIONS ONT ÉTÉ CONFIRMÉES INSERTION DANS LA BASE DE DONNÉES
if ($HTTP_POST_VARS['valide'] == "y"){
$groupe = $HTTP_SESSION_VARS['INSC']['id_groupe'];
$login = addslashes($HTTP_SESSION_VARS['INSC']['login']);
$password = sha1($HTTP_SESSION_VARS['INSC']['password']);
$nom = $HTTP_SESSION_VARS['INSC']['nom'];
$prenom = $HTTP_SESSION_VARS['INSC']['prenom'];
$sexe = $HTTP_SESSION_VARS['INSC']['sexe'];
#CRÉATION D'UN USAGER
$requete_sql = "INSERT INTO usager (login, password, type)
VALUES (\"$login\", \"$password\", \"eleve\")
";
$reponse_log = bd_executer_sql($requete_sql);
# echo $requete_sql."<br>";
$idu = mysql_insert_id();
#CRÉATION D'UN ÉLÈVE
if ($HTTP_SESSION_VARS['SESSION']['periode'] == "cand" || $HTTP_SESSION_VARS['SESSION']['periode'] == "debut"){
$cand = 1;
}
$requete_sql = "INSERT INTO eleve (nom, prenom, sexe, groupe_id, usager_id,
valide, date_valide, candidat, projet_id)
VALUES (\"$nom\", \"$prenom\", \"$sexe\", $groupe, $idu,
\"0\", \"0000-00-00\", \"$cand\", $projet)
";
$reponse_ins = bd_executer_sql($requete_sql);
# echo $requete_sql;
$ide = mysql_insert_id();
#CRÉATION D'UNE FICHE SI ÉLECTEUR
/*if ($HTTP_SESSION_VARS[SESSION][periode] == "cand" || $HTTP_SESSION_VARS[SESSION][periode] == "debut"){
$requete_sql = "INSERT INTO fiche (eleve_id, projet_id)
VALUES ($ide, $projet)
";
$reponse_log = bd_executer_sql($requete_sql);
}*/
#INITIALISATION DES VARIABLES DE SESSION
if(isset($HTTP_POST_VARS['prenom']) && isset($HTTP_POST_VARS['nom'])){
$HTTP_SESSION_VARS['SESSION']["nom_complet"] = $HTTP_POST_VARS['prenom']." ".$HTTP_POST_VARS['nom'];
}
$HTTP_SESSION_VARS['SESSION']["usager_id"] = $ide;
$HTTP_SESSION_VARS['SESSION']["niveau"] = "eleve";
session_unregister("INSC");
header("Location: ele_compte.php");
#SI NON RETOUR À LA PAGE D'INSCRIPTION, LES INFORMATIONS SONT EFFACÉES
} else if ($HTTP_POST_VARS['valide'] == "n"){
session_unregister("INSC");
header("Location: gen_inscription.php");
}
}
?>