Subversion Repositories Applications.papyrus

Rev

Rev 474 | 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
// +------------------------------------------------------------------------------------------------------+
508 alexandre_ 22
// CVS : $Id: inscription_liste.class.php,v 1.3 2005-10-04 10:12:16 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
508 alexandre_ 34
*@version       $Revision: 1.3 $
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
    {
508 alexandre_ 167
 
448 ddelon 168
        // envoie d'une demande d'inscription par email à la liste
474 alexandre_ 169
        //include_once 'Mail.php' ;
448 ddelon 170
 
171
        switch ($type_inscription) {
172
            case 0 :
508 alexandre_ 173
 
474 alexandre_ 174
            // Ajout du modérateur en tant qu'utilisateur
508 alexandre_ 175
            $resultat_suppression_utilisateur = file_get_contents (PROJET_SERVEUR_VPOPMAIL.'/suppression_abonne.php?domaine='.
474 alexandre_ 176
                                    $liste->getDomaine().'&liste='.$liste->getNom().'&mail='.$utilisateur->getInfo('mail')) ;
177
 
448 ddelon 178
            break ;
179
            case 1 :
508 alexandre_ 180
 
448 ddelon 181
            break ;
182
            case 2 :
508 alexandre_ 183
 
474 alexandre_ 184
                // Ajout d'un utilisateur
508 alexandre_ 185
                $resultat_ajout_utilisateur = file_get_contents (PROJET_SERVEUR_VPOPMAIL.'/ajout_abonne.php?domaine='.
474 alexandre_ 186
                                    $liste->getDomaine().'&liste='.$liste->getNom().'&mail='.$utilisateur->getInfo('mail')) ;
448 ddelon 187
            break ;
188
        }
189
    } // end of member function modifierTypeInscription
190
 
191
    /**
192
     * Renvoie la liste des statuts d'un utilisateur
193
     *
194
     * @param int id_utilisateur
195
     * @return Array
196
     * @access public
197
     */
198
    function getStatutsInscrit( $id_utilisateur )
199
    {
474 alexandre_ 200
 
448 ddelon 201
        $requete = 'select pil_id_liste, pil_id_statut from projet_inscription_liste where pil_id_utilisateur='.$id_utilisateur ;
474 alexandre_ 202
        $resultat = $this->_db->query ($requete) ;echo $requete;
448 ddelon 203
        if (DB::isError ($resultat)) {
204
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
205
        }
206
        $tableau_resultat = array() ;
207
        while ($ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) {
208
            $tableau_resultat[$ligne->pil_id_liste] = $ligne->pil_id_statut ;
209
        }
210
        return $tableau_resultat ;
474 alexandre_ 211
 
212
 
448 ddelon 213
    } // end of member function getStatutsInscrit
214
 
215
    /**
216
     * Renvoie le statut d'un inscrit à une liste
217
     *
218
     * @param int id_liste
219
     * @param int id_utilisateur
220
     * @return int
221
     * @access public
222
     */
474 alexandre_ 223
    function getStatutInscrit( $id_liste,  &$auth )
448 ddelon 224
    {
474 alexandre_ 225
        /*
448 ddelon 226
        $requete = 'select pil_id_liste, pil_id_statut from projet_inscription_liste where pil_id_utilisateur='.$id_utilisateur.
227
                    ' and pil_id_liste='.$id_liste;
228
        $resultat = $this->_db->query ($requete) ;
229
        if (DB::isError ($resultat)) {
230
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
231
        }
232
 
233
        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
234
 
235
        return $ligne->pil_id_statut;
474 alexandre_ 236
        */
237
        // Récupération de la liste des listes !!
238
        $requete = 'select pl_nom_liste, pl_domaine from projet_liste where pl_id_liste='.$id_liste ;
239
        $resultat = $this->_db->query ($requete) ;
240
        if (DB::isError ($resultat)) {
241
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
242
        }
243
        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
508 alexandre_ 244
        $xml = file_get_contents(PROJET_SERVEUR_VPOPMAIL.'/liste_abonnes.php?domaine='.
474 alexandre_ 245
                            $ligne->pl_domaine.'&liste='.$ligne->pl_nom_liste) ;
246
        $tableau_mail = array() ;
247
        $tableau_ligne = explode ('<email>', $xml) ;
248
        foreach ($tableau_ligne as $ligne) array_push ($tableau_mail, strip_tags($ligne)) ;
249
        array_shift($tableau_mail) ;
250
        if (in_array($auth->getUsername(), $tableau_mail)) {
251
            return 2;       // Inscrit est le statut  2
252
        }
253
        return 0 ;
448 ddelon 254
    } // end of member function getStatutInscrit
255
} // end of isncription_liste
256
?>