Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 1669 Rev 1670
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
			$info = $this->getElementParDefaut($param);
40
			$info = $this->getElementParDefaut($param);
41
		} else {
41
		} else {
42
			$methode = 'getElement'.$type;
42
			$methode = 'getElement'.$type;
43
			if (method_exists($this, $methode)) {
43
			if (method_exists($this, $methode)) {
44
				array_shift($param);
44
				array_shift($param);
45
				$info = $this->$methode($param);
45
				$info = $this->$methode($param);
46
			} else {
46
			} else {
47
				$this->messages[] = "Le type d'information demandé '$type' n'est pas disponible.";
47
				$this->messages[] = "Le type d'information demandé '$type' n'est pas disponible.";
48
			}
48
			}
49
		}
49
		}
50
		
50
		
51
		// Envoie sur la sortie standard
51
		// Envoie sur la sortie standard
52
		$this->envoyer($info);
52
		$this->envoyer($info);
53
	}
53
	}
54
	
54
	
55
	/**
55
	/**
56
	 * Méthode par défaut pour garder la compatibilité avec Coel.
56
	 * Méthode par défaut pour garder la compatibilité avec Coel.
57
	 * Appelée avec les paramêtres d'url suivant :
57
	 * Appelée avec les paramêtres d'url suivant :
58
	 * /CoelStructure/_/_/_
58
	 * /CoelStructure/_/_/_
59
	 * ou les _ représentent dans l'ordre : id_projet, id_structure et nom
59
	 * 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 *
60
	 * Si un des paramêtres est abscent, il prendre la valeur *
61
	 */
61
	 */
62
	public function getElementParDefaut($param) {
62
	public function getElementParDefaut($param) {
63
		// Initialisation des variables
63
		// Initialisation des variables
64
		$info = array();
64
		$info = array();
65
				
65
				
66
		// Pré traitement des paramêtres
66
		// Pré traitement des paramêtres
67
		$p = $this->traiterParametresUrl(array('id_projet', 'id_structure', 'recherche'), $param);
67
		$p = $this->traiterParametresUrl(array('id_projet', 'id_structure', 'recherche'), $param);
68
				 
68
				 
69
		// Construction de la requête
69
		// Construction de la requête
70
		$requete =	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' cs.*, csc.*, csv.*, '.
70
		$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 '.
71
					'	cmhl_date_modification, cmhl_notes, cmhl_source, cmhl_ce_modifier_par, cmhl_ce_etat, cmhl_ip '.
72
					'FROM coel_structure AS cs '.
72
					'FROM coel_structure AS cs '.
73
					'	LEFT JOIN coel_meta_historique_ligne ON (cs_ce_meta = cmhl_id_historique_ligne) '.
73
					'	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) '.
74
					'	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) '.
75
					'	LEFT JOIN coel_structure_valorisation AS csv ON (cs_id_structure = csv_id_structure) '.
76
					((count($p) != 0) ? 'WHERE ' : '').			
76
					((count($p) != 0) ? 'WHERE ' : '').			
77
					((isset($p['id_projet'])) ? "AND cs_ce_projet = {$p['id_projet']} " : '').
77
					((isset($p['id_projet'])) ? "AND cs_ce_projet = {$p['id_projet']} " : '').
78
					((isset($p['id_structure'])) ? "AND cs_id_structure = {$p['id_structure']} " : '').
78
					((isset($p['id_structure'])) ? "AND cs_id_structure = {$p['id_structure']} " : '').
79
					(isset($p['recherche']) ? $this->construireWhereRecherche($p['recherche']) : '').
79
					(isset($p['recherche']) ? $this->construireWhereRecherche($p['recherche']) : '').
80
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'cs.cs_nom ASC').' ';
80
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'cs.cs_nom ASC').' ';
81
		
81
		
82
		$requete = str_replace('WHERE AND', 'WHERE', $requete);
82
		$requete = str_replace('WHERE AND', 'WHERE', $requete);
83
		$requete_compte = $requete;
83
		$requete_compte = $requete;
84
		$requete .= "LIMIT $this->start, $this->limit ";
84
		$requete .= "LIMIT $this->start, $this->limit ";
85
 
85
 
86
		// Récupération des résultats
86
		// Récupération des résultats
87
		try {
87
		try {
88
			// SPÉCIAL :
88
			// SPÉCIAL :
89
			// Lorsqu'on cherche une seule structure avec un id passé en paramêtre, nous devons renvoyer un objet
89
			// 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);
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);
91
			if ($donnees === false) {
91
			if ($donnees === false) {
92
				$this->messages[] = "La requête a retourné aucun résultat.";
92
				$this->messages[] = "La requête a retourné aucun résultat.";
93
			}
93
			}
94
			
94
			
95
			$elements_nbre = $this->bdd->query($requete_compte)->rowCount();
95
			$elements_nbre = $this->bdd->query($requete_compte)->rowCount();
96
			$info['nbElements'] = $elements_nbre;
96
			$info['nbElements'] = $elements_nbre;
97
			$info['structures'] = $donnees;			
97
			$info['structures'] = $donnees;			
98
		} catch (PDOException $e) {
98
		} catch (PDOException $e) {
99
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
99
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
100
		}
100
		}
101
 
101
 
102
		return $info;
102
		return $info;
103
	}
103
	}
104
	
104
	
105
	private function construireWhereRecherche($recherche) {
105
	private function construireWhereRecherche($recherche) {
106
		$recherche = "AND ".
106
		$recherche = "AND ".
107
		"(".
107
		"(".
108
			"cs_nom LIKE {$recherche}  OR ".
108
			"cs_nom LIKE {$recherche}  OR ".
109
			"cs_ville LIKE {$recherche} ".
109
			"cs_ville LIKE {$recherche} ".
110
		")";
110
		")";
111
		return $recherche;
111
		return $recherche;
112
	}
112
	}
113
	
113
	
114
	/* Méthode pour récupérer le nombre de structure par zone géographique.
114
	/* Méthode pour récupérer le nombre de structure par zone géographique.
115
	 * Appelée avec les paramêtres d'url suivant :
115
	 * Appelée avec les paramêtres d'url suivant :
116
	 * /CoelStructure/ParZoneGeo/_
116
	 * /CoelStructure/ParZoneGeo/_
117
	 * ou les _ représentent dans l'ordre : type.
117
	 * ou les _ représentent dans l'ordre : type.
118
	 * ou type peut valoir: FRD (= département français) 
118
	 * ou type peut valoir: FRD (= département français) 
119
	 * Si un des paramêtres est abscent, il prendre la valeur *
119
	 * Si un des paramêtres est abscent, il prendre la valeur *
120
	 */
120
	 */
121
	public function getElementParZoneGeo($param) {
121
	public function getElementParZoneGeo($param) {
122
		// Initialisation des variables
122
		// Initialisation des variables
123
		$info = array();
123
		$info = array();
124
				
124
				
125
		// Pré traitement des paramêtres
125
		// Pré traitement des paramêtres
126
		$p = $this->traiterParametresUrl(array('type', 'projets'), $param);
126
		$p = $this->traiterParametresUrl(array('type', 'projets'), $param);
127
		if (!isset($p['type'])) {
127
		if (!isset($p['type'])) {
128
			$this->messages[] = "Il est obligatoire d'indiquer type de recherche pour utiliser ce service.";
128
			$this->messages[] = "Il est obligatoire d'indiquer type de recherche pour utiliser ce service.";
129
		} else {
129
		} else {
130
			// Construction de la requête
130
			// Construction de la requête
131
			$requete =	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
131
			$requete =	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
132
						'	IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
132
						'	IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
133
						'		SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
133
						'		SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
134
						'		SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) AS id, '.
134
						'		SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) AS id, '.
135
						'	COUNT( cs_id_structure ) AS nbre '.
135
						'	COUNT( cs_id_structure ) AS nbre '.
136
						'FROM coel_structure '.
136
						'FROM coel_structure '.
137
						'WHERE cs_ce_truk_pays = 2654 '.
137
						'WHERE cs_ce_truk_pays = 2654 '.
138
						(isset($p['projets']) ? "	AND cs_ce_projet IN ({$p['projets']}) " : '').
138
						(isset($p['projets']) ? "	AND cs_ce_projet IN ({$p['projets']}) " : '').
139
						'GROUP BY IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
139
						'GROUP BY IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
140
						'	SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
140
						'	SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
141
						'	SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) '.
141
						'	SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) '.
142
						'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'id ASC').' ';
142
						'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'id ASC').' ';
143
			// Récupération des résultats
143
			// Récupération des résultats
144
			try {
144
			try {
145
				$donnees = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
145
				$donnees = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
146
				if ($donnees === false) {
146
				if ($donnees === false) {
147
					$this->messages[] = "La requête a retourné aucun résultat.";
147
					$this->messages[] = "La requête a retourné aucun résultat.";
148
				} else {
148
				} else {
149
					foreach ($donnees as $donnee) {
149
					foreach ($donnees as $donnee) {
150
						$info[$donnee['id']] = $donnee['nbre'];
150
						$info[$donnee['id']] = $donnee['nbre'];
151
					}
151
					}
152
				}
152
				}
153
			} catch (PDOException $e) {
153
			} catch (PDOException $e) {
154
				$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
154
				$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
155
			}
155
			}
156
		}
156
		}
157
		return $info;
157
		return $info;
158
	}
158
	}
159
	
159
	
160
	/**
160
	/**
161
	 * Méthode appelée pour ajouter un élément.
161
	 * Méthode appelée pour ajouter un élément.
162
	 */
162
	 */
163
	public function createElement($params) {
163
	public function createElement($params) {
164
		// Identification de l'utilisateur
164
		// Identification de l'utilisateur
165
		list($id_utilisateur, $id_session) = $this->getIdentification($params);
165
		list($id_utilisateur, $id_session) = $this->getIdentification($params);
166
 
166
 
167
		// Contrôle du non détournement de l'utilisateur
167
		// Contrôle du non détournement de l'utilisateur
168
		if (!$this->etreAutorise($id_utilisateur)) {
168
		if (!$this->etreAutorise($id_utilisateur)) {
169
			$this->envoyer();
169
			$this->envoyer();
170
			return;
170
			return;
171
		}
171
		}
172
		try {
172
		try {
173
			// Vérification des tables à vraiment mettre à jour en fonction des données passées.
173
			// Vérification des tables à vraiment mettre à jour en fonction des données passées.
174
			if( (! @$params['cs_latitude'] || ! @$params['cs_longitude']) &&
174
			if( (! @$params['cs_latitude'] || ! @$params['cs_longitude']) &&
175
				(@$params['cs_adresse_01'] || @$params['cs_code_postal'] || @$params['cs_ville']) ) {
175
				(@$params['cs_adresse_01'] || @$params['cs_code_postal'] || @$params['cs_ville']) ) {
176
				$lonlat = array();
176
				$lonlat = array();
177
				if(Coel::coordGuess(Coel::addrReStruct($params), $lonlat)) {
177
				if(Coel::coordGuess(Coel::addrReStruct($params), $lonlat)) {
178
					$params['cs_latitude'] = $lonlat['lat'];
178
					$params['cs_latitude'] = $lonlat['lat'];
179
					$params['cs_longitude'] = $lonlat['lon'];
179
					$params['cs_longitude'] = $lonlat['lon'];
180
				}
180
				}
181
			}
181
			}
182
 
182
 
183
			$tables_a_modifier = $this->recupererTablesAModifier($params);
183
			$tables_a_modifier = $this->recupererTablesAModifier($params);
184
			reset($tables_a_modifier);
184
			reset($tables_a_modifier);
185
 
185
 
186
			$id_structure = null;
186
			$id_structure = null;
187
			while (list($table_id, $table) = each($tables_a_modifier)) {
187
			while (list($table_id, $table) = each($tables_a_modifier)) {
188
				if (is_null($table['champs'])) continue;
188
				if (is_null($table['champs'])) continue;
189
				if ($this->avoirCleComplete($table)) {
189
				if ($this->avoirCleComplete($table)) {
190
					$this->mettreAJourAvecCle($id_utilisateur, $id_session, $table_id, $table);
190
					$this->mettreAJourAvecCle($id_utilisateur, $id_session, $table_id, $table);
191
					continue;
191
					continue;
192
				}
192
				}
193
 
193
 
194
				// Ajout des données à la table des données
194
				// Ajout des données à la table des données
195
				$id_structure = $this->ajouter($table);
195
				$id_structure = $this->ajouter($table);
196
				if ($id_structure === false) continue;
196
				if ($id_structure === false) continue;
197
 
197
 
198
				$table['champs_valeurs_id']['cs_id_structure'] = $id_structure;
198
				$table['champs_valeurs_id']['cs_id_structure'] = $id_structure;
199
				$table['champs_valeurs_brut']['cs_id_structure'] = $id_structure;
199
				$table['champs_valeurs_brut']['cs_id_structure'] = $id_structure;
200
				$tables_a_modifier[122]['champs_valeurs_id']['csc_id_structure'] = $id_structure;
200
				$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;
201
				$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);
202
				$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;
203
				$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;
204
				$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);
205
				$tables_a_modifier[123]['champs_valeurs_protege']['csv_id_structure'] = $this->bdd->quote($id_structure);
206
 
206
 
207
				// Historisation (Ajout des méta-données)
207
				// Historisation (Ajout des méta-données)
208
				$etat = 1; // Ajout
208
				$etat = 1; // Ajout
209
				$cle = $this->recupererCle($table);
209
				$cle = $this->recupererCle($table);
210
				$info = $this->creerXmlHisto($table['champs_valeurs_brut']);
210
				$info = $this->creerXmlHisto($table['champs_valeurs_brut']);
211
				$id_meta = $this->historiser($table_id, $cle, $info, $id_utilisateur, $etat, $id_session);
211
				$id_meta = $this->historiser($table_id, $cle, $info, $id_utilisateur, $etat, $id_session);
212
								
212
								
213
				// Liaison de la table des données à ses méta-données
213
				// Liaison de la table des données à ses méta-données
214
				$champ_meta = "{$table['prefixe']}_ce_meta";
214
				$champ_meta = "{$table['prefixe']}_ce_meta";
215
				$table['champs_valeurs_protege'] = array($champ_meta => $id_meta);
215
				$table['champs_valeurs_protege'] = array($champ_meta => $id_meta);
216
				$this->modifier($table);
216
				$this->modifier($table);
217
			}
217
			}
218
 
218
 
219
			if(isset($params['cpr_abreviation']) && !empty($params['cpr_abreviation'])) {
219
			if(isset($params['cpr_abreviation']) && !empty($params['cpr_abreviation'])) {
220
				$this->ajouterGuid($params['cpr_abreviation'], $id_structure);
220
				$this->ajouterGuid($params['cpr_abreviation'], $id_structure);
221
			}
221
			}
222
		} catch (PDOException $e) {
222
		} catch (PDOException $e) {
223
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
223
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
224
		}
224
		}
225
		
225
		
226
		$this->envoyer($id_structure);
226
		$this->envoyer($id_structure);
227
	}
227
	}
228
	
228
	
229
	/**
229
	/**
230
	 * Méthode appelée pour mettre à jour un élément
230
	 * Méthode appelée pour mettre à jour un élément
231
	 */
231
	 */
232
	public function updateElement($uid, $params) {
232
	public function updateElement($uid, $params) {
233
		// Vérification de la présence des id passés par l'url
233
		// Vérification de la présence des id passés par l'url
234
		if (!isset($uid[0])) {
234
		if (!isset($uid[0])) {
235
			$this->messages[] = "Identifiant de structure manquant. Vous ne devriez pas avoir accès à ce service.";
235
			$this->messages[] = "Identifiant de structure manquant. Vous ne devriez pas avoir accès à ce service.";
236
			$this->envoyer();
236
			$this->envoyer();
237
			return;
237
			return;
238
		}
238
		}
239
 
239
 
240
		// Identification de l'utilisateur
240
		// Identification de l'utilisateur
241
		list($id_utilisateur, $id_session) = $this->getIdentification($params);
241
		list($id_utilisateur, $id_session) = $this->getIdentification($params);
242
		// Contrôle du non détournement de l'utilisateur
242
		// Contrôle du non détournement de l'utilisateur
243
		if (!$this->etreAutorise($id_utilisateur)) {
243
		if (!$this->etreAutorise($id_utilisateur)) {
244
			$this->envoyer();
244
			$this->envoyer();
245
			return;
245
			return;
246
		}
246
		}
247
		try {
247
		try {
248
			$form_needs_refresh = FALSE;
248
			$form_needs_refresh = FALSE;
249
			if( (! @$params['cs_latitude'] || ! @$params['cs_longitude']) &&
249
			if( (! @$params['cs_latitude'] || ! @$params['cs_longitude']) &&
250
				(@$params['cs_adresse_01'] || @$params['cs_code_postal'] || @$params['cs_ville']) ) {
250
				(@$params['cs_adresse_01'] || @$params['cs_code_postal'] || @$params['cs_ville']) ) {
251
				$lonlat = array();
251
				$lonlat = array();
252
				if(Coel::coordGuess(Coel::addrReStruct($params), $lonlat)) {
252
				if(Coel::coordGuess(Coel::addrReStruct($params), $lonlat)) {
253
					$params['cs_latitude'] = $lonlat['lat'];
253
					$params['cs_latitude'] = $lonlat['lat'];
254
					$params['cs_longitude'] = $lonlat['lon'];
254
					$params['cs_longitude'] = $lonlat['lon'];
255
					$form_needs_refresh = TRUE;
255
					$form_needs_refresh = TRUE;
256
				}
256
				}
257
			}
257
			}
258
 
258
 
259
			// Vérification des tables à vraiment mettre à jour en fonction des données passées.
259
			// Vérification des tables à vraiment mettre à jour en fonction des données passées.
260
			$tables_a_modifier = $this->recupererTablesAModifier($params);
260
			$tables_a_modifier = $this->recupererTablesAModifier($params);
261
					
261
					
262
			// Pour chaque table du module nous lançons si nécessaire l'historisation puis la mise à jour
262
			// 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) {
263
			foreach ($tables_a_modifier as $table_id => $table) {
264
				if(!$this->avoirCleComplete($table)) {
264
				if(@$table['nom'] == 'coel_structure' && !$this->avoirCleComplete($table)) {
265
					error_log("tentative d'UPDATE sans contrainte de WHERE, $table = " . print_r($table, TRUE));
265
					error_log("tentative d'UPDATE sans contrainte de WHERE, \$table = " . print_r($table, TRUE));
266
					continue; // ne pas mettre à jour sans contrainte de WHERE
266
					continue; // ne pas mettre à jour sans contrainte de WHERE
267
				}
267
				}
268
				$this->mettreAJourAvecCle($id_utilisateur, $id_session, $table_id, $table);
268
				$this->mettreAJourAvecCle($id_utilisateur, $id_session, $table_id, $table);
269
			}
269
			}
270
		} catch (PDOException $e) {
270
		} catch (PDOException $e) {
271
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
271
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
272
		}
272
		}
273
 
273
 
274
		// Envoie sur la sortie standard
274
		// Envoie sur la sortie standard
275
 
275
 
276
		if($form_needs_refresh) { // coordonnées mises à jour en DB: en informer le formulaire (si resté ouvert)
276
		if($form_needs_refresh) { // coordonnées mises à jour en DB: en informer le formulaire (si resté ouvert)
277
			// $this->envoyer('reload'); // TODO: handle this
277
			// $this->envoyer('reload'); // TODO: handle this
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
?>