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