| 424 | jpm | 1 | <?php
 | 
        
           | 575 | jpm | 2 | // declare(encoding='UTF-8');
 | 
        
           | 424 | jpm | 3 | /**
 | 
        
           |  |  | 4 |  * Service fournissant une carte dynamique des obsertions publiques du CEL.
 | 
        
           |  |  | 5 |  * Encodage en entrée : utf8
 | 
        
           |  |  | 6 |  * Encodage en sortie : utf8
 | 
        
           |  |  | 7 |  *
 | 
        
           | 575 | jpm | 8 |  * Cas d'utilisation et documentation :
 | 
        
           |  |  | 9 |  * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetCarto
 | 
        
           | 424 | jpm | 10 |  *
 | 
        
           | 575 | jpm | 11 |  * Paramètres :
 | 
        
           |  |  | 12 |  * ===> utilisateur = identifiant
 | 
        
           |  |  | 13 |  * Affiche seulement les observations d'un utilisateur donné. L'identifiant correspond au courriel de
 | 
        
           |  |  | 14 |  * l'utilisateur avec lequel il s'est inscrit sur Tela Botanica.
 | 
        
           |  |  | 15 |  * ===> dept = code_du_département
 | 
        
           |  |  | 16 |  * Affiche seulement les observations pour le département français métropolitain indiqué. Les codes de département utilisables
 | 
        
           |  |  | 17 |  * sont : 01 à 19, 2A, 2B et 21 à 95.
 | 
        
           |  |  | 18 |  * ===> projet = mot-clé
 | 
        
           |  |  | 19 |  * Affiche seulement les observations pour le projet d'observations indiqué. Dans l'interface du CEL, vous pouvez taguer vos
 | 
        
           |  |  | 20 |  * observations avec un mot-clé de projet. Si vous voulez regrouper des observations de plusieurs utilisateurs, communiquez un
 | 
        
           |  |  | 21 |  * mot-clé de projet à vos amis et visualisez les informations ainsi regroupées.
 | 
        
           |  |  | 22 |  * ===> num_taxon = num_taxon
 | 
        
           |  |  | 23 |  * Affiche seulement les observations pour la plante indiquée. Le num_taxon correspond au numéro taxonomique de la plante.
 | 
        
           |  |  | 24 |  * Ce numéro est disponible dans les fiches d'eFlore. Par exemple, pour "Poa bulbosa L." le numéro taxonomique vaut 7080.
 | 
        
           |  |  | 25 |  *
 | 
        
           |  |  | 26 |  * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
 | 
        
           |  |  | 27 |  * @license	GPL v3 <http://www.gnu.org/licenses/gpl.txt>
 | 
        
           |  |  | 28 |  * @license	CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
 | 
        
           |  |  | 29 |  * @version	$Id$
 | 
        
           |  |  | 30 |  * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
 | 
        
           | 424 | jpm | 31 |  */
 | 
        
           | 1091 | aurelien | 32 | class Cartopoint extends WidgetCommun {
 | 
        
           | 464 | delphine | 33 | 	const DS = DIRECTORY_SEPARATOR;
 | 
        
           | 1091 | aurelien | 34 | 	const SERVICE_CARTO_NOM = 'CelWidgetMapPoint';
 | 
        
           | 836 | jpm | 35 | 	const SERVICE_CARTO_ACTION_DEFAUT = 'carte-defaut';
 | 
        
           | 424 | jpm | 36 |   | 
        
           | 836 | jpm | 37 | 	private $carte = null;
 | 
        
           |  |  | 38 | 	private $utilisateur = null;
 | 
        
           |  |  | 39 | 	private $projet = null;
 | 
        
           |  |  | 40 | 	private $dept = null;
 | 
        
           |  |  | 41 | 	private $num_taxon = null;
 | 
        
           |  |  | 42 | 	private $station = null;
 | 
        
           |  |  | 43 | 	private $format = null;// Format des obs pour les stations (tableau/liste)
 | 
        
           | 1438 | aurelien | 44 | 	private $photos = null; // Seulement les obs avec photos ou bien toutes
 | 
        
           |  |  | 45 | 	private $titre = null; // Indication s'il faut le titre par défaut, personnalisé ou bien sans titre
 | 
        
           |  |  | 46 | 	private $logo = null; // url du logo à ajouter si nécessaire
 | 
        
           |  |  | 47 | 	private $url_site = null; // url du site auquel le logo est lié
 | 
        
           | 1448 | aurelien | 48 | 	private $image = null; // url d'une image à ajouter dans l'interface
 | 
        
           | 836 | jpm | 49 |   | 
        
           | 424 | jpm | 50 | 	/**
 | 
        
           | 575 | jpm | 51 | 	 * Méthode appelée par défaut pour charger ce widget.
 | 
        
           | 424 | jpm | 52 | 	 */
 | 
        
           |  |  | 53 | 	public function executer() {
 | 
        
           |  |  | 54 | 		$retour = null;
 | 
        
           | 836 | jpm | 55 | 		$this->extraireParametres();
 | 
        
           |  |  | 56 | 		$methode = $this->traiterNomMethodeExecuter($this->carte);
 | 
        
           | 471 | jpm | 57 | 		if (method_exists($this, $methode)) {
 | 
        
           |  |  | 58 | 			$retour = $this->$methode();
 | 
        
           | 424 | jpm | 59 | 		} else {
 | 
        
           | 471 | jpm | 60 | 			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
 | 
        
           | 424 | jpm | 61 | 		}
 | 
        
           |  |  | 62 | 		if (is_null($retour)) {
 | 
        
           |  |  | 63 | 			$info = 'Un problème est survenu : '.print_r($this->messages, true);
 | 
        
           |  |  | 64 | 			$this->envoyer($info);
 | 
        
           |  |  | 65 | 		} else {
 | 
        
           | 543 | jpm | 66 | 			$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
 | 
        
           | 424 | jpm | 67 | 			$html = $this->traiterSquelettePhp($squelette, $retour['donnees']);
 | 
        
           |  |  | 68 | 			$this->envoyer($html);
 | 
        
           |  |  | 69 | 		}
 | 
        
           |  |  | 70 | 	}
 | 
        
           | 836 | jpm | 71 |   | 
        
           |  |  | 72 | 	public function extraireParametres() {
 | 
        
           |  |  | 73 | 		extract($this->parametres);
 | 
        
           |  |  | 74 | 		$this->carte = (isset($carte) ? $carte : self::SERVICE_CARTO_ACTION_DEFAUT);
 | 
        
           |  |  | 75 | 		$this->utilisateur = (isset($utilisateur) ? $utilisateur : '*');
 | 
        
           |  |  | 76 | 		$this->projet = (isset($projet) ? $projet : '*');
 | 
        
           | 939 | jpm | 77 | 		$this->tag = (isset($tag) ? $tag : '*');
 | 
        
           | 836 | jpm | 78 | 		$this->dept = (isset($dept) ? $dept : '*');
 | 
        
           | 837 | jpm | 79 | 		$this->commune = (isset($commune) ? $commune : '*');
 | 
        
           | 836 | jpm | 80 | 		$this->num_taxon = (isset($num_taxon) ? $num_taxon : '*');
 | 
        
           | 939 | jpm | 81 | 		$this->date = (isset($date) ? $date : '*');
 | 
        
           |  |  | 82 | 		$this->taxon = (isset($taxon) ? $taxon : '*');
 | 
        
           | 940 | jpm | 83 | 		$this->commentaire = (isset($commentaire) ? $commentaire : null);
 | 
        
           | 836 | jpm | 84 | 		$this->station = (isset($station) ? $station : null);
 | 
        
           |  |  | 85 | 		$this->format = (isset($format) ? $format : null);
 | 
        
           | 1438 | aurelien | 86 | 		$this->photos = (isset($photos) ? $photos : null);
 | 
        
           |  |  | 87 | 		$this->titre = (isset($titre) ? urldecode($titre) : null);
 | 
        
           |  |  | 88 | 		$this->logo = (isset($logo) ? urldecode($logo) : null);
 | 
        
           |  |  | 89 | 		$this->url_site = (isset($url_site) ? urldecode($url_site) : null);
 | 
        
           | 1448 | aurelien | 90 | 		$this->image = (isset($image) ? urldecode($image) : null);
 | 
        
           | 841 | jpm | 91 | 		$this->start = (isset($start) ? $start : null);
 | 
        
           |  |  | 92 | 		$this->limit = (isset($limit) ? $limit : null);
 | 
        
           | 836 | jpm | 93 | 	}
 | 
        
           | 424 | jpm | 94 |   | 
        
           |  |  | 95 | 	/**
 | 
        
           |  |  | 96 | 	 * Carte par défaut
 | 
        
           |  |  | 97 | 	 */
 | 
        
           |  |  | 98 | 	public function executerCarteDefaut() {
 | 
        
           |  |  | 99 | 		$widget = null;
 | 
        
           | 939 | jpm | 100 | 		$url_stations = $this->contruireUrlServiceCarto('stations');
 | 
        
           | 424 | jpm | 101 | 		$url_base = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
 | 
        
           |  |  | 102 |   | 
        
           |  |  | 103 | 		// Création des infos du widget
 | 
        
           | 836 | jpm | 104 | 		$widget['donnees']['url_cel_carto'] = $this->contruireUrlServiceCarto();
 | 
        
           | 939 | jpm | 105 | 		$widget['donnees']['url_stations'] = $url_stations;
 | 
        
           | 424 | jpm | 106 | 		$widget['donnees']['url_base'] = $url_base;
 | 
        
           | 836 | jpm | 107 | 		$widget['donnees']['utilisateur'] = $this->utilisateur;
 | 
        
           |  |  | 108 | 		$widget['donnees']['projet'] = $this->projet;
 | 
        
           | 939 | jpm | 109 | 		$widget['donnees']['tag'] = $this->tag;
 | 
        
           | 836 | jpm | 110 | 		$widget['donnees']['dept'] = $this->dept;
 | 
        
           | 837 | jpm | 111 | 		$widget['donnees']['commune'] = $this->commune;
 | 
        
           | 836 | jpm | 112 | 		$widget['donnees']['num_taxon'] = $this->num_taxon;
 | 
        
           | 939 | jpm | 113 | 		$widget['donnees']['date'] = $this->date;
 | 
        
           |  |  | 114 | 		$widget['donnees']['taxon'] = $this->taxon;
 | 
        
           | 940 | jpm | 115 | 		$widget['donnees']['commentaire'] = $this->commentaire;
 | 
        
           | 1438 | aurelien | 116 | 		$widget['donnees']['photos'] = $this->photos;
 | 
        
           |  |  | 117 | 		$widget['donnees']['titre'] = $this->titre;
 | 
        
           |  |  | 118 | 		$widget['donnees']['logo'] = $this->logo;
 | 
        
           |  |  | 119 | 		$widget['donnees']['url_site'] = $this->url_site;
 | 
        
           | 1448 | aurelien | 120 | 		$widget['donnees']['image'] = $this->image;
 | 
        
           | 939 | jpm | 121 | 		$widget['donnees']['url_limites_communales'] = $this->obtenirUrlsLimitesCommunales();
 | 
        
           | 1091 | aurelien | 122 | 		$widget['donnees']['communeImageUrl'] = $this->config['carto']['communeImageUrl'];
 | 
        
           |  |  | 123 | 		$widget['donnees']['pointImageUrl'] = $this->config['carto']['pointImageUrl'];
 | 
        
           |  |  | 124 | 		$widget['donnees']['groupeImageUrlTpl'] = $this->config['carto']['groupeImageUrlTpl'];
 | 
        
           | 939 | jpm | 125 |   | 
        
           | 424 | jpm | 126 | 		$widget['squelette'] = 'carte_defaut';
 | 
        
           | 464 | delphine | 127 |   | 
        
           | 424 | jpm | 128 | 		return $widget;
 | 
        
           |  |  | 129 | 	}
 | 
        
           | 464 | delphine | 130 |   | 
        
           | 836 | jpm | 131 | 	private function contruireUrlServiceCarto($action = null) {
 | 
        
           |  |  | 132 | 		// Création url données json
 | 
        
           |  |  | 133 | 		$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::SERVICE_CARTO_NOM);
 | 
        
           |  |  | 134 | 		if ($action) {
 | 
        
           |  |  | 135 | 			$url .= "/$action";
 | 
        
           |  |  | 136 |   | 
        
           |  |  | 137 | 			$parametres_retenus = array();
 | 
        
           | 939 | jpm | 138 | 			$parametres_a_tester = array('station', 'utilisateur', 'projet', 'tag', 'dept', 'commune',
 | 
        
           | 940 | jpm | 139 | 				'num_taxon', 'taxon', 'date', 'commentaire',
 | 
        
           | 939 | jpm | 140 | 				'start', 'limit');
 | 
        
           | 836 | jpm | 141 | 			foreach ($parametres_a_tester as $param) {
 | 
        
           | 841 | jpm | 142 | 				if (isset($this->$param) && $this->$param != '*') {
 | 
        
           | 836 | jpm | 143 | 					$parametres_retenus[$param] = $this->$param;
 | 
        
           |  |  | 144 | 				}
 | 
        
           |  |  | 145 | 			}
 | 
        
           |  |  | 146 | 			if (count($parametres_retenus) > 0) {
 | 
        
           |  |  | 147 | 				$parametres_url = array();
 | 
        
           |  |  | 148 | 				foreach ($parametres_retenus as $cle => $valeur) {
 | 
        
           |  |  | 149 | 					$parametres_url[] = $cle.'='.$valeur;
 | 
        
           |  |  | 150 | 				}
 | 
        
           |  |  | 151 | 				$url .= '?'.implode('&', $parametres_url);
 | 
        
           |  |  | 152 | 			}
 | 
        
           |  |  | 153 | 		}
 | 
        
           |  |  | 154 | 		return $url;
 | 
        
           |  |  | 155 | 	}
 | 
        
           |  |  | 156 |   | 
        
           | 939 | jpm | 157 | 	private function obtenirUrlsLimitesCommunales() {
 | 
        
           |  |  | 158 | 		$urls = null;
 | 
        
           |  |  | 159 | 		if (isset($this->dept)) {
 | 
        
           | 1096 | aurelien | 160 | 			// si on veut afficher les limites départementales on va compter et chercher les noms de fichiers
 | 
        
           | 939 | jpm | 161 | 			$fichiersKml = $this->chercherFichierKml();
 | 
        
           |  |  | 162 | 			if (count($fichiersKml) > 0) {
 | 
        
           |  |  | 163 | 				foreach ($fichiersKml as $kml => $dossier){
 | 
        
           |  |  | 164 | 					$url_limites_communales = sprintf($this->config['carto']['limitesCommunaleUrlTpl'], $dossier, $kml);
 | 
        
           |  |  | 165 | 					$urls[] = $url_limites_communales;
 | 
        
           | 490 | jpm | 166 | 				}
 | 
        
           |  |  | 167 | 			}
 | 
        
           |  |  | 168 | 		}
 | 
        
           | 939 | jpm | 169 | 		$urls = json_encode($urls);
 | 
        
           |  |  | 170 | 		return $urls;
 | 
        
           | 490 | jpm | 171 | 	}
 | 
        
           |  |  | 172 |   | 
        
           | 836 | jpm | 173 | 	private function chercherFichierKml(){
 | 
        
           | 939 | jpm | 174 | 		$fichiers = array();
 | 
        
           | 574 | jpm | 175 | 		$chemins = explode(',', $this->config['carto']['communesKmzChemin']);
 | 
        
           | 836 | jpm | 176 | 		$departements = explode(',', $this->dept);// plrs code de départements peuvent être demandés séparés par des virgules
 | 
        
           | 599 | jpm | 177 | 		$departements_trouves = array();
 | 
        
           | 574 | jpm | 178 | 		foreach ($chemins as $dossier_chemin) {
 | 
        
           |  |  | 179 | 			if ($dossier_ressource = opendir($dossier_chemin)) {
 | 
        
           |  |  | 180 | 				while ($element = readdir($dossier_ressource)) {
 | 
        
           |  |  | 181 | 					if ($element != '.' && $element != '..') {
 | 
        
           | 599 | jpm | 182 | 						foreach ($departements as $departement) {
 | 
        
           |  |  | 183 | 							$nom_dossier = basename($dossier_chemin);
 | 
        
           |  |  | 184 | 							if (!isset($departements_trouves[$departement]) || $departements_trouves[$departement] == $nom_dossier) {
 | 
        
           |  |  | 185 | 								$dept_protege = preg_quote($departement);
 | 
        
           |  |  | 186 | 								if (!is_dir($dossier_chemin.'/'.$element) && preg_match("/^$dept_protege(?:_[0-9]+|)\.km[lz]$/", $element)) {
 | 
        
           |  |  | 187 | 									$fichiers[$element] = $nom_dossier;
 | 
        
           |  |  | 188 | 									$departements_trouves[$departement] = $nom_dossier;
 | 
        
           |  |  | 189 | 								}
 | 
        
           |  |  | 190 | 							}
 | 
        
           | 574 | jpm | 191 | 						}
 | 
        
           | 543 | jpm | 192 | 					}
 | 
        
           | 464 | delphine | 193 | 				}
 | 
        
           | 574 | jpm | 194 | 				closedir($dossier_ressource);
 | 
        
           | 464 | delphine | 195 | 			}
 | 
        
           |  |  | 196 | 		}
 | 
        
           | 599 | jpm | 197 |   | 
        
           | 574 | jpm | 198 | 		return $fichiers;
 | 
        
           | 471 | jpm | 199 | 	}
 | 
        
           |  |  | 200 |   | 
        
           |  |  | 201 | 	/**
 | 
        
           | 501 | jpm | 202 | 	 * Afficher message d'avertissement.
 | 
        
           |  |  | 203 | 	 */
 | 
        
           |  |  | 204 | 	public function executerAvertissement() {
 | 
        
           |  |  | 205 | 		$widget = null;
 | 
        
           |  |  | 206 |   | 
        
           |  |  | 207 | 		// Création des infos du widget
 | 
        
           |  |  | 208 | 		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
 | 
        
           |  |  | 209 | 		$widget['squelette'] = 'avertissement';
 | 
        
           |  |  | 210 |   | 
        
           |  |  | 211 | 		return $widget;
 | 
        
           |  |  | 212 | 	}
 | 
        
           | 1091 | aurelien | 213 | }
 | 
        
           |  |  | 214 | ?>
 |