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/show' => $this->make_hook('show', AUTH_COOKIE
),
29 'ax/edit' => $this->make_hook('submit', AUTH_MDP
),
30 'ax/edit/cancel' => $this->make_hook('cancel', AUTH_MDP
),
31 'ax/edit/valid' => $this->make_hook('valid', AUTH_MDP
),
32 'admin/axletter/rights' => $this->make_hook('admin_rights', AUTH_MDP
, 'admin'),
36 function handler_index(&$page, $action = null
, $hash = null
)
38 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
40 $page->changeTpl('axletter/index.tpl');
41 $page->assign('xorg_title','Polytechnique.org - Envois de l\'AX');
44 case 'out': AXLetter
::unsubscribe($hash); break;
45 case 'in': AXLetter
::subscribe(); break;
49 $perm = AXLetter
::hasPerms();
51 $waiting = AXLetter
::awaiting();
53 $new = new AXLetter($waiting);
54 $page->assign('new', $new);
57 $page->assign('axs', AXLetter
::subscriptionState());
58 $page->assign('ax_list', AXLetter
::listSent());
59 $page->assign('ax_rights', $perm);
62 function handler_submit(&$page, $action = null
)
64 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
65 if (!AXLetter
::hasPerms()) {
69 $page->changeTpl('axletter/edit.tpl');
71 $saved = Post
::i('saved');
74 $shortname = trim(Post
::v('shortname'));
75 $subject = trim(Post
::v('subject'));
76 $title = trim(Post
::v('title'));
77 $body = rtrim(Post
::v('body'));
78 $signature = trim(Post
::v('signature'));
79 $promo_min = Post
::i('promo_min');
80 $promo_max = Post
::i('promo_max');
81 $echeance = Post
::has('echeance_date') ? Post
::v('echeance_date') . ' ' . Post
::v('echeance_time')
82 : Post
::v('echeance');
83 $echeance_date = Post
::v('echeance_date');
84 $echeance_time = Post
::v('echeance_time');
87 $res = XDB
::query("SELECT * FROM axletter WHERE FIND_IN_SET('new', bits)");
88 if ($res->numRows()) {
89 extract($res->fetchOneAssoc(), EXTR_OVERWRITE
);
92 XDB
::execute("INSERT INTO axletter SET id = NULL");
93 $id = XDB
::insertId();
95 if (!$echeance ||
$echeance == '0000-00-00 00:00:00') {
99 } elseif (Post
::has('valid')) {
100 if (!$subject && $title) {
103 if (!$title && $subject) {
106 if (!$subject ||
!$title ||
!$body) {
107 $page->trig("L'article doit avoir un sujet et un contenu");
110 if (($promo_min > $promo_max && $promo_max != 0)||
111 ($promo_min != 0 && ($promo_min <= 1900 ||
$promo_min >= 2020)) ||
112 ($promo_max != 0 && ($promo_max <= 1900 ||
$promo_max >= 2020)))
114 $page->trig("L'intervalle de promotions n'est pas valide");
117 if (empty($shortname)) {
118 $page->trig("L'annonce doit avoir un nom raccourci pour simplifier la navigation dans les archives");
120 } elseif (!preg_match('/^[a-z][-a-z0-9]*[a-z0-9]$/', $shortname)) {
121 $page->trig("Le nom raccourci n'est pas valide, il doit comporter au moins 2 caractères et n'être composé "
122 . "que de chiffres, lettres et tirets");
124 } elseif ($shortname != Post
::v('old_shortname')) {
125 $res = XDB
::query("SELECT id FROM axletter WHERE shortname = {?}", $shortname);
126 if ($res->numRows() && $res->fetchOneCell() != $id) {
127 $page->trig("Le nom $shortname est déjà utilisé, merci d'en choisir un autre");
128 $shortname = Post
::v('old_shortname');
129 if (empty($shortname)) {
135 switch (@Post
::v('valid')) {
137 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
138 $al = new AXLetter(array($id, $shortname, $subject, $title, $body, $signature,
139 $promo_min, $promo_max, $echeance, 0, 'new'));
140 $al->toHtml($page, S
::v('prenom'), S
::v('nom'), S
::v('femme'));
144 XDB
::execute("REPLACE INTO axletter
145 SET id = {?}, shortname = {?}, subject = {?}, title = {?}, body = {?},
146 signature = {?}, promo_min = {?}, promo_max = {?}, echeance = {?}",
147 $id, $shortname, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance);
149 $echeance_date = null
;
150 $echeance_time = null
;
155 $page->assign('id', $id);
156 $page->assign('shortname', $shortname);
157 $page->assign('subject', $subject);
158 $page->assign('title', $title);
159 $page->assign('body', $body);
160 $page->assign('signature', $signature);
161 $page->assign('promo_min', $promo_min);
162 $page->assign('promo_max', $promo_max);
163 $page->assign('echeance', $echeance);
164 $page->assign('echeance_date', $echeance_date);
165 $page->assign('echeance_time', $echeance_time);
166 $page->assign('saved', $saved);
167 $page->assign('new', $new);
168 $page->assign('is_xorg', S
::has_perms());
172 $time = time() +
3600 * 24 * 2;
173 for ($i = 0 ; $i < 15 ; $i++
) {
175 $p_stamp = date('Ymd', $time);
176 $year = date('Y', $time);
177 $month = date('m', $time);
178 $day = date('d', $time);
180 if ($p_stamp == $echeance_date) {
181 $sel = ' selected="selected"';
185 $select .= "<option value=\"$p_stamp\"$sel> $day / $month / $year</option>\n";
187 $page->assign('echeance_date', $select);
189 for ($i = 0 ; $i < 24 ; $i++
) {
190 $stamp = sprintf('%02d:00:00', $i);
191 if ($stamp == $echeance_time) {
192 $sel = ' selected="selected"';
196 $select .= "<option value=\"$stamp\"$sel>{$i}h</option>\n";
198 $page->assign('echeance_time', $select);
202 function handler_cancel(&$page, $force = null
)
204 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
205 if (!AXLetter
::hasPerms()) {
209 $url = parse_url($_SERVER['HTTP_REFERER']);
210 if ($force != 'force' && trim($url['path'], '/') != 'ax/edit') {
214 $waiting = AXLetter
::awaiting();
216 $page->kill("Aucune lettre en attente");
219 $al = new AXLetter($waiting);
220 if (!$al->invalid()) {
221 $page->kill("Une erreur est survenue lors de l'annulation de l'envoi");
225 $page->kill("L'envoi de l'annonce {$al->title()} est annulé");
228 function handler_valid(&$page, $force = null
)
230 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
231 if (!AXLetter
::hasPerms()) {
235 $url = parse_url($_SERVER['HTTP_REFERER']);
236 if ($force != 'force' && trim($url['path'], '/') != 'ax/edit') {
240 $waiting = AXLetter
::awaiting();
242 $page->kill("Aucune lettre en attente");
245 $al = new AXLetter($waiting);
247 $page->kill("Une erreur est survenue lors de la validation de l'envoi");
251 $page->kill("L'envoi de l'annonce aura lieu dans l'heure qui vient.");
254 function handler_show(&$page, $nid = 'last')
256 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
257 $page->changeTpl('axletter/show.tpl');
259 $nl = new AXLetter($nid);
260 if (Get
::has('text')) {
261 $nl->toText($page, S
::v('prenom'), S
::v('nom'), S
::v('femme'));
263 $nl->toHtml($page, S
::v('prenom'), S
::v('nom'), S
::v('femme'));
265 if (Post
::has('send')) {
266 $nl->sendTo(S
::v('prenom'), S
::v('nom'),
267 S
::v('bestalias'), S
::v('femme'),
268 S
::v('mail_fmt') != 'texte');