Subversion Repositories eFlore/Projets.eflore-projets

Rev

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