Subversion Repositories eFlore/Applications.cel

Rev

Rev 1082 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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