Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3347 Rev 3349
1
 <?php
1
 <?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Service affichant les dernières photo publiques du CEL ouvrable sous forme de diaporama.
4
 * Service affichant les dernières photo publiques du CEL ouvrable sous forme de diaporama.
5
 * Encodage en entrée : utf8
5
 * Encodage en entrée : utf8
6
 * Encodage en sortie : utf8
6
 * Encodage en sortie : utf8
7
 *
7
 *
8
 * Cas d'utilisation et documentation :
8
 * Cas d'utilisation et documentation :
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetPhoto
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetPhoto
10
 *
10
 *
11
 * Paramètres :
11
 * Paramètres :
12
 * ===> extra = booléen (1 ou 0)  [par défaut : 1]
12
 * ===> extra = booléen (1 ou 0)  [par défaut : 1]
13
 * Affiche / Cache la vignette en taille plus importante au bas du widget.
13
 * Affiche / Cache la vignette en taille plus importante au bas du widget.
14
 * ===> vignette = [0-9]+,[0-9]+  [par défaut : 4,3]
14
 * ===> vignette = [0-9]+,[0-9]+  [par défaut : 4,3]
15
 * Indique le nombre de vignette par ligne et le nombre de ligne.
15
 * Indique le nombre de vignette par ligne et le nombre de ligne.
16
 *
16
 *
17
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
17
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
18
 * @license	GPL v3 <http://www.gnu.org/licenses/gpl.txt>
18
 * @license	GPL v3 <http://www.gnu.org/licenses/gpl.txt>
19
 * @license	CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
19
 * @license	CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
20
 * @version	$Id$
20
 * @version	$Id$
21
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
21
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
22
 */
22
 */
23
class Saisie2 extends WidgetCommun {
23
class Saisie2 extends WidgetCommun {
24
 
24
 
25
	const DS = DIRECTORY_SEPARATOR;
25
	const DS = DIRECTORY_SEPARATOR;
26
	const SERVICE_DEFAUT = 'saisie';
26
	const SERVICE_DEFAUT = 'saisie';
27
	const WS_SAISIE = 'CelWidgetSaisie';
27
	const WS_SAISIE = 'CelWidgetSaisie';
28
	const WS_UPLOAD = 'CelWidgetUploadImageTemp';
28
	const WS_UPLOAD = 'CelWidgetUploadImageTemp';
29
	const WS_OBS = 'CelObs';
29
	const WS_OBS = 'CelObs';
30
	const LANGUE_DEFAUT = 'fr';
30
	const LANGUE_DEFAUT = 'fr';
31
	const PROJET_DEFAUT = 'base';
31
	const PROJET_DEFAUT = 'base';
32
	const WS_NOM = 'noms';
32
	const WS_NOM = 'noms';
33
	const EFLORE_API_VERSION = '0.1';
33
	const EFLORE_API_VERSION = '0.1';
34
	private $cel_url_tpl = null;
34
	private $cel_url_tpl = null;
35
	/** Si spécifié, on ajoute une barre de navigation inter-applications */
35
	/** Si spécifié, on ajoute une barre de navigation inter-applications */
36
	private $bar;
36
	private $bar;
37
	//private $parametres_autorises = array('projet', 'type', 'langue', 'order');
37
	//private $parametres_autorises = array('projet', 'type', 'langue', 'order');
38
	private $parametres_autorises = array(
38
	private $parametres_autorises = array(
39
			'projet' => 'projet',
39
			'projet' => 'projet',
40
			'type' => 'type',
40
			'type' => 'type',
41
			'langue' => 'langue',
41
			'langue' => 'langue',
42
			'order' => 'order'
42
			'order' => 'order'
43
	);
43
	);
44
	/**
44
	/**
45
	 * Méthode appelée par défaut pour charger ce widget.
45
	 * Méthode appelée par défaut pour charger ce widget.
46
	 */
46
	 */
47
	public function executer() {
47
	public function executer() {
48
		$retour = null;
48
		$retour = null;
49
		// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
49
		// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
50
		unset($this->parametres['callback']);
50
		unset($this->parametres['callback']);
51
		extract($this->parametres);
51
		extract($this->parametres);
52
		$this->bar = (isset($bar)) ? $bar : false;
52
		$this->bar = (isset($bar)) ? $bar : false;
53
		/* Le fichier Framework.php du Framework de Tela Botanica doit être appelé avant tout autre chose dans l'application.
53
		/* Le fichier Framework.php du Framework de Tela Botanica doit être appelé avant tout autre chose dans l'application.
54
		 Sinon, rien ne sera chargé.
54
		 Sinon, rien ne sera chargé.
55
		 L'emplacement du Framework peut varier en fonction de l'environnement (test, prod...). Afin de faciliter la configuration
55
		 L'emplacement du Framework peut varier en fonction de l'environnement (test, prod...). Afin de faciliter la configuration
56
		 de l'emplacement du Framework, un fichier framework.defaut.php doit être renommé en framework.php et configuré pour chaque installation de
56
		 de l'emplacement du Framework, un fichier framework.defaut.php doit être renommé en framework.php et configuré pour chaque installation de
57
		 l'application.
57
		 l'application.
58
		 Chemin du fichier chargeant le framework requis */
58
		 Chemin du fichier chargeant le framework requis */
59
		$framework = dirname(__FILE__).'/framework.php';
59
		$framework = dirname(__FILE__).'/framework.php';
60
		if (!file_exists($framework)) {
60
		if (!file_exists($framework)) {
61
			$e = "Veuillez paramêtrer l'emplacement et la version du Framework dans le fichier $framework";
61
			$e = "Veuillez paramêtrer l'emplacement et la version du Framework dans le fichier $framework";
62
			trigger_error($e, E_USER_ERROR);
62
			trigger_error($e, E_USER_ERROR);
63
		} else {
63
		} else {
64
			// Inclusion du Framework
64
			// Inclusion du Framework
65
			require_once $framework;
65
			require_once $framework;
66
			// Ajout d'information concernant cette application
66
			// Ajout d'information concernant cette application
67
			Framework::setCheminAppli(__FILE__);// Obligatoire
67
			Framework::setCheminAppli(__FILE__);// Obligatoire
68
			Framework::setInfoAppli(Config::get('info'));// Optionnel
68
			Framework::setInfoAppli(Config::get('info'));// Optionnel
69
 
69
 
70
		}
70
		}
71
		$langue = (isset($langue)) ? $langue : self::LANGUE_DEFAUT;
71
		$langue = (isset($langue)) ? $langue : self::LANGUE_DEFAUT;
72
		$this->langue = I18n::setLangue($langue);
72
		$this->langue = I18n::setLangue($langue);
73
		$this->parametres['langue'] = $langue;
73
		$this->parametres['langue'] = $langue;
74
 
74
 
75
		if (!isset($mode)) {
75
		if (!isset($mode)) {
76
			$mode = self::SERVICE_DEFAUT;
76
			$mode = self::SERVICE_DEFAUT;
77
		}
77
		}
78
		if (!isset($projet)) {
78
		if (!isset($projet)) {
79
			$this->parametres['projet'] = self::PROJET_DEFAUT;
79
			$this->parametres['projet'] = self::PROJET_DEFAUT;
80
		}
80
		}
81
 
81
 
82
		$methode = $this->traiterNomMethodeExecuter($mode);
82
		$methode = $this->traiterNomMethodeExecuter($mode);
83
		if (method_exists($this, $methode)) {
83
		if (method_exists($this, $methode)) {
84
			$retour = $this->$methode();
84
			$retour = $this->$methode();
85
		} else {
85
		} else {
86
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
86
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
87
		}
87
		}
88
 
88
 
89
		$contenu = ''; //print_r($retour);exit;
89
		$contenu = ''; //print_r($retour);exit;
90
		if (is_null($retour)) {
90
		if (is_null($retour)) {
91
			$this->messages[] = 'La ressource demandée a retourné une valeur nulle.';
91
			$this->messages[] = 'La ressource demandée a retourné une valeur nulle.';
92
		} else {
92
		} else {
93
			if (isset($retour['donnees'])) {
93
			if (isset($retour['donnees'])) {
94
				// ne pas afficher le projet dans l'url si on est dans saisie de base
94
				// ne pas afficher le projet dans l'url si on est dans saisie de base
95
				$projet_dans_url = ( $this->parametres['projet'] !== 'base') ? '?'. $this->parametres['projet'].'&'.'langue='.$this->parametres['langue'] : '';
95
				$projet_dans_url = ( $this->parametres['projet'] !== 'base') ? '?'. $this->parametres['projet'].'&'.'langue='.$this->parametres['langue'] : '';
96
 
96
 
97
				$retour['donnees']['conf_mode'] = $this->config['parametres']['modeServeur'];
97
				$retour['donnees']['conf_mode'] = $this->config['parametres']['modeServeur'];
98
				$retour['donnees']['prod'] = ($this->config['parametres']['modeServeur'] === 'prod');
98
				$retour['donnees']['prod'] = ($this->config['parametres']['modeServeur'] === 'prod');
99
				$retour['donnees']['bar'] = $this->bar;
99
				$retour['donnees']['bar'] = $this->bar;
100
				$retour['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], $this->config['manager']['cheminDos']);
100
				$retour['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], $this->config['manager']['cheminDos']);
101
				$retour['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
101
				$retour['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
102
				$retour['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
102
				$retour['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
103
				$retour['donnees']['url_ws_obs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS);
103
				$retour['donnees']['url_ws_obs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS);
104
				$retour['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
104
				$retour['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
105
				$retour['donnees']['authTpl'] = $this->config['manager']['authTpl']. $projet_dans_url;
105
				$retour['donnees']['authTpl'] = $this->config['manager']['authTpl']. $projet_dans_url;
106
				$retour['donnees']['mode'] = $mode;
106
				$retour['donnees']['mode'] = $mode;
107
				if( isset( $this->parametres['squelette'] ) ) {
107
				if( isset( $this->parametres['squelette'] ) ) {
108
					$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS. $this->parametres['squelette'].'.tpl.html';
108
					$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS. $this->parametres['squelette'].'.tpl.html';
109
				} else {
109
				} else {
110
					$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
110
					$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
111
				}
111
				}
112
				$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
112
				$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
113
			} else {
113
			} else {
114
				$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
114
				$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
115
			}
115
			}
116
		}
116
		}
117
		$this->envoyer($contenu);
117
		$this->envoyer($contenu);
118
	}
118
	}
119
 
119
 
120
 
120
 
121
	private function executerSaisie() {
121
	private function executerSaisie() {
122
		$retour = array();
122
		$retour = array();
123
		$retour['squelette'] = 'saisie';
123
		$retour['squelette'] = 'saisie';
124
		$retour['donnees']['general'] = I18n::get('General');
124
		$retour['donnees']['general'] = I18n::get('General');
125
		$retour['donnees']['aide'] = I18n::get('Aide');
125
		$retour['donnees']['aide'] = I18n::get('Aide');
126
		$retour['donnees']['observateur'] = I18n::get('Observateur');
126
		$retour['donnees']['observateur'] = I18n::get('Observateur');
127
		$retour['donnees']['observation'] = I18n::get('Observation');
127
		$retour['donnees']['observation'] = I18n::get('Observation');
128
		$retour['donnees']['image'] = I18n::get('Image');
128
		$retour['donnees']['image'] = I18n::get('Image');
129
 		$retour['donnees']['chpsupp'] = I18n::get('Chpsupp');
129
 		$retour['donnees']['chpsupp'] = I18n::get('Chpsupp');
130
 		$retour['donnees']['resume'] = I18n::get('Resume');
130
 		$retour['donnees']['resume'] = I18n::get('Resume');
131
		$retour['donnees']['widget'] = $this->rechercherProjet();
131
		$retour['donnees']['widget'] = $this->rechercherProjet();
132
		return $retour;
132
		return $retour;
133
	}
133
	}
134
 
134
 
135
	/* Recherche si le projet existe sinon va chercher les infos de base */
135
	/* Recherche si le projet existe sinon va chercher les infos de base */
136
	private function rechercherProjet() {
136
	private function rechercherProjet() {
137
		// projet avec un squelette défini (et non juste un mot-clé d'observation)
137
		// projet avec un squelette défini (et non juste un mot-clé d'observation)
138
		$estProjetDefini = true;
138
		$estProjetDefini = true;
139
		$tab = array();
139
		$tab = array();
140
		$url = $this->config['manager']['celUrlTpl'].'?projet='.$this->parametres['projet'].'&langue='.$this->parametres['langue'];
140
		$url = $this->config['manager']['celUrlTpl'].'?projet='.$this->parametres['projet'].'&langue='.$this->parametres['langue'];
141
		$json = $this->getDao()->consulter($url);
141
		$json = $this->getDao()->consulter($url);
142
 
142
 
143
		if ( $json !== "[]" ) {
143
		if ( $json !== "[]" ) {
144
			$tab = $this->rechercherChampsSupp();
144
			$tab = $this->rechercherChampsSupp();
145
		} else {
145
		} else {
146
			$url = $this->config['manager']['celUrlTpl'].'?projet=base&langue='.$this->parametres['langue'];
146
			$url = $this->config['manager']['celUrlTpl'].'?projet=base&langue='.$this->parametres['langue'];
147
			$json = $this->getDao()->consulter($url);
147
			$json = $this->getDao()->consulter($url);
148
			$estProjetDefini = false;
148
			$estProjetDefini = false;
149
		}
149
		}
150
		$tableau = json_decode($json, true);
150
		$tableau = json_decode($json, true);
151
		$tableau = $this->traiterParametres($estProjetDefini, $tableau[0]);
151
		$tableau = $this->traiterParametres($estProjetDefini, $tableau[0]);
152
		$tableau['especes'] = $this->rechercherInfosEspeces($tableau);
152
		$tableau['especes'] = $this->rechercherInfosEspeces($tableau);
153
		if ($tableau['milieux'] != '') {
153
		if ($tableau['milieux'] != '') {
154
			$tableau['milieux'] = explode(';', $tableau['milieux']);
154
			$tableau['milieux'] = explode(';', $tableau['milieux']);
155
		} else {
155
		} else {
156
			$tableau['milieux'] = array();
156
			$tableau['milieux'] = array();
157
		}
157
		}
158
		if (isset($tableau['motscles'])) {
158
		if (isset($tableau['motscles'])) {
159
		    $tableau['tag-obs'] = $tableau['tag-img'] = $tableau['motscles'];
159
		    $tableau['tag-obs'] = $tableau['tag-img'] = $tableau['motscles'];
160
		}
160
		}
161
		$tableau['chpSupp'] = $tab;
161
		$tableau['chpSupp'] = $tab;
162
		$langue_projet_url = ( isset ( $this->parametres['langue'] ) && $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
162
		$langue_projet_url = ( isset ( $this->parametres['langue'] ) && $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
163
		$tableau['chemin_fichiers'] = sprintf( $this->config['chemins']['baseURLAbsoluDyn'], $this->config['manager']['imgProjet'] . $tableau['projet'] . $langue_projet_url . '/' );
163
		$tableau['chemin_fichiers'] = sprintf( $this->config['chemins']['baseURLAbsoluDyn'], $this->config['manager']['imgProjet'] . $tableau['projet'] . $langue_projet_url . '/' );
164
		return $tableau;
164
		return $tableau;
165
	}
165
	}
166
 
166
 
167
	/* Recherche si un projet a des champs de saisie supplémentaire */
167
	/* Recherche si un projet a des champs de saisie supplémentaire */
168
	private function rechercherChampsSupp() {
168
	private function rechercherChampsSupp() {
169
		$retour = array();
169
		$retour = array();
170
		$projet = $this->parametres['projet'];
170
		$projet = $this->parametres['projet'];
171
		$url = $this->config['manager']['celChpSupTpl'] .'?projet=' . $projet . '&langue=' . $this->parametres['langue'];
171
		$url = $this->config['manager']['celChpSupTpl'] .'?projet=' . $projet . '&langue=' . $this->parametres['langue'];
172
		$json = $this->getDao()->consulter($url);
172
		$json = $this->getDao()->consulter($url);
173
		$retour = (array) json_decode($json, true);
173
		$retour = (array) json_decode($json, true);
174
 
174
 
175
		foreach ( $retour[$projet]['champs-supp'] as $key => $chsup ) {
175
		foreach ( $retour[$projet]['champs-supp'] as $key => $chsup ) {
176
 
176
 
177
			$retour[$projet]['champs-supp'][$key]['name'] = $this->clean_string( $chsup['name'] );
177
			$retour[$projet]['champs-supp'][$key]['name'] = $this->clean_string( $chsup['name'] );
178
			$retour[$projet]['champs-supp'][$key]['description'] = $this->clean_string( $chsup['description']);
178
			$retour[$projet]['champs-supp'][$key]['description'] = $this->clean_string( $chsup['description']);
179
			$retour[$projet]['champs-supp'][$key]['unit'] = $this->clean_string( $chsup['unit'] );
179
			$retour[$projet]['champs-supp'][$key]['unit'] = $this->clean_string( $chsup['unit'] );
180
 
180
 
181
			if ( isset( $chsup['fieldValues'] ) ) {
181
			if ( isset( $chsup['fieldValues'] ) ) {
182
				$retour[$projet]['champs-supp'][$key]['fieldValues'] = json_decode( $chsup['fieldValues'], true );
182
				$retour[$projet]['champs-supp'][$key]['fieldValues'] = json_decode( $chsup['fieldValues'], true );
183
				if ( isset($retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] ) ) {
183
				if ( isset($retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] ) ) {
184
					$retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] = $this->clean_string( $retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] );
184
					$retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] = $this->clean_string( $retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] );
185
				}
185
				}
186
 
186
 
187
				if ( isset( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] ) ) {
187
				if ( isset( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] ) ) {
188
					foreach( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] as $list_key => $list_value_array ) {
188
					foreach( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] as $list_key => $list_value_array ) {
189
						$retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'][$list_key][0] = $this->clean_string( $list_value_array[0] );
189
						$retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'][$list_key][0] = $this->clean_string( $list_value_array[0] );
190
						// Obtenir une liste de valeurs utilisables dans les attributs for id ou name par exemple
190
						// Obtenir une liste de valeurs utilisables dans les attributs for id ou name par exemple
191
						$retour[$projet]['champs-supp'][$key]['fieldValues']['cleanListValue'][] = 'val-' . preg_replace( '/[^A-Za-z0-9_\-]/', '', $this->remove_accents( $list_value ) );
191
						$retour[$projet]['champs-supp'][$key]['fieldValues']['cleanListValue'][] = 'val-' . preg_replace( '/[^A-Za-z0-9_\-]/', '', $this->remove_accents( $list_value_array[0] ) );
192
						$retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'][$list_key][1] = $this->clean_string( $list_value_array[1] );
192
						$retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'][$list_key][1] = $this->clean_string( $list_value_array[1] );
193
					}
193
					}
194
				}
194
				}
195
			}
195
			}
196
			$retour[$projet]['champs-supp'][$key]['mandatory'] = intval( $chsup['mandatory'] );
196
			$retour[$projet]['champs-supp'][$key]['mandatory'] = intval( $chsup['mandatory'] );
197
		}
197
		}
198
		return $retour;
198
		return $retour;
199
	}
199
	}
200
 
200
 
201
	private function clean_string( $string ) {
201
	private function clean_string( $string ) {
202
		// les fonctions de base de php ne parviennent pas à une conversion satisfaisante des codes ascii
202
		// les fonctions de base de php ne parviennent pas à une conversion satisfaisante des codes ascii
203
		// qui ont été générés automatiquement lors de la transmission des chaines en json
203
		// qui ont été générés automatiquement lors de la transmission des chaines en json
204
		// dans le widget cel manager vers la base
204
		// dans le widget cel manager vers la base
205
		// Pour les mêmes raisons, @apos@ et @quot@ est une autre astuces utilisée dans ce même widget
205
		// Pour les mêmes raisons, @apos@ et @quot@ est une autre astuces utilisée dans ce même widget
206
		// pour permettre la transmission des apostrophes et guillements sans erreur
206
		// pour permettre la transmission des apostrophes et guillements sans erreur
207
		$patterns = array( '/\@apos\@/', '/\@quot\@/', '/u00c0/', '/u00c1/', '/u00c2/', '/u00c3/', '/u00c4/', '/u00c5/', '/u00c6/', '/u00c7/', '/u00c8/', '/u00c9/', '/u00ca/', '/u00cb/', '/u00cc/', '/u00cd/', '/u00ce/', '/u00cf/', '/u00d1/', '/u00d2/', '/u00d3/', '/u00d4/', '/u00d5/', '/u00d6/', '/u00d8/', '/u00d9/', '/u00da/', '/u00db/', '/u00dc/', '/u00dd/', '/u00df/', '/u00e0/', '/u00e1/', '/u00e2/', '/u00e3/', '/u00e4/', '/u00e5/', '/u00e6/', '/u00e7/', '/u00e8/', '/u00e9/', '/u00ea/', '/u00eb/', '/u00ec/', '/u00ed/', '/u00ee/', '/u00ef/', '/u00f0/', '/u00f1/', '/u00f2/', '/u00f3/', '/u00f4/', '/u00f5/', '/u00f6/', '/u00f8/', '/u00f9/', '/u00fa/', '/u00fb/', '/u00fc/', '/u00fd/', '/u00ff/' );
207
		$patterns = array( '/\@apos\@/', '/\@quot\@/', '/u00c0/', '/u00c1/', '/u00c2/', '/u00c3/', '/u00c4/', '/u00c5/', '/u00c6/', '/u00c7/', '/u00c8/', '/u00c9/', '/u00ca/', '/u00cb/', '/u00cc/', '/u00cd/', '/u00ce/', '/u00cf/', '/u00d1/', '/u00d2/', '/u00d3/', '/u00d4/', '/u00d5/', '/u00d6/', '/u00d8/', '/u00d9/', '/u00da/', '/u00db/', '/u00dc/', '/u00dd/', '/u00df/', '/u00e0/', '/u00e1/', '/u00e2/', '/u00e3/', '/u00e4/', '/u00e5/', '/u00e6/', '/u00e7/', '/u00e8/', '/u00e9/', '/u00ea/', '/u00eb/', '/u00ec/', '/u00ed/', '/u00ee/', '/u00ef/', '/u00f0/', '/u00f1/', '/u00f2/', '/u00f3/', '/u00f4/', '/u00f5/', '/u00f6/', '/u00f8/', '/u00f9/', '/u00fa/', '/u00fb/', '/u00fc/', '/u00fd/', '/u00ff/' );
208
		$replacements = array( '&apos;', '&quot;', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý','ÿ' );
208
		$replacements = array( '&apos;', '&quot;', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý','ÿ' );
209
 
209
 
210
		$clean_string = preg_replace( $patterns, $replacements, $string );
210
		$clean_string = preg_replace( $patterns, $replacements, $string );
211
 
211
 
212
		return $clean_string;
212
		return $clean_string;
213
	}
213
	}
214
 
214
 
215
	// remplace certains parametres définis en bd par les parametres définis dans l'url
215
	// remplace certains parametres définis en bd par les parametres définis dans l'url
216
	private function traiterParametres($estProjetDefini, $tableau) {
216
	private function traiterParametres($estProjetDefini, $tableau) {
217
		$criteres = array('tag-obs', 'tag-img', 'projet', 'titre', 'logo');
217
		$criteres = array('tag-obs', 'tag-img', 'projet', 'titre', 'logo');
218
		$criteresProjetNonDefini = array('commune', 'num_nom', 'referentiel');
218
		$criteresProjetNonDefini = array('commune', 'num_nom', 'referentiel');
219
		foreach($this->parametres as $nom_critere => $valeur_critere) {
219
		foreach($this->parametres as $nom_critere => $valeur_critere) {
220
			if (($estProjetDefini == false || $tableau['projet'] == 'base') && in_array($nom_critere, $criteresProjetNonDefini)) {
220
			if (($estProjetDefini == false || $tableau['projet'] == 'base') && in_array($nom_critere, $criteresProjetNonDefini)) {
221
				$tableau[$nom_critere] = $valeur_critere;
221
				$tableau[$nom_critere] = $valeur_critere;
222
			} else if (in_array($nom_critere, $criteres)) {
222
			} else if (in_array($nom_critere, $criteres)) {
223
				$tableau[$nom_critere] = $valeur_critere;
223
				$tableau[$nom_critere] = $valeur_critere;
224
			}
224
			}
225
		}
225
		}
226
		return $tableau;
226
		return $tableau;
227
	}
227
	}
228
 
228
 
229
	private function rechercherInfosEspeces( $infos_projets ) { //print_r($infos_projets);exit;
229
	private function rechercherInfosEspeces( $infos_projets ) { //print_r($infos_projets);exit;
230
		$retour = array();
230
		$retour = array();
231
		$referentiel = $infos_projets['referentiel'];
231
		$referentiel = $infos_projets['referentiel'];
232
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
232
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
233
		$retour['url_ws_autocompletion_ns'] = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, $referentiel, self::WS_NOM );;
233
		$retour['url_ws_autocompletion_ns'] = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, $referentiel, self::WS_NOM );;
234
		$retour['url_ws_autocompletion_ns_tpl'] = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM );
234
		$retour['url_ws_autocompletion_ns_tpl'] = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM );
235
		$retour['ns_referentiel'] = $referentiel;
235
		$retour['ns_referentiel'] = $referentiel;
236
 
236
 
237
		if ( isset( $infos_projets['type_especes'] ) ) {
237
		if ( isset( $infos_projets['type_especes'] ) ) {
238
 
238
 
239
			switch ( $infos_projets['type_especes'] ) {
239
			switch ( $infos_projets['type_especes'] ) {
240
				case 'fixe' :
240
				case 'fixe' :
241
					$retour = $this->chargerInfosTaxon( $infos_projets['referentiel'], $infos_projets['especes'] );
241
					$retour = $this->chargerInfosTaxon( $infos_projets['referentiel'], $infos_projets['especes'] );
242
					break;
242
					break;
243
				case 'referentiel' : break;
243
				case 'referentiel' : break;
244
				case 'liste' :
244
				case 'liste' :
245
					$referentiel = $infos_projets['referentiel'];
245
					$referentiel = $infos_projets['referentiel'];
246
////////////////////// temporaire test transmission liste taxons
246
////////////////////// temporaire test transmission liste taxons
247
					$retour['taxons'] = $this->recupererListeNomsSci();
247
					$retour['taxons'] = $this->recupererListeNomsSci();
248
					break;
248
					break;
249
			}
249
			}
250
		} else if ( isset( $infos_projets['referentiel'] ) ) {
250
		} else if ( isset( $infos_projets['referentiel'] ) ) {
251
			$referentiel = $infos_projets['referentiel'];
251
			$referentiel = $infos_projets['referentiel'];
252
			if ( isset($infos_projets['num_nom'] ) ) {
252
			if ( isset($infos_projets['num_nom'] ) ) {
253
				$retour = $this->chargerInfosTaxon( $infos_projets['referentiel'], $infos_projets['num_nom'] );
253
				$retour = $this->chargerInfosTaxon( $infos_projets['referentiel'], $infos_projets['num_nom'] );
254
			}
254
			}
255
		}
255
		}
256
		return $retour;
256
		return $retour;
257
	}
257
	}
258
 
258
 
259
	/**
259
	/**
260
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
260
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
261
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
261
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
262
	 * et non le taxon?)
262
	 * et non le taxon?)
263
	 * @param string|int $num_nom
263
	 * @param string|int $num_nom
264
	 * @return array
264
	 * @return array
265
	 */
265
	 */
266
	protected function chargerInfosTaxon( $referentiel, $num_nom ) {
266
	protected function chargerInfosTaxon( $referentiel, $num_nom ) {
267
		$url_service_infos = sprintf( $this->config['chemins']['infosTaxonUrl'], $referentiel, $num_nom );
267
		$url_service_infos = sprintf( $this->config['chemins']['infosTaxonUrl'], $referentiel, $num_nom );
268
		$infos = json_decode( file_get_contents( $url_service_infos ) );
268
		$infos = json_decode( file_get_contents( $url_service_infos ) );
269
		// trop de champs injectés dans les infos espèces peuvent
269
		// trop de champs injectés dans les infos espèces peuvent
270
		// faire planter javascript
270
		// faire planter javascript
271
		$champs_a_garder = array( 'id', 'nom_sci','nom_sci_complet', 'nom_complet', 'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique' );
271
		$champs_a_garder = array( 'id', 'nom_sci','nom_sci_complet', 'nom_complet', 'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique' );
272
		$resultat = array();
272
		$resultat = array();
273
		$retour = array();
273
		$retour = array();
274
		if ( isset( $infos ) && !empty( $infos ) ) {
274
		if ( isset( $infos ) && !empty( $infos ) ) {
275
			$infos = (array) $infos;
275
			$infos = (array) $infos;
276
			if ( isset( $infos['nom_sci'] ) && $infos['nom_sci'] !== '' ) {
276
			if ( isset( $infos['nom_sci'] ) && $infos['nom_sci'] !== '' ) {
277
				$resultat = array_intersect_key( $infos, array_flip($champs_a_garder ) );
277
				$resultat = array_intersect_key( $infos, array_flip($champs_a_garder ) );
278
				$resultat['retenu'] = ( $infos['id'] == $infos['nom_retenu.id'] ) ? 'true' : 'false';
278
				$resultat['retenu'] = ( $infos['id'] == $infos['nom_retenu.id'] ) ? 'true' : 'false';
279
				$retour['espece_imposee'] = true;
279
				$retour['espece_imposee'] = true;
280
				$retour['nn_espece_defaut'] = $nnEspeceImposee;
280
				$retour['nn_espece_defaut'] = $nnEspeceImposee;
281
				$retour['nom_sci_espece_defaut'] = $resultat['nom_complet'];
281
				$retour['nom_sci_espece_defaut'] = $resultat['nom_complet'];
282
				$retour['infos_espece'] = $this->array2js( $resultat, true );
282
				$retour['infos_espece'] = $this->array2js( $resultat, true );
283
			}
283
			}
284
		}
284
		}
285
		return $retour;
285
		return $retour;
286
	}
286
	}
287
 
287
 
288
	protected function getReferentielImpose() {
288
	protected function getReferentielImpose() {
289
		$referentiel_impose = true;
289
		$referentiel_impose = true;
290
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] !== 'autre') {
290
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] !== 'autre') {
291
			$this->ns_referentiel = $_GET['referentiel'];
291
			$this->ns_referentiel = $_GET['referentiel'];
292
		} else if (isset($this->configProjet['referentiel'])) {
292
		} else if (isset($this->configProjet['referentiel'])) {
293
			$this->ns_referentiel = $this->configProjet['referentiel'];
293
			$this->ns_referentiel = $this->configProjet['referentiel'];
294
		} else if (isset($this->configMission['referentiel'])) {
294
		} else if (isset($this->configMission['referentiel'])) {
295
			$this->ns_referentiel = $this->configMission['referentiel'];
295
			$this->ns_referentiel = $this->configMission['referentiel'];
296
		} else {
296
		} else {
297
			$referentiel_impose = false;
297
			$referentiel_impose = false;
298
		}
298
		}
299
		return $referentiel_impose;
299
		return $referentiel_impose;
300
	}
300
	}
301
 
301
 
302
	/**
302
	/**
303
	 * Trie par nom français les taxons lus dans le fichier csv
303
	 * Trie par nom français les taxons lus dans le fichier csv
304
	 */
304
	 */
305
	protected function recupererListeNomsSci() {
305
	protected function recupererListeNomsSci() {
306
		$taxons = $this->recupererListeTaxon();
306
		$taxons = $this->recupererListeTaxon();
307
		if (is_array($taxons)) {
307
		if (is_array($taxons)) {
308
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
308
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
309
		}
309
		}
310
		return $taxons;
310
		return $taxons;
311
	}
311
	}
312
 
312
 
313
	/**
313
	/**
314
	 * @TODO documenter
314
	 * @TODO documenter
315
	 * @return array
315
	 * @return array
316
	 */
316
	 */
317
	protected function recupererListeNoms() {
317
	protected function recupererListeNoms() {
318
		$taxons = $this->recupererListeTaxon();
318
		$taxons = $this->recupererListeTaxon();
319
		$nomsAAfficher = array();
319
		$nomsAAfficher = array();
320
		$nomsSpeciaux = array();
320
		$nomsSpeciaux = array();
321
		if (is_array($taxons)) {
321
		if (is_array($taxons)) {
322
			foreach ($taxons as $taxon) {
322
			foreach ($taxons as $taxon) {
323
				$nomSciTitle = $taxon['nom_ret'].
323
				$nomSciTitle = $taxon['nom_ret'].
324
				($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
324
				($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
325
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
325
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
326
				$nomFrTitle = $taxon['nom_sel'].
326
				$nomFrTitle = $taxon['nom_sel'].
327
				($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
327
				($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
328
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
328
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
329
 
329
 
330
				if ($taxon['groupe'] == 'special') {
330
				if ($taxon['groupe'] == 'special') {
331
					$nomsSpeciaux[] = array(
331
					$nomsSpeciaux[] = array(
332
							'num_nom' => $taxon['num_nom_sel'],
332
							'num_nom' => $taxon['num_nom_sel'],
333
							'nom_a_afficher' => $taxon['nom_fr'],
333
							'nom_a_afficher' => $taxon['nom_fr'],
334
							'nom_a_sauver' => $taxon['nom_sel'],
334
							'nom_a_sauver' => $taxon['nom_sel'],
335
							'nom_title' => $nomSciTitle,
335
							'nom_title' => $nomSciTitle,
336
							'nom_type' => 'nom-special');
336
							'nom_type' => 'nom-special');
337
				} else {
337
				} else {
338
					$nomsAAfficher[] = array(
338
					$nomsAAfficher[] = array(
339
							'num_nom' => $taxon['num_nom_sel'],
339
							'num_nom' => $taxon['num_nom_sel'],
340
							'nom_a_afficher' => $taxon['nom_sel'],
340
							'nom_a_afficher' => $taxon['nom_sel'],
341
							'nom_a_sauver' => $taxon['nom_sel'],
341
							'nom_a_sauver' => $taxon['nom_sel'],
342
							'nom_title' => $nomSciTitle,
342
							'nom_title' => $nomSciTitle,
343
							'nom_type' => 'nom-sci');
343
							'nom_type' => 'nom-sci');
344
					$nomsAAfficher[] = array(
344
					$nomsAAfficher[] = array(
345
							'num_nom' => $taxon['num_nom_sel'],
345
							'num_nom' => $taxon['num_nom_sel'],
346
							'nom_a_afficher' => $taxon['nom_fr'],
346
							'nom_a_afficher' => $taxon['nom_fr'],
347
							'nom_a_sauver' => $taxon['nom_fr'],
347
							'nom_a_sauver' => $taxon['nom_fr'],
348
							'nom_title' => $nomFrTitle,
348
							'nom_title' => $nomFrTitle,
349
							'nom_type' => 'nom-fr');
349
							'nom_type' => 'nom-fr');
350
				}
350
				}
351
			}
351
			}
352
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
352
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
353
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
353
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
354
		}
354
		}
355
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
355
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
356
	}
356
	}
357
 
357
 
358
	/**
358
	/**
359
	 * Lit une liste de taxons depuis un fichier csv fourni
359
	 * Lit une liste de taxons depuis un fichier csv fourni
360
	 */
360
	 */
361
	protected function recupererListeTaxon() {
361
	protected function recupererListeTaxon() {
362
		$taxons = array();
362
		$taxons = array();
363
		$langue_projet_url = ( isset ( $this->parametres['langue'] ) && $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
363
		$langue_projet_url = ( isset ( $this->parametres['langue'] ) && $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
364
		$chemin_images = dirname(__FILE__) . self::DS . '..' . self::DS . 'manager' . self::DS . 'squelettes' . self::DS . 'img' . self::DS . 'images_projets' . self::DS;
364
		$chemin_images = dirname(__FILE__) . self::DS . '..' . self::DS . 'manager' . self::DS . 'squelettes' . self::DS . 'img' . self::DS . 'images_projets' . self::DS;
365
		$fichier_csv = $chemin_images . $this->parametres['projet'] . $langue_projet_url . self::DS . 'especes.csv';
365
		$fichier_csv = $chemin_images . $this->parametres['projet'] . $langue_projet_url . self::DS . 'especes.csv';
366
 
366
 
367
		if ( file_exists( $fichier_csv ) && is_readable( $fichier_csv ) ) {
367
		if ( file_exists( $fichier_csv ) && is_readable( $fichier_csv ) ) {
368
			$taxons = $this->decomposerFichierCsv( $fichier_csv );
368
			$taxons = $this->decomposerFichierCsv( $fichier_csv );
369
		} else {
369
		} else {
370
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_csv'.";
370
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_csv'.";
371
		}
371
		}
372
		return $taxons;
372
		return $taxons;
373
	}
373
	}
374
 
374
 
375
	/**
375
	/**
376
	 * Découpe un fihcier csv
376
	 * Découpe un fihcier csv
377
	 */
377
	 */
378
	protected function decomposerFichierCsv($fichier, $delimiter = "\t"){
378
	protected function decomposerFichierCsv($fichier, $delimiter = "\t"){
379
		$header = null;
379
		$header = null;
380
		$data = array();
380
		$data = array();
381
		if (($handle = fopen($fichier, "r")) !== FALSE) {
381
		if (($handle = fopen($fichier, "r")) !== FALSE) {
382
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
382
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
383
				if (!$header) {
383
				if (!$header) {
384
					$header = $row;
384
					$header = $row;
385
				} else {
385
				} else {
386
					$data[] = array_combine($header, $row);
386
					$data[] = array_combine($header, $row);
387
				}
387
				}
388
			}
388
			}
389
			fclose($handle);
389
			fclose($handle);
390
		}
390
		}
391
		return $data;
391
		return $data;
392
	}
392
	}
393
 
393
 
394
	/**
394
	/**
395
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
395
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
396
	 * @param array $array
396
	 * @param array $array
397
	 * @param boolean $show_keys
397
	 * @param boolean $show_keys
398
	 * @return une portion de JSON représentant le tableau
398
	 * @return une portion de JSON représentant le tableau
399
	 */
399
	 */
400
	protected function array2js($array,$show_keys) {
400
	protected function array2js($array,$show_keys) {
401
		$tableauJs = '{}';
401
		$tableauJs = '{}';
402
		if (!empty($array)) {
402
		if (!empty($array)) {
403
			$total = count($array) - 1;
403
			$total = count($array) - 1;
404
			$i = 0;
404
			$i = 0;
405
			$dimensions = array();
405
			$dimensions = array();
406
			foreach ($array as $key => $value) {
406
			foreach ($array as $key => $value) {
407
				if (is_array($value)) {
407
				if (is_array($value)) {
408
					$dimensions[$i] = array2js($value,$show_keys);
408
					$dimensions[$i] = array2js($value,$show_keys);
409
					if ($show_keys) {
409
					if ($show_keys) {
410
						$dimensions[$i] = '\"'.$key.'\":'.$dimensions[$i];
410
						$dimensions[$i] = '\"'.$key.'\":'.$dimensions[$i];
411
					}
411
					}
412
				} else {
412
				} else {
413
					$dimensions[$i] = '\"'.addslashes($value).'\"';
413
					$dimensions[$i] = '\"'.addslashes($value).'\"';
414
					if ($show_keys) {
414
					if ($show_keys) {
415
						$dimensions[$i] = '\"'.$key.'\":'.$dimensions[$i];
415
						$dimensions[$i] = '\"'.$key.'\":'.$dimensions[$i];
416
					}
416
					}
417
				}
417
				}
418
				if ($i == 0) {
418
				if ($i == 0) {
419
					$dimensions[$i] = '{'.$dimensions[$i];
419
					$dimensions[$i] = '{'.$dimensions[$i];
420
				}
420
				}
421
				if ($i == $total) {
421
				if ($i == $total) {
422
					$dimensions[$i].= '}';
422
					$dimensions[$i].= '}';
423
				}
423
				}
424
				$i++;
424
				$i++;
425
			}
425
			}
426
			$tableauJs = implode(',', $dimensions);
426
			$tableauJs = implode(',', $dimensions);
427
		}
427
		}
428
		return $tableauJs;
428
		return $tableauJs;
429
	}
429
	}
430
 
430
 
431
	private function remove_accents($string) {
431
	private function remove_accents($string) {
432
	    if ( !preg_match('/[\x80-\xff]/', $string) )
432
	    if ( !preg_match('/[\x80-\xff]/', $string) )
433
	        return $string;
433
	        return $string;
434
 
434
 
435
	        $chars = array(
435
	        $chars = array(
436
	            // Decompositions for Latin-1 Supplement
436
	            // Decompositions for Latin-1 Supplement
437
	            chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
437
	            chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
438
	            chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
438
	            chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
439
	            chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
439
	            chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
440
	            chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
440
	            chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
441
	            chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
441
	            chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
442
	            chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
442
	            chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
443
	            chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
443
	            chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
444
	            chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
444
	            chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
445
	            chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
445
	            chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
446
	            chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
446
	            chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
447
	            chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
447
	            chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
448
	            chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
448
	            chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
449
	            chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
449
	            chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
450
	            chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
450
	            chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
451
	            chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
451
	            chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
452
	            chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
452
	            chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
453
	            chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
453
	            chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
454
	            chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
454
	            chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
455
	            chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
455
	            chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
456
	            chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
456
	            chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
457
	            chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
457
	            chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
458
	            chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
458
	            chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
459
	            chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
459
	            chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
460
	            chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
460
	            chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
461
	            chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
461
	            chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
462
	            chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
462
	            chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
463
	            chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
463
	            chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
464
	            chr(195).chr(191) => 'y',
464
	            chr(195).chr(191) => 'y',
465
	            // Decompositions for Latin Extended-A
465
	            // Decompositions for Latin Extended-A
466
	            chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
466
	            chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
467
	            chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
467
	            chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
468
	            chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
468
	            chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
469
	            chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
469
	            chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
470
	            chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
470
	            chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
471
	            chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
471
	            chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
472
	            chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
472
	            chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
473
	            chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
473
	            chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
474
	            chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
474
	            chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
475
	            chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
475
	            chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
476
	            chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
476
	            chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
477
	            chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
477
	            chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
478
	            chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
478
	            chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
479
	            chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
479
	            chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
480
	            chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
480
	            chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
481
	            chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
481
	            chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
482
	            chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
482
	            chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
483
	            chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
483
	            chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
484
	            chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
484
	            chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
485
	            chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
485
	            chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
486
	            chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
486
	            chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
487
	            chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
487
	            chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
488
	            chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
488
	            chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
489
	            chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
489
	            chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
490
	            chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
490
	            chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
491
	            chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
491
	            chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
492
	            chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
492
	            chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
493
	            chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
493
	            chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
494
	            chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
494
	            chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
495
	            chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
495
	            chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
496
	            chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
496
	            chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
497
	            chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
497
	            chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
498
	            chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
498
	            chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
499
	            chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
499
	            chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
500
	            chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
500
	            chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
501
	            chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
501
	            chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
502
	            chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
502
	            chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
503
	            chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
503
	            chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
504
	            chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
504
	            chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
505
	            chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
505
	            chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
506
	            chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
506
	            chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
507
	            chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
507
	            chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
508
	            chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
508
	            chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
509
	            chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
509
	            chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
510
	            chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
510
	            chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
511
	            chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
511
	            chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
512
	            chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
512
	            chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
513
	            chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
513
	            chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
514
	            chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
514
	            chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
515
	            chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
515
	            chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
516
	            chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
516
	            chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
517
	            chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
517
	            chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
518
	            chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
518
	            chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
519
	            chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
519
	            chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
520
	            chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
520
	            chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
521
	            chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
521
	            chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
522
	            chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
522
	            chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
523
	            chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
523
	            chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
524
	            chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
524
	            chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
525
	            chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
525
	            chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
526
	            chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
526
	            chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
527
	            chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
527
	            chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
528
	            chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
528
	            chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
529
	            chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
529
	            chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
530
	        );
530
	        );
531
	        
531
	        
532
	        $string = strtr($string, $chars);
532
	        $string = strtr($string, $chars);
533
	        
533
	        
534
	        return $string;
534
	        return $string;
535
	}
535
	}
536
}
536
}
537
?>
537
?>