Code

Added ogroups acls
[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 $info= array();
32         var $headlines = 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);
42                 /* Fill info part of pluglist */
43                 $classes= get_declared_classes();
44                 foreach (get_declared_classes() as $cname){
45                         if (method_exists($cname, 'plInfo')){
46                                 $this->info[$cname]= @call_user_func(array($cname, 'plInfo'));
47                         }
48                 }
49         }
51         function get_plugins($list, $config)
52         {
53                 /* Error reporting, because I'm getting strange messages in PHP 4.2.x */
54                 if (!isset($config['PATH']) && !isset($config['CLASS'])){
55                         if (is_array($config)){
56                                 foreach ($config as $val){
57                                         $list= $this->get_plugins($list, $val);
58                                 }
59                         }
60                 } else {
61                         if (isset ($config['PATH']) && is_array($config)){
62                                 $list[$this->index++]= $config['PATH'];
63                                 if (isset($config['CLASS'])){
64                                         $class= $config['CLASS'];
65                                 }
66                         }
67                 }
69                 return ($list);
70         }
72         function check_access($modname)
73         {
74                 /* This plugin is readable for everyone, return true */
75                 if ($modname == 'default'){
76                         return (TRUE);
77                 }
79                 /* Look through ACL's */
80                 foreach($this->ui->subtreeACL as $arr){
81                         foreach($arr as $value){
82                                 if ($value == ':all' || preg_match("/[,:]$modname#/", $value)){
83                                         if (!preg_match('/^!/', $value)){
84                                                 return (TRUE);
85                                         }
86                                 }
87                         }
88                 }
90                 return (FALSE);
91         }
93         function gen_headlines()
94         {
95                 $ret = array();
96                 if(count($this->headlines) == 0){
97                         foreach($this->config->data['MENU'] as $headline => $plugins){
98                                 foreach( $plugins as $id => $plug){
99                                         $attrs = (get_class_vars($plug['CLASS']));
100                                         $ret[$id]['HEADLINE'] = $headline;
101                                         $ret[$id]['NAME']         = $attrs['plHeadline'];       
102                                 }
103                         }
104                         $this->headlines = $ret;
105                 }
106                 return($this->headlines);
107         }
109         function gen_menu()
110         {
111                 if ($this->menu == ""){
112                         $cfg= $this->config->data['MENU'];
114                         /* Parse headlines */
115                         foreach ($cfg as $headline => $plug){
116                                 $menu= "<p class=\"menuheader\">"._($headline)."</p>\n";
117                                 $entries= "";
118                                 $this->menuparts[_($headline)]= array();
120                                 /* Parse sub-plugins */
121                                 foreach ($plug as $info){
123                                         /* Read information from class variable */
124                                         if (!isset($info['CLASS'])){
125                                                 print_red(_("Your gosa.conf information has changed partly. Please convert it using the contributed script fix_config.sh!"));
126                                                 echo $_SESSION['errors'];
127                                                 exit;
128                                         }
129                                         $vars= get_class_vars($info['CLASS']);
130                                         $plHeadline= $vars['plHeadline'];
131                                         $plDescription= $vars['plDescription'];
134                                         $index= $this->get_index($info['PATH']);
135                                         $image= get_template_path('images/'.$info['ICON']);
136                                         $href= "main.php?plug=$index&amp;reset=1";
138                                         if(!$vars){
139                                                 $plHeadline     = _("Unknown");
140                                                 $plDescription  = _("Unknown");
141                                                 $href= "main.php?reset=1";
142                                         }
144                                         #if ($this->check_access($info['ACL'])){
146                                                 $entries= $entries."<p class=\"menuitem\" ".
147                                                         "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>".
148                                                         "<a class=\"menuitem\" ".
149                                                         "href=\"$href\">".
150                                                         _($plHeadline)."</a></p>\n";
152                                                 /* Generate icon entry with description */
153                                                 $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>';
154                                                 if(!isset($_SESSION['maxC'])){
155                                                         $_SESSION['maxC'] = "RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP";
156                                                 }
157                                         #}
158                                 }
160                                 /* Append to menu */
161                                 if ($entries != ""){
162                                         $this->menu.= $menu.$entries;
163                                 }
164                         }
166                 }
168                 /* Write menu output */
169                 return ($this->menu);
170         }
172         function gen_current()
173         {
174                 /* Do we have a current value? */
175                 if ($this->current == ""){
176                         $tmp= array_keys($this->menuparts);
177                         $this->current= $tmp[0];
178                 }
180                 /* Fill current array */
181                 $result= "<table width=\"100%\" summary=\"\">";
182                 $count= 0;
183                 foreach ($this->menuparts[$this->current] as $entry){
184                         if ($count == 2){
185                                 $result.= "</tr>";
186                                 $count= 0;
187                         }
188                         if ($count == 0){
189                                 $result.= "<tr>";
190                         }
191                         $result.= "<td>$entry</td>";
192                         $count++;
193                 }
195                 /* Add missing cell? */
196                 if ($count == 1){
197                         $result.= "<td>&nbsp;</td>";
198                 }
200                 $result.= "</table>";
201                 return $result;
202         }
205         function show_iconmenu()
206         {
207                 if ($this->iconmenu == ""){
208                         $cfg= $this->config->data['MENU'];
210                         if (isset($this->config->current['ICONSIZE'])){
211                                 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
212                                 $isize= "width=\"$x\" height=\"$y\"";
213                         } else {
214                                 $isize= "";
215                         }
217                         /* Parse headlines */
218                         foreach ($cfg as $headline => $plug){
219                                 $col= 1;
220                                 $menu= "<h1 class=\"menuheader\">".
221                                         _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
222                                         "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
223                                 $entries= "";
225                                 foreach ($plug as $info){
227                                         /* Read information from class variable */
228                                         $vars= get_class_vars($info['CLASS']);
229                                         $plHeadline= $vars['plHeadline'];
230                                         $plDescription= $vars['plDescription'];
232                                         $index= $this->get_index($info['PATH']);
234                                         $href = "main.php?plug=".$index."&amp;reset=1";
236                                         /* Check if class is available. If the class doesn't exists display error symbol 
237                                                 to avoid that a user clicks on a non existing plugin  */
238                                         if(!$vars){
239                                                 $plHeadline = $plDescription = _("Unknown");
240                                                 $info['ICON'] = "error.png";
241                                                 $href="main.php?reset=1";
242                                         }
245                                         #if ($this->check_access($info['ACL'])){
247                                                 /* Hm this looks doubled */
248                                                 $image= get_template_path('images/'.$info['ICON']);
249                                                 if ($col > 5){
250                                                         $entries= $entries."</tr><tr>";
251                                                         $col = 1;
252                                                 }
253                                                 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
254                                                         "><a class=\"iconmenu\" href=\"".$href."\">".
255                                                         "<img $isize border=0 align=middle src=\"$image".
256                                                         "\" alt=\"*\">&nbsp;".
257                                                         _($plHeadline)."</a></td>\n";
258                                                 $col++ ;
260                                         #}
261                                 }
263                                 /* Append to menu */
264                                 if ($entries != ""){
265                                         $this->iconmenu.= $menu.$entries;
267                                         /* Fill up remaining columns */
268                                         if ($col != 1){
269                                                 $col--;
270                                                 while ($col % 5){
271                                                         $this->iconmenu= $this->iconmenu.
272                                                                 "<td style=\"width:20%\">&nbsp;</td>\n";
273                                                         $col++;
274                                                 }
275                                         }
277                                         /* close table */
278                                         $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
279                                 }
280                         }
282                 }
284                 /* Write menu output */
285                 return ($this->iconmenu);
286         }
288         function get_path($index)
289         {
290                 if(!isset($this->dirlist[$index])){
291                         return ("");
292                 }
293                 return ("../".$this->dirlist[$index]);
294         }
296         function get_index($path)
297         {
298                 return (array_search($path, $this->dirlist));
299         }
301 ?>