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'), |
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'); |
41 | $page->assign('xorg_title','Polytechnique.org - Lettres mensuelles'); |
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 | |
59 | $nl = new NewsLetter($nid); |
11f44323 |
60 | if (Get::has('text')) { |
61 | $nl->toText($page, S::v('prenom'), S::v('nom'), S::v('femme')); |
62 | } else { |
63 | $nl->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme')); |
64 | } |
e2efba7d |
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'); |
69 | } |
70 | } |
71 | |
72 | function handler_nl_submit(&$page) |
73 | { |
74 | $page->changeTpl('newsletter/submit.tpl'); |
75 | |
76 | require_once 'newsletter.inc.php'; |
77 | |
1970c12b |
78 | if (Post::has('see') || (Post::has('valid') && (!trim(Post::v('title')) || !trim(Post::v('body'))))) { |
79 | if (!Post::has('see')) { |
80 | $page->trig("L'article doit avoir un titre et un contenu"); |
81 | } |
e2efba7d |
82 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append')); |
83 | $page->assign('art', $art); |
84 | } elseif (Post::has('valid')) { |
85 | require_once('validations.inc.php'); |
86 | $art = new NLReq(S::v('uid'), Post::v('title'), |
87 | Post::v('body'), Post::v('append')); |
88 | $art->submit(); |
89 | $page->assign('submited', true); |
90 | } |
1970c12b |
91 | $page->addCssLink('nl.css'); |
e2efba7d |
92 | } |
93 | |
94 | function handler_admin_nl(&$page, $new = false) { |
95 | $page->changeTpl('newsletter/admin.tpl'); |
96 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : liste'); |
97 | require_once("newsletter.inc.php"); |
98 | |
99 | if($new) { |
4882f4a5 |
100 | Newsletter::create(); |
101 | pl_redirect("admin/newsletter"); |
e2efba7d |
102 | } |
103 | |
4882f4a5 |
104 | $page->assign('nl_list', Newsletter::listAll()); |
e2efba7d |
105 | } |
106 | |
107 | function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null, $action = 'edit') { |
108 | $page->changeTpl('newsletter/edit.tpl'); |
109 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Edition'); |
110 | require_once("newsletter.inc.php"); |
111 | |
112 | $nl = new NewsLetter($nid); |
113 | |
114 | if($action == 'delete') { |
115 | $nl->delArticle($aid); |
116 | pl_redirect("admin/newsletter/edit/$nid"); |
117 | } |
118 | |
119 | if($aid == 'update') { |
120 | $nl->_title = Post::v('title'); |
121 | $nl->_title_mail= Post::v('title_mail'); |
122 | $nl->_date = Post::v('date'); |
123 | $nl->_head = Post::v('head'); |
124 | $nl->_shortname = strlen(Post::v('shortname')) ? Post::v('shortname') : null; |
125 | if (preg_match('/^[-a-z0-9]*$/i', $nl->_shortname) && !is_numeric($nl->_shortname)) { |
126 | $nl->save(); |
127 | } else { |
128 | $page->trig('Le nom de la NL n\'est pas valide'); |
129 | pl_redirect('admin/newsletter/edit/' . $nl->_id); |
130 | } |
131 | } |
132 | |
133 | if(Post::v('save')) { |
134 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), |
135 | $aid, Post::v('cid'), Post::v('pos')); |
136 | $nl->saveArticle($art); |
137 | pl_redirect("admin/newsletter/edit/$nid"); |
138 | } |
139 | |
140 | if($action == 'edit' && $aid != 'update') { |
141 | $eaid = $aid; |
142 | if(Post::has('title')) { |
143 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), |
144 | $eaid, Post::v('cid'), Post::v('pos')); |
145 | } else { |
146 | $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid); |
147 | } |
148 | $page->assign('art', $art); |
149 | } |
150 | |
151 | $page->assign_by_ref('nl',$nl); |
152 | } |
153 | |
154 | function handler_admin_nl_cat(&$page, $action = 'list', $id = null) { |
155 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Catégories'); |
156 | $page->assign('title', 'Gestion des catégories de la newsletter'); |
157 | $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid'); |
158 | $table_editor->describe('titre','intitulé',true); |
159 | $table_editor->describe('pos','position',true); |
160 | $table_editor->apply($page, $action, $id); |
bc0903c7 |
161 | } |
e2efba7d |
162 | } |
163 | |
164 | ?> |