Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 308 | Rev 315 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
// +------------------------------------------------------------------------------------------------------+
// | PHP version 5.1.1                                                                                    |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2006 Tela Botanica (accueil@tela-botanica.org)                                         |
// +------------------------------------------------------------------------------------------------------+
// | This file is part of eFlore-Fiche.                                                                   |
// |                                                                                                      |
// | Foobar is free software; you can redistribute it and/or modify                                       |
// | it under the terms of the GNU General Public License as published by                                 |
// | the Free Software Foundation; either version 2 of the License, or                                    |
// | (at your option) any later version.                                                                  |
// |                                                                                                      |
// | Foobar is distributed in the hope that it will be useful,                                            |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
// | GNU General Public License for more details.                                                         |
// |                                                                                                      |
// | You should have received a copy of the GNU General Public License                                    |
// | along with Foobar; if not, write to the Free Software                                                |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: effi_cel.action.php,v 1.9 2007-11-06 10:54:03 jp_milcent Exp $
/**
* Fichier d'action du module eFlore-Fiche : Cel
*
* Appel Carnet en ligne
* 
*
*@package eFlore
*@subpackage ef_fiche
//Auteur original :
*@author        David Delon <dd@clapas.net>
//Autres auteurs :
*@author        aucun
*@copyright     Tela-Botanica 2000-2006
*@version       $Revision: 1.9 $ $Date: 2007-11-06 10:54:03 $
// +------------------------------------------------------------------------------------------------------+
*/

// +------------------------------------------------------------------------------------------------------+
// |                                            ENTETE du PROGRAMME                                       |
// +------------------------------------------------------------------------------------------------------+

// +------------------------------------------------------------------------------------------------------+
// |                                            CORPS du PROGRAMME                                        |
// +------------------------------------------------------------------------------------------------------+



// TODO : CSS specifique (id)

class Cartes {
        private $tab_code_insee = array();
        public $src_map;
        private $cartesFormateur = null;
        
        public function consulter($ressources, $param) {
                // Initialisation des variables
                $this->ressources = $ressources;
                $this->param = $param;
                $this->traiterParametres();
                $this->creerFormateur();
                $this->cartesFormateur->initialiserImage();
                
                $inventories = $this->cartesFormateur->chargerDonnees();
                $retour = '';
                if (is_array($inventories) && $inventories !== array()){
                        // Connection referentiel communes 
                        $this->chargerVille();
                        list($text, $merge) = $this->calculerRepartition($inventories);
                        // D�finition des couleurs des points
                        $couleurs = $this->cartesFormateur->definirCouleurs();
                        if ($text) {
                                $usemap = $this->cartesFormateur->dessinerPoint($text, $merge, $couleurs);
                        }
                        if (isset($usemap)) {
                                $this->cartesFormateur->img();
                                
                                if ($this->info['miniature'] !== 'min')  {
                                        $retour = $this->cartesFormateur->formaterCartes($usemap);
                                } else { // miniature
                                        $retour = $this->cartesFormateur->formaterCarteMiniature($retour, $usemap);
                                }
                        }
                } else {
                        $retour = $this->formaterCarteVide();
                }
                if ($retour == '') {
                        $retour = $this->formaterCarteVide();
                }
                
                print_r($retour);
        }
        
        public function creerFormateur(){
                $projet = ucwords($this->param['projet']);
                $Classe = $projet.'Formateur';
                $chemin = dirname(__FILE__).DS.'cartes'.DS;
                $cheminClasse = $chemin.$Classe.'.php';
                $cheminInterface = $chemin.'Formateur.php';
                if (file_exists($cheminInterface)) {
                        include_once $cheminInterface;
                        if (file_exists($cheminClasse)) {
                                include_once $cheminClasse;
                                $this->cartesFormateur = new $Classe($this->param, $this->info);
                        } else {
                                $message = "La classe '$Classe' est introuvable.";Debug::printr($message);
                                throw new Exception($message);
                        }
                }
        }
        
        private function traiterParametres() {
                $this->info['miniature'] = (isset($this->param['retour.format'])) ? $this->param['retour.format'] : false;
                if ($this->info['miniature'] == 'min') {
                        $this->info['src_map'] = 'france_utm_miniature.jpg';
                } else {
                        $this->info['src_map'] = 'france_utm_600x564.jpg';
                }
                // Ajout du code du r�f�rentiel
                $this->info['referentiel'] = 'bdtfx';
                $projets = array('cenlr', 'cel', 'cbnmed', 'sophy');
                if (isset($this->param['projet'])) {
                        if (!in_array($this->param['projet'], $projets)) {
                                $this->param['projet'] = 'general';
                        }
                } else {
                        $this->param['projet'] = 'general';
                }
                // R�cup�ration d'infos g�n�rales
                // donnees exemple nn = 141; nt = 8522; nom = 'Acer campestre L.'; nom_ss_auteur = 'Acer campestre';
                $this->info['nn'] = $this->param['masque.nn'];
                $this->info['nt'] = $this->param['masque.nt'];
                $this->info['nom'] = $this->param['masque.ns'].' '.$this->param['masque.au'];
                $this->info['nom_ss_auteur'] = $this->param['masque.ns'];
        }
        
        private function chargerVille() {
                $requete = "SELECT * FROM tb_cel.locations";
                $villes = $this->getBdd()->recupererTous($requete);
                foreach ($villes as $ville) {
                        $this->tab_code_insee[$ville['insee_code']] = $ville;
                }
        }
        
        private function calculerRepartition($inventories) {
                $text = '';
                // Recuperation du positionnement de la carte
                $jpg_txt = file_get_contents(Config::get('Cartes.chemin').str_replace('jpg', 'txt', $this->info['src_map']));
                parse_str($jpg_txt);
                // "Resolution" calculer à partir du fichier $jpg_txt par fuseau
                $p['31T'] = ($X231T - $X131T) / ($X231TUTM - $X131TUTM);
                $p['32T'] = ($X231T - $X131T ) / ($X231TUTM - $X131TUTM);
                $p['30T'] = ($X231T - $X131T ) / ($X231TUTM - $X131TUTM);
                
                $text = array();
                $merge = array();
                foreach ($inventories as $inventory){
                        $utm = $this->cartesFormateur->chercherVille($inventory, $this->tab_code_insee);
                        // Ultime tentative 
                        if (!$utm) {
                                $requete = "SELECT *  FROM tb_cel.locations WHERE name LIKE ".$this->getBdd()->proteger($inventory['location']);
                                $utm = $this->getBdd()->recupererTous($requete);
                        }

                        // Si des doublons sur la commune : pas d'affichage , il vaut mieux ne rien afficher que d'afficher des erreurs.
                        if (sizeof($utm) == 1) {
                                $utm = $utm[0];
                                        
                                // On centre le point au milieu de la maille 10x10 par defaut ...
                                $utm = $this->chercherCentreMaille($utm);
                                        
                                // Calcul coordonnes x, y sur l'image
                                if ($utm['sector']=='31T') {// Fuseau 31 T
                                        $x = (($utm['x_utm'] - $X131TUTM) * $p['31T'] ) + $X131T;
                                        $y = $Y231T - (($utm['y_utm'] - $Y131TUTM) * $p['31T'] );
                                } elseif ($utm['sector'] == '32T') {// Fuseau 32 T : une rotation + translation est appliqu�e
                                        $cosa = cos(deg2rad($angle3132));
                                        $sina = sin(deg2rad($angle3132));
                                        $xp = (($utm['x_utm'] - $X132TUTM) * $cosa) + (($utm['y_utm']- $Y132TUTM) * $sina);
                                        $yp = (-($utm['x_utm'] - $X132TUTM)* $sina) + (($utm['y_utm'] - $Y132TUTM) * $cosa);
                                        $x = ($xp * $p['32T'] ) + $X132T;
                                        $y = $Y232T-($yp * $p['32T'] );
                                } elseif ($utm['sector'] == '30T') {// Fuseau 30 T : une rotation + translation est appliqu�e
                                        $cosa = cos(deg2rad($angle3031));
                                        $sina = sin(deg2rad($angle3031));
                                        $xp = (($utm['x_utm'] - $X130TUTM) * $cosa) + (($utm['y_utm'] - $Y130TUTM) * $sina);
                                        $yp = (-($utm['x_utm'] - $X130TUTM) * $sina) + (($utm['y_utm'] - $Y130TUTM) * $cosa);
                                        $x = ($xp * $p['30T'] ) + $X130T;
                                        $y = $Y230T - ($yp * $p['30T'] );
                                }
                                $x = round($x);
                                $y = round($y);
                                        
                                        
                                if ($utm['name'] != null) {
                                        $name = utf8_decode($utm['name']);
                                }
                                $comment = $this->cartesFormateur->formerCommentaire($utm, $inventory);
                                // On stocke les commentaires pour affichage dans les tooltips
                                // Commentaire deja pr�sent ? : on ajoute � la suite
                                list($text, $merge) = $this->cartesFormateur->stockerCommentaire($text, $merge, $name, $comment, $inventory['collection_code'],$x,$y); 
                        }
                }
                        
                return array($text, $merge);
        }
        

        
        private function formaterCarteVide() {
                $this->cheminCartesBase = Config::get('Cartes.chemin');
                $dest_map['vide'] = 'vide_'.$this->info['src_map'];
                $img['vide'] = imagecreatefromjpeg($this->cheminCartesBase.$this->info['src_map']);
                imagejpeg($img['vide'], Config::get('cache.stockageChemin').$dest_map['vide'], 90);
                $retour =  "<img src=\"".Config::get('cel_dst').$dest_map['vide']."\" style=\"border:none; cursor:crosshair\" alt=\"\" />\n";
                return $retour;
        }
        

        
        
        //+----------------------------------------------------------------------------------------------------------------+
        // sous fonction de calculer répartition
        
        
        private function chercherCentreMaille($utm) {
                $pad = str_repeat ('0' ,(7 - strlen( $utm['x_utm'])));
                $utm['x_utm'] = $pad.$utm['x_utm'];
        
                $pad = str_repeat ('0' ,(7 - strlen( $utm['y_utm'])));
                $utm['y_utm'] = $pad.$utm['y_utm'];
        
                $utm['x_utm'] = substr($utm['x_utm'] ,0,3);
                $utm['x_utm'] = $utm['x_utm'].'5000';
        
                $utm['y_utm'] = substr($utm['y_utm'] ,0,3);
                $utm['y_utm'] = $utm['y_utm'].'5000';
                return $utm;
        }

        //+----------------------------------------------------------------------------------------------------------------+
        // Méthodes d'accès aux objets du Framework
        /**
        * Méthode de connection à la base de données sur demande.
        * Tous les services web n'ont pas besoin de s'y connecter.
        */
        protected function getBdd() {
                if (! isset($this->Bdd)) {
                        $this->Bdd = new Bdd();
                }
        return $this->Bdd;
        }
        

        
}
?>