Code

last files, added summary
[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= "";
32   function pluglist($config, $ui)
33   {
34         $this->ui= $ui;
35         $this->config= $config;
37         /* Create dirlist for all plugins */
38         $this->dirlist= $this->get_plugins ($this->dirlist, $this->config->data);
39   }
41   function get_plugins($list, $config)
42   {
43         /* Error reporting, because I'm getting strange messages in PHP 4.2.x */
44         error_reporting(0);
45         if (!isset($config['PATH']) && !isset($config['CLASS'])){
46                 if (is_array($config)){
47                         foreach ($config as $val){
48                                 $list= $this->get_plugins($list, $val);
49                         }
50                 }
51         } else {
52                 if (isset ($config['PATH']) && is_array($config)){
53                         $list[$this->index++]= $config['PATH'];
54                 }
55         }
56         error_reporting(E_ALL);
58         return ($list);
59   }
61   function check_access($modname)
62   {
63         /* This plugin is readable for everyone, return true */
64         if ($modname == 'default'){
65                 return (TRUE);
66         }
68         /* Look through ACL's */
69         foreach($this->ui->subtreeACL as $arr){
70                 foreach($arr as $value){
71                         if ($value == ':all' || preg_match("/[,:]$modname#/", $value)){
72                                 if (!preg_match('/^!/', $value)){
73                                         return (TRUE);
74                                 }
75                         }
76                 }
77         }
79         return (FALSE);
80   }
82   function gen_menu()
83   {
84         if ($this->menu == ""){
85                 $cfg= $this->config->data['MENU'];
87                 /* Parse headlines */
88                 foreach ($cfg as $headline => $plug){
89                         $menu= "<p class=\"menuheader\">"._($headline)."</p>\n";
90                         $entries= "";
91                         $this->menuparts[_($headline)]= array();
93                         /* Parse sub-plugins */
94                         foreach ($plug as $info){
96                                 /* Read information from class variable */
97                                 if (!isset($info['CLASS'])){
98                                         print_red(_("Your gosa.conf information has changed partly. Please convert it using the contributed script fix_config.sh!"));
99                                         echo $_SESSION['errors'];
100                                         exit;
101                                 }
102                                 $vars= get_class_vars($info['CLASS']);
103                                 $plHeadline= $vars['plHeadline'];
104                                 $plDescription= $vars['plDescription'];
106                                 $index= $this->get_index($info['PATH']);
107                                 $image= get_template_path('images/'.$info['ICON']);
108                                 $href= "main.php?plug=$index&amp;reset=1";
110                                 if ($this->check_access($info['ACL'])){
112                                         $entries= $entries."<p class=\"menuitem\" ".
113                                                 "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>".
114                                                 "<a class=\"menuitem\" ".
115                                                 "href=\"$href\">".
116                                                 _($plHeadline)."</a></p>\n";
118                                 /* Generate icon entry with description */
119                                 $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>';
121                                 }
122                         }
124                         /* Append to menu */
125                         if ($entries != ""){
126                                 $this->menu.= $menu.$entries;
127                         }
128                 }
130         }
132         /* Write menu output */
133         return ($this->menu);
134   }
136   function gen_current()
137   {
138         /* Do we have a current value? */
139         if ($this->current == ""){
140                 $tmp= array_keys($this->menuparts);
141                 $this->current= $tmp[0];
142         }
144         /* Fill current array */
145         $result= "<table width=\"100%\" summary=\"\">";
146         $count= 0;
147         foreach ($this->menuparts[$this->current] as $entry){
148                 if ($count == 2){
149                         $result.= "</tr>";
150                         $count= 0;
151                 }
152                 if ($count == 0){
153                         $result.= "<tr>";
154                 }
155                 $result.= "<td>$entry</td>";
156                 $count++;
157         }
159         /* Add missing cell? */
160         if ($count == 1){
161                 $result.= "<td>&nbsp;</td>";
162         }
164         $result.= "</table>";
165         return $result;
166   }
167   
169   function show_iconmenu()
170   {
171         if ($this->iconmenu == ""){
172                 $cfg= $this->config->data['MENU'];
174                 if (isset($this->config->current['ICONSIZE'])){
175                         list($x, $y)= split("x", $this->config->current['ICONSIZE']);
176                         $isize= "width=\"$x\" height=\"$y\"";
177                 } else {
178                         $isize= "";
179                 }
181                 /* Parse headlines */
182                 foreach ($cfg as $headline => $plug){
183                         $col= 1;
184                         $menu= "<h1 class=\"menuheader\">".
185                                         _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
186                                         "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
187                         $entries= "";
189                         foreach ($plug as $info){
191                                 /* Read information from class variable */
192                                 $vars= get_class_vars($info['CLASS']);
193                                 $plHeadline= $vars['plHeadline'];
194                                 $plDescription= $vars['plDescription'];
196                                 $index= $this->get_index($info['PATH']);
198                                 if ($this->check_access($info['ACL'])){
199                                 
200                                 /* Hm this looks doubled */
201                                 $image= get_template_path('images/'.$info['ICON']);
202                     if ($col > 5){
203                                                 $entries= $entries."</tr><tr>";
204                                                 $col = 1;
205                                         }
206                     $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"main.php?plug=$index&amp;reset=1\"'".
207                         "><a class=\"iconmenu\" href=\"main.php?plug=$index&amp;reset=1\">".
208                         "<img $isize border=0 align=middle src=\"$image".
209                         "\" alt=\"*\">&nbsp;".
210                         _($plHeadline)."</a></td>\n";
211                     $col++ ;
213                                 }
214                         }
216                         /* Append to menu */
217                         if ($entries != ""){
218                                 $this->iconmenu.= $menu.$entries;
220                                 /* Fill up remaining columns */
221                                 if ($col != 1){
222                                         $col--;
223                                         while ($col % 5){
224                                                 $this->iconmenu= $this->iconmenu.
225                                                         "<td style=\"width:20%\">&nbsp;</td>\n";
226                                                 $col++;
227                                         }
228                                 }
230                                 /* close table */
231                                 $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
232                         }
233                 }
235         }
237         /* Write menu output */
238         return ($this->iconmenu);
239   }
241   function get_path($index)
242   {
243         if(!isset($this->dirlist[$index])){
244                 return ("");
245         }
246         return ("../".$this->dirlist[$index]);
247   }
249   function get_index($path)
250   {
251         return (array_search($path, $this->dirlist));
252   }
255 ?>