Subversion Repositories Applications.bazar

Rev

Rev 469 | 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 4.1                                                                                      |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
// +------------------------------------------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or                                        |
// | modify it under the terms of the GNU Lesser General Public                                           |
// | License as published by the Free Software Foundation; either                                         |
// | version 2.1 of the License, or (at your option) any later version.                                   |
// |                                                                                                      |
// | This library 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                                    |
// | Lesser General Public License for more details.                                                      |
// |                                                                                                      |
// | You should have received a copy of the GNU Lesser General Public                                     |
// | License along with this library; if not, write to the Free Software                                  |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: bazar.carte_google.php,v 1.9 2008-10-29 15:51:36 alexandre_tb Exp $
/**
*
*@package bazar
//Auteur original :
*@author        Alexandre GRANIER <alexandre@tela-botanica.org>
//Autres auteurs :
*@copyright     Tela-Satanica 2000-2007
*@version       $Revision: 1.9 $
// +------------------------------------------------------------------------------------------------------+
*/

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


include_once 'configuration/baz_config.inc.php';
include_once BAZ_CHEMIN_APPLI.'bibliotheque/bazar.fonct.php';
// Inclusion d'une classe personnalise si elle existe

// Le fichier de script de google map
//GEN_stockerFichierScript('googleMapScript', 'http://maps.google.com/maps?file=api&amp;v=2&amp;key='.BAZ_GOOGLE_KEY);
GEN_stockerFichierScript('googleMapScript', "http://maps.googleapis.com/maps/api/js?sensor=false&key=".BAZ_GOOGLE_KEY);

// Le fichier jquery pour le date picker
//GEN_stockerFichierScript('jquery', 'api/js/jquery/jquery.js');
//GEN_stockerFichierScript('jquery', 'http://code.jquery.com/jquery-latest.js');
GEN_stockerFichierScript('jquery_date_picker', 'api/js/jquery/ui.datepicker.js');
GEN_stockerFichierScript('jquery_date_picker_fr', 'api/js/jquery/ui.datepicker-fr.js');

GEN_stockerStyleExterne( 'jquery_date_picker_style', 'api/js/jquery/ui.datepicker.css');


if (defined('PAP_VERSION')) { //si on est dans Papyrus
    GEN_stockerStyleExterne( 'bazar_interne', 'reseau/bazar/bazar.interne.css');
}
$GLOBALS['_BAZAR_']['id_typeannonce']=$GLOBALS['_GEN_commun']['info_application']->id_nature;
$GLOBALS['_BAZAR_']['categorie_nature']=$GLOBALS['_GEN_commun']['info_application']->categorie_nature;
// requete sur le bazar pour recuperer les evenements

$requete_where = '';
foreach ($_POST as $cle => $valeur) {
    if (preg_match ('/bazar_filtre_([0-9]+)/', $cle, $sousmotif)) {
        $variable = $sousmotif[0] ;
        if ($_POST[$variable] != '*') {
            $requete_where = ' and bfvl_ce_liste="'.$sousmotif[1].'" and bfvl_valeur="'.$_POST[$variable].'" ';   
        } else {
            $requete_where = ' and bfvl_ce_liste="'.$sousmotif[1].'" ';
        }
    } else {
       
    }
}

if (isset($_POST['date_debut']) && $_POST['date_debut'] != '') {
   
    $requete_date = '((bf_date_debut_evenement <= "'.date('Y-m-d', strtotime($_POST['date_fin'])).'" and bf_date_debut_evenement >="'.date('Y-m-d', strtotime($_POST['date_debut'])).'" )' .
            ' or (bf_date_fin_evenement >="'.date('Y-m-d', strtotime($_POST['date_debut'])).'" and bf_date_fin_evenement <="'.date('Y-m-d', strtotime($_POST['date_fin'])).'")' .
                    ' or bf_date_debut_evenement <= "'.date('Y-m-d', strtotime($_POST['date_debut'])).'" and bf_date_fin_evenement >= "'.date('Y-m-d', strtotime($_POST['date_fin'])).'")  ';
} else {
    $requete_date = '((bf_date_debut_validite_fiche <= now( ) AND bf_date_fin_validite_fiche >= now( ))
    OR (bf_date_fin_validite_fiche = "0000-00-00" AND date_add( bf_date_fin_evenement, INTERVAL 15 DAY ) > now( )) )';
}

$requete = 'SELECT blv_label,blv_valeur, bazar_fiche.*'.
 ' FROM bazar_fiche, bazar_fiche_valeur_liste , bazar_liste_valeurs'.
 ' WHERE   bf_statut_fiche =1 and bf_id_fiche=bfvl_ce_fiche'.
 ' and  bfvl_ce_liste=blv_ce_liste and bfvl_ce_liste=31 and bfvl_valeur=blv_valeur '.$requete_where.' and '.
 $requete_date;
$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete);

if (DB::isError($resultat)) {
        return BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage().'<br />'.$resultat->getDebugInfo(), $requete);echo $requete;
}

// Le code complique avec ces 2 tableaux sert
// a ne pas mettre 2 points aux memes coordonnees
// car dans ce cas la seul le second serait visible

$donnees = array();

if ($resultat->numRows() != 0) {
    $script_marker = '';
    $couleur_drapeau = array ( 1 => 'bleu', 2 => 'vert', 3 => 'orange', 4 => 'rose');

    while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
        if ($ligne['bf_latitude'] == 0 && $ligne['bf_longitude'] == 0) continue;
        $cle = $ligne['bf_latitude'].'-'.$ligne['bf_longitude'];
        $donnees[$cle][] = $ligne;
    }

    foreach ($donnees as $valeur) {
        // cas un : une seule entree pour le point de coordonnees
        if (count ($valeur) == 1) {
            $chaine = $valeur[0];

                        $script_marker .= 'var icon = {' .
                                'url: "reseau/bazar/images/drapeau_'.$couleur_drapeau[$chaine['blv_valeur']].'.png",
                                size: new google.maps.Size(16,16),
                                anchor: new google.maps.Point(6,16)'
                        . '};' . "\n";

              $script_marker .= "\t".'point = new google.maps.LatLng('.$chaine['bf_latitude'].','.$chaine['bf_longitude'].');'."\n"
                ."\t".'createMarker(point, \''.'<div class="BAZ_cadre_map">'.
                preg_replace ('/\n/', '', str_replace ("\r\n", '',
                    str_replace ("'", "\'", baz_voir_fiche(0, $chaine['bf_id_fiche'])))).'</div>\',icon, new google.maps.Size(5,1));'."\n";

        } else { // Cas 2 plusieurs entrees
            $tableau_id = array();
            foreach ($valeur as $val) {
                array_push ($tableau_id, $val['bf_id_fiche']);
            }

                        $script_marker .= 'var icon = {' .
                                'url: "reseau/bazar/images/drapeau_'.$couleur_drapeau[$chaine['blv_valeur']].'.png",
                                size: new google.maps.Size(16,16),
                                anchor: new google.maps.Point(6,3)'
                        . '};' . "\n";

            $script_marker .= "\t".'point = new google.maps.LatLng('.$val['bf_latitude'].','.$val['bf_longitude'].');'."\n"
                ."\t".'createMarker(point, \''.'<div class="BAZ_cadre_map">'.
                preg_replace ('/\n/', '', str_replace ("\r\n", '',
                    str_replace ("'", "\'", baz_voir_fiches(0, $tableau_id)))).'</div>\', icon, new google.maps.Size(5,1));'."\n";
        }
    }
} else {
    $script_marker = '';
}

$script = '    // Variables globales
    var map = null;
    // cette fonction peut d�j� �tre pr�sente
        if (typeof(addListener) != \'function\') {
                // fonction portable pour ajout de listeners
                function addListener(element, baseName, handler)
                {
                        if (element.addEventListener) {
                                element.addEventListener(baseName, handler, false) ;
                        } else if (element.attachEvent) {
                                element.attachEvent(\'on\'+baseName, handler) ;
                        }
                }
        }               
        addListener(window,\'load\',loadMap) ;';

if (BAZ_GOOGLE_MAXIMISE_TAILLE) $script .= '
    // Pour gerer la taille  
    var winW = 630, winH = 560;
    var deltaH = 220;
    var deltaW = 270;

    function setWinHW() {
        if (window.innerHeight) {
                        winW = window.innerWidth  - deltaW;
                        winH = window.innerHeight - deltaH;
        } else {
                        winW = document.documentElement.offsetWidth  - 20 - deltaW;
                        winH = document.documentElement.offsetHeight - 20 - deltaH ; 
        }

        var me = document.getElementById("map");
        if (me != null) {
            me.style.width= \'\' + winW + \'px\';
            me.style.height= \'\' + winH + \'px\';
        }
    }

    window.onresize = function () {
        setWinHW();
        if (map)  map.checkResize();
    }';
$script .= '
    
    function createMarker(point, chaine, icon, offset) {
                var marker = new google.maps.Marker({
                        position: point,
                        map: map,
                        icon: icon
                });
                google.maps.event.addListener(marker, "click", function() {
                var infowindow = new google.maps.InfoWindow({
                                content: chaine,
                                pixelOffset: offset
                        });
                        infowindow.open(map, marker);
                });

                return marker;
        }
    function loadMap() {';
if (BAZ_GOOGLE_MAXIMISE_TAILLE) $script .= '
    setWinHW();';
$script .= '
    var optionsGoogleMapsv3 = {
                // On centre la carte sur le languedoc roussillon
                center: new google.maps.LatLng(' . BAZ_GOOGLE_CENTRE_LAT . ', ' . BAZ_GOOGLE_CENTRE_LON . '),
                zoom: ' . BAZ_GOOGLE_ALTITUDE . ',
                mapTypeId: "OSM",
                mapTypeControlOptions: {
                        mapTypeIds: ["OSM", 
                                google.maps.MapTypeId.ROADMAP,
                                google.maps.MapTypeId.HYBRID,
                                google.maps.MapTypeId.SATELLITE,
                                google.maps.MapTypeId.TERRAIN]
                },
                mapTypeControl: true,
                scaleControl: true
        };

    map = new google.maps.Map(document.getElementById("map"), optionsGoogleMapsv3);
        map.mapTypes.set("OSM", new google.maps.ImageMapType({
                getTileUrl: function(coord, zoom) {
                        return "http://osm.tela-botanica.org/tile/" + // cache de tuiles avec nginx
                        zoom + "/" + coord.x + "/" + coord.y + ".png";
                },
                tileSize: new google.maps.Size(256, 256),
                isPng: true,
                alt: "OpenStreetMap",
                name: "OSM",
                maxZoom: 19
        }));';

if (BAZ_GOOGLE_FOND_KML != '') {
                $script .= 'geoXml = new google.maps.KmlLayer(' . BAZ_GOOGLE_FOND_KML . ');';
        }

        $script .= $script_marker;
        if (BAZ_GOOGLE_FOND_KML != '') {
                $script .= 'geoXml.setMap(map);';
        }

$script .= '};';

GEN_stockerCodeScript($script);
// On ajoute l attribut load a la balise body
//GEN_AttributsBody('onload', 'load()');
 


function afficherContenuCorps() {
        
        include_once BAZ_CHEMIN_APPLI.'bibliotheque/bazarTemplate.class.php';
    $modele = new bazarTemplate($GLOBALS['_BAZAR_']['db']);
    $html = $modele->getTemplate(BAZ_TEMPLATE_ACCUEIL_CARTE_GOOGLE, $GLOBALS['_BAZAR_']['langue'], $GLOBALS['_BAZAR_']['categorie_nature']);
    if (PEAR::isError($html)) return $html->getMessage();
    
    // nettoyage url 
    $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ID_FICHE) ;
    $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION) ;
    $html = bazar::getFormulaireFiltre($html) ;
   
        $res = str_replace ('{CARTE}', '<div id="map" style="width: '.BAZ_GOOGLE_IMAGE_LARGEUR.
                                                        'px; height: '.BAZ_GOOGLE_IMAGE_HAUTEUR.'px"></div>', $html);

        return $res;
}


/* +--Fin du code ----------------------------------------------------------------------------------------+
*
* $Log: not supported by cvs2svn $
* Revision 1.5.2.3  2008-01-29 09:41:11  alexandre_tb
* utilisation des constantes BAZ_GOOGLE_FOND_KML
*
* Revision 1.5.2.2  2007-12-14 09:57:15  alexandre_tb
* utilisation des constantes de la carte google
*
* Revision 1.5.2.1  2007-12-04 16:19:32  jp_milcent
* Ajout de la prise en charge de l'applette body_attributs
*
* Revision 1.5  2007-10-01 12:07:03  alexandre_tb
* utilisation de constantes du fichier de conf pour centrer la carte
*
* Revision 1.4  2007-08-27 12:27:34  alexandre_tb
* mise en place d un icone personnalise
* et de l affichage de plusieurs donnees sur un meme point
*
* Revision 1.3  2007-07-04 10:08:41  alexandre_tb
* Appel du template carte_google
*
* Revision 1.2  2007-06-13 10:02:47  alexandre_tb
* le carte s adapte a la taille du conteneur
*
* Revision 1.1  2007-06-04 15:26:57  alexandre_tb
* version initiale
*
* +-- Fin du code ----------------------------------------------------------------------------------------+
*/