Commit | Line | Data |
---|---|---|
92412b28 FB |
1 | <?php |
2 | /*************************************************************************** | |
9f5bd98e | 3 | * Copyright (C) 2003-2010 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 | ||
12bcf04b | 22 | class ProfileSettingSection 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 | |
e5bcd851 FB |
29 | FROM profiles |
30 | WHERE pid = {?}", | |
31 | $page->pid()); | |
57b73804 FB |
32 | return intval($res->fetchOneCell()); |
33 | } | |
34 | return intval($value); | |
35 | } | |
92412b28 | 36 | |
57b73804 | 37 | public function save(ProfilePage &$page, $field, $value) |
92412b28 | 38 | { |
e5bcd851 | 39 | XDB::execute("UPDATE profiles |
57b73804 | 40 | SET section = {?} |
e5bcd851 FB |
41 | WHERE pid = {?}", |
42 | $value, $page->pid()); | |
57b73804 | 43 | } |
a0fce0c6 SJ |
44 | |
45 | public function getText($value) { | |
46 | $sectionsList = DirEnum::getOptions(DirEnum::SECTIONS); | |
47 | return $sectionsList[$value]; | |
48 | } | |
57b73804 FB |
49 | } |
50 | ||
12bcf04b | 51 | class ProfileSettingBinets implements ProfileSetting |
57b73804 | 52 | { |
bdd977d7 | 53 | public function __construct() |
57b73804 | 54 | { |
92412b28 FB |
55 | } |
56 | ||
57b73804 | 57 | public function value(ProfilePage &$page, $field, $value, &$success) |
92412b28 | 58 | { |
57b73804 FB |
59 | if (is_null($value)) { |
60 | $value = array(); | |
61 | $res = XDB::iterRow("SELECT g.id, g.text | |
bdd977d7 FB |
62 | FROM profile_binet_enum AS g |
63 | INNER JOIN profile_binets AS i ON (i.binet_id = g.id) | |
64 | WHERE i.pid = {?}", | |
e5bcd851 | 65 | $page->pid()); |
57b73804 FB |
66 | while (list($gid, $text) = $res->next()) { |
67 | $value[intval($gid)] = $text; | |
68 | } | |
69 | } | |
70 | if (!is_array($value)) { | |
71 | $value = array(); | |
72 | } | |
73 | ksort($value); | |
74 | $success = true; | |
75 | return $value; | |
92412b28 FB |
76 | } |
77 | ||
57b73804 FB |
78 | public function save(ProfilePage &$page, $field, $value) |
79 | { | |
bdd977d7 FB |
80 | XDB::execute("DELETE FROM profile_binets |
81 | WHERE pid = {?}", | |
e5bcd851 | 82 | $page->pid()); |
57b73804 FB |
83 | if (!count($value)) { |
84 | return; | |
85 | } | |
86 | $insert = array(); | |
87 | foreach ($value as $id=>$text) { | |
e5bcd851 | 88 | $insert[] = XDB::format('({?}, {?})', $page->pid(), $id); |
57b73804 | 89 | } |
bdd977d7 | 90 | XDB::execute("INSERT INTO profile_binets (pid, binet_id) |
57b73804 FB |
91 | VALUES " . implode(',', $insert)); |
92 | } | |
a0fce0c6 SJ |
93 | |
94 | public function getText($value) { | |
95 | return implode(', ', $value); | |
96 | } | |
57b73804 FB |
97 | } |
98 | ||
12bcf04b | 99 | class ProfileSettingGroups extends ProfilePage |
57b73804 FB |
100 | { |
101 | protected $pg_template = 'profile/groups.tpl'; | |
102 | ||
103 | public function __construct(PlWizard &$wiz) | |
92412b28 | 104 | { |
57b73804 | 105 | parent::__construct($wiz); |
12bcf04b RB |
106 | $this->settings['section'] = new ProfileSettingSection(); |
107 | $this->settings['binets'] = new ProfileSettingBinets(); | |
a2a1c2f2 | 108 | $this->watched['section'] = $this->watched['binets'] = true; |
b37aacd9 FB |
109 | } |
110 | ||
04334c61 | 111 | public function _prepare(PlPage &$page, $id) |
b37aacd9 | 112 | { |
b37aacd9 | 113 | $page->assign('mygroups', XDB::iterator("SELECT a.nom, a.site, a.diminutif, a.unsub_url, a.pub, m.perms |
eb41eda9 FB |
114 | FROM groups AS a |
115 | INNER JOIN group_members AS m ON (m.asso_id = a.id) | |
b37aacd9 | 116 | WHERE m.uid = {?} AND (a.cat = 'GroupesX' OR a.cat = 'Institutions')", |
e5bcd851 | 117 | $this->pid())); |
b37aacd9 FB |
118 | $page->assign('listgroups', XDB::iterator("SELECT a.nom, a.diminutif, a.sub_url, |
119 | IF (a.cat = 'Institutions', a.cat, d.nom) AS dom | |
eb41eda9 FB |
120 | FROM groups AS a |
121 | LEFT JOIN group_dom AS d ON (d.id = a.dom) | |
b37aacd9 FB |
122 | WHERE a.inscriptible != 0 |
123 | AND (a.cat = 'GroupesX' OR a.cat = 'Institutions') | |
124 | ORDER BY a.cat, a.dom, a.nom")); | |
fa5c8df7 | 125 | $page->assign('old', (int) date('Y') >= $this->profile->grad_year); |
92412b28 FB |
126 | } |
127 | } | |
128 | ||
129 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
130 | ?> |