1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
22 class pluglist {
23 var $index= 0;
24 var $menu= "";
25 var $iconmenu= "";
26 var $menuparts= array();
27 var $config= NULL;
28 var $dirlist= array();
29 var $ui= NULL;
30 var $current= "";
31 var $info= array();
32 var $headlines = array();
34 function pluglist(&$config, &$ui)
35 {
36 $this->ui= &$ui;
37 $this->config= &$config;
39 /* Create dirlist for all plugins */
40 $this->dirlist= $this->get_plugins ($this->dirlist, $this->config->data);
42 /* Fill info part of pluglist */
43 $classes= get_declared_classes();
45 foreach ($classes as $cname){
46 $cmethods = get_class_methods($cname);
47 if (in_array_ics('plInfo',$cmethods)){
48 $this->info[$cname]= @call_user_func(array($cname, 'plInfo'));
49 }
50 }
52 /* Provide field for 'all' */
53 $this->info['all']= array();
54 $this->info['all']['plProvidedAcls']= array();
55 $this->info['all']['plDescription']= _("All objects in this category");
56 $this->info['all']['plSelfModify']= FALSE;
57 }
59 function get_plugins($list, &$config)
60 {
61 /* Error reporting, because I'm getting strange messages in PHP 4.2.x */
62 if (!isset($config['PATH']) && !isset($config['CLASS'])){
63 if (is_array($config)){
64 foreach ($config as $val){
65 $list= $this->get_plugins($list, $val);
66 }
67 }
68 } else {
69 if (isset ($config['PATH']) && is_array($config)){
70 $list[$this->index++]= $config['PATH'];
71 if (isset($config['CLASS'])){
72 $class= $config['CLASS'];
73 }
74 }
75 }
77 return ($list);
78 }
80 function check_access($aclname)
81 {
82 $acls_to_check = array();
83 if(preg_match("/,/",$aclname)){
84 $acls_to_check = split(",",$aclname);
85 }else{
86 $acls_to_check = array($aclname);
87 }
89 foreach($acls_to_check as $acl_to_check){
90 $deps = $this->ui->get_module_departments($acl_to_check);
91 foreach($deps as $dep){
92 if(preg_match("/\//",$acl_to_check)){
93 if($this->ui->get_permissions($dep,$acl_to_check) != ""){
94 return(TRUE);
95 }
96 }else{
97 if($this->ui->get_category_permissions($dep,$acl_to_check) != ""){
98 return(TRUE);
99 }
100 }
101 }
102 }
103 return (FALSE);
104 }
106 function gen_headlines()
107 {
108 $ret = array();
109 if(count($this->headlines) == 0){
110 foreach($this->config->data['MENU'] as $headline => $plugins){
111 foreach( $plugins as $id => $plug){
112 if (plugin_available($plug['CLASS'])){
113 $attrs = (get_class_vars($plug['CLASS']));
114 $ret[$id]['HEADLINE'] = $headline;
115 $ret[$id]['NAME'] = $attrs['plHeadline'];
116 }
117 }
118 }
119 $this->headlines = $ret;
120 }
121 return($this->headlines);
122 }
124 function gen_menu()
125 {
126 if ($this->menu == ""){
127 $first= TRUE;
128 $cfg= $this->config->data['MENU'];
130 /* Parse headlines */
131 foreach ($cfg as $headline => $plug){
132 if ($first){
133 $style= "";
134 $first= FALSE;
135 } else {
136 $style= "style='border-top:1px solid #AAA; margin-top:0.8em;'";
137 }
138 $menu= "<p class=\"menuheader\" $style>"._($headline)."</p>\n";
139 $entries= "";
140 $this->menuparts[_($headline)]= array();
142 /* Parse sub-plugins */
143 foreach ($plug as $info){
145 /* Read information from class variable */
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 continue;
155 }
156 $vars= get_class_vars($info['CLASS']);
157 $plHeadline= $vars['plHeadline'];
158 $plDescription= $vars['plDescription'];
161 $index= $this->get_index($info['PATH'],$info['CLASS']);
162 $image= get_template_path('images/'.$info['ICON']);
163 $href= "main.php?plug=$index&reset=1";
165 if(!$vars){
166 $plHeadline = _("Unknown");
167 $plDescription = _("Unknown");
168 $href= "main.php?reset=1";
169 }
171 if ($this->check_access($info['ACL'])){
173 $entries= $entries."<p class=\"menuitem\" ".
174 "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>";
175 if(session::get('js')){
176 $entries.= _($plHeadline)."</p>\n";
177 } else {
178 $entries.= "<a class=\"menuitem\" ".
179 "href=\"$href\">".
180 _($plHeadline)."</a></p>\n";
181 }
183 /* Generate icon entry with description */
184 $current= '<table summary=\"\" class="menuitem" onClick=\'location.href="'.$href.'"\'><tr><td style="background-color:#F0F0F0;"><a href="'.$href.'"><img alt=\"\" border=0 src="'.$image.'"></a></td><td style="width:100%; vertical-align:top; text-align:justify; padding-left:10px;">';
185 if(session::get('js')){
186 $current.= '<b>'._($plHeadline).'</b><br>'._($plDescription);
187 } else {
188 $current.= '<a href="'.$href.'"><b>'._($plHeadline).'</b></a><br><a href="'.$href.'">'._($plDescription).'</a>';
189 }
190 $current.= '</td></tr></table>';
191 $this->menuparts[_($headline)][]= $current;
192 if(!session::is_set('maxC')){
193 session::set('maxC',"RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP");
194 }
195 }
196 }
198 /* Append to menu */
199 if ($entries != ""){
200 $this->menu.= $menu.$entries;
201 }
202 }
204 }
206 /* Write menu output */
207 return ($this->menu);
208 }
210 function gen_current()
211 {
212 /* Do we have a current value? */
213 if ($this->current == ""){
214 $tmp= array_keys($this->menuparts);
215 $this->current= $tmp[0];
216 }
218 /* Fill current array */
219 $result= "<table width=\"100%\" summary=\"\">";
220 $count= 0;
221 foreach ($this->menuparts[$this->current] as $entry){
222 if ($count == 2){
223 $result.= "</tr>";
224 $count= 0;
225 }
226 if ($count == 0){
227 $result.= "<tr>";
228 }
229 $result.= "<td>$entry</td>";
230 $count++;
231 }
233 /* Add missing cell? */
234 if ($count == 1){
235 $result.= "<td> </td>";
236 }
238 $result.= "</table>";
239 return $result;
240 }
243 function show_iconmenu()
244 {
245 if ($this->iconmenu == ""){
246 $cfg= $this->config->data['MENU'];
248 if (isset($this->config->current['ICONSIZE'])){
249 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
250 $isize= "width=\"$x\" height=\"$y\"";
251 } else {
252 $isize= "";
253 }
255 /* Parse headlines */
256 foreach ($cfg as $headline => $plug){
257 $col= 1;
258 $menu= "<h1 class=\"menuheader\">".
259 _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
260 "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
261 $entries= "";
263 foreach ($plug as $info){
265 if (!plugin_available($info['CLASS'])){
266 continue;
267 }
269 /* Read information from class variable */
270 $vars= get_class_vars($info['CLASS']);
271 $plHeadline= $vars['plHeadline'];
272 $plDescription= $vars['plDescription'];
274 $index= $this->get_index($info['PATH'],$info['CLASS']);
276 $href = "main.php?plug=".$index."&reset=1";
278 /* Check if class is available. If the class doesn't exists display error symbol
279 to avoid that a user clicks on a non existing plugin */
280 if(!$vars){
281 $plHeadline = $plDescription = _("Unknown");
282 $info['ICON'] = "error.png";
283 $href="main.php?reset=1";
284 }
287 if ($this->check_access($info['ACL'])){
289 /* Hm this looks doubled */
290 $image= get_template_path('images/'.$info['ICON']);
291 if ($col > 5){
292 $entries= $entries."</tr><tr>";
293 $col = 1;
294 }
295 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
296 ">";
297 if(session::get('js')){
298 $entries.= "<img $isize border=0 align=middle src=\"$image".
299 "\" alt=\"*\"> ".
300 _($plHeadline);
301 } else {
302 $entries.= "<a class=\"iconmenu\" href=\"".$href."\">".
303 "<img $isize border=0 align=middle src=\"$image".
304 "\" alt=\"*\"> ".
305 _($plHeadline)."</a>";
306 }
307 $entries.= "</td>\n";
308 $col++ ;
310 }
311 }
313 /* Append to menu */
314 if ($entries != ""){
315 $this->iconmenu.= $menu.$entries;
317 /* Fill up remaining columns */
318 if ($col != 1){
319 $col--;
320 while ($col % 5){
321 $this->iconmenu= $this->iconmenu.
322 "<td style=\"width:20%\"> </td>\n";
323 $col++;
324 }
325 }
327 /* close table */
328 $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
329 }
330 }
332 }
334 /* Write menu output */
335 return ($this->iconmenu);
336 }
338 function get_path($index)
339 {
340 if(!isset($this->dirlist[$index])){
341 return ("");
342 }
343 return ("../".$this->dirlist[$index]);
344 }
346 function get_index($path,$class)
347 {
348 /* Search for plugin index (id), identify entry by path && class */
349 $data = $this->config->data['MENU'];
350 foreach($data as $section => $plugins){
351 foreach($plugins as $key => $plugin) {
352 if($plugin['CLASS'] == $class && $plugin['PATH'] == $path){
353 return($key);
354 }
355 }
356 }
358 /* Indentify by path*/
359 return (array_search($path, $this->dirlist));
361 }
362 }
363 ?>