87ba7a1397b123d0fc07d2ddbec89df409e9f0d3
2 /***************************************************************************
3 * Copyright (C) 2003-2006 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 NewsletterModule
extends PLModule
27 'nl' => $this->make_hook('nl', AUTH_COOKIE
),
28 'nl/show' => $this->make_hook('nl_show', AUTH_COOKIE
),
29 'nl/submit' => $this->make_hook('nl_submit', AUTH_MDP
),
30 'admin/newsletter' => $this->make_hook('admin_nl', AUTH_MDP
, 'admin'),
31 'admin/newsletter/categories' => $this->make_hook('admin_nl_cat', AUTH_MDP
, 'admin'),
32 'admin/newsletter/edit' => $this->make_hook('admin_nl_edit', AUTH_MDP
, 'admin'),
36 function handler_nl(&$page, $action = null
)
38 require_once 'newsletter.inc.php';
40 $page->changeTpl('newsletter/index.tpl');
41 $page->assign('xorg_title','Polytechnique.org - Lettres mensuelles');
44 case 'out': Newsletter
::unsubscribe(); break;
45 case 'in': Newsletter
::subscribe(); break;
49 $page->assign('nls', Newsletter
::subscriptionState());
50 $page->assign('nl_list', Newsletter
::listSent());
53 function handler_nl_show(&$page, $nid = 'last')
55 $page->changeTpl('newsletter/show.tpl');
57 require_once 'newsletter.inc.php';
59 $nl = new NewsLetter($nid);
60 if (Get
::has('text')) {
61 $nl->toText($page, S
::v('prenom'), S
::v('nom'), S
::v('femme'));
63 $nl->toHtml($page, S
::v('prenom'), S
::v('nom'), S
::v('femme'));
65 if (Post
::has('send')) {
66 $nl->sendTo(S
::v('prenom'), S
::v('nom'),
67 S
::v('bestalias'), S
::v('femme'),
68 S
::v('mail_fmt') != 'texte');
72 function handler_nl_submit(&$page)
74 $page->changeTpl('newsletter/submit.tpl');
76 require_once 'newsletter.inc.php';
78 if (Post
::has('see')) {
79 $art = new NLArticle(Post
::v('title'), Post
::v('body'), Post
::v('append'));
80 $page->assign('art', $art);
81 } elseif (Post
::has('valid')) {
82 require_once('validations.inc.php');
83 $art = new NLReq(S
::v('uid'), Post
::v('title'),
84 Post
::v('body'), Post
::v('append'));
86 $page->assign('submited', true
);
90 function handler_admin_nl(&$page, $new = false
) {
91 $page->changeTpl('newsletter/admin.tpl');
92 $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : liste');
93 require_once("newsletter.inc.php");
97 pl_redirect("admin/newsletter");
100 $page->assign('nl_list', Newsletter
::listAll());
103 function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null
, $action = 'edit') {
104 $page->changeTpl('newsletter/edit.tpl');
105 $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Edition');
106 require_once("newsletter.inc.php");
108 $nl = new NewsLetter($nid);
110 if($action == 'delete') {
111 $nl->delArticle($aid);
112 pl_redirect("admin/newsletter/edit/$nid");
115 if($aid == 'update') {
116 $nl->_title
= Post
::v('title');
117 $nl->_title_mail
= Post
::v('title_mail');
118 $nl->_date
= Post
::v('date');
119 $nl->_head
= Post
::v('head');
120 $nl->_shortname
= strlen(Post
::v('shortname')) ? Post
::v('shortname') : null
;
121 if (preg_match('/^[-a-z0-9]*$/i', $nl->_shortname
) && !is_numeric($nl->_shortname
)) {
124 $page->trig('Le nom de la NL n\'est pas valide');
125 pl_redirect('admin/newsletter/edit/' . $nl->_id
);
129 if(Post
::v('save')) {
130 $art = new NLArticle(Post
::v('title'), Post
::v('body'), Post
::v('append'),
131 $aid, Post
::v('cid'), Post
::v('pos'));
132 $nl->saveArticle($art);
133 pl_redirect("admin/newsletter/edit/$nid");
136 if($action == 'edit' && $aid != 'update') {
138 if(Post
::has('title')) {
139 $art = new NLArticle(Post
::v('title'), Post
::v('body'), Post
::v('append'),
140 $eaid, Post
::v('cid'), Post
::v('pos'));
142 $art = ($eaid == 'new') ?
new NLArticle() : $nl->getArt($eaid);
144 $page->assign('art', $art);
147 $page->assign_by_ref('nl',$nl);
150 function handler_admin_nl_cat(&$page, $action = 'list', $id = null
) {
151 $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Catégories');
152 $page->assign('title', 'Gestion des catégories de la newsletter');
153 $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid');
154 $table_editor->describe('titre','intitulé',true
);
155 $table_editor->describe('pos','position',true
);
156 $table_editor->apply($page, $action, $id);