Subversion Repositories eFlore/Applications.cel

Rev

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

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