Code

Don't allow switching to hidden plugin by using plug=x attribute
[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();
32         var $allowed_plug_ids =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                         }
57                 }
58                 error_reporting(E_ALL);
60                 return ($list);
61         }
63         function check_access($modname)
64         {
65                 /* This plugin is readable for everyone, return true */
66                 if ($modname == 'default'){
67                         return (TRUE);
68                 }
70                 /* Look through ACL's */
71                 foreach($this->ui->subtreeACL as $arr){
72                         foreach($arr as $value){
73                                 if ($value == ':all' || preg_match("/[,:]$modname#/", $value)){
74                                         if (!preg_match('/^!/', $value)){
75                                                 return (TRUE);
76                                         }
77                                 }
78                         }
79                 }
81                 return (FALSE);
82         }
84         function gen_headlines()
85         {
86                 $ret = array();
87                 if(count($this->headlines) == 0){
88                         foreach($this->config->data['MENU'] as $headline => $plugins){
89                                 foreach( $plugins as $id => $plug){
90                                         $attrs = (get_class_vars($plug['CLASS']));
91                                         $ret[$id]['HEADLINE'] = $headline;
92                                         $ret[$id]['NAME']         = $attrs['plHeadline'];       
93                                 }
94                         }
95                         $this->headlines = $ret;
96                 }
97                 return($this->headlines);
98         }
100         function gen_menu()
101         {
102                 if ($this->menu == ""){
103                         $cfg= $this->config->data['MENU'];
105                         /* Parse headlines */
106                         foreach ($cfg as $headline => $plug){
107                                 $menu= "<p class=\"menuheader\">"._($headline)."</p>\n";
108                                 $entries= "";
109                                 $this->menuparts[_($headline)]= array();
111                                 /* Parse sub-plugins */
112                                 foreach ($plug as $info){
114                                         /* Read information from class variable */
115                                         if (!isset($info['CLASS'])){
116                                                 print_red(_("Your gosa.conf information has changed partly. Please convert it using the contributed script fix_config.sh!"));
117                                                 echo $_SESSION['errors'];
118                                                 exit;
119                                         }
120                                         $vars= get_class_vars($info['CLASS']);
121                                         $plHeadline= $vars['plHeadline'];
122                                         $plDescription= $vars['plDescription'];
125                                         $index= $this->get_index($info['PATH'],$info['CLASS']);
126                                         $image= get_template_path('images/'.$info['ICON']);
127                                         $href= "main.php?plug=$index&amp;reset=1";
129                                         if(!$vars){
130                                                 $plHeadline     = _("Unknown");
131                                                 $plDescription  = _("Unknown");
132                                                 $href= "main.php?reset=1";
133                                         }
135                                         if ($this->check_access($info['ACL'])){
136                                                 $this->allowed_plug_ids[$index]=$index;
137                                                 $entries= $entries."<p class=\"menuitem\" ".
138                                                         "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>".
139                                                         "<a class=\"menuitem\" ".
140                                                         "href=\"$href\">".
141                                                         _($plHeadline)."</a></p>\n";
143                                                 /* Generate icon entry with description */
144                                                 $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>';
145                                                 if(!isset($_SESSION['maxC'])){
146                                                         $_SESSION['maxC'] = "RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP";
147                                                 }
148                                         }
149                                 }
151                                 /* Append to menu */
152                                 if ($entries != ""){
153                                         $this->menu.= $menu.$entries;
154                                 }
155                         }
157                 }
159                 /* Write menu output */
160                 return ($this->menu);
161         }
163         function gen_current()
164         {
165                 /* Do we have a current value? */
166                 if ($this->current == ""){
167                         $tmp= array_keys($this->menuparts);
168                         $this->current= $tmp[0];
169                 }
171                 /* Fill current array */
172                 $result= "<table width=\"100%\" summary=\"\">";
173                 $count= 0;
174                 foreach ($this->menuparts[$this->current] as $entry){
175                         if ($count == 2){
176                                 $result.= "</tr>";
177                                 $count= 0;
178                         }
179                         if ($count == 0){
180                                 $result.= "<tr>";
181                         }
182                         $result.= "<td>$entry</td>";
183                         $count++;
184                 }
186                 /* Add missing cell? */
187                 if ($count == 1){
188                         $result.= "<td>&nbsp;</td>";
189                 }
191                 $result.= "</table>";
192                 return $result;
193         }
196         function show_iconmenu()
197         {
198                 if ($this->iconmenu == ""){
199                         $cfg= $this->config->data['MENU'];
201                         if (isset($this->config->current['ICONSIZE'])){
202                                 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
203                                 $isize= "width=\"$x\" height=\"$y\"";
204                         } else {
205                                 $isize= "";
206                         }
208                         /* Parse headlines */
209                         foreach ($cfg as $headline => $plug){
210                                 $col= 1;
211                                 $menu= "<h1 class=\"menuheader\">".
212                                         _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
213                                         "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
214                                 $entries= "";
216                                 foreach ($plug as $info){
218                                         /* Read information from class variable */
219                                         $vars= get_class_vars($info['CLASS']);
220                                         $plHeadline= $vars['plHeadline'];
221                                         $plDescription= $vars['plDescription'];
223                                         $index= $this->get_index($info['PATH'],$info['CLASS']);
225                                         $href = "main.php?plug=".$index."&amp;reset=1";
227                                         /* Check if class is available. If the class doesn't exists display error symbol 
228                                                 to avoid that a user clicks on a non existing plugin  */
229                                         if(!$vars){
230                                                 $plHeadline = $plDescription = _("Unknown");
231                                                 $info['ICON'] = "error.png";
232                                                 $href="main.php?reset=1";
233                                         }
236                                         if ($this->check_access($info['ACL'])){
238                                                 /* Hm this looks doubled */
239                                                 $image= get_template_path('images/'.$info['ICON']);
240                                                 if ($col > 5){
241                                                         $entries= $entries."</tr><tr>";
242                                                         $col = 1;
243                                                 }
244                                                 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
245                                                         "><a class=\"iconmenu\" href=\"".$href."\">".
246                                                         "<img $isize border=0 align=middle src=\"$image".
247                                                         "\" alt=\"*\">&nbsp;".
248                                                         _($plHeadline)."</a></td>\n";
249                                                 $col++ ;
251                                         }
252                                 }
254                                 /* Append to menu */
255                                 if ($entries != ""){
256                                         $this->iconmenu.= $menu.$entries;
258                                         /* Fill up remaining columns */
259                                         if ($col != 1){
260                                                 $col--;
261                                                 while ($col % 5){
262                                                         $this->iconmenu= $this->iconmenu.
263                                                                 "<td style=\"width:20%\">&nbsp;</td>\n";
264                                                         $col++;
265                                                 }
266                                         }
268                                         /* close table */
269                                         $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
270                                 }
271                         }
273                 }
275                 /* Write menu output */
276                 return ($this->iconmenu);
277         }
279         function get_path($index)
280         {
281                 if(!isset($this->dirlist[$index])){
282                         return ("");
283                 }
284                 return ("../".$this->dirlist[$index]);
285         }
287         function get_index($path,$class)
288         {
289                 /* Search for plugin index (id), identify entry by path && class */
290                 $data = $this->config->data['MENU'];
291                 foreach($data as $section => $plugins){
292                         foreach($plugins as $key => $plugin)    {
293                                 if($plugin['CLASS'] == $class && $plugin['PATH'] == $path){
294                                         return($key);
295                                 }
296                         }
297                 }
299                 /* Indentify by path*/
300                 return (array_search($path, $this->dirlist));
302         }
304 ?>