Code

Added function to passwordMethod, create_template_hash()
[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();
34   var $allowed_plugins = array();
35   var $silly_cache= array();
37         function pluglist(&$config, &$ui)
38         {
39                 $this->ui= &$ui;
40                 $this->config= &$config;
42                 /* Create dirlist for all plugins */
43                 $this->dirlist= $this->get_plugins ($this->dirlist, $this->config->data['MENU']);
45                 /* Fill info part of pluglist */
46                 $classes= get_declared_classes();
48                                 foreach ($classes as $cname){
49                                         $cmethods = get_class_methods($cname);
50                                         if (in_array_ics('plInfo',$cmethods)){
51                                                 $this->info[$cname]= call_user_func(array($cname, 'plInfo'));
52                                         }
53                                 }
55                 /* Provide field for 'all' */
56                 $this->info['all']= array();
57                 $this->info['all']['plProvidedAcls']= array();
58                 $this->info['all']['plDescription']= _("All objects in this category");
59                 $this->info['all']['plSelfModify']= FALSE;
60         }
62         function get_plugins($list, &$config)
63         {
64                 global $class_mapping;
66                 /* Error reporting, because I'm getting strange messages in PHP 4.2.x */
67                 if (!isset($config['CLASS'])){
68                         if (is_array($config)){
69                                 foreach ($config as $val){
70                                         $list= $this->get_plugins($list, $val);
71                                 }
72                         }
73                 } else {
74                         if (is_array($config) && isset($class_mapping[$config['CLASS']])){
75                                 $list[$this->index++]= dirname($class_mapping[$config['CLASS']]);
76                         } else {
77                                 $list[$this->index++]= "";
78                         }
79                 }
81                 return ($list);
82         }
85         /*! \brief  Check whether we are allowed to modify the given acl or not..
86                                 This function is used to check which plugins are visible.
87                                 
88                 @param  The acl tag to test, eg.        "users/user:self", "systems", ...
89                 @return Boolean TRUE on success else FALSE
90      */
91         function check_access($aclname)
92         {
93                 if (isset($this->silly_cache[$aclname])) {
94                         return $this->silly_cache[$aclname];
95                 }
97                 /* Split given acl string into an array. 
98                         e.g. "user,systems" => array("users","systems");
99          */
100                 $acls_to_check = array();
101                 if(preg_match("/,/",$aclname)){
102                         $acls_to_check = split(",",$aclname);
103                 }else{
104                         $acls_to_check = array($aclname);
105                 }
107                 foreach($acls_to_check as $acl_to_check){
108       $acl_to_check = trim($acl_to_check);
109                 
110                         /* Check if the given acl tag is only valid for self acl entries  
111                  <plugin acl="users/user:self" class="user"...
112              */ 
113                         if(preg_match("/:self$/",$acl_to_check)){
114                                 $acl_to_check = preg_replace("/:self$/","",$acl_to_check);      
115                                 if($this->ui->get_permissions($this->ui->dn,$acl_to_check,"") != ""){
116                                         $this->silly_cache[$aclname]= TRUE;
117                                         return(TRUE);
118                                 }
119                                 $this->silly_cache[$aclname]= FALSE;
120                                 return(FALSE);
121                         }else{
122                 
123                                 /* No self acls. Check if we have any acls for the given ACL type 
124                  */
125                                 $deps = $this->ui->get_module_departments($acl_to_check,TRUE);
126                                 if(count($deps)){
127                                         $this->silly_cache[$aclname]= TRUE;
128                                         return TRUE;
129                                 }
130                         }
131                 }
133                 $this->silly_cache[$aclname]= FALSE;
134                 return (FALSE);
135         }
138         function gen_headlines()
139         {
140                 $ret = array();
141                 if(count($this->headlines) == 0){
142                         foreach($this->config->data['MENU'] as $headline => $plugins){
143                                 foreach( $plugins as $id => $plug){
144                                         if (plugin_available($plug['CLASS'])){
145                                                 $attrs = (get_class_vars($plug['CLASS']));
146                                                 $ret[$id]['HEADLINE'] = $headline;
147                                                 $ret[$id]['NAME']         = $attrs['plHeadline'];
148                                         }
149                                 }
150                         }
151                         $this->headlines = $ret;
152                 }
153                 return($this->headlines);
154         }
156         function gen_menu()
157         {
158                 if ($this->menu == ""){
159                         $first= TRUE;
160                         $cfg= $this->config->data['MENU'];
162                         /* Parse headlines */
163                         foreach ($cfg as $headline => $plug){
164                                 if ($first){
165                                         $style= "";
166                                         $first= FALSE;
167                                 } else {
168                                         $style= "style='border-top:1px solid #AAA; margin-top:0.8em;'";
169                                 }
170                                 $menu= "<p class=\"menuheader\" $style>"._($headline)."</p>\n";
171                                 $entries= "";
172                                 $this->menuparts[_($headline)]= array();
174                                 /* Parse sub-plugins */
175                                 foreach ($plug as $info){
177                                         /* Read information from class variable */
178                                         if (!isset($info['CLASS'])){
179                                                 msg_dialog::display(
180                                                                 _("Configuration error"), 
181                                                                 _("The configuration format has changed. Please re-run setup!"), 
182                                                                 FATAL_ERROR_DIALOG);
183                                                 exit();
184                                         }
185                                         if (!plugin_available($info['CLASS'])){
186                                                 continue;
187                                         }
188                                         $vars= get_class_vars($info['CLASS']);
189                                         $plHeadline= $vars['plHeadline'];
190                                         $plDescription= $vars['plDescription'];
192                                         $index= $this->get_index($info['CLASS']);
193                                         $href= "main.php?plug=$index&amp;reset=1";
195                                         if(!$vars){
196                                                 $plHeadline     = _("Unknown");
197                                                 $plDescription  = _("Unknown");
198                                                 $href= "main.php?reset=1";
199                                         }
201                                         if ($this->check_access($info['ACL'])){
203             $this->allowed_plugins[$index] = $index;
204  
205                                                 $entries= $entries."<p class=\"menuitem\" ".
206                                                         "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>";
207                                                 if(session::get('js')){
208                                                         $entries.= _($plHeadline)."</p>\n";
209                                                 } else {
210                                                         $entries.= "<a class=\"menuitem\" ".
211                                                         "href=\"$href\">".
212                                                         _($plHeadline)."</a></p>\n";
213                                                 }
215                                                 if(!session::is_set('maxC')){
216                                                         session::set('maxC',"RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP");
217                                                 }
218                                         }
219                                 }
221                                 /* Append to menu */
222                                 if ($entries != ""){
223                                         $this->menu.= $menu.$entries;
224                                 }
225                         }
227                 }
229                 /* Write menu output */
230                 return ($this->menu);
231         }
233         function gen_current()
234         {
235                 /* Do we have a current value? */
236                 if ($this->current == ""){
237                         $tmp= array_keys($this->menuparts);
238                         $this->current= $tmp[0];
239                 }
241                 /* Fill current array */
242                 $result= "<table width=\"100%\" summary=\"\">";
243                 $count= 0;
244                 foreach ($this->menuparts[$this->current] as $entry){
245                         if ($count == 2){
246                                 $result.= "</tr>";
247                                 $count= 0;
248                         }
249                         if ($count == 0){
250                                 $result.= "<tr>";
251                         }
252                         $result.= "<td>$entry</td>";
253                         $count++;
254                 }
256                 /* Add missing cell? */
257                 if ($count == 1){
258                         $result.= "<td>&nbsp;</td>";
259                 }
261                 $result.= "</table>";
262                 return $result;
263         }
266         function show_iconmenu()
267         {
268                 global $class_mapping;
269                 if ($this->iconmenu == ""){
270                         $cfg= $this->config->data['MENU'];
272                         if (isset($this->config->current['ICONSIZE'])){
273                                 list($x, $y)= split("x", $this->config->get_cfg_value("iconsize"));
274                                 $isize= "width=\"$x\" height=\"$y\"";
275                         } else {
276                                 $isize= "";
277                         }
279                         /* Parse headlines */
280                         foreach ($cfg as $headline => $plug){
281                                 $col= 1;
282                                 $menu= "<h1 class=\"menuheader\">".
283                                         _($headline)."</h1>\n<table summary=\"\" style=\"width:100%;".
284                                         "font-size: 14px;\" cellpadding=7 border=0>\n<tr>\n";
285                                 $entries= "";
287                                 foreach ($plug as $info){
289                                         if (!plugin_available($info['CLASS'])){
290                                                 continue;
291                                         }
293                                         /* Read information from class variable */
294                                         $vars= get_class_vars($info['CLASS']);
295                                         $plHeadline= $vars['plHeadline'];
296                                         $plDescription= $vars['plDescription'];
297           if (isset($vars['plIcon'])){
298                                         $plIcon= $vars['plIcon'];
299           } else {
300                                         $plIcon= "plugin.png";
301           }
303                                         $index= $this->get_index($info['CLASS']);
305                                         $href = "main.php?plug=".$index."&amp;reset=1";
307                                         /* Check if class is available. If the class doesn't exists display error symbol 
308                                                 to avoid that a user clicks on a non existing plugin  */
309                                         if(!$vars){
310                                                 $plHeadline = $plDescription = _("Unknown");
311                                                 $info['ICON'] = "error.png";
312                                                 $href="main.php?reset=1";
313                                         }
316                                         if ($this->check_access($info['ACL'])){
318                                                 /* Load icon */
319                                                 if (isset($info['ICON'])){
320                                                         $image= get_template_path('images/'.$info['ICON']);
321                                                 } else {
322               if(!preg_match("/\//",$plIcon)){
323                                                         $image= get_template_path("plugins/".preg_replace('%^.*/([^/]+)/[^/]+$%', '\1', $class_mapping[$info['CLASS']])."/images/$plIcon");
324               }else{
325                 $image = $plIcon; 
326               }
327                                                 }
328                                                 if ($col > 5){
329                                                         $entries= $entries."</tr><tr>";
330                                                         $col = 1;
331                                                 }
332                                                 $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
333                                                         ">";
334                                                         if(session::get('js')){
335                                                                 $entries.= "<img $isize border=0 align=middle src=\"$image".
336                                                                         "\" alt=\"*\">&nbsp;".
337                                                                         _($plHeadline);
338                                                         } else {
339                                                                 $entries.= "<a class=\"iconmenu\" href=\"".$href."\">".
340                                                                         "<img $isize border=0 align=middle src=\"$image".
341                                                                         "\" alt=\"*\">&nbsp;".
342                                                                         _($plHeadline)."</a>";
343                                                         }
344                                                         $entries.= "</td>\n";
345                                                 $col++ ;
347                                         }
348                                 }
350                                 /* Append to menu */
351                                 if ($entries != ""){
352                                         $this->iconmenu.= $menu.$entries;
354                                         /* Fill up remaining columns */
355                                         if ($col != 1){
356                                                 $col--;
357                                                 while ($col % 5){
358                                                         $this->iconmenu= $this->iconmenu.
359                                                                 "<td style=\"width:20%\">&nbsp;</td>\n";
360                                                         $col++;
361                                                 }
362                                         }
364                                         /* close table */
365                                         $this->iconmenu= $this->iconmenu."</tr>\n</table>\n";
366                                 }
367                         }
369                 }
371                 /* Write menu output */
372                 return ($this->iconmenu);
373         }
375         function get_path($index)
376         {
377                 if(!isset($this->dirlist[$index])){
378                         return ("");
379                 }
380                 return ("../".$this->dirlist[$index]);
381         }
383         function get_index($class)
384         {
385                 /* Search for plugin index (id), identify entry by path && class */
386                 $data = $this->config->data['MENU'];
387                 foreach($data as $section => $plugins){
388                         foreach($plugins as $key => $plugin)    {
389                                 if($plugin['CLASS'] == $class){
390                                         return($key);
391                                 }
392                         }
393                 }
395                 /* Nothing */
396                 return (0);
398         }
400   /*! \brief  This function checks if we are allowed to view the plugin with the given id 
401       @param  $plug_id  Integer  The ID of the plugin.
402       @return Boolean   TRUE if we are allowed to view the plugin else FASLE
403    */
404   function plugin_access_allowed($plug_id)
405   {
406     return(isset($this->allowed_plugins[$plug_id]));
407   }
410   /*! \brief  Force the menu to be recreated 
411    */
412   function reset_menus()
413   {
414     $this->menu = "";
415     $this->iconmenu ="";
416   }
419 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
420 ?>