2 /***************************************************************************
3 * Copyright (C) 2003-2008 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 ProfileSection
implements ProfileSetting
24 public function value(ProfilePage
&$page, $field, $value, &$success)
27 if (is_null($value)) {
28 $res = XDB
::query("SELECT section
32 return intval($res->fetchOneCell());
34 return intval($value);
37 public function save(ProfilePage
&$page, $field, $value)
39 XDB
::execute("UPDATE auth_user_md5
46 class ProfileGroup
implements ProfileSetting
52 public function __construct($table, $user, $group)
54 $this->table
= $table;
55 $this->user_field
= $user;
56 $this->group_field
= $group;
59 public function value(ProfilePage
&$page, $field, $value, &$success)
61 if (is_null($value)) {
63 $res = XDB
::iterRow("SELECT g.id, g.text
64 FROM {$this->table}_def AS g
65 INNER JOIN {$this->table}_ins AS i ON (i.{$this->group_field} = g.id)
66 WHERE i.{$this->user_field} = {?}",
68 while (list($gid, $text) = $res->next()) {
69 $value[intval($gid)] = $text;
72 if (!is_array($value)) {
80 public function save(ProfilePage
&$page, $field, $value)
82 XDB
::execute("DELETE FROM {$this->table}_ins
83 WHERE {$this->user_field} = {?}",
89 foreach ($value as $id=>$text) {
90 $insert[] = '(' . S
::i('uid') . ", $id)";
92 XDB
::execute("INSERT INTO {$this->table}_ins ({$this->user_field}, {$this->group_field})
93 VALUES " . implode(',', $insert));
97 class ProfileGroups
extends ProfilePage
99 protected $pg_template = 'profile/groups.tpl';
101 public function __construct(PlWizard
&$wiz)
103 parent
::__construct($wiz);
104 $this->settings
['section'] = new ProfileSection();
105 $this->settings
['binets'] = new ProfileGroup('binets', 'user_id', 'binet_id');
106 $this->watched
['section'] = $this->watched
['binets'] = true
;
109 public function _prepare(PlPage
&$page, $id)
111 $page->assign('mygroups', XDB
::iterator("SELECT a.nom, a.site, a.diminutif, a.unsub_url, a.pub, m.perms
112 FROM groupex.asso AS a
113 INNER JOIN groupex.membres AS m ON (m.asso_id = a.id)
114 WHERE m.uid = {?} AND (a.cat = 'GroupesX' OR a.cat = 'Institutions')",
116 $page->assign('listgroups', XDB
::iterator("SELECT a.nom, a.diminutif, a.sub_url,
117 IF (a.cat = 'Institutions', a.cat, d.nom) AS dom
118 FROM groupex.asso AS a
119 LEFT JOIN groupex.dom AS d ON (d.id = a.dom)
120 WHERE a.inscriptible != 0
121 AND (a.cat = 'GroupesX' OR a.cat = 'Institutions')
122 ORDER BY a.cat, a.dom, a.nom"));
123 $page->assign('old', (int)date('Y') >= S
::i('promo_sortie'));
127 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: