Subversion Repositories Sites.gentiana.org

Rev

Rev 83 | Rev 87 | 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: annuaire.fonct.php,v 1.1 2005/03/24 08:46:07 alex Exp $
/**
* Fonctions du module annuaire
*
* Fonctions du module annuaire
*
*@package annuaire
//Auteur original :
*@author                Alexandre Granier <alexandre@tela-botanica.org>
//Autres auteurs :
*@author                Aucun
*@copyright      Tela-Botanica 2000-2004
*@version          $Revision: 1.1 $
// +------------------------------------------------------------------------------------------------------+
*/

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



// +------------------------------------------------------------------------------------------------------+
// |                                                                               LISTE de FONCTIONS                                                                            |
// +------------------------------------------------------------------------------------------------------+

function AUTH_formulaire_login() {
        $res = '';
        
        $url = preg_replace ('/&amp;/', '&', $GLOBALS['ann_url']->getURL()) ;

        $res .= '<p>'.ANN_IDENTIFICATION_PRESENTATION_XHTML.'</p>'."\n" ;
        
        $form = new HTML_QuickForm ('inscription', 'post', $url) ;
        $form->addElement ('text', 'username', ANN_EMAIL) ;
        $form->addElement ('password', 'password', ANN_MOT_DE_PASSE) ;
        $form->addElement('submit', 'valider', ANN_VALIDER);
        $res .= $form->toHTML() ;

        return $res;
}

/** function parcourrirAnnu ()  Affiche l'annuaire à partir d'une lettre
*
*
*
*       @return string HTML
*/
function parcourrirAnnu($event) {

        $res = '<p id="annuaire_alphabet">';

        // Alphabet pour la rechercher par lettre du nom des inscrits
        for ($i = 65 ; $i < 91 ; $i++) {
                $GLOBALS['ann_url']->addQueryString('lettre', chr($i));
                $url_lettre = $GLOBALS['ann_url']->getURL();
                $GLOBALS['ann_url']->removeQueryString('lettre');
                $res .= '<a href="'.$url_lettre.'">'.chr($i).'</a>&nbsp;'."\n";
        }
        $GLOBALS['ann_url']->addQueryString('lettre', 'tous');
        $url_lettre = $GLOBALS['ann_url']->getURL();
        $GLOBALS['ann_url']->removeQueryString('lettre');
        $res .= '<a href="'.$url_lettre.'">'.'Tous'.'</a>'."\n";
        $res .= '</p>'."\n";

        // Si aucune lettre n'est sélectionnée, attribution de la lettre par défaut
        if (empty($_REQUEST['lettre'])) {
                $_REQUEST['lettre'] = ANN_LETTRE_DEFAUT;
        }
        // Si une lettre est sélectionnée
        if (!empty($_REQUEST['lettre'])) {
                $requete = "SELECT ".ANN_ANNUAIRE.".*, ".ANN_TABLE_PAYS.".* FROM ".ANN_ANNUAIRE.",".ANN_TABLE_PAYS." WHERE ".ANN_CHAMPS_PAYS." = ".ANN_GC_ID." ";
                if ($_REQUEST['lettre'] != 'tous') {
                        $requete .= " AND ".ANN_CHAMPS_NOM." LIKE \"".$_REQUEST['lettre']."%\"" ;
                }
                $requete .= " ORDER BY ".ANN_CHAMPS_NOM ;
                
                $res .= listes_inscrit ($requete, $GLOBALS['ann_url']->getURL(), $select, '', $GLOBALS['ann_db'], $niveau = 'pays').
                                carto_texte_cocher().
                                carto_formulaire($_POST['titre'], $_POST['corps']) ;
        }
        return $res;
}

/**
 *  Renvoie le code HTML de la liste des inscrits
 *  en fonction de la requete passé en parametre
 *
 * @return  Renvoie le code HTML de la liste des inscrits
 */
function listes_inscrit ($requete, $url, $select, $argument, &$db, $niveau = 'pays') {
        $resultat = $GLOBALS['ann_db']->query($requete);
        (DB::isError($resultat)) ? die($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) : '';
        
        if ($resultat->numRows() > 0) {
                $res = "<form action=\"$url?mailer=1&amp;lettre=".$_REQUEST['lettre']."\" method=\"post\" name=\"formmail\">\n";
                $res .= '<div id="annuaire" class="conteneur_table">    
                                        <table id="table_inscrit" class="table_cadre">
                                                <colgroup>
                                                        <col />
                                                        <col />
                                                        <col />
                                                        <col />
                                                        <col />
                                                        <col />
                                                        <col />
                                                </colgroup>
                                                        <thead class="entete_fixe">
                                                                <tr>
                                                                        <th>&nbsp;</th>
                                                                        <th>'.ANN_NOM.'</th>
                                                                        <th>'.ANN_PRENOM.'</th>
                                                                        <th>'.ANN_DATE_INS.'</th>
                                                                        <th>'.ANN_CP.'</th>
                                                                        <th>'.ANN_VILLE.'</th>
                                                                        <th>'.ANN_PAYS.'</th>
                                                                </tr>
                                                        </thead>
                                                        <tbody class="contenu_deroulant">';
                $indic = 0;
                $i = 1;
                while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
                        if ($indic==0) {
                                $res.="<tr class=\"ligne_impaire\">\n";
                                $indic=1;
                        } else {
                                $res.="<tr class=\"ligne_paire\">\n";
                                $indic=0;
                        }
                        $res.= "<td><input type=\"checkbox\" name=\"select[]\" value=\"".$ligne[ANN_CHAMPS_MAIL]."\" /></td>\n
                                                        <td>".strtoupper($ligne[ANN_CHAMPS_NOM])."&nbsp;</td>\n
                                                        <td>".str_replace(' - ', '-', ucwords(strtolower(str_replace('-', ' - ', $ligne[ANN_CHAMPS_PRENOM]))))."&nbsp;</td>\n
                                                        <td>".date("d m Y", strtotime($ligne[ANN_CHAMPS_DATE_INS]))."&nbsp;</td>\n
                                                        <td>".$ligne[ANN_CHAMPS_CODE_POSTAL]."&nbsp;</td>\n
                                                        <td>".strtoupper($ligne[ANN_CHAMPS_VILLE])."&nbsp;</td>\n
                                                        <td>".str_replace(' - ', '-', ucwords(strtolower(str_replace('-', ' - ', ($ligne[ANN_GC_NOM])))))."&nbsp;</td>\n" ;
                        $res .= "</tr>\n";
                }
                $res .= "</tbody></table></div>\n";
        } else {
                $res = '<p class="information">Aucun inscrit n\'a de nom commençant par '.$_REQUEST['lettre'].'</p>'."\n";
        }
        return $res;
}


function carto_formulaire ($titre_mail="", $corps = "") {
        $res = '<h2 class="chapo">'.ANN_ENVOYER_MAIL.'</h2>'."\n";
        $res .= '<p class="attention surveillance">'.ANN_SURVEILLANCE.'</p>'."\n";
        $res .= '<p class="information message_a_tous">'.sprintf(ANN_MESSAGE_A_TOUS, '<a href="'.ANN_URL_ACTUALITE.'">'.ANN_ACTUALITE.'</a>').'</p>'."\n";
        $res .= '<table>'."\n".
                        '<tr><td class="texte">'.ANN_SUJET.' :</td>'."\n".
                        '<td><input class="forml" type="text" name="titre_mail" size="60" value="'.$GLOBALS['titre_mail'].'"/></td>'."\n".
                        '</tr><tr><td class="texte" valign="top">'.ANN_MESSAGE.'&nbsp;:&nbsp;</td>'."\n".
                        '<td><textarea class="forml" name="corps" rows="5" cols="60">'.$GLOBALS['corps'].'</textarea></td>'."\n".
                        '</tr><tr><td></td><td align="center">';
        $res .= '<input class="spip_bouton" type="submit" value="'.ANN_ENVOYER.'" />'."\n";
        $res .= '</td>'."\n";
        $res .= '</tr>'."\n";
        $res .= '</table>'."\n";
        $res .= '</form>'."\n";
        return $res;
}


/** function carto_texte_cocher ()
*
*
*       @return string  HTML
*/
function carto_texte_cocher () {
        $res .= '<div class="texte">'.ANN_CHECK_UNCHECK."\n";
        $res .= '&nbsp;<input type="checkbox" name="selecttotal" onclick="javascript:setCheckboxes(\'formmail\');"/>'."\n";
        $res .= '</div>';
        return $res;
}


/** envoie_mail()
 *
 *
 * @return  envoie l'email
 */
function envoie_mail () {
        $requete =      'SELECT '.ANN_CHAMPS_MAIL.' '.
                                'FROM '.ANN_ANNUAIRE.' '.
                                'WHERE '.ANN_CHAMPS_ID.' = "'.$GLOBALS['AUTH']->getAuthData(ANN_CHAMPS_ID).'" ';
        $resultat = $GLOBALS['ann_db']->query($requete);
        if (DB::isError($resultat)) {
                die($resultat->getMessage().'<br />'.$resultat->getDebugInfo());
        }
        $ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
        $entete = 'From: <'.$ligne[ANN_CHAMPS_MAIL].">\n";
        
        $_POST['corps'] .= "\n".ANN_PIED_MESSAGE;
        $_POST['corps'] = stripslashes($_POST['corps']);
        $liste = '';
        foreach ($_POST['select'] as $key => $value) {
                mail($value, stripslashes($_POST['titre_mail']), $_POST['corps'] , $entete);
                $liste .= $value."\n";
        }
        
        $_POST['corps'] .= "\n----------------------------------------------------------------------------";
        $_POST['corps'] .= "\n".ANN_MESSAGE_APPLI."\n" ;
        $_POST['corps'] .= "\n".ANN_MESSAGE_ENVOYE_A." :\n $liste" ;
        
        mail(ANN_MAIL_ADMIN, stripslashes($_POST['titre_mail']), $_POST['corps'], $entete);
        $_POST['corps'] = '';
        $_POST['titre_mail'] = '';
        return '<div class="information">'.ANN_MAIL_ENVOYER.'</div>' ;
}
?>