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'];
161 $index= $this->get_index($info['PATH'],$info['CLASS']);
162 $href= "main.php?plug=$index&reset=1";
164 if(!$vars){
165 $plHeadline = _("Unknown");
166 $plDescription = _("Unknown");
167 $href= "main.php?reset=1";
168 }
170 if ($this->check_access($info['ACL'])){
172 $entries= $entries."<p class=\"menuitem\" ".
173 "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>";
174 if(session::get('js')){
175 $entries.= _($plHeadline)."</p>\n";
176 } else {
177 $entries.= "<a class=\"menuitem\" ".
178 "href=\"$href\">".
179 _($plHeadline)."</a></p>\n";
180 }
182 if(!session::is_set('maxC')){
183 session::set('maxC',"RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP");
184 }
185 }
186 }
188 /* Append to menu */
189 if ($entries != ""){
190 $this->menu.= $menu.$entries;
191 }
192 }
194 }
196 /* Write menu output */
197 return ($this->menu);
198 }
200 function gen_current()
201 {
202 /* Do we have a current value? */
203 if ($this->current == ""){
204 $tmp= array_keys($this->menuparts);
205 $this->current= $tmp[0];
206 }
208 /* Fill current array */
209 $result= "<table width=\"100%\" summary=\"\">";
210 $count= 0;
211 foreach ($this->menuparts[$this->current] as $entry){
212 if ($count == 2){
213 $result.= "</tr>";
214 $count= 0;
215 }
216 if ($count == 0){
217 $result.= "<tr>";
218 }
219 $result.= "<td>$entry</td>";
220 $count++;
221 }
223 /* Add missing cell? */
224 if ($count == 1){
225 $result.= "<td> </td>";
226 }
228 $result.= "</table>";
229 return $result;
230 }
233 function show_iconmenu()
234 {
235 if ($this->iconmenu == ""){
236 $cfg= $this->config->data['MENU'];
238 if (isset($this->config->current['ICONSIZE'])){
239 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
240 $isize= "width=\"$x\" height=\"$y\"";
241 } else {
242 $isize= "";
243 }
245 /* Parse headlines */
246 foreach ($cfg as $headline => $plug){
247 $col= 1;
248 $menu= "<h1 class=\"menuheader\">".
249 _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
250 "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
251 $entries= "";
253 foreach ($plug as $info){
255 if (!plugin_available($info['CLASS'])){
256 continue;
257 }
259 /* Read information from class variable */
260 $vars= get_class_vars($info['CLASS']);
261 $plHeadline= $vars['plHeadline'];
262 $plDescription= $vars['plDescription'];
264 $index= $this->get_index($info['PATH'],$info['CLASS']);
266 $href = "main.php?plug=".$index."&reset=1";
268 /* Check if class is available. If the class doesn't exists display error symbol
269 to avoid that a user clicks on a non existing plugin */
270 if(!$vars){
271 $plHeadline = $plDescription = _("Unknown");
272 $info['ICON'] = "error.png";
273 $href="main.php?reset=1";
274 }
277 if ($this->check_access($info['ACL'])){
279 /* Load icon */
280 if (isset($info['ICON'])){
281 $image= get_template_path('images/'.$info['ICON']);
282 } else {
283 $image= get_template_path("plugins/".preg_replace("/^.*\//", "", $info['PATH'])."/images/plugin.png");
284 }
285 if ($col > 5){
286 $entries= $entries."</tr><tr>";
287 $col = 1;
288 }
289 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
290 ">";
291 if(session::get('js')){
292 $entries.= "<img $isize border=0 align=middle src=\"$image".
293 "\" alt=\"*\"> ".
294 _($plHeadline);
295 } else {
296 $entries.= "<a class=\"iconmenu\" href=\"".$href."\">".
297 "<img $isize border=0 align=middle src=\"$image".
298 "\" alt=\"*\"> ".
299 _($plHeadline)."</a>";
300 }
301 $entries.= "</td>\n";
302 $col++ ;
304 }
305 }
307 /* Append to menu */
308 if ($entries != ""){
309 $this->iconmenu.= $menu.$entries;
311 /* Fill up remaining columns */
312 if ($col != 1){
313 $col--;
314 while ($col % 5){
315 $this->iconmenu= $this->iconmenu.
316 "<td style=\"width:20%\"> </td>\n";
317 $col++;
318 }
319 }
321 /* close table */
322 $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
323 }
324 }
326 }
328 /* Write menu output */
329 return ($this->iconmenu);
330 }
332 function get_path($index)
333 {
334 if(!isset($this->dirlist[$index])){
335 return ("");
336 }
337 return ("../".$this->dirlist[$index]);
338 }
340 function get_index($path,$class)
341 {
342 /* Search for plugin index (id), identify entry by path && class */
343 $data = $this->config->data['MENU'];
344 foreach($data as $section => $plugins){
345 foreach($plugins as $key => $plugin) {
346 if($plugin['CLASS'] == $class && $plugin['PATH'] == $path){
347 return($key);
348 }
349 }
350 }
352 /* Indentify by path*/
353 return (array_search($path, $this->dirlist));
355 }
356 }
357 ?>