Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 1670 Rev 1673
1
<?php
1
<?php
2
/**
2
/**
3
 * Service fournissant la liste des structures et leurs informations.
3
 * Service fournissant la liste des structures et leurs informations.
4
 * Encodage en entrée : utf8
4
 * Encodage en entrée : utf8
5
 * Encodage en sortie : utf8
5
 * Encodage en sortie : utf8
6
 * 
6
 * 
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
 * @version $Id$
10
 * @version $Id$
11
 * @copyright 2009
11
 * @copyright 2009
12
 */
12
 */
13
class CoelStructure extends Coel {
13
class CoelStructure extends Coel {
14
	
14
	
15
	// ATTENTION : tjrs garder la table principale en premier, puis mettre les tables spécialisées.
15
	// ATTENTION : tjrs garder la table principale en premier, puis mettre les tables spécialisées.
16
	protected $tables = array(	120 => array(
16
	protected $tables = array(	120 => array(
17
									'nom' => 'coel_structure', 
17
									'nom' => 'coel_structure', 
18
									'prefixe' => 'cs', 
18
									'prefixe' => 'cs', 
19
									'id' => array('cs_id_structure')),
19
									'id' => array('cs_id_structure')),
20
								122 => array(
20
								122 => array(
21
									'nom' => 'coel_structure_conservation', 
21
									'nom' => 'coel_structure_conservation', 
22
									'prefixe' => 'csc',
22
									'prefixe' => 'csc',
23
									'id' => array('csc_id_structure')),
23
									'id' => array('csc_id_structure')),
24
								123 => array(
24
								123 => array(
25
									'nom' => 'coel_structure_valorisation', 
25
									'nom' => 'coel_structure_valorisation', 
26
									'prefixe' => 'csv',
26
									'prefixe' => 'csv',
27
									'id' => array('csv_id_structure')));	
27
									'id' => array('csv_id_structure')));	
28
 
28
 
29
	/**
29
	/**
30
	 * Méthode principale appelée avec une requête de type GET.
30
	 * Méthode principale appelée avec une requête de type GET.
31
	 */
31
	 */
32
	public function getElement($param = array()) {
32
	public function getElement($param = array()) {
33
		// Initialisation des variables
33
		// Initialisation des variables
34
		$info = array();
34
		$info = array();
35
				
35
				
36
		// Nour recherchons le type de requête demandé
36
		// Nour recherchons le type de requête demandé
37
		$type = $param[0];
37
		$type = $param[0];
38
				 
38
				 
39
		if ($type == '*' || is_numeric($type)) {
39
		if ($type == '*' || is_numeric($type)) {
-
 
40
			// Pré traitement des paramêtres
-
 
41
			$p = $this->traiterParametresUrl(array('id_projet', 'id_structure', 'recherche'), $param);
40
			$info = $this->getElementParDefaut($param);
42
			$info = $this->getElementParDefaut($p);
41
		} else {
43
		} else {
42
			$methode = 'getElement'.$type;
44
			$methode = 'getElement'.$type;
43
			if (method_exists($this, $methode)) {
45
			if (method_exists($this, $methode)) {
44
				array_shift($param);
46
				array_shift($param);
45
				$info = $this->$methode($param);
47
				$info = $this->$methode($param);
46
			} else {
48
			} else {
47
				$this->messages[] = "Le type d'information demandé '$type' n'est pas disponible.";
49
				$this->messages[] = "Le type d'information demandé '$type' n'est pas disponible.";
48
			}
50
			}
49
		}
51
		}
50
		
52
		
51
		// Envoie sur la sortie standard
53
		// Envoie sur la sortie standard
52
		$this->envoyer($info);
54
		$this->envoyer($info);
53
	}
55
	}
54
	
56
	
55
	/**
57
	/**
56
	 * Méthode par défaut pour garder la compatibilité avec Coel.
58
	 * Méthode par défaut pour garder la compatibilité avec Coel.
57
	 * Appelée avec les paramêtres d'url suivant :
59
	 * Appelée avec les paramêtres d'url suivant :
58
	 * /CoelStructure/_/_/_
60
	 * /CoelStructure/_/_/_
59
	 * ou les _ représentent dans l'ordre : id_projet, id_structure et nom
61
	 * ou les _ représentent dans l'ordre : id_projet, id_structure et nom
60
	 * Si un des paramêtres est abscent, il prendre la valeur *
62
	 * Si un des paramêtres est abscent, il prendre la valeur *
61
	 */
63
	 */
62
	public function getElementParDefaut($param) {
64
	public function getElementParDefaut($p) {
63
		// Initialisation des variables
65
		// Initialisation des variables
64
		$info = array();
66
		$info = array();
65
				
67
 
66
		// Pré traitement des paramêtres
-
 
67
		$p = $this->traiterParametresUrl(array('id_projet', 'id_structure', 'recherche'), $param);
-
 
68
				 
-
 
69
		// Construction de la requête
68
		// Construction de la requête
70
		$requete =	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' cs.*, csc.*, csv.*, '.
69
		$requete =	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' cs.*, csc.*, csv.*, '.
71
					'	cmhl_date_modification, cmhl_notes, cmhl_source, cmhl_ce_modifier_par, cmhl_ce_etat, cmhl_ip '.
70
					'	cmhl_date_modification, cmhl_notes, cmhl_source, cmhl_ce_modifier_par, cmhl_ce_etat, cmhl_ip '.
72
					'FROM coel_structure AS cs '.
71
					'FROM coel_structure AS cs '.
73
					'	LEFT JOIN coel_meta_historique_ligne ON (cs_ce_meta = cmhl_id_historique_ligne) '.
72
					'	LEFT JOIN coel_meta_historique_ligne ON (cs_ce_meta = cmhl_id_historique_ligne) '.
74
					'	LEFT JOIN coel_structure_conservation AS csc ON (cs_id_structure = csc_id_structure) '.
73
					'	LEFT JOIN coel_structure_conservation AS csc ON (cs_id_structure = csc_id_structure) '.
75
					'	LEFT JOIN coel_structure_valorisation AS csv ON (cs_id_structure = csv_id_structure) '.
74
					'	LEFT JOIN coel_structure_valorisation AS csv ON (cs_id_structure = csv_id_structure) '.
76
					((count($p) != 0) ? 'WHERE ' : '').			
75
					((count($p) != 0) ? 'WHERE ' : '').			
77
					((isset($p['id_projet'])) ? "AND cs_ce_projet = {$p['id_projet']} " : '').
76
					((isset($p['id_projet'])) ? "AND cs_ce_projet = {$p['id_projet']} " : '').
78
					((isset($p['id_structure'])) ? "AND cs_id_structure = {$p['id_structure']} " : '').
77
					((isset($p['id_structure'])) ? "AND cs_id_structure = {$p['id_structure']} " : '').
79
					(isset($p['recherche']) ? $this->construireWhereRecherche($p['recherche']) : '').
78
					(isset($p['recherche']) ? $this->construireWhereRecherche($p['recherche']) : '').
80
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'cs.cs_nom ASC').' ';
79
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'cs.cs_nom ASC').' ';
81
		
80
		
82
		$requete = str_replace('WHERE AND', 'WHERE', $requete);
81
		$requete = str_replace('WHERE AND', 'WHERE', $requete);
83
		$requete_compte = $requete;
82
		$requete_compte = $requete;
84
		$requete .= "LIMIT $this->start, $this->limit ";
83
		$requete .= "LIMIT $this->start, $this->limit ";
85
 
84
 
86
		// Récupération des résultats
85
		// Récupération des résultats
87
		try {
86
		try {
88
			// SPÉCIAL :
87
			// SPÉCIAL :
89
			// Lorsqu'on cherche une seule structure avec un id passé en paramêtre, nous devons renvoyer un objet
88
			// Lorsqu'on cherche une seule structure avec un id passé en paramêtre, nous devons renvoyer un objet
90
			$donnees = ($this->formatRetour == 'objet' && isset($p['id_structure'])) ? $this->bdd->query($requete)->fetch(PDO::FETCH_OBJ) : $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
89
			$donnees = ($this->formatRetour == 'objet' && isset($p['id_structure'])) ? $this->bdd->query($requete)->fetch(PDO::FETCH_OBJ) : $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
91
			if ($donnees === false) {
90
			if ($donnees === false) {
92
				$this->messages[] = "La requête a retourné aucun résultat.";
91
				$this->messages[] = "La requête a retourné aucun résultat.";
93
			}
92
			}
94
			
93
			
95
			$elements_nbre = $this->bdd->query($requete_compte)->rowCount();
94
			$elements_nbre = $this->bdd->query($requete_compte)->rowCount();
96
			$info['nbElements'] = $elements_nbre;
95
			$info['nbElements'] = $elements_nbre;
97
			$info['structures'] = $donnees;			
96
			$info['structures'] = $donnees;			
98
		} catch (PDOException $e) {
97
		} catch (PDOException $e) {
99
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
98
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
100
		}
99
		}
101
 
100
 
102
		return $info;
101
		return $info;
103
	}
102
	}
104
	
103
	
105
	private function construireWhereRecherche($recherche) {
104
	private function construireWhereRecherche($recherche) {
106
		$recherche = "AND ".
105
		$recherche = "AND ".
107
		"(".
106
		"(".
108
			"cs_nom LIKE {$recherche}  OR ".
107
			"cs_nom LIKE {$recherche}  OR ".
109
			"cs_ville LIKE {$recherche} ".
108
			"cs_ville LIKE {$recherche} ".
110
		")";
109
		")";
111
		return $recherche;
110
		return $recherche;
112
	}
111
	}
113
	
112
	
114
	/* Méthode pour récupérer le nombre de structure par zone géographique.
113
	/* Méthode pour récupérer le nombre de structure par zone géographique.
115
	 * Appelée avec les paramêtres d'url suivant :
114
	 * Appelée avec les paramêtres d'url suivant :
116
	 * /CoelStructure/ParZoneGeo/_
115
	 * /CoelStructure/ParZoneGeo/_
117
	 * ou les _ représentent dans l'ordre : type.
116
	 * ou les _ représentent dans l'ordre : type.
118
	 * ou type peut valoir: FRD (= département français) 
117
	 * ou type peut valoir: FRD (= département français) 
119
	 * Si un des paramêtres est abscent, il prendre la valeur *
118
	 * Si un des paramêtres est abscent, il prendre la valeur *
120
	 */
119
	 */
121
	public function getElementParZoneGeo($param) {
120
	public function getElementParZoneGeo($param) {
122
		// Initialisation des variables
121
		// Initialisation des variables
123
		$info = array();
122
		$info = array();
124
				
123
				
125
		// Pré traitement des paramêtres
124
		// Pré traitement des paramêtres
126
		$p = $this->traiterParametresUrl(array('type', 'projets'), $param);
125
		$p = $this->traiterParametresUrl(array('type', 'projets'), $param);
127
		if (!isset($p['type'])) {
126
		if (!isset($p['type'])) {
128
			$this->messages[] = "Il est obligatoire d'indiquer type de recherche pour utiliser ce service.";
127
			$this->messages[] = "Il est obligatoire d'indiquer type de recherche pour utiliser ce service.";
129
		} else {
128
		} else {
130
			// Construction de la requête
129
			// Construction de la requête
131
			$requete =	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
130
			$requete =	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
132
						'	IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
131
						'	IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
133
						'		SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
132
						'		SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
134
						'		SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) AS id, '.
133
						'		SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) AS id, '.
135
						'	COUNT( cs_id_structure ) AS nbre '.
134
						'	COUNT( cs_id_structure ) AS nbre '.
136
						'FROM coel_structure '.
135
						'FROM coel_structure '.
137
						'WHERE cs_ce_truk_pays = 2654 '.
136
						'WHERE cs_ce_truk_pays = 2654 '.
138
						(isset($p['projets']) ? "	AND cs_ce_projet IN ({$p['projets']}) " : '').
137
						(isset($p['projets']) ? "	AND cs_ce_projet IN ({$p['projets']}) " : '').
139
						'GROUP BY IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
138
						'GROUP BY IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
140
						'	SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
139
						'	SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
141
						'	SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) '.
140
						'	SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) '.
142
						'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'id ASC').' ';
141
						'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'id ASC').' ';
143
			// Récupération des résultats
142
			// Récupération des résultats
144
			try {
143
			try {
145
				$donnees = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
144
				$donnees = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
146
				if ($donnees === false) {
145
				if ($donnees === false) {
147
					$this->messages[] = "La requête a retourné aucun résultat.";
146
					$this->messages[] = "La requête a retourné aucun résultat.";
148
				} else {
147
				} else {
149
					foreach ($donnees as $donnee) {
148
					foreach ($donnees as $donnee) {
150
						$info[$donnee['id']] = $donnee['nbre'];
149
						$info[$donnee['id']] = $donnee['nbre'];
151
					}
150
					}
152
				}
151
				}
153
			} catch (PDOException $e) {
152
			} catch (PDOException $e) {
154
				$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
153
				$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
155
			}
154
			}
156
		}
155
		}
157
		return $info;
156
		return $info;
158
	}
157
	}
159
	
158
	
160
	/**
159
	/**
161
	 * Méthode appelée pour ajouter un élément.
160
	 * Méthode appelée pour ajouter un élément.
162
	 */
161
	 */
163
	public function createElement($params) {
162
	public function createElement($params) {
164
		// Identification de l'utilisateur
163
		// Identification de l'utilisateur
165
		list($id_utilisateur, $id_session) = $this->getIdentification($params);
164
		list($id_utilisateur, $id_session) = $this->getIdentification($params);
166
 
165
 
167
		// Contrôle du non détournement de l'utilisateur
166
		// Contrôle du non détournement de l'utilisateur
168
		if (!$this->etreAutorise($id_utilisateur)) {
167
		if (!$this->etreAutorise($id_utilisateur)) {
169
			$this->envoyer();
168
			$this->envoyer();
170
			return;
169
			return;
171
		}
170
		}
172
		try {
171
		try {
173
			// Vérification des tables à vraiment mettre à jour en fonction des données passées.
172
			// Vérification des tables à vraiment mettre à jour en fonction des données passées.
174
			if( (! @$params['cs_latitude'] || ! @$params['cs_longitude']) &&
173
			if( (! @$params['cs_latitude'] || ! @$params['cs_longitude']) &&
175
				(@$params['cs_adresse_01'] || @$params['cs_code_postal'] || @$params['cs_ville']) ) {
174
				(@$params['cs_adresse_01'] || @$params['cs_code_postal'] || @$params['cs_ville']) ) {
176
				$lonlat = array();
175
				$lonlat = array();
177
				if(Coel::coordGuess(Coel::addrReStruct($params), $lonlat)) {
176
				if(Coel::coordGuess(Coel::addrReStruct($params), $lonlat)) {
178
					$params['cs_latitude'] = $lonlat['lat'];
177
					$params['cs_latitude'] = $lonlat['lat'];
179
					$params['cs_longitude'] = $lonlat['lon'];
178
					$params['cs_longitude'] = $lonlat['lon'];
180
				}
179
				}
181
			}
180
			}
182
 
181
 
183
			$tables_a_modifier = $this->recupererTablesAModifier($params);
182
			$tables_a_modifier = $this->recupererTablesAModifier($params);
184
			reset($tables_a_modifier);
183
			reset($tables_a_modifier);
185
 
184
 
186
			$id_structure = null;
185
			$id_structure = null;
187
			while (list($table_id, $table) = each($tables_a_modifier)) {
186
			while (list($table_id, $table) = each($tables_a_modifier)) {
188
				if (is_null($table['champs'])) continue;
187
				if (is_null($table['champs'])) continue;
189
				if ($this->avoirCleComplete($table)) {
188
				if ($this->avoirCleComplete($table)) {
190
					$this->mettreAJourAvecCle($id_utilisateur, $id_session, $table_id, $table);
189
					$this->mettreAJourAvecCle($id_utilisateur, $id_session, $table_id, $table);
191
					continue;
190
					continue;
192
				}
191
				}
193
 
192
 
194
				// Ajout des données à la table des données
193
				// Ajout des données à la table des données
195
				$id_structure = $this->ajouter($table);
194
				$id_structure = $this->ajouter($table);
196
				if ($id_structure === false) continue;
195
				if ($id_structure === false) continue;
197
 
196
 
198
				$table['champs_valeurs_id']['cs_id_structure'] = $id_structure;
197
				$table['champs_valeurs_id']['cs_id_structure'] = $id_structure;
199
				$table['champs_valeurs_brut']['cs_id_structure'] = $id_structure;
198
				$table['champs_valeurs_brut']['cs_id_structure'] = $id_structure;
200
				$tables_a_modifier[122]['champs_valeurs_id']['csc_id_structure'] = $id_structure;
199
				$tables_a_modifier[122]['champs_valeurs_id']['csc_id_structure'] = $id_structure;
201
				$tables_a_modifier[122]['champs_valeurs_brut']['csc_id_structure'] = $id_structure;
200
				$tables_a_modifier[122]['champs_valeurs_brut']['csc_id_structure'] = $id_structure;
202
				$tables_a_modifier[122]['champs_valeurs_protege']['csc_id_structure'] = $this->bdd->quote($id_structure);
201
				$tables_a_modifier[122]['champs_valeurs_protege']['csc_id_structure'] = $this->bdd->quote($id_structure);
203
				$tables_a_modifier[123]['champs_valeurs_id']['csv_id_structure'] = $id_structure;
202
				$tables_a_modifier[123]['champs_valeurs_id']['csv_id_structure'] = $id_structure;
204
				$tables_a_modifier[123]['champs_valeurs_brut']['csv_id_structure'] = $id_structure;
203
				$tables_a_modifier[123]['champs_valeurs_brut']['csv_id_structure'] = $id_structure;
205
				$tables_a_modifier[123]['champs_valeurs_protege']['csv_id_structure'] = $this->bdd->quote($id_structure);
204
				$tables_a_modifier[123]['champs_valeurs_protege']['csv_id_structure'] = $this->bdd->quote($id_structure);
206
 
205
 
207
				// Historisation (Ajout des méta-données)
206
				// Historisation (Ajout des méta-données)
208
				$etat = 1; // Ajout
207
				$etat = 1; // Ajout
209
				$cle = $this->recupererCle($table);
208
				$cle = $this->recupererCle($table);
210
				$info = $this->creerXmlHisto($table['champs_valeurs_brut']);
209
				$info = $this->creerXmlHisto($table['champs_valeurs_brut']);
211
				$id_meta = $this->historiser($table_id, $cle, $info, $id_utilisateur, $etat, $id_session);
210
				$id_meta = $this->historiser($table_id, $cle, $info, $id_utilisateur, $etat, $id_session);
212
								
211
								
213
				// Liaison de la table des données à ses méta-données
212
				// Liaison de la table des données à ses méta-données
214
				$champ_meta = "{$table['prefixe']}_ce_meta";
213
				$champ_meta = "{$table['prefixe']}_ce_meta";
215
				$table['champs_valeurs_protege'] = array($champ_meta => $id_meta);
214
				$table['champs_valeurs_protege'] = array($champ_meta => $id_meta);
216
				$this->modifier($table);
215
				$this->modifier($table);
217
			}
216
			}
218
 
217
 
219
			if(isset($params['cpr_abreviation']) && !empty($params['cpr_abreviation'])) {
218
			if(isset($params['cpr_abreviation']) && !empty($params['cpr_abreviation'])) {
220
				$this->ajouterGuid($params['cpr_abreviation'], $id_structure);
219
				$this->ajouterGuid($params['cpr_abreviation'], $id_structure);
221
			}
220
			}
222
		} catch (PDOException $e) {
221
		} catch (PDOException $e) {
223
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
222
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
224
		}
223
		}
225
		
224
		
226
		$this->envoyer($id_structure);
225
		$this->envoyer($id_structure);
227
	}
226
	}
228
	
227
	
229
	/**
228
	/**
230
	 * Méthode appelée pour mettre à jour un élément
229
	 * Méthode appelée pour mettre à jour un élément
231
	 */
230
	 */
232
	public function updateElement($uid, $params) {
231
	public function updateElement($uid, $params) {
233
		// Vérification de la présence des id passés par l'url
232
		// Vérification de la présence des id passés par l'url
234
		if (!isset($uid[0])) {
233
		if (!isset($uid[0])) {
235
			$this->messages[] = "Identifiant de structure manquant. Vous ne devriez pas avoir accès à ce service.";
234
			$this->messages[] = "Identifiant de structure manquant. Vous ne devriez pas avoir accès à ce service.";
236
			$this->envoyer();
235
			$this->envoyer();
237
			return;
236
			return;
238
		}
237
		}
239
 
238
 
240
		// Identification de l'utilisateur
239
		// Identification de l'utilisateur
241
		list($id_utilisateur, $id_session) = $this->getIdentification($params);
240
		list($id_utilisateur, $id_session) = $this->getIdentification($params);
242
		// Contrôle du non détournement de l'utilisateur
241
		// Contrôle du non détournement de l'utilisateur
243
		if (!$this->etreAutorise($id_utilisateur)) {
242
		if (!$this->etreAutorise($id_utilisateur)) {
244
			$this->envoyer();
243
			$this->envoyer();
245
			return;
244
			return;
246
		}
245
		}
247
		try {
246
		try {
248
			$form_needs_refresh = FALSE;
247
			$form_needs_refresh = FALSE;
249
			if( (! @$params['cs_latitude'] || ! @$params['cs_longitude']) &&
248
			if( (! @$params['cs_latitude'] || ! @$params['cs_longitude']) &&
250
				(@$params['cs_adresse_01'] || @$params['cs_code_postal'] || @$params['cs_ville']) ) {
249
				(@$params['cs_adresse_01'] || @$params['cs_code_postal'] || @$params['cs_ville']) ) {
251
				$lonlat = array();
250
				$lonlat = array();
252
				if(Coel::coordGuess(Coel::addrReStruct($params), $lonlat)) {
251
				if(Coel::coordGuess(Coel::addrReStruct($params), $lonlat)) {
253
					$params['cs_latitude'] = $lonlat['lat'];
252
					$params['cs_latitude'] = $lonlat['lat'];
254
					$params['cs_longitude'] = $lonlat['lon'];
253
					$params['cs_longitude'] = $lonlat['lon'];
255
					$form_needs_refresh = TRUE;
254
					$form_needs_refresh = TRUE;
256
				}
255
				}
257
			}
256
			}
258
 
257
 
259
			// Vérification des tables à vraiment mettre à jour en fonction des données passées.
258
			// Vérification des tables à vraiment mettre à jour en fonction des données passées.
260
			$tables_a_modifier = $this->recupererTablesAModifier($params);
259
			$tables_a_modifier = $this->recupererTablesAModifier($params);
261
					
260
					
262
			// Pour chaque table du module nous lançons si nécessaire l'historisation puis la mise à jour
261
			// Pour chaque table du module nous lançons si nécessaire l'historisation puis la mise à jour
263
			foreach ($tables_a_modifier as $table_id => $table) {
262
			foreach ($tables_a_modifier as $table_id => $table) {
264
				if(@$table['nom'] == 'coel_structure' && !$this->avoirCleComplete($table)) {
263
				if(@$table['nom'] == 'coel_structure' && !$this->avoirCleComplete($table)) {
265
					error_log("tentative d'UPDATE sans contrainte de WHERE, \$table = " . print_r($table, TRUE));
264
					error_log("tentative d'UPDATE sans contrainte de WHERE, \$table = " . print_r($table, TRUE));
266
					continue; // ne pas mettre à jour sans contrainte de WHERE
265
					continue; // ne pas mettre à jour sans contrainte de WHERE
267
				}
266
				}
268
				$this->mettreAJourAvecCle($id_utilisateur, $id_session, $table_id, $table);
267
				$this->mettreAJourAvecCle($id_utilisateur, $id_session, $table_id, $table);
269
			}
268
			}
270
		} catch (PDOException $e) {
269
		} catch (PDOException $e) {
271
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
270
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
272
		}
271
		}
273
 
272
 
274
		// Envoie sur la sortie standard
273
		// Envoie sur la sortie standard
275
 
274
 
276
		if($form_needs_refresh) { // coordonnées mises à jour en DB: en informer le formulaire (si resté ouvert)
275
		if($form_needs_refresh) { // coordonnées mises à jour en DB: en informer le formulaire (si resté ouvert)
277
			// $this->envoyer('reload'); // TODO: handle this
276
			$this->envoyer($this->getElementParDefaut(array('id_structure' => $uid[0])));
-
 
277
			exit;
278
		}
278
		}
279
		$this->envoyer(); // OK par défaut
279
		$this->envoyer(); // OK par défaut
280
	}
280
	}
281
	
281
	
282
	/**
282
	/**
283
	 * Méthode appelée pour supprimer un élément
283
	 * Méthode appelée pour supprimer un élément
284
	 */
284
	 */
285
	public function deleteElement($uid) {
285
	public function deleteElement($uid) {
286
		// NOTES : une structure ne peut pas être supprimée si elle possède des collections liées.
286
		// NOTES : une structure ne peut pas être supprimée si elle possède des collections liées.
287
		// Vérification de la présence des id passés par l'url
287
		// Vérification de la présence des id passés par l'url
288
		if (!isset($uid[0]) || !isset($uid[1])) {
288
		if (!isset($uid[0]) || !isset($uid[1])) {
289
				$this->messages[] = "Identifiant de structure ou d'utilisateur manquant. Vous ne devriez pas avoir accès à ce service.";
289
				$this->messages[] = "Identifiant de structure ou d'utilisateur manquant. Vous ne devriez pas avoir accès à ce service.";
290
		} else {
290
		} else {
291
			// Identification de l'utilisateur
291
			// Identification de l'utilisateur
292
			list($id_utilisateur, $id_session) = $this->getIdentification($uid[0]);
292
			list($id_utilisateur, $id_session) = $this->getIdentification($uid[0]);
293
		
293
		
294
			// Contrôle du non détournement de l'utilisateur		
294
			// Contrôle du non détournement de l'utilisateur		
295
			if ($this->etreAutorise($id_utilisateur)) {		  
295
			if ($this->etreAutorise($id_utilisateur)) {		  
296
				// Récupération des id passés par l'url
296
				// Récupération des id passés par l'url
297
				$identifiants = explode(',', rtrim($uid[1], ','));
297
				$identifiants = explode(',', rtrim($uid[1], ','));
298
	
298
	
299
				try {
299
				try {
300
					if (count($identifiants) == 0) {
300
					if (count($identifiants) == 0) {
301
						$this->messages[] = "Aucun enregistrement n'a été supprimé.";
301
						$this->messages[] = "Aucun enregistrement n'a été supprimé.";
302
					} else {
302
					} else {
303
						foreach ($identifiants as $id_structure) {
303
						foreach ($identifiants as $id_structure) {
304
							// Vérification que la structure ne possède pas de collections liées
304
							// Vérification que la structure ne possède pas de collections liées
305
							if ($this->verifierPresenceCollection($id_structure) === false) {
305
							if ($this->verifierPresenceCollection($id_structure) === false) {
306
								$params = array('cs_id_structure' => $id_structure, 'csc_id_structure' => $id_structure, 'csv_id_structure' => $id_structure);
306
								$params = array('cs_id_structure' => $id_structure, 'csc_id_structure' => $id_structure, 'csv_id_structure' => $id_structure);
307
								$tables_a_modifier = $this->recupererTablesAModifier($params);
307
								$tables_a_modifier = $this->recupererTablesAModifier($params);
308
								
308
								
309
								foreach ($tables_a_modifier as $table_id => $table) {
309
								foreach ($tables_a_modifier as $table_id => $table) {
310
									if ($this->avoirEnregistrement($table)) {
310
									if ($this->avoirEnregistrement($table)) {
311
										$resultat = $this->supprimer($table);
311
										$resultat = $this->supprimer($table);
312
										if ($resultat === true) {
312
										if ($resultat === true) {
313
											// Historisation (Ajout des méta-données)
313
											// Historisation (Ajout des méta-données)
314
											$cle = $this->recupererCle($table);
314
											$cle = $this->recupererCle($table);
315
											$this->historiser($table_id, $cle, 'NULL', $id_utilisateur, 3, $id_session);
315
											$this->historiser($table_id, $cle, 'NULL', $id_utilisateur, 3, $id_session);
316
										}
316
										}
317
									}
317
									}
318
								}
318
								}
319
							} else {
319
							} else {
320
								$this->messages[] = "La structure '$id_structure' ne peut pas être supprimée car elle possède des collections liées.";
320
								$this->messages[] = "La structure '$id_structure' ne peut pas être supprimée car elle possède des collections liées.";
321
							}
321
							}
322
						}
322
						}
323
					}
323
					}
324
				} catch (PDOException $e) {
324
				} catch (PDOException $e) {
325
					$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
325
					$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
326
				}
326
				}
327
			}
327
			}
328
		}
328
		}
329
 
329
 
330
		// Envoie sur la sortie standard
330
		// Envoie sur la sortie standard
331
		$this->envoyer();
331
		$this->envoyer();
332
	}
332
	}
333
	
333
	
334
	private function verifierPresenceCollection($id_structure) {
334
	private function verifierPresenceCollection($id_structure) {
335
		$requete =	'SELECT COUNT(cc_id_collection) AS nbre_collection '.
335
		$requete =	'SELECT COUNT(cc_id_collection) AS nbre_collection '.
336
					'FROM coel_collection '.
336
					'FROM coel_collection '.
337
					"WHERE cc_ce_structure = '$id_structure' ".
337
					"WHERE cc_ce_structure = '$id_structure' ".
338
					'GROUP BY cc_ce_structure ';
338
					'GROUP BY cc_ce_structure ';
339
		
339
		
340
		// Vérification que la structure ne possède pas de collections liées
340
		// Vérification que la structure ne possède pas de collections liées
341
		$nbre_collection = $this->bdd->query($requete)->fetchColumn();
341
		$nbre_collection = $this->bdd->query($requete)->fetchColumn();
342
		
342
		
343
		$presence = false;
343
		$presence = false;
344
		if ($nbre_collection != 0) {
344
		if ($nbre_collection != 0) {
345
			$presence = true;
345
			$presence = true;
346
		}
346
		}
347
		return $presence;
347
		return $presence;
348
	}
348
	}
349
	
349
	
350
	private function ajouterGuid($abr_projet, $id_structure) {
350
	private function ajouterGuid($abr_projet, $id_structure) {
351
		if ($id_structure !== false) {
351
		if ($id_structure !== false) {
352
			$table_guid = $this->tables[120];
352
			$table_guid = $this->tables[120];
353
			$table_guid['champs_valeurs_id']['cs_id_structure'] = $id_structure;
353
			$table_guid['champs_valeurs_id']['cs_id_structure'] = $id_structure;
354
			$table_guid['champs_valeurs_protege']['cs_guid'] = $this->bdd->quote(sprintf($this->config['coel']['guid'], $abr_projet, 'str'.$id_structure));
354
			$table_guid['champs_valeurs_protege']['cs_guid'] = $this->bdd->quote(sprintf($this->config['coel']['guid'], $abr_projet, 'str'.$id_structure));
355
			$this->modifier($table_guid);
355
			$this->modifier($table_guid);
356
		}
356
		}
357
	}
357
	}
358
}
358
}
359
?>
359
?>