Merge branch 'platal-0.10.0'
[platal.git] / classes / xnetpage.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2009 Polytechnique.org *
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
22 class XnetPage extends PlPage
23 {
24 public $nomenu = false;
25
26 // {{{ function XnetPage()
27
28 public function __construct()
29 {
30 parent::__construct();
31
32 $this->register_function('list_all_my_groups', 'list_all_my_groups');
33 $this->register_modifier('cat_pp', 'cat_pp');
34 $this->assign('it_is_xnet', true);
35
36 global $globals;
37 $this->assign('is_logged', S::logged());
38 if ($globals->asso('id')) {
39 $this->assign('asso', $globals->asso());
40 $this->setType($globals->asso('cat'));
41 $this->assign('is_admin', may_update());
42 $this->assign('is_member', is_member());
43 }
44 $this->addJsLink('xorg.js');
45 $this->setTitle('Les associations polytechniciennes');
46 }
47
48 // }}}
49 // {{{ function run()
50
51 public function run()
52 {
53 if (!$this->nomenu) {
54 $this->useMenu();
55 }
56 $this->_run('xnet/skin.tpl');
57 }
58
59 // }}}
60 // {{{ function setType
61
62 public function setType($type)
63 {
64 $this->assign('xnet_type', strtolower($type));
65 }
66
67 // }}}
68 // {{{ function useMenu
69
70 private function useMenu()
71 {
72 global $globals;
73
74 $menu = array();
75
76 $sub = array();
77 $sub['tous les groupes'] = 'plan';
78 $sub['documentation'] = 'Xnet';
79 $sub['signaler un bug'] = array('href' => 'send_bug/'.$_SERVER['REQUEST_URI'], 'class' => 'popup_840x600');
80 $menu["no_title"] = $sub;
81
82 $perms = S::v('perms');
83 $dim = $globals->asso('diminutif');
84 if (S::logged() && $globals->asso()) {
85 $sub = array();
86 $sub['présentation'] = "login/$dim/";
87 if ($perms->hasFlag('groupannu')) {
88 $sub['annuaire du groupe'] = "$dim/annuaire";
89 $sub['trombinoscope'] = "$dim/trombi";
90 $sub['planisphère'] = "$dim/geoloc";
91 }
92 if ($perms->hasFlag('groupmember')) {
93 if ($globals->asso('forum')) {
94 $sub['forum'] = "$dim/forum";
95 }
96 if ($globals->asso('mail_domain')) {
97 $sub['listes de diffusion'] = "$dim/lists";
98 }
99 }
100 $sub['événement'] = "$dim/events";
101 if ($perms->hasFlag('groupmember')) {
102 $sub['télépaiement'] = "$dim/payment";
103 }
104
105 $menu[$globals->asso('nom')] = $sub;
106 }
107
108 if ($globals->asso() && is_object($perms) && $perms->hasFlag('groupadmin')) {
109 $sub = array();
110 $sub['modifier l\'accueil'] = "$dim/edit";
111 $sub['gérer les annonces'] = "$dim/admin/announces";
112 if ($globals->asso('mail_domain')) {
113 $sub['envoyer un mail'] = "$dim/mail";
114 $sub['créer une liste'] = "$dim/lists/create";
115 $sub['créer un alias'] = "$dim/alias/create";
116 }
117 if (S::has_perms()) {
118 $sub['gérer les groupes'] = array('href' => 'admin', 'style' => 'color: gray;');
119 $sub['clear cache'] = array('href' => 'purge_cache?token=' . S::v('xsrf_token'), 'style' => 'color: gray;');
120 }
121 $menu['Administrer'] = $sub;
122 } elseif (S::has_perms()) {
123 $sub = array();
124 $sub['gérer les groupes'] = 'admin';
125 $sub['clear cache'] = 'purge_cache?token=' . S::v('xsrf_token');
126 $menu['Administrer'] = $sub;
127 }
128
129 $this->assign('menu', $menu);
130 }
131
132 // }}}
133 }
134
135 // {{{ function list_all_my_groups
136
137 function list_all_my_groups($params)
138 {
139 if (!S::logged()) {
140 return;
141 }
142 $res = XDB::iterRow(
143 "SELECT a.nom, a.diminutif
144 FROM groupex.asso AS a
145 INNER JOIN groupex.membres AS m ON m.asso_id = a.id
146 WHERE m.uid={?}", S::v('uid'));
147 $links = '<a href="exit">déconnexion</a>';
148 $html = '<div>Mes groupes (' . $links . ') :</div>';
149 while (list($nom, $mini) = $res->next()) {
150 $html .= "<span class='gp'>&bull; <a href='login/$mini'>$nom</a></span>";
151 }
152 return $html;
153 }
154
155 // }}}
156 // {{{ cat_pp
157
158 function cat_pp($cat)
159 {
160 $trans = array(
161 'groupesx' => 'Groupes X' ,
162 'binets' => 'Binets' ,
163 'institutions' => 'Institutions' ,
164 'promotions' => 'Promotions'
165 );
166
167 return $trans[strtolower($cat)];
168 }
169
170 // }}}
171
172 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
173 ?>