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($modname)
81 {
82 /* This plugin is readable for everyone, return true */
83 if ($modname == 'default'){
84 return (TRUE);
85 }
87 /* Look through ACL's */
88 foreach($this->ui->subtreeACL as $arr){
89 foreach($arr as $value){
90 if ($value == ':all' || preg_match("/[,:]$modname#/", $value)){
91 if (!preg_match('/^!/', $value)){
92 return (TRUE);
93 }
94 }
95 }
96 }
98 return (FALSE);
99 }
101 function gen_headlines()
102 {
103 $ret = array();
104 if(count($this->headlines) == 0){
105 foreach($this->config->data['MENU'] as $headline => $plugins){
106 foreach( $plugins as $id => $plug){
107 $attrs = (get_class_vars($plug['CLASS']));
108 $ret[$id]['HEADLINE'] = $headline;
109 $ret[$id]['NAME'] = $attrs['plHeadline'];
110 }
111 }
112 $this->headlines = $ret;
113 }
114 return($this->headlines);
115 }
117 function gen_menu()
118 {
119 if ($this->menu == ""){
120 $first= TRUE;
121 $cfg= $this->config->data['MENU'];
123 /* Parse headlines */
124 foreach ($cfg as $headline => $plug){
125 if ($first){
126 $style= "";
127 $first= FALSE;
128 } else {
129 $style= "style='border-top:1px solid #AAA; margin-top:0.8em;'";
130 }
131 $menu= "<p class=\"menuheader\" $style>"._($headline)."</p>\n";
132 $entries= "";
133 $this->menuparts[_($headline)]= array();
135 /* Parse sub-plugins */
136 foreach ($plug as $info){
138 /* Read information from class variable */
139 if (!isset($info['CLASS'])){
140 print_red(_("Your gosa.conf information has changed partly. Please convert it using the contributed script fix_config.sh!"));
141 echo $_SESSION['errors'];
142 exit;
143 }
144 $vars= get_class_vars($info['CLASS']);
145 $plHeadline= $vars['plHeadline'];
146 $plDescription= $vars['plDescription'];
149 $index= $this->get_index($info['PATH'],$info['CLASS']);
150 $image= get_template_path('images/'.$info['ICON']);
151 $href= "main.php?plug=$index&reset=1";
153 if(!$vars){
154 $plHeadline = _("Unknown");
155 $plDescription = _("Unknown");
156 $href= "main.php?reset=1";
157 }
159 #if ($this->check_access($info['ACL'])){
161 $entries= $entries."<p class=\"menuitem\" ".
162 "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>".
163 "<a class=\"menuitem\" ".
164 "href=\"$href\">".
165 _($plHeadline)."</a></p>\n";
167 /* Generate icon entry with description */
168 $this->menuparts[_($headline)][]= '<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;"><a href="'.$href.'"><b>'._($plHeadline).'</b></a><br><a href="'.$href.'">'._($plDescription).'</a></td></tr></table>';
169 if(!isset($_SESSION['maxC'])){
170 $_SESSION['maxC'] = "RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP";
171 }
172 #}
173 }
175 /* Append to menu */
176 if ($entries != ""){
177 $this->menu.= $menu.$entries;
178 }
179 }
181 }
183 /* Write menu output */
184 return ($this->menu);
185 }
187 function gen_current()
188 {
189 /* Do we have a current value? */
190 if ($this->current == ""){
191 $tmp= array_keys($this->menuparts);
192 $this->current= $tmp[0];
193 }
195 /* Fill current array */
196 $result= "<table width=\"100%\" summary=\"\">";
197 $count= 0;
198 foreach ($this->menuparts[$this->current] as $entry){
199 if ($count == 2){
200 $result.= "</tr>";
201 $count= 0;
202 }
203 if ($count == 0){
204 $result.= "<tr>";
205 }
206 $result.= "<td>$entry</td>";
207 $count++;
208 }
210 /* Add missing cell? */
211 if ($count == 1){
212 $result.= "<td> </td>";
213 }
215 $result.= "</table>";
216 return $result;
217 }
220 function show_iconmenu()
221 {
222 if ($this->iconmenu == ""){
223 $cfg= $this->config->data['MENU'];
225 if (isset($this->config->current['ICONSIZE'])){
226 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
227 $isize= "width=\"$x\" height=\"$y\"";
228 } else {
229 $isize= "";
230 }
232 /* Parse headlines */
233 foreach ($cfg as $headline => $plug){
234 $col= 1;
235 $menu= "<h1 class=\"menuheader\">".
236 _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
237 "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
238 $entries= "";
240 foreach ($plug as $info){
242 /* Read information from class variable */
243 $vars= get_class_vars($info['CLASS']);
244 $plHeadline= $vars['plHeadline'];
245 $plDescription= $vars['plDescription'];
247 $index= $this->get_index($info['PATH'],$info['CLASS']);
249 $href = "main.php?plug=".$index."&reset=1";
251 /* Check if class is available. If the class doesn't exists display error symbol
252 to avoid that a user clicks on a non existing plugin */
253 if(!$vars){
254 $plHeadline = $plDescription = _("Unknown");
255 $info['ICON'] = "error.png";
256 $href="main.php?reset=1";
257 }
260 #if ($this->check_access($info['ACL'])){
262 /* Hm this looks doubled */
263 $image= get_template_path('images/'.$info['ICON']);
264 if ($col > 5){
265 $entries= $entries."</tr><tr>";
266 $col = 1;
267 }
268 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
269 "><a class=\"iconmenu\" href=\"".$href."\">".
270 "<img $isize border=0 align=middle src=\"$image".
271 "\" alt=\"*\"> ".
272 _($plHeadline)."</a></td>\n";
273 $col++ ;
275 #}
276 }
278 /* Append to menu */
279 if ($entries != ""){
280 $this->iconmenu.= $menu.$entries;
282 /* Fill up remaining columns */
283 if ($col != 1){
284 $col--;
285 while ($col % 5){
286 $this->iconmenu= $this->iconmenu.
287 "<td style=\"width:20%\"> </td>\n";
288 $col++;
289 }
290 }
292 /* close table */
293 $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
294 }
295 }
297 }
299 /* Write menu output */
300 return ($this->iconmenu);
301 }
303 function get_path($index)
304 {
305 if(!isset($this->dirlist[$index])){
306 return ("");
307 }
308 return ("../".$this->dirlist[$index]);
309 }
311 function get_index($path,$class)
312 {
313 /* Search for plugin index (id), identify entry by path && class */
314 $data = $this->config->data['MENU'];
315 foreach($data as $section => $plugins){
316 foreach($plugins as $key => $plugin) {
317 if($plugin['CLASS'] == $class && $plugin['PATH'] == $path){
318 return($key);
319 }
320 }
321 }
323 /* Indentify by path*/
324 return (array_search($path, $this->dirlist));
326 }
327 }
328 ?>