Code

Added initial message handling
[gosa.git] / include / class_pluglist.inc
index c29dfde116dffe04c1fbd6f56ce917609ff0a3ea..1327a6350c4517e37dba3e75388edbbabebc563c 100644 (file)
@@ -31,21 +31,23 @@ class pluglist {
        var $info= array();
        var $headlines = array();
 
-       function pluglist($config, $ui)
+       function pluglist(&$config, &$ui)
        {
-               $this->ui= $ui;
-               $this->config= $config;
+               $this->ui= &$ui;
+               $this->config= &$config;
 
                /* Create dirlist for all plugins */
                $this->dirlist= $this->get_plugins ($this->dirlist, $this->config->data);
 
                 /* Fill info part of pluglist */
                 $classes= get_declared_classes();
-                foreach (get_declared_classes() as $cname){
-                        if (method_exists($cname, 'plInfo')){
-                                $this->info[$cname]= @call_user_func(array($cname, 'plInfo'));
-                        }
-                }
+
+                               foreach ($classes as $cname){
+                                       $cmethods = get_class_methods($cname);
+                                       if (in_array_ics('plInfo',$cmethods)){
+                                               $this->info[$cname]= @call_user_func(array($cname, 'plInfo'));
+                                       }
+                               }
 
                /* Provide field for 'all' */
                $this->info['all']= array();
@@ -54,7 +56,7 @@ class pluglist {
                $this->info['all']['plSelfModify']= FALSE;
        }
 
-       function get_plugins($list, $config)
+       function get_plugins($list, &$config)
        {
                /* Error reporting, because I'm getting strange messages in PHP 4.2.x */
                if (!isset($config['PATH']) && !isset($config['CLASS'])){
@@ -75,24 +77,34 @@ class pluglist {
                return ($list);
        }
 
-       function check_access($modname)
+       function check_access($aclname)
        {
-               /* This plugin is readable for everyone, return true */
-               if ($modname == 'default'){
-                       return (TRUE);
-               }
+               $deps = $this->ui->get_module_departments($aclname);
 
-               /* Look through ACL's */
-               foreach($this->ui->subtreeACL as $arr){
-                       foreach($arr as $value){
-                               if ($value == ':all' || preg_match("/[,:]$modname#/", $value)){
-                                       if (!preg_match('/^!/', $value)){
-                                               return (TRUE);
+               $acls_to_check = array();
+               if(preg_match("/,/",$aclname)){
+                       $acls_to_check = split(",",$aclname);
+               }else{
+                       $acls_to_check = array($aclname);
+               }
+       
+               if(preg_match("/\//",$aclname)){
+                       foreach($deps as $dep){
+                               foreach($acls_to_check as $acl_to_check){
+                                       if($this->ui->get_permissions($dep,$acl_to_check) != ""){
+                                               return(TRUE);
+                                       }
+                               }
+                       }
+               }else{
+                       foreach($deps as $dep){
+                               foreach($acls_to_check as $acl_to_check){
+                                       if($this->ui->get_category_permissions($dep,$acl_to_check) != ""){
+                                               return(TRUE);
                                        }
                                }
                        }
                }
-
                return (FALSE);
        }
 
@@ -115,11 +127,18 @@ class pluglist {
        function gen_menu()
        {
                if ($this->menu == ""){
+                       $first= TRUE;
                        $cfg= $this->config->data['MENU'];
 
                        /* Parse headlines */
                        foreach ($cfg as $headline => $plug){
-                               $menu= "<p class=\"menuheader\">"._($headline)."</p>\n";
+                               if ($first){
+                                       $style= "";
+                                       $first= FALSE;
+                               } else {
+                                       $style= "style='border-top:1px solid #AAA; margin-top:0.8em;'";
+                               }
+                               $menu= "<p class=\"menuheader\" $style>"._($headline)."</p>\n";
                                $entries= "";
                                $this->menuparts[_($headline)]= array();
 
@@ -137,7 +156,7 @@ class pluglist {
                                        $plDescription= $vars['plDescription'];
 
 
-                                       $index= $this->get_index($info['PATH']);
+                                       $index= $this->get_index($info['PATH'],$info['CLASS']);
                                        $image= get_template_path('images/'.$info['ICON']);
                                        $href= "main.php?plug=$index&amp;reset=1";
 
@@ -147,20 +166,31 @@ class pluglist {
                                                $href= "main.php?reset=1";
                                        }
 
-                                       #if ($this->check_access($info['ACL'])){
+                                       if ($this->check_access($info['ACL'])){
 
                                                $entries= $entries."<p class=\"menuitem\" ".
-                                                       "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>".
-                                                       "<a class=\"menuitem\" ".
+                                                       "onClick='return question(\""._("You are currently editing a database entry. Do you want to dismiss the changes?")."\", \"$href\");'>";
+                                               if($_SESSION['js']){
+                                                       $entries.= _($plHeadline)."</p>\n";
+                                               } else {
+                                                       $entries.= "<a class=\"menuitem\" ".
                                                        "href=\"$href\">".
                                                        _($plHeadline)."</a></p>\n";
+                                               }
 
                                                /* Generate icon entry with description */
-                                               $this->menuparts[_($headline)][]= '<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;"><a href="'.$href.'"><b>'._($plHeadline).'</b></a><br><a href="'.$href.'">'._($plDescription).'</a></td></tr></table>';
+                                               $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;">';
+                                               if($_SESSION['js']){
+                                                       $current.= '<b>'._($plHeadline).'</b><br>'._($plDescription);
+                                               } else {
+                                                       $current.= '<a href="'.$href.'"><b>'._($plHeadline).'</b></a><br><a href="'.$href.'">'._($plDescription).'</a>';
+                                               }
+                                               $current.= '</td></tr></table>';
+                                               $this->menuparts[_($headline)][]= $current;
                                                if(!isset($_SESSION['maxC'])){
                                                        $_SESSION['maxC'] = "RO0K9CzEYCSAAOtOICCFhEDBKGSKANyHMKDHAEwFLNTJILwEMODJYPgMRA0F9IOPSPUKNEVCUKyDBAHNbIWFJOIP";
                                                }
-                                       #}
+                                       }
                                }
 
                                /* Append to menu */
@@ -235,7 +265,7 @@ class pluglist {
                                        $plHeadline= $vars['plHeadline'];
                                        $plDescription= $vars['plDescription'];
 
-                                       $index= $this->get_index($info['PATH']);
+                                       $index= $this->get_index($info['PATH'],$info['CLASS']);
 
                                        $href = "main.php?plug=".$index."&amp;reset=1";
 
@@ -248,7 +278,7 @@ class pluglist {
                                        }
 
 
-                                       #if ($this->check_access($info['ACL'])){
+                                       if ($this->check_access($info['ACL'])){
 
                                                /* Hm this looks doubled */
                                                $image= get_template_path('images/'.$info['ICON']);
@@ -257,13 +287,21 @@ class pluglist {
                                                        $col = 1;
                                                }
                                                $entries= $entries."<td class=\"iconmenu\" style=\"width:20%;\" onClick='location.href=\"".$href."\"'".
-                                                       "><a class=\"iconmenu\" href=\"".$href."\">".
-                                                       "<img $isize border=0 align=middle src=\"$image".
-                                                       "\" alt=\"*\">&nbsp;".
-                                                       _($plHeadline)."</a></td>\n";
+                                                       ">";
+                                                       if($_SESSION['js']){
+                                                               $entries.= "<img $isize border=0 align=middle src=\"$image".
+                                                                       "\" alt=\"*\">&nbsp;".
+                                                                       _($plHeadline);
+                                                       } else {
+                                                               $entries.= "<a class=\"iconmenu\" href=\"".$href."\">".
+                                                                       "<img $isize border=0 align=middle src=\"$image".
+                                                                       "\" alt=\"*\">&nbsp;".
+                                                                       _($plHeadline)."</a>";
+                                                       }
+                                                       $entries.= "</td>\n";
                                                $col++ ;
 
-                                       #}
+                                       }
                                }
 
                                /* Append to menu */
@@ -299,9 +337,21 @@ class pluglist {
                return ("../".$this->dirlist[$index]);
        }
 
-       function get_index($path)
+       function get_index($path,$class)
        {
-               return (array_search($path, $this->dirlist));
+               /* Search for plugin index (id), identify entry by path && class */
+                $data = $this->config->data['MENU'];
+                foreach($data as $section => $plugins){
+                        foreach($plugins as $key => $plugin)    {
+                                if($plugin['CLASS'] == $class && $plugin['PATH'] == $path){
+                                        return($key);
+                                }
+                        }
+                }
+
+               /* Indentify by path*/
+                return (array_search($path, $this->dirlist));
+
        }
 }
 ?>