Subversion Repositories eFlore/Projets.eflore-projets

Rev

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