74e0093f |
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 EventsModule extends PLModule |
23 | { |
24 | function handlers() |
25 | { |
26 | return array( |
164ca57a |
27 | 'events/submit' => $this->make_hook('submit', AUTH_MDP), |
b829e258 |
28 | |
164ca57a |
29 | 'nl' => $this->make_hook('nl', AUTH_COOKIE), |
30 | 'nl/show' => $this->make_hook('nl_show', AUTH_COOKIE), |
31 | 'nl/submit' => $this->make_hook('nl_submit', AUTH_COOKIE), |
74e0093f |
32 | ); |
33 | } |
34 | |
35 | function handler_submit(&$page) |
36 | { |
37 | global $globals; |
38 | $page->changeTpl('evenements.tpl'); |
39 | |
40 | $titre = Post::get('titre'); |
41 | $texte = Post::get('texte'); |
42 | $promo_min = Post::getInt('promo_min'); |
43 | $promo_max = Post::getInt('promo_max'); |
44 | $peremption = Post::getInt('peremption'); |
45 | $valid_mesg = Post::get('valid_mesg'); |
46 | $action = Post::get('action'); |
47 | |
48 | $page->assign('titre', $titre); |
49 | $page->assign('texte', $texte); |
50 | $page->assign('promo_min', $promo_min); |
51 | $page->assign('promo_max', $promo_max); |
52 | $page->assign('peremption', $peremption); |
53 | $page->assign('valid_mesg', $valid_mesg); |
54 | $page->assign('action', strtolower($action)); |
55 | |
56 | if ($action == 'Confirmer') { |
57 | $texte = preg_replace('/((http|ftp)+(s)?:\/\/[^<>\s]+)/i', |
58 | '<a href=\"\\0\">\\0</a>', $texte); |
59 | $texte = preg_replace('/([^,\s]+@[^,\s]+)/i', |
60 | '<a href=\"mailto:\\0\">\\0</a>', $texte); |
61 | require_once 'validations.inc.php'; |
62 | $evtreq = new EvtReq($titre, $texte, $promo_min, $promo_max, |
63 | $peremption, $valid_mesg, Session::getInt('uid')); |
64 | $evtreq->submit(); |
65 | $page->assign('ok', true); |
66 | } |
67 | |
68 | $select = ''; |
69 | for ($i = 1 ; $i < 30 ; $i++) { |
70 | $time = time() + 3600 * 24 * $i; |
71 | $p_stamp = date('Ymd', $time); |
72 | $year = date('Y', $time); |
73 | $month = date('m', $time); |
74 | $day = date('d', $time); |
75 | |
76 | $select .= "<option value=\"$p_stamp\""; |
77 | if ($p_stamp == strtr($peremption, array("-" => ""))) { |
78 | $select .= " selected='selected'"; |
79 | } |
80 | $select .= "> $day / $month / $year</option>\n"; |
81 | } |
82 | $page->assign('select',$select); |
83 | |
84 | return PL_OK; |
85 | } |
b829e258 |
86 | |
164ca57a |
87 | function handler_nl(&$page, $action = null) |
88 | { |
89 | require_once 'newsletter.inc.php'; |
90 | |
91 | $page->changeTpl('newsletter/index.tpl'); |
92 | $page->assign('xorg_title','Polytechnique.org - Lettres mensuelles'); |
93 | |
94 | switch ($action) { |
95 | case 'out': unsubscribe_nl(); break; |
96 | case 'in': subscribe_nl(); break; |
97 | default: ; |
98 | } |
99 | |
100 | $page->assign('nls', get_nl_state()); |
101 | $page->assign_by_ref('nl_list', get_nl_list()); |
102 | |
103 | return PL_OK; |
104 | } |
105 | |
106 | function handler_nl_show(&$page, $nid = 'last') |
b829e258 |
107 | { |
108 | $page->changeTpl('newsletter/show.tpl'); |
109 | |
110 | require_once 'newsletter.inc.php'; |
111 | |
112 | $nl = new NewsLetter($nid); |
113 | $page->assign_by_ref('nl', $nl); |
114 | |
115 | if (Post::has('send')) { |
116 | $nl->sendTo(Session::get('prenom'), Session::get('nom'), |
117 | Session::get('bestalias'), Session::get('femme'), |
118 | Session::get('mail_fmt') != 'text'); |
119 | } |
120 | |
121 | return PL_OK; |
122 | } |
164ca57a |
123 | |
124 | function handler_nl_submit(&$page) |
125 | { |
126 | $page->changeTpl('newsletter/submit.tpl'); |
127 | |
128 | require_once 'newsletter.inc.php'; |
129 | |
130 | if (Post::has('see')) { |
131 | $art = new NLArticle(Post::get('title'), Post::get('body'), Post::get('append')); |
132 | $page->assign('art', $art); |
133 | } elseif (Post::has('valid')) { |
134 | require_once('validations.inc.php'); |
135 | $art = new NLReq(Session::getInt('uid'), Post::get('title'), |
136 | Post::get('body'), Post::get('append')); |
137 | $art->submit(); |
138 | $page->assign('submited', true); |
139 | } |
140 | |
141 | return PL_OK; |
142 | } |
74e0093f |
143 | } |
144 | |
145 | ?> |