Commit | Line | Data |
---|---|---|
e2efba7d | 1 | <?php |
2 | /*************************************************************************** | |
12262f13 | 3 | * Copyright (C) 2003-2011 Polytechnique.org * |
e2efba7d | 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 NewsletterModule extends PLModule | |
23 | { | |
24 | function handlers() | |
25 | { | |
26 | return array( | |
e5ceaa8c RB |
27 | 'nl' => $this->make_hook('nl', AUTH_COOKIE, 'user'), |
28 | 'nl/show' => $this->make_hook('nl_show', AUTH_COOKIE, 'user'), | |
29 | 'nl/search' => $this->make_hook('nl_search', AUTH_COOKIE, 'user'), | |
bfe9f4c7 SJ |
30 | 'nl/submit' => $this->make_hook('nl_submit', AUTH_PASSWD, 'user'), |
31 | 'nl/remaining' => $this->make_hook('nl_remaining', AUTH_PASSWD, 'user'), | |
32 | 'admin/nls' => $this->make_hook('admin_nl_groups', AUTH_PASSWD, 'admin'), | |
33 | 'admin/newsletter' => $this->make_hook('admin_nl', AUTH_PASSWD, 'admin'), | |
34 | 'admin/newsletter/categories' => $this->make_hook('admin_nl_cat', AUTH_PASSWD, 'admin'), | |
35 | 'admin/newsletter/edit' => $this->make_hook('admin_nl_edit', AUTH_PASSWD, 'admin'), | |
36 | 'admin/newsletter/edit/delete' => $this->make_hook('admin_nl_delete', AUTH_PASSWD, 'admin'), | |
a8d1ec11 | 37 | 'stat/newsletter' => $this->make_hook('stat_nl', AUTH_PASSWD, 'admin') |
84163d58 | 38 | // Automatic mailing is disabled for X.org NL |
bfe9f4c7 SJ |
39 | // 'admin/newsletter/edit/cancel' => $this->make_hook('cancel', AUTH_PASSWD, 'admin'), |
40 | // 'admin/newsletter/edit/valid' => $this->make_hook('valid', AUTH_PASSWD, 'admin'), | |
e2efba7d | 41 | ); |
42 | } | |
43 | ||
84163d58 RB |
44 | /** This function should return the adequate NewsLetter object for the current module. |
45 | */ | |
46 | protected function getNl() | |
e2efba7d | 47 | { |
48 | require_once 'newsletter.inc.php'; | |
84163d58 RB |
49 | return NewsLetter::forGroup(NewsLetter::GROUP_XORG); |
50 | } | |
51 | ||
602119a2 | 52 | function handler_nl($page, $action = null, $hash = null, $issue_id = null) |
84163d58 RB |
53 | { |
54 | $nl = $this->getNl(); | |
55 | if (!$nl) { | |
56 | return PL_NOT_FOUND; | |
57 | } | |
e2efba7d | 58 | |
602119a2 | 59 | $hash = ($hash == 'nohash') ? null : $hash; |
e2efba7d | 60 | switch ($action) { |
440b8516 SJ |
61 | case 'out': |
62 | $success = $nl->unsubscribe($issue_id, $hash, $hash != null); | |
63 | if (!is_null($hash)) { | |
64 | if ($success) { | |
65 | $page->trigSuccess('La désinscription a été effectuée avec succès.'); | |
66 | } else { | |
67 | $page->trigError("La désinscription n'a été pas pu être effectuée."); | |
68 | } | |
69 | return; | |
70 | } | |
71 | break; | |
84163d58 | 72 | case 'in': $nl->subscribe(); break; |
e2efba7d | 73 | default: ; |
74 | } | |
75 | ||
440b8516 SJ |
76 | $page->changeTpl('newsletter/index.tpl'); |
77 | $page->setTitle('Lettres mensuelles'); | |
78 | ||
84163d58 RB |
79 | $page->assign_by_ref('nl', $nl); |
80 | $page->assign('nls', $nl->subscriptionState()); | |
81 | $page->assign('nl_list', $nl->listSentIssues(true)); | |
e2efba7d | 82 | } |
83 | ||
26ba053e | 84 | function handler_nl_show($page, $nid = 'last') |
e2efba7d | 85 | { |
86 | $page->changeTpl('newsletter/show.tpl'); | |
84163d58 RB |
87 | $nl = $this->getNl(); |
88 | if (!$nl) { | |
89 | return PL_NOT_FOUND; | |
90 | } | |
e2efba7d | 91 | |
9da70671 | 92 | try { |
84163d58 | 93 | $issue = $nl->getIssue($nid); |
6d1747b3 | 94 | $user =& S::user(); |
9da70671 | 95 | if (Get::has('text')) { |
84163d58 | 96 | $issue->toText($page, $user); |
9da70671 | 97 | } else { |
84163d58 | 98 | $issue->toHtml($page, $user); |
9da70671 SJ |
99 | } |
100 | if (Post::has('send')) { | |
84163d58 | 101 | $issue->sendTo($user); |
9da70671 SJ |
102 | } |
103 | } catch (MailNotFound $e) { | |
104 | return PL_NOT_FOUND; | |
e2efba7d | 105 | } |
106 | } | |
107 | ||
5e9a29ed SJ |
108 | function handler_nl_search($page) |
109 | { | |
110 | S::assert_xsrf_token(); | |
111 | $nl = $this->getNl(); | |
112 | if (!$nl) { | |
113 | return PL_NOT_FOUND; | |
114 | } | |
115 | ||
116 | if (!Post::has('nl_search')) { | |
b6d52898 | 117 | pl_redirect($nl->prefix(true, false)); |
5e9a29ed SJ |
118 | } |
119 | ||
120 | $nl_search = Post::t('nl_search'); | |
121 | $nl_search_type = Post::t('nl_search_type'); | |
122 | if (!$nl_search || !($nl_search_type > 0 && $nl_search_type < 10)) { | |
123 | $page->trigErrorRedirect('La recherche est vide ou erronée.', $nl->prefix()); | |
124 | } | |
125 | ||
126 | $page->changeTpl('newsletter/search.tpl'); | |
127 | $user = S::user(); | |
128 | $fields = array(1 => 'all', 2 => 'all', 3 => 'title', 4 => 'body', 5 => 'append', 6 => 'all', 7 => 'title', 8 => 'head', 9 => 'signature'); | |
129 | $res_articles = $res_issues = array(); | |
130 | if ($nl_search_type < 6) { | |
131 | $res_articles = $nl->articleSearch($nl_search, $fields[$nl_search_type], $user); | |
132 | } | |
133 | if ($nl_search_type > 5 || $nl_search_type == 1) { | |
134 | $res_issues = $nl->issueSearch($nl_search, $fields[$nl_search_type], $user); | |
135 | } | |
136 | ||
137 | $articles_count = count($res_articles); | |
138 | $issues_count = count($res_issues); | |
139 | $results_count = $articles_count + $issues_count; | |
140 | if ($results_count > 200) { | |
141 | $page->trigError('Recherche trop générale.'); | |
142 | } elseif ($results_count == 0) { | |
143 | $page->trigWarning('Aucun résultat pour cette recherche.'); | |
144 | } else { | |
145 | $page->assign('res_articles', $res_articles); | |
146 | $page->assign('res_issues', $res_issues); | |
147 | $page->assign('articles_count', $articles_count); | |
148 | $page->assign('issues_count', $issues_count); | |
149 | } | |
150 | ||
151 | $page->assign_by_ref('nl', $nl); | |
152 | $page->assign('nl_search', $nl_search); | |
153 | $page->assign('nl_search_type', $nl_search_type); | |
154 | $page->assign('results_count', $results_count); | |
155 | } | |
156 | ||
26ba053e | 157 | function handler_nl_submit($page) |
e2efba7d | 158 | { |
159 | $page->changeTpl('newsletter/submit.tpl'); | |
160 | ||
84163d58 RB |
161 | $nl = $this->getNl(); |
162 | if (!$nl) { | |
163 | return PL_NOT_FOUND; | |
164 | } | |
165 | ||
8f201b69 FB |
166 | $wp = new PlWikiPage('Xorg.LettreMensuelle'); |
167 | $wp->buildCache(); | |
e2efba7d | 168 | |
1970c12b | 169 | if (Post::has('see') || (Post::has('valid') && (!trim(Post::v('title')) || !trim(Post::v('body'))))) { |
170 | if (!Post::has('see')) { | |
a7d35093 | 171 | $page->trigError("L'article doit avoir un titre et un contenu"); |
1970c12b | 172 | } |
e2efba7d | 173 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append')); |
174 | $page->assign('art', $art); | |
175 | } elseif (Post::has('valid')) { | |
5daf68f6 | 176 | $art = new NLReq(S::user(), Post::v('title'), |
e2efba7d | 177 | Post::v('body'), Post::v('append')); |
178 | $art->submit(); | |
179 | $page->assign('submited', true); | |
180 | } | |
84163d58 | 181 | $page->addCssLink($nl->cssFile()); |
e2efba7d | 182 | } |
183 | ||
0fd5be99 SJ |
184 | function handler_nl_remaining($page) |
185 | { | |
186 | require_once 'newsletter.inc.php'; | |
187 | ||
188 | pl_content_headers('text/html'); | |
189 | $page->changeTpl('newsletter/remaining.tpl', NO_SKIN); | |
190 | ||
191 | $article = new NLArticle('', Post::t('body'), ''); | |
192 | $rest = $article->remain(); | |
193 | ||
194 | $page->assign('too_long', $rest['remaining_lines'] < 0); | |
195 | $page->assign('last_line', ($rest['remaining_lines'] == 0)); | |
196 | $page->assign('remaining', ($rest['remaining_lines'] == 0) ? $rest['remaining_characters_for_last_line'] : $rest['remaining_lines']); | |
197 | } | |
198 | ||
26ba053e | 199 | function handler_admin_nl($page, $new = false) { |
e2efba7d | 200 | $page->changeTpl('newsletter/admin.tpl'); |
46f272fe | 201 | $page->setTitle('Administration - Newsletter : liste'); |
84163d58 RB |
202 | |
203 | $nl = $this->getNl(); | |
204 | if (!$nl) { | |
205 | return PL_NOT_FOUND; | |
206 | } | |
eaf30d86 | 207 | |
2d1ed661 | 208 | if ($new == 'new') { |
93f23312 SJ |
209 | // Logs NL creation. |
210 | S::logger()->log('nl_issue_create', $nid); | |
211 | ||
84163d58 | 212 | $id = $nl->createPending(); |
b6d52898 | 213 | pl_redirect($nl->adminPrefix(true, false) . '/edit/' . $id); |
e2efba7d | 214 | } |
eaf30d86 | 215 | |
84163d58 RB |
216 | $page->assign_by_ref('nl', $nl); |
217 | $page->assign('nl_list', $nl->listAllIssues()); | |
218 | } | |
219 | ||
63273514 | 220 | function handler_admin_nl_groups($page, $sort = 'id', $order = 'ASC') |
84163d58 RB |
221 | { |
222 | require_once 'newsletter.inc.php'; | |
223 | ||
63273514 SJ |
224 | static $titles = array( |
225 | 'id' => 'Id', | |
226 | 'group_name' => 'Groupe', | |
227 | 'name' => 'Titre', | |
228 | 'custom_css' => 'CSS spécifique', | |
229 | 'criteria' => 'Critères actifs' | |
230 | ); | |
231 | static $next_orders = array( | |
232 | 'ASC' => 'DESC', | |
233 | 'DESC' => 'ASC' | |
234 | ); | |
235 | ||
236 | if (!array_key_exists($sort, $titles)) { | |
237 | $sort = 'id'; | |
238 | } | |
239 | if (!in_array($order, array('ASC', 'DESC'))) { | |
240 | $order = 'ASC'; | |
241 | } | |
242 | ||
84163d58 RB |
243 | $page->changeTpl('newsletter/admin_all.tpl'); |
244 | $page->setTitle('Administration - Newsletters : Liste des Newsletters'); | |
63273514 SJ |
245 | $page->assign('nls', Newsletter::getAll($sort, $order)); |
246 | $page->assign('sort', $sort); | |
247 | $page->assign('order', $order); | |
248 | $page->assign('next_order', $next_orders[$order]); | |
249 | $page->assign('titles', $titles); | |
e2efba7d | 250 | } |
eaf30d86 | 251 | |
26ba053e | 252 | function handler_admin_nl_edit($page, $nid = 'last', $aid = null, $action = 'edit') { |
e2efba7d | 253 | $page->changeTpl('newsletter/edit.tpl'); |
84163d58 | 254 | $page->addCssLink('nl.Polytechnique.org.css'); |
e4705641 | 255 | $page->setTitle('Administration - Newsletter : Édition'); |
eaf30d86 | 256 | |
84163d58 RB |
257 | $nl = $this->getNl(); |
258 | if (!$nl) { | |
259 | return PL_NOT_FOUND; | |
260 | } | |
eaf30d86 | 261 | |
84163d58 RB |
262 | try { |
263 | $issue = $nl->getIssue($nid, false); | |
264 | } catch (MailNotFound $e) { | |
265 | return PL_NOT_FOUND; | |
e2efba7d | 266 | } |
eaf30d86 | 267 | |
84163d58 RB |
268 | $ufb = $nl->getSubscribersUFB(); |
269 | $ufb_keepenv = false; // Will be set to True if there were invalid modification to the UFB. | |
270 | ||
271 | // Convert NLIssue error messages to human-readable errors | |
272 | $error_msgs = array( | |
5f0c028a | 273 | NLIssue::ERROR_INVALID_REPLY_TO => "L'adresse de réponse est invalide.", |
84163d58 RB |
274 | NLIssue::ERROR_INVALID_SHORTNAME => "Le nom court est invalide ou vide.", |
275 | NLIssue::ERROR_INVALID_UFC => "Le filtre des destinataires est invalide.", | |
a718afe9 | 276 | NLIssue::ERROR_TOO_LONG_UFC => "Le nombre de matricules AX renseigné est trop élevé.", |
84163d58 RB |
277 | NLIssue::ERROR_SQL_SAVE => "Une erreur est survenue en tentant de sauvegarder la lettre, merci de réessayer.", |
278 | ); | |
279 | ||
280 | // Update the current issue | |
2d1ed661 | 281 | if($aid == 'update' && Post::has('submit')) { |
84163d58 RB |
282 | |
283 | // Save common fields | |
284 | $issue->title = Post::s('title'); | |
285 | $issue->title_mail = Post::s('title_mail'); | |
286 | $issue->head = Post::s('head'); | |
287 | $issue->signature = Post::s('signature'); | |
5f0c028a | 288 | $issue->reply_to = Post::s('reply_to'); |
84163d58 RB |
289 | |
290 | if ($issue->isEditable()) { | |
291 | // Date and shortname may only be modified for pending NLs, otherwise all links get broken. | |
292 | $issue->date = Post::s('date'); | |
293 | $issue->shortname = strlen(Post::blank('shortname')) ? null : Post::s('shortname'); | |
294 | $issue->sufb->updateFromEnv($ufb->getEnv()); | |
295 | ||
296 | if ($nl->automaticMailingEnabled()) { | |
297 | $issue->send_before = preg_replace('/^(\d\d\d\d)(\d\d)(\d\d)$/', '\1-\2-\3', Post::v('send_before_date')) . ' ' . Post::i('send_before_time_Hour') . ':00:00'; | |
298 | } | |
299 | } | |
300 | $errors = $issue->save(); | |
301 | if (count($errors)) { | |
302 | foreach ($errors as $error_code) { | |
303 | $page->trigError($error_msgs[$error_code]); | |
304 | } | |
e2efba7d | 305 | } |
306 | } | |
eaf30d86 | 307 | |
84163d58 RB |
308 | // Delete an article |
309 | if($action == 'delete') { | |
310 | $issue->delArticle($aid); | |
b6d52898 | 311 | pl_redirect($nl->adminPrefix(true, false) . "/edit/$nid"); |
84163d58 RB |
312 | } |
313 | ||
314 | // Save an article | |
e2efba7d | 315 | if(Post::v('save')) { |
316 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), | |
9e2a6a32 | 317 | $aid, Post::v('cid'), Post::v('pos')); |
84163d58 | 318 | $issue->saveArticle($art); |
b6d52898 | 319 | pl_redirect($nl->adminPrefix(true, false) . "/edit/$nid"); |
e2efba7d | 320 | } |
eaf30d86 | 321 | |
84163d58 | 322 | // Edit an article |
9e2a6a32 | 323 | if ($action == 'edit' && $aid != 'update') { |
e2efba7d | 324 | $eaid = $aid; |
e4705641 | 325 | if (Post::has('title')) { |
e2efba7d | 326 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), |
e4705641 | 327 | $eaid, Post::v('cid'), Post::v('pos')); |
e2efba7d | 328 | } else { |
84163d58 | 329 | $art = ($eaid == 'new') ? new NLArticle() : $issue->getArt($eaid); |
e4705641 SJ |
330 | } |
331 | if ($art && !$art->check()) { | |
332 | $page->trigError("Cet article est trop long."); | |
e2efba7d | 333 | } |
334 | $page->assign('art', $art); | |
335 | } | |
eaf30d86 | 336 | |
84163d58 | 337 | // Check blacklisted IPs |
9e2a6a32 | 338 | if ($aid == 'blacklist_check') { |
955109ba | 339 | global $globals; |
9e2a6a32 | 340 | $ips_to_check = array(); |
955109ba | 341 | $blacklist_host_resolution_count = 0; |
9e2a6a32 | 342 | |
84163d58 | 343 | foreach ($issue->arts as $key => $articles) { |
9e2a6a32 | 344 | foreach ($articles as $article) { |
955109ba | 345 | $article_ips = $article->getLinkIps($blacklist_host_resolution_count); |
9e2a6a32 SJ |
346 | if (!empty($article_ips)) { |
347 | $ips_to_check[$article->title()] = $article_ips; | |
348 | } | |
349 | } | |
350 | } | |
351 | ||
352 | $page->assign('ips_to_check', $ips_to_check); | |
955109ba SJ |
353 | if ($blacklist_host_resolution_count >= $globals->mail->blacklist_host_resolution_limit) { |
354 | $page->trigError("Toutes les url et adresses emails de la lettre" | |
9e2a6a32 SJ |
355 | . " n'ont pas été prises en compte car la" |
356 | . " limite du nombre de résolutions DNS" | |
357 | . " autorisée a été atteinte."); | |
358 | } | |
359 | } | |
360 | ||
84163d58 RB |
361 | if ($issue->state == NLIssue::STATE_SENT) { |
362 | $page->trigWarning("Cette lettre a déjà été envoyée ; il est recommandé de limiter les modifications au maximum (orthographe, adresses web et mail)."); | |
363 | } | |
364 | ||
365 | $ufb->setEnv($issue->sufb->getEnv()); | |
9e2a6a32 | 366 | $page->assign_by_ref('nl', $nl); |
84163d58 RB |
367 | $page->assign_by_ref('issue', $issue); |
368 | } | |
369 | ||
370 | /** This handler will cancel the sending of the currently pending issue | |
371 | * It is disabled for X.org mailings. | |
372 | */ | |
26ba053e | 373 | function handler_admin_nl_cancel($page, $nid, $force = null) |
84163d58 RB |
374 | { |
375 | $nl = $this->getNl(); | |
376 | if (!$nl) { | |
377 | return PL_NOT_FOUND; | |
378 | } | |
379 | ||
380 | if (!$nl->mayEdit() || !S::has_xsrf_token()) { | |
381 | return PL_FORBIDDEN; | |
382 | } | |
383 | ||
384 | if (!$nid) { | |
385 | $page->kill("La lettre n'a pas été spécifiée"); | |
386 | } | |
387 | ||
388 | $issue = $nl->getIssue($nid); | |
389 | if (!$issue) { | |
390 | $page->kill("La lettre {$nid} n'existe pas."); | |
391 | } | |
392 | if (!$issue->cancelMailing()) { | |
393 | $page->trigErrorRedirect("Une erreur est survenue lors de l'annulation de l'envoi.", $nl->adminPrefix()); | |
394 | } | |
395 | ||
93f23312 SJ |
396 | // Logs NL cancelling. |
397 | S::logger()->log('nl_mailing_cancel', $nid); | |
398 | ||
84163d58 RB |
399 | $page->trigSuccessRedirect("L'envoi de l'annonce {$issue->title()} est annulé.", $nl->adminPrefix()); |
400 | } | |
401 | ||
402 | /** This handler will enable the sending of the currently pending issue | |
403 | * It is disabled for X.org mailings. | |
404 | */ | |
26ba053e | 405 | function handler_admin_nl_valid($page, $nid, $force = null) |
84163d58 RB |
406 | { |
407 | $nl = $this->getNl(); | |
408 | if (!$nl) { | |
409 | return PL_NOT_FOUND; | |
410 | } | |
411 | ||
412 | if (!$nl->mayEdit() || !S::has_xsrf_token()) { | |
413 | return PL_FORBIDDEN; | |
414 | } | |
415 | ||
416 | if (!$nid) { | |
417 | $page->kill("La lettre n'a pas été spécifiée."); | |
418 | } | |
419 | ||
420 | $issue = $nl->getIssue($nid); | |
421 | if (!$issue) { | |
422 | $page->kill("La lettre {$nid} n'existe pas."); | |
423 | } | |
424 | if (!$issue->scheduleMailing()) { | |
425 | $page->trigErrorRedirect("Une erreur est survenue lors de la validation de l'envoi.", $nl->adminPrefix()); | |
426 | } | |
427 | ||
93f23312 SJ |
428 | // Logs NL validation. |
429 | S::logger()->log('nl_mailing_valid', $nid); | |
430 | ||
84163d58 RB |
431 | $page->trigSuccessRedirect("L'envoi de la newsletter {$issue->title()} a été validé.", $nl->adminPrefix()); |
432 | } | |
433 | ||
434 | /** This handler will remove the given issue. | |
435 | */ | |
26ba053e | 436 | function handler_admin_nl_delete($page, $nid, $force = null) |
84163d58 RB |
437 | { |
438 | $nl = $this->getNl(); | |
439 | if (!$nl) { | |
440 | return PL_NOT_FOUND; | |
441 | } | |
442 | ||
443 | if (!$nl->mayEdit() || !S::has_xsrf_token()) { | |
444 | return PL_FORBIDDEN; | |
445 | } | |
446 | ||
447 | if (!$nid) { | |
448 | $page->kill("La lettre n'a pas été spécifiée."); | |
449 | } | |
450 | ||
451 | $issue = $nl->getIssue($nid); | |
452 | if (!$issue) { | |
453 | $page->kill("La lettre {$nid} n'existe pas"); | |
454 | } | |
455 | if (!$issue->isEditable()) { | |
456 | $page->trigErrorRedirect("La lette a été envoyée ou est en cours d'envoi, elle ne peut être supprimée.", $nl->adminPrefix()); | |
457 | } | |
458 | if (!$issue->delete()) { | |
459 | $page->trigErrorRedirect("Une erreur est survenue lors de la suppression de la lettre.", $nl->adminPrefix()); | |
460 | } | |
461 | ||
93f23312 SJ |
462 | // Logs NL deletion. |
463 | S::logger()->log('nl_issue_delete', $nid); | |
464 | ||
84163d58 | 465 | $page->trigSuccessRedirect("La lettre a bien été supprimée.", $nl->adminPrefix()); |
e2efba7d | 466 | } |
467 | ||
26ba053e | 468 | function handler_admin_nl_cat($page, $action = 'list', $id = null) { |
42df7fa8 RB |
469 | $nl = $this->getNl(); |
470 | if (!$nl) { | |
471 | return PL_NOT_FOUND; | |
472 | } | |
473 | ||
474 | if (!$nl->mayEdit()) { | |
475 | return PL_FORBIDDEN; | |
476 | } | |
477 | ||
46f272fe | 478 | $page->setTitle('Administration - Newsletter : Catégories'); |
a7de4ef7 | 479 | $page->assign('title', 'Gestion des catégories de la newsletter'); |
42df7fa8 | 480 | $table_editor = new PLTableEditor($nl->adminPrefix() . '/categories', 'newsletter_cat','cid'); |
84163d58 | 481 | $table_editor->describe('title','intitulé',true); |
e2efba7d | 482 | $table_editor->describe('pos','position',true); |
42df7fa8 RB |
483 | if ($nl->group == Newsletter::GROUP_XORG) { |
484 | $table_editor->add_option_table('newsletters', 'newsletters.id = t.nlid'); | |
485 | $table_editor->add_option_field('newsletters.name', 'newsletter_name', 'Newsletter', null, 'nlid'); | |
486 | $table_editor->describe('nlid', 'ID NL', true); | |
487 | } else { | |
488 | $table_editor->force_field_value('nlid', $nl->id); | |
47f51789 | 489 | $table_editor->describe('nlid', 'nlid', false, false); |
42df7fa8 RB |
490 | } |
491 | // Prevent deletion. | |
492 | $table_editor->on_delete(null, null); | |
e2efba7d | 493 | $table_editor->apply($page, $action, $id); |
bc0903c7 | 494 | } |
a8d1ec11 SJ |
495 | |
496 | function handler_stat_nl($page) | |
497 | { | |
498 | $nl = $this->getNl(); | |
499 | if (!$nl) { | |
500 | return PL_NOT_FOUND; | |
501 | } | |
502 | if (!$nl->mayEdit()) { | |
503 | return PL_FORBIDDEN; | |
504 | } | |
505 | ||
506 | $page->setTitle('Statistiques - Newsletter'); | |
507 | $page->changeTpl('newsletter/statistics.tpl'); | |
ccabe1ac SJ |
508 | |
509 | $data = array(); | |
510 | foreach (Profile::$cycles as $grade => $name) { | |
511 | $data[$name] = array(); | |
512 | list($min, $max) = Profile::extremePromotions($grade); | |
513 | $bound = (((int)($min / 10)) + 1) * 10; | |
514 | while ($bound <= $max) { | |
515 | $data[$name][$min . ' - ' . $bound] = array( | |
516 | 'count' => $nl->subscriberCount(null, null, $grade, $min, $bound), | |
517 | 'lost' => $nl->subscriberCount(true, null, $grade, $min, $bound), | |
518 | 'count_female' => $nl->subscriberCount(null, User::GENDER_FEMALE, $grade, $min, $bound), | |
519 | 'lost_female' => $nl->subscriberCount(true, User::GENDER_FEMALE, $grade, $min, $bound) | |
520 | ); | |
521 | $min = $bound + 1; | |
522 | $bound += 10; | |
523 | } | |
524 | $bound -= 9; | |
525 | if ($bound <= $max) { | |
526 | $data[$name][$bound . ' - ' . $max] = array( | |
527 | 'count' => $nl->subscriberCount(null, null, $grade, $bound, $max), | |
528 | 'lost' => $nl->subscriberCount(true, null, $grade, $bound, $max), | |
529 | 'count_female' => $nl->subscriberCount(null, User::GENDER_FEMALE, $grade, $bound, $max), | |
530 | 'lost_female' => $nl->subscriberCount(true, User::GENDER_FEMALE, $grade, $bound, $max) | |
531 | ); | |
532 | } | |
533 | } | |
a8d1ec11 | 534 | $page->assign_by_ref('nl', $nl); |
ccabe1ac SJ |
535 | $page->assign('count', $nl->subscriberCount()); |
536 | $page->assign('lost', $nl->lostSubscriberCount()); | |
537 | $page->assign('count_female', $nl->subscriberCount(null, User::GENDER_FEMALE)); | |
538 | $page->assign('lost_female', $nl->lostSubscriberCount(User::GENDER_FEMALE)); | |
539 | $page->assign('data', $data); | |
a8d1ec11 | 540 | } |
e2efba7d | 541 | } |
542 | ||
a7de4ef7 | 543 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
e2efba7d | 544 | ?> |