e2efba7d |
1 | <?php |
2 | /*************************************************************************** |
5ddeb07c |
3 | * Copyright (C) 2003-2007 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'), |
bc0903c7 |
33 | |
34 | 'ax' => $this->make_hook('ax', AUTH_COOKIE), |
35 | 'ax/show' => $this->make_hook('ax_show', AUTH_COOKIE), |
36 | 'ax/submit' => $this->make_hook('ax_submit', AUTH_MDP), |
37 | 'ax/edit' => $this->make_hook('ax_submit', AUTH_MDP), |
38 | 'admin/axletter/rights' => $this->make_hook('admin_ax_rights', AUTH_MDP, 'admin'), |
e2efba7d |
39 | ); |
40 | } |
41 | |
e2efba7d |
42 | function handler_nl(&$page, $action = null) |
43 | { |
44 | require_once 'newsletter.inc.php'; |
45 | |
46 | $page->changeTpl('newsletter/index.tpl'); |
47 | $page->assign('xorg_title','Polytechnique.org - Lettres mensuelles'); |
48 | |
49 | switch ($action) { |
4882f4a5 |
50 | case 'out': Newsletter::unsubscribe(); break; |
51 | case 'in': Newsletter::subscribe(); break; |
e2efba7d |
52 | default: ; |
53 | } |
54 | |
4882f4a5 |
55 | $page->assign('nls', Newsletter::subscriptionState()); |
56 | $page->assign('nl_list', Newsletter::listSent()); |
e2efba7d |
57 | } |
58 | |
59 | function handler_nl_show(&$page, $nid = 'last') |
60 | { |
61 | $page->changeTpl('newsletter/show.tpl'); |
62 | |
63 | require_once 'newsletter.inc.php'; |
64 | |
65 | $nl = new NewsLetter($nid); |
11f44323 |
66 | if (Get::has('text')) { |
67 | $nl->toText($page, S::v('prenom'), S::v('nom'), S::v('femme')); |
68 | } else { |
69 | $nl->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme')); |
70 | } |
e2efba7d |
71 | if (Post::has('send')) { |
72 | $nl->sendTo(S::v('prenom'), S::v('nom'), |
73 | S::v('bestalias'), S::v('femme'), |
74 | S::v('mail_fmt') != 'texte'); |
75 | } |
76 | } |
77 | |
78 | function handler_nl_submit(&$page) |
79 | { |
80 | $page->changeTpl('newsletter/submit.tpl'); |
81 | |
82 | require_once 'newsletter.inc.php'; |
83 | |
84 | if (Post::has('see')) { |
85 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append')); |
86 | $page->assign('art', $art); |
87 | } elseif (Post::has('valid')) { |
88 | require_once('validations.inc.php'); |
89 | $art = new NLReq(S::v('uid'), Post::v('title'), |
90 | Post::v('body'), Post::v('append')); |
91 | $art->submit(); |
92 | $page->assign('submited', true); |
93 | } |
94 | } |
95 | |
96 | function handler_admin_nl(&$page, $new = false) { |
97 | $page->changeTpl('newsletter/admin.tpl'); |
98 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : liste'); |
99 | require_once("newsletter.inc.php"); |
100 | |
101 | if($new) { |
4882f4a5 |
102 | Newsletter::create(); |
103 | pl_redirect("admin/newsletter"); |
e2efba7d |
104 | } |
105 | |
4882f4a5 |
106 | $page->assign('nl_list', Newsletter::listAll()); |
e2efba7d |
107 | } |
108 | |
109 | function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null, $action = 'edit') { |
110 | $page->changeTpl('newsletter/edit.tpl'); |
111 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Edition'); |
112 | require_once("newsletter.inc.php"); |
113 | |
114 | $nl = new NewsLetter($nid); |
115 | |
116 | if($action == 'delete') { |
117 | $nl->delArticle($aid); |
118 | pl_redirect("admin/newsletter/edit/$nid"); |
119 | } |
120 | |
121 | if($aid == 'update') { |
122 | $nl->_title = Post::v('title'); |
123 | $nl->_title_mail= Post::v('title_mail'); |
124 | $nl->_date = Post::v('date'); |
125 | $nl->_head = Post::v('head'); |
126 | $nl->_shortname = strlen(Post::v('shortname')) ? Post::v('shortname') : null; |
127 | if (preg_match('/^[-a-z0-9]*$/i', $nl->_shortname) && !is_numeric($nl->_shortname)) { |
128 | $nl->save(); |
129 | } else { |
130 | $page->trig('Le nom de la NL n\'est pas valide'); |
131 | pl_redirect('admin/newsletter/edit/' . $nl->_id); |
132 | } |
133 | } |
134 | |
135 | if(Post::v('save')) { |
136 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), |
137 | $aid, Post::v('cid'), Post::v('pos')); |
138 | $nl->saveArticle($art); |
139 | pl_redirect("admin/newsletter/edit/$nid"); |
140 | } |
141 | |
142 | if($action == 'edit' && $aid != 'update') { |
143 | $eaid = $aid; |
144 | if(Post::has('title')) { |
145 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), |
146 | $eaid, Post::v('cid'), Post::v('pos')); |
147 | } else { |
148 | $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid); |
149 | } |
150 | $page->assign('art', $art); |
151 | } |
152 | |
153 | $page->assign_by_ref('nl',$nl); |
154 | } |
155 | |
156 | function handler_admin_nl_cat(&$page, $action = 'list', $id = null) { |
157 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Catégories'); |
158 | $page->assign('title', 'Gestion des catégories de la newsletter'); |
159 | $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid'); |
160 | $table_editor->describe('titre','intitulé',true); |
161 | $table_editor->describe('pos','position',true); |
162 | $table_editor->apply($page, $action, $id); |
bc0903c7 |
163 | } |
164 | |
165 | function handler_ax(&$page, $action = null) |
166 | { |
167 | require_once 'newsletter.inc.php'; |
168 | |
169 | $page->changeTpl('newsletter/ax.tpl'); |
170 | $page->assign('xorg_title','Polytechnique.org - Envois de l\'AX'); |
171 | |
172 | switch ($action) { |
173 | case 'out': AXLetter::unsubscribe(); break; |
174 | case 'in': AXLetter::subscribe(); break; |
175 | default: ; |
176 | } |
177 | |
178 | $perm = AXLetter::hasPerms(); |
179 | if ($perm) { |
180 | $waiting = AXLetter::awaiting(); |
181 | if ($waiting) { |
182 | $new = new AXLetter($waiting); |
183 | $page->assign('new', $new); |
184 | } |
185 | } |
186 | $page->assign('axs', AXLetter::subscriptionState()); |
187 | $page->assign('ax_list', AXLetter::listSent()); |
188 | $page->assign('ax_rights', AXLetter::hasPerms()); |
189 | } |
190 | |
191 | function handler_ax_submit(&$page) |
192 | { |
193 | require_once('newsletter.inc.php'); |
194 | if (!AXLetter::hasPerms()) { |
195 | return PL_FORBIDDEN; |
196 | } |
197 | } |
e2efba7d |
198 | } |
199 | |
200 | ?> |