e2efba7d |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
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 | |
36 | function on_subscribe($forlife, $uid, $promo, $password) |
37 | { |
38 | require_once 'newsletter.inc.php'; |
39 | subscribe_nl($uid); |
40 | } |
41 | |
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) { |
50 | case 'out': unsubscribe_nl(); break; |
51 | case 'in': subscribe_nl(); break; |
52 | default: ; |
53 | } |
54 | |
55 | $page->assign('nls', get_nl_state()); |
56 | $page->assign('nl_list', get_nl_list()); |
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); |
66 | $page->assign_by_ref('nl', $nl); |
67 | |
68 | if (Post::has('send')) { |
69 | $nl->sendTo(S::v('prenom'), S::v('nom'), |
70 | S::v('bestalias'), S::v('femme'), |
71 | S::v('mail_fmt') != 'texte'); |
72 | } |
73 | } |
74 | |
75 | function handler_nl_submit(&$page) |
76 | { |
77 | $page->changeTpl('newsletter/submit.tpl'); |
78 | |
79 | require_once 'newsletter.inc.php'; |
80 | |
81 | if (Post::has('see')) { |
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 | } |
91 | } |
92 | |
93 | function handler_admin_nl(&$page, $new = false) { |
94 | $page->changeTpl('newsletter/admin.tpl'); |
95 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : liste'); |
96 | require_once("newsletter.inc.php"); |
97 | |
98 | if($new) { |
99 | insert_new_nl(); |
100 | pl_redirect("admin/newsletter"); |
101 | } |
102 | |
103 | $page->assign('nl_list', get_nl_slist()); |
104 | } |
105 | |
106 | function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null, $action = 'edit') { |
107 | $page->changeTpl('newsletter/edit.tpl'); |
108 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Edition'); |
109 | require_once("newsletter.inc.php"); |
110 | |
111 | $nl = new NewsLetter($nid); |
112 | |
113 | if($action == 'delete') { |
114 | $nl->delArticle($aid); |
115 | pl_redirect("admin/newsletter/edit/$nid"); |
116 | } |
117 | |
118 | if($aid == 'update') { |
119 | $nl->_title = Post::v('title'); |
120 | $nl->_title_mail= Post::v('title_mail'); |
121 | $nl->_date = Post::v('date'); |
122 | $nl->_head = Post::v('head'); |
123 | $nl->_shortname = strlen(Post::v('shortname')) ? Post::v('shortname') : null; |
124 | if (preg_match('/^[-a-z0-9]*$/i', $nl->_shortname) && !is_numeric($nl->_shortname)) { |
125 | $nl->save(); |
126 | } else { |
127 | $page->trig('Le nom de la NL n\'est pas valide'); |
128 | pl_redirect('admin/newsletter/edit/' . $nl->_id); |
129 | } |
130 | } |
131 | |
132 | if(Post::v('save')) { |
133 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), |
134 | $aid, Post::v('cid'), Post::v('pos')); |
135 | $nl->saveArticle($art); |
136 | pl_redirect("admin/newsletter/edit/$nid"); |
137 | } |
138 | |
139 | if($action == 'edit' && $aid != 'update') { |
140 | $eaid = $aid; |
141 | if(Post::has('title')) { |
142 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), |
143 | $eaid, Post::v('cid'), Post::v('pos')); |
144 | } else { |
145 | $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid); |
146 | } |
147 | $page->assign('art', $art); |
148 | } |
149 | |
150 | $page->assign_by_ref('nl',$nl); |
151 | } |
152 | |
153 | function handler_admin_nl_cat(&$page, $action = 'list', $id = null) { |
154 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Catégories'); |
155 | $page->assign('title', 'Gestion des catégories de la newsletter'); |
156 | $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid'); |
157 | $table_editor->describe('titre','intitulé',true); |
158 | $table_editor->describe('pos','position',true); |
159 | $table_editor->apply($page, $action, $id); |
160 | } |
161 | |
162 | } |
163 | |
164 | ?> |