Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 1649 Rev 1651
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;
-
 
249
			if( (! @$params['cs_latitude'] || ! @$params['cs_longitude']) &&
-
 
250
				(@$params['cs_adresse_01'] || @$params['cs_code_postal'] || @$params['cs_ville']) ) {
-
 
251
				$lonlat = array();
-
 
252
				if(Coel::coordGuess(Coel::addrReStruct($params), $lonlat)) {
-
 
253
					$params['cs_latitude'] = $lonlat['lat'];
-
 
254
					$params['cs_longitude'] = $lonlat['lon'];
-
 
255
					$form_needs_refresh = TRUE;
-
 
256
				}
-
 
257
			}
-
 
258
 
248
			// 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.
249
			$tables_a_modifier = $this->recupererTablesAModifier($params);
260
			$tables_a_modifier = $this->recupererTablesAModifier($params);
250
		   			
261
		   			
251
			// 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
252
			foreach ($tables_a_modifier as $table_id => $table) {
263
			foreach ($tables_a_modifier as $table_id => $table) {
253
				$this->mettreAJourAvecCle($id_utilisateur, $id_session, $table_id, $table);
264
				$this->mettreAJourAvecCle($id_utilisateur, $id_session, $table_id, $table);
254
			}
265
			}
255
		} catch (PDOException $e) {
266
		} catch (PDOException $e) {
256
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
267
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
257
		}
268
		}
258
				
269
 
259
		// Envoie sur la sortie standard
270
		// Envoie sur la sortie standard
-
 
271
 
-
 
272
		if($form_needs_refresh) { // coordonnées mises à jour en DB: en informer le formulaire (si resté ouvert)
-
 
273
			// $this->envoyer('reload'); // TODO: handle this
-
 
274
		}
260
		$this->envoyer();
275
		$this->envoyer(); // OK par défaut
261
	}
276
	}
262
	
277
	
263
	/**
278
	/**
264
	 * Méthode appelée pour supprimer un élément
279
	 * Méthode appelée pour supprimer un élément
265
	 */
280
	 */
266
	public function deleteElement($uid) {
281
	public function deleteElement($uid) {
267
	   	// NOTES : une structure ne peut pas être supprimée si elle possède des collections liées.
282
	   	// NOTES : une structure ne peut pas être supprimée si elle possède des collections liées.
268
		// Vérification de la présence des id passés par l'url
283
		// Vérification de la présence des id passés par l'url
269
		if (!isset($uid[0]) || !isset($uid[1])) {
284
		if (!isset($uid[0]) || !isset($uid[1])) {
270
				$this->messages[] = "Identifiant de structure ou d'utilisateur manquant. Vous ne devriez pas avoir accès à ce service.";
285
				$this->messages[] = "Identifiant de structure ou d'utilisateur manquant. Vous ne devriez pas avoir accès à ce service.";
271
		} else {
286
		} else {
272
			// Identification de l'utilisateur
287
			// Identification de l'utilisateur
273
			list($id_utilisateur, $id_session) = $this->getIdentification($uid[0]);
288
			list($id_utilisateur, $id_session) = $this->getIdentification($uid[0]);
274
		
289
		
275
			// Contrôle du non détournement de l'utilisateur		
290
			// Contrôle du non détournement de l'utilisateur		
276
			if ($this->etreAutorise($id_utilisateur)) {    	  
291
			if ($this->etreAutorise($id_utilisateur)) {    	  
277
				// Récupération des id passés par l'url
292
				// Récupération des id passés par l'url
278
				$identifiants = explode(',', rtrim($uid[1], ','));
293
				$identifiants = explode(',', rtrim($uid[1], ','));
279
	
294
	
280
		   		try {
295
		   		try {
281
		   			if (count($identifiants) == 0) {
296
		   			if (count($identifiants) == 0) {
282
		   				$this->messages[] = "Aucun enregistrement n'a été supprimé.";
297
		   				$this->messages[] = "Aucun enregistrement n'a été supprimé.";
283
		   			} else {
298
		   			} else {
284
			   			foreach ($identifiants as $id_structure) {
299
			   			foreach ($identifiants as $id_structure) {
285
				   			// Vérification que la structure ne possède pas de collections liées
300
				   			// Vérification que la structure ne possède pas de collections liées
286
							if ($this->verifierPresenceCollection($id_structure) === false) {
301
							if ($this->verifierPresenceCollection($id_structure) === false) {
287
								$params = array('cs_id_structure' => $id_structure, 'csc_id_structure' => $id_structure, 'csv_id_structure' => $id_structure);
302
								$params = array('cs_id_structure' => $id_structure, 'csc_id_structure' => $id_structure, 'csv_id_structure' => $id_structure);
288
								$tables_a_modifier = $this->recupererTablesAModifier($params);
303
								$tables_a_modifier = $this->recupererTablesAModifier($params);
289
								
304
								
290
								foreach ($tables_a_modifier as $table_id => $table) {
305
								foreach ($tables_a_modifier as $table_id => $table) {
291
						   			if ($this->avoirEnregistrement($table)) {
306
						   			if ($this->avoirEnregistrement($table)) {
292
						   				$resultat = $this->supprimer($table);
307
						   				$resultat = $this->supprimer($table);
293
										if ($resultat === true) {
308
										if ($resultat === true) {
294
											// Historisation (Ajout des méta-données)
309
											// Historisation (Ajout des méta-données)
295
											$cle = $this->recupererCle($table);
310
											$cle = $this->recupererCle($table);
296
											$this->historiser($table_id, $cle, 'NULL', $id_utilisateur, 3, $id_session);
311
											$this->historiser($table_id, $cle, 'NULL', $id_utilisateur, 3, $id_session);
297
										}
312
										}
298
						   			}
313
						   			}
299
					   			}
314
					   			}
300
							} else {
315
							} else {
301
								$this->messages[] = "La structure '$id_structure' ne peut pas être supprimée car elle possède des collections liées.";
316
								$this->messages[] = "La structure '$id_structure' ne peut pas être supprimée car elle possède des collections liées.";
302
							}
317
							}
303
			   			}
318
			   			}
304
		   			}
319
		   			}
305
			   	} catch (PDOException $e) {
320
			   	} catch (PDOException $e) {
306
					$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
321
					$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
307
				}
322
				}
308
		   	}
323
		   	}
309
		}
324
		}
310
 
325
 
311
		// Envoie sur la sortie standard
326
		// Envoie sur la sortie standard
312
		$this->envoyer();
327
		$this->envoyer();
313
	}
328
	}
314
	
329
	
315
	private function verifierPresenceCollection($id_structure) {
330
	private function verifierPresenceCollection($id_structure) {
316
		$requete = 	'SELECT COUNT(cc_id_collection) AS nbre_collection '.
331
		$requete = 	'SELECT COUNT(cc_id_collection) AS nbre_collection '.
317
					'FROM coel_collection '.
332
					'FROM coel_collection '.
318
					"WHERE cc_ce_structure = '$id_structure' ".
333
					"WHERE cc_ce_structure = '$id_structure' ".
319
	   				'GROUP BY cc_ce_structure ';
334
	   				'GROUP BY cc_ce_structure ';
320
	   	
335
	   	
321
		// Vérification que la structure ne possède pas de collections liées
336
		// Vérification que la structure ne possède pas de collections liées
322
		$nbre_collection = $this->bdd->query($requete)->fetchColumn();
337
		$nbre_collection = $this->bdd->query($requete)->fetchColumn();
323
		
338
		
324
		$presence = false;
339
		$presence = false;
325
		if ($nbre_collection != 0) {
340
		if ($nbre_collection != 0) {
326
			$presence = true;
341
			$presence = true;
327
		}
342
		}
328
		return $presence;
343
		return $presence;
329
	}
344
	}
330
	
345
	
331
	private function ajouterGuid($abr_projet, $id_structure) {
346
	private function ajouterGuid($abr_projet, $id_structure) {
332
		if ($id_structure !== false) {
347
		if ($id_structure !== false) {
333
			$table_guid = $this->tables[120];
348
			$table_guid = $this->tables[120];
334
			$table_guid['champs_valeurs_id']['cs_id_structure'] = $id_structure;
349
			$table_guid['champs_valeurs_id']['cs_id_structure'] = $id_structure;
335
			$table_guid['champs_valeurs_protege']['cs_guid'] = $this->bdd->quote(sprintf($this->config['coel']['guid'], $abr_projet, 'str'.$id_structure));
350
			$table_guid['champs_valeurs_protege']['cs_guid'] = $this->bdd->quote(sprintf($this->config['coel']['guid'], $abr_projet, 'str'.$id_structure));
336
			$this->modifier($table_guid);
351
			$this->modifier($table_guid);
337
		}
352
		}
338
	}
353
	}
339
}
354
}
340
?>
355
?>