b0ce5a2cb548a372e1085a617171a6a29e776e32
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class pluglist
24 {
25 var $index= 0;
26 var $config= NULL;
27 var $dirlist= array();
28 var $ui= NULL;
29 var $info= array();
30 var $headlines = array();
31 var $silly_cache= array();
33 var $pluginList = array();
35 var $pathMenu = "";
36 var $menu= "";
37 var $iconmenu= "";
39 function pluglist(&$config, &$ui)
40 {
41 $this->ui= &$ui;
42 $this->config= &$config;
43 $this->loadPluginList();
44 }
46 function loadPluginList()
47 {
48 $this->pluginList = array();
50 // First load Menu Plugins
51 if(isset($this->config->data['MENU'])){
52 foreach($this->config->data['MENU'] as $section => $plugins){
53 foreach($plugins as $id => $plug){
54 if(!$this->registerPlugin($plug)){
55 unset($this->config->data['MENU'][$section][$id]);
56 }
57 }
58 }
59 }
61 // Now register pathMenu plugins
62 if(isset($this->config->data['PATHMENU'])){
63 foreach($this->config->data['PATHMENU'] as $id => $plugin){
64 if(!$this->registerPlugin($plugin)){
65 unset($this->config->data['PATHMENU'][$id]);
66 }
67 }
68 }
70 if(!session::is_set('maxC')){
71 session::set('maxC',"RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP");
72 }
73 $this->gen_menu();
74 $this->show_iconmenu();
75 $this->genPathMenu();
76 }
79 function registerPlugin($plug)
80 {
81 global $class_mapping;
83 if (!isset($plug['CLASS'])){
84 msg_dialog::display(
85 _("Configuration error"),
86 _("The configuration format has changed. Please re-run setup!"),
87 FATAL_ERROR_DIALOG);
88 exit();
89 }
90 if (!plugin_available($plug['CLASS'])){
91 return(FALSE);
92 }
93 if (!$this->check_access($plug['ACL'])){
94 return(FALSE);
95 }
96 $this->dirlist[$this->index] = dirname($class_mapping[$plug['CLASS']]);
97 $this->pluginList[$this->index] = $plug['CLASS'];
98 $this->index++;
99 return(TRUE);
100 }
103 /*! \brief Check whether we are allowed to modify the given acl or not..
104 * This function is used to check which plugins are visible.
105 *
106 * @param The acl tag to check for, eg. "users/user:self", "systems", ...
107 * @return Boolean TRUE on success else FALSE
108 */
109 function check_access($aclname)
110 {
111 if (isset($this->silly_cache[$aclname])) {
112 return $this->silly_cache[$aclname];
113 }
115 // Split given acl string into an array. e.g. "user,systems" => array("users","systems");
116 $acls_to_check = array();
117 if(preg_match("/,/",$aclname)){
118 $acls_to_check = explode(",",$aclname);
119 }else{
120 $acls_to_check = array($aclname);
121 }
123 foreach($acls_to_check as $acl_to_check){
124 $acl_to_check = trim($acl_to_check);
126 /* Check if the given acl tag is only valid for self acl entries
127 * <plugin acl="users/user:self" class="user"...
128 */
129 if(preg_match("/:self$/",$acl_to_check)){
130 $acl_to_check = preg_replace("/:self$/","",$acl_to_check);
131 if($this->ui->get_permissions($this->ui->dn,$acl_to_check,"") != ""){
132 $this->silly_cache[$aclname]= TRUE;
133 return(TRUE);
134 }
135 $this->silly_cache[$aclname]= FALSE;
136 return(FALSE);
137 }else{
139 // No self acls. Check if we have any acls for the given ACL type
140 $deps = $this->ui->get_module_departments($acl_to_check,TRUE);
141 if(count($deps)){
142 $this->silly_cache[$aclname]= TRUE;
143 return TRUE;
144 }
145 }
146 }
148 $this->silly_cache[$aclname]= FALSE;
149 return (FALSE);
150 }
154 /*! \brief Generate the GOsa Main-Menu here (The menu on the left),
155 * this usually only done once during login.
156 * -----------------------------------------------------------------
157 * Do NOT add style changes here manually, use the style.css or
158 * if you prefer create your own theme!!
159 * -----------------------------------------------------------------
160 */
161 function gen_menu()
162 {
163 if ($this->menu == ""){
164 $cfg= $this->config->data['MENU'];
165 $menu = "\n<div class='navigation'>";
166 foreach ($cfg as $headline => $plug){
168 if(!count($plug)) continue;
170 $menu.= "\n<div class='menu'>";
171 $menu.= "\n <ul>";
172 $menu.= "\n <li class='menu-header'>"._($headline)."</li>";
173 $id = 0;
174 foreach ($plug as $info){
176 // Used to detect the last element in the menu
177 $id ++;
179 list($index, $title, $desc, $icon) = $this->getPlugData($info['CLASS']);
180 $class= "";
181 if($id == count($plug)) $class=" class='menu-last' \n ";
182 $menu .= "\n <li id='plugMenuId_{$index}' $class onClick='return openPlugin({$index});'>".$title."</li>";
183 }
184 $menu.= "\n </ul>";
185 $menu.= "\n <div></div>\n";
186 $menu.= "\n</div>\n";
187 $menu.= "\n<div></div>\n";
188 $menu.= "\n<div class='v-spacer'></div>\n";
189 }
190 $menu.= "\n</div>";
191 $this->menu = $menu;
193 // Add javascript method to print out warning messages while leaving an unsaved form.
194 // We do it in here to get the string translated.
195 $this->menu .= "
196 <script language='javascript' type='text/javascript'>
197 function openPlugin(id){
198 return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\",
199 \"main.php?plug=\" + id + \"&reset=1\");
200 }
201 </script>
202 ";
203 }
205 // Use javascript to mark the currently selected plugin.
206 $menu = $this->menu;
207 if(isset($_GET['plug'])){
208 $menu.= "
209 <script language='javascript' type='text/javascript'>
210 if($('plugMenuId_".$_GET['plug']."')){
211 $('plugMenuId_".$_GET['plug']."').className= 'current'
212 }
213 </script>
214 ";
215 }
217 // Return the generated/cached gosa menu.
218 return ($menu);
219 }
222 /*! \brief Generate the GOsa Icon-Menu here, this usually only done once during
223 * login.
224 * -----------------------------------------------------------------
225 * Do NOT add style changes here manually, use the style.css or
226 * if you prefer create your own theme!!
227 * -----------------------------------------------------------------
228 */
229 function show_iconmenu()
230 {
231 $add_hr =FALSE;
232 if ($this->iconmenu == ""){
233 $cfg= $this->config->data['MENU'];
234 foreach ($cfg as $headline => $plug){
235 $col= 0;
237 $this->iconmenu .= "\n <div class='clear'></div>\n";
238 if($add_hr){
239 $add_hr = FALSE;
240 $this->iconmenu .= "\n <hr>\n";
241 }
242 $this->iconmenu .= "\n <h3 class='icon-menu-title'>". _($headline)."</h3>\n";
244 foreach ($plug as $info){
246 // Get Plugin info
247 list($index, $title, $desc, $icon) = $this->getPlugData($info['CLASS']);
249 // Add a seperating row
250 if (($col % 4) == 0){
251 $this->iconmenu .= "\n <div class='clear'></div>\n";
252 }
255 $this->iconmenu.= "\n <div class='icon-menu-item' style='width: 25%;' onclick='openPlugin({$index})'>";
256 $this->iconmenu.= "\n ".image($icon);
257 $this->iconmenu.= "\n <div class='dsc'>";
258 $this->iconmenu.= "\n <h1>{$title}</h1>";
259 $this->iconmenu.= "\n <p>{$desc}</p>";
260 $this->iconmenu.= "\n </div>";
261 $this->iconmenu.= "\n </div>";
263 $col++ ;
264 }
265 $add_hr = TRUE;
266 }
267 }
268 return ($this->iconmenu);
269 }
272 function genPathMenu()
273 {
274 if(empty($this->pathMenu)){
275 $this->pathMenu =
276 "\n <div class='plugin-path'>".
277 "\n <ul class='path-navigation'>".
278 "\n <li class='left right-border' onClick=\"openPlugin('');\">".
279 "\n <div class='nav-home'></div>".
280 "\n </li>".
281 "\n <li class='left'>Welcome to GOsa</li>";
283 if(isset($this->config->data['PATHMENU'])){
284 $cfg= &$this->config->data['PATHMENU'];
285 $rcfg = array_reverse($cfg);
286 foreach($rcfg as $id => $plug){
287 list($index, $title, $desc, $icon) = $this->getPlugData($plug['CLASS']);
288 $this->pathMenu.= "\n <li class='right left-border' onClick='openPlugin({$index})'>{$title}</li>";
289 }
290 }
291 $this->pathMenu.= "\n </ul>";
292 $this->pathMenu.= "\n </div>";
293 }
294 return($this->pathMenu);
295 }
298 function getPlugData($class)
299 {
300 global $class_mapping;
301 $vars= get_class_vars($class);
302 $plHeadline= _($vars['plHeadline']);
303 $plDescription= _($vars['plDescription']);
304 $plIcon = (isset($vars['plIcon'])) ? $vars['plIcon']: "plugin.png";
305 $index= $this->get_index($class);
307 /* Check if class is available. If the class doesn't exists display error symbol
308 * to avoid that a user clicks on a non existing plugin
309 */
310 if(!$vars){
311 $plHeadline = $plDescription = _("Unknown");
312 $plIcon = "error.png";
313 $index = '';
314 }
316 // Detect the correct position of the plugin icon
317 if(!preg_match("/\//",$plIcon)){
318 $image= get_template_path("plugins/".preg_replace('%^.*/([^/]+)/[^/]+$%', '\1',
319 $class_mapping[$class])."/images/$plIcon");
320 }else{
321 $image = $plIcon;
322 }
323 return(array($index, $plHeadline, $plDescription, $image));
324 }
327 /*! \brief Returns the installation path of a plugin.
328 * e.g. '../plugins/admin/mimetypes'
329 */
330 function get_path($index)
331 {
332 if(!isset($this->dirlist[$index])){
333 return ("");
334 }
335 return ("../".$this->dirlist[$index]);
336 }
339 /*! \brief Returns the plugins id for a given class.
340 */
341 function get_index($class)
342 {
343 return (array_search($class, $this->pluginList));
344 }
347 /*! \brief This function checks if we are allowed to view the plugin with the given id
348 *
349 * @param $plug_id Integer The ID of the plugin.
350 * @return Boolean TRUE if we are allowed to view the plugin else FASLE
351 */
352 function plugin_access_allowed($plug_id)
353 {
354 return(isset($this->pluginList[$plug_id]));
355 }
358 /*! \brief Force the menu to be recreated
359 */
360 function reset_menus()
361 {
362 $this->menu = "";
363 $this->iconmenu ="";
364 }
367 /*! \brief Generates an array containing plugin names (headlines) and theirs ids.
368 * This is just used in the helpviewer.php
369 */
370 function gen_headlines()
371 {
372 $ret = array();
373 if(count($this->headlines) == 0){
374 foreach($this->config->data['MENU'] as $headline => $plugins){
375 foreach( $plugins as $id => $plug){
376 if (plugin_available($plug['CLASS'])){
377 $attrs = (get_class_vars($plug['CLASS']));
378 $ret[$id]['HEADLINE'] = $headline;
379 $ret[$id]['NAME'] = $attrs['plHeadline'];
380 }
381 }
382 }
383 $this->headlines = $ret;
384 }
385 return($this->headlines);
386 }
387 }
388 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
389 ?>