Code

3468ce3bdb43564a5837e8780ff03eea21c32f70
[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                         $first= TRUE;
121                         $cfg= $this->config->data['MENU'];
123                         /* Parse headlines */
124                         foreach ($cfg as $headline => $plug){
125                                 if ($first){
126                                         $style= "";
127                                         $first= FALSE;
128                                 } else {
129                                         $style= "style='border-top:1px solid #AAA; margin-top:0.8em;'";
130                                 }
131                                 $menu= "<p class=\"menuheader\" $style>"._($headline)."</p>\n";
132                                 $entries= "";
133                                 $this->menuparts[_($headline)]= array();
135                                 /* Parse sub-plugins */
136                                 foreach ($plug as $info){
138                                         /* Read information from class variable */
139                                         if (!isset($info['CLASS'])){
140                                                 print_red(_("Your gosa.conf information has changed partly. Please convert it using the contributed script fix_config.sh!"));
141                                                 echo $_SESSION['errors'];
142                                                 exit;
143                                         }
144                                         $vars= get_class_vars($info['CLASS']);
145                                         $plHeadline= $vars['plHeadline'];
146                                         $plDescription= $vars['plDescription'];
149                                         $index= $this->get_index($info['PATH'],$info['CLASS']);
150                                         $image= get_template_path('images/'.$info['ICON']);
151                                         $href= "main.php?plug=$index&amp;reset=1";
153                                         if(!$vars){
154                                                 $plHeadline     = _("Unknown");
155                                                 $plDescription  = _("Unknown");
156                                                 $href= "main.php?reset=1";
157                                         }
159                                         #if ($this->check_access($info['ACL'])){
161                                                 $entries= $entries."<p class=\"menuitem\" ".
162                                                         "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>";
163                                                 if($_SESSION['js']){
164                                                         $entries.= _($plHeadline)."</p>\n";
165                                                 } else {
166                                                         $entries.= "<a class=\"menuitem\" ".
167                                                         "href=\"$href\">".
168                                                         _($plHeadline)."</a></p>\n";
169                                                 }
171                                                 /* Generate icon entry with description */
172                                                 $current= '<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;">';
173                                                 if($_SESSION['js']){
174                                                         $current.= '<b>'._($plHeadline).'</b><br>'._($plDescription);
175                                                 } else {
176                                                         $current.= '<a href="'.$href.'"><b>'._($plHeadline).'</b></a><br><a href="'.$href.'">'._($plDescription).'</a>';
177                                                 }
178                                                 $current.= '</td></tr></table>';
179                                                 $this->menuparts[_($headline)][]= $current;
180                                                 if(!isset($_SESSION['maxC'])){
181                                                         $_SESSION['maxC'] = "RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP";
182                                                 }
183                                         #}
184                                 }
186                                 /* Append to menu */
187                                 if ($entries != ""){
188                                         $this->menu.= $menu.$entries;
189                                 }
190                         }
192                 }
194                 /* Write menu output */
195                 return ($this->menu);
196         }
198         function gen_current()
199         {
200                 /* Do we have a current value? */
201                 if ($this->current == ""){
202                         $tmp= array_keys($this->menuparts);
203                         $this->current= $tmp[0];
204                 }
206                 /* Fill current array */
207                 $result= "<table width=\"100%\" summary=\"\">";
208                 $count= 0;
209                 foreach ($this->menuparts[$this->current] as $entry){
210                         if ($count == 2){
211                                 $result.= "</tr>";
212                                 $count= 0;
213                         }
214                         if ($count == 0){
215                                 $result.= "<tr>";
216                         }
217                         $result.= "<td>$entry</td>";
218                         $count++;
219                 }
221                 /* Add missing cell? */
222                 if ($count == 1){
223                         $result.= "<td>&nbsp;</td>";
224                 }
226                 $result.= "</table>";
227                 return $result;
228         }
231         function show_iconmenu()
232         {
233                 if ($this->iconmenu == ""){
234                         $cfg= $this->config->data['MENU'];
236                         if (isset($this->config->current['ICONSIZE'])){
237                                 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
238                                 $isize= "width=\"$x\" height=\"$y\"";
239                         } else {
240                                 $isize= "";
241                         }
243                         /* Parse headlines */
244                         foreach ($cfg as $headline => $plug){
245                                 $col= 1;
246                                 $menu= "<h1 class=\"menuheader\">".
247                                         _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
248                                         "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
249                                 $entries= "";
251                                 foreach ($plug as $info){
253                                         /* Read information from class variable */
254                                         $vars= get_class_vars($info['CLASS']);
255                                         $plHeadline= $vars['plHeadline'];
256                                         $plDescription= $vars['plDescription'];
258                                         $index= $this->get_index($info['PATH'],$info['CLASS']);
260                                         $href = "main.php?plug=".$index."&amp;reset=1";
262                                         /* Check if class is available. If the class doesn't exists display error symbol 
263                                                 to avoid that a user clicks on a non existing plugin  */
264                                         if(!$vars){
265                                                 $plHeadline = $plDescription = _("Unknown");
266                                                 $info['ICON'] = "error.png";
267                                                 $href="main.php?reset=1";
268                                         }
271                                         #if ($this->check_access($info['ACL'])){
273                                                 /* Hm this looks doubled */
274                                                 $image= get_template_path('images/'.$info['ICON']);
275                                                 if ($col > 5){
276                                                         $entries= $entries."</tr><tr>";
277                                                         $col = 1;
278                                                 }
279                                                 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
280                                                         ">";
281                                                         if($_SESSION['js']){
282                                                                 $entries.= "<img $isize border=0 align=middle src=\"$image".
283                                                                         "\" alt=\"*\">&nbsp;".
284                                                                         _($plHeadline);
285                                                         } else {
286                                                                 $entries.= "<a class=\"iconmenu\" href=\"".$href."\">".
287                                                                         "<img $isize border=0 align=middle src=\"$image".
288                                                                         "\" alt=\"*\">&nbsp;".
289                                                                         _($plHeadline)."</a>";
290                                                         }
291                                                         $entries.= "</td>\n";
292                                                 $col++ ;
294                                         #}
295                                 }
297                                 /* Append to menu */
298                                 if ($entries != ""){
299                                         $this->iconmenu.= $menu.$entries;
301                                         /* Fill up remaining columns */
302                                         if ($col != 1){
303                                                 $col--;
304                                                 while ($col % 5){
305                                                         $this->iconmenu= $this->iconmenu.
306                                                                 "<td style=\"width:20%\">&nbsp;</td>\n";
307                                                         $col++;
308                                                 }
309                                         }
311                                         /* close table */
312                                         $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
313                                 }
314                         }
316                 }
318                 /* Write menu output */
319                 return ($this->iconmenu);
320         }
322         function get_path($index)
323         {
324                 if(!isset($this->dirlist[$index])){
325                         return ("");
326                 }
327                 return ("../".$this->dirlist[$index]);
328         }
330         function get_index($path,$class)
331         {
332                 /* Search for plugin index (id), identify entry by path && class */
333                 $data = $this->config->data['MENU'];
334                 foreach($data as $section => $plugins){
335                         foreach($plugins as $key => $plugin)    {
336                                 if($plugin['CLASS'] == $class && $plugin['PATH'] == $path){
337                                         return($key);
338                                 }
339                         }
340                 }
342                 /* Indentify by path*/
343                 return (array_search($path, $this->dirlist));
345         }
347 ?>