Automation of the management of associations' mailing lists (Closes #817), Updates...
[platal.git] / include / validations / listes.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
179afa7f 3 * Copyright (C) 2003-2008 Polytechnique.org *
0337d704 4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22// {{{ class ListeReq
23
24class ListeReq extends Validate
25{
26 // {{{ properties
eaf30d86 27
612a2d8a 28 public $liste;
29 public $desc;
59887c4a
SJ
30 public $asso;
31 public $domain;
0337d704 32
612a2d8a 33 public $advertise;
34 public $modlevel;
35 public $inslevel;
0337d704 36
612a2d8a 37 public $owners;
38 public $members;
0337d704 39
612a2d8a 40 public $rules = "Refuser les listes de binets si elles ne sont pas datées (oui : apv2002@, non : apv@).
a7de4ef7 41 Refuser également des listes qui pourraient nous servir (admin, postmaster,...)";
0337d704 42 // }}}
43 // {{{ constructor
eaf30d86 44
59887c4a
SJ
45 public function __construct($_uid, $_asso, $_liste, $_domain, $_desc, $_advertise,
46 $_modlevel, $_inslevel, $_owners, $_members, $_stamp=0)
0337d704 47 {
9b591cc9 48 parent::__construct($_uid, false, 'liste', $_stamp);
eaf30d86 49
59887c4a 50 $this->asso = $_asso;
0337d704 51 $this->liste = $_liste;
59887c4a 52 $this->domain = $_domain;
0337d704 53 $this->desc = $_desc;
54 $this->advertise = $_advertise;
55 $this->modlevel = $_modlevel;
56 $this->inslevel = $_inslevel;
57 $this->owners = $_owners;
58 $this->members = $_members;
59 }
60
61 // }}}
62 // {{{ function formu()
63
612a2d8a 64 public function formu()
65 {
66 return 'include/form.valid.listes.tpl';
67 }
0337d704 68
69 // }}}
e2a78862 70 // {{{ function editor()
71
612a2d8a 72 public function editor()
e2a78862 73 {
74 return 'include/form.valid.edit-listes.tpl';
75 }
76
77 // }}}
78 // {{{ function handle_editor()
79
612a2d8a 80 protected function handle_editor()
e2a78862 81 {
82 if (Env::has('listname')) {
83 $this->liste = trim(Env::v('listname'));
84 }
59887c4a
SJ
85 if (Env::has('domainname')) {
86 $this->domain = trim(Env::v('domainname'));
87 }
88 if (Env::has('assotype')) {
89 $this->asso = trim(Env::v('assotype'));
90 }
91 if (!$this->asso) {
92 $this->domain = "polytechnique.org";
93 }
e2a78862 94 return true;
95 }
96
97 // }}}
0337d704 98 // {{{ function _mail_subj
99
612a2d8a 100 protected function _mail_subj()
0337d704 101 {
102 return "[Polytechnique.org/LISTES] Demande de la liste {$this->liste}";
103 }
104
105 // }}}
106 // {{{ function _mail_body
107
612a2d8a 108 protected function _mail_body($isok)
0337d704 109 {
110 if ($isok) {
a7de4ef7 111 return " La mailing list {$this->liste} que tu avais demandée vient d'être créée.";
0337d704 112 } else {
a7de4ef7 113 return " La demande que tu avais faite pour la mailing list {$this->liste} a été refusée.";
0337d704 114 }
115 }
116
117 // }}}
118 // {{{ function commit()
9bb8bf21 119
612a2d8a 120 public function commit()
0337d704 121 {
59887c4a
SJ
122 global $globals;
123
124 if ($this->asso == "alias") {
125 $new = $this->liste . '@' . $this->domain;
126 XDB::query('INSERT INTO x4dat.virtual (alias,type) VALUES({?}, "user")', $new);
127 foreach ($this->members as $member) {
128 $res = XDB::query(
129 "SELECT a.alias, b.alias
130 FROM x4dat.aliases AS a
131 LEFT JOIN x4dat.aliases AS b ON (a.id=b.id AND b.type = 'a_vie')
132 WHERE a.alias={?} AND a.type!='homonyme'", $member);
133 list($alias, $blias) = $res->fetchOneRow();
134 $alias = empty($blias) ? $alias : $blias;
135 XDB::query(
136 "INSERT INTO x4dat.virtual_redirect (vid,redirect)
137 SELECT vid, {?}
138 FROM x4dat.virtual
139 WHERE alias={?}", $alias . "@" . $globals->mail->domain, $new);
140 }
141 return 1;
142 }
143
144 $list = new MMList(S::v('uid'), S::v('password'), $this->domain);
92144f3e 145 $ret = $list->create_list($this->liste, utf8_decode($this->desc), $this->advertise,
9bb8bf21 146 $this->modlevel, $this->inslevel,
147 $this->owners, $this->members);
0337d704 148 $liste = strtolower($this->liste);
59887c4a
SJ
149 if ($ret && !$this->asso) {
150 foreach(Array($liste, $liste . "-owner", $liste . "-admin", $liste . "-bounces", $liste . "-unsubscribe") as $l) {
08cce2ff 151 XDB::execute("INSERT INTO aliases (alias,type) VALUES({?}, 'liste')", $l);
0337d704 152 }
59887c4a
SJ
153 } else {
154 if ($ret) {
155 foreach (Array('', 'owner', 'admin', 'bounces', 'unsubscribe') as $app) {
156 $mdir = $app == '' ? '+post' : '+' . $app;
157 if (!empty($app)) {
158 $app = '-' . $app;
159 }
160 $red = $this->domain . '_' . $liste;
161 XDB::execute('INSERT INTO x4dat.virtual (alias,type)
162 VALUES({?},{?})', $liste . $app . '@' . $this->domain, 'list');
163 XDB::execute('INSERT INTO x4dat.virtual_redirect (vid,redirect)
164 VALUES ({?}, {?})', XDB::insertId(),
165 $red . $mdir . '@listes.polytechnique.org');
166 $list->mass_subscribe($liste, join(' ', $this->members));
167 }
168 }
0337d704 169 }
170 return $ret;
171 }
172
173 // }}}
174}
175
176// }}}
177
a7de4ef7 178// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 179?>