Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 1700 Rev 1702
1
<?php
1
<?php
2
/**
2
/**
3
 * Service fournissant des informations sur les collections et les structures répondant aux critères de recherche
3
 * Service fournissant des informations sur les collections et les structures répondant aux critères de recherche
4
 * fournis en paramêtre.
4
 * fournis en paramêtre.
5
 *
5
 *
6
 * @author Raphaël Droz <raphael@tela-botanica.org>
6
 * @author Raphaël Droz <raphael@tela-botanica.org>
7
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
7
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
8
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
8
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
9
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
9
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
10
 * @copyright 2009, 2013 Tela-Botanica
10
 * @copyright 2009, 2013 Tela-Botanica
11
 */
11
 */
12
class CoelRecherche extends Coel {
12
class CoelRecherche extends Coel {
13
 
13
 
14
	/**
14
	/**
15
	 * Méthode principale appelée avec une requête de type GET.
15
	 * Méthode principale appelée avec une requête de type GET.
16
	 * Elle sert d'aiguilleur pour appeller la méthode correspondant au type de recherche passé en paramêtre.
16
	 * Elle sert d'aiguilleur pour appeller la méthode correspondant au type de recherche passé en paramêtre.
17
	 */
17
	 */
18
	public function getElement($param = array()) {
18
	public function getElement($param = array()) {
19
		// Initialisation des variables
19
		// Initialisation des variables
20
		$info = array();
20
		$info = array();
21
				
21
				
22
		// Nour recherchons le type de requête demandé
22
		// Nour recherchons le type de requête demandé
23
		$type = $param[0];
23
		$type = $param[0];
24
				 
24
				 
25
		$methode = 'getElement'.$type;
25
		$methode = 'getElement'.$type;
26
		if (method_exists($this, $methode)) {
26
		if (method_exists($this, $methode)) {
27
			array_shift($param);
27
			array_shift($param);
28
			$info = $this->$methode($param);
28
			$info = $this->$methode($param);
29
		} else {
29
		} else {
30
			$this->messages[] = "Le type de recherche demandé '$type' n'est pas disponible.";
30
			$this->messages[] = "Le type de recherche demandé '$type' n'est pas disponible.";
31
		}
31
		}
32
		
32
		
33
		// Envoie sur la sortie standard
33
		// Envoie sur la sortie standard
34
		if($this->formatRetour == 'text/plain') {
34
		if($this->formatRetour == 'text/plain') {
35
			$this->envoyer($info, 'text/plain', 'utf-8', false);
35
			$this->envoyer($info, 'text/plain', 'utf-8', false);
36
			exit;
36
			exit;
37
		}
37
		}
38
		$this->envoyer($info);
38
		$this->envoyer($info);
39
	}
39
	}
40
	
40
	
41
	/* Méthode pour récupérer une liste d'information sur les collections et/ou structures en fonction de mots et de
41
	/* Méthode pour récupérer une liste d'information sur les collections et/ou structures en fonction de mots et de
42
	 * restrictions.
42
	 * restrictions.
43
	 * Appelée avec les paramêtres d'url suivant :
43
	 * Appelée avec les paramêtres d'url suivant :
44
	 * /CoelRecherche/ParDefaut/_
44
	 * /CoelRecherche/ParDefaut/_
45
	 * ou les _ représentent dans l'ordre : mots
45
	 * ou les _ représentent dans l'ordre : mots
46
	 * Si un des paramêtres est absent, il prendre la valeur *
46
	 * Si un des paramêtres est absent, il prendre la valeur *
47
	 */
47
	 */
48
	public function getElementParDefaut($param) {
48
	public function getElementParDefaut($param) {
49
		// Initialisation des variables
49
		// Initialisation des variables
50
		$info = array();
50
		$info = array();
51
				
51
				
52
		// Pré traitement des paramêtres
52
		// Pré traitement des paramêtres
53
		$p = $this->pretraiterParametresUrl($param);
53
		$p = $this->pretraiterParametresUrl($param, $_GET);
54
 
54
 
55
		$fromClause = $whereClause = $joinClause = array();
55
		$fromClause = $whereClause = $joinClause = array();
56
		self::construireFromEtWhere($p, $fromClause, $joinClause, $whereClause);
56
		self::construireFromEtWhere($p, $fromClause, $joinClause, $whereClause);
57
 
57
 
58
		// Construction de la requête
58
		// Construction de la requête
59
		$requete = sprintf(
59
		$requete = sprintf(
60
			'SELECT %s cs_id_structure, cs_ville, cs_nom, cs_code_postal, cs_latitude, cs_longitude, cc_id_collection, cc_nom'
60
			'SELECT %s cs_id_structure, cs_ville, cs_nom, cs_code_postal, cs_latitude, cs_longitude, cc_id_collection, cc_nom'
61
			. ' FROM %s %s'
61
			. ' FROM %s %s'
62
			. ' WHERE %s ORDER BY %s %s -- %s:%d',
62
			. ' WHERE %s ORDER BY %s %s -- %s:%d',
63
 
63
 
64
			$this->distinct ? 'DISTINCT' : '',
64
			$this->distinct ? 'DISTINCT' : '',
65
 
65
 
66
			implode(',', $fromClause),
66
			implode(',', $fromClause),
67
			implode(' ', $joinClause),
67
			implode(' ', $joinClause),
68
 
68
 
69
			$whereClause ? implode(" AND ", $whereClause) : TRUE,
69
			$whereClause ? implode(" AND ", $whereClause) : TRUE,
70
			is_null($this->orderby) ? 'cs_ville ASC, cs_nom ASC, cc_nom ASC' : $this->orderby,
70
			is_null($this->orderby) ? 'cs_ville ASC, cs_nom ASC, cc_nom ASC' : $this->orderby,
71
 
71
 
72
			$this->limit != -1 ? "LIMIT {$this->start}, {$this->limit}" : "",
72
			$this->limit != -1 ? "LIMIT {$this->start}, {$this->limit}" : "",
73
			__FILE__, __LINE__);
73
			__FILE__, __LINE__);
74
 
74
 
75
		
75
		
76
		// Récupération des résultats
76
		// Récupération des résultats
77
		try {
77
		try {
78
			$donnees = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
78
			$donnees = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
79
			if ($donnees === false) {
79
			if ($donnees === false) {
80
				$this->messages[] = "La requête a retourné aucun résultat.";
80
				$this->messages[] = "La requête a retourné aucun résultat.";
81
			} else {
81
			} else {
82
				$info = $donnees;
82
				$info = $donnees;
83
			}
83
			}
84
		} catch (PDOException $e) {
84
		} catch (PDOException $e) {
85
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
85
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
86
		}
86
		}
87
		return $info;
87
		return $info;
88
	}
88
	}
89
	
89
	
90
	/* Méthode pour récupérer une liste d'information sur les collections et/ou structures en fonction de mots et de
90
	/* Méthode pour récupérer une liste d'information sur les collections et/ou structures en fonction de mots et de
91
	 * restrictions.
91
	 * restrictions.
92
	 * Appelée avec les paramêtres d'url suivant :
92
	 * Appelée avec les paramêtres d'url suivant :
93
	 * /CoelRecherche/ParDefaut/_
93
	 * /CoelRecherche/ParDefaut/_
94
	 * ou les _ représentent dans l'ordre : mots
94
	 * ou les _ représentent dans l'ordre : mots
95
	 * Si un des paramêtres est absent, il prendre la valeur *
95
	 * Si un des paramêtres est absent, il prendre la valeur *
96
	 */
96
	 */
97
	public function getElementNombre($param) {
97
	public function getElementNombre($param) {
98
		// Initialisation des variables
98
		// Initialisation des variables
99
		$info = array();
99
		$info = array();
100
				
100
				
101
		// Pré traitement des paramêtres
101
		// Pré traitement des paramêtres
102
		$p = $this->pretraiterParametresUrl($param);
102
		$p = $this->pretraiterParametresUrl($param, $_GET);
103
 
103
 
104
		$fromClause = $whereClause = $joinClause = array();
104
		$fromClause = $whereClause = $joinClause = array();
105
		self::construireFromEtWhere($p, $fromClause, $joinClause, $whereClause);
105
		self::construireFromEtWhere($p, $fromClause, $joinClause, $whereClause);
106
 
106
 
107
		// Construction de la requête
107
		// Construction de la requête
108
		// Il est important de compter le nombre d'association structure-collection différentes pour obtenir le bon nombre
108
		// Il est important de compter le nombre d'association structure-collection différentes pour obtenir le bon nombre
109
		$requete = sprintf(
109
		$requete = sprintf(
110
			'SELECT %s COUNT(cs_id_structure) AS nbre, cc_id_collection '
110
			'SELECT %s COUNT(cs_id_structure) AS nbre, cc_id_collection '
111
			. ' FROM %s %s'
111
			. ' FROM %s %s'
112
			. ' WHERE %s ORDER BY %s LIMIT %d, %d -- %s:%d',
112
			. ' WHERE %s ORDER BY %s LIMIT %d, %d -- %s:%d',
113
 
113
 
114
			$this->distinct ? 'DISTINCT' : '',
114
			$this->distinct ? 'DISTINCT' : '',
115
 
115
 
116
			implode(',', $fromClause),
116
			implode(',', $fromClause),
117
			implode(' ', $joinClause),
117
			implode(' ', $joinClause),
118
 
118
 
119
			$whereClause ? implode(" AND ", $whereClause) : TRUE,
119
			$whereClause ? implode(" AND ", $whereClause) : TRUE,
120
			is_null($this->orderby) ? 'cs_ville ASC, cs_nom ASC' : $this->orderby,
120
			is_null($this->orderby) ? 'cs_ville ASC, cs_nom ASC' : $this->orderby,
121
			$this->start, $this->limit,
121
			$this->start, $this->limit,
122
			__FILE__, __LINE__);
122
			__FILE__, __LINE__);
123
 
123
 
124
 
124
 
125
		// Récupération des résultats
125
		// Récupération des résultats
126
		try {
126
		try {
127
			$donnees = $this->bdd->query($requete)->fetch(PDO::FETCH_ASSOC);
127
			$donnees = $this->bdd->query($requete)->fetch(PDO::FETCH_ASSOC);
128
			if ($donnees === false) {
128
			if ($donnees === false) {
129
				$this->messages[] = "La requête a retourné aucun résultat.";
129
				$this->messages[] = "La requête a retourné aucun résultat.";
130
			} else {
130
			} else {
131
				$info = $donnees['nbre'];
131
				$info = $donnees['nbre'];
132
			}
132
			}
133
		} catch (PDOException $e) {
133
		} catch (PDOException $e) {
134
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
134
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
135
		}
135
		}
136
 
136
 
137
		return $info;
137
		return $info;
138
	}
138
	}
139
	
139
	
140
	private function pretraiterParametresUrl($param) {
140
	private function pretraiterParametresUrl($param, $qs /* query-string */) {
141
		// Tableau des paramêtres qui peuvent être passés dans l'url
141
		// Tableau des paramêtres qui peuvent être passés dans l'url
142
		$params_passes = array(
142
		$params_passes = array(
143
			'mots' => 'str', 
143
			'mots' => 'str', 
144
			'sci' => 'bool', 
144
			'sci' => 'bool', 
145
			'bot' => 'int', 
145
			'bot' => 'int', 
146
			'zg' => 'str', 
146
			'zg' => 'str', 
147
			'p' => 'str', 
147
			'p' => 'str', 
148
			'pr' => 'int',
148
			'pr' => 'int',
149
			'str-d' => 'frdepliste',
149
			'str-d' => 'frdepliste',
150
			'veg' => 'int',
150
			'veg' => 'int',
151
			'projets' => 'int');
151
			'projets' => 'int');
152
		
152
		
153
		$p = $this->traiterParametresUrl(array_keys($params_passes), $param, false);
153
		$p = $this->traiterParametresUrl(array_keys($params_passes), $param, false);
154
		$this->debug[] = $param;
154
		$this->debug[] = $param;
155
		foreach ($params_passes as $param_passe => $type) {
155
		foreach ($params_passes as $param_passe => $type) {
156
			if (isset($p[$param_passe])) {
156
			if (isset($p[$param_passe])) {
157
				// Suppression des éventuels espaces en début et fin de chaine
157
				// Suppression des éventuels espaces en début et fin de chaine
158
				$valeur = trim($p[$param_passe]);
158
				$valeur = trim($p[$param_passe]);
159
				
159
				
160
				// Type de paramêtre chaine
160
				// Type de paramêtre chaine
161
				if ($type == 'str') {
161
				if ($type == 'str') {
162
					// Suppression des slash
162
					// Suppression des slash
163
					$valeur = stripslashes($valeur);
163
					$valeur = stripslashes($valeur);
164
					
164
					
165
					// Utilisation d'une recherche de chaîne exacte
165
					// Utilisation d'une recherche de chaîne exacte
166
					if (preg_match('/^"(.*)"$/', $valeur, $match)) {
166
					if (preg_match('/^"(.*)"$/', $valeur, $match)) {
167
						$valeur = '%'.$match[1].'%';
167
						$valeur = '%'.$match[1].'%';
168
					} else {
168
					} else {
169
						// Recherche de mots non liés
169
						// Recherche de mots non liés
170
						$mots = explode(' ', $valeur);
170
						$mots = explode(' ', $valeur);
171
						$valeur = '%'.implode ('%', $mots).'%';
171
						$valeur = '%'.implode ('%', $mots).'%';
172
					}
172
					}
173
					// Mise en place des quotes pour l'intérogation dans la bdd
173
					// Mise en place des quotes pour l'intérogation dans la bdd
174
					$valeur = $this->bdd->quote($valeur);
174
					$valeur = $this->bdd->quote($valeur);
175
				}
175
				}
176
				// Type de paramêtre booléen
176
				// Type de paramêtre booléen
177
				if ($type == 'bool') {
177
				if ($type == 'bool') {
178
					if (preg_match('/^[0]$/', $valeur)) {
178
					if (preg_match('/^[0]$/', $valeur)) {
179
						$valeur = false;
179
						$valeur = false;
180
					} else if (preg_match('/^[1]$/', $valeur)) {
180
					} else if (preg_match('/^[1]$/', $valeur)) {
181
						$valeur = true;
181
						$valeur = true;
182
					} else {
182
					} else {
183
						$this->messages[] = "Le paramêtre '$param_passe' attend une valeur de type 0 ou 1 et non '$valeur'.";
183
						$this->messages[] = "Le paramêtre '$param_passe' attend une valeur de type 0 ou 1 et non '$valeur'.";
184
						$valeur = null;
184
						$valeur = null;
185
					}
185
					}
186
					
186
					
187
				}
187
				}
188
				// Type de paramêtre entier
188
				// Type de paramêtre entier
189
				if ($type == 'int') {
189
				if ($type == 'int') {
190
					if (!preg_match('/^(?:[0-9]+,\s*)*[0-9]+$/', $valeur)) {
190
					if (!preg_match('/^(?:[0-9]+,\s*)*[0-9]+$/', $valeur)) {
191
						$this->messages[] = "Le paramêtre '$param_passe' attend une ou plusieurs valeurs de type entiers ".
191
						$this->messages[] = "Le paramêtre '$param_passe' attend une ou plusieurs valeurs de type entiers ".
192
							"séparés par des virgules et non '$valeur'.";
192
							"séparés par des virgules et non '$valeur'.";
193
						$valeur = null;
193
						$valeur = null;
194
					}
194
					}
195
				}
195
				}
196
 
196
 
197
				if ($type == 'frdepliste') {
197
				if ($type == 'frdepliste') {
198
					$valeur = array_filter(explode(',', $valeur), create_function('$val', 'return preg_match("/^(\d+|2A|2B)$/i", $val);'));
198
					$valeur = array_filter(explode(',', $valeur), create_function('$val', 'return preg_match("/^(\d+|2A|2B)$/i", $val);'));
199
				}
199
				}
200
 
200
 
201
				$p[$param_passe] = $valeur;
201
				$p[$param_passe] = $valeur;
202
			}
202
			}
203
		}
203
		}
204
		
204
 
-
 
205
        if(isset($qs['pays'])) {
-
 
206
            $p['pays'] = array_filter(explode(',', $qs['pays']), create_function('$val', 'return preg_match("/^[A-Z][A-Z]$/", $val);'));
-
 
207
            if(!$p['pays']) unset($p['pays']);
-
 
208
        }
-
 
209
 
205
		return $p;
210
		return $p;
206
	}
211
	}
207
	
212
	
208
	static function construireFromEtWhere($p, &$from, &$join, &$where) {
213
	static function construireFromEtWhere($p, &$from, &$join, &$where) {
209
		$from = array('coel_collection');
214
		$from = array('coel_collection');
210
		$join = array('LEFT JOIN coel_structure ON (cc_ce_structure = cs_id_structure)');
215
		$join = array('LEFT JOIN coel_structure ON (cc_ce_structure = cs_id_structure)');
211
		$where = array();
216
		$where = array();
212
 
217
 
213
		// Gestion du from en fonction des paramêtres
218
		// Gestion du from en fonction des paramêtres
214
		if (isset($p['str-d'])) {// ATTENTION : Remplace $from, doit être situé en première position!
219
		if (isset($p['str-d'])) {// ATTENTION : Remplace $from, doit être situé en première position!
215
			$from = array('coel_structure');
220
			$from = array('coel_structure');
216
			$join = array('LEFT JOIN coel_collection ON (cs_id_structure = cc_ce_structure)');
221
			$join = array('LEFT JOIN coel_collection ON (cs_id_structure = cc_ce_structure)');
217
		}
222
		}
218
		
223
		
219
		// Construire from et where en fonction des paramêtres 
224
		// Construire from et where en fonction des paramêtres 
220
		if (isset($p['mots'])) {
225
		if (isset($p['mots'])) {
221
			$where[] = '(' . implode(' OR ', array(
226
			$where[] = '(' . implode(' OR ', array(
222
				"cc_nom LIKE {$p['mots']}",
227
				"cc_nom LIKE {$p['mots']}",
223
				"cc_truk_nom_alternatif LIKE {$p['mots']}",
228
				"cc_truk_nom_alternatif LIKE {$p['mots']}",
224
				"cc_truk_code LIKE {$p['mots']}",
229
				"cc_truk_code LIKE {$p['mots']}",
225
				"cc_description LIKE {$p['mots']}",
230
				"cc_description LIKE {$p['mots']}",
226
				"cc_description_specialiste LIKE {$p['mots']}",
231
				"cc_description_specialiste LIKE {$p['mots']}",
227
				"cc_historique LIKE {$p['mots']}",
232
				"cc_historique LIKE {$p['mots']}",
228
				"cs_nom LIKE {$p['mots']}",
233
				"cs_nom LIKE {$p['mots']}",
229
				"cs_truk_nom_alternatif LIKE {$p['mots']}",
234
				"cs_truk_nom_alternatif LIKE {$p['mots']}",
230
				"cs_description LIKE {$p['mots']}",
235
				"cs_description LIKE {$p['mots']}",
231
				"cs_adresse_01 LIKE {$p['mots']}",
236
				"cs_adresse_01 LIKE {$p['mots']}",
232
				"cs_adresse_02 LIKE {$p['mots']}",
237
				"cs_adresse_02 LIKE {$p['mots']}",
233
				"cs_ville LIKE {$p['mots']}",
238
				"cs_ville LIKE {$p['mots']}",
234
				"cs_truk_identifiant_alternatif LIKE {$p['mots']}",
239
				"cs_truk_identifiant_alternatif LIKE {$p['mots']}",
235
				"cs_condition_acces LIKE {$p['mots']}",
240
				"cs_condition_acces LIKE {$p['mots']}",
236
				"cs_condition_usage LIKE {$p['mots']}",
241
				"cs_condition_usage LIKE {$p['mots']}",
237
				"cs_truk_telephone LIKE {$p['mots']}",
242
				"cs_truk_telephone LIKE {$p['mots']}",
238
				"cs_courriel LIKE {$p['mots']}",
243
				"cs_courriel LIKE {$p['mots']}",
239
				"cs_truk_url LIKE {$p['mots']}") . ')');
244
				"cs_truk_url LIKE {$p['mots']}") . ')');
240
		}
245
		}
241
 
246
 
242
		if (isset($p['sci'])) {
247
		if (isset($p['sci'])) {
243
			if ($p['sci'] === true) {
248
			if ($p['sci'] === true) {
244
				$where[] = 'csv_mark_visite_avec_motif = 1';
249
				$where[] = 'csv_mark_visite_avec_motif = 1';
245
			} else if ($p['sci'] === false) {
250
			} else if ($p['sci'] === false) {
246
				$where[] = 'csv_mark_acces_ss_motif = 1';
251
				$where[] = 'csv_mark_acces_ss_motif = 1';
247
			}
252
			}
248
		}
253
		}
249
 
254
 
250
		if (isset($p['bot'])) {
255
		if (isset($p['bot'])) {
251
			$where[] = "ccb_ce_truk_type IN ({$p['bot']})";
256
			$where[] = "ccb_ce_truk_type IN ({$p['bot']})";
252
		}
257
		}
253
		if (isset($p['zg'])) {
258
		if (isset($p['zg'])) {
254
			$where[] = "cc_truk_couverture_lieu LIKE {$p['zg']}";
259
			$where[] = "cc_truk_couverture_lieu LIKE {$p['zg']}";
255
		}
260
		}
256
		if (isset($p['p'])) {
261
		if (isset($p['p'])) {
257
			$where[] = "cp_fmt_nom_complet LIKE {$p['p']}";
262
			$where[] = "cp_fmt_nom_complet LIKE {$p['p']}";
258
		}
263
		}
259
		if (isset($p['pr'])) {
264
		if (isset($p['pr'])) {
260
			$where[] = "ccap_id_role IN ({$p['pr']})";
265
			$where[] = "ccap_id_role IN ({$p['pr']})";
261
		}
266
		}
-
 
267
 
-
 
268
        // par défaut, spécifier un département restreint à la France
262
		if (isset($p['str-d'])) {
269
		if (isset($p['str-d'])) {
-
 
270
            $join[] = 'LEFT JOIN coel_meta_liste_valeur cv ON cv.cmlv_id_valeur = cs_ce_truk_pays';
263
			$where[] = 'cs_ce_truk_pays = 2654';
271
			$where[] = 'cv.cmlv_abreviation = "FR"';
264
			$where[] = sprintf("cs_code_postal REGEXP '^(%s).*'", implode('|', $p['str-d']));
272
			$where[] = sprintf("cs_code_postal REGEXP '^(%s).*'", implode('|', $p['str-d']));
265
		}
273
		}
-
 
274
 
-
 
275
		if (isset($p['pays'])) {
-
 
276
            $join[] = 'LEFT JOIN coel_meta_liste_valeur cv ON cv.cmlv_id_valeur = cs_ce_truk_pays';
-
 
277
			$where[] = sprintf('cv.cmlv_abreviation IN ("%s")', implode('","', $p['pays']));
-
 
278
		}
266
 
279
 
267
		if (isset($p['veg'])) {
280
		if (isset($p['veg'])) {
268
			$veg = explode(',', $p['veg']);
281
			$veg = explode(',', $p['veg']);
269
			$veg_nbre = count($veg);
282
			$veg_nbre = count($veg);
270
			
283
			
271
			if ($veg_nbre == 1) {
284
			if ($veg_nbre == 1) {
272
				$where[] = "ccb_truk_nature LIKE '%{$p['veg']}%'";
285
				$where[] = "ccb_truk_nature LIKE '%{$p['veg']}%'";
273
			} else {
286
			} else {
274
				$recherche = array();
287
				$recherche = array();
275
				foreach ($veg as $id) {
288
				foreach ($veg as $id) {
276
					$recherche[] = "ccb_truk_nature LIKE '%$id%'";
289
					$recherche[] = "ccb_truk_nature LIKE '%$id%'";
277
				}
290
				}
278
				$where[] = '('.implode(' OR ', $recherche).') ';
291
				$where[] = '('.implode(' OR ', $recherche).') ';
279
			}
292
			}
280
		}
293
		}
281
		
294
		
282
		if (isset($p['projets'])) {
295
		if (isset($p['projets'])) {
283
			$where[] = "cc_ce_projet IN ({$p['projets']})";
296
			$where[] = "cc_ce_projet IN ({$p['projets']})";
284
			$where[] = "cs_ce_projet IN ({$p['projets']})";
297
			$where[] = "cs_ce_projet IN ({$p['projets']})";
285
		}
298
		}
286
		
299
		
287
 
300
 
288
		if (isset($p['sci'])) {
301
		if (isset($p['sci'])) {
289
			$join[] = 'LEFT JOIN coel_structure_valorisation ON (cs_id_structure = csv_id_structure)';
302
			$join[] = 'LEFT JOIN coel_structure_valorisation ON (cs_id_structure = csv_id_structure)';
290
		}
303
		}
291
		if (isset($p['bot']) || isset($p['veg'])) {
304
		if (isset($p['bot']) || isset($p['veg'])) {
292
			$join[] = 'LEFT JOIN coel_collection_botanique ON (cc_id_collection = ccb_id_collection)';
305
			$join[] = 'LEFT JOIN coel_collection_botanique ON (cc_id_collection = ccb_id_collection)';
293
		}
306
		}
294
		if (isset($p['p']) || isset($p['pr'])) {
307
		if (isset($p['p']) || isset($p['pr'])) {
295
			$join[] = 'LEFT JOIN coel_collection_a_personne ON (cc_id_collection = ccap_id_collection)';
308
			$join[] = 'LEFT JOIN coel_collection_a_personne ON (cc_id_collection = ccap_id_collection)';
296
		}
309
		}
297
		if (isset($p['p'])) {
310
		if (isset($p['p'])) {
298
			$join[] = 'LEFT JOIN coel_personne ON (ccap_id_personne = cp_id_personne)';
311
			$join[] = 'LEFT JOIN coel_personne ON (ccap_id_personne = cp_id_personne)';
299
		}
312
		}
-
 
313
 
-
 
314
 
-
 
315
        $join = array_unique($join);
-
 
316
 
300
	}
317
	}
301
}
318
}