Subversion Repositories eFlore/Applications.coel

Rev

Rev 1709 | Rev 1713 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1709 Rev 1711
Line 17... Line 17...
17
		'csc_mark_acquisition_collection', 'csc_mark_acquisition_echantillon',
17
		'csc_mark_acquisition_collection', 'csc_mark_acquisition_echantillon',
18
		'cs_latitude', 'cs_longitude',
18
		'cs_latitude', 'cs_longitude',
19
	);
19
	);
Line 20... Line 20...
20
 
20
 
21
	// 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.
22
    protected $tables = array(	120 => array(
22
	protected $tables = array(	120 => array(
23
        'nom' => 'coel_structure', 
23
		'nom' => 'coel_structure', 
24
        'prefixe' => 'cs', 
24
		'prefixe' => 'cs', 
25
        'id' => array('cs_id_structure')),
25
		'id' => array('cs_id_structure')),
26
    122 => array(
26
	122 => array(
27
        'nom' => 'coel_structure_conservation', 
27
		'nom' => 'coel_structure_conservation', 
28
        'prefixe' => 'csc',
28
		'prefixe' => 'csc',
29
        'id' => array('csc_id_structure')),
29
		'id' => array('csc_id_structure')),
30
    123 => array(
30
	123 => array(
31
        'nom' => 'coel_structure_valorisation', 
31
		'nom' => 'coel_structure_valorisation', 
32
        'prefixe' => 'csv',
32
		'prefixe' => 'csv',
Line 33... Line 33...
33
        'id' => array('csv_id_structure')));	
33
		'id' => array('csv_id_structure')));	
34
 
34
 
35
	/**
35
	/**
36
	 * Méthode principale appelée avec une requête de type GET.
36
	 * Méthode principale appelée avec une requête de type GET.
Line 74... Line 74...
74
		$whereClause = array();
74
		$whereClause = array();
75
		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']}";
76
		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']}";
Line 77... Line 77...
77
 
77
 
78
		if(isset($p['recherche'])) {
78
		if(isset($p['recherche'])) {
79
			if(@$this->searchCity && trim($this->searchCity) == true) {
79
			if(@$this->searchCity && trim($this->searchCity) == 'true') {
80
				$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']}")) . ")";
81
			} else {
81
			} else {
82
				$whereClause[] = "cs_nom LIKE {$p['recherche']}";
82
				$whereClause[] = "cs_nom LIKE {$p['recherche']}";
83
			}
83
			}
Line 139... Line 139...
139
	public function getElementParZoneGeo($param) {
139
	public function getElementParZoneGeo($param) {
140
		// Pré traitement des paramêtres
140
		// Pré traitement des paramêtres
141
		$p = $this->traiterParametresUrl(array('type', 'projets'), $param);
141
		$p = $this->traiterParametresUrl(array('type', 'projets'), $param);
142
		if (!isset($p['type'])) {
142
		if (!isset($p['type'])) {
143
			$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.";
144
            return array();
144
			return array();
145
		}
145
		}
Line 146... Line 146...
146
 
146
 
147
        // Construction de la requête
147
		// Construction de la requête
148
        $requete =	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
148
		$requete =	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
149
            '	IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
149
			'	IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
150
            '		SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
150
			'		SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
151
            '		SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) AS id, '.
151
			'		SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) AS id, '.
152
            '	COUNT( cs_id_structure ) AS nbre '.
152
			'	COUNT( cs_id_structure ) AS nbre '.
153
            'FROM coel_structure '.
153
			'FROM coel_structure '.
154
            'WHERE cs_ce_truk_pays = 2654 '.
154
			'WHERE cs_ce_truk_pays = 2654 '.
155
            (isset($p['projets']) ? "	AND cs_ce_projet IN ({$p['projets']}) " : '').
155
			(isset($p['projets']) ? "	AND cs_ce_projet IN ({$p['projets']}) " : '').
156
            'GROUP BY IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
156
			'GROUP BY IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
157
            '	SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
157
			'	SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
158
            '	SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) '.
158
			'	SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) '.
159
            'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'id ASC').' ';
159
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'id ASC').' ';
160
 
160
 
161
        // Récupération des résultats
161
		// Récupération des résultats
162
        try {
162
		try {
163
            $donnees = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
163
			$donnees = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
164
        } catch (PDOException $e) {
164
		} catch (PDOException $e) {
165
            $this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
165
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
166
        }
166
		}
167
 
167
 
168
        if ($donnees === false) {
168
		if ($donnees === false) {
169
            $this->messages[] = "La requête a retourné aucun résultat.";
169
			$this->messages[] = "La requête a retourné aucun résultat.";
170
            return array();
170
			return array();
171
        }
171
		}
172
 
172
 
173
        $info = array();
173
		$info = array();
174
        foreach ($donnees as $donnee) {
174
		foreach ($donnees as $donnee) {
175
            $info[$donnee['id']] = $donnee['nbre'];
175
			$info[$donnee['id']] = $donnee['nbre'];
176
        }
176
		}
177
        return $info;
177
		return $info;
Line 178... Line 178...
178
    }
178
	}
179
 
179
 
180
 
180
 
Line 306... Line 306...
306
	 */
306
	 */
307
	public function deleteElement($uid) {
307
	public function deleteElement($uid) {
308
		// NOTES : une structure ne peut pas être supprimée si elle possède des collections liées.
308
		// NOTES : une structure ne peut pas être supprimée si elle possède des collections liées.
309
		// Vérification de la présence des id passés par l'url
309
		// Vérification de la présence des id passés par l'url
310
		if (!isset($uid[0]) || !isset($uid[1])) {
310
		if (!isset($uid[0]) || !isset($uid[1])) {
311
            $this->messages[] = "Identifiant de structure ou d'utilisateur manquant. Vous ne devriez pas avoir accès à ce service.";
311
			$this->messages[] = "Identifiant de structure ou d'utilisateur manquant. Vous ne devriez pas avoir accès à ce service.";
312
            $this->envoyer();
312
			$this->envoyer();
313
            return;
313
			return;
314
		}
314
		}
315
 
315
 
316
        // Identification de l'utilisateur
316
		// Identification de l'utilisateur
317
        list($id_utilisateur, $id_session) = $this->getIdentification($uid[0]);
317
		list($id_utilisateur, $id_session) = $this->getIdentification($uid[0]);
318
        // Contrôle du non détournement de l'utilisateur		
318
		// Contrôle du non détournement de l'utilisateur		
319
        if (! $this->etreAutorise($id_utilisateur)) {
319
		if (! $this->etreAutorise($id_utilisateur)) {
320
            $this->envoyer();
320
			$this->envoyer();
321
            return;
321
			return;
322
        }
322
		}
323
 
323
 
324
        // Récupération des id passés par l'url
324
		// Récupération des id passés par l'url
325
        $identifiants = explode(',', rtrim($uid[1], ','));
325
		$identifiants = explode(',', rtrim($uid[1], ','));
326
 
326
 
327
        if (count($identifiants) == 0) {
327
		if (count($identifiants) == 0) {
328
            $this->messages[] = "Aucun enregistrement n'a été supprimé.";
328
			$this->messages[] = "Aucun enregistrement n'a été supprimé.";
329
            $this->envoyer();
329
			$this->envoyer();
330
            return;
330
			return;
331
        }
331
		}
Line 332... Line 332...
332
	
332
	
333
        try {
333
		try {
334
            foreach ($identifiants as $id_structure) {
334
			foreach ($identifiants as $id_structure) {
335
                // Vérification que la structure ne possède pas de collections liées
335
				// Vérification que la structure ne possède pas de collections liées
336
                if (self::verifierPresenceCollection($this->bdd, $id_structure)) {
336
				if (self::verifierPresenceCollection($this->bdd, $id_structure)) {
337
                    $this->messages[] = "La structure '$id_structure' ne peut pas être supprimée car elle possède des collections liées.";
337
					$this->messages[] = "La structure '$id_structure' ne peut pas être supprimée car elle possède des collections liées.";
338
                    continue;
338
					continue;
Line 339... Line 339...
339
                }
339
				}
340
 
340
 
Line 341... Line 341...
341
                $params = array('cs_id_structure' => $id_structure, 'csc_id_structure' => $id_structure, 'csv_id_structure' => $id_structure);
341
				$params = array('cs_id_structure' => $id_structure, 'csc_id_structure' => $id_structure, 'csv_id_structure' => $id_structure);
342
                $tables_a_modifier = $this->recupererTablesAModifier($params);
342
				$tables_a_modifier = $this->recupererTablesAModifier($params);
Line 343... Line 343...
343
								
343
								
344
                foreach ($tables_a_modifier as $table_id => $table) {
344
				foreach ($tables_a_modifier as $table_id => $table) {
345
                    if (! $this->avoirEnregistrement($table)) continue;
345
					if (! $this->avoirEnregistrement($table)) continue;
346
 
346
 
347
                    if ($this->supprimer($table) === true) {
347
					if ($this->supprimer($table) === true) {
348
                        // Historisation (Ajout des méta-données)
348
						// Historisation (Ajout des méta-données)
349
                        $cle = $this->recupererCle($table);
349
						$cle = $this->recupererCle($table);
350
                        $this->historiser($table_id, $cle, 'NULL', $id_utilisateur, 3, $id_session);
350
						$this->historiser($table_id, $cle, 'NULL', $id_utilisateur, 3, $id_session);
351
                    }
351
					}
352
                }
352
				}
Line 353... Line 353...
353
            }
353
			}
354
        } catch (PDOException $e) {
354
		} catch (PDOException $e) {
355
            $this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
355
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
Line 356... Line 356...
356
        }
356
		}
357
 
357
 
358
		// Envoie sur la sortie standard
358
		// Envoie sur la sortie standard
359
		$this->envoyer();
359
		$this->envoyer();
360
	}
360
	}
361
	
361
	
362
	static function verifierPresenceCollection($db, $id_structure) {
362
	static function verifierPresenceCollection($db, $id_structure) {
Line 363... Line 363...
363
		// Vérification que la structure ne possède pas de collections liées
363
		// Vérification que la structure ne possède pas de collections liées
364
        return ($db->query(sprintf(
364
		return ($db->query(sprintf(
365
            'SELECT COUNT(cc_id_collection) AS nbre_collection FROM coel_collection ' .
365
			'SELECT COUNT(cc_id_collection) AS nbre_collection FROM coel_collection ' .
Line 366... Line 366...
366
            ' WHERE cc_ce_structure = %d GROUP BY cc_ce_structure ',
366
			' WHERE cc_ce_structure = %d GROUP BY cc_ce_structure ',
367
            $id_structure))->fetchColumn() != 0);
367
			$id_structure))->fetchColumn() != 0);
Line 368... Line 368...
368
	}
368
	}
369
 
369
 
370
	static function callNominatim(&$params, $db = NULL) {
370
	static function callNominatim(&$params, $db = NULL) {
371
        // lon/lat déjà saisies ?
371
		// lon/lat déjà saisies ?
372
		if (@$params['cs_latitude'] && @$params['cs_longitude']) return FALSE;
372
		if (@$params['cs_latitude'] && @$params['cs_longitude']) return FALSE;
373
 
373
 
374
        // ni adresse, ni CP, ni ville ? rien n'est possible
374
		// ni adresse, ni CP, ni ville ? rien n'est possible
375
        if (!@$params['cs_adresse_01'] && !@$params['cs_code_postal'] && !@$params['cs_ville']) return FALSE;
375
		if (!@$params['cs_adresse_01'] && !@$params['cs_code_postal'] && !@$params['cs_ville']) return FALSE;
376
 
376
 
377
        $lonlat = array();
377
		$lonlat = array();
378
        if(Coel::coordGuess(Coel::addrReStruct($params, $db), $lonlat)) {
378
		if(Coel::coordGuess(Coel::addrReStruct($params, $db), $lonlat)) {
379
            $params['cs_latitude'] = $lonlat['lat'];
379
			$params['cs_latitude'] = $lonlat['lat'];
380
            $params['cs_longitude'] = $lonlat['lon'];
380
			$params['cs_longitude'] = $lonlat['lon'];
381
            return TRUE;
381
			return TRUE;
382
        }
382
		}
383
 
383
 
384
        // second guess, sans code postal
384
		// second guess, sans code postal
385
        if(@$params['cs_code_postal']) {
385
		if(@$params['cs_code_postal']) {
386
            $params2 = $params;
386
			$params2 = $params;
Line 387... Line 387...
387
            unset($params2['cs_code_postal']);
387
			unset($params2['cs_code_postal']);
388
            if(Coel::coordGuess(Coel::addrReStruct($params2, $db), $lonlat)) {
388
			if(Coel::coordGuess(Coel::addrReStruct($params2, $db), $lonlat)) {