1897b0554fdb0732a8f8b549590906d6458b18ec
[platal.git] / include / validations / listes.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2011 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&hellip;)";
42 // }}}
43 // {{{ constructor
44
45 public function __construct(User $_user, $_asso, $_liste, $_domain, $_desc, $_advertise,
46 $_modlevel, $_inslevel, $_owners, $_members, $_stamp = 0)
47 {
48 parent::__construct($_user, 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 = Post::t('listname');
86 }
87 if (Env::has('domainname')) {
88 $this->domain = Post::t('domainname');
89 }
90 if (Env::has('assotype')) {
91 $this->asso = Post::t('assotype');
92 }
93 if (!$this->asso) {
94 $this->domain = $globals->mail->domain;
95 }
96 foreach ($this->owners as $key => &$email) {
97 $email = Post::t('owners_' . $key);
98 }
99 foreach ($this->members as $key => &$email) {
100 $email = Post::t('members_' . $key);
101 }
102 return true;
103 }
104
105 // }}}
106 // {{{ function _mail_subj
107
108 protected function _mail_subj()
109 {
110 return "[Polytechnique.org/LISTES] Demande de la liste {$this->liste}@{$this->domain}";
111 }
112
113 // }}}
114 // {{{ function _mail_body
115
116 protected function _mail_body($isok)
117 {
118 if ($isok) {
119 return " Suite à ta demande de création de liste de diffusion, nous avons créé l'adresse {$this->liste}@{$this->domain}, qui est maintenant à ta disposition.";
120 } else {
121 return " La demande que tu avais faite pour la liste de diffusion {$this->liste}@{$this->domain} a été refusée.";
122 }
123 }
124
125 // }}}
126 // {{{ function commit()
127
128 public function commit()
129 {
130 require_once 'emails.inc.php';
131
132 if ($this->asso == 'alias') {
133 foreach ($this->members as $member) {
134 add_to_list_alias($member, $this->liste, $this->domain);
135 }
136 } else {
137 $members = User::getBulkForlifeEmails($this->members, true,
138 array('ListsModule', 'no_login_callback'));
139 $owners = User::getBulkForlifeEmails($this->owners, true,
140 array('ListsModule', 'no_login_callback'));
141 $list = new MMList(S::user(), $this->domain);
142 $success = $list->create_list($this->liste, utf8_decode($this->desc), $this->advertise,
143 $this->modlevel, $this->inslevel,
144 $owners, $members);
145 if ($success) {
146 create_list($this->liste, $this->domain);
147 }
148 return $success;
149 }
150 }
151
152 // }}}
153 }
154
155 // }}}
156
157 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
158 ?>