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();
44 foreach (get_declared_classes() as $cname){
45 if (method_exists($cname, 'plInfo')){
46 $this->info[$cname]= @call_user_func(array($cname, 'plInfo'));
47 }
48 }
50 /* Provide field for 'all' */
51 $this->info['all']= array();
52 $this->info['all']['plProvidedAcls']= array();
53 $this->info['all']['plDescription']= _("All objects in this category");
54 $this->info['all']['plSelfModify']= FALSE;
55 }
57 function get_plugins($list, $config)
58 {
59 /* Error reporting, because I'm getting strange messages in PHP 4.2.x */
60 if (!isset($config['PATH']) && !isset($config['CLASS'])){
61 if (is_array($config)){
62 foreach ($config as $val){
63 $list= $this->get_plugins($list, $val);
64 }
65 }
66 } else {
67 if (isset ($config['PATH']) && is_array($config)){
68 $list[$this->index++]= $config['PATH'];
69 if (isset($config['CLASS'])){
70 $class= $config['CLASS'];
71 }
72 }
73 }
75 return ($list);
76 }
78 function check_access($modname)
79 {
80 /* This plugin is readable for everyone, return true */
81 if ($modname == 'default'){
82 return (TRUE);
83 }
85 /* Look through ACL's */
86 foreach($this->ui->subtreeACL as $arr){
87 foreach($arr as $value){
88 if ($value == ':all' || preg_match("/[,:]$modname#/", $value)){
89 if (!preg_match('/^!/', $value)){
90 return (TRUE);
91 }
92 }
93 }
94 }
96 return (FALSE);
97 }
99 function gen_headlines()
100 {
101 $ret = array();
102 if(count($this->headlines) == 0){
103 foreach($this->config->data['MENU'] as $headline => $plugins){
104 foreach( $plugins as $id => $plug){
105 $attrs = (get_class_vars($plug['CLASS']));
106 $ret[$id]['HEADLINE'] = $headline;
107 $ret[$id]['NAME'] = $attrs['plHeadline'];
108 }
109 }
110 $this->headlines = $ret;
111 }
112 return($this->headlines);
113 }
115 function gen_menu()
116 {
117 if ($this->menu == ""){
118 $cfg= $this->config->data['MENU'];
120 /* Parse headlines */
121 foreach ($cfg as $headline => $plug){
122 $menu= "<p class=\"menuheader\">"._($headline)."</p>\n";
123 $entries= "";
124 $this->menuparts[_($headline)]= array();
126 /* Parse sub-plugins */
127 foreach ($plug as $info){
129 /* Read information from class variable */
130 if (!isset($info['CLASS'])){
131 print_red(_("Your gosa.conf information has changed partly. Please convert it using the contributed script fix_config.sh!"));
132 echo $_SESSION['errors'];
133 exit;
134 }
135 $vars= get_class_vars($info['CLASS']);
136 $plHeadline= $vars['plHeadline'];
137 $plDescription= $vars['plDescription'];
140 $index= $this->get_index($info['PATH'],$info['CLASS']);
141 $image= get_template_path('images/'.$info['ICON']);
142 $href= "main.php?plug=$index&reset=1";
144 if(!$vars){
145 $plHeadline = _("Unknown");
146 $plDescription = _("Unknown");
147 $href= "main.php?reset=1";
148 }
150 #if ($this->check_access($info['ACL'])){
152 $entries= $entries."<p class=\"menuitem\" ".
153 "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>".
154 "<a class=\"menuitem\" ".
155 "href=\"$href\">".
156 _($plHeadline)."</a></p>\n";
158 /* Generate icon entry with description */
159 $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>';
160 if(!isset($_SESSION['maxC'])){
161 $_SESSION['maxC'] = "RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP";
162 }
163 #}
164 }
166 /* Append to menu */
167 if ($entries != ""){
168 $this->menu.= $menu.$entries;
169 }
170 }
172 }
174 /* Write menu output */
175 return ($this->menu);
176 }
178 function gen_current()
179 {
180 /* Do we have a current value? */
181 if ($this->current == ""){
182 $tmp= array_keys($this->menuparts);
183 $this->current= $tmp[0];
184 }
186 /* Fill current array */
187 $result= "<table width=\"100%\" summary=\"\">";
188 $count= 0;
189 foreach ($this->menuparts[$this->current] as $entry){
190 if ($count == 2){
191 $result.= "</tr>";
192 $count= 0;
193 }
194 if ($count == 0){
195 $result.= "<tr>";
196 }
197 $result.= "<td>$entry</td>";
198 $count++;
199 }
201 /* Add missing cell? */
202 if ($count == 1){
203 $result.= "<td> </td>";
204 }
206 $result.= "</table>";
207 return $result;
208 }
211 function show_iconmenu()
212 {
213 if ($this->iconmenu == ""){
214 $cfg= $this->config->data['MENU'];
216 if (isset($this->config->current['ICONSIZE'])){
217 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
218 $isize= "width=\"$x\" height=\"$y\"";
219 } else {
220 $isize= "";
221 }
223 /* Parse headlines */
224 foreach ($cfg as $headline => $plug){
225 $col= 1;
226 $menu= "<h1 class=\"menuheader\">".
227 _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
228 "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
229 $entries= "";
231 foreach ($plug as $info){
233 /* Read information from class variable */
234 $vars= get_class_vars($info['CLASS']);
235 $plHeadline= $vars['plHeadline'];
236 $plDescription= $vars['plDescription'];
238 $index= $this->get_index($info['PATH'],$info['CLASS']);
240 $href = "main.php?plug=".$index."&reset=1";
242 /* Check if class is available. If the class doesn't exists display error symbol
243 to avoid that a user clicks on a non existing plugin */
244 if(!$vars){
245 $plHeadline = $plDescription = _("Unknown");
246 $info['ICON'] = "error.png";
247 $href="main.php?reset=1";
248 }
251 #if ($this->check_access($info['ACL'])){
253 /* Hm this looks doubled */
254 $image= get_template_path('images/'.$info['ICON']);
255 if ($col > 5){
256 $entries= $entries."</tr><tr>";
257 $col = 1;
258 }
259 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
260 "><a class=\"iconmenu\" href=\"".$href."\">".
261 "<img $isize border=0 align=middle src=\"$image".
262 "\" alt=\"*\"> ".
263 _($plHeadline)."</a></td>\n";
264 $col++ ;
266 #}
267 }
269 /* Append to menu */
270 if ($entries != ""){
271 $this->iconmenu.= $menu.$entries;
273 /* Fill up remaining columns */
274 if ($col != 1){
275 $col--;
276 while ($col % 5){
277 $this->iconmenu= $this->iconmenu.
278 "<td style=\"width:20%\"> </td>\n";
279 $col++;
280 }
281 }
283 /* close table */
284 $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
285 }
286 }
288 }
290 /* Write menu output */
291 return ($this->iconmenu);
292 }
294 function get_path($index)
295 {
296 if(!isset($this->dirlist[$index])){
297 return ("");
298 }
299 return ("../".$this->dirlist[$index]);
300 }
302 function get_index($path,$class)
303 {
304 /* Search for plugin index (id), identify entry by path && class */
305 $data = $this->config->data['MENU'];
306 foreach($data as $section => $plugins){
307 foreach($plugins as $key => $plugin) {
308 if($plugin['CLASS'] == $class && $plugin['PATH'] == $path){
309 return($key);
310 }
311 }
312 }
314 /* Indentify by path*/
315 return (array_search($path, $this->dirlist));
317 }
318 }
319 ?>