New file |
0,0 → 1,233 |
<? |
include("../modules/connect.php"); |
|
/**** GESTION DES PARTICIPANTS ****/ |
|
//INDICES DANS LES FICHIERS CSV |
$ajout_pseudo = 0; |
$ajout_type = 1; |
$ajout_ecole = 2; |
$ajout_niveau = 3; |
$ajout_nom = 4; |
$ajout_prenom = 5; |
$ajout_adresse = 6; |
$ajout_commune = 7; |
$ajout_email = 8; |
|
/*** Modification/Ajout d'un participant ***/ |
|
//a-t-on uploadé un fichier ? |
if (isset($_POST['valid_participants'])) { |
if (isset($_FILES['participants'])) { |
$nomfic = $_FILES['participants']['tmp_name']; |
if ($handle = fopen($nomfic,'r')) { |
//on récupère dans la base les valeurs pour les niveaux de classe et types d'inscription |
$req_niveaux = mysql_query("select NIVEAU_ID,NIVEAU_NOM from NIVEAU"); |
while ($niveau = mysql_fetch_row($req_niveaux)) |
$niveaux[$niveau[1]] = $niveau[0]; |
$req_types = mysql_query("select TYPE_INSCRIPTION_ID,TYPE_INSCRIPTION_NOM from TYPE_INSCRIPTION"); |
while ($type = mysql_fetch_row($req_types)) |
$types[$type[1]] = $type[0]; |
|
$numligne = 0; |
$ligne = fgetcsv($handle,1000,';'); |
while ($ligne = fgetcsv($handle,1000,';')) { |
$numligne++; |
|
//vérif sur le niveau de classe, s'il existe |
if ($ligne[$ajout_ecole] && !$niveaux[$ligne[$ajout_niveau]]) |
$erreurs[] = "Ligne $numligne : Le niveau de classe entré n'est pas correct (".$ligne[$ajout_niveau].")"; |
//vérif sur le type d'inscr, s'il existe |
if (!$types[$ligne[$ajout_type]]) |
$erreurs[] = "Ligne $numligne : Le type d'inscription entré n'est pas correct (".$ligne[$ajout_type].")"; |
//vérif sur la commune, si elle existe |
$requete_commune = mysql_query("select COMMUNE_ID from COMMUNE where COMMUNE_NOM like '".$ligne[$ajout_commune]."'"); |
if (!$commune = mysql_fetch_row($requete_commune)) |
$erreurs[] = "Ligne $numligne : La commune entrée n'est pas correcte (".$ligne[$ajout_commune].")"; |
//vérif sur le pseudo, si il n'existe pas |
$requete_login = mysql_query("select PARTICIPANT_ID from PARTICIPANT where PARTICIPANT_PSEUDO like '".addSlashes($ligne[$ajout_pseudo])."'"); |
if ($login = mysql_fetch_row($requete_login)) |
$erreurs[] = "Ligne $numligne : Le pseudo est déjà pris (".$ligne[$ajout_pseudo].")"; |
|
if (sizeof($erreurs)==0) { |
//on génère un mot de passe |
$motdepasse = ""; |
$alphabet = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'); |
for ($i=0; $i<8; $i++) { |
$motdepasse .= $alphabet[rand(0,sizeof($alphabet))]; |
} |
|
//on insère le participant dans la base |
$requete = "insert into PARTICIPANT (PARTICIPANT_PSEUDO,TYPE_INSCRIPTION_ID,PARTICIPANT_ECOLE,". |
"NIVEAU_ID,PARTICIPANT_NOM,PARTICIPANT_PRENOM,PARTICIPANT_ADRESSE,COMMUNE_ID,". |
"PARTICIPANT_EMAIL,PARTICIPANT_EN_ATTENTE,PARTICIPANT_MOTDEPASSE) ". |
"values ('".$ligne[$ajout_pseudo]."',".$types[$ligne[$ajout_type]]. |
",'".$ligne[$ajout_ecole]."','".$niveaux[$ligne[$ajout_niveau]]."','".$ligne[$ajout_nom]."'". |
",'".$ligne[$ajout_prenom]."','".$ligne[$ajout_adresse]."','".$commune[0]."'". |
",'".$ligne[$ajout_email]."',1,'".$motdepasse."')"; |
|
//si tout s'est bien passé on l'inscrit aussi au forum |
if (mysql_query($requete)) { |
$sql_forum = "SELECT MAX(user_id) AS total |
FROM phpbb_users"; |
if ( !($result = mysql_query($sql_forum)) ) { |
$erreurs[] = "1 Une erreur est survenue"; |
} |
if ( !($row = mysql_fetch_row($result)) ) { |
$erreurs[] = "2 Une erreur est survenue"; |
} |
$user_id = $row[0] + 1; |
$sql = "INSERT INTO phpbb_users (user_id, username, user_regdate, user_email, user_lang, user_password) |
VALUES ($user_id, '" . str_replace("\'", "''", addSlashes($ligne[$ajout_pseudo])) . "', " . time() . ", '" . str_replace("\'", "''", $ligne[$ajout_email]) . "', 'french', '".md5($motdepasse)."')"; |
|
if (mysql_query($sql)) { |
|
//on envoie le mail de bienvenue |
$texte_mail = "Bonjour! |
Tu as été inscrit automatiquement à l'Observatoire des Saisons Junior car tu t'es inscrit sur le site de Phenoclim. |
Pour valider ton inscription, va à l'adresse http://shiva/pheno-ecoles/valider.php?pseudo=".urlencode($ligne[$ajout_pseudo]).". |
|
Pour en savoir plus, va sur notre site à l'adresse http://shiva/pheno-ecoles |
|
Ton pseudo est : ".addSlashes($ligne[$ajout_pseudo])." |
Ton mot de passe est : $motdepasse |
|
Garde précieusement ce message car tu auras besoin de ton pseudo et de mot de passe pour accéder à certaines rubriques."; |
|
//Envoi du mail |
if (!mail($ligne[$ajout_email],"Bienvenue sur l'Observatoire des Saisons Junior!",$texte_mail,"From: no-reply@observatoire-des-saisons.com")) { |
$erreurs[] = "Ligne $numligne : Adresse e-mail invalide:".$ligne[$ajout_email]; |
} |
} else |
$erreurs[] = "Ligne $numligne : Erreur lors de l'inscription au forum (".mysql_error().")"; |
} |
else |
$erreurs[] = "Ligne $numligne : Erreur lors de l'insertion dans la base (".mysql_error().")"; |
} |
} |
} |
} |
else |
$erreurs[] = "Le fichier des participants n'a pas pu être récupéré."; |
} |
|
//a-t-on demandé l'ajout de participants ? |
if (isset($_GET['n'])) { |
?> |
<form name="formparticipants" method="post" action="index.php?a=2" enctype="multipart/form-data"> |
Fichier à uploader : <input type="hidden" name="MAX_FILE_SIZE" value="100000000"> |
<input type="file" name="participants" size="30"> |
|
<input type="submit" name="valid_participants" value="Envoyer le fichier"> |
</form> |
<? |
} |
//a-t-on demandé l'export ? |
/*else if (isset($_GET['x'])) { |
$contenu = ""; |
$entetes = array("Pseudo","Type inscription","Ecole","Niveau","Nom","Prenom", |
"Adresse","Commune","E-mail"); |
$requete_utils = mysql_query("select distinct PARTICIPANT_PSEUDO,TYPE_INSCRIPTION_NOM,PARTICIPANT_ECOLE,". |
"NIVEAU_NOM,PARTICIPANT_NOM,PARTICIPANT_PRENOM,PARTICIPANT_ADRESSE,COMMUNE_NOM,". |
"PARTICIPANT_EMAIL from PARTICIPANT,NIVEAU,TYPE_INSCRIPTION,COMMUNE ". |
"where NIVEAU.NIVEAU_ID=PARTICIPANT.NIVEAU_ID and COMMUNE.COMMUNE_ID=PARTICIPANT.COMMUNE_ID ". |
"and TYPE_INSCRIPTION.TYPE_INSCRIPTION_ID=PARTICIPANT.TYPE_INSCRIPTION_ID ". |
"and PARTICIPANT.TYPE_INSCRIPTION_ID=1 ". |
"order by PARTICIPANT.COMMUNE_ID,PARTICIPANT_NOM"); |
$fichier = implode(';',$entetes).";\n"; |
while ($util = mysql_fetch_row($requete_utils)) { |
$fichier .= implode(';',$util).";\n"; |
} |
$requete_utils = mysql_query("select distinct PARTICIPANT_PSEUDO,TYPE_INSCRIPTION_NOM,'',". |
"'',PARTICIPANT_NOM,PARTICIPANT_PRENOM,PARTICIPANT_ADRESSE,COMMUNE_NOM,". |
"PARTICIPANT_EMAIL from PARTICIPANT,NIVEAU,TYPE_INSCRIPTION,COMMUNE ". |
"where COMMUNE.COMMUNE_ID=PARTICIPANT.COMMUNE_ID ". |
"and TYPE_INSCRIPTION.TYPE_INSCRIPTION_ID=PARTICIPANT.TYPE_INSCRIPTION_ID ". |
"and PARTICIPANT.TYPE_INSCRIPTION_ID!=1 ". |
"order by PARTICIPANT.COMMUNE_ID,PARTICIPANT_NOM"); |
while ($util = mysql_fetch_row($requete_utils)) { |
$fichier .= implode(';',$util).";\n"; |
} |
//echo "<pre>".$fichier."</pre>"; |
$chemin = "/tmp/"; |
$fichier = "participants_export.csv"; |
$handle = fopen($chemin.$fichier,'w'); |
fwrite($handle,$fichier); |
fclose($handle); |
include("telech.php"); |
}*/ |
|
if (sizeof($erreurs)>0) { |
echo "Toutes les premières lignes jusqu'à la première ligne d'erreur ont été prises en compte."; |
foreach ($erreurs as $err) |
echo $err."<br>"; |
} |
|
//on récupère le participant à supprimer |
if (isset($_GET['s'])) { |
|
$participant_id = $_GET['s']; |
$req_qui = mysql_query("select PARTICIPANT_PSEUDO from PARTICIPANT where PARTICIPANT_ID=$participant_id"); |
$qui = mysql_fetch_row($req_qui); |
$req_participant = mysql_query("delete from PARTICIPANT where PARTICIPANT.PARTICIPANT_ID=$participant_id"); |
|
if ($req_participant) { |
//on le supprime aussi des forums |
$sql = mysql_query("DELETE FROM phpbb_users where username like '". str_replace("\'", "''", addSlashes($qui[0]))."'"); |
echo mysql_error(); |
} |
} |
|
|
//on récupère le participant à valider |
if (isset($_GET['v'])) { |
|
$participant_id = $_GET['v']; |
$req = mysql_query("update PARTICIPANT set PARTICIPANT_EN_ATTENTE=0 where PARTICIPANT_ID=$participant_id"); |
echo mysql_error(); |
} |
|
/*** Liste des participants***/ |
|
/*** Requête de sélection pour l'affichage de la bd ***/ |
$req_participants = mysql_query("select PARTICIPANT_ID,PARTICIPANT_ECOLE,PARTICIPANT_PSEUDO,PARTICIPANT_NOM,PARTICIPANT_PRENOM,PARTICIPANT_ADULTE,PARTICIPANT_MOTDEPASSE,PARTICIPANT_EN_ATTENTE,PARTICIPANT_EMAIL from PARTICIPANT order by PARTICIPANT_ADULTE, PARTICIPANT_PSEUDO"); |
echo mysql_error(); |
?> |
<center> |
<a href="index.php?a=2&n">Ajouter une liste de participants</a> |
<br> |
<a href="exportjunior.php">Exporter la liste des participants junior</a> |
<br> |
<a href="exportadultes.php">Exporter la liste des participants adultes</a> |
<table class="liste"> |
<tr class="titre"> |
<td>Pseudo</td> |
<td>E-mail</td> |
<td>Ecole</td> |
<td>Nom</td> |
<td>Mot de passe</td> |
<td>Inscription validée</td> |
<td>Action</td> |
</tr> |
<? |
$i=0; |
$enfants = true; |
while ($participant = mysql_fetch_row($req_participants)) { |
if ($enfants && $participant[5]=='1') { |
$enfants = false; |
echo "<tr class='titre'><td colspan='4'>Adultes</td></tr>"; |
} |
echo "<tr class='std$i'><td>".$participant[2]."</td> |
<td><a href='mailto:".$participant[8]."'>".$participant[8]."</a></td> |
<td>".$participant[1]."</td> |
<td>".$participant[3]." ".$participant[4]."</td> |
<td>".$participant[6]."</td> |
<td>".($participant[7]==0 ? "Oui" : "<a href='index.php?a=2&v=".$participant[0]."'>En attente</a>")."</td> |
<td><a href='index.php?a=2&s=".$participant[0]."' onclick=\"return confirm('Supprimer le participant ".$participant[2]." ?')\">SUPPR</a></tr>"; |
$i++; |
if ($i==2) |
$i=0; |
} |
?> |
</table> |
</center> |