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);
41 }
43 function get_plugins($list, $config)
44 {
45 /* Error reporting, because I'm getting strange messages in PHP 4.2.x */
46 error_reporting(0);
47 if (!isset($config['PATH']) && !isset($config['CLASS'])){
48 if (is_array($config)){
49 foreach ($config as $val){
50 $list= $this->get_plugins($list, $val);
51 }
52 }
53 } else {
54 if (isset ($config['PATH']) && is_array($config)){
55 $list[$this->index++]= $config['PATH'];
56 if (isset($config['CLASS'])){
57 $class= $config['CLASS'];
58 $this->info[$class]= call_user_func(array($class, 'plInfo'));
59 }
60 }
61 }
62 error_reporting(E_ALL);
64 return ($list);
65 }
67 function check_access($modname)
68 {
69 /* This plugin is readable for everyone, return true */
70 if ($modname == 'default'){
71 return (TRUE);
72 }
74 /* Look through ACL's */
75 foreach($this->ui->subtreeACL as $arr){
76 foreach($arr as $value){
77 if ($value == ':all' || preg_match("/[,:]$modname#/", $value)){
78 if (!preg_match('/^!/', $value)){
79 return (TRUE);
80 }
81 }
82 }
83 }
85 return (FALSE);
86 }
88 function gen_headlines()
89 {
90 $ret = array();
91 if(count($this->headlines) == 0){
92 foreach($this->config->data['MENU'] as $headline => $plugins){
93 foreach( $plugins as $id => $plug){
94 $attrs = (get_class_vars($plug['CLASS']));
95 $ret[$id]['HEADLINE'] = $headline;
96 $ret[$id]['NAME'] = $attrs['plHeadline'];
97 }
98 }
99 $this->headlines = $ret;
100 }
101 return($this->headlines);
102 }
104 function gen_menu()
105 {
106 if ($this->menu == ""){
107 $cfg= $this->config->data['MENU'];
109 /* Parse headlines */
110 foreach ($cfg as $headline => $plug){
111 $menu= "<p class=\"menuheader\">"._($headline)."</p>\n";
112 $entries= "";
113 $this->menuparts[_($headline)]= array();
115 /* Parse sub-plugins */
116 foreach ($plug as $info){
118 /* Read information from class variable */
119 if (!isset($info['CLASS'])){
120 print_red(_("Your gosa.conf information has changed partly. Please convert it using the contributed script fix_config.sh!"));
121 echo $_SESSION['errors'];
122 exit;
123 }
124 $vars= get_class_vars($info['CLASS']);
125 $plHeadline= $vars['plHeadline'];
126 $plDescription= $vars['plDescription'];
129 $index= $this->get_index($info['PATH']);
130 $image= get_template_path('images/'.$info['ICON']);
131 $href= "main.php?plug=$index&reset=1";
133 if(!$vars){
134 $plHeadline = _("Unknown");
135 $plDescription = _("Unknown");
136 $href= "main.php?reset=1";
137 }
139 #if ($this->check_access($info['ACL'])){
141 $entries= $entries."<p class=\"menuitem\" ".
142 "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>".
143 "<a class=\"menuitem\" ".
144 "href=\"$href\">".
145 _($plHeadline)."</a></p>\n";
147 /* Generate icon entry with description */
148 $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>';
149 if(!isset($_SESSION['maxC'])){
150 $_SESSION['maxC'] = "RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP";
151 }
152 #}
153 }
155 /* Append to menu */
156 if ($entries != ""){
157 $this->menu.= $menu.$entries;
158 }
159 }
161 }
163 /* Write menu output */
164 return ($this->menu);
165 }
167 function gen_current()
168 {
169 /* Do we have a current value? */
170 if ($this->current == ""){
171 $tmp= array_keys($this->menuparts);
172 $this->current= $tmp[0];
173 }
175 /* Fill current array */
176 $result= "<table width=\"100%\" summary=\"\">";
177 $count= 0;
178 foreach ($this->menuparts[$this->current] as $entry){
179 if ($count == 2){
180 $result.= "</tr>";
181 $count= 0;
182 }
183 if ($count == 0){
184 $result.= "<tr>";
185 }
186 $result.= "<td>$entry</td>";
187 $count++;
188 }
190 /* Add missing cell? */
191 if ($count == 1){
192 $result.= "<td> </td>";
193 }
195 $result.= "</table>";
196 return $result;
197 }
200 function show_iconmenu()
201 {
202 if ($this->iconmenu == ""){
203 $cfg= $this->config->data['MENU'];
205 if (isset($this->config->current['ICONSIZE'])){
206 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
207 $isize= "width=\"$x\" height=\"$y\"";
208 } else {
209 $isize= "";
210 }
212 /* Parse headlines */
213 foreach ($cfg as $headline => $plug){
214 $col= 1;
215 $menu= "<h1 class=\"menuheader\">".
216 _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
217 "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
218 $entries= "";
220 foreach ($plug as $info){
222 /* Read information from class variable */
223 $vars= get_class_vars($info['CLASS']);
224 $plHeadline= $vars['plHeadline'];
225 $plDescription= $vars['plDescription'];
227 $index= $this->get_index($info['PATH']);
229 $href = "main.php?plug=".$index."&reset=1";
231 /* Check if class is available. If the class doesn't exists display error symbol
232 to avoid that a user clicks on a non existing plugin */
233 if(!$vars){
234 $plHeadline = $plDescription = _("Unknown");
235 $info['ICON'] = "error.png";
236 $href="main.php?reset=1";
237 }
240 #if ($this->check_access($info['ACL'])){
242 /* Hm this looks doubled */
243 $image= get_template_path('images/'.$info['ICON']);
244 if ($col > 5){
245 $entries= $entries."</tr><tr>";
246 $col = 1;
247 }
248 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
249 "><a class=\"iconmenu\" href=\"".$href."\">".
250 "<img $isize border=0 align=middle src=\"$image".
251 "\" alt=\"*\"> ".
252 _($plHeadline)."</a></td>\n";
253 $col++ ;
255 #}
256 }
258 /* Append to menu */
259 if ($entries != ""){
260 $this->iconmenu.= $menu.$entries;
262 /* Fill up remaining columns */
263 if ($col != 1){
264 $col--;
265 while ($col % 5){
266 $this->iconmenu= $this->iconmenu.
267 "<td style=\"width:20%\"> </td>\n";
268 $col++;
269 }
270 }
272 /* close table */
273 $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
274 }
275 }
277 }
279 /* Write menu output */
280 return ($this->iconmenu);
281 }
283 function get_path($index)
284 {
285 if(!isset($this->dirlist[$index])){
286 return ("");
287 }
288 return ("../".$this->dirlist[$index]);
289 }
291 function get_index($path)
292 {
293 return (array_search($path, $this->dirlist));
294 }
295 }
296 ?>