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 $deps= $this->ui->get_module_departments($aclname);
84 $acls_to_check = array();
85 if(preg_match("/,/",$aclname)){
86 $acls_to_check = split(",",$aclname);
87 }else{
88 $acls_to_check = array($aclname);
89 }
91 if(preg_match("/\//",$aclname)){
92 foreach($deps as $dep){
93 foreach($acls_to_check as $acl_to_check){
94 if($this->ui->get_permissions($dep,$acl_to_check) != ""){
95 return(TRUE);
96 }
97 }
98 }
99 }else{
100 foreach($deps as $dep){
101 foreach($acls_to_check as $acl_to_check){
102 if($this->ui->get_category_permissions($dep,$acl_to_check) != ""){
103 return(TRUE);
104 }
105 }
106 }
107 }
108 return (FALSE);
109 }
111 function gen_headlines()
112 {
113 $ret = array();
114 if(count($this->headlines) == 0){
115 foreach($this->config->data['MENU'] as $headline => $plugins){
116 foreach( $plugins as $id => $plug){
117 $attrs = (get_class_vars($plug['CLASS']));
118 $ret[$id]['HEADLINE'] = $headline;
119 $ret[$id]['NAME'] = $attrs['plHeadline'];
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 print_red(_("Your gosa.conf format has changed. Please re-run setup!"));
151 display_error_page();
152 }
153 $vars= get_class_vars($info['CLASS']);
154 $plHeadline= $vars['plHeadline'];
155 $plDescription= $vars['plDescription'];
158 $index= $this->get_index($info['PATH'],$info['CLASS']);
159 $image= get_template_path('images/'.$info['ICON']);
160 $href= "main.php?plug=$index&reset=1";
162 if(!$vars){
163 $plHeadline = _("Unknown");
164 $plDescription = _("Unknown");
165 $href= "main.php?reset=1";
166 }
168 if ($this->check_access($info['ACL'])){
170 $entries= $entries."<p class=\"menuitem\" ".
171 "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>";
172 if($_SESSION['js']){
173 $entries.= _($plHeadline)."</p>\n";
174 } else {
175 $entries.= "<a class=\"menuitem\" ".
176 "href=\"$href\">".
177 _($plHeadline)."</a></p>\n";
178 }
180 /* Generate icon entry with description */
181 $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;">';
182 if($_SESSION['js']){
183 $current.= '<b>'._($plHeadline).'</b><br>'._($plDescription);
184 } else {
185 $current.= '<a href="'.$href.'"><b>'._($plHeadline).'</b></a><br><a href="'.$href.'">'._($plDescription).'</a>';
186 }
187 $current.= '</td></tr></table>';
188 $this->menuparts[_($headline)][]= $current;
189 if(!isset($_SESSION['maxC'])){
190 $_SESSION['maxC'] = "RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP";
191 }
192 }
193 }
195 /* Append to menu */
196 if ($entries != ""){
197 $this->menu.= $menu.$entries;
198 }
199 }
201 }
203 /* Write menu output */
204 return ($this->menu);
205 }
207 function gen_current()
208 {
209 /* Do we have a current value? */
210 if ($this->current == ""){
211 $tmp= array_keys($this->menuparts);
212 $this->current= $tmp[0];
213 }
215 /* Fill current array */
216 $result= "<table width=\"100%\" summary=\"\">";
217 $count= 0;
218 foreach ($this->menuparts[$this->current] as $entry){
219 if ($count == 2){
220 $result.= "</tr>";
221 $count= 0;
222 }
223 if ($count == 0){
224 $result.= "<tr>";
225 }
226 $result.= "<td>$entry</td>";
227 $count++;
228 }
230 /* Add missing cell? */
231 if ($count == 1){
232 $result.= "<td> </td>";
233 }
235 $result.= "</table>";
236 return $result;
237 }
240 function show_iconmenu()
241 {
242 if ($this->iconmenu == ""){
243 $cfg= $this->config->data['MENU'];
245 if (isset($this->config->current['ICONSIZE'])){
246 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
247 $isize= "width=\"$x\" height=\"$y\"";
248 } else {
249 $isize= "";
250 }
252 /* Parse headlines */
253 foreach ($cfg as $headline => $plug){
254 $col= 1;
255 $menu= "<h1 class=\"menuheader\">".
256 _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
257 "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
258 $entries= "";
260 foreach ($plug as $info){
262 /* Read information from class variable */
263 $vars= get_class_vars($info['CLASS']);
264 $plHeadline= $vars['plHeadline'];
265 $plDescription= $vars['plDescription'];
267 $index= $this->get_index($info['PATH'],$info['CLASS']);
269 $href = "main.php?plug=".$index."&reset=1";
271 /* Check if class is available. If the class doesn't exists display error symbol
272 to avoid that a user clicks on a non existing plugin */
273 if(!$vars){
274 $plHeadline = $plDescription = _("Unknown");
275 $info['ICON'] = "error.png";
276 $href="main.php?reset=1";
277 }
280 if ($this->check_access($info['ACL'])){
282 /* Hm this looks doubled */
283 $image= get_template_path('images/'.$info['ICON']);
284 if ($col > 5){
285 $entries= $entries."</tr><tr>";
286 $col = 1;
287 }
288 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
289 ">";
290 if($_SESSION['js']){
291 $entries.= "<img $isize border=0 align=middle src=\"$image".
292 "\" alt=\"*\"> ".
293 _($plHeadline);
294 } else {
295 $entries.= "<a class=\"iconmenu\" href=\"".$href."\">".
296 "<img $isize border=0 align=middle src=\"$image".
297 "\" alt=\"*\"> ".
298 _($plHeadline)."</a>";
299 }
300 $entries.= "</td>\n";
301 $col++ ;
303 }
304 }
306 /* Append to menu */
307 if ($entries != ""){
308 $this->iconmenu.= $menu.$entries;
310 /* Fill up remaining columns */
311 if ($col != 1){
312 $col--;
313 while ($col % 5){
314 $this->iconmenu= $this->iconmenu.
315 "<td style=\"width:20%\"> </td>\n";
316 $col++;
317 }
318 }
320 /* close table */
321 $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
322 }
323 }
325 }
327 /* Write menu output */
328 return ($this->iconmenu);
329 }
331 function get_path($index)
332 {
333 if(!isset($this->dirlist[$index])){
334 return ("");
335 }
336 return ("../".$this->dirlist[$index]);
337 }
339 function get_index($path,$class)
340 {
341 /* Search for plugin index (id), identify entry by path && class */
342 $data = $this->config->data['MENU'];
343 foreach($data as $section => $plugins){
344 foreach($plugins as $key => $plugin) {
345 if($plugin['CLASS'] == $class && $plugin['PATH'] == $path){
346 return($key);
347 }
348 }
349 }
351 /* Indentify by path*/
352 return (array_search($path, $this->dirlist));
354 }
355 }
356 ?>