Commit | Line | Data |
---|---|---|
92412b28 FB |
1 | <?php |
2 | /*************************************************************************** | |
179afa7f | 3 | * Copyright (C) 2003-2008 Polytechnique.org * |
92412b28 FB |
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 | ||
57b73804 | 22 | class ProfileSection implements ProfileSetting |
92412b28 | 23 | { |
57b73804 FB |
24 | public function value(ProfilePage &$page, $field, $value, &$success) |
25 | { | |
26 | $success = true; | |
27 | if (is_null($value)) { | |
28 | $res = XDB::query("SELECT section | |
29 | FROM auth_user_md5 | |
30 | WHERE user_id = {?}", | |
31 | S::i('uid')); | |
32 | return intval($res->fetchOneCell()); | |
33 | } | |
34 | return intval($value); | |
35 | } | |
92412b28 | 36 | |
57b73804 | 37 | public function save(ProfilePage &$page, $field, $value) |
92412b28 | 38 | { |
57b73804 FB |
39 | XDB::execute("UPDATE auth_user_md5 |
40 | SET section = {?} | |
41 | WHERE user_id = {?}", | |
42 | $value, S::i('uid')); | |
43 | } | |
44 | } | |
45 | ||
46 | class ProfileGroup implements ProfileSetting | |
47 | { | |
48 | private $table; | |
49 | private $user_field; | |
50 | private $group_field; | |
51 | ||
52 | public function __construct($table, $user, $group) | |
53 | { | |
54 | $this->table = $table; | |
55 | $this->user_field = $user; | |
56 | $this->group_field = $group; | |
92412b28 FB |
57 | } |
58 | ||
57b73804 | 59 | public function value(ProfilePage &$page, $field, $value, &$success) |
92412b28 | 60 | { |
57b73804 FB |
61 | if (is_null($value)) { |
62 | $value = array(); | |
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} = {?}", | |
67 | S::i('uid')); | |
68 | while (list($gid, $text) = $res->next()) { | |
69 | $value[intval($gid)] = $text; | |
70 | } | |
71 | } | |
72 | if (!is_array($value)) { | |
73 | $value = array(); | |
74 | } | |
75 | ksort($value); | |
76 | $success = true; | |
77 | return $value; | |
92412b28 FB |
78 | } |
79 | ||
57b73804 FB |
80 | public function save(ProfilePage &$page, $field, $value) |
81 | { | |
82 | XDB::execute("DELETE FROM {$this->table}_ins | |
83 | WHERE {$this->user_field} = {?}", | |
84 | S::i('uid')); | |
85 | if (!count($value)) { | |
86 | return; | |
87 | } | |
88 | $insert = array(); | |
89 | foreach ($value as $id=>$text) { | |
90 | $insert[] = '(' . S::i('uid') . ", $id)"; | |
91 | } | |
92 | XDB::execute("INSERT INTO {$this->table}_ins ({$this->user_field}, {$this->group_field}) | |
93 | VALUES " . implode(',', $insert)); | |
94 | } | |
95 | } | |
96 | ||
97 | class ProfileGroups extends ProfilePage | |
98 | { | |
99 | protected $pg_template = 'profile/groups.tpl'; | |
100 | ||
101 | public function __construct(PlWizard &$wiz) | |
92412b28 | 102 | { |
57b73804 FB |
103 | parent::__construct($wiz); |
104 | $this->settings['section'] = new ProfileSection(); | |
105 | $this->settings['binets'] = new ProfileGroup('binets', 'user_id', 'binet_id'); | |
a2a1c2f2 | 106 | $this->watched['section'] = $this->watched['binets'] = true; |
b37aacd9 FB |
107 | } |
108 | ||
04334c61 | 109 | public function _prepare(PlPage &$page, $id) |
b37aacd9 | 110 | { |
b37aacd9 FB |
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')", | |
115 | S::i('uid'))); | |
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")); | |
46ae38a9 | 123 | $page->assign('old', (int)date('Y') >= S::i('promo_sortie')); |
92412b28 FB |
124 | } |
125 | } | |
126 | ||
127 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
128 | ?> |