Subversion Repositories eFlore/Projets.eflore-projets

Rev

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