Rev 2 | 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: bba_droit_mail.fonct.php,v 1.1 2004/09/14 11:12:27 jpm Exp $/*** Fonctions de gestion des mails et des droits de l'application administration de Biblio Bota.** Contient des fonctions de gestion des mails et des droits d'accès.**@package BiblioBota-Administration*@subpackage Fonctions//Auteur original :*@author Jean-Charles GRANGER <tela@vecteur.org>//Autres auteurs :*@author Jean-Pascal MILCENT <jpm@clapas.org>*@copyright Tela-Botanica 2000-2004*@version $Revision: 1.1 $ $Date: 2004/09/14 11:12:27 $// +------------------------------------------------------------------------------------------------------+*/// +------------------------------------------------------------------------------------------------------+// | ENTETE du PROGRAMME |// +------------------------------------------------------------------------------------------------------+/*Mettre ici les inclusions de fichiers*/// +------------------------------------------------------------------------------------------------------+// | LISTE de FONCTIONS |// +------------------------------------------------------------------------------------------------------+/*Mettre ici la liste de fonctions.*//* ***********************************boolean create_mail($from,$to,$to_cc="",$to_bcc="",$subject="",$body,$head="",$format="plain")permet de générer un mail correctement formatéENTREE :- string array $from : adresse de l'expéditeur ; tableau texte à deux entrées $from['name'] et $from['address']- string array $to : adresses des destinataires ; tableau texte à deux entrées $to[$i]['name'] et $to[$i]['address']- string array $to_cc : adresses mises en copies conformes ; tableau texte à deux entrées $to_cc[$i]['name'] et $to_cc[$i]['address']- string array $to_bcc : adresses mises en copies conformes cachées ; tableau texte à deux entrées $to_bcc[$i]['name'] et $to_bcc[$i]['address']- string $subject : sujet du mail- string $body : contenu du mail- string array $head : ajouter des lignes d'en-têtes au mail ; tableau texte à deux entrées $head[$i]['title'] et $head[$i]['value']. Exemple : $head[0]['title']="Reply-To" et $head[0]['value']="\"Tela Botanica\"<accueil@tela-botanica.org>\n"- string $format : format du mail (valeurs possibles : plain [défaut], html)SORTIE : void*********************************** */function create_mail($from,$to,$to_cc="",$to_bcc="",$subject="",$body,$head="",$format="plain"){// on initialise $head avec en un tableau avec une valeur bidon// s'il est vide, afin de pouvoir utiliser in_array plus loinif ($head == ""){$head['novalue'] = "";}// on formate correctement le champ fromif (empty($from['name'])){$from['name'] = $from['address'];}$from_string = "\"".$from['name']."\" <".$from['address'].">";// on créé une chaine contenant les adresses To$to_string = "";if ($to != ""){$to_string = "";$nb_to = count($to);$i = 0;while ($i <= ($nb_to-1)){if (!empty($to[$i]['name'])){$le_nom = $to[$i]['name'];}else{$le_nom = $to[$i]['address'];}$le_mail = $to[$i]['address'];if ($le_mail != ""){$to_string .= "\"$le_nom\" <$le_mail>";if ($i < ($nb_to-1)){$to_string .= ",\n";}else{$to_string .= "\n";}}$i++;}}// on créé une chaine contenant les adresses CC$cc_string = "";if ($to_cc != ""){$cc_string = "Cc: ";$nb_cc = count($to_cc);$i = 0;while ($i <= ($nb_cc-1)){if (!empty($to_cc[$i]['name'])){$le_nom = $to_cc[$i]['name'];}else{$le_nom = $to_cc[$i]['address'];}$le_mail = $to_cc[$i]['address'];if ($le_mail != ""){$cc_string .= "\"$le_nom\" <$le_mail>";if ($i < ($nb_cc-1)){$cc_string .= ",\n";}else{$cc_string .= "\n";}}$i++;}}// on créé une chaine contenant les adresses BCC$bcc_string = "";if ($to_bcc != ""){$bcc_string = "Bcc: ";$nb_bcc = count($to_bcc);$i = 0;while ($i <= ($nb_bcc-1)){if (!empty($to_bcc[$i]['name'])){$le_nom = $to_bcc[$i]['name'];}else{$le_nom = $to_bcc[$i]['address'];}$le_mail = $to_bcc[$i]['address'];if ($le_mail != ""){$bcc_string .= "\"$le_nom\" <$le_mail>";if ($i < ($nb_bcc-1)){$bcc_string .= ",\n";}else{$bcc_string .= "\n";}}$i++;}}// on créé une chaine contenant le format$format_string = "Content-Type: text/$format;\n charset=\"iso-8859-1\"";// on créé une chaine contenant l'en-tête// définition de l'en-tête par defaut$head_def['Return-Path'] = "accueil@tela-botanica.org";$head_def['Organization'] = "Tela Botanica";$head_def['MIME-Version'] = "1.0";$head_def['X-Priority'] = "3";$head_def['X-Mailer'] = "Tela Botanica / PHP";$head_def['Reply-To'] = $from_string;$head_string = "";// on construit l'entete à partir de l'entete par defaut, sauf si une valeur existe dans $head$head_string .= $format_string."\n";foreach($head_def as $key => $value){if ((!isset($head[$key])) && ($value != "")){$head_string .= "$key: $value\n";}}// on ajoute l'entete supplémentaireif ($head != ""){foreach($head as $key => $value){if ($value != ""){$head_string .= "$key: $value\n";}}}$head_string .= $cc_string;$head_string .= $bcc_string;// fin de l'entete// envoi du mail//echo "De : ".$from_string."<BR><BR>".$to_string."<BR><BR>".$cc_string."<BR><BR>".$bcc_string."<BR><BR>Message: ".$body."<BR><BR>".$head_string;return mail($to_string,$subject,$body,$head_string);}/* ***********************************array get_his_rights($table,$appli,$user)récupère les droits d'un utilisateur sur un appliEntrée :- string $table : nom de la table où sont les données d'autorisations- string $appli : nom de l'appli recherché- int $user : id de la personne pour qui on veut récupérer les droitsSortie : ARRAY de la forme :$table['nom_du_droit'] = "level pour ce droit (un entier)"Dans le programme appelant, il suffit de faire if (isser($table['nom_du_droit']))pour savoir un un utilisateur dispose d'un droit particulier*********************************** */function get_his_rights($table,$appli,$user){$query = "select GEN_AUT_DROIT, GEN_AUT_LVL, GEN_AUT_PARAM from $table where GEN_AUT_USER = $user AND GEN_AUT_APPLI = '$appli'";$resu = mysql_query($query) or die("<B>ERREUR !!</B>. Echec de la récupéreration des droits de l'utilisateur : $query");$droits[0] = "";while ($row = mysql_fetch_object($resu)){$nom_droit = $row->GEN_AUT_DROIT;$lvl_droit = $row->GEN_AUT_LVL;$param_droit = $row->GEN_AUT_PARAM;if (($nom_droit != "")&&($lvl_droit >= 0)){$droits[$nom_droit]['lvl'] = $lvl_droit;$droits[$nom_droit]['param'] = $param_droit;}}mysql_free_result($resu);return $droits;}/* +--Fin du code ----------------------------------------------------------------------------------------+** $Log: bba_droit_mail.fonct.php,v $* Revision 1.1 2004/09/14 11:12:27 jpm* Ajout des fonctions de gestion des mails et des droits d'accès de BiblioBota admin.*** +-- Fin du code ----------------------------------------------------------------------------------------+*/?>