Subversion Repositories eFlore/Projets.eflore-projets

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
303 delphine 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 5.1.1                                                                                    |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2006 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This file is part of eFlore-Fiche.                                                                   |
9
// |                                                                                                      |
10
// | Foobar is free software; you can redistribute it and/or modify                                       |
11
// | it under the terms of the GNU General Public License as published by                                 |
12
// | the Free Software Foundation; either version 2 of the License, or                                    |
13
// | (at your option) any later version.                                                                  |
14
// |                                                                                                      |
15
// | Foobar is distributed in the hope that it will be useful,                                            |
16
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
17
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
18
// | GNU General Public License for more details.                                                         |
19
// |                                                                                                      |
20
// | You should have received a copy of the GNU General Public License                                    |
21
// | along with Foobar; if not, write to the Free Software                                                |
22
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
23
// +------------------------------------------------------------------------------------------------------+
24
// CVS : $Id: effi_cel.action.php,v 1.9 2007-11-06 10:54:03 jp_milcent Exp $
25
/**
26
* Fichier d'action du module eFlore-Fiche : Cel
27
*
28
* Appel Carnet en ligne
29
*
30
*
31
*@package eFlore
32
*@subpackage ef_fiche
33
//Auteur original :
34
*@author        David Delon <dd@clapas.net>
35
//Autres auteurs :
36
*@author        aucun
37
*@copyright     Tela-Botanica 2000-2006
38
*@version       $Revision: 1.9 $ $Date: 2007-11-06 10:54:03 $
39
// +------------------------------------------------------------------------------------------------------+
40
*/
41
 
42
// +------------------------------------------------------------------------------------------------------+
43
// |                                            ENTETE du PROGRAMME                                       |
44
// +------------------------------------------------------------------------------------------------------+
45
 
46
// +------------------------------------------------------------------------------------------------------+
47
// |                                            CORPS du PROGRAMME                                        |
48
// +------------------------------------------------------------------------------------------------------+
49
 
50
 
51
 
52
// TODO : CSS specifique (id)
53
 
54
class Cartes {
55
	private $tab_code_insee = array();
314 delphine 56
	public $src_map;
57
	private $cartesFormateur = null;
315 delphine 58
	const MIME_MAP = 'text/html';
319 aurelien 59
	const MIME_PNG = 'image/png';
303 delphine 60
 
61
	public function consulter($ressources, $param) {
314 delphine 62
		// Initialisation des variables
308 delphine 63
		$this->ressources = $ressources;
64
		$this->param = $param;
322 delphine 65
		if ($this->analyserRessources() == true) {
66
			$resultat = $this->formerLegende();
67
		} else {
68
			$this->traiterParametres();
69
			$resultat = $this->formerCarte();
70
		}
71
		return $resultat;
72
	}
73
 
74
	public function formerCarte() {
314 delphine 75
		$this->creerFormateur();
76
		$this->cartesFormateur->initialiserImage();
322 delphine 77
 
314 delphine 78
		$inventories = $this->cartesFormateur->chargerDonnees();
79
		$retour = '';
80
		if (is_array($inventories) && $inventories !== array()){
322 delphine 81
			$this->chargerVille();// Connection referentiel communes
314 delphine 82
			list($text, $merge) = $this->calculerRepartition($inventories);
319 aurelien 83
			// Définition des couleurs des points
314 delphine 84
			$couleurs = $this->cartesFormateur->definirCouleurs();
85
			if ($text) {
86
				$usemap = $this->cartesFormateur->dessinerPoint($text, $merge, $couleurs);
87
			}
88
			if (isset($usemap)) {
89
				$this->cartesFormateur->img();
315 delphine 90
				$retour = $this->cartesFormateur->formaterCartes($usemap);
314 delphine 91
			}
92
		}
93
		if ($retour == '') {
94
			$retour = $this->formaterCarteVide();
95
		}
315 delphine 96
		$resultat = new ResultatService();
97
		$resultat->corps = ($this->info['retour'] == self::MIME_MAP) ? $retour : file_get_contents($retour);
319 aurelien 98
		$resultat->mime = ($this->info['retour'] == self::MIME_MAP) ? self::MIME_MAP : self::MIME_PNG;
315 delphine 99
		return $resultat;
308 delphine 100
	}
101
 
314 delphine 102
	public function creerFormateur(){
315 delphine 103
		$projet = ucwords($this->info['projet']);
314 delphine 104
		$Classe = $projet.'Formateur';
105
		$chemin = dirname(__FILE__).DS.'cartes'.DS;
106
		$cheminClasse = $chemin.$Classe.'.php';
107
		$cheminInterface = $chemin.'Formateur.php';
108
		if (file_exists($cheminInterface)) {
109
			include_once $cheminInterface;
110
			if (file_exists($cheminClasse)) {
111
				include_once $cheminClasse;
315 delphine 112
				$this->cartesFormateur = new $Classe($this->info);
314 delphine 113
			} else {
114
				$message = "La classe '$Classe' est introuvable.";Debug::printr($message);
115
				throw new Exception($message);
116
			}
117
		}
118
	}
322 delphine 119
	private function analyserRessources() {
120
		$ok = false;
121
		if (isset($this->ressources[0]) && $this->ressources[0] == 'legende') {
122
			$ok = true;
123
		}
124
		return $ok;
125
	}
314 delphine 126
 
322 delphine 127
	private function formerLegende() {
128
		$classe = 'LegendeCartes';
129
		require_once dirname(__FILE__).DS.'cartes'.DS.$classe.'.php';
130
		$sousService = new $classe(new Conteneur());
131
		$resultat = $sousService->consulter($this->ressources, $this->param);
132
		return $resultat;
133
	}
134
 
308 delphine 135
	private function traiterParametres() {
314 delphine 136
		$this->info['miniature'] = (isset($this->param['retour.format'])) ? $this->param['retour.format'] : false;
319 aurelien 137
		$this->info['src_map'] = ($this->info['miniature'] == 'min') ? 'france_utm_miniature.png' : 'france_utm_600x564.png';
138
		$this->info['retour'] = (isset($this->param['retour'])) ? $this->param['retour'] : self::MIME_PNG ;
139
		// Ajout du code du référentiel
303 delphine 140
		$this->info['referentiel'] = 'bdtfx';
316 delphine 141
		$projets = array('cenlr', 'cel', 'cbnmed', 'sophy', 'general');
315 delphine 142
		if (isset($this->param['projet']) && in_array($this->param['projet'], $projets)) {
143
			$this->info['projet'] = $this->param['projet'];
314 delphine 144
		} else {
315 delphine 145
			$this->info['projet'] = 'general';
314 delphine 146
		}
319 aurelien 147
		// Récupération d'infos générales
314 delphine 148
		// donnees exemple nn = 141; nt = 8522; nom = 'Acer campestre L.'; nom_ss_auteur = 'Acer campestre';
308 delphine 149
		$this->info['nn'] = $this->param['masque.nn'];
150
		$this->info['nt'] = $this->param['masque.nt'];
151
		$this->info['nom'] = $this->param['masque.ns'].' '.$this->param['masque.au'];
152
		$this->info['nom_ss_auteur'] = $this->param['masque.ns'];
303 delphine 153
	}
154
 
314 delphine 155
	private function chargerVille() {
156
		$requete = "SELECT * FROM tb_cel.locations";
157
		$villes = $this->getBdd()->recupererTous($requete);
158
		foreach ($villes as $ville) {
159
			$this->tab_code_insee[$ville['insee_code']] = $ville;
160
		}
161
	}
162
 
163
	private function calculerRepartition($inventories) {
303 delphine 164
		$text = '';
314 delphine 165
		// Recuperation du positionnement de la carte
319 aurelien 166
		$png_txt = file_get_contents(Config::get('Cartes.chemin').str_replace('png', 'txt', $this->info['src_map']));
167
		parse_str($png_txt);
168
		// "Resolution" calculer à partir du fichier $png_txt par fuseau
314 delphine 169
		$p['31T'] = ($X231T - $X131T) / ($X231TUTM - $X131TUTM);
170
		$p['32T'] = ($X231T - $X131T ) / ($X231TUTM - $X131TUTM);
171
		$p['30T'] = ($X231T - $X131T ) / ($X231TUTM - $X131TUTM);
303 delphine 172
 
314 delphine 173
		$text = array();
174
		$merge = array();
175
		foreach ($inventories as $inventory){
176
			$utm = $this->cartesFormateur->chercherVille($inventory, $this->tab_code_insee);
177
			// Ultime tentative
178
			if (!$utm) {
179
				$requete = "SELECT *  FROM tb_cel.locations WHERE name LIKE ".$this->getBdd()->proteger($inventory['location']);
180
				$utm = $this->getBdd()->recupererTous($requete);
181
			}
303 delphine 182
 
314 delphine 183
			// Si des doublons sur la commune : pas d'affichage , il vaut mieux ne rien afficher que d'afficher des erreurs.
184
			if (sizeof($utm) == 1) {
185
				$utm = $utm[0];
303 delphine 186
 
314 delphine 187
				// On centre le point au milieu de la maille 10x10 par defaut ...
188
				$utm = $this->chercherCentreMaille($utm);
303 delphine 189
 
314 delphine 190
				// Calcul coordonnes x, y sur l'image
191
				if ($utm['sector']=='31T') {// Fuseau 31 T
192
					$x = (($utm['x_utm'] - $X131TUTM) * $p['31T'] ) + $X131T;
193
					$y = $Y231T - (($utm['y_utm'] - $Y131TUTM) * $p['31T'] );
194
				} elseif ($utm['sector'] == '32T') {// Fuseau 32 T : une rotation + translation est appliqu�e
195
					$cosa = cos(deg2rad($angle3132));
196
					$sina = sin(deg2rad($angle3132));
197
					$xp = (($utm['x_utm'] - $X132TUTM) * $cosa) + (($utm['y_utm']- $Y132TUTM) * $sina);
198
					$yp = (-($utm['x_utm'] - $X132TUTM)* $sina) + (($utm['y_utm'] - $Y132TUTM) * $cosa);
199
					$x = ($xp * $p['32T'] ) + $X132T;
200
					$y = $Y232T-($yp * $p['32T'] );
201
				} elseif ($utm['sector'] == '30T') {// Fuseau 30 T : une rotation + translation est appliqu�e
202
					$cosa = cos(deg2rad($angle3031));
203
					$sina = sin(deg2rad($angle3031));
204
					$xp = (($utm['x_utm'] - $X130TUTM) * $cosa) + (($utm['y_utm'] - $Y130TUTM) * $sina);
205
					$yp = (-($utm['x_utm'] - $X130TUTM) * $sina) + (($utm['y_utm'] - $Y130TUTM) * $cosa);
206
					$x = ($xp * $p['30T'] ) + $X130T;
207
					$y = $Y230T - ($yp * $p['30T'] );
208
				}
209
				$x = round($x);
210
				$y = round($y);
303 delphine 211
 
212
 
314 delphine 213
				if ($utm['name'] != null) {
214
					$name = utf8_decode($utm['name']);
303 delphine 215
				}
315 delphine 216
				$comment = ($this->info['retour'] == self::MIME_MAP) ? $this->cartesFormateur->formerCommentaire($utm, $inventory) : '';
314 delphine 217
				// On stocke les commentaires pour affichage dans les tooltips
319 aurelien 218
				// Commentaire deja présent ? : on ajoute à la suite
314 delphine 219
				list($text, $merge) = $this->cartesFormateur->stockerCommentaire($text, $merge, $name, $comment, $inventory['collection_code'],$x,$y);
303 delphine 220
			}
314 delphine 221
		}
303 delphine 222
 
314 delphine 223
		return array($text, $merge);
224
	}
225
 
303 delphine 226
 
227
 
314 delphine 228
	private function formaterCarteVide() {
229
		$this->cheminCartesBase = Config::get('Cartes.chemin');
230
		$dest_map['vide'] = 'vide_'.$this->info['src_map'];
333 delphine 231
		$img['vide'] = imagecreatefrompng($this->cheminCartesBase.$this->info['src_map']);
319 aurelien 232
		imagepng($img['vide'], Config::get('cache.stockageChemin').$dest_map['vide'], 9);
315 delphine 233
		$retour = Config::get('cel_dst').$dest_map['vide'];
234
		if ($this->info['retour'] == self::MIME_MAP) {
235
			$retour =  "<img src=\"".$retour."\" style=\"border:none; cursor:crosshair\" alt=\"\" />\n";
236
		}
303 delphine 237
		return $retour;
238
	}
239
 
240
 
314 delphine 241
 
242
 
243
	//+----------------------------------------------------------------------------------------------------------------+
244
	// sous fonction de calculer répartition
245
 
246
 
247
	private function chercherCentreMaille($utm) {
248
		$pad = str_repeat ('0' ,(7 - strlen( $utm['x_utm'])));
249
		$utm['x_utm'] = $pad.$utm['x_utm'];
250
 
251
		$pad = str_repeat ('0' ,(7 - strlen( $utm['y_utm'])));
252
		$utm['y_utm'] = $pad.$utm['y_utm'];
253
 
254
		$utm['x_utm'] = substr($utm['x_utm'] ,0,3);
255
		$utm['x_utm'] = $utm['x_utm'].'5000';
256
 
257
		$utm['y_utm'] = substr($utm['y_utm'] ,0,3);
258
		$utm['y_utm'] = $utm['y_utm'].'5000';
259
		return $utm;
303 delphine 260
	}
261
 
314 delphine 262
	//+----------------------------------------------------------------------------------------------------------------+
303 delphine 263
	// Méthodes d'accès aux objets du Framework
264
	/**
265
	* Méthode de connection à la base de données sur demande.
266
	* Tous les services web n'ont pas besoin de s'y connecter.
267
	*/
268
	protected function getBdd() {
314 delphine 269
		if (! isset($this->Bdd)) {
270
			$this->Bdd = new Bdd();
271
		}
303 delphine 272
	return $this->Bdd;
273
	}
274
 
314 delphine 275
 
303 delphine 276
 
277
}
278
?>