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();
362 delphine 77
		$inventories = '';
78
		if ($this->cartesFormateur->testerParametresProjets() == true) {
79
			$inventories = $this->cartesFormateur->chargerDonnees();
80
		}
314 delphine 81
		$retour = '';
82
		if (is_array($inventories) && $inventories !== array()){
322 delphine 83
			$this->chargerVille();// Connection referentiel communes
314 delphine 84
			list($text, $merge) = $this->calculerRepartition($inventories);
319 aurelien 85
			// Définition des couleurs des points
314 delphine 86
			$couleurs = $this->cartesFormateur->definirCouleurs();
87
			if ($text) {
88
				$usemap = $this->cartesFormateur->dessinerPoint($text, $merge, $couleurs);
89
			}
90
			if (isset($usemap)) {
91
				$this->cartesFormateur->img();
315 delphine 92
				$retour = $this->cartesFormateur->formaterCartes($usemap);
314 delphine 93
			}
94
		}
95
		if ($retour == '') {
96
			$retour = $this->formaterCarteVide();
97
		}
315 delphine 98
		$resultat = new ResultatService();
99
		$resultat->corps = ($this->info['retour'] == self::MIME_MAP) ? $retour : file_get_contents($retour);
319 aurelien 100
		$resultat->mime = ($this->info['retour'] == self::MIME_MAP) ? self::MIME_MAP : self::MIME_PNG;
315 delphine 101
		return $resultat;
308 delphine 102
	}
103
 
314 delphine 104
	public function creerFormateur(){
315 delphine 105
		$projet = ucwords($this->info['projet']);
314 delphine 106
		$Classe = $projet.'Formateur';
107
		$chemin = dirname(__FILE__).DS.'cartes'.DS;
108
		$cheminClasse = $chemin.$Classe.'.php';
109
		$cheminInterface = $chemin.'Formateur.php';
110
		if (file_exists($cheminInterface)) {
111
			include_once $cheminInterface;
112
			if (file_exists($cheminClasse)) {
113
				include_once $cheminClasse;
315 delphine 114
				$this->cartesFormateur = new $Classe($this->info);
314 delphine 115
			} else {
116
				$message = "La classe '$Classe' est introuvable.";Debug::printr($message);
117
				throw new Exception($message);
118
			}
119
		}
120
	}
322 delphine 121
	private function analyserRessources() {
122
		$ok = false;
123
		if (isset($this->ressources[0]) && $this->ressources[0] == 'legende') {
124
			$ok = true;
125
		}
126
		return $ok;
127
	}
314 delphine 128
 
322 delphine 129
	private function formerLegende() {
130
		$classe = 'LegendeCartes';
131
		require_once dirname(__FILE__).DS.'cartes'.DS.$classe.'.php';
132
		$sousService = new $classe(new Conteneur());
133
		$resultat = $sousService->consulter($this->ressources, $this->param);
134
		return $resultat;
135
	}
136
 
308 delphine 137
	private function traiterParametres() {
314 delphine 138
		$this->info['miniature'] = (isset($this->param['retour.format'])) ? $this->param['retour.format'] : false;
319 aurelien 139
		$this->info['src_map'] = ($this->info['miniature'] == 'min') ? 'france_utm_miniature.png' : 'france_utm_600x564.png';
140
		$this->info['retour'] = (isset($this->param['retour'])) ? $this->param['retour'] : self::MIME_PNG ;
141
		// Ajout du code du référentiel
303 delphine 142
		$this->info['referentiel'] = 'bdtfx';
316 delphine 143
		$projets = array('cenlr', 'cel', 'cbnmed', 'sophy', 'general');
315 delphine 144
		if (isset($this->param['projet']) && in_array($this->param['projet'], $projets)) {
145
			$this->info['projet'] = $this->param['projet'];
314 delphine 146
		} else {
315 delphine 147
			$this->info['projet'] = 'general';
314 delphine 148
		}
319 aurelien 149
		// Récupération d'infos générales
314 delphine 150
		// donnees exemple nn = 141; nt = 8522; nom = 'Acer campestre L.'; nom_ss_auteur = 'Acer campestre';
308 delphine 151
		$this->info['nn'] = $this->param['masque.nn'];
152
		$this->info['nt'] = $this->param['masque.nt'];
153
		$this->info['nom'] = $this->param['masque.ns'].' '.$this->param['masque.au'];
154
		$this->info['nom_ss_auteur'] = $this->param['masque.ns'];
303 delphine 155
	}
156
 
314 delphine 157
	private function chargerVille() {
542 delphine 158
		$requete = "SELECT nom as name, code as insee_code, utm_x as x_utm, utm_y as y_utm, utm_secteur as sector".
159
					" FROM tb_cel.cel_zones_geo;";
314 delphine 160
		$villes = $this->getBdd()->recupererTous($requete);
161
		foreach ($villes as $ville) {
162
			$this->tab_code_insee[$ville['insee_code']] = $ville;
163
		}
164
	}
165
 
166
	private function calculerRepartition($inventories) {
303 delphine 167
		$text = '';
314 delphine 168
		// Recuperation du positionnement de la carte
319 aurelien 169
		$png_txt = file_get_contents(Config::get('Cartes.chemin').str_replace('png', 'txt', $this->info['src_map']));
170
		parse_str($png_txt);
171
		// "Resolution" calculer à partir du fichier $png_txt par fuseau
314 delphine 172
		$p['31T'] = ($X231T - $X131T) / ($X231TUTM - $X131TUTM);
173
		$p['32T'] = ($X231T - $X131T ) / ($X231TUTM - $X131TUTM);
174
		$p['30T'] = ($X231T - $X131T ) / ($X231TUTM - $X131TUTM);
303 delphine 175
 
314 delphine 176
		$text = array();
177
		$merge = array();
178
		foreach ($inventories as $inventory){
179
			$utm = $this->cartesFormateur->chercherVille($inventory, $this->tab_code_insee);
180
			// Ultime tentative
181
			if (!$utm) {
542 delphine 182
				$requete = "SELECT nom as name, code as insee_code, utm_x as x_utm, utm_y as y_utm, utm_secteur as sector".
183
					" FROM tb_cel.cel_zones_geo WHERE name LIKE ".$this->getBdd()->proteger($inventory['location']);
314 delphine 184
				$utm = $this->getBdd()->recupererTous($requete);
185
			}
303 delphine 186
 
314 delphine 187
			// Si des doublons sur la commune : pas d'affichage , il vaut mieux ne rien afficher que d'afficher des erreurs.
188
			if (sizeof($utm) == 1) {
189
				$utm = $utm[0];
303 delphine 190
 
314 delphine 191
				// On centre le point au milieu de la maille 10x10 par defaut ...
192
				$utm = $this->chercherCentreMaille($utm);
303 delphine 193
 
314 delphine 194
				// Calcul coordonnes x, y sur l'image
195
				if ($utm['sector']=='31T') {// Fuseau 31 T
196
					$x = (($utm['x_utm'] - $X131TUTM) * $p['31T'] ) + $X131T;
197
					$y = $Y231T - (($utm['y_utm'] - $Y131TUTM) * $p['31T'] );
198
				} elseif ($utm['sector'] == '32T') {// Fuseau 32 T : une rotation + translation est appliqu�e
199
					$cosa = cos(deg2rad($angle3132));
200
					$sina = sin(deg2rad($angle3132));
201
					$xp = (($utm['x_utm'] - $X132TUTM) * $cosa) + (($utm['y_utm']- $Y132TUTM) * $sina);
202
					$yp = (-($utm['x_utm'] - $X132TUTM)* $sina) + (($utm['y_utm'] - $Y132TUTM) * $cosa);
203
					$x = ($xp * $p['32T'] ) + $X132T;
204
					$y = $Y232T-($yp * $p['32T'] );
205
				} elseif ($utm['sector'] == '30T') {// Fuseau 30 T : une rotation + translation est appliqu�e
206
					$cosa = cos(deg2rad($angle3031));
207
					$sina = sin(deg2rad($angle3031));
208
					$xp = (($utm['x_utm'] - $X130TUTM) * $cosa) + (($utm['y_utm'] - $Y130TUTM) * $sina);
209
					$yp = (-($utm['x_utm'] - $X130TUTM) * $sina) + (($utm['y_utm'] - $Y130TUTM) * $cosa);
210
					$x = ($xp * $p['30T'] ) + $X130T;
211
					$y = $Y230T - ($yp * $p['30T'] );
212
				}
213
				$x = round($x);
214
				$y = round($y);
303 delphine 215
 
216
 
314 delphine 217
				if ($utm['name'] != null) {
218
					$name = utf8_decode($utm['name']);
303 delphine 219
				}
315 delphine 220
				$comment = ($this->info['retour'] == self::MIME_MAP) ? $this->cartesFormateur->formerCommentaire($utm, $inventory) : '';
314 delphine 221
				// On stocke les commentaires pour affichage dans les tooltips
319 aurelien 222
				// Commentaire deja présent ? : on ajoute à la suite
314 delphine 223
				list($text, $merge) = $this->cartesFormateur->stockerCommentaire($text, $merge, $name, $comment, $inventory['collection_code'],$x,$y);
303 delphine 224
			}
314 delphine 225
		}
303 delphine 226
 
314 delphine 227
		return array($text, $merge);
228
	}
229
 
303 delphine 230
 
231
 
314 delphine 232
	private function formaterCarteVide() {
233
		$this->cheminCartesBase = Config::get('Cartes.chemin');
234
		$dest_map['vide'] = 'vide_'.$this->info['src_map'];
333 delphine 235
		$img['vide'] = imagecreatefrompng($this->cheminCartesBase.$this->info['src_map']);
319 aurelien 236
		imagepng($img['vide'], Config::get('cache.stockageChemin').$dest_map['vide'], 9);
315 delphine 237
		$retour = Config::get('cel_dst').$dest_map['vide'];
238
		if ($this->info['retour'] == self::MIME_MAP) {
239
			$retour =  "<img src=\"".$retour."\" style=\"border:none; cursor:crosshair\" alt=\"\" />\n";
240
		}
303 delphine 241
		return $retour;
242
	}
243
 
244
 
314 delphine 245
 
246
 
247
	//+----------------------------------------------------------------------------------------------------------------+
248
	// sous fonction de calculer répartition
249
 
250
 
251
	private function chercherCentreMaille($utm) {
252
		$pad = str_repeat ('0' ,(7 - strlen( $utm['x_utm'])));
253
		$utm['x_utm'] = $pad.$utm['x_utm'];
254
 
255
		$pad = str_repeat ('0' ,(7 - strlen( $utm['y_utm'])));
256
		$utm['y_utm'] = $pad.$utm['y_utm'];
257
 
258
		$utm['x_utm'] = substr($utm['x_utm'] ,0,3);
259
		$utm['x_utm'] = $utm['x_utm'].'5000';
260
 
261
		$utm['y_utm'] = substr($utm['y_utm'] ,0,3);
262
		$utm['y_utm'] = $utm['y_utm'].'5000';
263
		return $utm;
303 delphine 264
	}
265
 
314 delphine 266
	//+----------------------------------------------------------------------------------------------------------------+
303 delphine 267
	// Méthodes d'accès aux objets du Framework
268
	/**
269
	* Méthode de connection à la base de données sur demande.
270
	* Tous les services web n'ont pas besoin de s'y connecter.
271
	*/
272
	protected function getBdd() {
314 delphine 273
		if (! isset($this->Bdd)) {
274
			$this->Bdd = new Bdd();
275
		}
303 delphine 276
	return $this->Bdd;
277
	}
278
 
314 delphine 279
 
303 delphine 280
 
281
}
282
?>