9f7e6b324417d0c0c67b3f323af2f46395f8b050
2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class XnetModule
extends PLModule
27 'index' => $this->make_hook('index', AUTH_PUBLIC
),
28 'exit' => $this->make_hook('exit', AUTH_PUBLIC
),
30 'admin' => $this->make_hook('admin', AUTH_PASSWD
, 'admin'),
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
),
34 // Should be removed in a future release as links will have expired anyway.
35 'register/ext' => $this->make_hook('register_ext', AUTH_PUBLIC
),
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'),
39 'Xnet' => $this->make_wiki_hook(),
43 function handler_photo($page, $x = null
)
45 if (!$x ||
!($profile = Profile
::get($x))) {
49 // Retrieve the photo and its mime type.
50 $photo = $profile->getPhoto(true
, true
);
52 // Display the photo, or a default one when not available.
56 function handler_index($page)
59 $page->changeTpl('xnet/index.tpl');
62 function handler_exit($page)
64 Platal
::session()->stopSUID();
65 Platal
::session()->destroy();
66 $page->changeTpl('xnet/deconnexion.tpl');
69 function handler_admin($page)
71 $page->changeTpl('xnet/admin.tpl');
73 if (Get
::has('del')) {
74 $res = XDB
::query('SELECT id, nom, mail_domain
75 FROM groups WHERE diminutif={?}',
77 list($id, $nom, $domain) = $res->fetchOneRow();
78 $page->assign('nom', $nom);
79 if ($id && Post
::has('del')) {
80 S
::assert_xsrf_token();
82 XDB
::query('DELETE FROM group_members WHERE asso_id={?}', $id);
83 $page->trigSuccess('membres supprimés');
86 XDB
::execute('DELETE v
87 FROM email_virtual AS v
88 INNER JOIN email_virtual_domains AS d ON (v.domain = d.id)
91 XDB
::execute('DELETE FROM email_virtual_domains
92 WHERE name = {?}', $domain);
93 $page->trigSuccess('suppression des alias mails');
95 $mmlist = new MMList(S
::v('uid'), S
::v('password'), $domain);
96 if ($listes = $mmlist->get_lists()) {
97 foreach ($listes as $l) {
98 $mmlist->delete_list($l['list'], true
);
100 $page->trigSuccess('mail lists surpprimées');
104 XDB
::query('DELETE FROM groups WHERE id={?}', $id);
105 $page->trigSuccess("Groupe $nom supprimé");
113 if (Post
::has('diminutif') && Post
::v('diminutif') != "") {
114 S
::assert_xsrf_token();
116 $res = XDB
::query('SELECT COUNT(*)
118 WHERE diminutif = {?}',
119 Post
::v('diminutif'));
121 if ($res->fetchOneCell() == 0) {
122 XDB
::execute('INSERT INTO groups (id, diminutif)
124 Post
::v('diminutif'));
125 pl_redirect(Post
::v('diminutif') . '/edit');
127 $page->trigError('Le diminutif demandé est déjà pris.');
131 $res = XDB
::query('SELECT nom, diminutif
134 $page->assign('assos', $res->fetchAllAssoc());
137 function handler_plan($page)
139 $page->changeTpl('xnet/plan.tpl');
141 $page->setType('plan');
143 $res = XDB
::iterator(
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');
150 while ($tmp = $res->next()) { $groupesx[$tmp['id']][] = $tmp; }
151 $page->assign('groupesx', $groupesx);
153 $res = XDB
::iterator(
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');
160 while ($tmp = $res->next()) { $binets[$tmp['id']][] = $tmp; }
161 $page->assign('binets', $binets);
163 $res = XDB
::iterator(
164 'SELECT diminutif, nom
166 WHERE cat LIKE "%Promotions%"
167 ORDER BY diminutif');
168 $page->assign('promos', $res);
170 $res = XDB
::iterator(
171 'SELECT diminutif, nom
173 WHERE FIND_IN_SET("Institutions", cat)
174 ORDER BY diminutif');
175 $page->assign('inst', $res);
178 function handler_groups2($page)
180 $this->handler_groups($page, Get
::v('cat'), Get
::v('dom'));
183 function handler_groups($page, $cat = null
, $dom = null
)
186 $this->handler_index($page);
189 $cat = mb_strtolower($cat);
191 $page->changeTpl('xnet/groupes.tpl');
192 $page->assign('cat', $cat);
193 $page->assign('dom', $dom);
195 $res = XDB
::query("SELECT id,nom
197 WHERE FIND_IN_SET({?}, cat)
198 ORDER BY nom", $cat);
199 $doms = $res->fetchAllAssoc();
200 $page->assign('doms', $doms);
203 $res = XDB
::query("SELECT diminutif, nom, site
205 WHERE FIND_IN_SET({?}, cat)
206 ORDER BY nom", $cat);
207 $page->assign('gps', $res->fetchAllAssoc());
208 } elseif (!is_null($dom)) {
209 $res = XDB
::query("SELECT diminutif, nom, site
211 WHERE FIND_IN_SET({?}, cat) AND dom={?}
212 ORDER BY nom", $cat, $dom);
213 $page->assign('gps', $res->fetchAllAssoc());
216 $page->setType($cat);
219 function handler_autologin($page)
221 $allkeys = func_get_args();
223 $url = join('/',$allkeys);
224 pl_content_headers("text/javascript");
225 echo '$.ajax({ url: "'.$url.'?forceXml=1", dataType: "xml", success: function(xml) { $("body",xml).insertBefore("body"); $("body:eq(1)").remove(); }});';
229 function handler_edit($page)
237 if ($user->type
!= 'xnet') {
238 pl_redirect('index');
241 $page->changeTpl('xnet/edit.tpl');
242 if (Post
::has('change')) {
243 S
::assert_xsrf_token();
245 // Convert user status to X
246 if (!Post
::blank('login_X')) {
247 $forlife = $this->changeLogin($page, $user, Post
::t('login_X'));
249 pl_redirect('index');
254 $full_name = Post
::t('firstname') . ' ' . Post
::t('lastname');
255 $directory_name = mb_strtoupper(Post
::t('lastname')) . ' ' . Post
::t('firstname');
256 XDB
::query('UPDATE accounts
257 SET full_name = {?}, directory_name = {?}, display_name = {?},
258 firstname = {?}, lastname = {?}, sex = {?}
260 $full_name, $directory_name, Post
::t('display_name'),
261 Post
::t('firstname'), Post
::t('lastname'),
262 (Post
::t('sex') == 'male') ?
'male' : 'female', $user->id());
265 require_once 'emails.inc.php';
266 $new_email = strtolower(Post
::t('email'));
267 if (require_email_update($user, $new_email)) {
268 XDB
::query('UPDATE accounts
271 $new_email, $user->id());
272 $listClient = new MMList(S
::user());
273 $listClient->change_user_email($user->forlifeEmail(), $new_email);
274 update_alias_user($user->forlifeEmail(), $new_email);
276 $user = User
::getWithUID($user->id());
277 S
::set('user', $user);
278 $page->trigSuccess('Données mises à jour.');
281 $page->addJsLink('password.js');
282 $page->assign('user', $user);
285 function handler_register_ext($page, $hash = null
)
287 http_redirect(Platal
::globals()->xnet
->xorg_baseurl
. 'register/ext/' . $hash);
291 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: