Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1175 | Rev 1182 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
11 jpm 1
<?php
771 delphine 2
// /opt/lampp/bin/php cli.php chorodep -a chargerVersions
242 jpm 3
class Chorodep extends EfloreScript {
11 jpm 4
	protected $nbre_dep = 0;
5
	private $type_donnee = '';
6
	protected $aso_num_nomenc = array();
7
	protected $nbre_ligne = 0;
8
	protected $nbre_plte_presente = 0;
9
	protected $nbre_plte_a_confirmer = 0;
10
	protected $nbre_plte_douteux = 0;
11
	protected $nbre_plte_erreur = 0;
12
	protected $nbre_plte_disparue = 0;
242 jpm 13
	protected $nbre_plte_erreur_a_confirmer = 0;
11 jpm 14
	protected $nc_autres_valeur_champ = 0;
242 jpm 15
	protected $nc_nbre_plte_presente = 0;
16
	protected $nc_nbre_plte_a_confirmer = 0;
17
	protected $nc_nbre_plte_douteux = 0;
18
	protected $nc_nbre_plte_disparue = 0;
19
	protected $nc_nbre_plte_erreur = 0;
20
	protected $nc_nbre_plte_erreur_a_confirmer = 0;
21
 
11 jpm 22
	protected $aso_totaux_dep = array();
242 jpm 23
	private $fichier_verif = './chorodep_verif.html';
11 jpm 24
 
242 jpm 25
	public function executer() {
26
		try {
27
			$this->initialiserProjet('chorodep');
11 jpm 28
 
242 jpm 29
			// Lancement de l'action demandée
30
			$cmd = $this->getParametre('a');
31
			switch ($cmd) {
32
 
33
				case 'chargerTous' :
34
					$this->chargerStructureSql();
35
					$this->chargerVersions();
36
					$this->chargerChorodepContributeurs();
37
					$this->chargerChorodepSources();
38
					$this->chargerChorodepOntologies();
39
					break;
40
				case 'chargerStructureSql' :
41
					$this->chargerStructureSql();
42
					break;
43
				case 'chargerVersions' :
44
					$this->chargerVersions();
45
					break;
46
				case 'chargerChorodep' :
47
					$this->chargerChorodepContributeurs();
48
					$this->chargerChorodepSources();
49
					$this->chargerChorodepOntologies();
50
					break;
51
				case 'verifierDonnees' :
52
					$this->initialiserTraitement();
53
					$this->verifierDonnees();
54
					break;
55
				case 'supprimerTous' :
56
					$this->supprimerTous();
57
					break;
1124 mathias 58
				// noms vernaculaires et statuts de protection
1179 mathias 59
				case 'chargerNVSP' :
60
					$this->chargerNVSP();
1124 mathias 61
					break;
62
				case 'nettoyageNVSP' :
63
					$this->nettoyageNVSP();
64
					break;
65
				case 'chargerStructureNVSP' :
66
					$this->chargerStructureNVSP();
67
					break;
1179 mathias 68
				case 'genererNomsVernaculaires' :
69
					$this->genererNomsVernaculaires();
1124 mathias 70
					break;
1179 mathias 71
				case 'genererStatutsProtection' :
72
					$this->genererStatutsProtection();
1124 mathias 73
					break;
242 jpm 74
				default :
75
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
76
			}
77
		} catch (Exception $e) {
78
			$this->traiterErreur($e->getMessage());
79
		}
11 jpm 80
	}
81
 
242 jpm 82
	private function chargerChorodepContributeurs() {
83
		$chemin = Config::get('chemins.chorodepContributeurs');
84
		$table = Config::get('tables.chorodepContributeurs');
85
		$requete = "LOAD DATA INFILE '$chemin' ".
86
						"REPLACE INTO TABLE $table ".
87
						'CHARACTER SET utf8 '.
88
						'FIELDS '.
89
						"	TERMINATED BY '\t' ".
90
						"	ENCLOSED BY '' ".
91
						"	ESCAPED BY '\\\' ".
92
						'IGNORE 2 LINES';
93
		$this->getBdd()->requeter($requete);
94
	}
11 jpm 95
 
242 jpm 96
	private function chargerChorodepSources() {
97
		$chemin = Config::get('chemins.chorodepSources');
98
		$table = Config::get('tables.chorodepSources');
99
		$requete = "LOAD DATA INFILE '$chemin' ".
100
							"REPLACE INTO TABLE $table ".
101
							'CHARACTER SET utf8 '.
102
							'FIELDS '.
103
							"	TERMINATED BY '\t' ".
104
							"	ENCLOSED BY '' ".
105
							"	ESCAPED BY '\\\' ".
106
							'IGNORE 2 LINES';
107
		$this->getBdd()->requeter($requete);
108
	}
11 jpm 109
 
242 jpm 110
	private function chargerChorodepOntologies() {
111
		$chemin = Config::get('chemins.chorodepOntologies');
112
		$table = Config::get('tables.chorodepOntologies');
113
		$requete = "LOAD DATA INFILE '$chemin' ".
114
								"REPLACE INTO TABLE $table ".
115
								'CHARACTER SET utf8 '.
116
								'FIELDS '.
117
								"	TERMINATED BY '\t' ".
118
								"	ENCLOSED BY '' ".
119
								"	ESCAPED BY '\\\' ".
120
								'IGNORE 1 LINES';
121
		$this->getBdd()->requeter($requete);
11 jpm 122
	}
123
 
242 jpm 124
	private function chargerVersions() {
125
		$versions = explode(',', Config::get('versions'));
126
		$versionsDonnees = explode(',', Config::get('versionsDonnees'));
127
		foreach ($versions as $id => $version) {
128
			$versionDonnees = $versionsDonnees[$id];
129
			$this->chargerStructureSqlVersion($versionDonnees);
130
			$this->chargerDonneesVersion($versionDonnees, $version);
11 jpm 131
		}
132
	}
242 jpm 133
 
134
	private function chargerStructureSqlVersion($versionDonnees) {
249 jpm 135
		$fichierSqlTpl = Config::get('chemins.structureSqlVersionTpl');
242 jpm 136
		$fichierSql = sprintf($fichierSqlTpl, $versionDonnees, $versionDonnees);
137
		$contenuSql = $this->recupererContenu($fichierSql);
138
		$this->executerScripSql($contenuSql);
139
	}
140
 
141
	private function chargerDonneesVersion($versionDonnees, $version) {
249 jpm 142
		$fichierTsvTpl = Config::get('chemins.chorodepTpl');
242 jpm 143
		$fichierTsv = sprintf($fichierTsvTpl, $versionDonnees, $versionDonnees);
249 jpm 144
		$tableTpl = Config::get('tables.chorodepTpl');
242 jpm 145
		$table = sprintf($tableTpl, $version);
773 delphine 146
		$champs = Config::get('chorodepChamps'.$version);
242 jpm 147
		$requete = "LOAD DATA INFILE '$fichierTsv' ".
148
						"REPLACE INTO TABLE $table ".
149
						'CHARACTER SET utf8 '.
150
						'FIELDS '.
151
						"	TERMINATED BY '\t' ".
152
						"	ENCLOSED BY '' ".
153
						"	ESCAPED BY '\\\' ".
154
						"($champs) ";
155
		$this->getBdd()->requeter($requete);
156
	}
157
 
11 jpm 158
	private function initialiserTraitement() {
159
		//------------------------------------------------------------------------------------------------------------//
160
		// Récupération des informations à vérifier
1124 mathias 161
		$table = $this->getNomTableDerniereVersion();
11 jpm 162
		$requete = 	'SELECT * '.
242 jpm 163
					"FROM $table ";
164
		$taxons = $this->getBdd()->recupererTous($requete);
11 jpm 165
		$tax_col = $taxons[1];
166
		$col = array_keys($tax_col);
167
		$this->initialiserTableaux($col);
168
		//------------------------------------------------------------------------------------------------------------//
169
		// Analyse des données
170
		echo 'Traitement de la ligne n° :';
171
		$i = 0;
172
		$j = 0;
173
		$aso_departements_analyses = array();
174
		$this->nbre_ligne_avec_guillemet = 0;
175
		foreach ($taxons as $aso_champs) {
176
			$nom = $aso_champs['nom_sci'];
177
			$num_taxo = $aso_champs['num_tax'];
178
			$num_nomenc = $aso_champs['num_nom'];
179
			if ($num_nomenc == 'nc') {
180
				$this->nc_nbre_nom++;
181
			} else if ($num_nomenc != 'nc') {
182
				$this->nbre_nom++;
183
				// Vérification de la nom duplication des numéros nomenclaturaux
184
				if ( !array_key_exists($num_nomenc, (array) $this->aso_num_nomenc) ) {
185
					$this->aso_num_nomenc[$num_nomenc]['compteur'] = 1;
186
					$this->aso_num_nomenc[$num_nomenc]['ligne'] = ($this->nbre_ligne+1);
187
				} else {
188
					$this->aso_num_nomenc[$num_nomenc]['compteur']++;
189
					$this->aso_num_nomenc[$num_nomenc]['ligne'] .= ' - '.($this->nbre_ligne+1);
190
				}
191
			}
192
			foreach ($aso_champs as $cle => $val ) {# Pour chaque département du taxon, on regarde la valeur
193
				$this->nbre_ligne_avec_guillemet += preg_match('/"/', $val);
194
				if ( preg_match('/^\d{2}$/', $cle) ) {# Nous vérifions que le nom du champs comprend bien le numéro du département entre ()
195
					$nd = $cle;# Numéro du département
196
					// Nous comptons le nombre de département en base de données
197
					if (!isset($aso_departements_analyses[$nd])) {
198
						$this->nbre_dep_analyse++;
199
						$aso_departements_analyses[$nd] = $nd;
200
					}
201
					if ( $num_nomenc != 'nc' && isset($val) && $val != '') {# Si le taxon n'est pas abscent du département
202
						if ($val == '1') {# Présent
203
							// Calcul du nombre de plante ayant un statut "Présent"
204
							$this->nbre_plte_presente++;
205
							// Stockage par département du nombre de plante ayant un statut "Présent"
206
							$this->aso_totaux_dep[$nd]['plte_presente']++;
207
							// Stockage des informations
208
							$this->tab_choro_dep[$j] = array(ZgFrDepartements::getIdChaine($nd), $num_taxo, $num_nomenc, 3, $this->id_donnee_choro++);
209
						} else if ($val == '1?') {# Présence à confirmer
210
							// Calcul du nombre de plante ayant un statut "Présence à confirmer"
211
							$this->nbre_plte_a_confirmer++;
212
							// Stockage par département du nombre de plante ayant un statut "Présence à confirmer"
213
							$this->aso_totaux_dep[$nd]['plte_a_confirmer']++;
214
							// Stockage des informations
215
							$this->tab_choro_dep[$j] = array(ZgFrDepartements::getIdChaine($nd), $num_taxo, $num_nomenc, 4, $this->id_donnee_choro++);
216
						} else if (preg_match('/^\s*(?:\?)\s*$/', $val)) {# Douteux
217
							// Calcul du nombre de plante ayant un statut "Disparu ou douteux"
218
							$this->nbre_plte_douteux++;
219
							// Stockage par département du nombre de plante ayant un statut "Douteux"
220
							$this->aso_totaux_dep[$nd]['plte_douteux']++;
221
							// Stockage des informations
222
							$this->tab_choro_dep[$j] = array(ZgFrDepartements::getIdChaine($nd), $num_taxo, $num_nomenc, 5, $this->id_donnee_choro++);
223
							if (preg_match('/(?: \?|\? | \? )/', $val)) {# Douteux
224
								// Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "?".
225
								$this->autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
226
														' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')<br />';
227
							}
228
						} elseif (preg_match('/^\s*(?:#)\s*$/', $val)) {# Erreur
229
	                        # Calcul du nombre de plante ayant un statut "Erreur"
230
	                        $this->nbre_plte_erreur++;
231
	                        # Stockage par département du nombre de plante ayant un statut "Erreur"
232
	                        $this->aso_totaux_dep[$nd]['plte_erreur']++;
233
	                        # Stockage des informations
234
	                        $this->tab_choro_dep[$j] = array(ZgFrDepartements::getIdChaine($nd), $num_taxo, $num_nomenc, 6, $this->id_donnee_choro++);
235
	                        if (preg_match('/(?: #|# | # )/', $val)) {# Erreur avec espace
236
	                            # Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "#".
237
	                            $autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
238
	                                                    ' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')<br />';
239
	                        }
240
                    	} elseif (preg_match('/^\s*(?:-\|-)\s*$/', $val)) {# Disparu
241
	                        # Calcul du nombre de plante ayant un statut "Disparu"
242
	                        $this->nbre_plte_disparue++;
243
	                        # Stockage par département du nombre de plante ayant un statut "Disparu"
244
	                        $this->aso_totaux_dep[$nd]['plte_disparue']++;
245
	                        # Stockage des informations
246
	                        $this->tab_choro_dep[$j] = array(ZgFrDepartements::getIdChaine($nd), $num_taxo, $num_nomenc, 6, $this->id_donnee_choro++);
247
	                        if (preg_match('/(?: -\|-|-\|- | -\|- )/', $val)) {# Disparu avec espace
248
	                            # Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "-|-".
249
	                            $autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
250
	                                                    ' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')<br />';
251
	                        }
242 jpm 252
                    	} elseif (preg_match('/^\s*(?:#\?)\s*$/', $val)) {# Erreur à confirmer
253
	                        # Calcul du nombre de plante ayant un statut "Erreur à confirmer"
254
	                        $this->nbre_plte_erreur_a_confirmer++;
255
	                        # Stockage par département du nombre de plante ayant un statut "Erreur à confirmer"
256
	                        $this->aso_totaux_dep[$nd]['plte_erreur_a_confirmer']++;
257
	                        # Stockage des informations
258
	                        $this->tab_choro_dep[$j] = array(ZgFrDepartements::getIdChaine($nd), $num_taxo, $num_nomenc, 6, $this->id_donnee_choro++);
259
                    		if (preg_match('/^(?:\s+#\?|#\?\s+|\s+#\?\s+)$/', $val)) {# Erreur à confirmer avec espace
260
	                            # Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "#?".
261
	                            $autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
262
	                                                    ' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')<br />';
263
	                        }
11 jpm 264
                    	} else {
265
							// Ajout de la valeur dans une variable car elle n'est pas conforme.
266
							$this->autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
267
													' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')<br />';
268
						}
269
						$j++;
270
					} else if (isset($val) && $val != '') {
271
						if ($val == '1') {# Présent
272
							// Calcul du nombre de plante 'nc' ayant un statut "Présent"
273
							$this->nc_nbre_plte_presente++;
274
							// Stockage par département du nombre de plante 'nc' ayant un statut "Présent"
275
							$this->aso_totaux_dep[$nd]['nc_plte_presente']++;
276
						} elseif ($val == '1?') {# Présence à confirmer
277
							// Calcul du nombre de plante 'nc' ayant un statut "Présence à confirmer"
278
							$this->nc_nbre_plte_a_confirmer++;
279
							// Stockage par département du nombre de plante 'nc' ayant un statut "Présence à confirmer"
280
							$this->aso_totaux_dep[$nd]['nc_plte_a_confirmer']++;
281
						} elseif (preg_match('/^(?:\?| \?|\? | \?)$/', $val)) {# Douteux
282
							// Calcul du nombre de plante 'nc' ayant un statut "Douteux"
283
							$this->nc_nbre_plte_douteux++;
284
							// Stockage par département du nombre de plante 'nc' ayant un statut "Douteux"
285
							$this->aso_totaux_dep[$nd]['nc_plte_douteux']++;
286
							if (preg_match('/(?: \?|\? | \? )/', $val)) {# Douteux
287
								// Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "?".
288
								$this->nc_autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
289
														' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')<br />';
290
							}
291
						} elseif (preg_match('/^(?:#| #|# | # )$/', $val)) {# Erreur
292
	                        # Calcul du nombre de plante 'nc' ayant un statut "Erreur"
293
	                        $this->nc_nbre_plte_erreur++;
294
	                        # Stockage par département du nombre de plante 'nc' ayant un statut "Erreur"
295
	                        $this->aso_totaux_dep[$nd]['nc_plte_erreur']++;
296
	                        if (preg_match('/(?: #|# | # )/', $val)) {# Erreur avec espace
297
	                            # Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "#".
298
	                            $nc_autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
299
	                                                    ' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')<br />';
300
	                        }
301
                    	} elseif (preg_match('/^\s*(?:-\|-)\s*$/', $val)) {# Disparu
302
	                        # Calcul du nombre de plante 'nc' ayant un statut "Disparu"
303
	                        $this->nc_nbre_plte_disparue++;
304
	                        # Stockage par département du nombre de plante 'nc' ayant un statut "Disparu"
305
	                        $this->aso_totaux_dep[$nd]['nc_plte_disparue']++;
306
	                        if (preg_match('/(?: -\|-|-\|- | -\|- )/', $val)) {# Disparu avec espace
307
	                            # Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "-|-".
308
	                            $nc_autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
309
	                                                    ' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')<br />';
310
	                        }
242 jpm 311
                    	} elseif (preg_match('/^\s*(?:#\?)\s*$/', $val)) {# Erreur à confirmer
312
	                        # Calcul du nombre de plante 'nc' ayant un statut "Erreur à confirmer"
313
	                        $this->nc_nbre_plte_erreur_a_confirmer++;
314
	                        # Stockage par département du nombre de plante 'nc' ayant un statut "Erreur à confirmer"
315
	                        $this->aso_totaux_dep[$nd]['nc_plte_erreur_a_confirmer']++;
316
	                        if (preg_match('/^(?:\s+#\?|#\?\s+|\s+#\?\s+)$/', $val)) {# Erreur à confirmer avec espace
317
	                            # Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "#?".
318
	                            $nc_autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
319
	                                                    ' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')<br />';
320
	                        }
11 jpm 321
                    	} else {
322
							// Ajout de la valeur dans une variable car elle n'est pas conforme.
323
							$this->nc_autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
324
													' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')<br />';
325
						}
326
					}
327
					// Affichage dans la console du numéro de l'enregistrement analysé.
328
					//echo str_repeat(chr(8), ( strlen( $i ) + 1 ))."\t".$i++;
329
				}
330
			}// fin du foreach
331
			// Affichage dans la console du numéro de l'enregistrement analysé.
332
			echo str_repeat(chr(8), ( strlen( $this->nbre_ligne ) + 1 ))."\t".$this->nbre_ligne++;
333
		}
334
		echo "\n";
335
	}
336
 
242 jpm 337
	private function initialiserTableaux($dep) {
338
		foreach ($dep as $code_dep) {
339
			if ( preg_match('/^\d{2}$/', $code_dep) ) {
340
				$this->aso_totaux_dep[$code_dep]['plte_presente'] = 0;
341
				$this->aso_totaux_dep[$code_dep]['plte_a_confirmer'] = 0;
342
				$this->aso_totaux_dep[$code_dep]['plte_douteux'] = 0;
343
				$this->aso_totaux_dep[$code_dep]['plte_erreur'] = 0;
344
				$this->aso_totaux_dep[$code_dep]['plte_disparue'] = 0;
345
				$this->aso_totaux_dep[$code_dep]['plte_erreur_a_confirmer'] = 0;
346
				$this->aso_totaux_dep[$code_dep]['autres_valeur_champ'] = 0;
347
				$this->aso_totaux_dep[$code_dep]['nc_plte_presente'] = 0;
348
				$this->aso_totaux_dep[$code_dep]['nc_plte_a_confirmer'] = 0;
349
				$this->aso_totaux_dep[$code_dep]['nc_plte_douteux'] = 0;
350
				$this->aso_totaux_dep[$code_dep]['nc_plte_erreur'] = 0;
351
				$this->aso_totaux_dep[$code_dep]['nc_plte_disparue'] = 0;
352
				$this->aso_totaux_dep[$code_dep]['nc_plte_erreur_a_confirmer'] = 0;
353
				$this->aso_totaux_dep[$code_dep]['nc_autres_valeur_champ'] = 0;
354
			}
355
		}
356
	}
357
 
358
	private function verifierDonnees() {
11 jpm 359
		// Ouverture du fichier contenant les résultats (sortie)
360
		if (!$handle = fopen($this->fichier_verif, 'w')) {
361
			echo "Impossible d'ouvrir le fichier ($this->fichier_verif)";
362
			exit;
363
		}
364
 
365
		// Création de la page
366
		$page = '<html>'."\n";
367
		$page .= '<head>'."\n";
242 jpm 368
		$page .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'."\n";
11 jpm 369
		$page .= '<title>RESULTAT DE LA VERIFICATION DU FICHIER TABULE DE LA CHOROLOGIE</title>'."\n";
370
		$page .= '</head>'."\n";
371
		$page .= '<body>'."\n";
372
		$page .= '<h1>RESULTAT DE LA VERIFICATION DU FICHIER TABULE DE LA CHOROLOGIE</h1>'."\n";
373
		$page .= '<hr/>'."\n";
374
		$page .= 	'<p>'.
375
						'Adresse fichier analysé : '.'<br />'."\n".
376
						'</p>'."\n";
377
		$page .= '<hr/>'."\n";
378
		$page .= '<h2>RESULTATS PROGRAMME DE VERIFICATION</h2>'."\n";
379
		$page .= 	'<p>'.
380
						'Nom du programme générant ce fichier : '.__FILE__.'<br />'."\n".
381
						'Nombre de lignes analysées : '.$this->nbre_ligne.'<br />'."\n".
382
						'Nbre de départements analysés : '.$this->nbre_dep_analyse.'<br />'."\n".
242 jpm 383
						'Date d\'exécution du programme : '.date('d.m.Y').'<br />'."\n".
11 jpm 384
						'</p>'."\n";
385
		$page .= '<hr/>'."\n";
386
		$page .= '<h2>RESULTATS ANALYSE CHOROLOGIE</h2>'."\n";
387
		$page .= 	'<p>'.
388
						'Nombre de nom "nc" : '.$this->nc_nbre_nom.'<br />'."\n".
389
						'Nombre de nom : '.$this->nbre_nom.'<br />'."\n".
242 jpm 390
						'Valeurs autres que 1, 1?, ?, #, #? et -|- : '.$this->autres_valeur_champ.'<br />'."\n".
391
						'Valeurs autres que 1, 1?, ?, #, #? et -|- pour les plantes nc : <br />'."\n".$this->nc_autres_valeur_champ.'</br>'."\n".
11 jpm 392
						'</p>'."\n";
393
		$page .= '<hr/>'."\n";
394
		$page .= '<h2>RESULTATS ANALYSE des CHAMPS</h2>'."\n";
395
		$page .= 	'<p>'.
396
						'Nombre de guillemets antislashés: '.$this->nbre_ligne_avec_guillemet.'<br />'."\n".
397
						'</p>'."\n";
398
		$page .= '<hr/>'."\n";
399
		$page .= '<h2>TABLEAUX</h2>'."\n";
400
 
401
		// Tableau des numéros nomenclaturaux dupliqués
402
		$table = '<table><thead><tr><th colspan="3">Tableau des numéros nomenclaturaux dupliqués </th></tr>';
403
		$table .= '<tr><th>Numéro nomenclatural</th><th>Nbre d\'itération</th><th>Lignes</th></tr></thead>';
404
		$afficher_tab_num_duplique = 0;
405
		ksort($this->aso_num_nomenc);
406
		$table .= '<tbody style="text-align: center;">';
407
		foreach ($this->aso_num_nomenc as $cle_nomenc => $val ) {
408
			$ligne = '<tr><td>'.$cle_nomenc.'</td><td>'.$val['compteur'].'</td><td>'.$val['ligne'].'</td></tr>';
409
			if ($val['compteur'] > 1) {
410
				$table .= $ligne;
411
				$afficher_tab_num_duplique = 1;
412
			}
413
		}
414
		if ( $afficher_tab_num_duplique == 1 ) {
415
			$page .= $table.'</tbody></table>';
416
		}
417
 
418
		// Tableau des résultats par départements
242 jpm 419
		$table = '<table><thead><tr><th colspan="14">Tableau des résulats par départements</th></tr>';
11 jpm 420
		$table .= '<tr><th>Département</th><th>Nbre pltes présentes</th><th>Nbre pltes à confirmer</th>'.
242 jpm 421
			'<th>Nbre pltes douteuses</th><th>Nbre pltes disparues</th><th>Nbre pltes erreur</th><th>Nbre pltes erreur à confirmer</th>'.
11 jpm 422
			'<th>Total</th><th>Nbre pltes nc présentes</th><th>Nbre pltes nc à confirmer</th>'.
242 jpm 423
			'<th>Nbre nc pltes douteuses</th><th>Nbre nc pltes disparues</th><th>Nbre nc pltes erreur</th><th>Nbre nc pltes erreur à confirmer</th></tr></thead>';
11 jpm 424
		$table .= '<tbody style="text-align: center;">';
425
		ksort($this->aso_totaux_dep);
426
		foreach ($this->aso_totaux_dep as $cle_dep => $val ) {
242 jpm 427
			$plt_total = $val{'plte_presente'} + $val{'plte_a_confirmer'} + $val{'plte_douteux'} + $val{'plte_disparue'} + $val{'plte_erreur'} + $val{'plte_erreur_a_confirmer'};
11 jpm 428
			$table .= '<tr><td>'.ZgFrDepartements::getNom($cle_dep).' ('.ZgFrDepartements::getIdChaine($cle_dep).') </td>'.
429
				'<td>'.$val{'plte_presente'}.'</td><td>'.$val{'plte_a_confirmer'}.'</td><td>'.$val{'plte_douteux'}.'</td>'.
242 jpm 430
				'<td>'.$val{'plte_disparue'}.'</td><td>'.$val{'plte_erreur'}.'</td><td>'.$val{'plte_erreur_a_confirmer'}.'</td><td>'.$plt_total.'</td>'.
11 jpm 431
				'<td>'.$val{'nc_plte_presente'}.'</td><td>'.$val{'nc_plte_a_confirmer'}.'</td><td>'.$val{'nc_plte_douteux'}.'</td>'.
242 jpm 432
				'<td>'.$val{'nc_plte_disparue'}.'</td><td>'.$val{'nc_plte_erreur'}.'</td><td>'.$val{'nc_plte_erreur_a_confirmer'}.'</td></tr>';
11 jpm 433
		}
434
 
242 jpm 435
		$table .= '<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>'.
436
				'<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
437
		$plt_total = $this->nbre_plte_presente + $this->nbre_plte_a_confirmer + $this->nbre_plte_douteux + $this->nbre_plte_disparue + $this->nbre_plte_erreur + $this->nbre_plte_erreur_a_confirmer;
11 jpm 438
		$table .= '<tr><td>Totaux : '.$this->nbre_dep_analyse.' départements</td><td>'.$this->nbre_plte_presente.'</td>'.
439
			'<td>'.$this->nbre_plte_a_confirmer.'</td><td>'.$this->nbre_plte_douteux.'</td><td>'.$this->nbre_plte_disparue.'</td>'.
242 jpm 440
			'<td>'.$this->nbre_plte_erreur.'</td><td>'.$this->nbre_plte_erreur_a_confirmer.'</td><td>'.$plt_total.'</td>'.
11 jpm 441
			'<td>'.$this->nc_nbre_plte_presente.'</td>'.'<td>'.$this->nc_nbre_plte_a_confirmer.'</td>'.
242 jpm 442
			'<td>'.$this->nc_nbre_plte_douteux.'</td><td>'.$this->nc_nbre_plte_disparue.'</td><td>'.$this->nc_nbre_plte_erreur.'</td><td>'.$this->nc_nbre_plte_erreur_a_confirmer.'</td></tr>';
11 jpm 443
 
444
		$table .= '<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>'.
445
				'<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
242 jpm 446
		$total_nbre_plte = ($this->nbre_plte_presente + $this->nbre_plte_a_confirmer + $this->nbre_plte_douteux + $this->nbre_plte_disparue + $this->nbre_plte_erreur + $this->nbre_plte_erreur_a_confirmer);
447
		$total_nbre_plte_nc = ($this->nc_nbre_plte_presente + $this->nc_nbre_plte_a_confirmer + $this->nc_nbre_plte_douteux + $this->nc_nbre_plte_disparue + $this->nc_nbre_plte_erreur + $this->nc_nbre_plte_erreur_a_confirmer);
448
		$table .= '<tr><td>Totaux plante / plante nc</td><td colspan="7">'.$total_nbre_plte.'</td>'.
449
			'<td colspan="6">'.$total_nbre_plte_nc.'</td></tr>';
11 jpm 450
 
242 jpm 451
		$table .= '<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>'.
452
				'<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
11 jpm 453
		$plt_total = $this->nbre_plte_presente + $this->nc_nbre_plte_presente + $this->nc_nbre_plte_a_confirmer + $this->nbre_plte_a_confirmer;
242 jpm 454
		$table .= '<tr><td>Total plantes présentes et à confirmer</td><td colspan="13">'.$plt_total.'</td></tr>';
11 jpm 455
 
242 jpm 456
		$table .= '<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>'.
457
				'<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
11 jpm 458
		$plt_total = $this->nbre_plte_presente + $this->nc_nbre_plte_presente;
242 jpm 459
		$table .= '<tr><td>Total plantes présentes</td><td colspan="13">'.$plt_total.'</td></tr>';
11 jpm 460
 
242 jpm 461
		$table .= '<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>'.
462
				'<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
11 jpm 463
		$plt_total = $total_nbre_plte + $total_nbre_plte_nc;
242 jpm 464
		$table .= '<tr><td>Total données chorologiques</td><td colspan="13">'.$plt_total.'</td></tr>';
11 jpm 465
 
466
		$table .= '</tbody></table>';
467
		$page .= $table;
468
 
469
		$page .= '<hr/>'."\n";
470
		$page .= '<h2>NOTES</h2>'."\n";
471
		$page .= 	'<p>'.
472
						'1.- Chaque champ précédé par "ATTENTION" doit être vide.'."\n".
473
						'S\'il ne l\'est pas, il y a une erreur'."\n".
474
						'</p>'."\n";
475
		$page .= '</body>'."\n";
476
		$page .= '</html>'."\n";
477
		// Fermeture de la poignée sur le fichier de sortie
478
		if (fwrite($handle, $page) === FALSE) {
479
			echo "Impossible d'écrire dans le fichier ($this->fichier_verif)";
480
			exit;
481
		}
482
		echo 'Ecriture du fichier de vérification de la chorologie réalisée!'."\n";
483
		fclose($handle);
484
	}
485
 
242 jpm 486
	private function supprimerTous() {
487
		$tablesChorodep = implode(',', $this->getNomsTablesChorodep());
488
		$tableContributeurs = Config::get('tables.chorodepContributeurs');
489
		$tableSources = Config::get('tables.chorodepSources');
490
		$tableOntologies = Config::get('tables.chorodepOntologies');
349 jpm 491
		$requete = "DROP TABLE IF EXISTS chorodep_meta, $tablesChorodep, $tableContributeurs, $tableSources, $tableOntologies ";
242 jpm 492
		$this->getBdd()->requeter($requete);
493
	}
494
 
495
	private function getNomsTablesChorodep() {
496
		$versions = explode(',', Config::get('versions'));
497
		$tableTpl = Config::get('tables.chorodepTpl');
498
		$tablesChorodep = array();
499
		foreach ($versions as $version) {
500
			$tablesChorodep[] = sprintf($tableTpl, $version);
501
		}
502
		return $tablesChorodep;
503
	}
504
 
1124 mathias 505
	private function getNomTableDerniereVersion() {
242 jpm 506
		$version = $this->getDerniereVersion();
507
		$table = sprintf(Config::get('tables.chorodepTpl'), $version);
508
		return $table;
509
	}
510
 
511
	private function getDerniereVersion() {
512
		$version = array_pop(explode(',', Config::get('versions')));
513
		return $version;
514
	}
1124 mathias 515
 
516
	// ----------
517
	// intégration des noms vernaculaires et statuts de protection (NVSP) dans
518
	// une table dédiée, pour permettre le service intégratif de l'applciation "chorologie"
519
	// (basé sur les scripts de "gentiana-services")
1179 mathias 520
	// @NOTE pas très content d'avoir mis ça là - c'est pratique mais pas très logique
1124 mathias 521
	// ----------
522
 
523
	/**
1179 mathias 524
	 * Effectue toutes les étapes du chargement des noms vernaculaires et statuts
525
	 * de protection
526
	 */
527
	protected function chargerNVSP() {
528
		$this->nettoyageNVSP();
529
		$this->chargerStructureNVSP();
530
		$this->genererNomsVernaculaires();
531
		$this->genererStatutsProtection();
532
	}
533
 
534
	/**
1124 mathias 535
	 * Dézingue tout le bousin
536
	 * @TODO chaque méthode devrait s'autonettoyer au début afin d'être répétable
537
	 * sans avoir à tout reprendre depuis le début (principe du dump)
538
	 */
539
	protected function nettoyageNVSP() {
540
		echo "---- suppression des tables\n";
541
		$tableStatutsProtection = Config::get('tables.statuts_protection');
542
		$tableNomsVernaculaires = Config::get('tables.noms_vernaculaires');
543
		$req = "DROP TABLE IF EXISTS `" . $tableStatutsProtection . "`";
544
		$this->getBdd()->requeter($req);
545
		$req = "DROP TABLE IF EXISTS `" . $tableNomsVernaculaires . "`;";
546
		$this->getBdd()->requeter($req);
547
	}
548
 
549
	/**
550
	 * Crée les tables vides
551
	 */
552
	protected function chargerStructureNVSP() {
553
		echo "---- création des tables\n";
554
		$contenuSql = $this->recupererContenu(Config::get('chemins.structureNVSP'));
555
		$this->executerScripSql($contenuSql);
556
	}
557
 
558
	/**
559
	 * Va chercher les noms vernaculaires pour chaque espèce, et les rajoute
560
	 * dans la table dédiée
561
	 */
1179 mathias 562
	protected function genererNomsVernaculaires() {
1124 mathias 563
		$tableNomsVernaculaires = Config::get('tables.noms_vernaculaires');
564
		restore_error_handler();
565
		restore_exception_handler();
566
		ini_set("display_errors", true);
567
		error_reporting(E_ALL);
568
		$squeletteUrlNvjfl = Config::get("url_nvjfl");
569
		echo "---- récupération des noms vernaculaires depuis eFlore\n";
570
		$depart = 0;
571
		$nbInsertions = 0;
572
		$yenaencore = true;
573
		$tailleTranche = 1000;
574
		while ($yenaencore) {
575
			$url = sprintf($squeletteUrlNvjfl, $depart, $tailleTranche);
576
			$noms = $this->chargerDonnees($url);
577
			// Si quelqu'un parvient à dédoublonner les $valeurs, on enlève le IGNORE
578
			$req = "INSERT IGNORE INTO " . $tableNomsVernaculaires . " VALUES ";
579
			$valeurs = array();
580
			// insertion des données
581
			foreach ($noms['resultat'] as $res) {
582
				$numTaxons = explode(',', $res['num_taxon']);
583
				$nvP = $this->getBdd()->proteger($res['nom']);
584
				foreach ($numTaxons as $numTaxon) {
585
					$valeurs[] = "(" . $numTaxon . ", " . $nvP  . ")";
586
				}
587
			}
588
			$req .= implode(",", $valeurs);
589
			$this->getBdd()->executer($req);
590
			// prochain tour
591
			$nbInsertions += count($valeurs); // Faux car INSERT IGNORE - dédoublonner ou compter les insertions réelles
592
			$depart += $tailleTranche;
593
			$total = $noms['entete']['total'];
594
			$yenaencore = $depart <= $total;
595
			echo "insérés: " . min($depart, $total) . " noms, " . $nbInsertions . " attributions\n";
596
		}
597
	}
598
 
599
	 /**
600
	  * Va chercher les statuts de protection pour chaque espèce et les rajoute
601
	  * à la table; importe un fichier dump SQL des lois
602
	  */
1179 mathias 603
	 protected function genererStatutsProtection() {
1124 mathias 604
	 	$tableChorologie = $this->getNomTableDerniereVersion();
605
	 	$tableStatutsProtection = Config::get('tables.statuts_protection');
606
	 	echo "---- récupération des statuts de protection depuis eFlore\n";
607
	 	$req = "SELECT distinct num_nom FROM " . $tableChorologie;
608
	 	$resultat = $this->getBdd()->recupererTous($req);
609
	 	// pour chaque taxon mentionné (inefficace mais évite d'implémenter un
610
	 	// mode liste sur le service eflore/sptb
611
	 	$squeletteUrlSptb = Config::get("url_sptb");
612
	 	foreach ($resultat as $res) {
613
	 		$nn = $res['num_nom'];
614
	 		//echo "NN: $nn\n";
615
	 		if ($nn != 0) {
616
	 			$url = sprintf($squeletteUrlSptb, $nn);
617
	 			//echo "URL: $url\n";
618
	 			$statuts = $this->chargerDonnees($url);
619
	 			//echo "STATUTS: " . print_r($statuts, true) . "\n";
620
	 			if (count($statuts) > 0) {
621
	 				$json = array();
622
	 				foreach ($statuts as $statut) {
623
 						$nouveauStatut = array();
624
 						$nouveauStatut['zone'] = $statut['code_zone_application'];
625
 						$nouveauStatut['lien'] = $statut['hyperlien_legifrance'];
626
 						$json[] =  $nouveauStatut;
627
	 				}
628
	 				// Si au moins un statut
629
	 				if (count($json) > 0) {
630
	 					$json = json_encode($json);
631
	 					//echo "JSON: " . print_r($json, true) . "\n";
632
	 					// Insertion d'un bout de JSON
633
	 					$jsonP = $this->getBdd()->proteger($json);
634
	 					$nnP = $this->getBdd()->proteger($nn);
635
	 					$reqIns = "INSERT INTO " . $tableStatutsProtection
636
	 					. " values($nnP, $jsonP)";
637
	 					//echo "ReqIns: $reqIns\n";
638
	 					$this->getBdd()->executer($reqIns);
639
	 				}
640
	 			}
641
	 		}
642
	 	}
643
	 }
11 jpm 644
}
645
 
646
class ZgFrDepartements {
647
	static private $departements =
648
        array(
649
        "01" => array("Ain", "01", 1),
650
        "02" => array("Aisne", "02", 2),
651
        "03" => array("Allier", "03", 3),
652
        "04" => array("Alpes-de-Haute-Provence", "04", 4),
653
        "05" => array("Hautes-Alpes", "05", 5),
654
        "06" => array("Alpes-Maritimes", "06", 6),
655
        "07" => array("Ardèche", "07", 7),
656
        "08" => array("Ardennes", "08", 8),
657
        "09" => array("Ariège", "09", 9),
658
        "10" => array("Aube", "10", 10),
659
        "11" => array("Aude", "11", 11),
660
        "12" => array("Aveyron", "12", 12),
661
        "13" => array("Bouches-du-Rhône", "13", 13),
662
        "14" => array("Calvados", "14", 14),
663
        "15" => array("Cantal", "15", 15),
664
        "16" => array("Charente", "16", 16),
665
        "17" => array("Charente-Maritime", "17", 17),
666
        "18" => array("Cher", "18", 18),
667
        "19" => array("Corrèze", "19", 19),
668
        "20" => array("Corse", "20", 20),
669
        "2A" => array("Haute-Corse", "2A", 20),
670
        "2B" => array("Corse-du-Sud", "2B", 20),
671
        "21" => array("Côte-d'Or", "21", 21),
672
        "22" => array("Côtes-d'Armor", "22", 22),
673
        "23" => array("Creuse", "23", 23),
674
        "24" => array("Dordogne", "24", 24),
675
        "25" => array("Doubs","25", 25),
676
        "26" => array("Drôme", "26", 26),
677
        "27" => array("Eure", "27", 27),
678
        "28" => array("Eure-et-Loir", "28", 28),
679
        "29" => array("Finistère", "29", 29),
680
        "30" => array("Gard", "30", 30),
681
        "31" => array("Haute-Garonne", "31", 31),
682
        "32" => array("Gers", "32", 32),
683
        "33" => array("Gironde", "33", 33),
684
        "34" => array("Hérault", "34", 34),
685
        "35" => array("Ille-et-Vilaine", "35", 35),
686
        "36" => array("Indre", "36", 36),
687
        "37" => array("Indre-et-Loire", "37", 37),
688
        "38" => array("Isère", "38", 38),
689
        "39" => array("Jura", "39", 39),
690
        "40" => array("Landes", "40", 40),
691
        "41" => array("Loir-et-Cher", "41", 41),
692
        "42" => array("Loire", "42", 42),
693
        "43" => array("Haute-Loire", "43", 43),
694
        "44" => array("Loire-Atlantique", "44", 44),
695
        "45" => array("Loiret", "45", 45),
696
        "46" => array("Lot", "46", 46),
697
        "47" => array("Lot-et-Garonne", "47", 47),
698
        "48" => array("Lozére ", "48", 48),
699
        "49" => array("Maine-et-Loire", "49", 49),
700
        "50" => array("Manche", "50", 50),
701
        "51" => array("Marne", "51", 51),
702
        "52" => array("Haute-Marne", "52", 52),
703
        "53" => array("Mayenne", "53", 53),
704
        "54" => array("Meurthe-et-Moselle", "54", 54),
705
        "55" => array("Meuse", "55", 55),
706
        "56" => array("Morbihan", "56", 56),
707
        "57" => array("Moselle", "57", 57),
708
        "58" => array("Nièvre", "58", 58),
709
        "59" => array("Nord", "59", 59),
710
        "60" => array("Oise", "60", 60),
711
        "61" => array("Orne", "61", 61),
712
        "62" => array("Pas-de-Calais", "62", 62),
713
        "63" => array("Puy-de-Dôme", "63", 63),
714
        "64" => array("Pyrénées-Atlantiques", "64", 64),
715
        "65" => array("Hautes-Pyrénées", "65", 65),
716
        "66" => array("Pyrénées-Orientales", "66", 66),
717
        "67" => array("Bas-Rhin", "67", 67),
718
        "68" => array("Haut-Rhin", "68", 68),
719
        "69" => array("Rhône", "69", 69),
720
        "70" => array("Haute-Saône", "70", 70),
721
        "71" => array("Saône-et-Loire", "71", 71),
722
        "72" => array("Sarthe", "72", 72),
723
        "73" => array("Savoie", "73", 73),
724
        "74" => array("Haute-Savoie", "74", 74),
725
        "75" => array("Paris", "75", 75),
726
        "76" => array("Seine-Maritime", "76", 76),
727
        "77" => array("Seine-et-Marne", "77", 77),
728
        "78" => array("Yvelines", "78", 78),
729
        "79" => array("Deux-Sèvres", "79", 79),
730
        "80" => array("Somme", "80", 80),
731
        "81" => array("Tarn", "81", 81),
732
        "82" => array("Tarn-et-Garonne", "82", 82),
733
        "83" => array("Var", "83", 83),
734
        "84" => array("Vaucluse", "84", 84),
735
        "85" => array("Vendée", "85", 85),
736
        "86" => array("Vienne", "86", 86),
737
        "87" => array("Haute-Vienne", "87", 87),
738
        "88" => array("Vosges", "88", 88),
739
        "89" => array("Yonne", "89", 89),
740
        "90" => array("Territoire-de-Belfort", "90", 90),
741
        "91" => array("Essonne", "91", 91),
742
        "92" => array("Hauts-de-Seine", "92", 92),
743
        "93" => array("Seine-Saint-Denis", "93", 93),
744
        "94" => array("Val-de-Marne", "94", 94),
745
        "95" => array("Val-d'Oise", "95", 95),
746
        "96" => array("aaa", "96", 96),
747
        "971" => array("Guadeloupe", "971", 971),
748
        "972" => array("Martinique", "972", 972),
749
        "973" => array("Guyane", "973", 973),
750
        "974" => array("Réunion", "974", 974),
751
        "99" => array("Etranger", "99", 99),
752
        );
753
 
754
	static public function get() {
755
		return self::$departements;
756
	}
757
 
758
    static public function getNom($n) {
759
		return self::$departements[$n][0];
760
	}
761
 
762
	static public function getIdChaine($n) {
763
		return self::$departements[$n][1];
764
	}
765
 
766
	static public function getIdNumerique($n) {
767
		return (int)self::$departements[$n][2];
768
	}
769
 
770
	static public function getIdEflore($n) {
771
		return (int)self::$departements[$n][3];
772
	}
773
}
1124 mathias 774
?>