Merge commit 'origin/master' into hruid
[platal.git] / include / validations / listes.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
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
24 class ListeReq extends Validate
25 {
26 // {{{ properties
27
28 public $liste;
29 public $desc;
30 public $asso;
31 public $domain;
32
33 public $advertise;
34 public $modlevel;
35 public $inslevel;
36
37 public $owners;
38 public $members;
39
40 public $rules = "Refuser les listes de binets si elles ne sont pas datées (oui : apv2002@, non : apv@).
41 Refuser également des listes qui pourraient nous servir (admin, postmaster,...)";
42 // }}}
43 // {{{ constructor
44
45 public function __construct($_uid, $_asso, $_liste, $_domain, $_desc, $_advertise,
46 $_modlevel, $_inslevel, $_owners, $_members, $_stamp=0)
47 {
48 parent::__construct($_uid, false, 'liste', $_stamp);
49
50 $this->asso = $_asso;
51 $this->liste = $_liste;
52 $this->domain = $_domain;
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
64 public function formu()
65 {
66 return 'include/form.valid.listes.tpl';
67 }
68
69 // }}}
70 // {{{ function editor()
71
72 public function editor()
73 {
74 return 'include/form.valid.edit-listes.tpl';
75 }
76
77 // }}}
78 // {{{ function handle_editor()
79
80 protected function handle_editor()
81 {
82 global $globals;
83
84 if (Env::has('listname')) {
85 $this->liste = trim(Env::v('listname'));
86 }
87 if (Env::has('domainname')) {
88 $this->domain = trim(Env::v('domainname'));
89 }
90 if (Env::has('assotype')) {
91 $this->asso = trim(Env::v('assotype'));
92 }
93 if (!$this->asso) {
94 $this->domain = $globals->mail->domain;
95 }
96 return true;
97 }
98
99 // }}}
100 // {{{ function _mail_subj
101
102 protected function _mail_subj()
103 {
104 return "[Polytechnique.org/LISTES] Demande de la liste {$this->liste}";
105 }
106
107 // }}}
108 // {{{ function _mail_body
109
110 protected function _mail_body($isok)
111 {
112 if ($isok) {
113 return " La liste de diffusion {$this->liste} que tu avais demandée vient d'être créée.";
114 } else {
115 return " La demande que tu avais faite pour la liste de diffusion {$this->liste} a été refusée.";
116 }
117 }
118
119 // }}}
120 // {{{ function commit()
121
122 public function commit()
123 {
124 global $globals;
125
126 if ($this->asso == "alias") {
127 $new = $this->liste . '@' . $this->domain;
128 XDB::query('INSERT INTO x4dat.virtual (alias,type) VALUES({?}, "user")', $new);
129 foreach ($this->members as $member) {
130 $res = XDB::query(
131 "SELECT a.alias, b.alias
132 FROM x4dat.aliases AS a
133 LEFT JOIN x4dat.aliases AS b ON (a.id=b.id AND b.type = 'a_vie')
134 WHERE a.alias={?} AND a.type!='homonyme'", $member);
135 list($alias, $blias) = $res->fetchOneRow();
136 $alias = empty($blias) ? $alias : $blias;
137 XDB::query(
138 "INSERT INTO x4dat.virtual_redirect (vid,redirect)
139 SELECT vid, {?}
140 FROM x4dat.virtual
141 WHERE alias={?}", $alias . "@" . $globals->mail->domain, $new);
142 }
143 return 1;
144 }
145
146 $list = new MMList(S::v('uid'), S::v('password'), $this->domain);
147 $ret = $list->create_list($this->liste, utf8_decode($this->desc), $this->advertise,
148 $this->modlevel, $this->inslevel,
149 $this->owners, $this->members);
150 $liste = strtolower($this->liste);
151 if ($ret && !$this->asso) {
152 foreach(Array($liste, $liste . "-owner", $liste . "-admin", $liste . "-bounces", $liste . "-unsubscribe") as $l) {
153 XDB::execute("INSERT INTO aliases (alias,type) VALUES({?}, 'liste')", $l);
154 }
155 } elseif ($ret) {
156 foreach (Array('', 'owner', 'admin', 'bounces', 'unsubscribe') as $app) {
157 $mdir = $app == '' ? '+post' : '+' . $app;
158 if (!empty($app)) {
159 $app = '-' . $app;
160 }
161 $red = $this->domain . '_' . $liste;
162 XDB::execute('INSERT INTO x4dat.virtual (alias,type)
163 VALUES({?},{?})', $liste . $app . '@' . $this->domain, 'list');
164 XDB::execute('INSERT INTO x4dat.virtual_redirect (vid,redirect)
165 VALUES ({?}, {?})', XDB::insertId(),
166 $red . $mdir . '@listes.polytechnique.org');
167 $list->mass_subscribe($liste, join(' ', $this->members));
168 }
169 }
170 return $ret;
171 }
172
173 // }}}
174 }
175
176 // }}}
177
178 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
179 ?>