Code

Updated gosaServerDeamon
[gosa.git] / gosa-core / 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                                         if (plugin_available($plug['CLASS'])){
118                                                 $attrs = (get_class_vars($plug['CLASS']));
119                                                 $ret[$id]['HEADLINE'] = $headline;
120                                                 $ret[$id]['NAME']         = $attrs['plHeadline'];
121                                         }
122                                 }
123                         }
124                         $this->headlines = $ret;
125                 }
126                 return($this->headlines);
127         }
129         function gen_menu()
130         {
131                 if ($this->menu == ""){
132                         $first= TRUE;
133                         $cfg= $this->config->data['MENU'];
135                         /* Parse headlines */
136                         foreach ($cfg as $headline => $plug){
137                                 if ($first){
138                                         $style= "";
139                                         $first= FALSE;
140                                 } else {
141                                         $style= "style='border-top:1px solid #AAA; margin-top:0.8em;'";
142                                 }
143                                 $menu= "<p class=\"menuheader\" $style>"._($headline)."</p>\n";
144                                 $entries= "";
145                                 $this->menuparts[_($headline)]= array();
147                                 /* Parse sub-plugins */
148                                 foreach ($plug as $info){
150                                         /* Read information from class variable */
151                                         if (!isset($info['CLASS'])){
152                                                 msg_dialog::display(_("Configuration error"), _("The configuration format has changed. Please re-run setup!"), ERROR_DIALOG);
153                                                 display_error_page();
154                                         }
155                                         if (!plugin_available($info['CLASS'])){
156                                                 continue;
157                                         }
158                                         $vars= get_class_vars($info['CLASS']);
159                                         $plHeadline= $vars['plHeadline'];
160                                         $plDescription= $vars['plDescription'];
163                                         $index= $this->get_index($info['PATH'],$info['CLASS']);
164                                         $image= get_template_path('images/'.$info['ICON']);
165                                         $href= "main.php?plug=$index&amp;reset=1";
167                                         if(!$vars){
168                                                 $plHeadline     = _("Unknown");
169                                                 $plDescription  = _("Unknown");
170                                                 $href= "main.php?reset=1";
171                                         }
173                                         if ($this->check_access($info['ACL'])){
175                                                 $entries= $entries."<p class=\"menuitem\" ".
176                                                         "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>";
177                                                 if(session::get('js')){
178                                                         $entries.= _($plHeadline)."</p>\n";
179                                                 } else {
180                                                         $entries.= "<a class=\"menuitem\" ".
181                                                         "href=\"$href\">".
182                                                         _($plHeadline)."</a></p>\n";
183                                                 }
185                                                 /* Generate icon entry with description */
186                                                 $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;">';
187                                                 if(session::get('js')){
188                                                         $current.= '<b>'._($plHeadline).'</b><br>'._($plDescription);
189                                                 } else {
190                                                         $current.= '<a href="'.$href.'"><b>'._($plHeadline).'</b></a><br><a href="'.$href.'">'._($plDescription).'</a>';
191                                                 }
192                                                 $current.= '</td></tr></table>';
193                                                 $this->menuparts[_($headline)][]= $current;
194                                                 if(!session::is_set('maxC')){
195                                                         session::set('maxC',"RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP");
196                                                 }
197                                         }
198                                 }
200                                 /* Append to menu */
201                                 if ($entries != ""){
202                                         $this->menu.= $menu.$entries;
203                                 }
204                         }
206                 }
208                 /* Write menu output */
209                 return ($this->menu);
210         }
212         function gen_current()
213         {
214                 /* Do we have a current value? */
215                 if ($this->current == ""){
216                         $tmp= array_keys($this->menuparts);
217                         $this->current= $tmp[0];
218                 }
220                 /* Fill current array */
221                 $result= "<table width=\"100%\" summary=\"\">";
222                 $count= 0;
223                 foreach ($this->menuparts[$this->current] as $entry){
224                         if ($count == 2){
225                                 $result.= "</tr>";
226                                 $count= 0;
227                         }
228                         if ($count == 0){
229                                 $result.= "<tr>";
230                         }
231                         $result.= "<td>$entry</td>";
232                         $count++;
233                 }
235                 /* Add missing cell? */
236                 if ($count == 1){
237                         $result.= "<td>&nbsp;</td>";
238                 }
240                 $result.= "</table>";
241                 return $result;
242         }
245         function show_iconmenu()
246         {
247                 if ($this->iconmenu == ""){
248                         $cfg= $this->config->data['MENU'];
250                         if (isset($this->config->current['ICONSIZE'])){
251                                 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
252                                 $isize= "width=\"$x\" height=\"$y\"";
253                         } else {
254                                 $isize= "";
255                         }
257                         /* Parse headlines */
258                         foreach ($cfg as $headline => $plug){
259                                 $col= 1;
260                                 $menu= "<h1 class=\"menuheader\">".
261                                         _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
262                                         "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
263                                 $entries= "";
265                                 foreach ($plug as $info){
267                                         if (!plugin_available($info['CLASS'])){
268                                                 continue;
269                                         }
271                                         /* Read information from class variable */
272                                         $vars= get_class_vars($info['CLASS']);
273                                         $plHeadline= $vars['plHeadline'];
274                                         $plDescription= $vars['plDescription'];
276                                         $index= $this->get_index($info['PATH'],$info['CLASS']);
278                                         $href = "main.php?plug=".$index."&amp;reset=1";
280                                         /* Check if class is available. If the class doesn't exists display error symbol 
281                                                 to avoid that a user clicks on a non existing plugin  */
282                                         if(!$vars){
283                                                 $plHeadline = $plDescription = _("Unknown");
284                                                 $info['ICON'] = "error.png";
285                                                 $href="main.php?reset=1";
286                                         }
289                                         if ($this->check_access($info['ACL'])){
291                                                 /* Hm this looks doubled */
292                                                 $image= get_template_path('images/'.$info['ICON']);
293                                                 if ($col > 5){
294                                                         $entries= $entries."</tr><tr>";
295                                                         $col = 1;
296                                                 }
297                                                 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
298                                                         ">";
299                                                         if(session::get('js')){
300                                                                 $entries.= "<img $isize border=0 align=middle src=\"$image".
301                                                                         "\" alt=\"*\">&nbsp;".
302                                                                         _($plHeadline);
303                                                         } else {
304                                                                 $entries.= "<a class=\"iconmenu\" href=\"".$href."\">".
305                                                                         "<img $isize border=0 align=middle src=\"$image".
306                                                                         "\" alt=\"*\">&nbsp;".
307                                                                         _($plHeadline)."</a>";
308                                                         }
309                                                         $entries.= "</td>\n";
310                                                 $col++ ;
312                                         }
313                                 }
315                                 /* Append to menu */
316                                 if ($entries != ""){
317                                         $this->iconmenu.= $menu.$entries;
319                                         /* Fill up remaining columns */
320                                         if ($col != 1){
321                                                 $col--;
322                                                 while ($col % 5){
323                                                         $this->iconmenu= $this->iconmenu.
324                                                                 "<td style=\"width:20%\">&nbsp;</td>\n";
325                                                         $col++;
326                                                 }
327                                         }
329                                         /* close table */
330                                         $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
331                                 }
332                         }
334                 }
336                 /* Write menu output */
337                 return ($this->iconmenu);
338         }
340         function get_path($index)
341         {
342                 if(!isset($this->dirlist[$index])){
343                         return ("");
344                 }
345                 return ("../".$this->dirlist[$index]);
346         }
348         function get_index($path,$class)
349         {
350                 /* Search for plugin index (id), identify entry by path && class */
351                 $data = $this->config->data['MENU'];
352                 foreach($data as $section => $plugins){
353                         foreach($plugins as $key => $plugin)    {
354                                 if($plugin['CLASS'] == $class && $plugin['PATH'] == $path){
355                                         return($key);
356                                 }
357                         }
358                 }
360                 /* Indentify by path*/
361                 return (array_search($path, $this->dirlist));
363         }
365 ?>