f585e5a4 |
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( |
3d9b1d30 |
27 | 'banana' => $this->make_hook('banana', AUTH_COOKIE), |
28 | 'banana/profile' => $this->make_hook('profile', AUTH_MDP), |
a3a1d23b |
29 | 'banana/subscription' => $this->make_hook('subscription', AUTH_COOKIE), |
f107d806 |
30 | 'banana/xface' => $this->make_hook('xface', AUTH_COOKIE), |
a3a1d23b |
31 | ); |
f585e5a4 |
32 | } |
33 | |
8d8f7607 |
34 | function on_subscribe($forlife, $uid, $promo, $password) |
35 | { |
36 | $cible = array('xorg.general', 'xorg.pa.divers', 'xorg.pa.logements'); |
37 | $p_for = "xorg.promo.x$promo"; |
38 | |
39 | // récupération de l'id du forum promo |
40 | $res = XDB::query("SELECT fid FROM forums.list WHERE nom={?}", $p_for); |
41 | if ($res->numRows()) { |
42 | $cible[] = $p_for; |
43 | } else { // pas de forum promo, il faut le créer |
44 | $res = XDB::query("SELECT SUM(perms IN ('admin','user') AND deces=0),COUNT(*) |
45 | FROM auth_user_md5 WHERE promo={?}", $promo); |
46 | list($effau, $effid) = $res->fetchOneRow(); |
47 | if (5*$effau>$effid) { // + de 20% d'inscrits |
1e33266a |
48 | $mymail = new PlMailer('mails/forums.promo.tpl'); |
8d8f7607 |
49 | $mymail->assign('promo', $promo); |
50 | $mymail->send(); |
51 | } |
52 | } |
53 | |
54 | while (list ($key, $val) = each ($cible)) { |
55 | XDB::execute("INSERT INTO forums.abos (fid,uid) |
56 | SELECT fid,{?} FROM forums.list WHERE nom={?}", $uid, $val); |
57 | } |
58 | } |
59 | |
3d9b1d30 |
60 | function handler_banana(&$page, $group = null, $action = null, $artid = null) |
f585e5a4 |
61 | { |
a3a1d23b |
62 | $get = Array(); |
63 | if (!is_null($group)) { |
64 | $get['group'] = $group; |
65 | } |
7e6495d4 |
66 | if (Post::has('updateall')) { |
85b9d118 |
67 | $get['updateall'] = Post::v('updateall'); |
7e6495d4 |
68 | } |
a3a1d23b |
69 | if (!is_null($action)) { |
70 | if ($action == 'new') { |
71 | $get['action'] = 'new'; |
aafe5c09 |
72 | } elseif ($action == 'reply' && !is_null($artid)) { |
73 | $get['action'] = 'new'; |
74 | $get['artid'] = $artid; |
75 | } elseif ($action == 'cancel' && !is_null($artid)) { |
a3a1d23b |
76 | $get['action'] = $action; |
77 | $get['artid'] = $artid; |
78 | } elseif ($action == 'from' && !is_null($artid)) { |
79 | $get['first'] = $artid; |
80 | } elseif ($action == 'read' && !is_null($artid)) { |
81 | $get['artid'] = $artid; |
82 | } |
83 | } |
84 | return BananaModule::run_banana($page, $get); |
f585e5a4 |
85 | } |
86 | |
3d9b1d30 |
87 | function handler_profile(&$page, $action = null) |
f585e5a4 |
88 | { |
89 | global $globals; |
90 | |
91 | $page->changeTpl('banana/profile.tpl'); |
92 | |
93 | if (!(Post::has('action') && Post::has('banananame') && Post::has('bananasig') |
94 | && Post::has('bananadisplay') && Post::has('bananamail') |
5e2307dc |
95 | && Post::has('bananaupdate') && Post::v('action')=="OK" )) |
f585e5a4 |
96 | { |
08cce2ff |
97 | $req = XDB::query(" |
f585e5a4 |
98 | SELECT nom,mail,sig,if(FIND_IN_SET('threads',flags),'1','0'), |
99 | IF(FIND_IN_SET('automaj',flags),'1','0') |
100 | FROM forums.profils |
cab08090 |
101 | WHERE uid = {?}", S::v('uid')); |
f585e5a4 |
102 | if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) { |
cab08090 |
103 | $nom = S::v('prenom').' '.S::v('nom'); |
104 | $mail = S::v('forlife').'@'.$globals->mail->domain; |
105 | $sig = $nom.' ('.S::v('promo').')'; |
f585e5a4 |
106 | $disp = 0; |
107 | $maj = 0; |
108 | } |
109 | $page->assign('nom' , $nom); |
110 | $page->assign('mail', $mail); |
111 | $page->assign('sig' , $sig); |
112 | $page->assign('disp', $disp); |
113 | $page->assign('maj' , $maj); |
114 | } else { |
08cce2ff |
115 | XDB::execute( |
f585e5a4 |
116 | 'REPLACE INTO forums.profils (uid,sig,mail,nom,flags) |
117 | VALUES ({?},{?},{?},{?},{?})', |
5e2307dc |
118 | S::v('uid'), Post::v('bananasig'), |
119 | Post::v('bananamail'), Post::v('banananame'), |
120 | (Post::b('bananadisplay') ? 'threads,' : '') . |
121 | (Post::b('bananaupdate') ? 'automaj' : '') |
f585e5a4 |
122 | ); |
123 | } |
f585e5a4 |
124 | } |
3d9b1d30 |
125 | |
a3a1d23b |
126 | function handler_subscription(&$page) |
127 | { |
128 | return $this->run_banana($page, Array('subscribe' => 1)); |
129 | } |
3d9b1d30 |
130 | |
7e6495d4 |
131 | function handler_xface(&$page, $face = null) |
f107d806 |
132 | { |
a011eab2 |
133 | header('Content-Type: image/gif'); |
7e6495d4 |
134 | passthru('echo ' . escapeshellarg(base64_decode(strtr($face, '.:', '+/'))) |
f107d806 |
135 | . '| uncompface -X ' |
7e6495d4 |
136 | . '| convert -transparent white xbm:- gif:-'); |
f107d806 |
137 | } |
138 | |
a3a1d23b |
139 | function run_banana(&$page, $params = null) |
140 | { |
3d9b1d30 |
141 | $page->changeTpl('banana/index.tpl'); |
c99ef281 |
142 | $page->addCssLink('banana.css'); |
3d9b1d30 |
143 | $page->assign('xorg_title','Polytechnique.org - Forums & PA'); |
144 | |
57e834ac |
145 | require_once dirname(__FILE__).'/banana/banana.inc.php'; |
3d9b1d30 |
146 | |
147 | $res = PlatalBanana::run($params); |
148 | $page->assign_by_ref('banana', $banana); |
149 | $page->assign('banana_res', $res); |
a3a1d23b |
150 | } |
f585e5a4 |
151 | } |
152 | |
153 | ?> |