Subversion Repositories Applications.papyrus

Rev

Rev 448 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
448 ddelon 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU General Public                                                  |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | General Public License for more details.                                                             |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU General Public                                            |
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                            |
21
// +------------------------------------------------------------------------------------------------------+
474 alexandre_ 22
// CVS : $Id: inscription_liste.class.php,v 1.2 2005-09-27 16:36:01 alexandre_tb Exp $
448 ddelon 23
/**
24
* Application projet
25
*
26
* La classe inscription_liste
27
*
28
*@package projet
29
//Auteur original :
30
*@author        Alexandre Granier <alexandre@tela-botanica.org>
31
//Autres auteurs :
32
*@author        Aucun
33
*@copyright     Tela-Botanica 2000-2004
474 alexandre_ 34
*@version       $Revision: 1.2 $
448 ddelon 35
// +------------------------------------------------------------------------------------------------------+
36
*/
37
 
38
 
39
// +------------------------------------------------------------------------------------------------------+
40
// |                                            ENTETE du PROGRAMME                                       |
41
// +------------------------------------------------------------------------------------------------------+
42
 
43
 
44
/**
45
 * class isncription_liste
46
 *
47
 */
48
class inscription_liste
49
{
50
     /*** Attributes: ***/
51
 
52
    /**
53
     * Identifiant de la liste
54
     * @access private
55
     */
56
    var $_id_liste;
57
    /**
58
     * Identifiant de l'utilisateur
59
     * @access private
60
     */
61
    var $_id_utilisateur;
62
    /**
63
     * Une ressource PEAR::DB
64
     * @access private
65
     */
66
    var $_db;
67
    /**
68
     * Le type d'inscription indique : - 0 : pas d'email - 1 : normale - 2 : résumé
69
     * @access private
70
     */
71
    var $_type_inscription;
72
 
73
    /**
74
     * Constructeur
75
     *
76
     * @param DB objetDB Une ressource PEAR::DB
77
     * @return void
78
     * @access public
79
     */
80
    function inscription_liste( &$objetDB )
81
    {
82
        $this->_db = $objetDB ;
83
    } // end of member function inscription_liste
84
 
85
    /**
86
     * Renvoie un tableau avec la liste des inscrit à une liste.
87
     *
88
     * @param int id_liste L'identifiant de la liste
89
     * @return Array
90
     * @access public
91
     */
92
    function getInscritsListe( $id_liste )
93
    {
94
 
95
    } // end of member function getInscritsListe
96
 
97
    /**
98
     *
99
     *
100
     * @param annire utilisateur
101
     * @param liste_discussion id_liste
102
     * @param int type_inscription
103
     * @return void
104
     * @access public
105
     */
106
    function inscrireUtilisateur( &$utilisateur,  &$liste,  $type_inscription )
107
    {
108
        $requete = 'update projet_inscription_liste set '.
109
                    'pil_id_liste='.$liste->getId().', pil_id_statut='.$type_inscription.' where pil_id_utilisateur='.$utilisateur->getInfo('identifiant') ;
110
        $resultat = $this->_db->query ($requete) ;
111
        if (DB::isError ($resultat)) {
112
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
113
        }
114
        if ($this->_db->affectedRows() == 0) {
115
            $requete = 'insert into projet_inscription_liste set pil_id_utilisateur='.$utilisateur->getInfo('identifiant').
116
                        ', pil_id_liste='.$liste->getId().', pil_id_statut='.$type_inscription ;
117
            $resultat = $this->_db->query ($requete) ;
118
            if (DB::isError ($resultat)) {
119
                die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
120
            }
121
        }
122
 
123
        // Ajout dans la liste des commandes au serveur
124
        // On inscrit le créateur de la liste
125
        // On lance une commande pour ezmlm.sh
126
        $commande = new commande_serveur (PROJET_CHEMIN_APPLI.'script_cron/ezmlm.sh') ;
127
        if (PEAR::isError($commande)) {
128
            echo $commande->getMessage() ;
129
        }
130
        $commande_ajout_utilisateur = 'sudo -u vpopmail /usr/local/bin/ezmlm/ezmlm-sub '.
131
                                    '/home/vpopmail/domains/'.$liste->getDomaine().'/'.$liste->getNom().' '.
132
                                    $utilisateur->getInfo('mail');
133
        $commande->ajouterCommande($commande_ajout_utilisateur) ;
134
    } // end of member function inscrireUtilisateur
135
 
136
    /**
137
     *
138
     *
139
     * @param int id_utilisateur
140
     * @param int id_liste
141
     * @return void
142
     * @access public
143
     */
144
    function desinscrireUtilisateur( &$utilisateur, &$liste )
145
    {
146
        $requete = 'delete from projet_inscription_liste where pil_id_utilisateur='.$utilisateur->getInfo('identifiant').' and pil_id_liste='.$liste->getId() ;
147
        $resultat = $this->_db->query ($requete) ;
148
        $commande_serveur = new commande_serveur(PROJET_CHEMIN_APPLI.'script_cron/ezmlm.sh') ;
149
        // On désinscrit l'utilisateur de la liste
150
        $commande_supressoin_utilisateur = 'sudo -u vpopmail /usr/local/bin/ezmlm/ezmlm-unsub '.
151
                                    '/home/vpopmail/domains/'.$liste->getDomaine().'/'.$liste->getNom().' '.
152
                                    $utilisateur->getInfo('mail');
153
        $commande_serveur->ajouterCommande ($commande_supressoin_utilisateur) ;
154
    } // end of member function desinscrireUtilisateur
155
 
156
    /**
157
     *
158
     *
159
     * @param int id_liste
160
     * @param int id_utilisateur
161
     * @param int type_inscription
162
     * @return void
163
     * @access public
164
     */
165
    function modifierTypeInscription( $liste,  $utilisateur,  $type_inscription )
166
    {
474 alexandre_ 167
        /*
448 ddelon 168
        $requete = 'update projet_inscription_liste set '.
169
                    'pil_id_liste='.$liste->getId().', pil_id_statut='.$type_inscription.' where pil_id_utilisateur='.$utilisateur->getInfo('identifiant') ;
170
        $resultat = $this->_db->query ($requete) ;
171
        if (DB::isError ($resultat)) {
172
            echo ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
173
        }
174
        if ($this->_db->affectedRows() == 0) {
175
            $requete = 'insert into projet_inscription_liste set '.
176
                        'pil_id_liste='.$liste->getId().', pil_id_statut='.$type_inscription.', pil_id_utilisateur='.$utilisateur->getInfo('identifiant') ;
177
            $resultat = $this->_db->query ($requete) ;
178
            if (DB::isError ($resultat)) {
179
                echo ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
180
            }
181
        }
474 alexandre_ 182
        */
448 ddelon 183
        // envoie d'une demande d'inscription par email à la liste
474 alexandre_ 184
        //include_once 'Mail.php' ;
448 ddelon 185
 
186
        switch ($type_inscription) {
187
            case 0 :
474 alexandre_ 188
            /*
448 ddelon 189
                $commande_serveur = new commande_serveur(PROJET_CHEMIN_APPLI.'script_cron/ezmlm.sh') ;
190
                if (PEAR::isError($commande_serveur)) {
191
                    echo $commande_serveur->getMessage() ;
192
                }
193
                // On désinscrit l'utilisateur de la liste
194
                $commande_supressoin_utilisateur = 'sudo -u vpopmail /usr/local/bin/ezmlm/ezmlm-unsub '.
195
                                            '/home/vpopmail/domains/'.$liste->getDomaine().'/'.$liste->getNom().' '.
196
                                            $utilisateur->getInfo('mail');
197
                $commande_serveur->ajouterCommande ($commande_supressoin_utilisateur) ;
474 alexandre_ 198
            */
199
            // Ajout du modérateur en tant qu'utilisateur
200
            $resultat_suppression_utilisateur = file_get_contents ('http://vpopmail.'.$liste->getDomaine().'/suppression_abonne.php?domaine='.
201
                                    $liste->getDomaine().'&liste='.$liste->getNom().'&mail='.$utilisateur->getInfo('mail')) ;
202
 
448 ddelon 203
            break ;
204
            case 1 :
474 alexandre_ 205
                /*
448 ddelon 206
                $commande_serveur = new commande_serveur(PROJET_CHEMIN_APPLI.'script_cron/ezmlm.sh') ;
207
                if (PEAR::isError($commande_serveur)) {
208
                    echo $commande->getMessage() ;
209
                }
210
                // On désinscrit l'utilisateur de la liste
211
                $commande_supressoin_utilisateur = 'sudo -u vpopmail /usr/local/bin/ezmlm/ezmlm-unsub '.
212
                                            '/home/vpopmail/domains/'.$liste->getDomaine().'/'.$liste->getNom().' '.
213
                                            $utilisateur->getInfo('mail');
214
                $commande_serveur->ajouterCommande ($commande_supressoin_utilisateur) ;
215
                // envoie d'une demande d'inscription par email à la liste
216
                include_once 'Mail.php' ;
217
 
218
                // Pour envoyer le mail on utilise la classe Mail de PEAR
219
                // on a besoin du mail de l'inscrit
220
 
221
                $entetes['From'] = $utilisateur->getInfo('mail');
222
                $entetes['To'] = $liste->getAdresseResume() ;
223
                $entetes['Subject'] = '' ;
224
 
225
                $objet_mail =& Mail::factory('smtp');
226
                $objet_mail->send($entetes['To'], $entetes, '');
474 alexandre_ 227
            */
448 ddelon 228
            break ;
229
            case 2 :
474 alexandre_ 230
            /*
448 ddelon 231
                $commande_serveur = new commande_serveur(PROJET_CHEMIN_APPLI.'script_cron/ezmlm.sh') ;
232
                if (PEAR::isError($commande_serveur)) {
233
                    echo $commande_serveur->getMessage() ;
234
                }
235
                // On désinscrit l'utilisateur de la liste
236
                $commande_ajout_utilisateur = 'sudo -u vpopmail /usr/local/bin/ezmlm/ezmlm-sub '.
237
                                            '/home/vpopmail/domains/'.$liste->getDomaine().'/'.$liste->getNom().' '.
238
                                            $utilisateur->getInfo('mail');
239
                $commande_serveur->ajouterCommande ($commande_ajout_utilisateur) ;
474 alexandre_ 240
            */
241
                // Ajout d'un utilisateur
242
                $resultat_ajout_utilisateur = file_get_contents ('http://vpopmail.'.$liste->getDomaine().'/ajout_abonne.php?domaine='.
243
                                    $liste->getDomaine().'&liste='.$liste->getNom().'&mail='.$utilisateur->getInfo('mail')) ;
448 ddelon 244
            break ;
245
        }
246
    } // end of member function modifierTypeInscription
247
 
248
    /**
249
     * Renvoie la liste des statuts d'un utilisateur
250
     *
251
     * @param int id_utilisateur
252
     * @return Array
253
     * @access public
254
     */
255
    function getStatutsInscrit( $id_utilisateur )
256
    {
474 alexandre_ 257
 
448 ddelon 258
        $requete = 'select pil_id_liste, pil_id_statut from projet_inscription_liste where pil_id_utilisateur='.$id_utilisateur ;
474 alexandre_ 259
        $resultat = $this->_db->query ($requete) ;echo $requete;
448 ddelon 260
        if (DB::isError ($resultat)) {
261
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
262
        }
263
        $tableau_resultat = array() ;
264
        while ($ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) {
265
            $tableau_resultat[$ligne->pil_id_liste] = $ligne->pil_id_statut ;
266
        }
267
        return $tableau_resultat ;
474 alexandre_ 268
 
269
 
448 ddelon 270
    } // end of member function getStatutsInscrit
271
 
272
    /**
273
     * Renvoie le statut d'un inscrit à une liste
274
     *
275
     * @param int id_liste
276
     * @param int id_utilisateur
277
     * @return int
278
     * @access public
279
     */
474 alexandre_ 280
    function getStatutInscrit( $id_liste,  &$auth )
448 ddelon 281
    {
474 alexandre_ 282
        /*
448 ddelon 283
        $requete = 'select pil_id_liste, pil_id_statut from projet_inscription_liste where pil_id_utilisateur='.$id_utilisateur.
284
                    ' and pil_id_liste='.$id_liste;
285
        $resultat = $this->_db->query ($requete) ;
286
        if (DB::isError ($resultat)) {
287
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
288
        }
289
 
290
        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
291
 
292
        return $ligne->pil_id_statut;
474 alexandre_ 293
        */
294
        // Récupération de la liste des listes !!
295
        $requete = 'select pl_nom_liste, pl_domaine from projet_liste where pl_id_liste='.$id_liste ;
296
        $resultat = $this->_db->query ($requete) ;
297
        if (DB::isError ($resultat)) {
298
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
299
        }
300
        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
301
        $xml = file_get_contents('http://vpopmail.'.$ligne->pl_domaine.'/liste_abonnes.php?domaine='.
302
                            $ligne->pl_domaine.'&liste='.$ligne->pl_nom_liste) ;
303
        $tableau_mail = array() ;
304
        $tableau_ligne = explode ('<email>', $xml) ;
305
        foreach ($tableau_ligne as $ligne) array_push ($tableau_mail, strip_tags($ligne)) ;
306
        array_shift($tableau_mail) ;
307
        if (in_array($auth->getUsername(), $tableau_mail)) {
308
            return 2;       // Inscrit est le statut  2
309
        }
310
        return 0 ;
448 ddelon 311
    } // end of member function getStatutInscrit
312
 
313
 
314
 
315
 
316
 
317
 
318
 
319
} // end of isncription_liste
320
?>