Code

Added some checks
[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'];
123                                 $index= $this->get_index($info['PATH']);
124                                 $image= get_template_path('images/'.$info['ICON']);
125                                 $href= "main.php?plug=$index&amp;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>';
138                                 }
139                         }
141                         /* Append to menu */
142                         if ($entries != ""){
143                                 $this->menu.= $menu.$entries;
144                         }
145                 }
147         }
149         /* Write menu output */
150         return ($this->menu);
151   }
153   function gen_current()
154   {
155         /* Do we have a current value? */
156         if ($this->current == ""){
157                 $tmp= array_keys($this->menuparts);
158                 $this->current= $tmp[0];
159         }
161         /* Fill current array */
162         $result= "<table width=\"100%\" summary=\"\">";
163         $count= 0;
164         foreach ($this->menuparts[$this->current] as $entry){
165                 if ($count == 2){
166                         $result.= "</tr>";
167                         $count= 0;
168                 }
169                 if ($count == 0){
170                         $result.= "<tr>";
171                 }
172                 $result.= "<td>$entry</td>";
173                 $count++;
174         }
176         /* Add missing cell? */
177         if ($count == 1){
178                 $result.= "<td>&nbsp;</td>";
179         }
181         $result.= "</table>";
182         return $result;
183   }
184   
186   function show_iconmenu()
187   {
188         if ($this->iconmenu == ""){
189                 $cfg= $this->config->data['MENU'];
191                 if (isset($this->config->current['ICONSIZE'])){
192                         list($x, $y)= split("x", $this->config->current['ICONSIZE']);
193                         $isize= "width=\"$x\" height=\"$y\"";
194                 } else {
195                         $isize= "";
196                 }
198                 /* Parse headlines */
199                 foreach ($cfg as $headline => $plug){
200                         $col= 1;
201                         $menu= "<h1 class=\"menuheader\">".
202                                         _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
203                                         "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
204                         $entries= "";
206                         foreach ($plug as $info){
208                                 /* Read information from class variable */
209                                 $vars= get_class_vars($info['CLASS']);
210                                 $plHeadline= $vars['plHeadline'];
211                                 $plDescription= $vars['plDescription'];
213                                 $index= $this->get_index($info['PATH']);
215                                 if ($this->check_access($info['ACL'])){
216                                 
217                                 /* Hm this looks doubled */
218                                 $image= get_template_path('images/'.$info['ICON']);
219                     if ($col > 5){
220                                                 $entries= $entries."</tr><tr>";
221                                                 $col = 1;
222                                         }
223                     $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"main.php?plug=$index&amp;reset=1\"'".
224                         "><a class=\"iconmenu\" href=\"main.php?plug=$index&amp;reset=1\">".
225                         "<img $isize border=0 align=middle src=\"$image".
226                         "\" alt=\"*\">&nbsp;".
227                         _($plHeadline)."</a></td>\n";
228                     $col++ ;
230                                 }
231                         }
233                         /* Append to menu */
234                         if ($entries != ""){
235                                 $this->iconmenu.= $menu.$entries;
237                                 /* Fill up remaining columns */
238                                 if ($col != 1){
239                                         $col--;
240                                         while ($col % 5){
241                                                 $this->iconmenu= $this->iconmenu.
242                                                         "<td style=\"width:20%\">&nbsp;</td>\n";
243                                                 $col++;
244                                         }
245                                 }
247                                 /* close table */
248                                 $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
249                         }
250                 }
252         }
254         /* Write menu output */
255         return ($this->iconmenu);
256   }
258   function get_path($index)
259   {
260         if(!isset($this->dirlist[$index])){
261                 return ("");
262         }
263         return ("../".$this->dirlist[$index]);
264   }
266   function get_index($path)
267   {
268         return (array_search($path, $this->dirlist));
269   }
272 ?>