09c6808bbf532c755c2a6fcd2a658dffd9cb9e78
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 $add_hr =FALSE;
244 if ($this->iconmenu == ""){
245 $cfg= $this->config->data['MENU'];
246 foreach ($cfg as $headline => $plug){
247 $col= 0;
249 $this->iconmenu .= "\n <div class='clear'></div>\n";
250 if($add_hr){
251 $add_hr = FALSE;
252 $this->iconmenu .= "\n <hr>\n";
253 }
254 $this->iconmenu .= "\n <h3 class='icon-menu-title'>". _($headline)."</h3>\n";
256 foreach ($plug as $info){
258 // Get Plugin info
259 $vars= get_class_vars($info['CLASS']);
260 $plHeadline= _($vars['plHeadline']);
261 $plDescription= _($vars['plDescription']);
262 $plIcon = (isset($vars['plIcon'])) ? $vars['plIcon']: "plugin.png";
263 $index= $this->get_index($info['CLASS']);
265 /* Check if class is available. If the class doesn't exists display error symbol
266 * to avoid that a user clicks on a non existing plugin
267 */
268 if(!$vars){
269 $plHeadline = $plDescription = _("Unknown");
270 $info['ICON'] = "error.png";
271 $index = '';
272 }
274 // Detect the correct position of the plugin icon
275 if(!preg_match("/\//",$plIcon)){
276 $image= get_template_path("plugins/".preg_replace('%^.*/([^/]+)/[^/]+$%', '\1',
277 $class_mapping[$info['CLASS']])."/images/$plIcon");
278 }else{
279 $image = $plIcon;
280 }
282 // Add a seperating row
283 if (($col % 4) == 0){
284 $this->iconmenu .= "\n <div class='clear'></div>\n";
285 }
287 $this->iconmenu.= "\n <div class='container-element' style='width: 25%;' onclick='openPlugin({$index})'> ";
288 $this->iconmenu.= "\n <div class='icon-menu-item' style='background-image: url({$image});'>";
289 $this->iconmenu.= "\n <h1>{$plHeadline}</h1>";
290 $this->iconmenu.= "\n <p>{$plDescription}</p>";
291 $this->iconmenu.= "\n </div>";
292 $this->iconmenu.= "\n </div>\n";
293 $col++ ;
294 }
295 $add_hr = TRUE;
296 }
297 }
298 return ($this->iconmenu);
299 }
302 /*! \brief Returns the installation path of a plugin.
303 * e.g. '../plugins/admin/mimetypes'
304 */
305 function get_path($index)
306 {
307 if(!isset($this->dirlist[$index])){
308 return ("");
309 }
310 return ("../".$this->dirlist[$index]);
311 }
314 /*! \brief Returns the plugins id for a given class.
315 */
316 function get_index($class)
317 {
318 /* Search for plugin index (id), identify entry by path && class */
319 $data = $this->config->data['MENU'];
320 foreach($data as $section => $plugins){
321 foreach($plugins as $key => $plugin) {
322 if($plugin['CLASS'] == $class){
323 return($key);
324 }
325 }
326 }
327 return (0);
328 }
331 /*! \brief This function checks if we are allowed to view the plugin with the given id
332 *
333 * @param $plug_id Integer The ID of the plugin.
334 * @return Boolean TRUE if we are allowed to view the plugin else FASLE
335 */
336 function plugin_access_allowed($plug_id)
337 {
338 return(isset($this->allowed_plugins[$plug_id]));
339 }
342 /*! \brief Force the menu to be recreated
343 */
344 function reset_menus()
345 {
346 $this->menu = "";
347 $this->iconmenu ="";
348 }
351 /*! \brief Generates an array containing plugin names (headlines) and theirs ids.
352 * This is just used in the helpviewer.php
353 */
354 function gen_headlines()
355 {
356 $ret = array();
357 if(count($this->headlines) == 0){
358 foreach($this->config->data['MENU'] as $headline => $plugins){
359 foreach( $plugins as $id => $plug){
360 if (plugin_available($plug['CLASS'])){
361 $attrs = (get_class_vars($plug['CLASS']));
362 $ret[$id]['HEADLINE'] = $headline;
363 $ret[$id]['NAME'] = $attrs['plHeadline'];
364 }
365 }
366 }
367 $this->headlines = $ret;
368 }
369 return($this->headlines);
370 }
371 }
372 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
373 ?>