Subversion Repositories Sites.obs-saisons.fr

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 aurelien 1
<?
2
include("../modules/connect.php");
3
 
4
/**** GESTION DES PARTICIPANTS ****/
5
 
6
//INDICES DANS LES FICHIERS CSV
7
$ajout_pseudo = 0;
8
$ajout_type = 1;
9
$ajout_ecole = 2;
10
$ajout_niveau = 3;
11
$ajout_nom = 4;
12
$ajout_prenom = 5;
13
$ajout_adresse = 6;
14
$ajout_commune = 7;
15
$ajout_email = 8;
16
 
17
/*** Modification/Ajout d'un participant ***/
18
 
19
//a-t-on uploadé un fichier ?
20
if (isset($_POST['valid_participants'])) {
21
    if (isset($_FILES['participants'])) {
22
      $nomfic = $_FILES['participants']['tmp_name'];
23
      if ($handle = fopen($nomfic,'r')) {
24
        //on récupère dans la base les valeurs pour les niveaux de classe et types d'inscription
25
	$req_niveaux = mysql_query("select NIVEAU_ID,NIVEAU_NOM from NIVEAU");
26
	while ($niveau = mysql_fetch_row($req_niveaux))
27
	  $niveaux[$niveau[1]] = $niveau[0];
28
	$req_types = mysql_query("select TYPE_INSCRIPTION_ID,TYPE_INSCRIPTION_NOM from TYPE_INSCRIPTION");
29
	while ($type = mysql_fetch_row($req_types))
30
	  $types[$type[1]] = $type[0];
31
 
32
	$numligne = 0;
33
	$ligne = fgetcsv($handle,1000,';');
34
	while ($ligne = fgetcsv($handle,1000,';')) {
35
	 $numligne++;
36
 
37
	 //vérif sur le niveau de classe, s'il existe
38
	 if ($ligne[$ajout_ecole] && !$niveaux[$ligne[$ajout_niveau]])
39
	  $erreurs[] = "Ligne $numligne : Le niveau de classe entré n'est pas correct (".$ligne[$ajout_niveau].")";
40
	 //vérif sur le type d'inscr, s'il existe
41
	 if (!$types[$ligne[$ajout_type]])
42
	  $erreurs[] = "Ligne $numligne : Le type d'inscription entré n'est pas correct (".$ligne[$ajout_type].")";
43
	 //vérif sur la commune, si elle existe
44
	 $requete_commune = mysql_query("select COMMUNE_ID from COMMUNE where COMMUNE_NOM like '".$ligne[$ajout_commune]."'");
45
	 if (!$commune = mysql_fetch_row($requete_commune))
46
	   $erreurs[] = "Ligne $numligne : La commune entrée n'est pas correcte (".$ligne[$ajout_commune].")";
47
	 //vérif sur le pseudo, si il n'existe pas
48
	 $requete_login = mysql_query("select PARTICIPANT_ID from PARTICIPANT where PARTICIPANT_PSEUDO like '".addSlashes($ligne[$ajout_pseudo])."'");
49
	if ($login = mysql_fetch_row($requete_login))
50
	   $erreurs[] = "Ligne $numligne : Le pseudo est déjà pris (".$ligne[$ajout_pseudo].")";
51
 
52
	 if (sizeof($erreurs)==0) {
53
	  //on génère un mot de passe
54
	  $motdepasse = "";
55
	  $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');
56
  	  for ($i=0; $i<8; $i++) {
57
    	    $motdepasse .= $alphabet[rand(0,sizeof($alphabet))];
58
  	  }
59
 
60
	  //on insère le participant dans la base
61
	  $requete = "insert into PARTICIPANT (PARTICIPANT_PSEUDO,TYPE_INSCRIPTION_ID,PARTICIPANT_ECOLE,".
62
			"NIVEAU_ID,PARTICIPANT_NOM,PARTICIPANT_PRENOM,PARTICIPANT_ADRESSE,COMMUNE_ID,".
63
			"PARTICIPANT_EMAIL,PARTICIPANT_EN_ATTENTE,PARTICIPANT_MOTDEPASSE) ".
64
			"values ('".$ligne[$ajout_pseudo]."',".$types[$ligne[$ajout_type]].
65
			",'".$ligne[$ajout_ecole]."','".$niveaux[$ligne[$ajout_niveau]]."','".$ligne[$ajout_nom]."'".
66
			",'".$ligne[$ajout_prenom]."','".$ligne[$ajout_adresse]."','".$commune[0]."'".
67
			",'".$ligne[$ajout_email]."',1,'".$motdepasse."')";
68
 
69
	  //si tout s'est bien passé on l'inscrit aussi au forum
70
	  if (mysql_query($requete)) {
71
  	    $sql_forum = "SELECT MAX(user_id) AS total
72
				FROM phpbb_users";
73
	    if ( !($result = mysql_query($sql_forum)) ) {
74
		$erreurs[] = "1 Une erreur est survenue";
75
	    }
76
	    if ( !($row = mysql_fetch_row($result)) ) {
77
		$erreurs[] = "2 Une erreur est survenue";
78
	    }
79
	    $user_id = $row[0] + 1;
80
	    $sql = "INSERT INTO phpbb_users (user_id, username, user_regdate, user_email, user_lang, user_password)
81
                                VALUES ($user_id, '" . str_replace("\'", "''", addSlashes($ligne[$ajout_pseudo])) . "', " . time() . ", '" . str_replace("\'", "''", $ligne[$ajout_email]) . "', 'french', '".md5($motdepasse)."')";
82
 
83
	    if (mysql_query($sql)) {
84
 
85
	      //on envoie le mail de bienvenue
86
  	      $texte_mail = "Bonjour!
87
Tu as été inscrit automatiquement à l'Observatoire des Saisons Junior car tu t'es inscrit sur le site de Phenoclim.
88
Pour valider ton inscription, va à l'adresse http://shiva/pheno-ecoles/valider.php?pseudo=".urlencode($ligne[$ajout_pseudo]).".
89
 
90
Pour en savoir plus, va sur notre site à l'adresse http://shiva/pheno-ecoles
91
 
92
Ton pseudo est : ".addSlashes($ligne[$ajout_pseudo])."
93
Ton mot de passe est : $motdepasse
94
 
95
Garde précieusement ce message car tu auras besoin de ton pseudo et de mot de passe pour accéder à certaines rubriques.";
96
 
97
  	      //Envoi du mail
98
  	      if (!mail($ligne[$ajout_email],"Bienvenue sur l'Observatoire des Saisons Junior!",$texte_mail,"From: no-reply@observatoire-des-saisons.com")) {
99
    	        $erreurs[] = "Ligne $numligne : Adresse e-mail invalide:".$ligne[$ajout_email];
100
	      }
101
	    } else
102
		$erreurs[] = "Ligne $numligne : Erreur lors de l'inscription au forum (".mysql_error().")";
103
	  }
104
	  else
105
	    $erreurs[] = "Ligne $numligne : Erreur lors de l'insertion dans la base (".mysql_error().")";
106
	 }
107
        }
108
      }
109
    }
110
      else
111
        $erreurs[] = "Le fichier des participants n'a pas pu être récupéré.";
112
}
113
 
114
//a-t-on demandé l'ajout de participants ?
115
if (isset($_GET['n'])) {
116
  ?>
117
<form name="formparticipants" method="post" action="index.php?a=2" enctype="multipart/form-data">
118
Fichier à uploader : <input type="hidden" name="MAX_FILE_SIZE" value="100000000">
119
<input type="file" name="participants" size="30">
120
 
121
<input type="submit" name="valid_participants" value="Envoyer le fichier">
122
</form>
123
  <?
124
}
125
//a-t-on demandé l'export ?
126
/*else if (isset($_GET['x'])) {
127
  $contenu = "";
128
  $entetes = array("Pseudo","Type inscription","Ecole","Niveau","Nom","Prenom",
129
		"Adresse","Commune","E-mail");
130
  $requete_utils = mysql_query("select distinct PARTICIPANT_PSEUDO,TYPE_INSCRIPTION_NOM,PARTICIPANT_ECOLE,".
131
                        "NIVEAU_NOM,PARTICIPANT_NOM,PARTICIPANT_PRENOM,PARTICIPANT_ADRESSE,COMMUNE_NOM,".
132
                        "PARTICIPANT_EMAIL from PARTICIPANT,NIVEAU,TYPE_INSCRIPTION,COMMUNE ".
133
			"where NIVEAU.NIVEAU_ID=PARTICIPANT.NIVEAU_ID and COMMUNE.COMMUNE_ID=PARTICIPANT.COMMUNE_ID ".
134
			"and TYPE_INSCRIPTION.TYPE_INSCRIPTION_ID=PARTICIPANT.TYPE_INSCRIPTION_ID ".
135
			"and PARTICIPANT.TYPE_INSCRIPTION_ID=1 ".
136
			"order by PARTICIPANT.COMMUNE_ID,PARTICIPANT_NOM");
137
  $fichier = implode(';',$entetes).";\n";
138
  while ($util = mysql_fetch_row($requete_utils)) {
139
    $fichier .= implode(';',$util).";\n";
140
  }
141
  $requete_utils = mysql_query("select distinct PARTICIPANT_PSEUDO,TYPE_INSCRIPTION_NOM,'',".
142
                        "'',PARTICIPANT_NOM,PARTICIPANT_PRENOM,PARTICIPANT_ADRESSE,COMMUNE_NOM,".
143
                        "PARTICIPANT_EMAIL from PARTICIPANT,NIVEAU,TYPE_INSCRIPTION,COMMUNE ".
144
			"where COMMUNE.COMMUNE_ID=PARTICIPANT.COMMUNE_ID ".
145
			"and TYPE_INSCRIPTION.TYPE_INSCRIPTION_ID=PARTICIPANT.TYPE_INSCRIPTION_ID ".
146
			"and PARTICIPANT.TYPE_INSCRIPTION_ID!=1 ".
147
			"order by PARTICIPANT.COMMUNE_ID,PARTICIPANT_NOM");
148
  while ($util = mysql_fetch_row($requete_utils)) {
149
    $fichier .= implode(';',$util).";\n";
150
  }
151
  //echo "<pre>".$fichier."</pre>";
152
  $chemin = "/tmp/";
153
  $fichier = "participants_export.csv";
154
  $handle = fopen($chemin.$fichier,'w');
155
  fwrite($handle,$fichier);
156
  fclose($handle);
157
  include("telech.php");
158
}*/
159
 
160
if (sizeof($erreurs)>0) {
161
echo "Toutes les premières lignes jusqu'à la première ligne d'erreur ont été prises en compte.";
162
foreach ($erreurs as $err)
163
  echo $err."<br>";
164
}
165
 
166
//on récupère le participant à supprimer
167
if (isset($_GET['s'])) {
168
 
169
  $participant_id = $_GET['s'];
170
  $req_qui = mysql_query("select PARTICIPANT_PSEUDO from PARTICIPANT where PARTICIPANT_ID=$participant_id");
171
  $qui = mysql_fetch_row($req_qui);
172
  $req_participant = mysql_query("delete from PARTICIPANT where PARTICIPANT.PARTICIPANT_ID=$participant_id");
173
 
174
  if ($req_participant) {
175
    //on le supprime aussi des forums
176
    $sql = mysql_query("DELETE FROM phpbb_users where username like '". str_replace("\'", "''", addSlashes($qui[0]))."'");
177
    echo mysql_error();
178
  }
179
}
180
 
181
 
182
//on récupère le participant à valider
183
if (isset($_GET['v'])) {
184
 
185
  $participant_id = $_GET['v'];
186
  $req = mysql_query("update PARTICIPANT set PARTICIPANT_EN_ATTENTE=0 where PARTICIPANT_ID=$participant_id");
187
  echo mysql_error();
188
}
189
 
190
/*** Liste des participants***/
191
 
192
/*** Requête de sélection pour l'affichage de la bd ***/
193
$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");
194
echo mysql_error();
195
?>
196
<center>
197
<a href="index.php?a=2&n">Ajouter une liste de participants</a>
198
<br>
199
<a href="exportjunior.php">Exporter la liste des participants junior</a>
200
<br>
201
<a href="exportadultes.php">Exporter la liste des participants adultes</a>
202
<table class="liste">
203
  <tr class="titre">
204
    <td>Pseudo</td>
205
    <td>E-mail</td>
206
    <td>Ecole</td>
207
    <td>Nom</td>
208
    <td>Mot de passe</td>
209
    <td>Inscription validée</td>
210
    <td>Action</td>
211
  </tr>
212
<?
213
$i=0;
214
$enfants = true;
215
while ($participant = mysql_fetch_row($req_participants)) {
216
  if ($enfants && $participant[5]=='1') {
217
    $enfants = false;
218
    echo "<tr class='titre'><td colspan='4'>Adultes</td></tr>";
219
  }
220
  echo "<tr class='std$i'><td>".$participant[2]."</td>
221
<td><a href='mailto:".$participant[8]."'>".$participant[8]."</a></td>
222
<td>".$participant[1]."</td>
223
<td>".$participant[3]." ".$participant[4]."</td>
224
<td>".$participant[6]."</td>
225
<td>".($participant[7]==0 ? "Oui" : "<a href='index.php?a=2&v=".$participant[0]."'>En attente</a>")."</td>
226
<td><a href='index.php?a=2&s=".$participant[0]."'  onclick=\"return confirm('Supprimer le participant ".$participant[2]." ?')\">SUPPR</a></tr>";
227
$i++;
228
if ($i==2)
229
  $i=0;
230
}
231
?>
232
</table>
233
</center>