Fix organizer display for events created by xnet accounts.
[platal.git] / modules / xnet.php
CommitLineData
bd4be95d 1<?php
2/***************************************************************************
c441aabe 3 * Copyright (C) 2003-2014 Polytechnique.org *
bd4be95d 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 XnetModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
5ae3e9a9
SJ
27 'index' => $this->make_hook('index', AUTH_PUBLIC),
28 'exit' => $this->make_hook('exit', AUTH_PUBLIC),
71fe935c 29
bfe9f4c7 30 'admin' => $this->make_hook('admin', AUTH_PASSWD, 'admin'),
5ae3e9a9
SJ
31 'groups' => $this->make_hook('groups', AUTH_PUBLIC),
32 'groupes.php' => $this->make_hook('groups2', AUTH_PUBLIC),
33 'plan' => $this->make_hook('plan', AUTH_PUBLIC),
250915b8
SJ
34 // Should be removed in a future release as links will have expired anyway.
35 'register/ext' => $this->make_hook('register_ext', AUTH_PUBLIC),
bfe9f4c7
SJ
36 'photo' => $this->make_hook('photo', AUTH_PASSWD, 'groups'),
37 'autologin' => $this->make_hook('autologin', AUTH_PASSWD, 'groups'),
38 'edit' => $this->make_hook('edit', AUTH_PASSWD, 'groups'),
5ae3e9a9 39 'Xnet' => $this->make_wiki_hook(),
bd4be95d 40 );
41 }
42
26ba053e 43 function handler_photo($page, $x = null)
deb09f59 44 {
706f830d 45 if (!$x || !($profile = Profile::get($x))) {
deb09f59 46 return PL_NOT_FOUND;
47 }
48
706f830d 49 // Retrieve the photo and its mime type.
470d14f6 50 $photo = $profile->getPhoto(true, true);
deb09f59 51
706f830d
FB
52 // Display the photo, or a default one when not available.
53 $photo->send();
deb09f59 54 }
eaf30d86 55
26ba053e 56 function handler_index($page)
bd4be95d 57 {
d83a1b04 58 $page->nomenu = true;
bd4be95d 59 $page->changeTpl('xnet/index.tpl');
bd4be95d 60 }
badfc7ee 61
26ba053e 62 function handler_exit($page)
71fe935c 63 {
ab694eb5
FB
64 Platal::session()->stopSUID();
65 Platal::session()->destroy();
b8e265bf 66 $page->changeTpl('xnet/deconnexion.tpl');
71fe935c 67 }
68
26ba053e 69 function handler_admin($page)
d55888e6 70 {
1490093c 71 $page->changeTpl('xnet/admin.tpl');
d55888e6 72
73 if (Get::has('del')) {
08cce2ff 74 $res = XDB::query('SELECT id, nom, mail_domain
eb41eda9 75 FROM groups WHERE diminutif={?}',
5e2307dc 76 Get::v('del'));
d55888e6 77 list($id, $nom, $domain) = $res->fetchOneRow();
78 $page->assign('nom', $nom);
40d428d8
VZ
79 if ($id && Post::has('del')) {
80 S::assert_xsrf_token();
81
eb41eda9 82 XDB::query('DELETE FROM group_members WHERE asso_id={?}', $id);
a7d35093 83 $page->trigSuccess('membres supprimés');
d55888e6 84
85 if ($domain) {
831aa467
SJ
86 XDB::execute('DELETE v
87 FROM email_virtual AS v
88 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
89 WHERE d.name = {?}',
90 $domain);
91 XDB::execute('DELETE FROM email_virtual_domains
92 WHERE name = {?}', $domain);
a7d35093 93 $page->trigSuccess('suppression des alias mails');
d55888e6 94
9bb8bf21 95 $mmlist = new MMList(S::v('uid'), S::v('password'), $domain);
96 if ($listes = $mmlist->get_lists()) {
d55888e6 97 foreach ($listes as $l) {
9bb8bf21 98 $mmlist->delete_list($l['list'], true);
d55888e6 99 }
a7d35093 100 $page->trigSuccess('mail lists surpprimées');
d55888e6 101 }
102 }
103
eb41eda9 104 XDB::query('DELETE FROM groups WHERE id={?}', $id);
a7d35093 105 $page->trigSuccess("Groupe $nom supprimé");
d55888e6 106 Get::kill('del');
107 }
108 if (!$id) {
109 Get::kill('del');
110 }
111 }
112
8d11b755 113 if (Post::has('diminutif') && Post::v('diminutif') != "") {
40d428d8
VZ
114 S::assert_xsrf_token();
115
3af5a31e 116 $res = XDB::query('SELECT COUNT(*)
eb41eda9 117 FROM groups
3af5a31e
SJ
118 WHERE diminutif = {?}',
119 Post::v('diminutif'));
120
121 if ($res->fetchOneCell() == 0) {
eb41eda9 122 XDB::execute('INSERT INTO groups (id, diminutif)
3af5a31e
SJ
123 VALUES (NULL, {?})',
124 Post::v('diminutif'));
fc4714d6 125 pl_redirect(Post::v('diminutif') . '/edit');
3af5a31e
SJ
126 } else {
127 $page->trigError('Le diminutif demandé est déjà pris.');
128 }
d55888e6 129 }
130
3af5a31e 131 $res = XDB::query('SELECT nom, diminutif
eb41eda9 132 FROM groups
3af5a31e 133 ORDER BY nom');
d55888e6 134 $page->assign('assos', $res->fetchAllAssoc());
135 }
136
26ba053e 137 function handler_plan($page)
71fe935c 138 {
71fe935c 139 $page->changeTpl('xnet/plan.tpl');
140
141 $page->setType('plan');
142
08cce2ff 143 $res = XDB::iterator(
e1406965
FB
144 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
145 FROM group_dom AS dom
146 INNER JOIN groups ON dom.id = groups.dom
147 WHERE FIND_IN_SET("GroupesX", dom.cat) AND FIND_IN_SET("GroupesX", groups.cat)
148 ORDER BY dom.nom, groups.nom');
71fe935c 149 $groupesx = array();
150 while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; }
151 $page->assign('groupesx', $groupesx);
152
08cce2ff 153 $res = XDB::iterator(
e1406965
FB
154 'SELECT dom.id, dom.nom as domnom, groups.diminutif, groups.nom
155 FROM group_dom AS dom
156 INNER JOIN groups ON dom.id = groups.dom
157 WHERE FIND_IN_SET("Binets", dom.cat) AND FIND_IN_SET("Binets", groups.cat)
158 ORDER BY dom.nom, groups.nom');
71fe935c 159 $binets = array();
160 while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; }
161 $page->assign('binets', $binets);
162
08cce2ff 163 $res = XDB::iterator(
e1406965 164 'SELECT diminutif, nom
eb41eda9 165 FROM groups
71fe935c 166 WHERE cat LIKE "%Promotions%"
167 ORDER BY diminutif');
168 $page->assign('promos', $res);
169
08cce2ff 170 $res = XDB::iterator(
e1406965 171 'SELECT diminutif, nom
eb41eda9 172 FROM groups
71fe935c 173 WHERE FIND_IN_SET("Institutions", cat)
174 ORDER BY diminutif');
175 $page->assign('inst', $res);
045a1522 176 }
0e02493e 177
26ba053e 178 function handler_groups2($page)
0e02493e 179 {
26ba053e 180 $this->handler_groups($page, Get::v('cat'), Get::v('dom'));
0e02493e 181 }
182
26ba053e 183 function handler_groups($page, $cat = null, $dom = null)
0e02493e 184 {
0e02493e 185 if (!$cat) {
26ba053e 186 $this->handler_index($page);
0e02493e 187 }
188
a953f7e7 189 $cat = mb_strtolower($cat);
0e02493e 190
191 $page->changeTpl('xnet/groupes.tpl');
192 $page->assign('cat', $cat);
193 $page->assign('dom', $dom);
194
aab2ffdd 195 $res = XDB::query("SELECT id,nom
eb41eda9 196 FROM group_dom
00112b2e
VZ
197 WHERE FIND_IN_SET({?}, cat)
198 ORDER BY nom", $cat);
0e02493e 199 $doms = $res->fetchAllAssoc();
200 $page->assign('doms', $doms);
201
202 if (empty($doms)) {
00112b2e 203 $res = XDB::query("SELECT diminutif, nom, site
eb41eda9 204 FROM groups
00112b2e
VZ
205 WHERE FIND_IN_SET({?}, cat)
206 ORDER BY nom", $cat);
f0430dc7 207 $page->assign('gps', $res->fetchAllAssoc());
0e02493e 208 } elseif (!is_null($dom)) {
00112b2e 209 $res = XDB::query("SELECT diminutif, nom, site
eb41eda9 210 FROM groups
00112b2e
VZ
211 WHERE FIND_IN_SET({?}, cat) AND dom={?}
212 ORDER BY nom", $cat, $dom);
f0430dc7 213 $page->assign('gps', $res->fetchAllAssoc());
0e02493e 214 }
0e02493e 215
0e02493e 216 $page->setType($cat);
217 }
eaf30d86 218
26ba053e 219 function handler_autologin($page)
4a8a1e0a 220 {
8c5c6d64 221 $allkeys = func_get_args();
222 unset($allkeys[0]);
223 $url = join('/',$allkeys);
3cb500d5 224 pl_content_headers("text/javascript");
8c5c6d64 225 echo '$.ajax({ url: "'.$url.'?forceXml=1", dataType: "xml", success: function(xml) { $("body",xml).insertBefore("body"); $("body:eq(1)").remove(); }});';
4a8a1e0a 226 exit;
227 }
f15d1307 228
2a1cd4ab 229 function handler_edit($page)
f15d1307
SJ
230 {
231 global $globals;
232
233 $user = S::user();
234 if (empty($user)) {
235 return PL_NOT_FOUND;
236 }
237 if ($user->type != 'xnet') {
238 pl_redirect('index');
239 }
240
241 $page->changeTpl('xnet/edit.tpl');
242 if (Post::has('change')) {
243 S::assert_xsrf_token();
244
245 // Convert user status to X
246 if (!Post::blank('login_X')) {
247 $forlife = $this->changeLogin($page, $user, Post::t('login_X'));
248 if ($forlife) {
249 pl_redirect('index');
250 }
251 }
252
75e295ff
SJ
253 require_once 'emails.inc.php';
254 require_once 'name.func.inc.php';
255
f15d1307 256 // Update user info
75e295ff
SJ
257 $lastname = capitalize_name(Post::t('lastname'));
258 $firstname = capitalize_name(Post::t('firstname'));
3ba2fdf6
SJ
259 $full_name = build_full_name($firstname, $lastname);
260 $directory_name = build_directory_name($firstname, $lastname);
b0788bf4 261 $sort_name = build_sort_name($firstname, $lastname);
f15d1307 262 XDB::query('UPDATE accounts
b0788bf4 263 SET full_name = {?}, directory_name = {?}, sort_name = {?}, display_name = {?},
8a41e7f9 264 firstname = {?}, lastname = {?}, sex = {?}
f15d1307 265 WHERE uid = {?}',
b0788bf4 266 $full_name, $directory_name, $sort_name, Post::t('display_name'),
b7753795 267 Post::t('firstname'), Post::t('lastname'),
8a41e7f9
SJ
268 (Post::t('sex') == 'male') ? 'male' : 'female', $user->id());
269
270 // Updates email.
8a41e7f9
SJ
271 $new_email = strtolower(Post::t('email'));
272 if (require_email_update($user, $new_email)) {
273 XDB::query('UPDATE accounts
274 SET email = {?}
275 WHERE uid = {?}',
276 $new_email, $user->id());
ca6980dc 277 $listClient = new MMList(S::user());
8a41e7f9
SJ
278 $listClient->change_user_email($user->forlifeEmail(), $new_email);
279 update_alias_user($user->forlifeEmail(), $new_email);
f15d1307 280 }
8a41e7f9
SJ
281 $user = User::getWithUID($user->id());
282 S::set('user', $user);
283 $page->trigSuccess('Données mises à jour.');
f15d1307
SJ
284 }
285
286 $page->addJsLink('password.js');
287 $page->assign('user', $user);
288 }
73f2bb48 289
250915b8
SJ
290 function handler_register_ext($page, $hash = null)
291 {
292 http_redirect(Platal::globals()->xnet->xorg_baseurl . 'register/ext/' . $hash);
293 }
bd4be95d 294}
295
448c8cdc 296// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
bd4be95d 297?>