Code

Updated application locking
[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                         foreach($deps as $dep){
95                                 if(preg_match("/\//",$acl_to_check)){
96                                         if($this->ui->get_permissions($dep,$acl_to_check) != ""){
97                                                 return(TRUE);
98                                         }
99                                 }else{
100                                         if($this->ui->get_category_permissions($dep,$acl_to_check) != ""){
101                                                 return(TRUE);
102                                         }
103                                 }
104                         }
105                 }
106                 return (FALSE);
107         }
109         function gen_headlines()
110         {
111                 $ret = array();
112                 if(count($this->headlines) == 0){
113                         foreach($this->config->data['MENU'] as $headline => $plugins){
114                                 foreach( $plugins as $id => $plug){
115                                         if (plugin_available($plug['CLASS'])){
116                                                 $attrs = (get_class_vars($plug['CLASS']));
117                                                 $ret[$id]['HEADLINE'] = $headline;
118                                                 $ret[$id]['NAME']         = $attrs['plHeadline'];
119                                         }
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                                                 msg_dialog::display(
151                                                                 _("Configuration error"), 
152                                                                 _("The configuration format has changed. Please re-run setup!"), 
153                                                                 FATAL_ERROR_DIALOG);
154                                                 exit();
155                                         }
156                                         if (!plugin_available($info['CLASS'])){
157                                                 continue;
158                                         }
159                                         $vars= get_class_vars($info['CLASS']);
160                                         $plHeadline= $vars['plHeadline'];
161                                         $plDescription= $vars['plDescription'];
163                                         $index= $this->get_index($info['CLASS']);
164                                         $href= "main.php?plug=$index&amp;reset=1";
166                                         if(!$vars){
167                                                 $plHeadline     = _("Unknown");
168                                                 $plDescription  = _("Unknown");
169                                                 $href= "main.php?reset=1";
170                                         }
172                                         if ($this->check_access($info['ACL'])){
174                                                 $entries= $entries."<p class=\"menuitem\" ".
175                                                         "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>";
176                                                 if(session::get('js')){
177                                                         $entries.= _($plHeadline)."</p>\n";
178                                                 } else {
179                                                         $entries.= "<a class=\"menuitem\" ".
180                                                         "href=\"$href\">".
181                                                         _($plHeadline)."</a></p>\n";
182                                                 }
184                                                 if(!session::is_set('maxC')){
185                                                         session::set('maxC',"RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP");
186                                                 }
187                                         }
188                                 }
190                                 /* Append to menu */
191                                 if ($entries != ""){
192                                         $this->menu.= $menu.$entries;
193                                 }
194                         }
196                 }
198                 /* Write menu output */
199                 return ($this->menu);
200         }
202         function gen_current()
203         {
204                 /* Do we have a current value? */
205                 if ($this->current == ""){
206                         $tmp= array_keys($this->menuparts);
207                         $this->current= $tmp[0];
208                 }
210                 /* Fill current array */
211                 $result= "<table width=\"100%\" summary=\"\">";
212                 $count= 0;
213                 foreach ($this->menuparts[$this->current] as $entry){
214                         if ($count == 2){
215                                 $result.= "</tr>";
216                                 $count= 0;
217                         }
218                         if ($count == 0){
219                                 $result.= "<tr>";
220                         }
221                         $result.= "<td>$entry</td>";
222                         $count++;
223                 }
225                 /* Add missing cell? */
226                 if ($count == 1){
227                         $result.= "<td>&nbsp;</td>";
228                 }
230                 $result.= "</table>";
231                 return $result;
232         }
235         function show_iconmenu()
236         {
237                 global $class_mapping;
239                 if ($this->iconmenu == ""){
240                         $cfg= $this->config->data['MENU'];
242                         if (isset($this->config->current['ICONSIZE'])){
243                                 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
244                                 $isize= "width=\"$x\" height=\"$y\"";
245                         } else {
246                                 $isize= "";
247                         }
249                         /* Parse headlines */
250                         foreach ($cfg as $headline => $plug){
251                                 $col= 1;
252                                 $menu= "<h1 class=\"menuheader\">".
253                                         _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
254                                         "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
255                                 $entries= "";
257                                 foreach ($plug as $info){
259                                         if (!plugin_available($info['CLASS'])){
260                                                 continue;
261                                         }
263                                         /* Read information from class variable */
264                                         $vars= get_class_vars($info['CLASS']);
265                                         $plHeadline= $vars['plHeadline'];
266                                         $plDescription= $vars['plDescription'];
267           if (isset($vars['plIcon'])){
268                                         $plIcon= $vars['plIcon'];
269           } else {
270                                         $plIcon= "plugin.png";
271           }
273                                         $index= $this->get_index($info['CLASS']);
275                                         $href = "main.php?plug=".$index."&amp;reset=1";
277                                         /* Check if class is available. If the class doesn't exists display error symbol 
278                                                 to avoid that a user clicks on a non existing plugin  */
279                                         if(!$vars){
280                                                 $plHeadline = $plDescription = _("Unknown");
281                                                 $info['ICON'] = "error.png";
282                                                 $href="main.php?reset=1";
283                                         }
286                                         if ($this->check_access($info['ACL'])){
288                                                 /* Load icon */
289                                                 if (isset($info['ICON'])){
290                                                         $image= get_template_path('images/'.$info['ICON']);
291                                                 } else {
292                                                         $image= get_template_path("plugins/".preg_replace('%^.*/([^/]+)/[^/]+$%', '\1', $class_mapping[$info['CLASS']])."/images/$plIcon");
293                                                 }
294                                                 if ($col > 5){
295                                                         $entries= $entries."</tr><tr>";
296                                                         $col = 1;
297                                                 }
298                                                 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
299                                                         ">";
300                                                         if(session::get('js')){
301                                                                 $entries.= "<img $isize border=0 align=middle src=\"$image".
302                                                                         "\" alt=\"*\">&nbsp;".
303                                                                         _($plHeadline);
304                                                         } else {
305                                                                 $entries.= "<a class=\"iconmenu\" href=\"".$href."\">".
306                                                                         "<img $isize border=0 align=middle src=\"$image".
307                                                                         "\" alt=\"*\">&nbsp;".
308                                                                         _($plHeadline)."</a>";
309                                                         }
310                                                         $entries.= "</td>\n";
311                                                 $col++ ;
313                                         }
314                                 }
316                                 /* Append to menu */
317                                 if ($entries != ""){
318                                         $this->iconmenu.= $menu.$entries;
320                                         /* Fill up remaining columns */
321                                         if ($col != 1){
322                                                 $col--;
323                                                 while ($col % 5){
324                                                         $this->iconmenu= $this->iconmenu.
325                                                                 "<td style=\"width:20%\">&nbsp;</td>\n";
326                                                         $col++;
327                                                 }
328                                         }
330                                         /* close table */
331                                         $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
332                                 }
333                         }
335                 }
337                 /* Write menu output */
338                 return ($this->iconmenu);
339         }
341         function get_path($index)
342         {
343                 if(!isset($this->dirlist[$index])){
344                         return ("");
345                 }
346                 return ("../".$this->dirlist[$index]);
347         }
349         function get_index($class)
350         {
351                 /* Search for plugin index (id), identify entry by path && class */
352                 $data = $this->config->data['MENU'];
353                 foreach($data as $section => $plugins){
354                         foreach($plugins as $key => $plugin)    {
355                                 if($plugin['CLASS'] == $class){
356                                         return($key);
357                                 }
358                         }
359                 }
361                 /* Nothing */
362                 return (0);
364         }
366 ?>