Fix naming convention.
[platal.git] / modules / profile / groups.inc.php
CommitLineData
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
57b73804 22class 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
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
FB
43 }
44}
45
bdd977d7 46class ProfileBinets implements ProfileSetting
57b73804 47{
bdd977d7 48 public function __construct()
57b73804 49 {
92412b28
FB
50 }
51
57b73804 52 public function value(ProfilePage &$page, $field, $value, &$success)
92412b28 53 {
57b73804
FB
54 if (is_null($value)) {
55 $value = array();
56 $res = XDB::iterRow("SELECT g.id, g.text
bdd977d7
FB
57 FROM profile_binet_enum AS g
58 INNER JOIN profile_binets AS i ON (i.binet_id = g.id)
59 WHERE i.pid = {?}",
e5bcd851 60 $page->pid());
57b73804
FB
61 while (list($gid, $text) = $res->next()) {
62 $value[intval($gid)] = $text;
63 }
64 }
65 if (!is_array($value)) {
66 $value = array();
67 }
68 ksort($value);
69 $success = true;
70 return $value;
92412b28
FB
71 }
72
57b73804
FB
73 public function save(ProfilePage &$page, $field, $value)
74 {
bdd977d7
FB
75 XDB::execute("DELETE FROM profile_binets
76 WHERE pid = {?}",
e5bcd851 77 $page->pid());
57b73804
FB
78 if (!count($value)) {
79 return;
80 }
81 $insert = array();
82 foreach ($value as $id=>$text) {
e5bcd851 83 $insert[] = XDB::format('({?}, {?})', $page->pid(), $id);
57b73804 84 }
bdd977d7 85 XDB::execute("INSERT INTO profile_binets (pid, binet_id)
57b73804
FB
86 VALUES " . implode(',', $insert));
87 }
88}
89
90class ProfileGroups extends ProfilePage
91{
92 protected $pg_template = 'profile/groups.tpl';
93
94 public function __construct(PlWizard &$wiz)
92412b28 95 {
57b73804
FB
96 parent::__construct($wiz);
97 $this->settings['section'] = new ProfileSection();
bdd977d7 98 $this->settings['binets'] = new ProfileBinets();
a2a1c2f2 99 $this->watched['section'] = $this->watched['binets'] = true;
b37aacd9
FB
100 }
101
04334c61 102 public function _prepare(PlPage &$page, $id)
b37aacd9 103 {
b37aacd9 104 $page->assign('mygroups', XDB::iterator("SELECT a.nom, a.site, a.diminutif, a.unsub_url, a.pub, m.perms
eb41eda9
FB
105 FROM groups AS a
106 INNER JOIN group_members AS m ON (m.asso_id = a.id)
b37aacd9 107 WHERE m.uid = {?} AND (a.cat = 'GroupesX' OR a.cat = 'Institutions')",
e5bcd851 108 $this->pid()));
b37aacd9
FB
109 $page->assign('listgroups', XDB::iterator("SELECT a.nom, a.diminutif, a.sub_url,
110 IF (a.cat = 'Institutions', a.cat, d.nom) AS dom
eb41eda9
FB
111 FROM groups AS a
112 LEFT JOIN group_dom AS d ON (d.id = a.dom)
b37aacd9
FB
113 WHERE a.inscriptible != 0
114 AND (a.cat = 'GroupesX' OR a.cat = 'Institutions')
115 ORDER BY a.cat, a.dom, a.nom"));
e5bcd851 116 # XXX: FIXME: promo_sortie
46ae38a9 117 $page->assign('old', (int)date('Y') >= S::i('promo_sortie'));
92412b28
FB
118 }
119}
120
121// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
122?>