Commit | Line | Data |
---|---|---|
e2efba7d | 1 | <?php |
2 | /*************************************************************************** | |
8d84c630 | 3 | * Copyright (C) 2003-2009 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( | |
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'), | |
33 | ); | |
34 | } | |
35 | ||
e2efba7d | 36 | function handler_nl(&$page, $action = null) |
37 | { | |
38 | require_once 'newsletter.inc.php'; | |
39 | ||
40 | $page->changeTpl('newsletter/index.tpl'); | |
46f272fe | 41 | $page->setTitle('Lettres mensuelles'); |
e2efba7d | 42 | |
43 | switch ($action) { | |
4882f4a5 | 44 | case 'out': Newsletter::unsubscribe(); break; |
45 | case 'in': Newsletter::subscribe(); break; | |
e2efba7d | 46 | default: ; |
47 | } | |
48 | ||
4882f4a5 | 49 | $page->assign('nls', Newsletter::subscriptionState()); |
50 | $page->assign('nl_list', Newsletter::listSent()); | |
e2efba7d | 51 | } |
52 | ||
53 | function handler_nl_show(&$page, $nid = 'last') | |
54 | { | |
55 | $page->changeTpl('newsletter/show.tpl'); | |
56 | ||
57 | require_once 'newsletter.inc.php'; | |
58 | ||
9da70671 SJ |
59 | try { |
60 | $nl = new NewsLetter($nid); | |
61 | if (Get::has('text')) { | |
62 | $nl->toText($page, S::v('prenom'), S::v('nom'), S::v('femme')); | |
63 | } else { | |
64 | $nl->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme')); | |
65 | } | |
66 | if (Post::has('send')) { | |
67 | $res = XDB::query("SELECT hash | |
68 | FROM newsletter_ins | |
69 | WHERE user_id = {?}", | |
70 | S::i('uid')); | |
71 | $nl->sendTo(S::user()->login(), S::user()->bestEmail(), | |
72 | S::v('prenom'), S::v('nom'), | |
73 | S::v('femme'), S::v('mail_fmt') != 'texte', | |
74 | $res->fetchOneCell()); | |
75 | } | |
76 | } catch (MailNotFound $e) { | |
77 | return PL_NOT_FOUND; | |
e2efba7d | 78 | } |
79 | } | |
80 | ||
81 | function handler_nl_submit(&$page) | |
82 | { | |
83 | $page->changeTpl('newsletter/submit.tpl'); | |
84 | ||
85 | require_once 'newsletter.inc.php'; | |
8f201b69 FB |
86 | $wp = new PlWikiPage('Xorg.LettreMensuelle'); |
87 | $wp->buildCache(); | |
e2efba7d | 88 | |
1970c12b | 89 | if (Post::has('see') || (Post::has('valid') && (!trim(Post::v('title')) || !trim(Post::v('body'))))) { |
90 | if (!Post::has('see')) { | |
a7d35093 | 91 | $page->trigError("L'article doit avoir un titre et un contenu"); |
1970c12b | 92 | } |
e2efba7d | 93 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append')); |
94 | $page->assign('art', $art); | |
95 | } elseif (Post::has('valid')) { | |
96 | require_once('validations.inc.php'); | |
5daf68f6 | 97 | $art = new NLReq(S::user(), Post::v('title'), |
e2efba7d | 98 | Post::v('body'), Post::v('append')); |
99 | $art->submit(); | |
100 | $page->assign('submited', true); | |
101 | } | |
1970c12b | 102 | $page->addCssLink('nl.css'); |
e2efba7d | 103 | } |
104 | ||
105 | function handler_admin_nl(&$page, $new = false) { | |
106 | $page->changeTpl('newsletter/admin.tpl'); | |
46f272fe | 107 | $page->setTitle('Administration - Newsletter : liste'); |
e2efba7d | 108 | require_once("newsletter.inc.php"); |
eaf30d86 | 109 | |
e2efba7d | 110 | if($new) { |
4882f4a5 | 111 | Newsletter::create(); |
112 | pl_redirect("admin/newsletter"); | |
e2efba7d | 113 | } |
eaf30d86 | 114 | |
4882f4a5 | 115 | $page->assign('nl_list', Newsletter::listAll()); |
e2efba7d | 116 | } |
eaf30d86 | 117 | |
e2efba7d | 118 | function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null, $action = 'edit') { |
119 | $page->changeTpl('newsletter/edit.tpl'); | |
3ad44e08 | 120 | $page->addCssLink('nl.css'); |
46f272fe | 121 | $page->setTitle('Administration - Newsletter : Edition'); |
e2efba7d | 122 | require_once("newsletter.inc.php"); |
eaf30d86 | 123 | |
e2efba7d | 124 | $nl = new NewsLetter($nid); |
eaf30d86 | 125 | |
e2efba7d | 126 | if($action == 'delete') { |
127 | $nl->delArticle($aid); | |
128 | pl_redirect("admin/newsletter/edit/$nid"); | |
129 | } | |
eaf30d86 | 130 | |
e2efba7d | 131 | if($aid == 'update') { |
132 | $nl->_title = Post::v('title'); | |
133 | $nl->_title_mail= Post::v('title_mail'); | |
134 | $nl->_date = Post::v('date'); | |
135 | $nl->_head = Post::v('head'); | |
136 | $nl->_shortname = strlen(Post::v('shortname')) ? Post::v('shortname') : null; | |
137 | if (preg_match('/^[-a-z0-9]*$/i', $nl->_shortname) && !is_numeric($nl->_shortname)) { | |
138 | $nl->save(); | |
139 | } else { | |
a7d35093 | 140 | $page->trigError('Le nom de la NL n\'est pas valide'); |
e2efba7d | 141 | pl_redirect('admin/newsletter/edit/' . $nl->_id); |
142 | } | |
143 | } | |
eaf30d86 | 144 | |
e2efba7d | 145 | if(Post::v('save')) { |
146 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), | |
147 | $aid, Post::v('cid'), Post::v('pos')); | |
148 | $nl->saveArticle($art); | |
149 | pl_redirect("admin/newsletter/edit/$nid"); | |
150 | } | |
eaf30d86 | 151 | |
e2efba7d | 152 | if($action == 'edit' && $aid != 'update') { |
153 | $eaid = $aid; | |
154 | if(Post::has('title')) { | |
155 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), | |
156 | $eaid, Post::v('cid'), Post::v('pos')); | |
157 | } else { | |
158 | $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid); | |
159 | } | |
160 | $page->assign('art', $art); | |
161 | } | |
eaf30d86 | 162 | |
e2efba7d | 163 | $page->assign_by_ref('nl',$nl); |
164 | } | |
165 | ||
166 | function handler_admin_nl_cat(&$page, $action = 'list', $id = null) { | |
46f272fe | 167 | $page->setTitle('Administration - Newsletter : Catégories'); |
a7de4ef7 | 168 | $page->assign('title', 'Gestion des catégories de la newsletter'); |
e2efba7d | 169 | $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid'); |
a7de4ef7 | 170 | $table_editor->describe('titre','intitulé',true); |
e2efba7d | 171 | $table_editor->describe('pos','position',true); |
172 | $table_editor->apply($page, $action, $id); | |
bc0903c7 | 173 | } |
e2efba7d | 174 | } |
175 | ||
a7de4ef7 | 176 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
e2efba7d | 177 | ?> |