Subversion Repositories eFlore/Applications.cel

Rev

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

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