Code

Updated gosa si DAK remove key ring entry.
[gosa.git] / gosa-core / include / class_pluglist.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class pluglist {
24         var $index= 0;
25         var $menu= "";
26         var $iconmenu= "";
27         var $menuparts= array();
28         var $config= NULL;
29         var $dirlist= array();
30         var $ui= NULL;
31         var $current= "";
32         var $info= array();
33         var $headlines = array();
35         function pluglist(&$config, &$ui)
36         {
37                 $this->ui= &$ui;
38                 $this->config= &$config;
40                 /* Create dirlist for all plugins */
41                 $this->dirlist= $this->get_plugins ($this->dirlist, $this->config->data['MENU']);
43                 /* Fill info part of pluglist */
44                 $classes= get_declared_classes();
46                                 foreach ($classes as $cname){
47                                         $cmethods = get_class_methods($cname);
48                                         if (in_array_ics('plInfo',$cmethods)){
49                                                 $this->info[$cname]= @call_user_func(array($cname, 'plInfo'));
50                                         }
51                                 }
53                 /* Provide field for 'all' */
54                 $this->info['all']= array();
55                 $this->info['all']['plProvidedAcls']= array();
56                 $this->info['all']['plDescription']= _("All objects in this category");
57                 $this->info['all']['plSelfModify']= FALSE;
58         }
60         function get_plugins($list, &$config)
61         {
62                 global $class_mapping;
64                 /* Error reporting, because I'm getting strange messages in PHP 4.2.x */
65                 if (!isset($config['CLASS'])){
66                         if (is_array($config)){
67                                 foreach ($config as $val){
68                                         $list= $this->get_plugins($list, $val);
69                                 }
70                         }
71                 } else {
72                         if (is_array($config) && isset($class_mapping[$config['CLASS']])){
73                                 $list[$this->index++]= dirname($class_mapping[$config['CLASS']]);
74                         } else {
75                                 $list[$this->index++]= "";
76                         }
77                 }
79                 return ($list);
80         }
83         function check_access($aclname)
84         {
85                 $acls_to_check = array();
86                 if(preg_match("/,/",$aclname)){
87                         $acls_to_check = split(",",$aclname);
88                 }else{
89                         $acls_to_check = array($aclname);
90                 }
92                 foreach($acls_to_check as $acl_to_check){
93                         $deps = $this->ui->get_module_departments($acl_to_check);
94                         if(count($deps)) return TRUE;
95                 }
96                 return (FALSE);
97         }
99         function gen_headlines()
100         {
101                 $ret = array();
102                 if(count($this->headlines) == 0){
103                         foreach($this->config->data['MENU'] as $headline => $plugins){
104                                 foreach( $plugins as $id => $plug){
105                                         if (plugin_available($plug['CLASS'])){
106                                                 $attrs = (get_class_vars($plug['CLASS']));
107                                                 $ret[$id]['HEADLINE'] = $headline;
108                                                 $ret[$id]['NAME']         = $attrs['plHeadline'];
109                                         }
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                                                 msg_dialog::display(
141                                                                 _("Configuration error"), 
142                                                                 _("The configuration format has changed. Please re-run setup!"), 
143                                                                 FATAL_ERROR_DIALOG);
144                                                 exit();
145                                         }
146                                         if (!plugin_available($info['CLASS'])){
147                                                 continue;
148                                         }
149                                         $vars= get_class_vars($info['CLASS']);
150                                         $plHeadline= $vars['plHeadline'];
151                                         $plDescription= $vars['plDescription'];
153                                         $index= $this->get_index($info['CLASS']);
154                                         $href= "main.php?plug=$index&amp;reset=1";
156                                         if(!$vars){
157                                                 $plHeadline     = _("Unknown");
158                                                 $plDescription  = _("Unknown");
159                                                 $href= "main.php?reset=1";
160                                         }
162                                         if ($this->check_access($info['ACL'])){
164                                                 $entries= $entries."<p class=\"menuitem\" ".
165                                                         "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>";
166                                                 if(session::get('js')){
167                                                         $entries.= _($plHeadline)."</p>\n";
168                                                 } else {
169                                                         $entries.= "<a class=\"menuitem\" ".
170                                                         "href=\"$href\">".
171                                                         _($plHeadline)."</a></p>\n";
172                                                 }
174                                                 if(!session::is_set('maxC')){
175                                                         session::set('maxC',"RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP");
176                                                 }
177                                         }
178                                 }
180                                 /* Append to menu */
181                                 if ($entries != ""){
182                                         $this->menu.= $menu.$entries;
183                                 }
184                         }
186                 }
188                 /* Write menu output */
189                 return ($this->menu);
190         }
192         function gen_current()
193         {
194                 /* Do we have a current value? */
195                 if ($this->current == ""){
196                         $tmp= array_keys($this->menuparts);
197                         $this->current= $tmp[0];
198                 }
200                 /* Fill current array */
201                 $result= "<table width=\"100%\" summary=\"\">";
202                 $count= 0;
203                 foreach ($this->menuparts[$this->current] as $entry){
204                         if ($count == 2){
205                                 $result.= "</tr>";
206                                 $count= 0;
207                         }
208                         if ($count == 0){
209                                 $result.= "<tr>";
210                         }
211                         $result.= "<td>$entry</td>";
212                         $count++;
213                 }
215                 /* Add missing cell? */
216                 if ($count == 1){
217                         $result.= "<td>&nbsp;</td>";
218                 }
220                 $result.= "</table>";
221                 return $result;
222         }
225         function show_iconmenu()
226         {
227                 global $class_mapping;
229                 if ($this->iconmenu == ""){
230                         $cfg= $this->config->data['MENU'];
232                         if (isset($this->config->current['ICONSIZE'])){
233                                 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
234                                 $isize= "width=\"$x\" height=\"$y\"";
235                         } else {
236                                 $isize= "";
237                         }
239                         /* Parse headlines */
240                         foreach ($cfg as $headline => $plug){
241                                 $col= 1;
242                                 $menu= "<h1 class=\"menuheader\">".
243                                         _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
244                                         "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
245                                 $entries= "";
247                                 foreach ($plug as $info){
249                                         if (!plugin_available($info['CLASS'])){
250                                                 continue;
251                                         }
253                                         /* Read information from class variable */
254                                         $vars= get_class_vars($info['CLASS']);
255                                         $plHeadline= $vars['plHeadline'];
256                                         $plDescription= $vars['plDescription'];
257           if (isset($vars['plIcon'])){
258                                         $plIcon= $vars['plIcon'];
259           } else {
260                                         $plIcon= "plugin.png";
261           }
263                                         $index= $this->get_index($info['CLASS']);
265                                         $href = "main.php?plug=".$index."&amp;reset=1";
267                                         /* Check if class is available. If the class doesn't exists display error symbol 
268                                                 to avoid that a user clicks on a non existing plugin  */
269                                         if(!$vars){
270                                                 $plHeadline = $plDescription = _("Unknown");
271                                                 $info['ICON'] = "error.png";
272                                                 $href="main.php?reset=1";
273                                         }
276                                         if ($this->check_access($info['ACL'])){
278                                                 /* Load icon */
279                                                 if (isset($info['ICON'])){
280                                                         $image= get_template_path('images/'.$info['ICON']);
281                                                 } else {
282                                                         $image= get_template_path("plugins/".preg_replace('%^.*/([^/]+)/[^/]+$%', '\1', $class_mapping[$info['CLASS']])."/images/$plIcon");
283                                                 }
284                                                 if ($col > 5){
285                                                         $entries= $entries."</tr><tr>";
286                                                         $col = 1;
287                                                 }
288                                                 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
289                                                         ">";
290                                                         if(session::get('js')){
291                                                                 $entries.= "<img $isize border=0 align=middle src=\"$image".
292                                                                         "\" alt=\"*\">&nbsp;".
293                                                                         _($plHeadline);
294                                                         } else {
295                                                                 $entries.= "<a class=\"iconmenu\" href=\"".$href."\">".
296                                                                         "<img $isize border=0 align=middle src=\"$image".
297                                                                         "\" alt=\"*\">&nbsp;".
298                                                                         _($plHeadline)."</a>";
299                                                         }
300                                                         $entries.= "</td>\n";
301                                                 $col++ ;
303                                         }
304                                 }
306                                 /* Append to menu */
307                                 if ($entries != ""){
308                                         $this->iconmenu.= $menu.$entries;
310                                         /* Fill up remaining columns */
311                                         if ($col != 1){
312                                                 $col--;
313                                                 while ($col % 5){
314                                                         $this->iconmenu= $this->iconmenu.
315                                                                 "<td style=\"width:20%\">&nbsp;</td>\n";
316                                                         $col++;
317                                                 }
318                                         }
320                                         /* close table */
321                                         $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
322                                 }
323                         }
325                 }
327                 /* Write menu output */
328                 return ($this->iconmenu);
329         }
331         function get_path($index)
332         {
333                 if(!isset($this->dirlist[$index])){
334                         return ("");
335                 }
336                 return ("../".$this->dirlist[$index]);
337         }
339         function get_index($class)
340         {
341                 /* Search for plugin index (id), identify entry by path && class */
342                 $data = $this->config->data['MENU'];
343                 foreach($data as $section => $plugins){
344                         foreach($plugins as $key => $plugin)    {
345                                 if($plugin['CLASS'] == $class){
346                                         return($key);
347                                 }
348                         }
349                 }
351                 /* Nothing */
352                 return (0);
354         }
356 ?>