Subversion Repositories eFlore/Applications.cel

Rev

Rev 1081 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1081 Rev 1127
1
<?php
1
<?php
2
 
2
 
3
// In : utf8
3
// In : utf8
4
// Out : utf8
4
// Out : utf8
5
 
5
 
6
/*
6
/*
7
 
7
 
8
Octobre 2010 David Delon.
8
Octobre 2010 David Delon.
9
Import d'observations dans le carnet en ligne à partir d'un fichier excel chargé par l'utilisateur
9
Import d'observations dans le carnet en ligne à partir d'un fichier excel chargé par l'utilisateur
10
et liaison d'images déjà chargee aux observations ainsi crées.
10
et liaison d'images déjà chargee aux observations ainsi crées.
11
 
11
 
12
Nom des colonnes imposé, mais présence de toutes les colonnes non obligatoires, ordre non imposé
12
Nom des colonnes imposé, mais présence de toutes les colonnes non obligatoires, ordre non imposé
13
Aucune valeur dans les colonnes n'est obligatoire
13
Aucune valeur dans les colonnes n'est obligatoire
14
Pour une ligne donnée, si tous les champs vides on ne fait rien, ou si seul le champ image est présent.
14
Pour une ligne donnée, si tous les champs vides on ne fait rien, ou si seul le champ image est présent.
15
Si la seule différence entre deux lignes est la valeur de la colonne image, on considère que c'est la même observation à laquelle on associe plusieurs images.
15
Si la seule différence entre deux lignes est la valeur de la colonne image, on considère que c'est la même observation à laquelle on associe plusieurs images.
16
Si au moins deux lignes (ou plus) sont complètement identiques on prend en compte une seule ligne (les doublons sont éliminés).
16
Si au moins deux lignes (ou plus) sont complètement identiques on prend en compte une seule ligne (les doublons sont éliminés).
17
 
17
 
18
*/
18
*/
19
 
-
 
20
 
19
 
21
// Nom des colonnes
20
// Nom des colonnes
22
 
21
 
23
define('COMMUNE','commune'); // soit un nom de commune, soit un code INSEE (5 chiffres), ou "nom de commune (numero departement)"
22
define('COMMUNE','commune'); // soit un nom de commune, soit un code INSEE (5 chiffres), ou "nom de commune (numero departement)"
24
define('LIEUDIT','lieu-dit'); // Texte libre
23
define('LIEUDIT','lieu-dit'); // Texte libre
25
define('STATION','station'); // Texte libre
24
define('STATION','station'); // Texte libre
26
define('MILIEU','milieu'); // Texte libre
25
define('MILIEU','milieu'); // Texte libre
27
define('LATITUDE','latitude'); // En decimal systeme WGS84
26
define('LATITUDE','latitude'); // En decimal systeme WGS84
28
define('LONGITUDE','longitude'); // En decimal systeme WGS84 
27
define('LONGITUDE','longitude'); // En decimal systeme WGS84 
29
define('NOTES','notes'); // Texte libre
28
define('NOTES','notes'); // Texte libre
30
define('DATEOBS','date'); // date au format jj/mm/aaaa
29
define('DATEOBS','date'); // date au format jj/mm/aaaa
31
define('ESPECE','espece'); // texte libre, nom latin, ou code nomenclatural (format BDNFFnn999999)
30
define('ESPECE','espece'); // texte libre, nom latin, ou code nomenclatural (format BDNFFnn999999)
32
define('IMAGE','image'); //  nom des fichiers images préalablement uploadés sur le CEL séparés par des "/"
31
define('IMAGE','image'); //  nom des fichiers images préalablement uploadés sur le CEL séparés par des "/"
33
define('DEPARTEMENT','departement'); //  Texte libre
32
define('DEPARTEMENT','departement'); //  Texte libre
34
define('TRANSMETTRE','transmettre'); //  "1" ou "oui", toute autre valeur (y compris vide) sera consideree comme "non""
33
define('TRANSMETTRE','transmettre'); //  "1" ou "oui", toute autre valeur (y compris vide) sera consideree comme "non""
35
 
34
 
36
 
35
 
37
// Resultat de l'analyse d'une ligne
36
// Resultat de l'analyse d'une ligne
38
define('LIGNE_VIDE',1); //  
37
define('LIGNE_VIDE',1); //  
39
define('LIGNE_NORMALE',2); //  
38
define('LIGNE_NORMALE',2); //  
40
define('LIGNE_IMAGE_SEULEMENT',3); //  
39
define('LIGNE_IMAGE_SEULEMENT',3); //  
41
 
40
 
42
// Parser de Nom
41
// Parser de Nom
43
include('NameParser.php');
42
include('NameParser.php');
44
 
43
 
45
Class InventoryImportExcel extends DBAccessor  {
44
Class InventoryImportExcel extends DBAccessor  {
46
 
45
 
47
// Element constituant une observation 
46
// Element constituant une observation 
48
 
47
 
49
	var $format_observation=array(COMMUNE ,LIEUDIT ,STATION , DEPARTEMENT, MILIEU ,LATITUDE ,LONGITUDE ,NOTES ,DATEOBS ,ESPECE ,TRANSMETTRE, IMAGE );
48
	var $format_observation=array(COMMUNE ,LIEUDIT ,STATION , DEPARTEMENT, MILIEU ,LATITUDE ,LONGITUDE ,NOTES ,DATEOBS ,ESPECE ,TRANSMETTRE, IMAGE );
50
 
49
 
51
// Fichier configuration
50
// Fichier configuration
52
	var $config;
51
	var $config;
53
 
52
 
54
// Encapsulation classe lecture fichier excel
53
// Encapsulation classe lecture fichier excel
55
	var $extendExcelReader;
54
	var $extendExcelReader;
56
 
55
 
57
// Dernier numero d'ordre utilise
56
// Dernier numero d'ordre utilise
58
	var $dernier_ordre=1;
57
	var $dernier_ordre=1;
59
	
58
	
60
	var $cpt_images_liees=0;
59
	var $cpt_images_liees=0;
61
 
60
 
62
/**
61
/**
63
 Constructeur
62
 Constructeur
64
**/
63
**/
65
	function InventoryImportExcel($config) {
64
	function InventoryImportExcel($config) {
66
 
65
 
67
		$this->config=$config;
66
		$this->config=$config;
68
		// Pas d'heritage multiple en php :(
67
		// Pas d'heritage multiple en php :(
69
 
68
 
70
		$this->extendExcelReader = new ExcelReader();
69
		$this->extendExcelReader = new ExcelReader();
71
		$this->extendExcelReader->initExcelReader();
70
		$this->extendExcelReader->initExcelReader();
72
	}
71
	}
73
 
72
 
74
/**
73
/**
75
 Sur post
74
 Sur post
76
**/
75
**/
77
	function createElement($pairs) {
76
	function createElement($pairs) {
78
 
77
 
79
 
78
 
80
		$pairs['utilisateur']= $_POST['identifiant'];
79
		$pairs['utilisateur']= $_POST['identifiant'];
81
		if(!isset($_SESSION)) {session_start();}
80
		if(!isset($_SESSION)) {session_start();}
82
        $this->controleUtilisateur($pairs['utilisateur']);
81
        $this->controleUtilisateur($pairs['utilisateur']);
83
 
82
 
84
        foreach($_FILES as $file) { // C'est le plus simple
83
        foreach($_FILES as $file) { // C'est le plus simple
85
            $infos_fichier = $file ;
84
            $infos_fichier = $file ;
86
        }
85
        }
87
 
86
 
88
		// Chargement tableau en memoire
87
		// Chargement tableau en memoire
89
		$data = new Spreadsheet_Excel_Reader($infos_fichier['tmp_name'], false); // false : pour menager la memoire.
88
		$data = new Spreadsheet_Excel_Reader($infos_fichier['tmp_name'], false); // false : pour menager la memoire.
90
		$arr = array();
89
		$arr = array();
91
 
90
 
92
		$rowcount=$data->rowcount(0);
91
		$rowcount=$data->rowcount(0);
93
		$colcount=$data->colcount(0);
92
		$colcount=$data->colcount(0);
94
 
93
 
95
		if ($rowcount<=1) { // TODO : retour erreur
94
		if ($rowcount<=1) { // TODO : retour erreur
96
			print "Tableau vide";
95
			print "Tableau vide";
97
			exit;
96
			exit;
98
		}
97
		}
99
 
98
 
100
		// Chargement tableau 
99
		// Chargement tableau 
101
        for($row=1;$row<=$rowcount;$row++) 
100
        for($row=1;$row<=$rowcount;$row++) 
102
            for($col=1;$col<=$colcount;$col++) 
101
            for($col=1;$col<=$colcount;$col++) 
103
                $arr[$col][$row] = $data->val($row,$col,0); // Attention, inversion voulue
102
                $arr[$col][$row] = $data->val($row,$col,0); // Attention, inversion voulue
104
              
103
              
105
		// 1 : Traitement intitules
104
		// 1 : Traitement intitules
106
		$line = array();
105
		$line = array();
107
 
106
 
108
		/* Les colonnes ne sont pas forcemment dans l'ordre  : on les extrait pour traitement futur  */
107
		/* Les colonnes ne sont pas forcemment dans l'ordre  : on les extrait pour traitement futur  */
109
        for($col=1;$col<=$colcount;$col++) {
108
        for($col=1;$col<=$colcount;$col++) {
110
            $colonne=strtolower($arr[$col][1]);
109
            $colonne=strtolower($arr[$col][1]);
111
            $colonne=trim($colonne);
110
            $colonne=trim($colonne);
112
            $colonne=cp1252_to_utf8($colonne);
111
            $colonne=cp1252_to_utf8($colonne);
113
            $colonne=remove_accent($colonne);
112
            $colonne=remove_accent($colonne);
114
            switch ($colonne) {  // On ne garde que les colonnes que l'on souhaite traiter
113
            switch ($colonne) {  // On ne garde que les colonnes que l'on souhaite traiter
115
                case COMMUNE:
114
                case COMMUNE:
116
                case LIEUDIT:
115
                case LIEUDIT:
117
                case STATION:
116
                case STATION:
118
                case MILIEU:
117
                case MILIEU:
119
                case DEPARTEMENT:
118
                case DEPARTEMENT:
120
                case LATITUDE:
119
                case LATITUDE:
121
                case LONGITUDE:
120
                case LONGITUDE:
122
                case NOTES:
121
                case NOTES:
123
                case DATEOBS:
122
                case DATEOBS:
124
                case ESPECE:
123
                case ESPECE:
125
                case TRANSMETTRE:
124
                case TRANSMETTRE:
126
                case IMAGE:
125
                case IMAGE:
127
                    $selection=array_values($arr[$col]);
126
                    $selection=array_values($arr[$col]);
128
                    array_shift($selection); // On ne garde pas la premiere ligne, qui contient les intitules
127
                    array_shift($selection); // On ne garde pas la premiere ligne, qui contient les intitules
129
                    $line[$colonne]=$selection;
128
                    $line[$colonne]=$selection;
130
                    break;
129
                    break;
131
 
130
 
132
            }
131
            }
133
        } 	
132
        } 	
134
		// 1 : Traitement lignes
133
		// 1 : Traitement lignes
135
		$cpt_obs=0;
134
		$cpt_obs=0;
136
		$cpt_img=0;
135
		$cpt_img=0;
137
 
136
 
138
        /* Recherche dernier numero d'ordre utilise : pas de mise a jour concurente a priori */
137
        /* Recherche dernier numero d'ordre utilise : pas de mise a jour concurente a priori */
139
        $DB=$this->connectDB($this->config,'database_cel'); 
138
        $DB=$this->connectDB($this->config,'database_cel'); 
140
        $query="SELECT MAX(ordre) AS ordre FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($pairs['utilisateur'])."' ";
139
        $query="SELECT MAX(ordre) AS ordre FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($pairs['utilisateur'])."' ";
141
 
140
 
142
        $res =& $DB->query($query);
141
        $res =& $DB->query($query);
143
        if (DB::isError($res)) {
142
        if (DB::isError($res)) {
144
            die($res->getMessage());
143
            die($res->getMessage());
145
        }
144
        }
146
 
145
 
147
        while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
146
        while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
148
            $this->dernier_ordre=$row['ordre']; // 1  par defaut
147
            $this->dernier_ordre=$row['ordre']; // 1  par defaut
149
        }
148
        }
150
 
149
 
151
		for ($i=0;$i<=$rowcount-1;$i++) {
150
		for ($i=0;$i<=$rowcount-1;$i++) {
152
			// On saute les eventuelles lignes vides du debut et les lignes contenant des information sur image uniquement
151
			// On saute les eventuelles lignes vides du debut et les lignes contenant des information sur image uniquement
153
			while ((in_array($retour_analyse=$this->analyserLigne($line,$i),array(LIGNE_IMAGE_SEULEMENT, LIGNE_VIDE))) && ($i<=$rowcount)) {
152
			while ((in_array($retour_analyse=$this->analyserLigne($line,$i),array(LIGNE_IMAGE_SEULEMENT, LIGNE_VIDE))) && ($i<=$rowcount)) {
154
				if  ($retour_analyse==LIGNE_IMAGE_SEULEMENT) {
153
				if  ($retour_analyse==LIGNE_IMAGE_SEULEMENT) {
155
					// print "image non rattachee a une observation";
154
					// print "image non rattachee a une observation";
156
				}
155
				}
157
				else {
156
				else {
158
					// print "vide";
157
					// print "vide";
159
				}
158
				}
160
				$i++;
159
				$i++;
161
			}
160
			}
162
			while (($this->analyserLigne($line,$i)==LIGNE_NORMALE) && ($i<=$rowcount)) {
161
			while (($this->analyserLigne($line,$i)==LIGNE_NORMALE) && ($i<=$rowcount)) {
163
				$ordre=$this->traiterLigne($line,$i,$pairs['utilisateur'],$DB);
162
				$ordre=$this->traiterLigne($line,$i,$pairs['utilisateur'],$DB);
164
				if ($ordre>0) {
163
				if ($ordre>0) {
165
					$cpt_obs++; // Compteur d'observations crees
164
					$cpt_obs++; // Compteur d'observations crees
166
				}
165
				}
167
				$i++;
166
				$i++;
168
				// On saute les lignes vide ou on traite les lignes suivantes contenant des informations sur image seulement
167
				// On saute les lignes vide ou on traite les lignes suivantes contenant des informations sur image seulement
169
				while ((in_array($retour_analyse=$this->analyserLigne($line,$i),array(LIGNE_IMAGE_SEULEMENT, LIGNE_VIDE))) && ($i<=$rowcount)) {
168
				while ((in_array($retour_analyse=$this->analyserLigne($line,$i),array(LIGNE_IMAGE_SEULEMENT, LIGNE_VIDE))) && ($i<=$rowcount)) {
170
					if  ($retour_analyse==LIGNE_IMAGE_SEULEMENT) {
169
					if  ($retour_analyse==LIGNE_IMAGE_SEULEMENT) {
171
						$this->traiterLigneComplement($line,$i,$pairs['utilisateur'],$ordre); // images supplementaires
170
						$this->traiterLigneComplement($line,$i,$pairs['utilisateur'],$ordre); // images supplementaires
172
					}
171
					}
173
					else {
172
					else {
174
						// print "vide";
173
						// print "vide";
175
					}
174
					}
176
					$i++;
175
					$i++;
177
				}	
176
				}	
178
			}
177
			}
179
		}
178
		}
180
		$message = '';
179
		$message = '';
181
		
180
		
182
		if($this->cpt_images_liees > 0) {
181
		if($this->cpt_images_liees > 0) {
183
			$message = $this->cpt_images_liees.' images liees pour ';
182
			$message = $this->cpt_images_liees.' images liees pour ';
184
		}
183
		}
185
		
184
		
186
		$message .= $cpt_obs;
185
		$message .= $cpt_obs;
187
		print $message;
186
		print $message;
188
 
187
 
189
	}
188
	}
190
 
189
 
191
function analyserLigne($line,$i) {
190
function analyserLigne($line,$i) {
192
	
191
	
193
	$ligne_vide=true;
192
	$ligne_vide=true;
194
	$ligne_image_seulement=true;
193
	$ligne_image_seulement=true;
195
	$ligne_normale=true;
194
	$ligne_normale=true;
196
	
195
	
197
	$ligne_identique_sauf_image = true;
196
	$ligne_identique_sauf_image = true;
198
	
197
	
199
	foreach ($this->format_observation as $colonne) {
198
	foreach ($this->format_observation as $colonne) {
200
		
199
		
201
		if($i < 1) {
200
		if($i < 1) {
202
			$ligne_identique_sauf_image = false;
201
			$ligne_identique_sauf_image = false;
203
		} else {
202
		} else {
204
			
203
			
205
			if($colonne!= IMAGE && isset($line[$colonne]) && isset($line[$colonne][$i - 1]) && isset($line[$colonne][$i]) 
204
			if($colonne!= IMAGE && isset($line[$colonne]) && isset($line[$colonne][$i - 1]) && isset($line[$colonne][$i]) 
206
				&& $line[$colonne][$i - 1] != $line[$colonne][$i] && $line[$colonne][$i] != '') {
205
				&& $line[$colonne][$i - 1] != $line[$colonne][$i] && $line[$colonne][$i] != '') {
207
				$ligne_identique_sauf_image = false;
206
				$ligne_identique_sauf_image = false;
208
			}
207
			}
209
		} 
208
		} 
210
		
209
		
211
		if (isset ($line[$colonne][$i]) && $line[$colonne][$i]!='') {
210
		if (isset ($line[$colonne][$i]) && $line[$colonne][$i]!='') {
212
			if ($colonne!=IMAGE) {
211
			if ($colonne!=IMAGE) {
213
				$ligne_image_seulement=false;
212
				$ligne_image_seulement=false;
214
				$ligne_vide=false;
213
				$ligne_vide=false;
215
			}		
214
			}		
216
			$ligne_vide=false;
215
			$ligne_vide=false;
217
		}		
216
		}		
218
	}
217
	}
219
	
218
	
220
	if ($ligne_vide) {
219
	if ($ligne_vide) {
221
		return LIGNE_VIDE;
220
		return LIGNE_VIDE;
222
	}
221
	}
223
	else {
222
	else {
224
		if ($ligne_image_seulement || $ligne_identique_sauf_image) {
223
		if ($ligne_image_seulement || $ligne_identique_sauf_image) {
225
			return LIGNE_IMAGE_SEULEMENT;
224
			return LIGNE_IMAGE_SEULEMENT;
226
		}
225
		}
227
		else {
226
		else {
228
			return LIGNE_NORMALE;
227
			return LIGNE_NORMALE;
229
		}
228
		}
230
	}
229
	}
231
	
230
	
232
 
231
 
233
}
232
}
234
 
233
 
235
function traiterLigne($line,$i,$utilisateur,$DB) { // Controle donnee et insertion
234
function traiterLigne($line,$i,$utilisateur,$DB) { // Controle donnee et insertion
236
	
235
	
237
	$info_image=array();
236
	$info_image=array();
238
	$info_transmettre = "0";
237
	$info_transmettre = "0";
239
	
238
	
240
	foreach ($this->format_observation as $colonne) {
239
	foreach ($this->format_observation as $colonne) {
241
		if (isset ($line[$colonne][$i]) && $line[$colonne][$i]!='') {
240
		if (isset ($line[$colonne][$i]) && $line[$colonne][$i]!='') {
242
			switch ($colonne) {  // On ne garde que les colonnes que l'on souhaite traiter
241
			switch ($colonne) {  // On ne garde que les colonnes que l'on souhaite traiter
243
				case COMMUNE:
242
				case COMMUNE:
244
					$info_commune=$this->traiterCommune($line[COMMUNE][$i]);
243
					$info_commune=$this->traiterCommune($line[COMMUNE][$i]);
245
					break;
244
					break;
246
				case LIEUDIT:
245
				case LIEUDIT:
247
					$info_lieudit=$this->traiterLieudit($line[LIEUDIT][$i]);
246
					$info_lieudit=$this->traiterLieudit($line[LIEUDIT][$i]);
248
					break;
247
					break;
249
				case STATION:
248
				case STATION:
250
					$info_station=$this->traiterStation($line[STATION][$i]);
249
					$info_station=$this->traiterStation($line[STATION][$i]);
251
					break;
250
					break;
252
				case MILIEU:
251
				case MILIEU:
253
					$info_milieu=$this->traiterMilieu($line[MILIEU][$i]);
252
					$info_milieu=$this->traiterMilieu($line[MILIEU][$i]);
254
					break;
253
					break;
255
                case DEPARTEMENT:
254
                case DEPARTEMENT:
256
					$info_commune['code']=$this->traiterDepartement($line[DEPARTEMENT][$i]);
255
					$info_commune['code']=$this->traiterDepartement($line[DEPARTEMENT][$i]);
257
					break;
256
					break;
258
				case LATITUDE:
257
				case LATITUDE:
259
					$info_latitude=$this->traiterLatitude($line[LATITUDE][$i]);
258
					$info_latitude=$this->traiterLatitude($line[LATITUDE][$i]);
260
					break;
259
					break;
261
				case LONGITUDE:
260
				case LONGITUDE:
262
					$info_longitude=$this->traiterLongitude($line[LONGITUDE][$i]);
261
					$info_longitude=$this->traiterLongitude($line[LONGITUDE][$i]);
263
					break;
262
					break;
264
				case NOTES:
263
				case NOTES:
265
					$info_notes=$this->traiterNotes($line[NOTES][$i]);
264
					$info_notes=$this->traiterNotes($line[NOTES][$i]);
266
					break;
265
					break;
267
				case DATEOBS:
266
				case DATEOBS:
268
					$info_dateobs=$this->traiterDateObs($line[DATEOBS][$i]);
267
					$info_dateobs=$this->traiterDateObs($line[DATEOBS][$i]);
269
					break;
268
					break;
270
				case TRANSMETTRE:
269
				case TRANSMETTRE:
271
					$info_transmettre=$this->traiterTransmettre($line[TRANSMETTRE][$i]);
270
					$info_transmettre=$this->traiterTransmettre($line[TRANSMETTRE][$i]);
272
				break;
271
				break;
273
				case ESPECE:
272
				case ESPECE:
274
					$info_espece=$this->traiterEspece($line[ESPECE][$i]);
273
					$info_espece=$this->traiterEspece($line[ESPECE][$i]);
275
                    if (isset($info_espece['en_id_nom']) && $info_espece['en_id_nom']!='') {
274
                    if (isset($info_espece['en_id_nom']) && $info_espece['en_id_nom']!='') {
276
                        $complement=$this->rechercherInformationsComplementaires($info_espece['en_id_nom']);
275
                        $complement=$this->rechercherInformationsComplementaires($info_espece['en_id_nom']);
277
                        $info_espece['nom_ret']=$complement['Nom_Retenu'];
276
                        $info_espece['nom_ret']=$complement['Nom_Retenu'];
278
                        $info_espece['num_nom_ret']=$complement['Num_Nom_Retenu'];
277
                        $info_espece['num_nom_ret']=$complement['Num_Nom_Retenu'];
279
                        $info_espece['num_taxon']=$complement['Num_Taxon'];
278
                        $info_espece['num_taxon']=$complement['Num_Taxon'];
280
                        $info_espece['famille']=$complement['Famille'];
279
                        $info_espece['famille']=$complement['Famille'];
281
                    }
280
                    }
282
                    break;
281
                    break;
283
				case IMAGE:
282
				case IMAGE:
284
					$info_image=$this->traiterImage($line[IMAGE][$i],$utilisateur); // Image separee par des / +  utilisateur
283
					$info_image=$this->traiterImage($line[IMAGE][$i],$utilisateur); // Image separee par des / +  utilisateur
285
					break;
284
					break;
286
			}
285
			}
287
		}
286
		}
288
		else {	
287
		else {	
289
		 	switch($colonne) {
288
		 	switch($colonne) {
290
				case COMMUNE:
289
				case COMMUNE:
291
					$info_commune['name']="000null";
290
					$info_commune['name']="000null";
292
					break;
291
					break;
293
				case LIEUDIT:
292
				case LIEUDIT:
294
					$info_lieudit="000null";
293
					$info_lieudit="000null";
295
					break;
294
					break;
296
				case STATION:
295
				case STATION:
297
					$info_station="000null";
296
					$info_station="000null";
298
					break;
297
					break;
299
				case MILIEU:
298
				case MILIEU:
300
					$info_milieu="000null";
299
					$info_milieu="000null";
301
					break;
300
					break;
302
				case DEPARTEMENT:
301
				case DEPARTEMENT:
303
		            if (!isset ($info_commune['code']) || $info_commune['code']=='') {
302
		            if (!isset ($info_commune['code']) || $info_commune['code']=='') {
304
					    $info_commune['code']="000null";
303
					    $info_commune['code']="000null";
305
                    }
304
                    }
306
					break;
305
					break;
307
				case LATITUDE:
306
				case LATITUDE:
308
					$info_latitude="000null";
307
					$info_latitude="000null";
309
					break;
308
					break;
310
				case LONGITUDE:
309
				case LONGITUDE:
311
					$info_longitude="000null";
310
					$info_longitude="000null";
312
					break;
311
					break;
313
				case NOTES:
312
				case NOTES:
314
					$info_notes='';
313
					$info_notes='';
315
					break;
314
					break;
316
				case TRANSMETTRE:
315
				case TRANSMETTRE:
317
					$info_transmettre = "0";
316
					$info_transmettre = "0";
318
				break;
317
				break;
319
 
318
 
320
			}
319
			}
321
 
320
 
322
		}
321
		}
323
	}
322
	}
324
 
323
 
325
                $this->dernier_ordre++;
324
                $this->dernier_ordre++;
326
 
325
 
327
                list($jour,$mois,$annee)=explode("/",$info_dateobs);
326
                list($jour,$mois,$annee) = isset($info_dateobs) ? explode("/",$info_dateobs) : array(null,null,null);
328
                $info_dateobs=$annee."-".$mois."-".$jour." 0:0:0";
327
                $info_dateobs=$annee."-".$mois."-".$jour." 0:0:0";
329
                $query  = "INSERT INTO cel_inventory (identifiant,ordre,nom_sel,num_nom_sel,nom_ret,num_nom_ret,num_taxon,famille,location,id_location,date_observation,lieudit,station, milieu, commentaire, transmission, date_creation,date_modification,coord_x,coord_y) " .
328
                $query  = "INSERT INTO cel_inventory (identifiant,ordre,nom_sel,num_nom_sel,nom_ret,num_nom_ret,num_taxon,famille,location,id_location,date_observation,lieudit,station, milieu, commentaire, transmission, date_creation,date_modification,coord_x,coord_y) " .
330
                    " VALUES('".$DB->escapeSimple($utilisateur)."','".
329
                    " VALUES('".$DB->escapeSimple($utilisateur)."','".
331
                    $DB->escapeSimple($this->dernier_ordre)."','".
330
                    $DB->escapeSimple($this->dernier_ordre)."','".
332
                    $DB->escapeSimple($info_espece['nom_sel'])."','".
331
                    $DB->escapeSimple($info_espece['nom_sel'])."','".
333
                    $DB->escapeSimple($info_espece['en_id_nom'])."','".
332
                    $DB->escapeSimple($info_espece['en_id_nom'])."','".
334
                    $DB->escapeSimple($info_espece['nom_ret'])."','".
333
                    $DB->escapeSimple($info_espece['nom_ret'])."','".
335
                    $DB->escapeSimple($info_espece['num_nom_ret'])."','".
334
                    $DB->escapeSimple($info_espece['num_nom_ret'])."','".
336
                    $DB->escapeSimple($info_espece['num_taxon'])."','".
335
                    $DB->escapeSimple($info_espece['num_taxon'])."','".
337
                    $DB->escapeSimple($info_espece['famille'])."','".
336
                    $DB->escapeSimple($info_espece['famille'])."','".
338
                    $DB->escapeSimple($info_commune['name'])."','".
337
                    $DB->escapeSimple($info_commune['name'])."','".
339
                    $DB->escapeSimple($info_commune['code'])."','".
338
                    $DB->escapeSimple($info_commune['code'])."','".
340
                    $DB->escapeSimple($info_dateobs)."','".
339
                    $DB->escapeSimple($info_dateobs)."','".
341
                    $DB->escapeSimple($info_lieudit)."','".
340
                    $DB->escapeSimple($info_lieudit)."','".
342
                    $DB->escapeSimple($info_station)."','".
341
                    $DB->escapeSimple($info_station)."','".
343
                    $DB->escapeSimple($info_milieu)."','".
342
                    $DB->escapeSimple($info_milieu)."','".
344
                    $DB->escapeSimple($info_notes)."','".
343
                    $DB->escapeSimple($info_notes)."','".
345
                    $DB->escapeSimple($info_transmettre)."',".
344
                    $DB->escapeSimple($info_transmettre)."',".
346
                    "now() , now(),'".
345
                    "now() , now(),'".
347
                    $DB->escapeSimple($info_latitude)."','".
346
                    $DB->escapeSimple($info_latitude)."','".
348
                    $DB->escapeSimple($info_longitude)."')";
347
                    $DB->escapeSimple($info_longitude)."')";
349
//		print "\n";
348
//		print "\n";
350
		   $res =& $DB->query($query);
349
		   $res =& $DB->query($query);
351
 
350
 
352
                if (PEAR::isError($res)) {
351
                if (PEAR::isError($res)) {
353
                        return false;
352
                        return false;
354
                }
353
                }
355
	
354
	
356
	// creation lien image
355
	// creation lien image
357
	foreach ($info_image as $pic) {
356
	foreach ($info_image as $pic) {
358
 
357
 
359
		$query = 'INSERT INTO cel_obs_images (coi_ce_image, coi_ce_utilisateur, coi_ce_observation ) VALUES ("'.$DB->escapeSimple($pic['ci_id_image']).'","'.$DB->escapeSimple($utilisateur).'",    "'.$DB->escapeSimple($this->dernier_ordre).'") ON DUPLICATE KEY UPDATE coi_ce_image = coi_ce_image' ;	
358
		$query = 'INSERT INTO cel_obs_images (coi_ce_image, coi_ce_utilisateur, coi_ce_observation ) VALUES ("'.$DB->escapeSimple($pic['ci_id_image']).'","'.$DB->escapeSimple($utilisateur).'",    "'.$DB->escapeSimple($this->dernier_ordre).'") ON DUPLICATE KEY UPDATE coi_ce_image = coi_ce_image' ;	
360
 
359
 
361
		$res =& $DB->query($query);
360
		$res =& $DB->query($query);
362
 
361
 
363
                if (PEAR::isError($res)) {
362
                if (PEAR::isError($res)) {
364
                        return false;
363
                        return false;
365
                } else {
364
                } else {
366
                	$this->cpt_images_liees++;
365
                	$this->cpt_images_liees++;
367
                }
366
                }
368
	}
367
	}
369
 
368
 
370
		return $this->dernier_ordre;
369
		return $this->dernier_ordre;
371
 
370
 
372
 
371
 
373
}
372
}
374
 
373
 
375
function traiterLigneComplement($line,$i,$utilisateur, $ordre = null) {
374
function traiterLigneComplement($line,$i,$utilisateur, $ordre = null) {
376
 
375
 
377
	$info_image=$this->traiterImage($line[IMAGE][$i],$utilisateur); // Image separee par des / +  utilisateur
376
	$info_image=$this->traiterImage($line[IMAGE][$i],$utilisateur); // Image separee par des / +  utilisateur
378
	
377
	
379
	// creation lien image
378
	// creation lien image
380
	foreach ($info_image as $pic) {
379
	foreach ($info_image as $pic) {
381
 
380
 
382
		$DB=$this->connectDB($this->config,'cel_db');
381
		$DB=$this->connectDB($this->config,'cel_db');
383
		$query = 'INSERT INTO cel_obs_images (coi_ce_image, coi_ce_utilisateur, coi_ce_observation) VALUES ("'.$DB->escapeSimple($pic['ci_id_image']).'","'.$DB->escapeSimple($utilisateur).'",    "'.$DB->escapeSimple($this->dernier_ordre).'") ON DUPLICATE KEY UPDATE coi_ce_image = coi_ce_image' ;	
382
		$query = 'INSERT INTO cel_obs_images (coi_ce_image, coi_ce_utilisateur, coi_ce_observation) VALUES ("'.$DB->escapeSimple($pic['ci_id_image']).'","'.$DB->escapeSimple($utilisateur).'",    "'.$DB->escapeSimple($this->dernier_ordre).'") ON DUPLICATE KEY UPDATE coi_ce_image = coi_ce_image' ;	
384
 
383
 
385
		$res =& $DB->query($query);
384
		$res =& $DB->query($query);
386
 
385
 
387
    	if (PEAR::isError($res)) {
386
    	if (PEAR::isError($res)) {
388
            return false;
387
            return false;
389
    	} else {
388
    	} else {
390
    		$this->cpt_images_liees++;
389
    		$this->cpt_images_liees++;
391
    	}
390
    	}
392
	}
391
	}
393
}
392
}
394
function traiterCommune($identifiant_commune) {  // Recherche correspondance sur nom, si pas unique, correspondance dep. sinon code insee
393
function traiterCommune($identifiant_commune) {  // Recherche correspondance sur nom, si pas unique, correspondance dep. sinon code insee
395
 
394
 
396
    $identifiant_commune=trim($identifiant_commune);
395
    $identifiant_commune=trim($identifiant_commune);
397
    $identifiant_commune=utf8_encode($identifiant_commune); // FIXME : devrait deja etre en utf8 a ce niveau
396
    $identifiant_commune=utf8_encode($identifiant_commune); // FIXME : devrait deja etre en utf8 a ce niveau
398
 
397
 
399
	preg_match('/(.*) \(([0-9][0-9]*)\)/',$identifiant_commune,$elements);
398
	preg_match('/(.*) \(([0-9][0-9]*)\)/',$identifiant_commune,$elements);
400
 
399
 
401
    $DB=$this->connectDB($this->config,'database_cel'); // FIXME regarder si opportun ici
400
    $DB=$this->connectDB($this->config,'database_cel'); // FIXME regarder si opportun ici
402
 
401
 
403
	if (isset($elements[1])) { // commune + departement : montpellier (34)
402
	if (isset($elements[1])) { // commune + departement : montpellier (34)
404
		$nom_commune=$elements[1];
403
		$nom_commune=$elements[1];
405
		$code_commune=$elements[2];
404
		$code_commune=$elements[2];
406
 	    $query="SELECT DISTINCT name, code  FROM locations WHERE name = '".$DB->escapeSimple($nom_commune)."' AND code ='".$DB->escapeSimple($code_commune)."'";
405
 	    $query="SELECT DISTINCT name, code  FROM locations WHERE name = '".$DB->escapeSimple($nom_commune)."' AND code ='".$DB->escapeSimple($code_commune)."'";
407
	}
406
	}
408
	else { // Code insee seul 
407
	else { // Code insee seul 
409
        preg_match('/([0-9][0-9]*)|(2A[0-9][0-9]*)|(2B[0-9][0-9]*)/',$identifiant_commune,$elements);
408
        preg_match('/([0-9][0-9]*)|(2A[0-9][0-9]*)|(2B[0-9][0-9]*)/',$identifiant_commune,$elements);
410
        if (isset($elements[1])) { // code insee  commune
409
        if (isset($elements[1])) { // code insee  commune
411
            $code_insee_commune=$elements[1];
410
            $code_insee_commune=$elements[1];
412
            $query="SELECT DISTINCT name, code  FROM locations WHERE insee_code ='".$DB->escapeSimple($code_insee_commune)."'";
411
            $query="SELECT DISTINCT name, code  FROM locations WHERE insee_code ='".$DB->escapeSimple($code_insee_commune)."'";
413
        }	
412
        }	
414
        else { // Commune seule (le departement sera recupere dans la colonne departement si elle est presente, on prend le risque ici de retourner une mauvaise
413
        else { // Commune seule (le departement sera recupere dans la colonne departement si elle est presente, on prend le risque ici de retourner une mauvaise
415
               // Commune
414
               // Commune
416
            preg_match('/(.*)/',$identifiant_commune,$elements);
415
            preg_match('/(.*)/',$identifiant_commune,$elements);
417
            if (isset($elements[1])) { // commune 
416
            if (isset($elements[1])) { // commune 
418
                $nom_commune=$elements[1];
417
                $nom_commune=$elements[1];
419
                $nom_commune=trim($nom_commune);
418
                $nom_commune=trim($nom_commune);
420
                $nom_commune=utf8_decode($nom_commune);
419
                $nom_commune=utf8_decode($nom_commune);
421
                $nom_commune=cp1252_to_utf8($nom_commune);
420
                $nom_commune=cp1252_to_utf8($nom_commune);
422
                $nom_commune=remove_accent($nom_commune);
421
                $nom_commune=remove_accent($nom_commune);
423
                $nom_commune=preg_replace("/ /","%",$nom_commune);
422
                $nom_commune=preg_replace("/ /","%",$nom_commune);
424
                $query="SELECT DISTINCT name, code  FROM locations WHERE name like '".$DB->escapeSimple($nom_commune)."'";
423
                $query="SELECT DISTINCT name, code  FROM locations WHERE name like '".$DB->escapeSimple($nom_commune)."'";
425
            }
424
            }
426
        }
425
        }
427
	}
426
	}
428
 
427
 
429
	$res =& $DB->query($query);
428
	$res =& $DB->query($query);
430
    if (DB::isError($res)) {
429
    if (DB::isError($res)) {
431
		 die($res->getMessage());
430
		 die($res->getMessage());
432
	}
431
	}
433
	
432
	
434
	$commune_code = $res->fetchrow(DB_FETCHMODE_ASSOC);
433
	$commune_code = $res->fetchrow(DB_FETCHMODE_ASSOC);
435
	
434
	
436
	// cas de la commune introuvable dans le référentiel
435
	// cas de la commune introuvable dans le référentiel
437
	if(!is_array($commune_code) || count($commune_code) == 0) {
436
	if(!is_array($commune_code) || count($commune_code) == 0) {
438
		$commune_code['name'] = fix_latin($identifiant_commune);
437
		$commune_code['name'] = fix_latin($identifiant_commune);
439
		$commune_code['code'] = '000null';
438
		$commune_code['code'] = '000null';
440
	}
439
	}
441
	return $commune_code;
440
	return $commune_code;
442
}
441
}
443
 
442
 
444
function traiterLieudit($lieudit) { // texte libre
443
function traiterLieudit($lieudit) { // texte libre
445
 
444
 
446
	//echo "traitement lieudit";
445
	//echo "traitement lieudit";
447
    $lieudit=fix_latin($lieudit);
446
    $lieudit=fix_latin($lieudit);
448
	return trim($lieudit);
447
	return trim($lieudit);
449
}
448
}
450
 
449
 
451
function traiterStation($station) { // texte libre
450
function traiterStation($station) { // texte libre
452
//	echo "traitement station";
451
//	echo "traitement station";
453
    $station=fix_latin($station);
452
    $station=fix_latin($station);
454
	return trim($station);
453
	return trim($station);
455
}
454
}
456
 
455
 
457
function traiterMilieu($milieu) { // texte libre
456
function traiterMilieu($milieu) { // texte libre
458
//	echo "traitement milieu";
457
//	echo "traitement milieu";
459
    $milieu=fix_latin($milieu);
458
    $milieu=fix_latin($milieu);
460
	return trim($milieu);
459
	return trim($milieu);
461
}
460
}
462
 
461
 
463
function traiterDepartement($departement) { // texte libre
462
function traiterDepartement($departement) { // texte libre
464
 
463
 
465
	if(is_numeric($departement) && strlen($departement) == 5) {
464
	if(is_numeric($departement) && strlen($departement) == 5) {
466
		$departement = substr($departement,0,2);
465
		$departement = substr($departement,0,2);
467
	}
466
	}
468
	
467
	
469
	if(is_numeric($departement) && strlen($departement) == 4) {
468
	if(is_numeric($departement) && strlen($departement) == 4) {
470
		$departement = substr($departement,0,1);
469
		$departement = substr($departement,0,1);
471
		$departement = "0"+$departement;
470
		$departement = "0"+$departement;
472
	}
471
	}
473
 
472
 
474
	if(is_numeric($departement) && $departement <= 9) {
473
	if(is_numeric($departement) && $departement <= 9) {
475
		$departement = "0"+$departement;
474
		$departement = "0"+$departement;
476
	}
475
	}
477
	return utf8_encode(trim($departement));
476
	return utf8_encode(trim($departement));
478
}
477
}
479
 
478
 
480
function traiterLatitude($latitude) {	//  verifier formal decimal + limite france ? TODO 
479
function traiterLatitude($latitude) {	//  verifier formal decimal + limite france ? TODO 
481
//	echo "traitement latitude";
480
//	echo "traitement latitude";
482
	return trim($latitude);
481
	return trim($latitude);
483
}
482
}
484
 
483
 
485
function traiterLongitude($longitude) { // verifier format decimal + limite france ? TODO 
484
function traiterLongitude($longitude) { // verifier format decimal + limite france ? TODO 
486
//	echo "traitement longitude";
485
//	echo "traitement longitude";
487
	return trim($longitude);
486
	return trim($longitude);
488
}
487
}
489
 
488
 
490
function traiterNotes($notes) { // texte libre
489
function traiterNotes($notes) { // texte libre
491
//	echo "traitement notes";
490
//	echo "traitement notes";
492
    $notes=remove_accent($notes);
491
    $notes=remove_accent($notes);
493
	return utf8_encode(trim($notes));
492
	return utf8_encode(trim($notes));
494
}
493
}
495
 
494
 
496
function traiterDateObs($dateobs) { // verifier jj/mm/aaaa sinon date vide TODO 
495
function traiterDateObs($dateobs) { // verifier jj/mm/aaaa sinon date vide TODO 
497
//	echo "traitement dateobs";
496
//	echo "traitement dateobs";
498
	return trim($dateobs);
497
	return trim($dateobs);
499
}
498
}
500
 
499
 
501
function traiterTransmettre($transmettre) {
500
function traiterTransmettre($transmettre) {
502
	
501
	
503
	$transmission = '0';
502
	$transmission = '0';
504
	
503
	
505
	if (trim($transmettre) == "1" || trim($transmettre) == "oui") {	
504
	if (trim($transmettre) == "1" || trim($transmettre) == "oui") {	
506
		$transmission = '1';
505
		$transmission = '1';
507
	}
506
	}
508
	
507
	
509
	return $transmission;
508
	return $transmission;
510
}
509
}
511
 
510
 
512
function traiterEspece($identifiant_espece) {  // texte libre, nom scientifique , ou code nomenclatural (format BDNFFnn999999) ou code taxonomique (format BDNFFnt999999)
511
function traiterEspece($identifiant_espece) {  // texte libre, nom scientifique , ou code nomenclatural (format BDNFFnn999999) ou code taxonomique (format BDNFFnt999999)
513
 
512
 
514
//	echo "traitement  espece";
513
//	echo "traitement  espece";
515
        $identifiant_espece=trim($identifiant_espece);
514
        $identifiant_espece=trim($identifiant_espece);
516
 
515
 
517
        $identifiant_espece=utf8_encode($identifiant_espece); // FIXME : devrait deja etre en utf8 a ce niveau
516
        $identifiant_espece=utf8_encode($identifiant_espece); // FIXME : devrait deja etre en utf8 a ce niveau
518
 
517
 
519
	    preg_match('/BDNFFnn([0-9][0-9]*)/',$identifiant_espece,$elements);
518
	    preg_match('/BDNFFnn([0-9][0-9]*)/',$identifiant_espece,$elements);
520
	
519
	
521
		if (isset($elements[1])) { // Numero nomenclatural 
520
		if (isset($elements[1])) { // Numero nomenclatural 
522
 
521
 
523
 
522
 
524
            // Recherche du nom associe
523
            // Recherche du nom associe
525
            $DB=$this->connectDB($this->config); // FIXME : gerer cache de connection
524
            $DB=$this->connectDB($this->config); // FIXME : gerer cache de connection
526
            $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
525
            $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
527
                "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
526
                "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
528
                " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
527
                " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
529
                " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
528
                " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
530
                " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
529
                " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
531
                " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom" .
530
                " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom" .
532
                " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom a,  " .
531
                " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom a,  " .
533
                " eflore_naturaliste_intitule_abreviation AS auteur_bex ".
532
                " eflore_naturaliste_intitule_abreviation AS auteur_bex ".
534
                " , eflore_naturaliste_intitule_abreviation AS auteur_b ".
533
                " , eflore_naturaliste_intitule_abreviation AS auteur_b ".
535
                " , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
534
                " , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
536
                " , eflore_naturaliste_intitule_abreviation AS auteur_m ".
535
                " , eflore_naturaliste_intitule_abreviation AS auteur_m ".
537
                " WHERE a.esn_id_nom= '".$elements[1]. "'".
536
                " WHERE a.esn_id_nom= '".$elements[1]. "'".
538
                " AND a.esn_id_version_projet_taxon = 25 ".
537
                " AND a.esn_id_version_projet_taxon = 25 ".
539
                " AND en_ce_rang = enrg_id_rang" .
538
                " AND en_ce_rang = enrg_id_rang" .
540
                " AND en_id_nom = a.esn_id_nom" .
539
                " AND en_id_nom = a.esn_id_nom" .
541
                " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
540
                " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
542
                " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
541
                " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
543
                " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
542
                " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
544
                " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
543
                " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
545
                " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
544
                " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
546
 
545
 
547
            $res =& $DB->query($query);
546
            $res =& $DB->query($query);
548
 
547
 
549
 
548
 
550
            if (DB::isError($res)) {
549
            if (DB::isError($res)) {
551
                die($res->getMessage());
550
                die($res->getMessage());
552
            }
551
            }
553
 
552
 
554
            $row =& $res->fetchrow(DB_FETCHMODE_ASSOC);
553
            $row =& $res->fetchrow(DB_FETCHMODE_ASSOC);
555
            return array("nom_sel"=>$this->formaterNom($row),"en_id_nom"=>$elements[1]);
554
            return array("nom_sel"=>$this->formaterNom($row),"en_id_nom"=>$elements[1]);
556
 
555
 
557
		}
556
		}
558
 
557
 
559
		else { //  Numero taxonomique ou nom scientifique
558
		else { //  Numero taxonomique ou nom scientifique
560
	        preg_match('/BDNFFnt([0-9][0-9]*)/',$identifiant_espece,$elements);
559
	        preg_match('/BDNFFnt([0-9][0-9]*)/',$identifiant_espece,$elements);
561
			
560
			
562
		    if (isset($elements[1])) { // Numero taxonomique
561
		    if (isset($elements[1])) { // Numero taxonomique
563
    
562
    
564
                $DB=$this->connectDB($this->config);
563
                $DB=$this->connectDB($this->config);
565
 
564
 
566
                $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
565
                $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
567
                    "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
566
                    "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
568
                    " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
567
                    " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
569
                    " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
568
                    " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
570
                    " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
569
                    " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
571
                    " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom" .
570
                    " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom" .
572
                    " FROM eflore_nom, eflore_nom_rang," .
571
                    " FROM eflore_nom, eflore_nom_rang," .
573
                    "     eflore_naturaliste_intitule_abreviation AS auteur_bex ".
572
                    "     eflore_naturaliste_intitule_abreviation AS auteur_bex ".
574
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
573
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
575
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
574
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
576
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
575
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
577
                    " , eflore_selection_nom ".
576
                    " , eflore_selection_nom ".
578
                    " WHERE esn_id_taxon = '".$elements[1]. "'".
577
                    " WHERE esn_id_taxon = '".$elements[1]. "'".
579
                    " AND esn_id_version_projet_taxon = 25 ".
578
                    " AND esn_id_version_projet_taxon = 25 ".
580
                    " AND esn_ce_statut=3 ".
579
                    " AND esn_ce_statut=3 ".
581
                    " AND en_id_nom = esn_id_nom" .
580
                    " AND en_id_nom = esn_id_nom" .
582
                    " AND en_ce_rang = enrg_id_rang" .
581
                    " AND en_ce_rang = enrg_id_rang" .
583
                    " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
582
                    " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
584
                    " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
583
                    " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
585
                    " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
584
                    " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
586
                    " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
585
                    " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
587
                    " AND esn_id_version_projet_taxon=en_id_version_projet_nom ";
586
                    " AND esn_id_version_projet_taxon=en_id_version_projet_nom ";
588
 
587
 
589
                $res =& $DB->query($query);
588
                $res =& $DB->query($query);
590
 
589
 
591
                if (DB::isError($res)) {
590
                if (DB::isError($res)) {
592
                    die($res->getMessage());
591
                    die($res->getMessage());
593
                }
592
                }
594
 
593
 
595
                $row =& $res->fetchrow(DB_FETCHMODE_ASSOC);
594
                $row =& $res->fetchrow(DB_FETCHMODE_ASSOC);
596
                return array("nom_sel"=>$this->formaterNom($row),"en_id_nom"=>$row['en_id_nom']);
595
                return array("nom_sel"=>$this->formaterNom($row),"en_id_nom"=>$row['en_id_nom']);
597
 
596
 
598
 
597
 
599
            }
598
            }
600
 
599
 
601
            else { // Nom scientifique
600
            else { // Nom scientifique
602
                $nameparser=new NameParser();
601
                $nameparser=new NameParser();
603
                $nom_latin_decoupe=$nameparser->parse($identifiant_espece);
602
                $nom_latin_decoupe=$nameparser->parse($identifiant_espece);
604
 
-
 
605
//print_r($nom_latin_decoupe);
603
 
606
                    $DB=$this->connectDB($this->config); // FIXME regarder si opportun ici
604
                    $DB=$this->connectDB($this->config); // FIXME regarder si opportun ici
607
 
605
 
608
                        // requete sous espece (on privilegie les noms retenu cf tri par esn_ce_statut) 
606
                        // requete sous espece (on privilegie les noms retenu cf tri par esn_ce_statut) 
609
                        if (isset($nom_latin_decoupe['infra']) && $nom_latin_decoupe['infra']!="") {
607
                        if (isset($nom_latin_decoupe['infra']) && $nom_latin_decoupe['infra']!="") {
610
                            $query="SELECT DISTINCT en_id_nom, esn_ce_statut" .
608
                            $query="SELECT DISTINCT en_id_nom, esn_ce_statut" .
611
                                            " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom " .
609
                                            " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom " .
612
                                            " WHERE en_id_version_projet_nom = '25' AND en_nom_genre = '".$DB->escapeSimple($nom_latin_decoupe['genus'])."' " .
610
                                            " WHERE en_id_version_projet_nom = '25' AND en_nom_genre = '".$DB->escapeSimple($nom_latin_decoupe['genus'])."' " .
613
                                            " AND enrg_abreviation_rang = '".$DB->escapeSimple($nom_latin_decoupe['infra_type'])."' " .
611
                                            " AND enrg_abreviation_rang = '".$DB->escapeSimple($nom_latin_decoupe['infra_type'])."' " .
614
                                            " AND en_epithete_infra_specifique = '".$DB->escapeSimple($nom_latin_decoupe['infra'])."' " .
612
                                            " AND en_epithete_infra_specifique = '".$DB->escapeSimple($nom_latin_decoupe['infra'])."' " .
615
                                            " AND esn_id_nom= en_id_nom ".
613
                                            " AND esn_id_nom= en_id_nom ".
616
                                            " AND esn_id_version_projet_taxon=en_id_version_projet_nom " .
614
                                            " AND esn_id_version_projet_taxon=en_id_version_projet_nom " .
617
                                            " AND en_epithete_espece =  '".$DB->escapeSimple($nom_latin_decoupe['species'])."' AND en_ce_rang = enrg_id_rang " .
615
                                            " AND en_epithete_espece =  '".$DB->escapeSimple($nom_latin_decoupe['species'])."' AND en_ce_rang = enrg_id_rang " .
618
                                            " ORDER BY esn_ce_statut ".
616
                                            " ORDER BY esn_ce_statut ".
619
                                            " LIMIT 1";
617
                                            " LIMIT 1";
620
                        }
618
                        }
621
                        else { // espece  (on privilegie les noms retenu cf tri par esn_ce_statut)
619
                        else { // espece  (on privilegie les noms retenu cf tri par esn_ce_statut)
622
                             $query="SELECT DISTINCT en_id_nom, esn_ce_statut" .
620
                             $query="SELECT DISTINCT en_id_nom, esn_ce_statut" .
623
                                            " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom " .
621
                                            " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom " .
624
                                            " WHERE en_id_version_projet_nom = '25' AND en_nom_genre = '".$DB->escapeSimple($nom_latin_decoupe['genus'])."' " .
622
                                            " WHERE en_id_version_projet_nom = '25' AND en_nom_genre = '".$DB->escapeSimple($nom_latin_decoupe['genus'])."' " .
625
                                            " AND enrg_abreviation_rang = 'sp.' " .
623
                                            " AND enrg_abreviation_rang = 'sp.' " .
626
                                            " AND esn_id_nom= en_id_nom ".
624
                                            " AND esn_id_nom= en_id_nom ".
627
                                            " AND esn_id_version_projet_taxon=en_id_version_projet_nom " .
625
                                            " AND esn_id_version_projet_taxon=en_id_version_projet_nom " .
628
                                            " AND en_epithete_espece =  '".$DB->escapeSimple($nom_latin_decoupe['species'])."' AND en_ce_rang = enrg_id_rang " .
626
                                            " AND en_epithete_espece =  '".$DB->escapeSimple($nom_latin_decoupe['species'])."' AND en_ce_rang = enrg_id_rang " .
629
                                            " ORDER BY esn_ce_statut ".
627
                                            " ORDER BY esn_ce_statut ".
630
                                            " LIMIT 1";
628
                                            " LIMIT 1";
631
                        
629
                        
632
                        }
630
                        }
633
                $res =& $DB->query($query);
631
                $res =& $DB->query($query);
634
                if (DB::isError($res)) {
632
                if (DB::isError($res)) {
635
                     die($res->getMessage());
633
                     die($res->getMessage());
636
                }
634
                }
637
 
635
 
638
                $id_nom=$res->fetchrow(DB_FETCHMODE_ASSOC);
636
                $id_nom=$res->fetchrow(DB_FETCHMODE_ASSOC);
639
 
637
 
640
                // Recherche du nom associe
638
                // Recherche du nom associe
641
                $DB=$this->connectDB($this->config); // FIXME : gerer cache de connection
639
                $DB=$this->connectDB($this->config); // FIXME : gerer cache de connection
642
                $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
640
                $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
643
                    "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
641
                    "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
644
                    " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
642
                    " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
645
                    " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
643
                    " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
646
                    " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
644
                    " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
647
                    " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom" .
645
                    " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom" .
648
                    " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom a,  " .
646
                    " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom a,  " .
649
                    "         eflore_naturaliste_intitule_abreviation AS auteur_bex ".
647
                    "         eflore_naturaliste_intitule_abreviation AS auteur_bex ".
650
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
648
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
651
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
649
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
652
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
650
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
653
                    " WHERE a.esn_id_nom= '".$id_nom['en_id_nom']. "'".
651
                    " WHERE a.esn_id_nom= '".$id_nom['en_id_nom']. "'".
654
                    " AND a.esn_id_version_projet_taxon = 25 ".
652
                    " AND a.esn_id_version_projet_taxon = 25 ".
655
                    " AND en_ce_rang = enrg_id_rang" .
653
                    " AND en_ce_rang = enrg_id_rang" .
656
                    " AND en_id_nom = a.esn_id_nom" .
654
                    " AND en_id_nom = a.esn_id_nom" .
657
                    " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
655
                    " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
658
                    " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
656
                    " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
659
                    " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
657
                    " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
660
                    " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
658
                    " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
661
                    " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
659
                    " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
662
                $res =& $DB->query($query);
660
                $res =& $DB->query($query);
663
 
661
 
664
 
662
 
665
                if (DB::isError($res)) {
663
                if (DB::isError($res)) {
666
                    die($res->getMessage());
664
                    die($res->getMessage());
667
                }
665
                }
668
 
666
 
669
                if ($res->numRows() > 0 ) {
667
                if ($res->numRows() > 0 ) {
670
                    $row =& $res->fetchrow(DB_FETCHMODE_ASSOC);
668
                    $row =& $res->fetchrow(DB_FETCHMODE_ASSOC);
671
                    return array("nom_sel"=>$this->formaterNom($row),"en_id_nom"=>$id_nom['en_id_nom']);
669
                    return array("nom_sel"=>$this->formaterNom($row),"en_id_nom"=>$id_nom['en_id_nom']);
672
                }
670
                }
673
                else {
671
                else {
674
                    return array("nom_sel"=>$identifiant_espece);
672
                    return array("nom_sel"=>$identifiant_espece);
675
                }
673
                }
676
 
674
 
677
 
675
 
678
                }
676
                }
679
            }
677
            }
680
	
678
	
681
 
679
 
682
}
680
}
683
 
681
 
684
 
682
 
685
 
683
 
686
function traiterImage($images,$utilisateur) { // recherche id image de ce nom 
684
function traiterImage($images,$utilisateur) { // recherche id image de ce nom 
687
 
685
 
688
        $DB=$this->connectDB($this->config,'cel_db');
686
        $DB=$this->connectDB($this->config,'cel_db');
689
 
687
 
690
	$liste_images = explode("/",$images) ;
688
	$liste_images = explode("/",$images) ;
691
 
689
 
692
	$row =array();
690
	$row =array();
693
        foreach($liste_images as $image) {
691
        foreach($liste_images as $image) {
694
 
692
 
695
		$query="SELECT * FROM cel_images WHERE ci_ce_utilisateur='".$DB->escapeSimple($utilisateur)."' AND ci_nom_original='".$DB->escapeSimple($image)."'";
693
		$query="SELECT * FROM cel_images WHERE ci_ce_utilisateur='".$DB->escapeSimple($utilisateur)."' AND ci_nom_original='".$DB->escapeSimple($image)."'";
696
 
694
 
697
	        $res  =& $DB->query($query);
695
	        $res  =& $DB->query($query);
698
		$row [] =& $res->fetchrow(DB_FETCHMODE_ASSOC);
696
		$row [] =& $res->fetchrow(DB_FETCHMODE_ASSOC);
699
 
697
 
700
	        if (DB::isError($res)) {
698
	        if (DB::isError($res)) {
701
        	    die($res->getMessage());
699
        	    die($res->getMessage());
702
	        }
700
	        }
703
 
701
 
704
	}
702
	}
705
	return $row;
703
	return $row;
706
 
704
 
707
 
705
 
708
}
706
}
709
 
707
 
710
       function rechercherInformationsComplementaires($numNom) { // Num taxon, Num retenu ...
708
       function rechercherInformationsComplementaires($numNom) { // Num taxon, Num retenu ...
711
 
709
 
712
                $DB=$this->connectDB($this->config);
710
                $DB=$this->connectDB($this->config);
713
 
711
 
714
                $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
712
                $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
715
                    "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
713
                    "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
716
                    " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
714
                    " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
717
                    " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
715
                    " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
718
                    " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
716
                    " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
719
                    " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, b.esn_id_taxon, b.esn_id_nom" .
717
                    " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, b.esn_id_taxon, b.esn_id_nom" .
720
                    " FROM eflore_nom, eflore_nom_rang," .
718
                    " FROM eflore_nom, eflore_nom_rang," .
721
                    "     eflore_naturaliste_intitule_abreviation AS auteur_bex ".
719
                    "     eflore_naturaliste_intitule_abreviation AS auteur_bex ".
722
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
720
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
723
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
721
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
724
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
722
                    "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
725
                    " ,eflore_selection_nom a, eflore_selection_nom b".
723
                    " ,eflore_selection_nom a, eflore_selection_nom b".
726
                    " WHERE a.esn_id_nom= ".$numNom.
724
                    " WHERE a.esn_id_nom= ".$numNom.
727
                    " AND a.esn_id_version_projet_taxon = 25 ".
725
                    " AND a.esn_id_version_projet_taxon = 25 ".
728
                    " AND a.esn_id_taxon=b.esn_id_taxon ".
726
                    " AND a.esn_id_taxon=b.esn_id_taxon ".
729
                    " AND b.esn_ce_statut=3 ".
727
                    " AND b.esn_ce_statut=3 ".
730
                    " AND a.esn_id_version_projet_taxon=b.esn_id_version_projet_taxon" .
728
                    " AND a.esn_id_version_projet_taxon=b.esn_id_version_projet_taxon" .
731
                    " AND en_ce_rang = enrg_id_rang" .
729
                    " AND en_ce_rang = enrg_id_rang" .
732
                    " AND en_id_nom = b.esn_id_nom" .
730
                    " AND en_id_nom = b.esn_id_nom" .
733
                    " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
731
                    " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
734
                    " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
732
                    " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
735
                    " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
733
                    " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
736
                    " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
734
                    " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
737
                    " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
735
                    " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
738
 
736
 
739
 
737
 
740
                $res =& $DB->query($query);
738
                $res =& $DB->query($query);
741
 
739
 
742
 
740
 
743
 
741
 
744
                if (DB::isError($res)) {
742
                if (DB::isError($res)) {
745
                    die($res->getMessage());
743
                    die($res->getMessage());
746
                }
744
                }
747
 
745
 
748
                // Nom retenu, Num Nomenclatural nom retenu, Num Taxon,
746
                // Nom retenu, Num Nomenclatural nom retenu, Num Taxon,
749
 
747
 
750
                $value=array('Nom_Retenu'=>"",'Num_Nom_Retenu'=>"0",'Num_Taxon'=>"0",'Famille'=>"");
748
                $value=array('Nom_Retenu'=>"",'Num_Nom_Retenu'=>"0",'Num_Taxon'=>"0",'Famille'=>"");
751
 
749
 
752
                while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
750
                while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
753
                    $fam=$this->rechercherFamille($row['esn_id_taxon'],$DB);
751
                    $fam=$this->rechercherFamille($row['esn_id_taxon'],$DB);
754
 
752
 
755
                    // Recherche Famille 
753
                    // Recherche Famille 
756
                    while (($fam['en_ce_rang']!='fin') && ($fam['en_ce_rang'] !=120)) {
754
                    while (($fam['en_ce_rang']!='fin') && ($fam['en_ce_rang'] !=120)) {
757
                        $fam=$this->rechercherFamille($fam['etr_id_taxon_2'],$DB);
755
                        $fam=$this->rechercherFamille($fam['etr_id_taxon_2'],$DB);
758
                    }
756
                    }
759
                    if ($fam['en_ce_rang']==120) {
757
                    if ($fam['en_ce_rang']==120) {
760
                        $famille=$fam['en_nom_supra_generique'];
758
                        $famille=$fam['en_nom_supra_generique'];
761
                    }
759
                    }
762
                    else {
760
                    else {
763
                        $famille="Famille inconnue";
761
                        $famille="Famille inconnue";
764
                    }
762
                    }
765
 
763
 
766
                    $value=array('Nom_Retenu'=>$this->formaterNom($row),'Num_Nom_Retenu'=>$row['esn_id_nom'],'Num_Taxon'=>$row['esn_id_taxon'],'Famille'=>$famille);
764
                    $value=array('Nom_Retenu'=>$this->formaterNom($row),'Num_Nom_Retenu'=>$row['esn_id_nom'],'Num_Taxon'=>$row['esn_id_taxon'],'Famille'=>$famille);
767
                }
765
                }
768
 
766
 
769
                return $value;
767
                return $value;
770
 
768
 
771
 
769
 
772
 
770
 
773
        }
771
        }
774
 
772
 
775
function formaterNom($rawnom) {
773
function formaterNom($rawnom) {
776
 
774
 
777
 
775
 
778
                // Constitution du nom:
776
                // Constitution du nom:
779
                $nom = '';
777
                $nom = '';
780
 
778
 
781
                if ($rawnom['en_nom_supra_generique'] != '') {
779
                if ($rawnom['en_nom_supra_generique'] != '') {
782
                    $nom .= $rawnom['en_nom_supra_generique'];
780
                    $nom .= $rawnom['en_nom_supra_generique'];
783
                } else if ($rawnom['en_epithete_infra_generique'] != '') {
781
                } else if ($rawnom['en_epithete_infra_generique'] != '') {
784
                    $nom .= $rawnom['en_epithete_infra_generique'];
782
                    $nom .= $rawnom['en_epithete_infra_generique'];
785
                } else {
783
                } else {
786
                        if ($rawnom['en_nom_genre'] != '') {
784
                        if ($rawnom['en_nom_genre'] != '') {
787
                            $nom .=  $rawnom['en_nom_genre'];
785
                            $nom .=  $rawnom['en_nom_genre'];
788
                        }
786
                        }
789
                        if ($rawnom['en_epithete_espece']!= '') {
787
                        if ($rawnom['en_epithete_espece']!= '') {
790
                            $nom .= ' '.$rawnom['en_epithete_espece'];
788
                            $nom .= ' '.$rawnom['en_epithete_espece'];
791
                        }
789
                        }
792
                        if ($rawnom['en_epithete_infra_specifique'] != '') {
790
                        if ($rawnom['en_epithete_infra_specifique'] != '') {
793
                                if (!empty($rawnom['enrg_abreviation_rang'])) {
791
                                if (!empty($rawnom['enrg_abreviation_rang'])) {
794
                                        $nom .= ' '.$rawnom['enrg_abreviation_rang'].'';
792
                                        $nom .= ' '.$rawnom['enrg_abreviation_rang'].'';
795
                                }
793
                                }
796
                                $nom .= ' '.$rawnom['en_epithete_infra_specifique'];
794
                                $nom .= ' '.$rawnom['en_epithete_infra_specifique'];
797
                        }
795
                        }
798
 
796
 
799
                }
797
                }
800
 
798
 
801
                return $nom .$this->retournerAuteur($rawnom) ;
799
                return $nom .$this->retournerAuteur($rawnom) ;
802
 
800
 
803
 }
801
 }
804
 
802
 
805
 
803
 
806
function rechercherFamille($taxon,&$DB) {
804
function rechercherFamille($taxon,&$DB) {
807
 
805
 
808
    $row=array();
806
    $row=array();
809
 
807
 
810
    $query="SELECT DISTINCT en_ce_rang, etr_id_taxon_2, en_id_nom, en_nom_supra_generique ".
808
    $query="SELECT DISTINCT en_ce_rang, etr_id_taxon_2, en_id_nom, en_nom_supra_generique ".
811
        " FROM eflore_taxon_relation, eflore_selection_nom, eflore_nom ".
809
        " FROM eflore_taxon_relation, eflore_selection_nom, eflore_nom ".
812
        " WHERE etr_id_taxon_1 = ".$taxon.
810
        " WHERE etr_id_taxon_1 = ".$taxon.
813
        " AND etr_id_version_projet_taxon_1 = 25 ".
811
        " AND etr_id_version_projet_taxon_1 = 25 ".
814
        " AND etr_id_categorie_taxon = 3 ".
812
        " AND etr_id_categorie_taxon = 3 ".
815
        " AND etr_id_valeur_taxon = 3 ".
813
        " AND etr_id_valeur_taxon = 3 ".
816
        " AND esn_id_taxon =  etr_id_taxon_2 ".
814
        " AND esn_id_taxon =  etr_id_taxon_2 ".
817
        " AND esn_ce_statut = 3 ".
815
        " AND esn_ce_statut = 3 ".
818
        " AND esn_id_version_projet_taxon = etr_id_version_projet_taxon_1 ".
816
        " AND esn_id_version_projet_taxon = etr_id_version_projet_taxon_1 ".
819
        " AND en_id_nom = esn_id_nom ".
817
        " AND en_id_nom = esn_id_nom ".
820
        " AND esn_id_version_projet_taxon=en_id_version_projet_nom  ";
818
        " AND esn_id_version_projet_taxon=en_id_version_projet_nom  ";
821
    $res =& $DB->query($query);
819
    $res =& $DB->query($query);
822
 
820
 
823
    if (DB::isError($res)) {
821
    if (DB::isError($res)) {
824
        die($res->getMessage());
822
        die($res->getMessage());
825
    }
823
    }
826
 
824
 
827
    if ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
825
    if ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
828
        return $row;
826
        return $row;
829
    }
827
    }
830
    else {
828
    else {
831
        $row['en_ce_rang']='fin';
829
        $row['en_ce_rang']='fin';
832
        return $row;
830
        return $row;
833
    }
831
    }
834
 
832
 
835
}
833
}
836
 
834
 
837
 
835
 
838
function retournerAuteur($rawnom) {
836
function retournerAuteur($rawnom) {
839
 
837
 
840
    $auteurs = '';
838
    $auteurs = '';
841
    $auteur_basio = '';
839
    $auteur_basio = '';
842
    $auteur_modif = '';
840
    $auteur_modif = '';
843
    if (!empty($rawnom['abreviation_auteur_basio_ex']) && $rawnom['abreviation_auteur_basio_ex']!='-' )  {
841
    if (!empty($rawnom['abreviation_auteur_basio_ex']) && $rawnom['abreviation_auteur_basio_ex']!='-' )  {
844
        $auteur_basio .= $rawnom['abreviation_auteur_basio_ex'];
842
        $auteur_basio .= $rawnom['abreviation_auteur_basio_ex'];
845
        if (!empty($rawnom['abreviation_auteur_basio']) && $rawnom['abreviation_auteur_basio']!='-') {
843
        if (!empty($rawnom['abreviation_auteur_basio']) && $rawnom['abreviation_auteur_basio']!='-') {
846
            $auteur_basio .= ' ex '.$rawnom['abreviation_auteur_basio'];
844
            $auteur_basio .= ' ex '.$rawnom['abreviation_auteur_basio'];
847
        }
845
        }
848
    } else if (!empty($rawnom['abreviation_auteur_basio']) && $rawnom['abreviation_auteur_basio']!='-') {
846
    } else if (!empty($rawnom['abreviation_auteur_basio']) && $rawnom['abreviation_auteur_basio']!='-') {
849
        $auteur_basio .= $rawnom['abreviation_auteur_basio'];
847
        $auteur_basio .= $rawnom['abreviation_auteur_basio'];
850
    }
848
    }
851
 
849
 
852
    if (!empty($rawnom['abreviation_auteur_modif_ex']) && $rawnom['abreviation_auteur_modif_ex']!='-') {
850
    if (!empty($rawnom['abreviation_auteur_modif_ex']) && $rawnom['abreviation_auteur_modif_ex']!='-') {
853
        $auteur_modif .= $rawnom['abreviation_auteur_modif_ex'];
851
        $auteur_modif .= $rawnom['abreviation_auteur_modif_ex'];
854
        if (!empty($rawnom['abreviation_auteur_modif']) && $rawnom['abreviation_auteur_modif']!='-') {
852
        if (!empty($rawnom['abreviation_auteur_modif']) && $rawnom['abreviation_auteur_modif']!='-') {
855
            $auteur_modif .= ' ex '.$rawnom['abreviation_auteur_modif'];
853
            $auteur_modif .= ' ex '.$rawnom['abreviation_auteur_modif'];
856
        }
854
        }
857
    } else if (!empty($rawnom['abreviation_auteur_modif']) && $rawnom['abreviation_auteur_modif']!='-')  {
855
    } else if (!empty($rawnom['abreviation_auteur_modif']) && $rawnom['abreviation_auteur_modif']!='-')  {
858
        $auteur_modif .= $rawnom['abreviation_auteur_modif'];
856
        $auteur_modif .= $rawnom['abreviation_auteur_modif'];
859
    }
857
    }
860
 
858
 
861
    if (!empty($auteur_modif)) {
859
    if (!empty($auteur_modif)) {
862
        $auteurs = ' ('.$auteur_basio.') '.$auteur_modif;
860
        $auteurs = ' ('.$auteur_basio.') '.$auteur_modif;
863
    } elseif (!empty($auteur_basio)) {
861
    } elseif (!empty($auteur_basio)) {
864
        $auteurs = ' '.$auteur_basio;
862
        $auteurs = ' '.$auteur_basio;
865
    }
863
    }
866
 
864
 
867
    return $auteurs ;
865
    return $auteurs ;
868
}
866
}
869
 
867
 
870
 
868
 
871
 
869
 
872
 
870
 
873
}
871
}
874
 
872
 
875
function init_byte_map(){
873
function init_byte_map(){
876
    $byte_map = array();
874
    $byte_map = array();
877
    for($x=128;$x<256;++$x){
875
    for($x=128;$x<256;++$x){
878
        $byte_map[chr($x)]=utf8_encode(chr($x));
876
        $byte_map[chr($x)]=utf8_encode(chr($x));
879
    }
877
    }
880
    $cp1252_map=array(
878
    $cp1252_map=array(
881
            "\x80"=>"\xE2\x82\xAC",    // EURO SIGN
879
            "\x80"=>"\xE2\x82\xAC",    // EURO SIGN
882
            "\x82" => "\xE2\x80\x9A",  // SINGLE LOW-9 QUOTATION MARK
880
            "\x82" => "\xE2\x80\x9A",  // SINGLE LOW-9 QUOTATION MARK
883
            "\x83" => "\xC6\x92",      // LATIN SMALL LETTER F WITH HOOK
881
            "\x83" => "\xC6\x92",      // LATIN SMALL LETTER F WITH HOOK
884
            "\x84" => "\xE2\x80\x9E",  // DOUBLE LOW-9 QUOTATION MARK
882
            "\x84" => "\xE2\x80\x9E",  // DOUBLE LOW-9 QUOTATION MARK
885
            "\x85" => "\xE2\x80\xA6",  // HORIZONTAL ELLIPSIS
883
            "\x85" => "\xE2\x80\xA6",  // HORIZONTAL ELLIPSIS
886
            "\x86" => "\xE2\x80\xA0",  // DAGGER
884
            "\x86" => "\xE2\x80\xA0",  // DAGGER
887
            "\x87" => "\xE2\x80\xA1",  // DOUBLE DAGGER
885
            "\x87" => "\xE2\x80\xA1",  // DOUBLE DAGGER
888
            "\x88" => "\xCB\x86",      // MODIFIER LETTER CIRCUMFLEX ACCENT
886
            "\x88" => "\xCB\x86",      // MODIFIER LETTER CIRCUMFLEX ACCENT
889
            "\x89" => "\xE2\x80\xB0",  // PER MILLE SIGN
887
            "\x89" => "\xE2\x80\xB0",  // PER MILLE SIGN
890
            "\x8A" => "\xC5\xA0",      // LATIN CAPITAL LETTER S WITH CARON
888
            "\x8A" => "\xC5\xA0",      // LATIN CAPITAL LETTER S WITH CARON
891
            "\x8B" => "\xE2\x80\xB9",  // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
889
            "\x8B" => "\xE2\x80\xB9",  // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
892
            "\x8C" => "\xC5\x92",      // LATIN CAPITAL LIGATURE OE
890
            "\x8C" => "\xC5\x92",      // LATIN CAPITAL LIGATURE OE
893
            "\x8E" => "\xC5\xBD",      // LATIN CAPITAL LETTER Z WITH CARON
891
            "\x8E" => "\xC5\xBD",      // LATIN CAPITAL LETTER Z WITH CARON
894
            "\x91" => "\xE2\x80\x98",  // LEFT SINGLE QUOTATION MARK
892
            "\x91" => "\xE2\x80\x98",  // LEFT SINGLE QUOTATION MARK
895
            "\x92" => "\xE2\x80\x99",  // RIGHT SINGLE QUOTATION MARK
893
            "\x92" => "\xE2\x80\x99",  // RIGHT SINGLE QUOTATION MARK
896
            "\x93" => "\xE2\x80\x9C",  // LEFT DOUBLE QUOTATION MARK
894
            "\x93" => "\xE2\x80\x9C",  // LEFT DOUBLE QUOTATION MARK
897
            "\x94" => "\xE2\x80\x9D",  // RIGHT DOUBLE QUOTATION MARK
895
            "\x94" => "\xE2\x80\x9D",  // RIGHT DOUBLE QUOTATION MARK
898
            "\x95" => "\xE2\x80\xA2",  // BULLET
896
            "\x95" => "\xE2\x80\xA2",  // BULLET
899
            "\x96" => "\xE2\x80\x93",  // EN DASH
897
            "\x96" => "\xE2\x80\x93",  // EN DASH
900
            "\x97" => "\xE2\x80\x94",  // EM DASH
898
            "\x97" => "\xE2\x80\x94",  // EM DASH
901
            "\x98" => "\xCB\x9C",      // SMALL TILDE
899
            "\x98" => "\xCB\x9C",      // SMALL TILDE
902
            "\x99" => "\xE2\x84\xA2",  // TRADE MARK SIGN
900
            "\x99" => "\xE2\x84\xA2",  // TRADE MARK SIGN
903
            "\x9A" => "\xC5\xA1",      // LATIN SMALL LETTER S WITH CARON
901
            "\x9A" => "\xC5\xA1",      // LATIN SMALL LETTER S WITH CARON
904
            "\x9B" => "\xE2\x80\xBA",  // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
902
            "\x9B" => "\xE2\x80\xBA",  // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
905
            "\x9C" => "\xC5\x93",      // LATIN SMALL LIGATURE OE
903
            "\x9C" => "\xC5\x93",      // LATIN SMALL LIGATURE OE
906
            "\x9E" => "\xC5\xBE",      // LATIN SMALL LETTER Z WITH CARON
904
            "\x9E" => "\xC5\xBE",      // LATIN SMALL LETTER Z WITH CARON
907
            "\x9F" => "\xC5\xB8"       // LATIN CAPITAL LETTER Y WITH DIAERESIS
905
            "\x9F" => "\xC5\xB8"       // LATIN CAPITAL LETTER Y WITH DIAERESIS
908
                );
906
                );
909
    foreach($cp1252_map as $k=>$v){
907
    foreach($cp1252_map as $k=>$v){
910
        $byte_map[$k]=$v;
908
        $byte_map[$k]=$v;
911
    }
909
    }
912
    
910
    
913
    return $byte_map;
911
    return $byte_map;
914
}
912
}
915
 
913
 
916
function fix_latin($instr){
914
function fix_latin($instr){
917
    
915
    
918
    $byte_map = init_byte_map();
916
    $byte_map = init_byte_map();
919
    
917
    
920
    $ascii_char='[\x00-\x7F]';
918
    $ascii_char='[\x00-\x7F]';
921
    $cont_byte='[\x80-\xBF]';
919
    $cont_byte='[\x80-\xBF]';
922
    $utf8_2='[\xC0-\xDF]'.$cont_byte;
920
    $utf8_2='[\xC0-\xDF]'.$cont_byte;
923
    $utf8_3='[\xE0-\xEF]'.$cont_byte.'{2}';
921
    $utf8_3='[\xE0-\xEF]'.$cont_byte.'{2}';
924
    $utf8_4='[\xF0-\xF7]'.$cont_byte.'{3}';
922
    $utf8_4='[\xF0-\xF7]'.$cont_byte.'{3}';
925
    $utf8_5='[\xF8-\xFB]'.$cont_byte.'{4}';
923
    $utf8_5='[\xF8-\xFB]'.$cont_byte.'{4}';
926
    
924
    
927
    $nibble_good_chars = "@^($ascii_char+|$utf8_2|$utf8_3|$utf8_4|$utf8_5)(.*)$@s";
925
    $nibble_good_chars = "@^($ascii_char+|$utf8_2|$utf8_3|$utf8_4|$utf8_5)(.*)$@s";
928
 
926
 
929
    if(mb_check_encoding($instr,'UTF-8'))return $instr; // no need for the rest if it's all valid UTF-8 already
927
    if(mb_check_encoding($instr,'UTF-8'))return $instr; // no need for the rest if it's all valid UTF-8 already
930
    $outstr='';
928
    $outstr='';
931
    $char='';
929
    $char='';
932
    $rest='';
930
    $rest='';
933
    while((strlen($instr))>0){
931
    while((strlen($instr))>0){
934
        if(1==@preg_match($nibble_good_chars,$instr,$match)){
932
        if(1==@preg_match($nibble_good_chars,$instr,$match)){
935
            $char=$match[1];
933
            $char=$match[1];
936
            $rest=$match[2];
934
            $rest=$match[2];
937
            $outstr.=$char;
935
            $outstr.=$char;
938
        }elseif(1==@preg_match('@^(.)(.*)$@s',$instr,$match)){
936
        }elseif(1==@preg_match('@^(.)(.*)$@s',$instr,$match)){
939
            $char=$match[1];
937
            $char=$match[1];
940
            $rest=$match[2];
938
            $rest=$match[2];
941
            $outstr.=$byte_map[$char];
939
            $outstr.=$byte_map[$char];
942
        }
940
        }
943
        $instr=$rest;
941
        $instr=$rest;
944
    }
942
    }
945
    return $outstr;
943
    return $outstr;
946
}
944
}
947
 
945
 
948
 
946
 
949
function remove_accent($str)
947
function remove_accent($str)
950
{
948
{
951
  $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î',
949
  $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î',
952
             'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß',
950
             'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß',
953
             'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î',
951
             'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î',
954
             'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā',
952
             'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā',
955
             'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď',
953
             'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď',
956
             'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ',
954
             'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ',
957
             'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ',
955
             'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ',
958
             'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ',
956
             'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ',
959
             'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ',
957
             'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ',
960
             'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ',
958
             'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ',
961
             'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ',
959
             'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ',
962
             'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż',
960
             'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż',
963
             'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ',
961
             'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ',
964
             'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ');
962
             'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ');
965
             
963
             
966
  $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I',
964
  $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I',
967
             'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's',
965
             'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's',
968
             'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i',
966
             'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i',
969
             'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a',
967
             'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a',
970
             'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd',
968
             'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd',
971
             'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g',
969
             'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g',
972
             'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i',
970
             'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i',
973
             'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l',
971
             'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l',
974
             'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R',
972
             'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R',
975
             'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't',
973
             'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't',
976
             'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y',
974
             'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y',
977
             'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I',
975
             'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I',
978
             'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
976
             'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
979
  return str_replace($a, $b, $str);
977
  return str_replace($a, $b, $str);
980
}
978
}
981
 
979
 
982
 
980
 
983
function cp1252_to_utf8($str) {
981
function cp1252_to_utf8($str) {
984
$cp1252_map = array ("\xc2\x80" => "\xe2\x82\xac",
982
$cp1252_map = array ("\xc2\x80" => "\xe2\x82\xac",
985
"\xc2\x82" => "\xe2\x80\x9a",
983
"\xc2\x82" => "\xe2\x80\x9a",
986
"\xc2\x83" => "\xc6\x92",    
984
"\xc2\x83" => "\xc6\x92",    
987
"\xc2\x84" => "\xe2\x80\x9e",
985
"\xc2\x84" => "\xe2\x80\x9e",
988
"\xc2\x85" => "\xe2\x80\xa6",
986
"\xc2\x85" => "\xe2\x80\xa6",
989
"\xc2\x86" => "\xe2\x80\xa0",
987
"\xc2\x86" => "\xe2\x80\xa0",
990
"\xc2\x87" => "\xe2\x80\xa1",
988
"\xc2\x87" => "\xe2\x80\xa1",
991
"\xc2\x88" => "\xcb\x86",
989
"\xc2\x88" => "\xcb\x86",
992
"\xc2\x89" => "\xe2\x80\xb0",
990
"\xc2\x89" => "\xe2\x80\xb0",
993
"\xc2\x8a" => "\xc5\xa0",
991
"\xc2\x8a" => "\xc5\xa0",
994
"\xc2\x8b" => "\xe2\x80\xb9",
992
"\xc2\x8b" => "\xe2\x80\xb9",
995
"\xc2\x8c" => "\xc5\x92",
993
"\xc2\x8c" => "\xc5\x92",
996
"\xc2\x8e" => "\xc5\xbd",
994
"\xc2\x8e" => "\xc5\xbd",
997
"\xc2\x91" => "\xe2\x80\x98",
995
"\xc2\x91" => "\xe2\x80\x98",
998
"\xc2\x92" => "\xe2\x80\x99",
996
"\xc2\x92" => "\xe2\x80\x99",
999
"\xc2\x93" => "\xe2\x80\x9c",
997
"\xc2\x93" => "\xe2\x80\x9c",
1000
"\xc2\x94" => "\xe2\x80\x9d",
998
"\xc2\x94" => "\xe2\x80\x9d",
1001
"\xc2\x95" => "\xe2\x80\xa2",
999
"\xc2\x95" => "\xe2\x80\xa2",
1002
"\xc2\x96" => "\xe2\x80\x93",
1000
"\xc2\x96" => "\xe2\x80\x93",
1003
"\xc2\x97" => "\xe2\x80\x94",
1001
"\xc2\x97" => "\xe2\x80\x94",
1004
 
1002
 
1005
"\xc2\x98" => "\xcb\x9c",
1003
"\xc2\x98" => "\xcb\x9c",
1006
"\xc2\x99" => "\xe2\x84\xa2",
1004
"\xc2\x99" => "\xe2\x84\xa2",
1007
"\xc2\x9a" => "\xc5\xa1",
1005
"\xc2\x9a" => "\xc5\xa1",
1008
"\xc2\x9b" => "\xe2\x80\xba",
1006
"\xc2\x9b" => "\xe2\x80\xba",
1009
"\xc2\x9c" => "\xc5\x93",
1007
"\xc2\x9c" => "\xc5\x93",
1010
"\xc2\x9e" => "\xc5\xbe",
1008
"\xc2\x9e" => "\xc5\xbe",
1011
"\xc2\x9f" => "\xc5\xb8"
1009
"\xc2\x9f" => "\xc5\xb8"
1012
);
1010
);
1013
return strtr ( utf8_encode ( $str ), $cp1252_map );
1011
return strtr ( utf8_encode ( $str ), $cp1252_map );
1014
}
1012
}
1015
 
1013
 
1016
/* +--Fin du code ---------------------------------------------------------------------------------------+
1014
/* +--Fin du code ---------------------------------------------------------------------------------------+
1017
* $Log$
1015
* $Log$
1018
*
1016
*
1019
*
1017
*
1020
*/
1018
*/
1021
 
1019
 
1022
 
1020
 
1023
?>
1021
?>