Subversion Repositories eFlore/Applications.bibliobota

Rev

Rev 2 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 30
1
<?php
1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
3
// +------------------------------------------------------------------------------------------------------+
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
10
// | License as published by the Free Software Foundation; either                                         |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | Lesser General Public License for more details.                                                      |
16
// | Lesser General Public License for more details.                                                      |
17
// |                                                                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
19
// | License along with this library; if not, write to the Free Software                                  |
19
// | License along with this library; if not, write to the Free Software                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
21
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: bba_droit_mail.fonct.php,v 1.1 2005-11-23 10:22:25 jp_milcent Exp $
22
// CVS : $Id: bba_droit_mail.fonct.php,v 1.1 2004/09/14 11:12:27 jpm Exp $
23
/**
23
/**
24
* Fonctions de gestion des mails et des droits de l'application administration de Biblio Bota.
24
* Fonctions de gestion des mails et des droits de l'application administration de Biblio Bota.
25
*
25
*
26
* Contient des fonctions de gestion des mails et des droits d'accès.
26
* Contient des fonctions de gestion des mails et des droits d'accès.
27
*
27
*
28
*@package BiblioBota-Administration
28
*@package BiblioBota-Administration
29
*@subpackage Fonctions
29
*@subpackage Fonctions
30
//Auteur original :
30
//Auteur original :
31
*@author        Jean-Charles GRANGER <tela@vecteur.org>
31
*@author        Jean-Charles GRANGER <tela@vecteur.org>
32
//Autres auteurs :
32
//Autres auteurs :
33
*@author        Jean-Pascal MILCENT <jpm@clapas.org>
33
*@author        Jean-Pascal MILCENT <jpm@clapas.org>
34
*@copyright     Tela-Botanica 2000-2004
34
*@copyright     Tela-Botanica 2000-2004
35
*@version       $Revision: 1.1 $ $Date: 2005-11-23 10:22:25 $
35
*@version       $Revision: 1.1 $ $Date: 2004/09/14 11:12:27 $
36
// +------------------------------------------------------------------------------------------------------+
36
// +------------------------------------------------------------------------------------------------------+
37
*/
37
*/
38
 
38
 
39
// +------------------------------------------------------------------------------------------------------+
39
// +------------------------------------------------------------------------------------------------------+
40
// |                                            ENTETE du PROGRAMME                                       |
40
// |                                            ENTETE du PROGRAMME                                       |
41
// +------------------------------------------------------------------------------------------------------+
41
// +------------------------------------------------------------------------------------------------------+
42
                                    /*Mettre ici les inclusions de fichiers*/                             
42
                                    /*Mettre ici les inclusions de fichiers*/                             
43
 
43
 
44
                    
44
                    
45
// +------------------------------------------------------------------------------------------------------+
45
// +------------------------------------------------------------------------------------------------------+
46
// |                                           LISTE de FONCTIONS                                         |
46
// |                                           LISTE de FONCTIONS                                         |
47
// +------------------------------------------------------------------------------------------------------+
47
// +------------------------------------------------------------------------------------------------------+
48
                                        /*Mettre ici la liste de fonctions.*/
48
                                        /*Mettre ici la liste de fonctions.*/
49
/* ***********************************
49
/* ***********************************
50
boolean create_mail($from,$to,$to_cc="",$to_bcc="",$subject="",$body,$head="",$format="plain")
50
boolean create_mail($from,$to,$to_cc="",$to_bcc="",$subject="",$body,$head="",$format="plain")
51
permet de générer un mail correctement formaté
51
permet de générer un mail correctement formaté
52
 
52
 
53
ENTREE :
53
ENTREE :
54
- string array $from : adresse de l'expéditeur ; tableau texte à deux entrées $from['name'] et $from['address']
54
- string array $from : adresse de l'expéditeur ; tableau texte à deux entrées $from['name'] et $from['address']
55
- string array $to : adresses des destinataires ; tableau texte à deux entrées $to[$i]['name'] et $to[$i]['address']
55
- string array $to : adresses des destinataires ; tableau texte à deux entrées $to[$i]['name'] et $to[$i]['address']
56
- string array $to_cc : adresses mises en copies conformes ; tableau texte à deux entrées $to_cc[$i]['name'] et $to_cc[$i]['address']
56
- string array $to_cc : adresses mises en copies conformes ; tableau texte à deux entrées $to_cc[$i]['name'] et $to_cc[$i]['address']
57
- 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']
57
- 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']
58
- string $subject : sujet du mail
58
- string $subject : sujet du mail
59
- string $body : contenu du mail
59
- string $body : contenu du mail
60
- 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"
60
- 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"
61
- string $format : format du mail (valeurs possibles : plain [défaut], html)
61
- string $format : format du mail (valeurs possibles : plain [défaut], html)
62
 
62
 
63
SORTIE : void
63
SORTIE : void
64
    *********************************** */
64
    *********************************** */
65
 
65
 
66
function create_mail($from,$to,$to_cc="",$to_bcc="",$subject="",$body,$head="",$format="plain")
66
function create_mail($from,$to,$to_cc="",$to_bcc="",$subject="",$body,$head="",$format="plain")
67
{
67
{
68
    // on initialise $head avec en un tableau avec une valeur bidon
68
    // on initialise $head avec en un tableau avec une valeur bidon
69
    // s'il est vide, afin de pouvoir utiliser in_array plus loin
69
    // s'il est vide, afin de pouvoir utiliser in_array plus loin
70
    if ($head == ""){
70
    if ($head == ""){
71
        $head['novalue'] = "";
71
        $head['novalue'] = "";
72
    }
72
    }
73
 
73
 
74
    // on formate correctement le champ from
74
    // on formate correctement le champ from
75
    if (empty($from['name'])){
75
    if (empty($from['name'])){
76
        $from['name'] = $from['address'];
76
        $from['name'] = $from['address'];
77
    }
77
    }
78
    $from_string = "\"".$from['name']."\" <".$from['address'].">";
78
    $from_string = "\"".$from['name']."\" <".$from['address'].">";
79
 
79
 
80
    // on créé une chaine contenant les adresses To
80
    // on créé une chaine contenant les adresses To
81
 
81
 
82
    $to_string = "";
82
    $to_string = "";
83
    if ($to != ""){
83
    if ($to != ""){
84
        $to_string = "";
84
        $to_string = "";
85
        $nb_to = count($to);
85
        $nb_to = count($to);
86
        $i = 0;
86
        $i = 0;
87
        while ($i <= ($nb_to-1)){
87
        while ($i <= ($nb_to-1)){
88
            if (!empty($to[$i]['name'])){
88
            if (!empty($to[$i]['name'])){
89
                $le_nom = $to[$i]['name'];
89
                $le_nom = $to[$i]['name'];
90
            }
90
            }
91
            else{
91
            else{
92
                $le_nom = $to[$i]['address'];
92
                $le_nom = $to[$i]['address'];
93
            }
93
            }
94
            
94
            
95
            $le_mail = $to[$i]['address'];
95
            $le_mail = $to[$i]['address'];
96
            
96
            
97
            if ($le_mail != ""){
97
            if ($le_mail != ""){
98
                $to_string .= "\"$le_nom\" <$le_mail>";
98
                $to_string .= "\"$le_nom\" <$le_mail>";
99
                if ($i < ($nb_to-1)){
99
                if ($i < ($nb_to-1)){
100
                    $to_string .= ",\n";
100
                    $to_string .= ",\n";
101
                }
101
                }
102
                else{
102
                else{
103
                    $to_string .= "\n";
103
                    $to_string .= "\n";
104
                }
104
                }
105
            }
105
            }
106
            $i++;
106
            $i++;
107
        }
107
        }
108
    }
108
    }
109
 
109
 
110
    // on créé une chaine contenant les adresses CC
110
    // on créé une chaine contenant les adresses CC
111
 
111
 
112
    $cc_string = "";
112
    $cc_string = "";
113
    if ($to_cc != ""){
113
    if ($to_cc != ""){
114
        $cc_string = "Cc: ";
114
        $cc_string = "Cc: ";
115
        
115
        
116
        $nb_cc = count($to_cc);
116
        $nb_cc = count($to_cc);
117
        $i = 0;
117
        $i = 0;
118
        
118
        
119
        while ($i <= ($nb_cc-1)){
119
        while ($i <= ($nb_cc-1)){
120
            if (!empty($to_cc[$i]['name'])){
120
            if (!empty($to_cc[$i]['name'])){
121
                $le_nom = $to_cc[$i]['name'];
121
                $le_nom = $to_cc[$i]['name'];
122
            }
122
            }
123
            else{
123
            else{
124
                $le_nom = $to_cc[$i]['address'];
124
                $le_nom = $to_cc[$i]['address'];
125
            }
125
            }
126
            
126
            
127
            $le_mail = $to_cc[$i]['address'];
127
            $le_mail = $to_cc[$i]['address'];
128
            
128
            
129
            if ($le_mail != ""){
129
            if ($le_mail != ""){
130
                $cc_string .= "\"$le_nom\" <$le_mail>";
130
                $cc_string .= "\"$le_nom\" <$le_mail>";
131
                if ($i < ($nb_cc-1)){
131
                if ($i < ($nb_cc-1)){
132
                    $cc_string .= ",\n";
132
                    $cc_string .= ",\n";
133
                }
133
                }
134
                else{
134
                else{
135
                    $cc_string .= "\n";
135
                    $cc_string .= "\n";
136
                }
136
                }
137
            }
137
            }
138
            $i++;
138
            $i++;
139
        }
139
        }
140
    }
140
    }
141
    
141
    
142
    // on créé une chaine contenant les adresses BCC
142
    // on créé une chaine contenant les adresses BCC
143
    
143
    
144
    $bcc_string = "";
144
    $bcc_string = "";
145
    if ($to_bcc != ""){
145
    if ($to_bcc != ""){
146
        $bcc_string = "Bcc: ";
146
        $bcc_string = "Bcc: ";
147
        
147
        
148
        $nb_bcc = count($to_bcc);
148
        $nb_bcc = count($to_bcc);
149
        
149
        
150
        $i = 0;
150
        $i = 0;
151
        
151
        
152
        while ($i <= ($nb_bcc-1)){
152
        while ($i <= ($nb_bcc-1)){
153
            if (!empty($to_bcc[$i]['name'])){
153
            if (!empty($to_bcc[$i]['name'])){
154
                $le_nom = $to_bcc[$i]['name'];
154
                $le_nom = $to_bcc[$i]['name'];
155
            }
155
            }
156
            else{
156
            else{
157
                $le_nom = $to_bcc[$i]['address'];
157
                $le_nom = $to_bcc[$i]['address'];
158
            }
158
            }
159
            
159
            
160
            $le_mail = $to_bcc[$i]['address'];
160
            $le_mail = $to_bcc[$i]['address'];
161
            
161
            
162
            if ($le_mail != ""){
162
            if ($le_mail != ""){
163
                $bcc_string .= "\"$le_nom\" <$le_mail>";
163
                $bcc_string .= "\"$le_nom\" <$le_mail>";
164
                if ($i < ($nb_bcc-1)){
164
                if ($i < ($nb_bcc-1)){
165
                    $bcc_string .= ",\n";
165
                    $bcc_string .= ",\n";
166
                }
166
                }
167
                else{
167
                else{
168
                    $bcc_string .= "\n";
168
                    $bcc_string .= "\n";
169
                }
169
                }
170
            }
170
            }
171
            $i++;
171
            $i++;
172
        }
172
        }
173
    }
173
    }
174
    
174
    
175
    // on créé une chaine contenant le format
175
    // on créé une chaine contenant le format
176
    $format_string = "Content-Type: text/$format;\n charset=\"iso-8859-1\"";
176
    $format_string = "Content-Type: text/$format;\n charset=\"iso-8859-1\"";
177
    
177
    
178
    // on créé une chaine contenant l'en-tête
178
    // on créé une chaine contenant l'en-tête
179
    
179
    
180
    // définition de l'en-tête par defaut
180
    // définition de l'en-tête par defaut
181
    $head_def['Return-Path'] = "accueil@tela-botanica.org";
181
    $head_def['Return-Path'] = "accueil@tela-botanica.org";
182
    $head_def['Organization'] = "Tela Botanica";
182
    $head_def['Organization'] = "Tela Botanica";
183
    $head_def['MIME-Version'] = "1.0";
183
    $head_def['MIME-Version'] = "1.0";
184
    $head_def['X-Priority'] = "3";
184
    $head_def['X-Priority'] = "3";
185
    $head_def['X-Mailer'] = "Tela Botanica / PHP";
185
    $head_def['X-Mailer'] = "Tela Botanica / PHP";
186
    $head_def['Reply-To'] = $from_string;
186
    $head_def['Reply-To'] = $from_string;
187
    
187
    
188
    
188
    
189
    $head_string = "";
189
    $head_string = "";
190
    // on construit l'entete à partir de l'entete par defaut, sauf si une valeur existe dans $head
190
    // on construit l'entete à partir de l'entete par defaut, sauf si une valeur existe dans $head
191
    
191
    
192
    $head_string .= $format_string."\n";
192
    $head_string .= $format_string."\n";
193
    
193
    
194
    foreach($head_def as $key => $value){
194
    foreach($head_def as $key => $value){
195
        if ((!isset($head[$key])) && ($value != "")){
195
        if ((!isset($head[$key])) && ($value != "")){
196
            $head_string .= "$key: $value\n";
196
            $head_string .= "$key: $value\n";
197
        }
197
        }
198
    }
198
    }
199
    
199
    
200
    // on ajoute l'entete supplémentaire
200
    // on ajoute l'entete supplémentaire
201
    if ($head != ""){
201
    if ($head != ""){
202
        foreach($head as $key => $value){
202
        foreach($head as $key => $value){
203
            if ($value != ""){
203
            if ($value != ""){
204
                $head_string .= "$key: $value\n";
204
                $head_string .= "$key: $value\n";
205
            }
205
            }
206
        }
206
        }
207
    }
207
    }
208
    
208
    
209
    $head_string .= $cc_string;
209
    $head_string .= $cc_string;
210
    $head_string .= $bcc_string;
210
    $head_string .= $bcc_string;
211
    
211
    
212
    // fin de l'entete
212
    // fin de l'entete
213
    
213
    
214
    // envoi du mail
214
    // envoi du mail
215
    //echo "De : ".$from_string."<BR><BR>".$to_string."<BR><BR>".$cc_string."<BR><BR>".$bcc_string."<BR><BR>Message: ".$body."<BR><BR>".$head_string;
215
    //echo "De : ".$from_string."<BR><BR>".$to_string."<BR><BR>".$cc_string."<BR><BR>".$bcc_string."<BR><BR>Message: ".$body."<BR><BR>".$head_string;
216
    return mail($to_string,$subject,$body,$head_string);
216
    return mail($to_string,$subject,$body,$head_string);
217
    }
217
    }
218
    
218
    
219
    
219
    
220
/* ***********************************
220
/* ***********************************
221
array get_his_rights($table,$appli,$user)
221
array get_his_rights($table,$appli,$user)
222
récupère les droits d'un utilisateur sur un appli
222
récupère les droits d'un utilisateur sur un appli
223
    
223
    
224
Entrée :
224
Entrée :
225
- string $table : nom de la table où sont les données d'autorisations
225
- string $table : nom de la table où sont les données d'autorisations
226
- string $appli : nom de l'appli recherché
226
- string $appli : nom de l'appli recherché
227
- int $user : id de la personne pour qui on veut récupérer les droits
227
- int $user : id de la personne pour qui on veut récupérer les droits
228
 
228
 
229
Sortie : ARRAY de la forme :
229
Sortie : ARRAY de la forme :
230
$table['nom_du_droit'] = "level pour ce droit (un entier)"
230
$table['nom_du_droit'] = "level pour ce droit (un entier)"
231
Dans le programme appelant, il suffit de faire if (isser($table['nom_du_droit'])) 
231
Dans le programme appelant, il suffit de faire if (isser($table['nom_du_droit'])) 
232
pour savoir un un utilisateur dispose d'un droit particulier
232
pour savoir un un utilisateur dispose d'un droit particulier
233
*********************************** */
233
*********************************** */
234
 
234
 
235
function get_his_rights($table,$appli,$user)
235
function get_his_rights($table,$appli,$user)
236
{
236
{
237
    $query = "select GEN_AUT_DROIT, GEN_AUT_LVL, GEN_AUT_PARAM from $table where GEN_AUT_USER = $user AND GEN_AUT_APPLI = '$appli'";
237
    $query = "select GEN_AUT_DROIT, GEN_AUT_LVL, GEN_AUT_PARAM from $table where GEN_AUT_USER = $user AND GEN_AUT_APPLI = '$appli'";
238
    $resu = mysql_query($query) or die("<B>ERREUR !!</B>. Echec de la récupéreration des droits de l'utilisateur : $query");
238
    $resu = mysql_query($query) or die("<B>ERREUR !!</B>. Echec de la récupéreration des droits de l'utilisateur : $query");
239
    
239
    
240
    $droits[0] = "";
240
    $droits[0] = "";
241
    
241
    
242
    while ($row = mysql_fetch_object($resu)){
242
    while ($row = mysql_fetch_object($resu)){
243
        $nom_droit = $row->GEN_AUT_DROIT;
243
        $nom_droit = $row->GEN_AUT_DROIT;
244
        $lvl_droit = $row->GEN_AUT_LVL;
244
        $lvl_droit = $row->GEN_AUT_LVL;
245
        $param_droit = $row->GEN_AUT_PARAM;
245
        $param_droit = $row->GEN_AUT_PARAM;
246
        
246
        
247
        if (($nom_droit != "")&&($lvl_droit >= 0)){
247
        if (($nom_droit != "")&&($lvl_droit >= 0)){
248
            $droits[$nom_droit]['lvl'] = $lvl_droit;
248
            $droits[$nom_droit]['lvl'] = $lvl_droit;
249
            $droits[$nom_droit]['param'] = $param_droit;
249
            $droits[$nom_droit]['param'] = $param_droit;
250
        }
250
        }
251
    }
251
    }
252
    
252
    
253
    mysql_free_result($resu);
253
    mysql_free_result($resu);
254
    
254
    
255
    return $droits;
255
    return $droits;
256
}
256
}
257
 
257
 
258
/* +--Fin du code ----------------------------------------------------------------------------------------+
258
/* +--Fin du code ----------------------------------------------------------------------------------------+
259
*
259
*
260
* $Log: not supported by cvs2svn $
260
* $Log: bba_droit_mail.fonct.php,v $
261
* Revision 1.1  2004/09/14 11:12:27  jpm
261
* Revision 1.1  2004/09/14 11:12:27  jpm
262
* Ajout des fonctions de gestion des mails et des droits d'accès de BiblioBota admin.
262
* Ajout des fonctions de gestion des mails et des droits d'accès de BiblioBota admin.
263
*
263
*
264
*
264
*
265
* +-- Fin du code ----------------------------------------------------------------------------------------+
265
* +-- Fin du code ----------------------------------------------------------------------------------------+
266
*/
266
*/
267
?>
267
?>