9ad82929af0ffae40b86eac93ba3639b4ed3addb
2 /***************************************************************************
3 * Copyright (C) 2003-2007 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class AXLetterModule
extends PLModule
27 'ax' => $this->make_hook('index', AUTH_COOKIE
),
28 'ax/out' => $this->make_hook('out', AUTH_PUBLIC
),
29 'ax/show' => $this->make_hook('show', AUTH_COOKIE
),
30 'ax/edit' => $this->make_hook('submit', AUTH_MDP
),
31 'ax/edit/cancel' => $this->make_hook('cancel', AUTH_MDP
),
32 'ax/edit/valid' => $this->make_hook('valid', AUTH_MDP
),
33 'admin/axletter/rights' => $this->make_hook('admin_rights', AUTH_MDP
, 'admin'),
37 function handler_out(&$page, $hash)
43 return $this->handler_index($page, 'out');
46 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
47 $page->changeTpl('axletter/unsubscribe.tpl');
48 $page->assign('success', AXLetter
::unsubscribe($hash, true
));
51 function handler_index(&$page, $action = null
)
53 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
55 $page->changeTpl('axletter/index.tpl');
56 $page->assign('xorg_title','Polytechnique.org - Envois de l\'AX');
59 case 'in': AXLetter
::subscribe(); break;
60 case 'out': AXLetter
::unsubscribe(); break;
63 $perm = AXLetter
::hasPerms();
65 $page->assign('new', AXLetter
::awaiting());
67 $page->assign('axs', AXLetter
::subscriptionState());
68 $page->assign('ax_list', AXLetter
::listSent());
69 $page->assign('ax_rights', $perm);
72 function handler_submit(&$page, $action = null
)
74 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
75 if (!AXLetter
::hasPerms()) {
79 $page->changeTpl('axletter/edit.tpl');
81 $saved = Post
::i('saved');
84 $shortname = trim(Post
::v('shortname'));
85 $subject = trim(Post
::v('subject'));
86 $title = trim(Post
::v('title'));
87 $body = rtrim(Post
::v('body'));
88 $signature = trim(Post
::v('signature'));
89 $promo_min = Post
::i('promo_min');
90 $promo_max = Post
::i('promo_max');
91 $echeance = Post
::has('echeance_date') ? Post
::v('echeance_date') . ' ' . Post
::v('echeance_time')
92 : Post
::v('echeance');
93 $echeance_date = Post
::v('echeance_date');
94 $echeance_time = Post
::v('echeance_time');
97 $res = XDB
::query("SELECT * FROM axletter WHERE FIND_IN_SET('new', bits)");
98 if ($res->numRows()) {
99 extract($res->fetchOneAssoc(), EXTR_OVERWRITE
);
102 XDB
::execute("INSERT INTO axletter SET id = NULL");
103 $id = XDB
::insertId();
105 if (!$echeance ||
$echeance == '0000-00-00 00:00:00') {
109 } elseif (Post
::has('valid')) {
110 if (!$subject && $title) {
113 if (!$title && $subject) {
116 if (!$subject ||
!$title ||
!$body) {
117 $page->trig("L'article doit avoir un sujet et un contenu");
120 if (($promo_min > $promo_max && $promo_max != 0)||
121 ($promo_min != 0 && ($promo_min <= 1900 ||
$promo_min >= 2020)) ||
122 ($promo_max != 0 && ($promo_max <= 1900 ||
$promo_max >= 2020)))
124 $page->trig("L'intervalle de promotions n'est pas valide");
127 if (empty($shortname)) {
128 $page->trig("L'annonce doit avoir un nom raccourci pour simplifier la navigation dans les archives");
130 } elseif (!preg_match('/^[a-z][-a-z0-9]*[a-z0-9]$/', $shortname)) {
131 $page->trig("Le nom raccourci n'est pas valide, il doit comporter au moins 2 caractères et n'être composé "
132 . "que de chiffres, lettres et tirets");
134 } elseif ($shortname != Post
::v('old_shortname')) {
135 $res = XDB
::query("SELECT id FROM axletter WHERE shortname = {?}", $shortname);
136 if ($res->numRows() && $res->fetchOneCell() != $id) {
137 $page->trig("Le nom $shortname est déjà utilisé, merci d'en choisir un autre");
138 $shortname = Post
::v('old_shortname');
139 if (empty($shortname)) {
145 switch (@Post
::v('valid')) {
147 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
148 $al = new AXLetter(array($id, $shortname, $subject, $title, $body, $signature,
149 $promo_min, $promo_max, $echeance, 0, 'new'));
150 $al->toHtml($page, S
::v('prenom'), S
::v('nom'), S
::v('femme'));
154 XDB
::execute("REPLACE INTO axletter
155 SET id = {?}, shortname = {?}, subject = {?}, title = {?}, body = {?},
156 signature = {?}, promo_min = {?}, promo_max = {?}, echeance = {?}",
157 $id, $shortname, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance);
159 $echeance_date = null
;
160 $echeance_time = null
;
165 $page->assign('id', $id);
166 $page->assign('shortname', $shortname);
167 $page->assign('subject', $subject);
168 $page->assign('title', $title);
169 $page->assign('body', $body);
170 $page->assign('signature', $signature);
171 $page->assign('promo_min', $promo_min);
172 $page->assign('promo_max', $promo_max);
173 $page->assign('echeance', $echeance);
174 $page->assign('echeance_date', $echeance_date);
175 $page->assign('echeance_time', $echeance_time);
176 $page->assign('saved', $saved);
177 $page->assign('new', $new);
178 $page->assign('is_xorg', S
::has_perms());
182 $time = time() +
3600 * 24 * 2;
183 for ($i = 0 ; $i < 15 ; $i++
) {
185 $p_stamp = date('Ymd', $time);
186 $year = date('Y', $time);
187 $month = date('m', $time);
188 $day = date('d', $time);
190 if ($p_stamp == $echeance_date) {
191 $sel = ' selected="selected"';
195 $select .= "<option value=\"$p_stamp\"$sel> $day / $month / $year</option>\n";
197 $page->assign('echeance_date', $select);
199 for ($i = 0 ; $i < 24 ; $i++
) {
200 $stamp = sprintf('%02d:00:00', $i);
201 if ($stamp == $echeance_time) {
202 $sel = ' selected="selected"';
206 $select .= "<option value=\"$stamp\"$sel>{$i}h</option>\n";
208 $page->assign('echeance_time', $select);
212 function handler_cancel(&$page, $force = null
)
214 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
215 if (!AXLetter
::hasPerms()) {
219 $url = parse_url($_SERVER['HTTP_REFERER']);
220 if ($force != 'force' && trim($url['path'], '/') != 'ax/edit') {
224 $al = AXLetter
::awaiting();
226 $page->kill("Aucune lettre en attente");
229 if (!$al->invalid()) {
230 $page->kill("Une erreur est survenue lors de l'annulation de l'envoi");
234 $page->kill("L'envoi de l'annonce {$al->title()} est annulé");
237 function handler_valid(&$page, $force = null
)
239 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
240 if (!AXLetter
::hasPerms()) {
244 $url = parse_url($_SERVER['HTTP_REFERER']);
245 if ($force != 'force' && trim($url['path'], '/') != 'ax/edit') {
249 $al = AXLetter
::awaiting();
251 $page->kill("Aucune lettre en attente");
255 $page->kill("Une erreur est survenue lors de la validation de l'envoi");
259 $page->kill("L'envoi de l'annonce aura lieu dans l'heure qui vient.");
262 function handler_show(&$page, $nid = 'last')
264 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
265 $page->changeTpl('axletter/show.tpl');
267 $nl = new AXLetter($nid);
268 if (Get
::has('text')) {
269 $nl->toText($page, S
::v('prenom'), S
::v('nom'), S
::v('femme'));
271 $nl->toHtml($page, S
::v('prenom'), S
::v('nom'), S
::v('femme'));
273 if (Post
::has('send')) {
274 $nl->sendTo(S
::v('prenom'), S
::v('nom'),
275 S
::v('bestalias'), S
::v('femme'),
276 S
::v('mail_fmt') != 'texte');