migrate changelog
[platal.git] / modules / banana.php
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 BananaModule extends PLModule
23 {
24 function handlers()
25 {
26 return array(
27 'banana' => $this->make_hook('banana', AUTH_COOKIE),
28 'banana/profile' => $this->make_hook('profile', AUTH_MDP),
29 );
30 }
31
32 function handler_banana(&$page)
33 {
34 $page->changeTpl('banana/index.tpl');
35 $page->addCssLink('css/banana.css');
36 $page->assign('xorg_title','Polytechnique.org - Forums & PA');
37
38 require_once 'banana.inc.php';
39
40 $res = PlatalBanana::run();
41 $page->assign_by_ref('banana', $banana);
42 $page->assign('banana_res', $res);
43
44 return PL_OK;
45 }
46
47 function handler_profile(&$page)
48 {
49 global $globals;
50
51 $page->changeTpl('banana/profile.tpl');
52
53 if (!(Post::has('action') && Post::has('banananame') && Post::has('bananasig')
54 && Post::has('bananadisplay') && Post::has('bananamail')
55 && Post::has('bananaupdate') && Post::get('action')=="OK" ))
56 {
57 $req = $globals->xdb->query("
58 SELECT nom,mail,sig,if(FIND_IN_SET('threads',flags),'1','0'),
59 IF(FIND_IN_SET('automaj',flags),'1','0')
60 FROM forums.profils
61 WHERE uid = {?}", Session::getInt('uid'));
62 if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
63 $nom = Session::get('prenom').' '.Session::get('nom');
64 $mail = Session::get('forlife').'@'.$globals->mail->domain;
65 $sig = $nom.' ('.Session::getInt('promo').')';
66 $disp = 0;
67 $maj = 0;
68 }
69 $page->assign('nom' , $nom);
70 $page->assign('mail', $mail);
71 $page->assign('sig' , $sig);
72 $page->assign('disp', $disp);
73 $page->assign('maj' , $maj);
74 } else {
75 $globals->xdb->execute(
76 'REPLACE INTO forums.profils (uid,sig,mail,nom,flags)
77 VALUES ({?},{?},{?},{?},{?})',
78 Session::getInt('uid'), Post::get('bananasig'), Post::get('bananamail'), Post::get('banananame'),
79 (Post::getBool('bananadisplay') ? 'threads,' : '') . (Post::getBool('bananaupdate') ? 'automaj' : '')
80 );
81 }
82
83 return PL_OK;
84 }
85 }
86
87 ?>