Code

Moved events into an extra file.
[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($aclname)
81         {
82                 $deps= $this->ui->get_module_departments($aclname);
84                 $acls_to_check = array();
85                 if(preg_match("/,/",$aclname)){
86                         $acls_to_check = split(",",$aclname);
87                 }else{
88                         $acls_to_check = array($aclname);
89                 }
90         
91                 if(preg_match("/\//",$aclname)){
92                         foreach($deps as $dep){
93                                 foreach($acls_to_check as $acl_to_check){
94                                         if($this->ui->get_permissions($dep,$acl_to_check) != ""){
95                                                 return(TRUE);
96                                         }
97                                 }
98                         }
99                 }else{
100                         foreach($deps as $dep){
101                                 foreach($acls_to_check as $acl_to_check){
102                                         if($this->ui->get_category_permissions($dep,$acl_to_check) != ""){
103                                                 return(TRUE);
104                                         }
105                                 }
106                         }
107                 }
108                 return (FALSE);
109         }
111         function gen_headlines()
112         {
113                 $ret = array();
114                 if(count($this->headlines) == 0){
115                         foreach($this->config->data['MENU'] as $headline => $plugins){
116                                 foreach( $plugins as $id => $plug){
117                                         $attrs = (get_class_vars($plug['CLASS']));
118                                         $ret[$id]['HEADLINE'] = $headline;
119                                         $ret[$id]['NAME']         = $attrs['plHeadline'];       
120                                 }
121                         }
122                         $this->headlines = $ret;
123                 }
124                 return($this->headlines);
125         }
127         function gen_menu()
128         {
129                 if ($this->menu == ""){
130                         $first= TRUE;
131                         $cfg= $this->config->data['MENU'];
133                         /* Parse headlines */
134                         foreach ($cfg as $headline => $plug){
135                                 if ($first){
136                                         $style= "";
137                                         $first= FALSE;
138                                 } else {
139                                         $style= "style='border-top:1px solid #AAA; margin-top:0.8em;'";
140                                 }
141                                 $menu= "<p class=\"menuheader\" $style>"._($headline)."</p>\n";
142                                 $entries= "";
143                                 $this->menuparts[_($headline)]= array();
145                                 /* Parse sub-plugins */
146                                 foreach ($plug as $info){
148                                         /* Read information from class variable */
149                                         if (!isset($info['CLASS'])){
150                                                 print_red(_("Your gosa.conf information has changed partly. Please convert it using the contributed script fix_config.sh!"));
151                                                 echo $_SESSION['errors'];
152                                                 exit;
153                                         }
154                                         $vars= get_class_vars($info['CLASS']);
155                                         $plHeadline= $vars['plHeadline'];
156                                         $plDescription= $vars['plDescription'];
159                                         $index= $this->get_index($info['PATH'],$info['CLASS']);
160                                         $image= get_template_path('images/'.$info['ICON']);
161                                         $href= "main.php?plug=$index&amp;reset=1";
163                                         if(!$vars){
164                                                 $plHeadline     = _("Unknown");
165                                                 $plDescription  = _("Unknown");
166                                                 $href= "main.php?reset=1";
167                                         }
169                                         if ($this->check_access($info['ACL'])){
171                                                 $entries= $entries."<p class=\"menuitem\" ".
172                                                         "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>";
173                                                 if($_SESSION['js']){
174                                                         $entries.= _($plHeadline)."</p>\n";
175                                                 } else {
176                                                         $entries.= "<a class=\"menuitem\" ".
177                                                         "href=\"$href\">".
178                                                         _($plHeadline)."</a></p>\n";
179                                                 }
181                                                 /* Generate icon entry with description */
182                                                 $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;">';
183                                                 if($_SESSION['js']){
184                                                         $current.= '<b>'._($plHeadline).'</b><br>'._($plDescription);
185                                                 } else {
186                                                         $current.= '<a href="'.$href.'"><b>'._($plHeadline).'</b></a><br><a href="'.$href.'">'._($plDescription).'</a>';
187                                                 }
188                                                 $current.= '</td></tr></table>';
189                                                 $this->menuparts[_($headline)][]= $current;
190                                                 if(!isset($_SESSION['maxC'])){
191                                                         $_SESSION['maxC'] = "RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP";
192                                                 }
193                                         }
194                                 }
196                                 /* Append to menu */
197                                 if ($entries != ""){
198                                         $this->menu.= $menu.$entries;
199                                 }
200                         }
202                 }
204                 /* Write menu output */
205                 return ($this->menu);
206         }
208         function gen_current()
209         {
210                 /* Do we have a current value? */
211                 if ($this->current == ""){
212                         $tmp= array_keys($this->menuparts);
213                         $this->current= $tmp[0];
214                 }
216                 /* Fill current array */
217                 $result= "<table width=\"100%\" summary=\"\">";
218                 $count= 0;
219                 foreach ($this->menuparts[$this->current] as $entry){
220                         if ($count == 2){
221                                 $result.= "</tr>";
222                                 $count= 0;
223                         }
224                         if ($count == 0){
225                                 $result.= "<tr>";
226                         }
227                         $result.= "<td>$entry</td>";
228                         $count++;
229                 }
231                 /* Add missing cell? */
232                 if ($count == 1){
233                         $result.= "<td>&nbsp;</td>";
234                 }
236                 $result.= "</table>";
237                 return $result;
238         }
241         function show_iconmenu()
242         {
243                 if ($this->iconmenu == ""){
244                         $cfg= $this->config->data['MENU'];
246                         if (isset($this->config->current['ICONSIZE'])){
247                                 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
248                                 $isize= "width=\"$x\" height=\"$y\"";
249                         } else {
250                                 $isize= "";
251                         }
253                         /* Parse headlines */
254                         foreach ($cfg as $headline => $plug){
255                                 $col= 1;
256                                 $menu= "<h1 class=\"menuheader\">".
257                                         _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
258                                         "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
259                                 $entries= "";
261                                 foreach ($plug as $info){
263                                         /* Read information from class variable */
264                                         $vars= get_class_vars($info['CLASS']);
265                                         $plHeadline= $vars['plHeadline'];
266                                         $plDescription= $vars['plDescription'];
268                                         $index= $this->get_index($info['PATH'],$info['CLASS']);
270                                         $href = "main.php?plug=".$index."&amp;reset=1";
272                                         /* Check if class is available. If the class doesn't exists display error symbol 
273                                                 to avoid that a user clicks on a non existing plugin  */
274                                         if(!$vars){
275                                                 $plHeadline = $plDescription = _("Unknown");
276                                                 $info['ICON'] = "error.png";
277                                                 $href="main.php?reset=1";
278                                         }
281                                         if ($this->check_access($info['ACL'])){
283                                                 /* Hm this looks doubled */
284                                                 $image= get_template_path('images/'.$info['ICON']);
285                                                 if ($col > 5){
286                                                         $entries= $entries."</tr><tr>";
287                                                         $col = 1;
288                                                 }
289                                                 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
290                                                         ">";
291                                                         if($_SESSION['js']){
292                                                                 $entries.= "<img $isize border=0 align=middle src=\"$image".
293                                                                         "\" alt=\"*\">&nbsp;".
294                                                                         _($plHeadline);
295                                                         } else {
296                                                                 $entries.= "<a class=\"iconmenu\" href=\"".$href."\">".
297                                                                         "<img $isize border=0 align=middle src=\"$image".
298                                                                         "\" alt=\"*\">&nbsp;".
299                                                                         _($plHeadline)."</a>";
300                                                         }
301                                                         $entries.= "</td>\n";
302                                                 $col++ ;
304                                         }
305                                 }
307                                 /* Append to menu */
308                                 if ($entries != ""){
309                                         $this->iconmenu.= $menu.$entries;
311                                         /* Fill up remaining columns */
312                                         if ($col != 1){
313                                                 $col--;
314                                                 while ($col % 5){
315                                                         $this->iconmenu= $this->iconmenu.
316                                                                 "<td style=\"width:20%\">&nbsp;</td>\n";
317                                                         $col++;
318                                                 }
319                                         }
321                                         /* close table */
322                                         $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
323                                 }
324                         }
326                 }
328                 /* Write menu output */
329                 return ($this->iconmenu);
330         }
332         function get_path($index)
333         {
334                 if(!isset($this->dirlist[$index])){
335                         return ("");
336                 }
337                 return ("../".$this->dirlist[$index]);
338         }
340         function get_index($path,$class)
341         {
342                 /* Search for plugin index (id), identify entry by path && class */
343                 $data = $this->config->data['MENU'];
344                 foreach($data as $section => $plugins){
345                         foreach($plugins as $key => $plugin)    {
346                                 if($plugin['CLASS'] == $class && $plugin['PATH'] == $path){
347                                         return($key);
348                                 }
349                         }
350                 }
352                 /* Indentify by path*/
353                 return (array_search($path, $this->dirlist));
355         }
357 ?>