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