Hide Menu options if not authorized
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 8 Sep 2012 17:07:55 +0000 (19:07 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 8 Sep 2012 17:07:55 +0000 (19:07 +0200)
themes/aqua/renderer.php
themes/cool/renderer.php
themes/default/renderer.php

index 10c3c95641d9e7e09f7aad57d26b94b2d753d01a..72e200cb4bf5481da2a68bf8d75adddcbbc97a23 100644 (file)
                                echo "<div class=tabs>";
                                foreach($applications as $app)
                                {
-                                       $acc = access_string($app->name);
-                                       echo "<a class='".($sel_app == $app->id ? 'selected' : 'menu_tab')
-                                               ."' href='$local_path_to_root/index.php?application=".$app->id
-                                               ."'$acc[1]>" .$acc[0] . "</a>";
+                    if ($this->check_application_access($app))
+                    {
+                                               $acc = access_string($app->name);
+                                               echo "<a class='".($sel_app == $app->id ? 'selected' : 'menu_tab')
+                                                       ."' href='$local_path_to_root/index.php?application=".$app->id
+                                                       ."'$acc[1]>" .$acc[0] . "</a>";
+                                       }               
                                }
                                echo "</div>";
 
                        global $path_to_root;
                        
                        $selected_app = $waapp->get_selected_application();
+                       if (!$this->check_application_access($selected_app))
+                               return;
 
                        foreach ($selected_app->modules as $module)
                        {
+                       if (!$this->check_module_access($module))
+                               continue;
                                // image
                                echo "<tr>";
                                // values
                                        {
                                                        echo $img.menu_link($appfunction->link, $appfunction->label)."<br>\n";
                                        }
-                                       else 
+                                       elseif (!$this->hide_inaccessible_menu_items()) 
                                        {
                                                        echo $img.'<span class="inactive">'
                                                                .access_string($appfunction->label, true)
                                                {
                                                                echo $img.menu_link($appfunction->link, $appfunction->label)."<br>\n";
                                                }
-                                               else 
+                                               elseif (!$this->hide_inaccessible_menu_items()) 
                                                {
                                                                echo $img.'<span class="inactive">'
                                                                        .access_string($appfunction->label, true)
 
                        echo "</table>";
                }
+
+        function check_application_access($waapp)
+        {
+            if (!$this->hide_inaccessible_menu_items())
+            {
+                return true;
+            }
+            
+            foreach ($waapp->modules as $module)
+            {
+                if ($this->check_module_access($module))
+                {
+                    return true;
+                }
+            }
+            
+            return false;
+                    
+        }
+        
+        function check_module_access($module)
+        {
+            
+            if (!$this->hide_inaccessible_menu_items())
+            {
+                return true;
+            }
+            
+            if (sizeof($module->lappfunctions) > 0)
+            {
+                foreach ($module->lappfunctions as $appfunction)
+                {
+                    if ($appfunction->label != "" && $_SESSION["wa_current_user"]->can_access_page($appfunction->access))
+                    {
+                        return true;
+                    }
+                }
+            }
+            
+            if (sizeof($module->rappfunctions) > 0)
+            {
+                foreach ($module->rappfunctions as $appfunction)
+                {
+                    if ($appfunction->label != "" && $_SESSION["wa_current_user"]->can_access_page($appfunction->access))
+                    {
+                        return true;
+                    }
+                }
+            }
+            
+            return false;
+            
+        }
+        
+        function hide_inaccessible_menu_items()
+        {
+            global $hide_inaccessible_menu_items;
+            
+            if (!isset($hide_inaccessible_menu_items) || $hide_inaccessible_menu_items == 0)
+            {
+                return false;
+            }
+            
+            else
+            {
+                return true;
+            }
+        }
        }
 
 ?>
\ No newline at end of file
index 925631403dcf966575cde1e9bb67bff9dbba0c3e..8ce153f2a128f17eeaba66703001574f85953d91 100644 (file)
                                echo "<div class=tabs>";
                                foreach($applications as $app)
                                {
-                                       $acc = access_string($app->name);
-                                       echo "<a class='".($sel_app == $app->id ? 'selected' : 'menu_tab')
-                                               ."' href='$local_path_to_root/index.php?application=".$app->id
-                                               ."'$acc[1]>" .$acc[0] . "</a>";
+                    if ($this->check_application_access($app))
+                    {
+                                               $acc = access_string($app->name);
+                                               echo "<a class='".($sel_app == $app->id ? 'selected' : 'menu_tab')
+                                                       ."' href='$local_path_to_root/index.php?application=".$app->id
+                                                       ."'$acc[1]>" .$acc[0] . "</a>";
+                                       }               
                                }
                                echo "</div>";
 
                {
                        global $path_to_root;
                        $selected_app = $waapp->get_selected_application();
+                       if (!$this->check_application_access($selected_app))
+                               return;
 
                        foreach ($selected_app->modules as $module)
                        {
+                       if (!$this->check_module_access($module))
+                               continue;
                                // image
                                echo "<tr>";
                                // values
                                        {
                                                        echo $img.menu_link($appfunction->link, $appfunction->label)."<br>\n";
                                        }
-                                       else 
+                                       elseif (!$this->hide_inaccessible_menu_items()) 
                                        {
                                                        echo $img.'<span class="inactive">'
                                                                .access_string($appfunction->label, true)
                                                {
                                                                echo $img.menu_link($appfunction->link, $appfunction->label)."<br>\n";
                                                }
-                                               else 
+                                               elseif (!$this->hide_inaccessible_menu_items()) 
                                                {
                                                                echo $img.'<span class="inactive">'
                                                                        .access_string($appfunction->label, true)
 
                        echo "</table>";
                }
+
+        function check_application_access($waapp)
+        {
+            if (!$this->hide_inaccessible_menu_items())
+            {
+                return true;
+            }
+            
+            foreach ($waapp->modules as $module)
+            {
+                if ($this->check_module_access($module))
+                {
+                    return true;
+                }
+            }
+            
+            return false;
+                    
+        }
+        
+        function check_module_access($module)
+        {
+            
+            if (!$this->hide_inaccessible_menu_items())
+            {
+                return true;
+            }
+            
+            if (sizeof($module->lappfunctions) > 0)
+            {
+                foreach ($module->lappfunctions as $appfunction)
+                {
+                    if ($appfunction->label != "" && $_SESSION["wa_current_user"]->can_access_page($appfunction->access))
+                    {
+                        return true;
+                    }
+                }
+            }
+            
+            if (sizeof($module->rappfunctions) > 0)
+            {
+                foreach ($module->rappfunctions as $appfunction)
+                {
+                    if ($appfunction->label != "" && $_SESSION["wa_current_user"]->can_access_page($appfunction->access))
+                    {
+                        return true;
+                    }
+                }
+            }
+            
+            return false;
+            
+        }
+        
+        function hide_inaccessible_menu_items()
+        {
+            global $hide_inaccessible_menu_items;
+            
+            if (!isset($hide_inaccessible_menu_items) || $hide_inaccessible_menu_items == 0)
+            {
+                return false;
+            }
+            
+            else
+            {
+                return true;
+            }
+        }
        }
 
 ?>
\ No newline at end of file
index c57cc92ebccc2d8bd3dd03588ffff9496e26f787..08d015abf77720543ab536995768f780b45cff2f 100644 (file)
@@ -9,6 +9,7 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
+
        class renderer
        {
                function get_icon($category)
@@ -34,7 +35,7 @@
 
                function menu_header($title, $no_menu, $is_index)
                {
-                       global $path_to_root, $help_base_url, $db_connections;
+                       global $path_to_root, $help_base_url, $db_connections, $show_inaccessible_menu_items;
                        echo "<table class='callout_main' border='0' cellpadding='0' cellspacing='0'>\n";
                        echo "<tr>\n";
                        echo "<td colspan='2' rowspan='2'>\n";
                                echo "<div class=tabs>";
                                foreach($applications as $app)
                                {
-                                       $acc = access_string($app->name);
-                                       echo "<a class='".($sel_app == $app->id ? 'selected' : 'menu_tab')
-                                               ."' href='$local_path_to_root/index.php?application=".$app->id
-                                               ."'$acc[1]>" .$acc[0] . "</a>";
+                    if ($this->check_application_access($app))
+                    {
+                        $acc = access_string($app->name);
+                        echo "<a class='".($sel_app == $app->id ? 'selected' : 'menu_tab')
+                            ."' href='$local_path_to_root/index.php?application=".$app->id
+                            ."'$acc[1]>" .$acc[0] . "</a>";
+                    }
                                }
                                echo "</div>";
                                echo "</td></tr></table>";
                        global $path_to_root;
 
                        $selected_app = $waapp->get_selected_application();
-
+                       if (!$this->check_application_access($selected_app))
+                               return;
                        foreach ($selected_app->modules as $module)
                        {
+                       if (!$this->check_module_access($module))
+                               continue;
                                // image
                                echo "<tr>";
                                // values
                                        {
                                                        echo $img.menu_link($appfunction->link, $appfunction->label)."<br>\n";
                                        }
-                                       else 
+                                       elseif (!$this->hide_inaccessible_menu_items())
                                        {
                                                        echo $img.'<span class="inactive">'
                                                                .access_string($appfunction->label, true)
                                                {
                                                                echo $img.menu_link($appfunction->link, $appfunction->label)."<br>\n";
                                                }
-                                               else 
+                                               elseif (!$this->hide_inaccessible_menu_items())
                                                {
                                                                echo $img.'<span class="inactive">'
                                                                        .access_string($appfunction->label, true)
                                }
 
                                echo "</tr></table></td></tr>";
-                       }
-
+                       }       
                        echo "</table>";
                }
-       }
+        
+        function check_application_access($waapp)
+        {
+            if (!$this->hide_inaccessible_menu_items())
+            {
+                return true;
+            }
+            
+            foreach ($waapp->modules as $module)
+            {
+                if ($this->check_module_access($module))
+                {
+                    return true;
+                }
+            }
+            
+            return false;
+                    
+        }
+        
+        function check_module_access($module)
+        {
+            
+            if (!$this->hide_inaccessible_menu_items())
+            {
+                return true;
+            }
+            
+            if (sizeof($module->lappfunctions) > 0)
+            {
+                foreach ($module->lappfunctions as $appfunction)
+                {
+                    if ($appfunction->label != "" && $_SESSION["wa_current_user"]->can_access_page($appfunction->access))
+                    {
+                        return true;
+                    }
+                }
+            }
+            
+            if (sizeof($module->rappfunctions) > 0)
+            {
+                foreach ($module->rappfunctions as $appfunction)
+                {
+                    if ($appfunction->label != "" && $_SESSION["wa_current_user"]->can_access_page($appfunction->access))
+                    {
+                        return true;
+                    }
+                }
+            }
+            
+            return false;
+            
+        }
+        
+        function hide_inaccessible_menu_items()
+        {
+            global $hide_inaccessible_menu_items;
+            
+            if (!isset($hide_inaccessible_menu_items) || $hide_inaccessible_menu_items == 0)
+            {
+                return false;
+            }
+            
+            else
+            {
+                return true;
+            }
+        }
+    }
+               
+
 
 ?>
\ No newline at end of file