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 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
22 |
// CVS : $Id: inscription_liste.class.php,v 1.1 2005-09-22 14:02:47 ddelon Exp $
|
|
|
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
|
|
|
34 |
*@version $Revision: 1.1 $
|
|
|
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 |
{
|
|
|
167 |
$requete = 'update projet_inscription_liste set '.
|
|
|
168 |
'pil_id_liste='.$liste->getId().', pil_id_statut='.$type_inscription.' where pil_id_utilisateur='.$utilisateur->getInfo('identifiant') ;
|
|
|
169 |
$resultat = $this->_db->query ($requete) ;
|
|
|
170 |
if (DB::isError ($resultat)) {
|
|
|
171 |
echo ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
|
|
|
172 |
}
|
|
|
173 |
if ($this->_db->affectedRows() == 0) {
|
|
|
174 |
$requete = 'insert into projet_inscription_liste set '.
|
|
|
175 |
'pil_id_liste='.$liste->getId().', pil_id_statut='.$type_inscription.', pil_id_utilisateur='.$utilisateur->getInfo('identifiant') ;
|
|
|
176 |
$resultat = $this->_db->query ($requete) ;
|
|
|
177 |
if (DB::isError ($resultat)) {
|
|
|
178 |
echo ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
|
|
|
179 |
}
|
|
|
180 |
}
|
|
|
181 |
// envoie d'une demande d'inscription par email à la liste
|
|
|
182 |
include_once 'Mail.php' ;
|
|
|
183 |
|
|
|
184 |
switch ($type_inscription) {
|
|
|
185 |
case 0 :
|
|
|
186 |
$commande_serveur = new commande_serveur(PROJET_CHEMIN_APPLI.'script_cron/ezmlm.sh') ;
|
|
|
187 |
if (PEAR::isError($commande_serveur)) {
|
|
|
188 |
echo $commande_serveur->getMessage() ;
|
|
|
189 |
}
|
|
|
190 |
// On désinscrit l'utilisateur de la liste
|
|
|
191 |
$commande_supressoin_utilisateur = 'sudo -u vpopmail /usr/local/bin/ezmlm/ezmlm-unsub '.
|
|
|
192 |
'/home/vpopmail/domains/'.$liste->getDomaine().'/'.$liste->getNom().' '.
|
|
|
193 |
$utilisateur->getInfo('mail');
|
|
|
194 |
$commande_serveur->ajouterCommande ($commande_supressoin_utilisateur) ;
|
|
|
195 |
break ;
|
|
|
196 |
case 1 :
|
|
|
197 |
$commande_serveur = new commande_serveur(PROJET_CHEMIN_APPLI.'script_cron/ezmlm.sh') ;
|
|
|
198 |
if (PEAR::isError($commande_serveur)) {
|
|
|
199 |
echo $commande->getMessage() ;
|
|
|
200 |
}
|
|
|
201 |
// On désinscrit l'utilisateur de la liste
|
|
|
202 |
$commande_supressoin_utilisateur = 'sudo -u vpopmail /usr/local/bin/ezmlm/ezmlm-unsub '.
|
|
|
203 |
'/home/vpopmail/domains/'.$liste->getDomaine().'/'.$liste->getNom().' '.
|
|
|
204 |
$utilisateur->getInfo('mail');
|
|
|
205 |
$commande_serveur->ajouterCommande ($commande_supressoin_utilisateur) ;
|
|
|
206 |
// envoie d'une demande d'inscription par email à la liste
|
|
|
207 |
include_once 'Mail.php' ;
|
|
|
208 |
|
|
|
209 |
// Pour envoyer le mail on utilise la classe Mail de PEAR
|
|
|
210 |
// on a besoin du mail de l'inscrit
|
|
|
211 |
|
|
|
212 |
$entetes['From'] = $utilisateur->getInfo('mail');
|
|
|
213 |
$entetes['To'] = $liste->getAdresseResume() ;
|
|
|
214 |
$entetes['Subject'] = '' ;
|
|
|
215 |
|
|
|
216 |
$objet_mail =& Mail::factory('smtp');
|
|
|
217 |
$objet_mail->send($entetes['To'], $entetes, '');
|
|
|
218 |
break ;
|
|
|
219 |
case 2 :
|
|
|
220 |
$commande_serveur = new commande_serveur(PROJET_CHEMIN_APPLI.'script_cron/ezmlm.sh') ;
|
|
|
221 |
if (PEAR::isError($commande_serveur)) {
|
|
|
222 |
echo $commande_serveur->getMessage() ;
|
|
|
223 |
}
|
|
|
224 |
// On désinscrit l'utilisateur de la liste
|
|
|
225 |
$commande_ajout_utilisateur = 'sudo -u vpopmail /usr/local/bin/ezmlm/ezmlm-sub '.
|
|
|
226 |
'/home/vpopmail/domains/'.$liste->getDomaine().'/'.$liste->getNom().' '.
|
|
|
227 |
$utilisateur->getInfo('mail');
|
|
|
228 |
$commande_serveur->ajouterCommande ($commande_ajout_utilisateur) ;
|
|
|
229 |
break ;
|
|
|
230 |
}
|
|
|
231 |
} // end of member function modifierTypeInscription
|
|
|
232 |
|
|
|
233 |
/**
|
|
|
234 |
* Renvoie la liste des statuts d'un utilisateur
|
|
|
235 |
*
|
|
|
236 |
* @param int id_utilisateur
|
|
|
237 |
* @return Array
|
|
|
238 |
* @access public
|
|
|
239 |
*/
|
|
|
240 |
function getStatutsInscrit( $id_utilisateur )
|
|
|
241 |
{
|
|
|
242 |
$requete = 'select pil_id_liste, pil_id_statut from projet_inscription_liste where pil_id_utilisateur='.$id_utilisateur ;
|
|
|
243 |
$resultat = $this->_db->query ($requete) ;
|
|
|
244 |
if (DB::isError ($resultat)) {
|
|
|
245 |
die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
|
|
|
246 |
}
|
|
|
247 |
$tableau_resultat = array() ;
|
|
|
248 |
while ($ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) {
|
|
|
249 |
$tableau_resultat[$ligne->pil_id_liste] = $ligne->pil_id_statut ;
|
|
|
250 |
}
|
|
|
251 |
return $tableau_resultat ;
|
|
|
252 |
} // end of member function getStatutsInscrit
|
|
|
253 |
|
|
|
254 |
/**
|
|
|
255 |
* Renvoie le statut d'un inscrit à une liste
|
|
|
256 |
*
|
|
|
257 |
* @param int id_liste
|
|
|
258 |
* @param int id_utilisateur
|
|
|
259 |
* @return int
|
|
|
260 |
* @access public
|
|
|
261 |
*/
|
|
|
262 |
function getStatutInscrit( $id_liste, $id_utilisateur )
|
|
|
263 |
{
|
|
|
264 |
$requete = 'select pil_id_liste, pil_id_statut from projet_inscription_liste where pil_id_utilisateur='.$id_utilisateur.
|
|
|
265 |
' and pil_id_liste='.$id_liste;
|
|
|
266 |
$resultat = $this->_db->query ($requete) ;
|
|
|
267 |
if (DB::isError ($resultat)) {
|
|
|
268 |
die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
$ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
|
|
|
272 |
|
|
|
273 |
return $ligne->pil_id_statut;
|
|
|
274 |
} // end of member function getStatutInscrit
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
|
279 |
|
|
|
280 |
|
|
|
281 |
|
|
|
282 |
} // end of isncription_liste
|
|
|
283 |
?>
|