Removes the now unused make_forlife smarty function.
[platal.git] / modules / newsletter.php
CommitLineData
e2efba7d 1<?php
2/***************************************************************************
179afa7f 3 * Copyright (C) 2003-2008 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
22class 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
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')) {
39337e2d 66 $res = XDB::query("SELECT hash FROM newsletter_ins WHERE user_id = {?}", S::i('uid'));
74f583b3
VZ
67 $nl->sendTo(S::user()->login(), S::user()->bestEmail(),
68 S::v('prenom'), S::v('nom'),
69 S::v('femme'), S::v('mail_fmt') != 'texte',
39337e2d 70 $res->fetchOneCell());
e2efba7d 71 }
72 }
73
74 function handler_nl_submit(&$page)
75 {
76 $page->changeTpl('newsletter/submit.tpl');
77
78 require_once 'newsletter.inc.php';
8f201b69
FB
79 $wp = new PlWikiPage('Xorg.LettreMensuelle');
80 $wp->buildCache();
e2efba7d 81
1970c12b 82 if (Post::has('see') || (Post::has('valid') && (!trim(Post::v('title')) || !trim(Post::v('body'))))) {
83 if (!Post::has('see')) {
a7d35093 84 $page->trigError("L'article doit avoir un titre et un contenu");
1970c12b 85 }
e2efba7d 86 $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'));
87 $page->assign('art', $art);
88 } elseif (Post::has('valid')) {
89 require_once('validations.inc.php');
90 $art = new NLReq(S::v('uid'), Post::v('title'),
91 Post::v('body'), Post::v('append'));
92 $art->submit();
93 $page->assign('submited', true);
94 }
1970c12b 95 $page->addCssLink('nl.css');
e2efba7d 96 }
97
98 function handler_admin_nl(&$page, $new = false) {
99 $page->changeTpl('newsletter/admin.tpl');
46f272fe 100 $page->setTitle('Administration - Newsletter : liste');
e2efba7d 101 require_once("newsletter.inc.php");
eaf30d86 102
e2efba7d 103 if($new) {
4882f4a5 104 Newsletter::create();
105 pl_redirect("admin/newsletter");
e2efba7d 106 }
eaf30d86 107
4882f4a5 108 $page->assign('nl_list', Newsletter::listAll());
e2efba7d 109 }
eaf30d86 110
e2efba7d 111 function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null, $action = 'edit') {
112 $page->changeTpl('newsletter/edit.tpl');
3ad44e08 113 $page->addCssLink('nl.css');
46f272fe 114 $page->setTitle('Administration - Newsletter : Edition');
e2efba7d 115 require_once("newsletter.inc.php");
eaf30d86 116
e2efba7d 117 $nl = new NewsLetter($nid);
eaf30d86 118
e2efba7d 119 if($action == 'delete') {
120 $nl->delArticle($aid);
121 pl_redirect("admin/newsletter/edit/$nid");
122 }
eaf30d86 123
e2efba7d 124 if($aid == 'update') {
125 $nl->_title = Post::v('title');
126 $nl->_title_mail= Post::v('title_mail');
127 $nl->_date = Post::v('date');
128 $nl->_head = Post::v('head');
129 $nl->_shortname = strlen(Post::v('shortname')) ? Post::v('shortname') : null;
130 if (preg_match('/^[-a-z0-9]*$/i', $nl->_shortname) && !is_numeric($nl->_shortname)) {
131 $nl->save();
132 } else {
a7d35093 133 $page->trigError('Le nom de la NL n\'est pas valide');
e2efba7d 134 pl_redirect('admin/newsletter/edit/' . $nl->_id);
135 }
136 }
eaf30d86 137
e2efba7d 138 if(Post::v('save')) {
139 $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'),
140 $aid, Post::v('cid'), Post::v('pos'));
141 $nl->saveArticle($art);
142 pl_redirect("admin/newsletter/edit/$nid");
143 }
eaf30d86 144
e2efba7d 145 if($action == 'edit' && $aid != 'update') {
146 $eaid = $aid;
147 if(Post::has('title')) {
148 $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'),
149 $eaid, Post::v('cid'), Post::v('pos'));
150 } else {
151 $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid);
152 }
153 $page->assign('art', $art);
154 }
eaf30d86 155
e2efba7d 156 $page->assign_by_ref('nl',$nl);
157 }
158
159 function handler_admin_nl_cat(&$page, $action = 'list', $id = null) {
46f272fe 160 $page->setTitle('Administration - Newsletter : Catégories');
a7de4ef7 161 $page->assign('title', 'Gestion des catégories de la newsletter');
e2efba7d 162 $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid');
a7de4ef7 163 $table_editor->describe('titre','intitulé',true);
e2efba7d 164 $table_editor->describe('pos','position',true);
165 $table_editor->apply($page, $action, $id);
bc0903c7 166 }
e2efba7d 167}
168
a7de4ef7 169// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
e2efba7d 170?>