Code

updated error msgs
[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();
45                                 foreach ($classes as $cname){
46                                         $cmethods = get_class_methods($cname);
47                                         if (in_array_ics('plInfo',$cmethods)){
48                                                 $this->info[$cname]= @call_user_func(array($cname, 'plInfo'));
49                                         }
50                                 }
52                 /* Provide field for 'all' */
53                 $this->info['all']= array();
54                 $this->info['all']['plProvidedAcls']= array();
55                 $this->info['all']['plDescription']= _("All objects in this category");
56                 $this->info['all']['plSelfModify']= FALSE;
57         }
59         function get_plugins($list, $config)
60         {
61                 /* Error reporting, because I'm getting strange messages in PHP 4.2.x */
62                 if (!isset($config['PATH']) && !isset($config['CLASS'])){
63                         if (is_array($config)){
64                                 foreach ($config as $val){
65                                         $list= $this->get_plugins($list, $val);
66                                 }
67                         }
68                 } else {
69                         if (isset ($config['PATH']) && is_array($config)){
70                                 $list[$this->index++]= $config['PATH'];
71                                 if (isset($config['CLASS'])){
72                                         $class= $config['CLASS'];
73                                 }
74                         }
75                 }
77                 return ($list);
78         }
80         function check_access($modname)
81         {
82                 /* This plugin is readable for everyone, return true */
83                 if ($modname == 'default'){
84                         return (TRUE);
85                 }
87                 /* Look through ACL's */
88                 foreach($this->ui->subtreeACL as $arr){
89                         foreach($arr as $value){
90                                 if ($value == ':all' || preg_match("/[,:]$modname#/", $value)){
91                                         if (!preg_match('/^!/', $value)){
92                                                 return (TRUE);
93                                         }
94                                 }
95                         }
96                 }
98                 return (FALSE);
99         }
101         function gen_headlines()
102         {
103                 $ret = array();
104                 if(count($this->headlines) == 0){
105                         foreach($this->config->data['MENU'] as $headline => $plugins){
106                                 foreach( $plugins as $id => $plug){
107                                         $attrs = (get_class_vars($plug['CLASS']));
108                                         $ret[$id]['HEADLINE'] = $headline;
109                                         $ret[$id]['NAME']         = $attrs['plHeadline'];       
110                                 }
111                         }
112                         $this->headlines = $ret;
113                 }
114                 return($this->headlines);
115         }
117         function gen_menu()
118         {
119                 if ($this->menu == ""){
120                         $cfg= $this->config->data['MENU'];
122                         /* Parse headlines */
123                         foreach ($cfg as $headline => $plug){
124                                 $menu= "<p class=\"menuheader\">"._($headline)."</p>\n";
125                                 $entries= "";
126                                 $this->menuparts[_($headline)]= array();
128                                 /* Parse sub-plugins */
129                                 foreach ($plug as $info){
131                                         /* Read information from class variable */
132                                         if (!isset($info['CLASS'])){
133                                                 print_red(_("Your gosa.conf information has changed partly. Please convert it using the contributed script fix_config.sh!"));
134                                                 echo $_SESSION['errors'];
135                                                 exit;
136                                         }
137                                         $vars= get_class_vars($info['CLASS']);
138                                         $plHeadline= $vars['plHeadline'];
139                                         $plDescription= $vars['plDescription'];
142                                         $index= $this->get_index($info['PATH'],$info['CLASS']);
143                                         $image= get_template_path('images/'.$info['ICON']);
144                                         $href= "main.php?plug=$index&amp;reset=1";
146                                         if(!$vars){
147                                                 $plHeadline     = _("Unknown");
148                                                 $plDescription  = _("Unknown");
149                                                 $href= "main.php?reset=1";
150                                         }
152                                         #if ($this->check_access($info['ACL'])){
154                                                 $entries= $entries."<p class=\"menuitem\" ".
155                                                         "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>".
156                                                         "<a class=\"menuitem\" ".
157                                                         "href=\"$href\">".
158                                                         _($plHeadline)."</a></p>\n";
160                                                 /* Generate icon entry with description */
161                                                 $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>';
162                                                 if(!isset($_SESSION['maxC'])){
163                                                         $_SESSION['maxC'] = "RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP";
164                                                 }
165                                         #}
166                                 }
168                                 /* Append to menu */
169                                 if ($entries != ""){
170                                         $this->menu.= $menu.$entries;
171                                 }
172                         }
174                 }
176                 /* Write menu output */
177                 return ($this->menu);
178         }
180         function gen_current()
181         {
182                 /* Do we have a current value? */
183                 if ($this->current == ""){
184                         $tmp= array_keys($this->menuparts);
185                         $this->current= $tmp[0];
186                 }
188                 /* Fill current array */
189                 $result= "<table width=\"100%\" summary=\"\">";
190                 $count= 0;
191                 foreach ($this->menuparts[$this->current] as $entry){
192                         if ($count == 2){
193                                 $result.= "</tr>";
194                                 $count= 0;
195                         }
196                         if ($count == 0){
197                                 $result.= "<tr>";
198                         }
199                         $result.= "<td>$entry</td>";
200                         $count++;
201                 }
203                 /* Add missing cell? */
204                 if ($count == 1){
205                         $result.= "<td>&nbsp;</td>";
206                 }
208                 $result.= "</table>";
209                 return $result;
210         }
213         function show_iconmenu()
214         {
215                 if ($this->iconmenu == ""){
216                         $cfg= $this->config->data['MENU'];
218                         if (isset($this->config->current['ICONSIZE'])){
219                                 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
220                                 $isize= "width=\"$x\" height=\"$y\"";
221                         } else {
222                                 $isize= "";
223                         }
225                         /* Parse headlines */
226                         foreach ($cfg as $headline => $plug){
227                                 $col= 1;
228                                 $menu= "<h1 class=\"menuheader\">".
229                                         _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
230                                         "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
231                                 $entries= "";
233                                 foreach ($plug as $info){
235                                         /* Read information from class variable */
236                                         $vars= get_class_vars($info['CLASS']);
237                                         $plHeadline= $vars['plHeadline'];
238                                         $plDescription= $vars['plDescription'];
240                                         $index= $this->get_index($info['PATH'],$info['CLASS']);
242                                         $href = "main.php?plug=".$index."&amp;reset=1";
244                                         /* Check if class is available. If the class doesn't exists display error symbol 
245                                                 to avoid that a user clicks on a non existing plugin  */
246                                         if(!$vars){
247                                                 $plHeadline = $plDescription = _("Unknown");
248                                                 $info['ICON'] = "error.png";
249                                                 $href="main.php?reset=1";
250                                         }
253                                         #if ($this->check_access($info['ACL'])){
255                                                 /* Hm this looks doubled */
256                                                 $image= get_template_path('images/'.$info['ICON']);
257                                                 if ($col > 5){
258                                                         $entries= $entries."</tr><tr>";
259                                                         $col = 1;
260                                                 }
261                                                 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
262                                                         "><a class=\"iconmenu\" href=\"".$href."\">".
263                                                         "<img $isize border=0 align=middle src=\"$image".
264                                                         "\" alt=\"*\">&nbsp;".
265                                                         _($plHeadline)."</a></td>\n";
266                                                 $col++ ;
268                                         #}
269                                 }
271                                 /* Append to menu */
272                                 if ($entries != ""){
273                                         $this->iconmenu.= $menu.$entries;
275                                         /* Fill up remaining columns */
276                                         if ($col != 1){
277                                                 $col--;
278                                                 while ($col % 5){
279                                                         $this->iconmenu= $this->iconmenu.
280                                                                 "<td style=\"width:20%\">&nbsp;</td>\n";
281                                                         $col++;
282                                                 }
283                                         }
285                                         /* close table */
286                                         $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
287                                 }
288                         }
290                 }
292                 /* Write menu output */
293                 return ($this->iconmenu);
294         }
296         function get_path($index)
297         {
298                 if(!isset($this->dirlist[$index])){
299                         return ("");
300                 }
301                 return ("../".$this->dirlist[$index]);
302         }
304         function get_index($path,$class)
305         {
306                 /* Search for plugin index (id), identify entry by path && class */
307                 $data = $this->config->data['MENU'];
308                 foreach($data as $section => $plugins){
309                         foreach($plugins as $key => $plugin)    {
310                                 if($plugin['CLASS'] == $class && $plugin['PATH'] == $path){
311                                         return($key);
312                                 }
313                         }
314                 }
316                 /* Indentify by path*/
317                 return (array_search($path, $this->dirlist));
319         }
321 ?>