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();
35 function pluglist(&$config, &$ui)
36 {
37 $this->ui= &$ui;
38 $this->config= &$config;
40 /* Create dirlist for all plugins */
41 $this->dirlist= $this->get_plugins ($this->dirlist, $this->config->data['MENU']);
43 /* Fill info part of pluglist */
44 $classes= get_declared_classes();
46 foreach ($classes as $cname){
47 $cmethods = get_class_methods($cname);
48 if (in_array_ics('plInfo',$cmethods)){
49 $this->info[$cname]= @call_user_func(array($cname, 'plInfo'));
50 }
51 }
53 /* Provide field for 'all' */
54 $this->info['all']= array();
55 $this->info['all']['plProvidedAcls']= array();
56 $this->info['all']['plDescription']= _("All objects in this category");
57 $this->info['all']['plSelfModify']= FALSE;
58 }
60 function get_plugins($list, &$config)
61 {
62 global $class_mapping;
64 /* Error reporting, because I'm getting strange messages in PHP 4.2.x */
65 if (!isset($config['CLASS'])){
66 if (is_array($config)){
67 foreach ($config as $val){
68 $list= $this->get_plugins($list, $val);
69 }
70 }
71 } else {
72 if (is_array($config) && isset($class_mapping[$config['CLASS']])){
73 $list[$this->index++]= dirname($class_mapping[$config['CLASS']]);
74 } else {
75 $list[$this->index++]= "";
76 }
77 }
79 return ($list);
80 }
83 function check_access($aclname)
84 {
85 $acls_to_check = array();
86 if(preg_match("/,/",$aclname)){
87 $acls_to_check = split(",",$aclname);
88 }else{
89 $acls_to_check = array($aclname);
90 }
92 foreach($acls_to_check as $acl_to_check){
93 $deps = $this->ui->get_module_departments($acl_to_check);
94 foreach($deps as $dep){
95 if(preg_match("/\//",$acl_to_check)){
96 if($this->ui->get_permissions($dep,$acl_to_check) != ""){
97 return(TRUE);
98 }
99 }else{
100 if($this->ui->get_category_permissions($dep,$acl_to_check) != ""){
101 return(TRUE);
102 }
103 }
104 }
105 }
106 return (FALSE);
107 }
109 function gen_headlines()
110 {
111 $ret = array();
112 if(count($this->headlines) == 0){
113 foreach($this->config->data['MENU'] as $headline => $plugins){
114 foreach( $plugins as $id => $plug){
115 if (plugin_available($plug['CLASS'])){
116 $attrs = (get_class_vars($plug['CLASS']));
117 $ret[$id]['HEADLINE'] = $headline;
118 $ret[$id]['NAME'] = $attrs['plHeadline'];
119 }
120 }
121 }
122 $this->headlines = $ret;
123 }
124 return($this->headlines);
125 }
127 function gen_menu()
128 {
129 if ($this->menu == ""){
130 $first= TRUE;
131 $cfg= $this->config->data['MENU'];
133 /* Parse headlines */
134 foreach ($cfg as $headline => $plug){
135 if ($first){
136 $style= "";
137 $first= FALSE;
138 } else {
139 $style= "style='border-top:1px solid #AAA; margin-top:0.8em;'";
140 }
141 $menu= "<p class=\"menuheader\" $style>"._($headline)."</p>\n";
142 $entries= "";
143 $this->menuparts[_($headline)]= array();
145 /* Parse sub-plugins */
146 foreach ($plug as $info){
148 /* Read information from class variable */
149 if (!isset($info['CLASS'])){
150 msg_dialog::display(
151 _("Configuration error"),
152 _("The configuration format has changed. Please re-run setup!"),
153 FATAL_ERROR_DIALOG);
154 exit();
155 }
156 if (!plugin_available($info['CLASS'])){
157 continue;
158 }
159 $vars= get_class_vars($info['CLASS']);
160 $plHeadline= $vars['plHeadline'];
161 $plDescription= $vars['plDescription'];
163 $index= $this->get_index($info['CLASS']);
164 $href= "main.php?plug=$index&reset=1";
166 if(!$vars){
167 $plHeadline = _("Unknown");
168 $plDescription = _("Unknown");
169 $href= "main.php?reset=1";
170 }
172 if ($this->check_access($info['ACL'])){
174 $entries= $entries."<p class=\"menuitem\" ".
175 "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>";
176 if(session::get('js')){
177 $entries.= _($plHeadline)."</p>\n";
178 } else {
179 $entries.= "<a class=\"menuitem\" ".
180 "href=\"$href\">".
181 _($plHeadline)."</a></p>\n";
182 }
184 if(!session::is_set('maxC')){
185 session::set('maxC',"RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP");
186 }
187 }
188 }
190 /* Append to menu */
191 if ($entries != ""){
192 $this->menu.= $menu.$entries;
193 }
194 }
196 }
198 /* Write menu output */
199 return ($this->menu);
200 }
202 function gen_current()
203 {
204 /* Do we have a current value? */
205 if ($this->current == ""){
206 $tmp= array_keys($this->menuparts);
207 $this->current= $tmp[0];
208 }
210 /* Fill current array */
211 $result= "<table width=\"100%\" summary=\"\">";
212 $count= 0;
213 foreach ($this->menuparts[$this->current] as $entry){
214 if ($count == 2){
215 $result.= "</tr>";
216 $count= 0;
217 }
218 if ($count == 0){
219 $result.= "<tr>";
220 }
221 $result.= "<td>$entry</td>";
222 $count++;
223 }
225 /* Add missing cell? */
226 if ($count == 1){
227 $result.= "<td> </td>";
228 }
230 $result.= "</table>";
231 return $result;
232 }
235 function show_iconmenu()
236 {
237 global $class_mapping;
239 if ($this->iconmenu == ""){
240 $cfg= $this->config->data['MENU'];
242 if (isset($this->config->current['ICONSIZE'])){
243 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
244 $isize= "width=\"$x\" height=\"$y\"";
245 } else {
246 $isize= "";
247 }
249 /* Parse headlines */
250 foreach ($cfg as $headline => $plug){
251 $col= 1;
252 $menu= "<h1 class=\"menuheader\">".
253 _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
254 "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
255 $entries= "";
257 foreach ($plug as $info){
259 if (!plugin_available($info['CLASS'])){
260 continue;
261 }
263 /* Read information from class variable */
264 $vars= get_class_vars($info['CLASS']);
265 $plHeadline= $vars['plHeadline'];
266 $plDescription= $vars['plDescription'];
268 $index= $this->get_index($info['CLASS']);
270 $href = "main.php?plug=".$index."&reset=1";
272 /* Check if class is available. If the class doesn't exists display error symbol
273 to avoid that a user clicks on a non existing plugin */
274 if(!$vars){
275 $plHeadline = $plDescription = _("Unknown");
276 $info['ICON'] = "error.png";
277 $href="main.php?reset=1";
278 }
281 if ($this->check_access($info['ACL'])){
283 /* Load icon */
284 if (isset($info['ICON'])){
285 $image= get_template_path('images/'.$info['ICON']);
286 } else {
287 $image= get_template_path("plugins/".preg_replace('%^.*/([^/]+)/[^/]+$%', '\1', $class_mapping[$info['CLASS']])."/images/plugin.png");
288 }
289 if ($col > 5){
290 $entries= $entries."</tr><tr>";
291 $col = 1;
292 }
293 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
294 ">";
295 if(session::get('js')){
296 $entries.= "<img $isize border=0 align=middle src=\"$image".
297 "\" alt=\"*\"> ".
298 _($plHeadline);
299 } else {
300 $entries.= "<a class=\"iconmenu\" href=\"".$href."\">".
301 "<img $isize border=0 align=middle src=\"$image".
302 "\" alt=\"*\"> ".
303 _($plHeadline)."</a>";
304 }
305 $entries.= "</td>\n";
306 $col++ ;
308 }
309 }
311 /* Append to menu */
312 if ($entries != ""){
313 $this->iconmenu.= $menu.$entries;
315 /* Fill up remaining columns */
316 if ($col != 1){
317 $col--;
318 while ($col % 5){
319 $this->iconmenu= $this->iconmenu.
320 "<td style=\"width:20%\"> </td>\n";
321 $col++;
322 }
323 }
325 /* close table */
326 $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
327 }
328 }
330 }
332 /* Write menu output */
333 return ($this->iconmenu);
334 }
336 function get_path($index)
337 {
338 if(!isset($this->dirlist[$index])){
339 return ("");
340 }
341 return ("../".$this->dirlist[$index]);
342 }
344 function get_index($class)
345 {
346 /* Search for plugin index (id), identify entry by path && class */
347 $data = $this->config->data['MENU'];
348 foreach($data as $section => $plugins){
349 foreach($plugins as $key => $plugin) {
350 if($plugin['CLASS'] == $class){
351 return($key);
352 }
353 }
354 }
356 /* Nothing */
357 return (0);
359 }
360 }
361 ?>