Subversion Repositories eFlore/Archives.eflore-consultation-v2

Rev

Rev 159 | 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.3                                                                                      |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
// +------------------------------------------------------------------------------------------------------+
// | This file is part of eFlore-consultation.                                                            |
// |                                                                                                      |
// | 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: eflore_recherche_nomenclature.inc.php,v 1.9 2005-03-15 12:57:16 jpm Exp $
/**
* Affichage du moteur de recherche nomenclatural et de ses résultats.
*
* Ce script fournit le code html correspondant aux moteurs de recherche nomenclatural et ses résultats.
*
*@package eFlore
//Auteur original :
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
//Autres auteurs :
*@author        Aucun
*@copyright     Tela-Botanica 2000-2004
*@version       $Revision: 1.9 $ $Date: 2005-03-15 12:57:16 $
// +------------------------------------------------------------------------------------------------------+
*/

// +------------------------------------------------------------------------------------------------------+
// |                                            ENTÊTE du PROGRAMME                                       |
// +------------------------------------------------------------------------------------------------------+

function remplacerUrlFicheNom($arguments) {
    $GLOBALS['_EFLORE_']['url']->addQueryString(EFLORE_LG_URL_ACTION, EFLORE_LG_URL_ACTION_FICHE);
    $GLOBALS['_EFLORE_']['url']->addQueryString(EFLORE_LG_URL_ONGLET, EFLORE_LG_URL_ONGLET_SYNTHESE);
    $GLOBALS['_EFLORE_']['url']->addQueryString(EFLORE_LG_URL_NN, $arguments[0]);
    $GLOBALS['_EFLORE_']['url']->addQueryString(EFLORE_LG_URL_NVP, $arguments[1]);
    return $GLOBALS['_EFLORE_']['url']->getURL();
}

// +------------------------------------------------------------------------------------------------------+
// |                                            CORPS du PROGRAMME                                        |
// +------------------------------------------------------------------------------------------------------+
$sortie .= '<h2>'.EFLORE_LG_RECH_NOM_TITRE.'</h2>';

// --------------------------------------------------------------------------------------------------------
// Création du formulaire
// Ajout du paramêtre action à l'url courante.
$GLOBALS['_EFLORE_']['url']->addQueryString(EFLORE_LG_URL_ACTION, EFLORE_LG_URL_ACTION_RECH_NOM);
// Notes : Quickform semble remplacer les & des &amp; à nouveau par des &amp; solution utiliser str_replace()...
$eflore_form = new HTML_QuickForm('eflore_form_nomenclature', 'post', str_replace('&amp;', '&', $GLOBALS['_EFLORE_']['url']->getUrl()));
$tab_index = EFLORE_RECH_NOM_FORM_TAB;
$eflore_squelette =& $eflore_form->defaultRenderer();
$eflore_squelette->setFormTemplate("\n".'<form{attributes}>'."\n".'{content}'."\n".'</form>');
$eflore_squelette->setElementTemplate( '<li>'."\n".
                                '{label}'."\n".
                                '{element}'."\n".
                                '<!-- BEGIN required --><span class="symbole_obligatoire">'.EFLORE_LG_FORM_SYMBOLE_OBLIGATOIRE.'</span><!-- END required -->'."\n".
                                '<!-- BEGIN error --><span class="erreur">{error}</span><!-- END error -->'."\n".
                                '</li>'."\n");
$eflore_form->accept($eflore_squelette);
$eflore_form->removeAttribute('name');

$partie_menu_debut = '<fieldset>'."\n".'<legend>'.EFLORE_LG_RECH_NOM_FORM_TITRE.'</legend><ul>'."\n";
$eflore_form->addElement('html', $partie_menu_debut);

$id = 'eflore_nom';
$aso_attributs = array( 'id'=>$id, 'class' => 'champ', 'tabindex' => $tab_index++, 
                        'size' => EFLORE_RECH_NOM_FORM_NOM_SIZE, 
                        'maxlength' => EFLORE_RECH_NOM_FORM_NOM_MAXLENGTH,
                        'onclick' => "javascript: this.value='';");
$label = '<label for="'.$id.'">'.EFLORE_LG_RECH_NOM_FORM_NOM.'</label>';
$eflore_form->addElement('text', $id, $label, $aso_attributs);

$liste_type_nom_debut = '<li><ul>'."\n";
$eflore_form->addElement('html', $liste_type_nom_debut);

$id = 'eflore_type_nom_scientifique';
$name = 'eflore_type_nom';
$valeur = 'nom_scientifique';
$aso_attributs = array( 'id'=> $id, 'tabindex' => $tab_index++);
$label = '';
$eflore_form->addElement('radio', $name, $label, EFLORE_LG_RECH_NOM_FORM_TYPE_NOM_SCI, $valeur, $aso_attributs);

$id = 'eflore_type_nom_vernaculaire';
$name = 'eflore_type_nom';
$valeur = 'nom_vernaculaire';
$aso_attributs = array( 'id'=> $id, 'tabindex' => $tab_index++);
$label = '';
$eflore_form->addElement('radio', $name, $label, EFLORE_LG_RECH_NOM_FORM_TYPE_NOM_VER, $valeur, $aso_attributs);

if (isset($_REQUEST[$name])) {
    switch ($_REQUEST[$name]) {
        case 'nom_scientifique' :
            $eflore_form->setDefaults(array($name => 'nom_scientifique'));
            break;
        case 'nom_vernaculaire' :
            $eflore_form->setDefaults(array($name => 'nom_vernaculaire'));
            break;
    }
} else {
    $eflore_form->setDefaults(array($name => 'nom_scientifique'));
}

$liste_type_nom_fin = '</ul></li>'."\n";
$eflore_form->addElement('html', $liste_type_nom_fin);

$id = 'eflore_valider_nom';
$aso_attributs = array('id'=> $id, 'class' => 'champ', 'tabindex' => $tab_index++);
$eflore_form->addElement('submit', $id, EFLORE_LG_RECH_NOM_FORM_VALIDER, $aso_attributs);

$partie_entete_fin = "\n".'</ul></fieldset>';
$eflore_form->addElement('html', $partie_entete_fin);

// Instanciation avec les valeur par défaut
if (isset($_SESSION['_EFLORE_']['rechercher'])) {
    $eflore_form->setDefaults($_SESSION['_EFLORE_']['rechercher']);
}

// Transformation en XHTML du formulaire
$sortie .= $eflore_form->toHTML()."\n";

// --------------------------------------------------------------------------------------------------------
// Lancement de la recherche
if (isset($_REQUEST['eflore_nom']) && $_REQUEST['eflore_nom'] != '' && !eregi("^%{1,}$", $_REQUEST['eflore_nom']) ) {
    // Formatage de la chaine à rechercher
    $_REQUEST['eflore_nom'] = '%'.str_replace(' ', '%', $_REQUEST['eflore_nom']).'%';
    if ($_REQUEST['eflore_type_nom'] == 'nom_scientifique') {
        // Recherche sur les noms scientifiques
        $contenu = file_get_contents(sprintf(EFLORE_URL_LISTE_NOM_LATIN, rawurlencode($_REQUEST['eflore_nom'])));
        
        //Analyse du squelette
        require_once 'HTML/Template/IT.php';
        $squelette = new HTML_Template_IT();
        $squelette->setTemplate($contenu, FALSE, FALSE);
        
        // Indique l'url pour obtenir fiche d'un nom
        $squelette->setCurrentBlock('corps');
        // Ajout du paramêtre action à l'url courante.
        $GLOBALS['_EFLORE_']['url']->addQueryString(EFLORE_LG_URL_ACTION, EFLORE_LG_URL_ACTION_FICHE);
        $GLOBALS['_EFLORE_']['url']->addQueryString(EFLORE_LG_URL_ONGLET, EFLORE_LG_URL_ONGLET_SYNTHESE);
        $GLOBALS['_EFLORE_']['url']->addQueryString(EFLORE_LG_URL_NN, '');
        $squelette->setVariable('UrlFicheNom', $GLOBALS['_EFLORE_']['url']->getURL());
        $squelette->parseCurrentBlock('corps');
        
        // Récupère le bloc "corps"
        $sortie .= $squelette->get('corps');
    } else if ($_REQUEST['eflore_type_nom'] == 'nom_vernaculaire') {
        // Recherche sur les noms vernaculaires
        $contenu = file_get_contents(sprintf(EFLORE_URL_LISTE_NOM_VERNA, rawurlencode($_REQUEST['eflore_nom'])));
        
        //Analyse du squelette
        require_once 'HTML/Template/ITX.php';
        $squelette = new HTML_Template_ITX();
        $squelette->setTemplate($contenu, FALSE, FALSE);
        
        // Indique l'url pour obtenir fiche d'un nom
        $squelette->setCurrentBlock('corps');
        $squelette->setCallbackFunction('UrlFicheNom', 'remplacerUrlFicheNom');
        $squelette->performCallback();
        $squelette->parseCurrentBlock('corps');
        
        // Récupère le bloc "corps"
        $sortie .= $squelette->get('corps');
        
    }
}

/* +--Fin du code ----------------------------------------------------------------------------------------+
*
* $Log: not supported by cvs2svn $
* Revision 1.8  2005/02/28 15:38:47  jpm
* Correction erreur due à un changement de nom.
*
* Revision 1.7  2005/02/23 12:39:27  jpm
* Correction bogue lié à QuickForm.
*
* Revision 1.6  2005/02/22 19:27:10  jpm
* Changement de nom de variables.
* Suppression de l'attribut nam de la balise form via une méthode de HTML_Common.
*
* Revision 1.5  2005/02/22 17:43:53  jpm
* Suppression de référence posant problème.
*
* Revision 1.4  2005/02/15 13:00:23  jpm
* Ajout d'un test pour initialiser une variable.
*
* Revision 1.3  2005/01/28 19:47:55  jpm
* Ajout de la recherche pour les taxons.
*
* Revision 1.2  2005/01/03 19:44:40  jpm
* Ajout de la gestion de l'action "fiche".
*
* Revision 1.1  2004/12/23 20:05:17  jpm
* Début prise en maine eflore-consultation.
*
*
* +-- Fin du code ----------------------------------------------------------------------------------------+
*/
?>