Code

Added check for available plugins
[gosa.git] / include / class_pluglist.inc
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'];
124                                         $index= $this->get_index($info['PATH']);
125                                         $image= get_template_path('images/'.$info['ICON']);
126                                         $href= "main.php?plug=$index&amp;reset=1";
128                                         if(!$vars){
129                                                 $plHeadline     = _("Unknown");
130                                                 $plDescription  = _("Unknown");
131                                                 $href= "main.php?reset=1";
132                                         }
134                                         if ($this->check_access($info['ACL'])){
136                                                 $entries= $entries."<p class=\"menuitem\" ".
137                                                         "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>".
138                                                         "<a class=\"menuitem\" ".
139                                                         "href=\"$href\">".
140                                                         _($plHeadline)."</a></p>\n";
142                                                 /* Generate icon entry with description */
143                                                 $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>';
144                                                 if(!isset($_SESSION['maxC'])){
145                                                         $_SESSION['maxC'] = "RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP";
146                                                 }
147                                         }
148                                 }
150                                 /* Append to menu */
151                                 if ($entries != ""){
152                                         $this->menu.= $menu.$entries;
153                                 }
154                         }
156                 }
158                 /* Write menu output */
159                 return ($this->menu);
160         }
162         function gen_current()
163         {
164                 /* Do we have a current value? */
165                 if ($this->current == ""){
166                         $tmp= array_keys($this->menuparts);
167                         $this->current= $tmp[0];
168                 }
170                 /* Fill current array */
171                 $result= "<table width=\"100%\" summary=\"\">";
172                 $count= 0;
173                 foreach ($this->menuparts[$this->current] as $entry){
174                         if ($count == 2){
175                                 $result.= "</tr>";
176                                 $count= 0;
177                         }
178                         if ($count == 0){
179                                 $result.= "<tr>";
180                         }
181                         $result.= "<td>$entry</td>";
182                         $count++;
183                 }
185                 /* Add missing cell? */
186                 if ($count == 1){
187                         $result.= "<td>&nbsp;</td>";
188                 }
190                 $result.= "</table>";
191                 return $result;
192         }
195         function show_iconmenu()
196         {
197                 if ($this->iconmenu == ""){
198                         $cfg= $this->config->data['MENU'];
200                         if (isset($this->config->current['ICONSIZE'])){
201                                 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
202                                 $isize= "width=\"$x\" height=\"$y\"";
203                         } else {
204                                 $isize= "";
205                         }
207                         /* Parse headlines */
208                         foreach ($cfg as $headline => $plug){
209                                 $col= 1;
210                                 $menu= "<h1 class=\"menuheader\">".
211                                         _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
212                                         "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
213                                 $entries= "";
215                                 foreach ($plug as $info){
217                                         /* Read information from class variable */
218                                         $vars= get_class_vars($info['CLASS']);
219                                         $plHeadline= $vars['plHeadline'];
220                                         $plDescription= $vars['plDescription'];
222                                         $index= $this->get_index($info['PATH']);
224                                         $href = "main.php?plug=".$index."&amp;reset=1";
226                                         /* Check if class is available. If the class doesn't exists display error symbol 
227                                                 to avoid that a user clicks on a non existing plugin  */
228                                         if(!$vars){
229                                                 $plHeadline = $plDescription = _("Unknown");
230                                                 $info['ICON'] = "error.png";
231                                                 $href="main.php?reset=1";
232                                         }
235                                         if ($this->check_access($info['ACL'])){
237                                                 /* Hm this looks doubled */
238                                                 $image= get_template_path('images/'.$info['ICON']);
239                                                 if ($col > 5){
240                                                         $entries= $entries."</tr><tr>";
241                                                         $col = 1;
242                                                 }
243                                                 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
244                                                         "><a class=\"iconmenu\" href=\"".$href."\">".
245                                                         "<img $isize border=0 align=middle src=\"$image".
246                                                         "\" alt=\"*\">&nbsp;".
247                                                         _($plHeadline)."</a></td>\n";
248                                                 $col++ ;
250                                         }
251                                 }
253                                 /* Append to menu */
254                                 if ($entries != ""){
255                                         $this->iconmenu.= $menu.$entries;
257                                         /* Fill up remaining columns */
258                                         if ($col != 1){
259                                                 $col--;
260                                                 while ($col % 5){
261                                                         $this->iconmenu= $this->iconmenu.
262                                                                 "<td style=\"width:20%\">&nbsp;</td>\n";
263                                                         $col++;
264                                                 }
265                                         }
267                                         /* close table */
268                                         $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
269                                 }
270                         }
272                 }
274                 /* Write menu output */
275                 return ($this->iconmenu);
276         }
278         function get_path($index)
279         {
280                 if(!isset($this->dirlist[$index])){
281                         return ("");
282                 }
283                 return ("../".$this->dirlist[$index]);
284         }
286         function get_index($path)
287         {
288                 return (array_search($path, $this->dirlist));
289         }
291 ?>