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);
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 /* Error reporting, because I'm getting strange messages in PHP 4.2.x */
63 if (!isset($config['PATH']) && !isset($config['CLASS'])){
64 if (is_array($config)){
65 foreach ($config as $val){
66 $list= $this->get_plugins($list, $val);
67 }
68 }
69 } else {
70 if (isset ($config['PATH']) && is_array($config)){
71 $list[$this->index++]= $config['PATH'];
72 if (isset($config['CLASS'])){
73 $class= $config['CLASS'];
74 }
75 }
76 }
78 return ($list);
79 }
81 function check_access($aclname)
82 {
83 $acls_to_check = array();
84 if(preg_match("/,/",$aclname)){
85 $acls_to_check = split(",",$aclname);
86 }else{
87 $acls_to_check = array($aclname);
88 }
90 foreach($acls_to_check as $acl_to_check){
91 $deps = $this->ui->get_module_departments($acl_to_check);
92 foreach($deps as $dep){
93 if(preg_match("/\//",$acl_to_check)){
94 if($this->ui->get_permissions($dep,$acl_to_check) != ""){
95 return(TRUE);
96 }
97 }else{
98 if($this->ui->get_category_permissions($dep,$acl_to_check) != ""){
99 return(TRUE);
100 }
101 }
102 }
103 }
104 return (FALSE);
105 }
107 function gen_headlines()
108 {
109 $ret = array();
110 if(count($this->headlines) == 0){
111 foreach($this->config->data['MENU'] as $headline => $plugins){
112 foreach( $plugins as $id => $plug){
113 if (plugin_available($plug['CLASS'])){
114 $attrs = (get_class_vars($plug['CLASS']));
115 $ret[$id]['HEADLINE'] = $headline;
116 $ret[$id]['NAME'] = $attrs['plHeadline'];
117 }
118 }
119 }
120 $this->headlines = $ret;
121 }
122 return($this->headlines);
123 }
125 function gen_menu()
126 {
127 if ($this->menu == ""){
128 $first= TRUE;
129 $cfg= $this->config->data['MENU'];
131 /* Parse headlines */
132 foreach ($cfg as $headline => $plug){
133 if ($first){
134 $style= "";
135 $first= FALSE;
136 } else {
137 $style= "style='border-top:1px solid #AAA; margin-top:0.8em;'";
138 }
139 $menu= "<p class=\"menuheader\" $style>"._($headline)."</p>\n";
140 $entries= "";
141 $this->menuparts[_($headline)]= array();
143 /* Parse sub-plugins */
144 foreach ($plug as $info){
146 /* Read information from class variable */
147 if (!isset($info['CLASS'])){
148 msg_dialog::display(
149 _("Configuration error"),
150 _("The configuration format has changed. Please re-run setup!"),
151 FATAL_ERROR_DIALOG);
152 exit();
153 }
154 if (!plugin_available($info['CLASS'])){
155 continue;
156 }
157 $vars= get_class_vars($info['CLASS']);
158 $plHeadline= $vars['plHeadline'];
159 $plDescription= $vars['plDescription'];
162 $index= $this->get_index($info['PATH'],$info['CLASS']);
163 $image= get_template_path('images/'.$info['ICON']);
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 /* Generate icon entry with description */
185 $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;">';
186 if(session::get('js')){
187 $current.= '<b>'._($plHeadline).'</b><br>'._($plDescription);
188 } else {
189 $current.= '<a href="'.$href.'"><b>'._($plHeadline).'</b></a><br><a href="'.$href.'">'._($plDescription).'</a>';
190 }
191 $current.= '</td></tr></table>';
192 $this->menuparts[_($headline)][]= $current;
193 if(!session::is_set('maxC')){
194 session::set('maxC',"RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP");
195 }
196 }
197 }
199 /* Append to menu */
200 if ($entries != ""){
201 $this->menu.= $menu.$entries;
202 }
203 }
205 }
207 /* Write menu output */
208 return ($this->menu);
209 }
211 function gen_current()
212 {
213 /* Do we have a current value? */
214 if ($this->current == ""){
215 $tmp= array_keys($this->menuparts);
216 $this->current= $tmp[0];
217 }
219 /* Fill current array */
220 $result= "<table width=\"100%\" summary=\"\">";
221 $count= 0;
222 foreach ($this->menuparts[$this->current] as $entry){
223 if ($count == 2){
224 $result.= "</tr>";
225 $count= 0;
226 }
227 if ($count == 0){
228 $result.= "<tr>";
229 }
230 $result.= "<td>$entry</td>";
231 $count++;
232 }
234 /* Add missing cell? */
235 if ($count == 1){
236 $result.= "<td> </td>";
237 }
239 $result.= "</table>";
240 return $result;
241 }
244 function show_iconmenu()
245 {
246 if ($this->iconmenu == ""){
247 $cfg= $this->config->data['MENU'];
249 if (isset($this->config->current['ICONSIZE'])){
250 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
251 $isize= "width=\"$x\" height=\"$y\"";
252 } else {
253 $isize= "";
254 }
256 /* Parse headlines */
257 foreach ($cfg as $headline => $plug){
258 $col= 1;
259 $menu= "<h1 class=\"menuheader\">".
260 _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
261 "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
262 $entries= "";
264 foreach ($plug as $info){
266 if (!plugin_available($info['CLASS'])){
267 continue;
268 }
270 /* Read information from class variable */
271 $vars= get_class_vars($info['CLASS']);
272 $plHeadline= $vars['plHeadline'];
273 $plDescription= $vars['plDescription'];
275 $index= $this->get_index($info['PATH'],$info['CLASS']);
277 $href = "main.php?plug=".$index."&reset=1";
279 /* Check if class is available. If the class doesn't exists display error symbol
280 to avoid that a user clicks on a non existing plugin */
281 if(!$vars){
282 $plHeadline = $plDescription = _("Unknown");
283 $info['ICON'] = "error.png";
284 $href="main.php?reset=1";
285 }
288 if ($this->check_access($info['ACL'])){
290 /* Hm this looks doubled */
291 $image= get_template_path('images/'.$info['ICON']);
292 if ($col > 5){
293 $entries= $entries."</tr><tr>";
294 $col = 1;
295 }
296 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
297 ">";
298 if(session::get('js')){
299 $entries.= "<img $isize border=0 align=middle src=\"$image".
300 "\" alt=\"*\"> ".
301 _($plHeadline);
302 } else {
303 $entries.= "<a class=\"iconmenu\" href=\"".$href."\">".
304 "<img $isize border=0 align=middle src=\"$image".
305 "\" alt=\"*\"> ".
306 _($plHeadline)."</a>";
307 }
308 $entries.= "</td>\n";
309 $col++ ;
311 }
312 }
314 /* Append to menu */
315 if ($entries != ""){
316 $this->iconmenu.= $menu.$entries;
318 /* Fill up remaining columns */
319 if ($col != 1){
320 $col--;
321 while ($col % 5){
322 $this->iconmenu= $this->iconmenu.
323 "<td style=\"width:20%\"> </td>\n";
324 $col++;
325 }
326 }
328 /* close table */
329 $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
330 }
331 }
333 }
335 /* Write menu output */
336 return ($this->iconmenu);
337 }
339 function get_path($index)
340 {
341 if(!isset($this->dirlist[$index])){
342 return ("");
343 }
344 return ("../".$this->dirlist[$index]);
345 }
347 function get_index($path,$class)
348 {
349 /* Search for plugin index (id), identify entry by path && class */
350 $data = $this->config->data['MENU'];
351 foreach($data as $section => $plugins){
352 foreach($plugins as $key => $plugin) {
353 if($plugin['CLASS'] == $class && $plugin['PATH'] == $path){
354 return($key);
355 }
356 }
357 }
359 /* Indentify by path*/
360 return (array_search($path, $this->dirlist));
362 }
363 }
364 ?>