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 $headlines = array();
33 function pluglist($config, $ui)
34 {
35 $this->ui= $ui;
36 $this->config= $config;
38 /* Create dirlist for all plugins */
39 $this->dirlist= $this->get_plugins ($this->dirlist, $this->config->data);
40 }
42 function get_plugins($list, $config)
43 {
44 /* Error reporting, because I'm getting strange messages in PHP 4.2.x */
45 error_reporting(0);
46 if (!isset($config['PATH']) && !isset($config['CLASS'])){
47 if (is_array($config)){
48 foreach ($config as $val){
49 $list= $this->get_plugins($list, $val);
50 }
51 }
52 } else {
53 if (isset ($config['PATH']) && is_array($config)){
54 $list[$this->index++]= $config['PATH'];
55 }
56 }
57 error_reporting(E_ALL);
59 return ($list);
60 }
62 function check_access($modname)
63 {
64 /* This plugin is readable for everyone, return true */
65 if ($modname == 'default'){
66 return (TRUE);
67 }
69 /* Look through ACL's */
70 foreach($this->ui->subtreeACL as $arr){
71 foreach($arr as $value){
72 if ($value == ':all' || preg_match("/[,:]$modname#/", $value)){
73 if (!preg_match('/^!/', $value)){
74 return (TRUE);
75 }
76 }
77 }
78 }
80 return (FALSE);
81 }
83 function gen_headlines()
84 {
85 $ret = array();
86 if(count($this->headlines) == 0){
87 foreach($this->config->data['MENU'] as $headline => $plugins){
88 foreach( $plugins as $id => $plug){
89 $attrs = (get_class_vars($plug['CLASS']));
90 $ret[$id]['HEADLINE'] = $headline;
91 $ret[$id]['NAME'] = $attrs['plHeadline'];
92 }
93 }
94 $this->headlines = $ret;
95 }
96 return($this->headlines);
97 }
99 function gen_menu()
100 {
101 if ($this->menu == ""){
102 $cfg= $this->config->data['MENU'];
104 /* Parse headlines */
105 foreach ($cfg as $headline => $plug){
106 $menu= "<p class=\"menuheader\">"._($headline)."</p>\n";
107 $entries= "";
108 $this->menuparts[_($headline)]= array();
110 /* Parse sub-plugins */
111 foreach ($plug as $info){
113 /* Read information from class variable */
114 if (!isset($info['CLASS'])){
115 print_red(_("Your gosa.conf information has changed partly. Please convert it using the contributed script fix_config.sh!"));
116 echo $_SESSION['errors'];
117 exit;
118 }
119 $vars= get_class_vars($info['CLASS']);
120 $plHeadline= $vars['plHeadline'];
121 $plDescription= $vars['plDescription'];
123 $index= $this->get_index($info['PATH']);
124 $image= get_template_path('images/'.$info['ICON']);
125 $href= "main.php?plug=$index&reset=1";
127 if ($this->check_access($info['ACL'])){
129 $entries= $entries."<p class=\"menuitem\" ".
130 "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>".
131 "<a class=\"menuitem\" ".
132 "href=\"$href\">".
133 _($plHeadline)."</a></p>\n";
135 /* Generate icon entry with description */
136 $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>';
137 if(!isset($_SESSION['maxC'])){
138 $_SESSION['maxC'] = "RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP";
139 }
140 }
141 }
143 /* Append to menu */
144 if ($entries != ""){
145 $this->menu.= $menu.$entries;
146 }
147 }
149 }
151 /* Write menu output */
152 return ($this->menu);
153 }
155 function gen_current()
156 {
157 /* Do we have a current value? */
158 if ($this->current == ""){
159 $tmp= array_keys($this->menuparts);
160 $this->current= $tmp[0];
161 }
163 /* Fill current array */
164 $result= "<table width=\"100%\" summary=\"\">";
165 $count= 0;
166 foreach ($this->menuparts[$this->current] as $entry){
167 if ($count == 2){
168 $result.= "</tr>";
169 $count= 0;
170 }
171 if ($count == 0){
172 $result.= "<tr>";
173 }
174 $result.= "<td>$entry</td>";
175 $count++;
176 }
178 /* Add missing cell? */
179 if ($count == 1){
180 $result.= "<td> </td>";
181 }
183 $result.= "</table>";
184 return $result;
185 }
188 function show_iconmenu()
189 {
190 if ($this->iconmenu == ""){
191 $cfg= $this->config->data['MENU'];
193 if (isset($this->config->current['ICONSIZE'])){
194 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
195 $isize= "width=\"$x\" height=\"$y\"";
196 } else {
197 $isize= "";
198 }
200 /* Parse headlines */
201 foreach ($cfg as $headline => $plug){
202 $col= 1;
203 $menu= "<h1 class=\"menuheader\">".
204 _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
205 "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
206 $entries= "";
208 foreach ($plug as $info){
210 /* Read information from class variable */
211 $vars= get_class_vars($info['CLASS']);
212 $plHeadline= $vars['plHeadline'];
213 $plDescription= $vars['plDescription'];
215 $index= $this->get_index($info['PATH']);
217 if ($this->check_access($info['ACL'])){
219 /* Hm this looks doubled */
220 $image= get_template_path('images/'.$info['ICON']);
221 if ($col > 5){
222 $entries= $entries."</tr><tr>";
223 $col = 1;
224 }
225 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"main.php?plug=$index&reset=1\"'".
226 "><a class=\"iconmenu\" href=\"main.php?plug=$index&reset=1\">".
227 "<img $isize border=0 align=middle src=\"$image".
228 "\" alt=\"*\"> ".
229 _($plHeadline)."</a></td>\n";
230 $col++ ;
232 }
233 }
235 /* Append to menu */
236 if ($entries != ""){
237 $this->iconmenu.= $menu.$entries;
239 /* Fill up remaining columns */
240 if ($col != 1){
241 $col--;
242 while ($col % 5){
243 $this->iconmenu= $this->iconmenu.
244 "<td style=\"width:20%\"> </td>\n";
245 $col++;
246 }
247 }
249 /* close table */
250 $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
251 }
252 }
254 }
256 /* Write menu output */
257 return ($this->iconmenu);
258 }
260 function get_path($index)
261 {
262 if(!isset($this->dirlist[$index])){
263 return ("");
264 }
265 return ("../".$this->dirlist[$index]);
266 }
268 function get_index($path)
269 {
270 return (array_search($path, $this->dirlist));
271 }
272 }
273 ?>