| Line 1... |
Line 1... |
| 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
|
- |
|
| 5 |
* Encodage en sortie : utf8
|
- |
|
| 6 |
*
|
4 |
*
|
| - |
|
5 |
* @author Raphaël Droz <raphael@tela-botanica.org>
|
| 7 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
6 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
| - |
|
7 |
* @Copyright (c) 2009, 2013 Tela Botanica (accueil@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$
|
- |
|
| 11 |
* @copyright 2009
|
- |
|
| 12 |
*/
|
10 |
*/
|
| 13 |
class CoelStructure extends Coel {
|
11 |
class CoelStructure extends Coel {
|
| Line 14... |
Line 12... |
| 14 |
|
12 |
|
| 15 |
static $optional_bool_fields = array(
|
13 |
static $optional_bool_fields = array(
|
| 16 |
'cs_nbre_personne',
|
14 |
'cs_nbre_personne',
|
| 17 |
'csc_mark_formation', 'csc_mark_formation_interet',
|
15 |
'csc_mark_formation', 'csc_mark_formation_interet',
|
| 18 |
/*'csc_mark_collection_commune',*/ 'csc_mark_acces_controle', 'csc_mark_restauration', 'csc_mark_traitement',
|
16 |
/*'csc_mark_collection_commune',*/ 'csc_mark_acces_controle', 'csc_mark_restauration', 'csc_mark_traitement',
|
| - |
|
17 |
'csc_mark_acquisition_collection', 'csc_mark_acquisition_echantillon',
|
| 19 |
'csc_mark_acquisition_collection', 'csc_mark_acquisition_echantillon'
|
18 |
'cs_latitude', 'cs_longitude',
|
| Line 20... |
Line 19... |
| 20 |
);
|
19 |
);
|
| 21 |
|
20 |
|
| 22 |
// ATTENTION : tjrs garder la table principale en premier, puis mettre les tables spécialisées.
|
21 |
// ATTENTION : tjrs garder la table principale en premier, puis mettre les tables spécialisées.
|
| 23 |
protected $tables = array( 120 => array(
|
22 |
static $tables = array( 120 => array(
|
| 24 |
'nom' => 'coel_structure',
|
23 |
'nom' => 'coel_structure',
|
| 25 |
'prefixe' => 'cs',
|
24 |
'prefixe' => 'cs',
|
| 26 |
'id' => array('cs_id_structure')),
|
25 |
'id' => array('cs_id_structure')),
|
| 27 |
122 => array(
|
26 |
122 => array(
|
| 28 |
'nom' => 'coel_structure_conservation',
|
27 |
'nom' => 'coel_structure_conservation',
|
| 29 |
'prefixe' => 'csc',
|
28 |
'prefixe' => 'csc',
|
| 30 |
'id' => array('csc_id_structure')),
|
29 |
'id' => array('csc_id_structure')),
|
| 31 |
123 => array(
|
30 |
123 => array(
|
| 32 |
'nom' => 'coel_structure_valorisation',
|
31 |
'nom' => 'coel_structure_valorisation',
|
| Line 33... |
Line 32... |
| 33 |
'prefixe' => 'csv',
|
32 |
'prefixe' => 'csv',
|
| 34 |
'id' => array('csv_id_structure')));
|
33 |
'id' => array('csv_id_structure')));
|
| 35 |
|
34 |
|
| 36 |
/**
|
35 |
/**
|
| Line 70... |
Line 69... |
| 70 |
*/
|
69 |
*/
|
| 71 |
public function getElementParDefaut($p) {
|
70 |
public function getElementParDefaut($p) {
|
| 72 |
// Initialisation des variables
|
71 |
// Initialisation des variables
|
| 73 |
$info = array();
|
72 |
$info = array();
|
| Line 74... |
Line 73... |
| 74 |
|
73 |
|
| 75 |
$whereClause = array();
|
74 |
$whereClause = array();
|
| 76 |
if(isset($p['id_projet'])) $whereClause[] = "cs_ce_projet = {$p['id_projet']}";
|
75 |
if(isset($p['id_projet'])) $whereClause[] = "cs_ce_projet = {$p['id_projet']}";
|
| 77 |
if(isset($p['id_structure'])) $whereClause[] = "cs_id_structure = {$p['id_structure']}";
|
76 |
if(isset($p['id_structure'])) $whereClause[] = "cs_id_structure = {$p['id_structure']}";
|
| 78 |
|
77 |
|
| 79 |
if(isset($p['recherche'])) {
|
78 |
if(isset($p['recherche'])) {
|
| 80 |
if(@$this->searchCity && trim($this->searchCity) == true) {
|
79 |
if(@$this->searchCity && trim($this->searchCity) == true) {
|
| 81 |
$whereClause[] = "(" . implode(" OR ", array("cs_nom LIKE {$p['recherche']}", "cs_ville LIKE {$p['recherche']}")) . ")";
|
80 |
$whereClause[] = "(" . implode(" OR ", array("cs_nom LIKE {$p['recherche']}", "cs_ville LIKE {$p['recherche']}")) . ")";
|
| 82 |
} else {
|
81 |
} else {
|
| 83 |
$whereClause[] = "cs_nom LIKE {$p['recherche']}";
|
82 |
$whereClause[] = "cs_nom LIKE {$p['recherche']}";
|
| 84 |
}
|
83 |
}
|
| Line 85... |
Line 84... |
| 85 |
}
|
84 |
}
|
| 86 |
|
85 |
|
| 87 |
// Construction de la requête
|
86 |
// Construction de la requête
|
| 88 |
$requete = sprintf(
|
87 |
$requete = sprintf(
|
| 89 |
'SELECT SQL_CALC_FOUND_ROWS %s cs.*, csc.*, csv.*, cmhl_date_modification, cmhl_notes, cmhl_source, cmhl_ce_modifier_par, cmhl_ce_etat, cmhl_ip '
|
88 |
'SELECT SQL_CALC_FOUND_ROWS %s cs.*, csc.*, csv.*, cmhl_date_modification, cmhl_notes, cmhl_source, cmhl_ce_modifier_par, cmhl_ce_etat, cmhl_ip '
|
| 90 |
. ' FROM coel_structure AS cs '
|
89 |
. ' FROM coel_structure AS cs '
|
| 91 |
. ' LEFT JOIN coel_meta_historique_ligne ON (cs_ce_meta = cmhl_id_historique_ligne) '
|
90 |
. ' LEFT JOIN coel_meta_historique_ligne ON (cs_ce_meta = cmhl_id_historique_ligne) '
|
| 92 |
. ' LEFT JOIN coel_structure_conservation AS csc ON (cs_id_structure = csc_id_structure) '
|
91 |
. ' LEFT JOIN coel_structure_conservation AS csc ON (cs_id_structure = csc_id_structure) '
|
| 93 |
. ' LEFT JOIN coel_structure_valorisation AS csv ON (cs_id_structure = csv_id_structure) '
|
92 |
. ' LEFT JOIN coel_structure_valorisation AS csv ON (cs_id_structure = csv_id_structure) '
|
| 94 |
. ' WHERE %s ORDER BY %s LIMIT %d, %d -- %s:%d',
|
93 |
. ' WHERE %s ORDER BY %s LIMIT %d, %d -- %s:%d',
|
| 95 |
|
94 |
|
| 96 |
$this->distinct ? 'DISTINCT' : '',
|
95 |
$this->distinct ? 'DISTINCT' : '',
|
| 97 |
$whereClause ? implode(" AND ", $whereClause) : TRUE,
|
96 |
$whereClause ? implode(" AND ", $whereClause) : TRUE,
|
| 98 |
is_null($this->orderby) ? 'cs.cs_nom ASC' : $this->orderby,
|
97 |
is_null($this->orderby) ? 'cs.cs_nom ASC' : $this->orderby,
|
| Line 99... |
Line 98... |
| 99 |
$this->start, $this->limit,
|
98 |
$this->start, $this->limit,
|
| 100 |
__FILE__, __LINE__);
|
99 |
__FILE__, __LINE__);
|
| 101 |
|
100 |
|
| 102 |
// Récupération des résultats
|
101 |
// Récupération des résultats
|
| 103 |
try {
|
102 |
try {
|
| 104 |
// SPÉCIAL :
|
103 |
// SPÉCIAL :
|
| 105 |
// Lorsqu'on cherche une seule structure avec un id passé en paramêtre, nous devons renvoyer un objet
|
104 |
// Lorsqu'on cherche une seule structure avec un id passé en paramêtre, nous devons renvoyer un objet
|
| 106 |
$donnees = ($this->formatRetour == 'objet' && isset($p['id_structure'])) ? $this->bdd->query($requete)->fetch(PDO::FETCH_OBJ) : $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
|
105 |
$donnees = ($this->formatRetour == 'objet' && isset($p['id_structure'])) ? $this->bdd->query($requete)->fetch(PDO::FETCH_OBJ) : $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
|
| Line 107... |
Line 106... |
| 107 |
if ($donnees === false) {
|
106 |
if ($donnees === false) {
|
| 108 |
$this->messages[] = "La requête a retourné aucun résultat.";
|
107 |
$this->messages[] = "La requête a retourné aucun résultat.";
|
| 109 |
}
|
108 |
}
|
| 110 |
|
109 |
|
| 111 |
// l'UI java n'aime pas les NULL
|
110 |
// l'UI java n'aime pas les NULL
|
| 112 |
if(!is_array($donnees)) {
|
111 |
if(!is_array($donnees)) {
|
| 113 |
// $donnees est un objet PHP
|
112 |
// $donnees est un objet PHP
|
| 114 |
array_walk($donnees, create_function('&$val', '$val = is_null($val) ? "" : $val;'));
|
113 |
array_walk($donnees, create_function('&$val', '$val = is_null($val) ? "" : $val;'));
|
| 115 |
}
|
114 |
}
|
| 116 |
else {
|
115 |
else {
|
| 117 |
// $donnees est un tableau d'objets PHP
|
116 |
// $donnees est un tableau d'objets PHP
|
| Line 118... |
Line 117... |
| 118 |
foreach($donnees as &$structure) {
|
117 |
foreach($donnees as &$structure) {
|
| 119 |
array_walk($structure, create_function('&$val', '$val = is_null($val) ? "" : $val;'));
|
118 |
array_walk($structure, create_function('&$val', '$val = is_null($val) ? "" : $val;'));
|
| 120 |
}
|
119 |
}
|
| 121 |
}
|
120 |
}
|
| Line 136... |
Line 135... |
| 136 |
* ou les _ représentent dans l'ordre : type.
|
135 |
* ou les _ représentent dans l'ordre : type.
|
| 137 |
* ou type peut valoir: FRD (= département français)
|
136 |
* ou type peut valoir: FRD (= département français)
|
| 138 |
* Si un des paramêtres est abscent, il prendre la valeur *
|
137 |
* Si un des paramêtres est abscent, il prendre la valeur *
|
| 139 |
*/
|
138 |
*/
|
| 140 |
public function getElementParZoneGeo($param) {
|
139 |
public function getElementParZoneGeo($param) {
|
| 141 |
// Initialisation des variables
|
- |
|
| 142 |
$info = array();
|
- |
|
| 143 |
|
- |
|
| 144 |
// Pré traitement des paramêtres
|
140 |
// Pré traitement des paramêtres
|
| 145 |
$p = $this->traiterParametresUrl(array('type', 'projets'), $param);
|
141 |
$p = $this->traiterParametresUrl(array('type', 'projets'), $param);
|
| 146 |
if (!isset($p['type'])) {
|
142 |
if (!isset($p['type'])) {
|
| 147 |
$this->messages[] = "Il est obligatoire d'indiquer type de recherche pour utiliser ce service.";
|
143 |
$this->messages[] = "Il est obligatoire d'indiquer type de recherche pour utiliser ce service.";
|
| 148 |
} else {
|
- |
|
| 149 |
// Construction de la requête
|
- |
|
| 150 |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
|
- |
|
| 151 |
' IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
|
- |
|
| 152 |
' SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
|
- |
|
| 153 |
' SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) AS id, '.
|
- |
|
| 154 |
' COUNT( cs_id_structure ) AS nbre '.
|
- |
|
| 155 |
'FROM coel_structure '.
|
- |
|
| 156 |
'WHERE cs_ce_truk_pays = 2654 '.
|
- |
|
| 157 |
(isset($p['projets']) ? " AND cs_ce_projet IN ({$p['projets']}) " : '').
|
- |
|
| 158 |
'GROUP BY IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
|
- |
|
| 159 |
' SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
|
- |
|
| 160 |
' SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) '.
|
- |
|
| 161 |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'id ASC').' ';
|
- |
|
| 162 |
// Récupération des résultats
|
- |
|
| 163 |
try {
|
- |
|
| 164 |
$donnees = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
|
- |
|
| 165 |
if ($donnees === false) {
|
144 |
return array();
|
| 166 |
$this->messages[] = "La requête a retourné aucun résultat.";
|
- |
|
| 167 |
} else {
|
- |
|
| 168 |
foreach ($donnees as $donnee) {
|
- |
|
| 169 |
$info[$donnee['id']] = $donnee['nbre'];
|
- |
|
| 170 |
}
|
- |
|
| 171 |
}
|
- |
|
| 172 |
} catch (PDOException $e) {
|
- |
|
| 173 |
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
|
- |
|
| 174 |
}
|
- |
|
| 175 |
}
|
145 |
}
|
| 176 |
return $info;
|
- |
|
| 177 |
}
|
- |
|
| Line -... |
Line 146... |
| - |
|
146 |
|
| - |
|
147 |
// Construction de la requête
|
| - |
|
148 |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
|
| - |
|
149 |
' IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
|
| - |
|
150 |
' SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
|
| - |
|
151 |
' SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) AS id, '.
|
| - |
|
152 |
' COUNT( cs_id_structure ) AS nbre '.
|
| - |
|
153 |
'FROM coel_structure '.
|
| - |
|
154 |
'WHERE cs_ce_truk_pays = 2654 '.
|
| - |
|
155 |
(isset($p['projets']) ? " AND cs_ce_projet IN ({$p['projets']}) " : '').
|
| - |
|
156 |
'GROUP BY IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
|
| - |
|
157 |
' SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
|
| - |
|
158 |
' SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) '.
|
| Line 178... |
Line 159... |
| 178 |
|
159 |
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'id ASC').' ';
|
| 179 |
|
160 |
|
| 180 |
static function NULLifNotNum(&$params, $keys_to_null) {
|
161 |
// Récupération des résultats
|
| 181 |
foreach($keys_to_null as $v) {
|
162 |
try {
|
| - |
|
163 |
$donnees = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
|
| 182 |
if(array_key_exists($v, $params) && !is_numeric($params[$v])) {
|
164 |
} catch (PDOException $e) {
|
| - |
|
165 |
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
|
| - |
|
166 |
}
|
| - |
|
167 |
|
| - |
|
168 |
if ($donnees === false) {
|
| 183 |
$params[$v] = NULL;
|
169 |
$this->messages[] = "La requête a retourné aucun résultat.";
|
| - |
|
170 |
return array();
|
| - |
|
171 |
}
|
| - |
|
172 |
|
| - |
|
173 |
$info = array();
|
| - |
|
174 |
foreach ($donnees as $donnee) {
|
| - |
|
175 |
$info[$donnee['id']] = $donnee['nbre'];
|
| 184 |
}
|
176 |
}
|
| - |
|
177 |
return $info;
|
| - |
|
178 |
}
|
| - |
|
179 |
|
| - |
|
180 |
|
| - |
|
181 |
static function NULLifNotNum(&$params, $keys_to_null) {
|
| - |
|
182 |
foreach($keys_to_null as $v) {
|
| - |
|
183 |
if(array_key_exists($v, $params) && !is_numeric($params[$v])) {
|
| - |
|
184 |
$params[$v] = NULL;
|
| - |
|
185 |
}
|
| Line 185... |
Line 186... |
| 185 |
}
|
186 |
}
|
| 186 |
}
|
187 |
}
|
| 187 |
|
188 |
|
| 188 |
/**
|
189 |
/**
|
| Line 196... |
Line 197... |
| 196 |
if (!$this->etreAutorise($id_utilisateur)) {
|
197 |
if (!$this->etreAutorise($id_utilisateur)) {
|
| 197 |
$this->envoyer();
|
198 |
$this->envoyer();
|
| 198 |
return;
|
199 |
return;
|
| 199 |
}
|
200 |
}
|
| 200 |
try {
|
201 |
try {
|
| 201 |
// Vérification des tables à vraiment mettre à jour en fonction des données passées.
|
- |
|
| 202 |
if( (! @$params['cs_latitude'] || ! @$params['cs_longitude']) &&
|
- |
|
| 203 |
(@$params['cs_adresse_01'] || @$params['cs_code_postal'] || @$params['cs_ville']) ) {
|
- |
|
| 204 |
$lonlat = array();
|
- |
|
| 205 |
if(Coel::coordGuess(Coel::addrReStruct($params), $lonlat)) {
|
202 |
$form_needs_refresh = self::callNominatim($params);
|
| 206 |
$params['cs_latitude'] = $lonlat['lat'];
|
- |
|
| 207 |
$params['cs_longitude'] = $lonlat['lon'];
|
- |
|
| 208 |
}
|
- |
|
| 209 |
}
|
- |
|
| Line 210... |
Line 203... |
| 210 |
|
203 |
|
| Line -... |
Line 204... |
| - |
|
204 |
self::NULLifNotNum($params, self::$optional_bool_fields);
|
| 211 |
self::NULLifNotNum($params, self::$optional_bool_fields);
|
205 |
|
| 212 |
|
206 |
// Vérification des tables à vraiment mettre à jour en fonction des données passées.
|
| Line 213... |
Line 207... |
| 213 |
$tables_a_modifier = $this->recupererTablesAModifier($params);
|
207 |
$tables_a_modifier = $this->recupererTablesAModifier($params);
|
| 214 |
reset($tables_a_modifier);
|
208 |
reset($tables_a_modifier);
|
| Line 253... |
Line 247... |
| 253 |
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
|
247 |
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
|
| 254 |
}
|
248 |
}
|
| Line 255... |
Line 249... |
| 255 |
|
249 |
|
| 256 |
$this->envoyer($id_structure);
|
250 |
$this->envoyer($id_structure);
|
| 257 |
}
|
251 |
}
|
| 258 |
|
252 |
|
| 259 |
/**
|
253 |
/**
|
| 260 |
* Méthode appelée pour mettre à jour un élément
|
254 |
* Méthode appelée pour mettre à jour un élément
|
| 261 |
*/
|
255 |
*/
|
| 262 |
public function updateElement($uid, $params) {
|
256 |
public function updateElement($uid, $params) {
|
| Line 273... |
Line 267... |
| 273 |
if (!$this->etreAutorise($id_utilisateur)) {
|
267 |
if (!$this->etreAutorise($id_utilisateur)) {
|
| 274 |
$this->envoyer();
|
268 |
$this->envoyer();
|
| 275 |
return;
|
269 |
return;
|
| 276 |
}
|
270 |
}
|
| 277 |
try {
|
271 |
try {
|
| 278 |
$form_needs_refresh = FALSE;
|
272 |
$form_needs_refresh = self::callNominatim($params);
|
| 279 |
if( (! @$params['cs_latitude'] || ! @$params['cs_longitude']) &&
|
- |
|
| 280 |
(@$params['cs_adresse_01'] || @$params['cs_code_postal'] || @$params['cs_ville']) ) {
|
- |
|
| 281 |
$lonlat = array();
|
- |
|
| 282 |
if(Coel::coordGuess(Coel::addrReStruct($params), $lonlat)) {
|
- |
|
| 283 |
$params['cs_latitude'] = $lonlat['lat'];
|
- |
|
| 284 |
$params['cs_longitude'] = $lonlat['lon'];
|
- |
|
| 285 |
$form_needs_refresh = TRUE;
|
- |
|
| 286 |
}
|
- |
|
| 287 |
}
|
- |
|
| Line 288... |
Line 273... |
| 288 |
|
273 |
|
| Line 289... |
Line 274... |
| 289 |
self::NULLifNotNum($params, self::$optional_bool_fields);
|
274 |
self::NULLifNotNum($params, self::$optional_bool_fields);
|
| 290 |
|
275 |
|
| 291 |
// Vérification des tables à vraiment mettre à jour en fonction des données passées.
|
276 |
// Vérification des tables à vraiment mettre à jour en fonction des données passées.
|
| 292 |
$tables_a_modifier = $this->recupererTablesAModifier($params);
|
277 |
$tables_a_modifier = $this->recupererTablesAModifier($params);
|
| Line 316... |
Line 301... |
| 316 |
*/
|
301 |
*/
|
| 317 |
public function deleteElement($uid) {
|
302 |
public function deleteElement($uid) {
|
| 318 |
// NOTES : une structure ne peut pas être supprimée si elle possède des collections liées.
|
303 |
// NOTES : une structure ne peut pas être supprimée si elle possède des collections liées.
|
| 319 |
// Vérification de la présence des id passés par l'url
|
304 |
// Vérification de la présence des id passés par l'url
|
| 320 |
if (!isset($uid[0]) || !isset($uid[1])) {
|
305 |
if (!isset($uid[0]) || !isset($uid[1])) {
|
| 321 |
$this->messages[] = "Identifiant de structure ou d'utilisateur manquant. Vous ne devriez pas avoir accès à ce service.";
|
306 |
$this->messages[] = "Identifiant de structure ou d'utilisateur manquant. Vous ne devriez pas avoir accès à ce service.";
|
| - |
|
307 |
$this->envoyer();
|
| - |
|
308 |
return;
|
| 322 |
} else {
|
309 |
}
|
| - |
|
310 |
|
| 323 |
// Identification de l'utilisateur
|
311 |
// Identification de l'utilisateur
|
| 324 |
list($id_utilisateur, $id_session) = $this->getIdentification($uid[0]);
|
312 |
list($id_utilisateur, $id_session) = $this->getIdentification($uid[0]);
|
| 325 |
|
- |
|
| 326 |
// Contrôle du non détournement de l'utilisateur
|
313 |
// Contrôle du non détournement de l'utilisateur
|
| 327 |
if ($this->etreAutorise($id_utilisateur)) {
|
314 |
if (! $this->etreAutorise($id_utilisateur)) {
|
| - |
|
315 |
$this->envoyer();
|
| - |
|
316 |
return;
|
| - |
|
317 |
}
|
| - |
|
318 |
|
| 328 |
// Récupération des id passés par l'url
|
319 |
// Récupération des id passés par l'url
|
| 329 |
$identifiants = explode(',', rtrim($uid[1], ','));
|
320 |
$identifiants = explode(',', rtrim($uid[1], ','));
|
| - |
|
321 |
|
| - |
|
322 |
if (count($identifiants) == 0) {
|
| - |
|
323 |
$this->messages[] = "Aucun enregistrement n'a été supprimé.";
|
| - |
|
324 |
$this->envoyer();
|
| - |
|
325 |
return;
|
| - |
|
326 |
}
|
| Line 330... |
Line 327... |
| 330 |
|
327 |
|
| 331 |
try {
|
- |
|
| 332 |
if (count($identifiants) == 0) {
|
- |
|
| 333 |
$this->messages[] = "Aucun enregistrement n'a été supprimé.";
|
- |
|
| 334 |
} else {
|
328 |
try {
|
| 335 |
foreach ($identifiants as $id_structure) {
|
329 |
foreach ($identifiants as $id_structure) {
|
| 336 |
// Vérification que la structure ne possède pas de collections liées
|
330 |
// Vérification que la structure ne possède pas de collections liées
|
| - |
|
331 |
if (self::verifierPresenceCollection($this->bdd, $id_structure)) {
|
| - |
|
332 |
$this->messages[] = "La structure '$id_structure' ne peut pas être supprimée car elle possède des collections liées.";
|
| - |
|
333 |
continue;
|
| - |
|
334 |
}
|
| 337 |
if ($this->verifierPresenceCollection($id_structure) === false) {
|
335 |
|
| 338 |
$params = array('cs_id_structure' => $id_structure, 'csc_id_structure' => $id_structure, 'csv_id_structure' => $id_structure);
|
336 |
$params = array('cs_id_structure' => $id_structure, 'csc_id_structure' => $id_structure, 'csv_id_structure' => $id_structure);
|
| Line 339... |
Line 337... |
| 339 |
$tables_a_modifier = $this->recupererTablesAModifier($params);
|
337 |
$tables_a_modifier = $this->recupererTablesAModifier($params);
|
| 340 |
|
338 |
|
| - |
|
339 |
foreach ($tables_a_modifier as $table_id => $table) {
|
| 341 |
foreach ($tables_a_modifier as $table_id => $table) {
|
340 |
if (! $this->avoirEnregistrement($table)) continue;
|
| 342 |
if ($this->avoirEnregistrement($table)) {
|
- |
|
| 343 |
$resultat = $this->supprimer($table);
|
341 |
|
| 344 |
if ($resultat === true) {
|
342 |
if ($this->supprimer($table) === true) {
|
| 345 |
// Historisation (Ajout des méta-données)
|
343 |
// Historisation (Ajout des méta-données)
|
| 346 |
$cle = $this->recupererCle($table);
|
344 |
$cle = $this->recupererCle($table);
|
| 347 |
$this->historiser($table_id, $cle, 'NULL', $id_utilisateur, 3, $id_session);
|
- |
|
| 348 |
}
|
- |
|
| 349 |
}
|
345 |
$this->historiser($table_id, $cle, 'NULL', $id_utilisateur, 3, $id_session);
|
| 350 |
}
|
- |
|
| 351 |
} else {
|
346 |
}
|
| 352 |
$this->messages[] = "La structure '$id_structure' ne peut pas être supprimée car elle possède des collections liées.";
|
- |
|
| 353 |
}
|
- |
|
| 354 |
}
|
347 |
}
|
| 355 |
}
|
348 |
}
|
| 356 |
} catch (PDOException $e) {
|
349 |
} catch (PDOException $e) {
|
| 357 |
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
|
- |
|
| 358 |
}
|
- |
|
| Line 359... |
Line 350... |
| 359 |
}
|
350 |
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
|
| 360 |
}
|
351 |
}
|
| 361 |
|
352 |
|
| Line 362... |
Line 353... |
| 362 |
// Envoie sur la sortie standard
|
353 |
// Envoie sur la sortie standard
|
| 363 |
$this->envoyer();
|
- |
|
| 364 |
}
|
- |
|
| 365 |
|
- |
|
| 366 |
private function verifierPresenceCollection($id_structure) {
|
- |
|
| 367 |
$requete = 'SELECT COUNT(cc_id_collection) AS nbre_collection '.
|
- |
|
| 368 |
'FROM coel_collection '.
|
354 |
$this->envoyer();
|
| - |
|
355 |
}
|
| - |
|
356 |
|
| - |
|
357 |
static function verifierPresenceCollection($db, $id_structure) {
|
| 369 |
"WHERE cc_ce_structure = '$id_structure' ".
|
358 |
// Vérification que la structure ne possède pas de collections liées
|
| - |
|
359 |
return ($db->query(sprintf(
|
| 370 |
'GROUP BY cc_ce_structure ';
|
360 |
'SELECT COUNT(cc_id_collection) AS nbre_collection FROM coel_collection ' .
|
| - |
|
361 |
' WHERE cc_ce_structure = %d GROUP BY cc_ce_structure ',
|
| - |
|
362 |
$id_structure))->fetchColumn() != 0);
|
| - |
|
363 |
}
|
| 371 |
|
364 |
|
| - |
|
365 |
static function callNominatim(&$params) {
|
| 372 |
// Vérification que la structure ne possède pas de collections liées
|
366 |
if ( (! @$params['cs_latitude'] || ! @$params['cs_longitude']) &&
|
| - |
|
367 |
(@$params['cs_adresse_01'] || @$params['cs_code_postal'] || @$params['cs_ville']) ) {
|
| 373 |
$nbre_collection = $this->bdd->query($requete)->fetchColumn();
|
368 |
$lonlat = array();
|
| - |
|
369 |
if(Coel::coordGuess(Coel::addrReStruct($params), $lonlat)) {
|
| 374 |
|
370 |
$params['cs_latitude'] = $lonlat['lat'];
|
| 375 |
$presence = false;
|
371 |
$params['cs_longitude'] = $lonlat['lon'];
|
| 376 |
if ($nbre_collection != 0) {
|
372 |
$form_needs_refresh = TRUE;
|
| Line 377... |
Line 373... |
| 377 |
$presence = true;
|
373 |
}
|
| 378 |
}
|
374 |
}
|
| 379 |
return $presence;
|
375 |
return FALSE;
|
| 380 |
}
|
376 |
}
|
| 381 |
|
377 |
|
| 382 |
private function ajouterGuid($abr_projet, $id_structure) {
|
378 |
private function ajouterGuid($abr_projet, $id_structure) {
|
| 383 |
if ($id_structure !== false) {
|
379 |
if ($id_structure !== false) {
|
| 384 |
$table_guid = $this->tables[120];
|
380 |
$table_guid = self::$tables[120];
|
| 385 |
$table_guid['champs_valeurs_id']['cs_id_structure'] = $id_structure;
|
381 |
$table_guid['champs_valeurs_id']['cs_id_structure'] = $id_structure;
|
| 386 |
$table_guid['champs_valeurs_protege']['cs_guid'] = $this->bdd->quote(sprintf($this->config['coel']['guid'], $abr_projet, 'str'.$id_structure));
|
- |
|
| 387 |
$this->modifier($table_guid);
|
382 |
$table_guid['champs_valeurs_protege']['cs_guid'] = $this->bdd->quote(sprintf($this->config['coel']['guid'], $abr_projet, 'str'.$id_structure));
|