989a54338b84102f49003b34eed05313a45f527a
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 var $index= 0;
25 var $menu= "";
26 var $iconmenu= "";
27 var $menuparts= array();
28 var $config= NULL;
29 var $dirlist= array();
30 var $ui= NULL;
31 var $current= "";
32 var $info= array();
33 var $headlines = array();
34 var $allowed_plugins = array();
35 var $silly_cache= array();
37 function pluglist(&$config, &$ui)
38 {
39 $this->ui= &$ui;
40 $this->config= &$config;
42 // Get list of plugin paths, this allows us to open the plugins main.inc if available.
43 $this->dirlist= $this->get_plugins ($this->dirlist, $this->config->data['MENU']);
45 // Detect installed plugins and their configuration, to be able to restrict access later.
46 $classes= get_declared_classes();
47 foreach ($classes as $cname){
48 $cmethods = get_class_methods($cname);
49 if (in_array_ics('plInfo',$cmethods)){
50 $this->info[$cname]= call_user_func(array($cname, 'plInfo'));
51 }
52 }
54 // Reserve a special ACL will allows us to display plugins/addons whenever a user
55 // is able to login into gosa. E.g. some kind of welcome page.
56 $this->info['all']= array();
57 $this->info['all']['plProvidedAcls']= array();
58 $this->info['all']['plDescription']= _("All objects in this category");
59 $this->info['all']['plSelfModify']= FALSE;
60 }
63 /*! \brief Detect plugin installation paths, by walking through the config.
64 */
65 function get_plugins($list, &$config)
66 {
67 global $class_mapping;
68 if (!isset($config['CLASS'])){
69 if (is_array($config)){
70 foreach ($config as $val){
71 $list= $this->get_plugins($list, $val);
72 }
73 }
74 } else {
75 if (is_array($config) && isset($class_mapping[$config['CLASS']])){
76 $list[$this->index++]= dirname($class_mapping[$config['CLASS']]);
77 } else {
78 $list[$this->index++]= "";
79 }
80 }
82 return ($list);
83 }
86 /*! \brief Check whether we are allowed to modify the given acl or not..
87 * This function is used to check which plugins are visible.
88 *
89 * @param The acl tag to check for, eg. "users/user:self", "systems", ...
90 * @return Boolean TRUE on success else FALSE
91 */
92 function check_access($aclname)
93 {
94 if (isset($this->silly_cache[$aclname])) {
95 return $this->silly_cache[$aclname];
96 }
98 // Split given acl string into an array. e.g. "user,systems" => array("users","systems");
99 $acls_to_check = array();
100 if(preg_match("/,/",$aclname)){
101 $acls_to_check = explode(",",$aclname);
102 }else{
103 $acls_to_check = array($aclname);
104 }
106 foreach($acls_to_check as $acl_to_check){
107 $acl_to_check = trim($acl_to_check);
109 /* Check if the given acl tag is only valid for self acl entries
110 * <plugin acl="users/user:self" class="user"...
111 */
112 if(preg_match("/:self$/",$acl_to_check)){
113 $acl_to_check = preg_replace("/:self$/","",$acl_to_check);
114 if($this->ui->get_permissions($this->ui->dn,$acl_to_check,"") != ""){
115 $this->silly_cache[$aclname]= TRUE;
116 return(TRUE);
117 }
118 $this->silly_cache[$aclname]= FALSE;
119 return(FALSE);
120 }else{
122 // No self acls. Check if we have any acls for the given ACL type
123 $deps = $this->ui->get_module_departments($acl_to_check,TRUE);
124 if(count($deps)){
125 $this->silly_cache[$aclname]= TRUE;
126 return TRUE;
127 }
128 }
129 }
131 $this->silly_cache[$aclname]= FALSE;
132 return (FALSE);
133 }
136 /*! \brief Check the accessibility of the configured plugins.
137 * We may simply have now permissions to access some plugins
138 * but some may be broken or missing!.
139 */
140 function checkMenu()
141 {
142 $cfg= &$this->config->data['MENU'];
143 foreach ($cfg as $headline => $plug){
144 $this->menuparts[_($headline)]= array();
145 foreach ($plug as $id => $info){
146 if (!isset($info['CLASS'])){
147 msg_dialog::display(
148 _("Configuration error"),
149 _("The configuration format has changed. Please re-run setup!"),
150 FATAL_ERROR_DIALOG);
151 exit();
152 }
153 if (!plugin_available($info['CLASS'])){
154 unset($cfg[$headline][$id]);
155 continue;
156 }
157 if (!$this->check_access($info['ACL'])){
158 unset($cfg[$headline][$id]);
159 continue;
160 }
161 }
162 }
163 if(!session::is_set('maxC')){
164 session::set('maxC',"RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP");
165 }
166 }
169 /*! \brief Generate the GOsa Main-Menu here (The menu on the left),
170 * this usually only done once during login.
171 * -----------------------------------------------------------------
172 * Do NOT add style changes here manually, use the style.css or
173 * if you prefer create your own theme!!
174 * -----------------------------------------------------------------
175 */
176 function gen_menu()
177 {
178 if ($this->menu == ""){
179 $this->checkMenu();
180 $cfg= $this->config->data['MENU'];
181 $menu = "\n<div class='navigation'>";
182 foreach ($cfg as $headline => $plug){
184 if(!count($plug)) continue;
185 $menu.= "\n<div class='menu'>";
186 $menu.= "\n <ul>";
187 $menu.= "\n <li class='menu-header'>"._($headline)."</li>";
188 $id = 0;
189 foreach ($plug as $info){
190 $id ++;
191 $vars= get_class_vars($info['CLASS']);
192 $plHeadline = _((isset($info['NAME'])) ? $info['NAME'] : $vars['plHeadline']);
193 $plDescription= $vars['plDescription'];
194 $index= $this->get_index($info['CLASS']);
195 $href= "main.php?plug=$index&reset=1";
196 if(!$vars){
197 $plHeadline = _("Unknown");
198 $plDescription = _("Unknown");
199 $href= "main.php?reset=1";
200 }
201 $this->allowed_plugins[$index] = $index;
202 $class= "";
203 if($id == count($plug)) $class=" class='menu-last' \n ";
204 $menu .= "\n <li $class onClick='return openPlugin({$index});'>".$plHeadline."</li>";
205 }
206 $menu.= "\n </ul>";
207 $menu.= "\n <div></div>\n";
208 $menu.= "\n</div>\n";
209 $menu.= "\n<div></div>\n";
210 $menu.= "\n<div class='v-spacer'></div>\n";
211 }
212 $menu.= "\n</div>";
213 $this->menu = $menu;
215 // Add javascript method to print out warning messages while leaving an unsaved form.
216 // We do it in here to get the string translated.
217 $this->menu .= "
218 <script language='javascript' type='text/javascript'>
219 function openPlugin(id){
220 return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\",
221 \"main.php?plug=\" + id + \"&reset=1\");
222 }
223 </script>
224 ";
225 }
227 // Return the generated/cached gosa menu.
228 return ($this->menu);
229 }
232 /*! \brief Generate the GOsa Icon-Menu here, this usually only done once during
233 * login.
234 * -----------------------------------------------------------------
235 * Do NOT add style changes here manually, use the style.css or
236 * if you prefer create your own theme!!
237 * -----------------------------------------------------------------
238 */
239 function show_iconmenu()
240 {
241 global $class_mapping;
243 $this->iconmenu = "";
244 if ($this->iconmenu == ""){
245 $cfg= $this->config->data['MENU'];
248 foreach ($cfg as $headline => $plug){
249 $col= 1;
251 $this->iconmenu .= "\n <div class='clear'></div>\n";
252 $this->iconmenu .= "\n <h3>". _($headline)."</h3>\n";
254 foreach ($plug as $info){
257 /* Read information from class variable */
258 $vars= get_class_vars($info['CLASS']);
259 $plHeadline= $vars['plHeadline'];
260 $plDescription= $vars['plDescription'];
261 if (isset($vars['plIcon'])){
262 $plIcon= $vars['plIcon'];
263 } else {
264 $plIcon= "plugin.png";
265 }
267 $index= $this->get_index($info['CLASS']);
269 /* Check if class is available. If the class doesn't exists display error symbol
270 to avoid that a user clicks on a non existing plugin */
271 if(!$vars){
272 $plHeadline = $plDescription = _("Unknown");
273 $info['ICON'] = "error.png";
274 $href="main.php?reset=1";
275 }
278 /* Load icon */
279 if (isset($info['ICON'])){
280 $image= get_template_path('images/'.$info['ICON']);
281 } else {
282 if(!preg_match("/\//",$plIcon)){
283 $image= get_template_path("plugins/".preg_replace('%^.*/([^/]+)/[^/]+$%', '\1', $class_mapping[$info['CLASS']])."/images/$plIcon");
284 }else{
285 $image = $plIcon;
286 }
287 }
288 if (($col % 5) == 0){
289 $this->iconmenu .= "\n <div class='clear'></div>\n";
290 $col = 1;
291 }
294 $this->iconmenu.=
295 "
296 <div class='container-element' style='width: 25%;' onclick='alert('clicked')'>
297 <div class='icon-menu-item' style='background-image: url(".$image.");'>
298 <h1>".$plHeadline."</h1>
299 <p>".$plDescription."</p>
300 </div>
301 </div>
302 ";
303 $col++ ;
304 }
305 }
306 }
308 /* Write menu output */
309 return ($this->iconmenu);
310 }
313 /*! \brief Returns the installation path of a plugin.
314 * e.g. '../plugins/admin/mimetypes'
315 */
316 function get_path($index)
317 {
318 if(!isset($this->dirlist[$index])){
319 return ("");
320 }
321 return ("../".$this->dirlist[$index]);
322 }
325 /*! \brief Returns the plugins id for a given class.
326 */
327 function get_index($class)
328 {
329 /* Search for plugin index (id), identify entry by path && class */
330 $data = $this->config->data['MENU'];
331 foreach($data as $section => $plugins){
332 foreach($plugins as $key => $plugin) {
333 if($plugin['CLASS'] == $class){
334 return($key);
335 }
336 }
337 }
338 return (0);
339 }
342 /*! \brief This function checks if we are allowed to view the plugin with the given id
343 *
344 * @param $plug_id Integer The ID of the plugin.
345 * @return Boolean TRUE if we are allowed to view the plugin else FASLE
346 */
347 function plugin_access_allowed($plug_id)
348 {
349 return(isset($this->allowed_plugins[$plug_id]));
350 }
353 /*! \brief Force the menu to be recreated
354 */
355 function reset_menus()
356 {
357 $this->menu = "";
358 $this->iconmenu ="";
359 }
362 /*! \brief Generates an array containing plugin names (headlines) and theirs ids.
363 * This is just used in the helpviewer.php
364 */
365 function gen_headlines()
366 {
367 $ret = array();
368 if(count($this->headlines) == 0){
369 foreach($this->config->data['MENU'] as $headline => $plugins){
370 foreach( $plugins as $id => $plug){
371 if (plugin_available($plug['CLASS'])){
372 $attrs = (get_class_vars($plug['CLASS']));
373 $ret[$id]['HEADLINE'] = $headline;
374 $ret[$id]['NAME'] = $attrs['plHeadline'];
375 }
376 }
377 }
378 $this->headlines = $ret;
379 }
380 return($this->headlines);
381 }
382 }
383 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
384 ?>