Code

Updated function.inc
[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 $headlines = array();
32         var $allowed_plug_ids =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);
41         }
43         function get_plugins($list, $config)
44         {
45                 /* Error reporting, because I'm getting strange messages in PHP 4.2.x */
46                 error_reporting(0);
47                 if (!isset($config['PATH']) && !isset($config['CLASS'])){
48                         if (is_array($config)){
49                                 foreach ($config as $val){
50                                         $list= $this->get_plugins($list, $val);
51                                 }
52                         }
53                 } else {
54                         if (isset ($config['PATH']) && is_array($config)){
55                                 $list[$this->index++]= $config['PATH'];
56                         }
57                 }
58                 error_reporting(E_ALL);
60                 return ($list);
61         }
63         function check_access($modname)
64         {
65                 /* This plugin is readable for everyone, return true */
66                 if ($modname == 'default'){
67                         return (TRUE);
68                 }
70                 /* Look through ACL's */
71                 foreach($this->ui->subtreeACL as $arr){
72                         foreach($arr as $value){
73                                 if ($value == ':all' || preg_match("/[,:]".normalizePreg($modname)."#/", $value)){
74                                         if (!preg_match('/^!/', $value)){
75                                                 return (TRUE);
76                                         }
77                                 }
78                         }
79                 }
81                 return (FALSE);
82         }
84         function gen_headlines()
85         {
86                 $ret = array();
87                 if(count($this->headlines) == 0){
88                         foreach($this->config->data['MENU'] as $headline => $plugins){
89                                 foreach( $plugins as $id => $plug){
90                                         $attrs = (get_class_vars($plug['CLASS']));
91                                         $ret[$id]['HEADLINE'] = $headline;
92                                         $ret[$id]['NAME']         = $attrs['plHeadline'];       
93                                 }
94                         }
95                         $this->headlines = $ret;
96                 }
97                 return($this->headlines);
98         }
100         function gen_menu()
101         {
102                 if ($this->menu == ""){
103                         $cfg= $this->config->data['MENU'];
105                         /* Parse headlines */
106                         foreach ($cfg as $headline => $plug){
107                                 $menu= "<p class=\"menuheader\">"._($headline)."</p>\n";
108                                 $entries= "";
109                                 $this->menuparts[_($headline)]= array();
111                                 /* Parse sub-plugins */
112                                 foreach ($plug as $info){
114                                         /* Read information from class variable */
115                                         if (!isset($info['CLASS'])){
116                                                 print_red(sprintf(_("Your %s information has changed partly. Please convert it using the contributed script fix_config.sh!"),CONFIG_FILE));
117                                                 echo $_SESSION['errors'];
118                                                 exit;
119                                         }
120                                         $vars= get_class_vars($info['CLASS']);
121                                         $plHeadline= $vars['plHeadline'];
122                                         $plDescription= $vars['plDescription'];
125                                         $index= $this->get_index($info['PATH'],$info['CLASS']);
126                                         $image= get_template_path('images/'.$info['ICON']);
127                                         $href= "main.php?plug=$index&amp;reset=1";
129                                         if(!$vars){
130                                                 $plHeadline     = _("Unknown");
131                                                 $plDescription  = _("Unknown");
132                                                 $href= "main.php?reset=1";
133                                         }
135                                         if ($this->check_access($info['ACL'])){
136                                                 $this->allowed_plug_ids[$index]=$index;
137                                                 $entries= $entries."<p class=\"menuitem\" ".
138                                                         "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>";
139                                                 if($_SESSION['js']){
140                                                         $entries.= _($plHeadline)."</p>\n";
141                                                 } else {
142                                                         $entries.= "<a class=\"menuitem\" ".
143                                                         "href=\"$href\">".
144                                                         _($plHeadline)."</a></p>\n";
145                                                 }
147                                                 /* Generate icon entry with description */
148                                                 $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;">';
149                                                 if($_SESSION['js']){
150                                                         $current.= '<b>'._($plHeadline).'</b><br>'._($plDescription);
151                                                 } else {
152                                                         $current.= '<a href="'.$href.'"><b>'._($plHeadline).'</b></a><br><a href="'.$href.'">'._($plDescription).'</a>';
153                                                 }
154                                                 $current.= '</td></tr></table>';
155                                                 $this->menuparts[_($headline)][]= $current;
156                                                 if(!isset($_SESSION['maxC'])){
157                                                         $_SESSION['maxC'] = "RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP";
158                                                 }
159                                         }
160                                 }
162                                 /* Append to menu */
163                                 if ($entries != ""){
164                                         $this->menu.= $menu.$entries;
165                                 }
166                         }
168                 }
170                 /* Write menu output */
171                 return ($this->menu);
172         }
174         function gen_current()
175         {
176                 /* Do we have a current value? */
177                 if ($this->current == ""){
178                         $tmp= array_keys($this->menuparts);
179                         $this->current= $tmp[0];
180                 }
182                 /* Fill current array */
183                 $result= "<table width=\"100%\" summary=\"\">";
184                 $count= 0;
185                 foreach ($this->menuparts[$this->current] as $entry){
186                         if ($count == 2){
187                                 $result.= "</tr>";
188                                 $count= 0;
189                         }
190                         if ($count == 0){
191                                 $result.= "<tr>";
192                         }
193                         $result.= "<td>$entry</td>";
194                         $count++;
195                 }
197                 /* Add missing cell? */
198                 if ($count == 1){
199                         $result.= "<td>&nbsp;</td>";
200                 }
202                 $result.= "</table>";
203                 return $result;
204         }
207         function show_iconmenu()
208         {
209                 if ($this->iconmenu == ""){
210                         $cfg= $this->config->data['MENU'];
212                         if (isset($this->config->current['ICONSIZE'])){
213                                 list($x, $y)= split("x", $this->config->current['ICONSIZE']);
214                                 $isize= "width=\"$x\" height=\"$y\"";
215                         } else {
216                                 $isize= "";
217                         }
219                         /* Parse headlines */
220                         foreach ($cfg as $headline => $plug){
221                                 $col= 1;
222                                 $menu= "<h1 class=\"menuheader\">".
223                                         _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
224                                         "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
225                                 $entries= "";
227                                 foreach ($plug as $info){
229                                         /* Read information from class variable */
230                                         $vars= get_class_vars($info['CLASS']);
231                                         $plHeadline= $vars['plHeadline'];
232                                         $plDescription= $vars['plDescription'];
234                                         $index= $this->get_index($info['PATH'],$info['CLASS']);
236                                         $href = "main.php?plug=".$index."&amp;reset=1";
238                                         /* Check if class is available. If the class doesn't exists display error symbol 
239                                                 to avoid that a user clicks on a non existing plugin  */
240                                         if(!$vars){
241                                                 $plHeadline = $plDescription = _("Unknown");
242                                                 $info['ICON'] = "error.png";
243                                                 $href="main.php?reset=1";
244                                         }
247                                         if ($this->check_access($info['ACL'])){
249                                                 /* Hm this looks doubled */
250                                                 $image= get_template_path('images/'.$info['ICON']);
251                                                 if ($col > 5){
252                                                         $entries= $entries."</tr><tr>";
253                                                         $col = 1;
254                                                 }
255                                                 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
256                                                         ">";
257                                                         if($_SESSION['js']){
258                                                                 $entries.= "<img $isize border=0 align=middle src=\"$image".
259                                                                         "\" alt=\"*\">&nbsp;".
260                                                                         _($plHeadline);
261                                                         } else {
262                                                                 $entries.= "<a class=\"iconmenu\" href=\"".$href."\">".
263                                                                         "<img $isize border=0 align=middle src=\"$image".
264                                                                         "\" alt=\"*\">&nbsp;".
265                                                                         _($plHeadline)."</a>";
266                                                         }
267                                                         $entries.= "</td>\n";
268                                                 $col++ ;
270                                         }
271                                 }
273                                 /* Append to menu */
274                                 if ($entries != ""){
275                                         $this->iconmenu.= $menu.$entries;
277                                         /* Fill up remaining columns */
278                                         if ($col != 1){
279                                                 $col--;
280                                                 while ($col % 5){
281                                                         $this->iconmenu= $this->iconmenu.
282                                                                 "<td style=\"width:20%\">&nbsp;</td>\n";
283                                                         $col++;
284                                                 }
285                                         }
287                                         /* close table */
288                                         $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
289                                 }
290                         }
292                 }
294                 /* Write menu output */
295                 return ($this->iconmenu);
296         }
298         function get_path($index)
299         {
300                 if(!isset($this->dirlist[$index])){
301                         return ("");
302                 }
303                 return ("../".$this->dirlist[$index]);
304         }
306         function get_index($path,$class)
307         {
308                 /* Search for plugin index (id), identify entry by path && class */
309                 $data = $this->config->data['MENU'];
310                 foreach($data as $section => $plugins){
311                         foreach($plugins as $key => $plugin)    {
312                                 if($plugin['CLASS'] == $class && $plugin['PATH'] == $path){
313                                         return($key);
314                                 }
315                         }
316                 }
318                 /* Indentify by path*/
319                 return (array_search($path, $this->dirlist));
321         }
323 ?>