fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [14722] api: fix ajax menu


From: Sigurd Nes
Subject: [Fmsystem-commits] [14722] api: fix ajax menu
Date: Thu, 11 Feb 2016 13:21:58 +0000

Revision: 14722
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=14722
Author:   sigurdne
Date:     2016-02-11 13:21:13 +0000 (Thu, 11 Feb 2016)
Log Message:
-----------
api: fix ajax menu

Modified Paths:
--------------
    trunk/phpgwapi/inc/class.menu.inc.php

Modified: trunk/phpgwapi/inc/class.menu.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.menu.inc.php       2016-02-11 12:30:42 UTC (rev 
14721)
+++ trunk/phpgwapi/inc/class.menu.inc.php       2016-02-11 13:21:13 UTC (rev 
14722)
@@ -1,4 +1,5 @@
 <?php
+
        /**
         * phpGroupWare menu handler class
         *
@@ -9,20 +10,19 @@
         * @subpackage phpgwapi
         * @version $Id$
         */
-
        /*
-          This program is free software: you can redistribute it and/or modify
-          it under the terms of the GNU General Public License as published by
-          the Free Software Foundation, either version 2 of the License, or
-          (at your option) any later version.
+         This program is free software: you can redistribute it and/or modify
+         it under the terms of the GNU General Public License as published by
+         the Free Software Foundation, either version 2 of the License, or
+         (at your option) any later version.
 
-          This program is distributed in the hope that it will be useful,
-          but WITHOUT ANY WARRANTY; without even the implied warranty of
-          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-          GNU General Public License for more details.
+         This program is distributed in the hope that it will be useful,
+         but WITHOUT ANY WARRANTY; without even the implied warranty of
+         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+         GNU General Public License for more details.
 
-          You should have received a copy of the GNU General Public License
-          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+         You should have received a copy of the GNU General Public License
+         along with this program.  If not, see <http://www.gnu.org/licenses/>.
         */
 
        /*
@@ -33,17 +33,18 @@
         */
        class phpgwapi_menu
        {
+
                var $public_functions = array
-               (
-                       'get_local_menu_ajax'   => true,
-                       'update_bookmark_menu'  => true
+                       (
+                       'get_local_menu_ajax' => true,
+                       'update_bookmark_menu' => true
                );
-               
+
                /**
-               * Clear the user's menu so it can be regenerated cleanly
-               *
-               * @return void
-               */
+                * Clear the user's menu so it can be regenerated cleanly
+                *
+                * @return void
+                */
                public function clear()
                {
                        $account_id = 
$GLOBALS['phpgw_info']['user']['account_id'];
@@ -51,30 +52,30 @@
                }
 
                /**
-               * Get the menu structure and return it
-               *
-               * @param string $mtype the type of menu sought - default all 
returned
-               *
-               * @return array menu structure
-               */
+                * Get the menu structure and return it
+                *
+                * @param string $mtype the type of menu sought - default all 
returned
+                *
+                * @return array menu structure
+                */
                public function get($mtype = null)
                {
                        static $menu = null;
 
                        $account_id = 
$GLOBALS['phpgw_info']['user']['account_id'];
 
-                       if ( !$menu )
+                       if(!$menu)
                        {
-                               $menu = phpgwapi_cache::user_get('phpgwapi', 
'menu', $account_id,true,true);
+                               $menu = phpgwapi_cache::user_get('phpgwapi', 
'menu', $account_id, true, true);
                        }
 
-                       if ( !$menu )
+                       if(!$menu)
                        {
                                $menu = self::load();
-                               phpgwapi_cache::user_set('phpgwapi', 'menu', 
$menu, $account_id,true,true);
+                               phpgwapi_cache::user_set('phpgwapi', 'menu', 
$menu, $account_id, true, true);
                        }
 
-                       if ( !is_null($mtype) && isset($menu[$mtype]) )
+                       if(!is_null($mtype) && isset($menu[$mtype]))
                        {
                                return $menu[$mtype];
                        }
@@ -82,12 +83,12 @@
                }
 
                /**
-               * Get categories available for the current user
-               *
-               * @param string $module the module the categories are sought for
-               *
-               * @return array menu class compatiable array of categories
-               */
+                * Get categories available for the current user
+                *
+                * @param string $module the module the categories are sought 
for
+                *
+                * @return array menu class compatiable array of categories
+                */
                public static function get_categories($module)
                {
                        $catobj = createObject('phpgwapi.categories', 
$GLOBALS['phpgw_info']['user']['account_id'], $module);
@@ -97,38 +98,38 @@
                }
 
                /**
-               * Load the menu structure from all available applications
-               *
-               * @return array the menu structure for the current user
-               */
+                * Load the menu structure from all available applications
+                *
+                * @return array the menu structure for the current user
+                */
                private function load()
                {
                        $menus = array();
                        $raw_menus = $GLOBALS['phpgw']->hooks->process('menu');
 
-                       foreach ( $GLOBALS['phpgw_info']['user']['apps'] as 
$app => $app_info )
-               //      foreach ( $raw_menus as $app => $raw_menu )
+                       foreach($GLOBALS['phpgw_info']['user']['apps'] as $app 
=> $app_info)
+                       //      foreach ( $raw_menus as $app => $raw_menu )
                        {
                                $raw_menu = $raw_menus[$app];
                                // Ignore invalid entries
-                               if ( !is_array($raw_menu) )
+                               if(!is_array($raw_menu))
                                {
                                        continue;
                                }
-                               foreach ( $raw_menu as $mtype => $menu )
+                               foreach($raw_menu as $mtype => $menu)
                                {
-                                        //no point in adding empty items
-                                       if ( !count($menu) )
+                                       //no point in adding empty items
+                                       if(!count($menu))
                                        {
                                                continue;
                                        }
 
-                                       if ( !isset($menus[$mtype]) )
+                                       if(!isset($menus[$mtype]))
                                        {
                                                $menus[$mtype] = array();
                                        }
 
-                                       switch ( $mtype )
+                                       switch($mtype)
                                        {
                                                case 'navbar':
                                                        $menus[$mtype] = 
array_merge($menus[$mtype], $menu);
@@ -136,14 +137,14 @@
                                                case 'admin':
                                                        $app_text = $app == 
'admin' ? lang('General') : lang($app);
                                                        
$menus['navigation']['admin'][$app] = array
-                                                       (
-                                                               'text'  => 
$GLOBALS['phpgw']->translation->translate($app, array(), true),
-                                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php',
-                                                                               
        array('menuaction' => 'admin.uiconfig.index', 'appname' => $app)),
-                                                               'image' => 
$raw_menu['navbar'][$app]['image'],
-                                                               'children'      
=> $menu
+                                                               (
+                                                               'text' => 
$GLOBALS['phpgw']->translation->translate($app, array(), true),
+                                                               'url' => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uiconfig.index',
+                                                                       
'appname' => $app)),
+                                                               'image' => 
$raw_menu['navbar'][$app]['image'],
+                                                               'children' => 
$menu
                                                        );
-                                                       // no break here - fall 
thru
+                                               // no break here - fall thru
                                                default:
                                                        $menus[$mtype][$app] = 
$menu;
                                        }
@@ -182,15 +183,15 @@
                 * @param string $children     rendered sub menu
                 * @param bool   $show_appname show appname as top level
                 */
-               protected static function _render_item($item, $id='', 
$children='', $show_appname = false)
+               protected static function _render_item($item, $id = '', 
$children = '', $show_appname = false)
                {
                        $current_class = '';
-                       if ( $id == 
"navbar::{$GLOBALS['phpgw_info']['flags']['menu_selection']}" )
+                       if($id == 
"navbar::{$GLOBALS['phpgw_info']['flags']['menu_selection']}")
                        {
                                $current_class = 'current';
                        }
 
-                       $link_class =" class=\"{$current_class}\"";
+                       $link_class = " class=\"{$current_class}\"";
 
                        if(isset($item['group']) && $show_appname) // at 
application
                        {
@@ -207,7 +208,7 @@
                                {$children}
 HTML;
                        }
-                       else if (isset($item['url']))
+                       else if(isset($item['url']))
                        {
                                return <<<HTML
                                <li>
@@ -230,7 +231,7 @@
                protected static function _render_submenu($parent, $menu, 
$show_appname = false)
                {
                        $out = '';
-                       foreach ( $menu as $key => $item )
+                       foreach($menu as $key => $item)
                        {
                                $children = isset($item['children']) ? 
self::_render_submenu("{$parent}::{$key}", $item['children'], $show_appname) : 
'';
                                $out .= self::_render_item($item, 
"navbar::{$parent}::{$key}", $children, $show_appname);
@@ -245,7 +246,6 @@
                        return $out;
                }
 
-
                /**
                 * Render a horisontal menu for an application
                 *
@@ -260,15 +260,15 @@
                                                <table>
                                                        <tr>
 HTML;
-                       foreach ($menu as &$item)
+                       foreach($menu as &$item)
                        {
                                $current_class = '';
-                               if ( $item['this'] )
+                               if($item['this'])
                                {
                                        $current_class = 'current';
                                        $item['text'] = 
"[<b>{$item['text']}</b>]";
                                }
-                               $link_class =" class=\"{$current_class}\"";
+                               $link_class = " class=\"{$current_class}\"";
                                $html .= <<<HTML
                                        <td>
                                                <a 
href="{$item['url']}"{$link_class} id="{$id}">
@@ -277,9 +277,9 @@
                                        </td>
 HTML;
 
-                               if ( $item['children'] )
+                               if($item['children'])
                                {
-                                       $children  = $item['children'];
+                                       $children = $item['children'];
                                }
                        }
                        $html .= <<<HTML
@@ -310,15 +310,15 @@
                                                        <tr>                    
        
 HTML;
 
-                       foreach ($menu as &$item)
+                       foreach($menu as &$item)
                        {
                                $current_class = '';
-                               if ( $item['this'] )
+                               if($item['this'])
                                {
                                        $current_class = 'current';
                                        $item['text'] = 
"[<b>{$item['text']}</b>]";
                                }
-                               $link_class =" class=\"{$current_class}\"";
+                               $link_class = " class=\"{$current_class}\"";
                                $html .= <<<HTML
                                        <td>
                                                <a 
href="{$item['url']}"{$link_class} id="{$id}">
@@ -327,9 +327,9 @@
                                        </td>
 HTML;
 
-                               if ( $item['children'] )
+                               if($item['children'])
                                {
-                                       $children  = $item['children'];
+                                       $children = $item['children'];
                                }
                        }
                        $html .= <<<HTML
@@ -345,25 +345,24 @@
                        return $html;
                }
 
-
                public function get_local_menu($app = '')
                {
                        $app = $app ? $app : 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       switch ( $app )
+                       switch($app)
                        {
                                case 'home':
                                case 'login':
                                        return array();
                                default:
-                                       // nothing
+                               // nothing
                        }
 
                        if(!$menu = 
$GLOBALS['phpgw']->session->appsession($GLOBALS['phpgw_info']['flags']['menu_selection'],
 "menu_{$app}"))
                        {
-                               $menu_gross = 
execMethod("{$app}.menu.get_menu",'horisontal');
-                               $selection = 
explode('::',$GLOBALS['phpgw_info']['flags']['menu_selection']);
-                               $level=0;
-                               $menu = 
self::_get_sub_menu($menu_gross['navigation'],$selection,$level);
+                               $menu_gross = 
execMethod("{$app}.menu.get_menu", 'horisontal');
+                               $selection = explode('::', 
$GLOBALS['phpgw_info']['flags']['menu_selection']);
+                               $level = 0;
+                               $menu = 
self::_get_sub_menu($menu_gross['navigation'], $selection, $level);
                                
$GLOBALS['phpgw']->session->appsession(isset($GLOBALS['phpgw_info']['flags']['menu_selection'])
 && $GLOBALS['phpgw_info']['flags']['menu_selection'] ? 
$GLOBALS['phpgw_info']['flags']['menu_selection'] : 'menu_missing_selection', 
"menu_{$app}", $menu);
                                unset($menu_gross);
                        }
@@ -375,34 +374,34 @@
                        $navbar = $this->get('navbar');
                        $exclude = array('logout', 'about', 'preferences');
                        $top_level_menu = array();
-                       foreach ( $navbar as $app => $app_data )
+                       foreach($navbar as $app => $app_data)
                        {
-                               if ( in_array($app, $exclude) )
+                               if(in_array($app, $exclude))
                                {
                                        continue;
                                }
 
                                $top_level_menu[] = array
-                               (
-                                       'app'   => $app,
+                                       (
+                                       'app' => $app,
                                        'text' => $app_data['text'],
-                                       'url'   => str_replace('&amp;','&', 
$app_data['url']),
-                                       'children'      => true
+                                       'url' => str_replace('&amp;', '&', 
$app_data['url']),
+                                       'children' => true
                                );
-
                        }
-                       
+
                        return $top_level_menu;
                }
+
                public function get_local_menu_ajax()
                {
-                       $node           = phpgw::get_var('node');
+                       $node = phpgw::get_var('node');
                        if($node == 'top_level')
                        {
                                return $this->get_top_level_menu_ajax();
                        }
 
-                       $selection = explode('|',$node);
+                       $selection = explode('|', $node);
                        $app = $selection[0];
 
                        if(!isset($GLOBALS['phpgw_info']['user']['apps'][$app]))
@@ -414,43 +413,44 @@
                        $parent_node = array();
                        if(isset($selection[1]))
                        {
-                               for ($i=1;$i<count($selection);$i++)
+                               for($i = 1; $i < count($selection); $i++)
                                {
-                                       $parent_node[] =  $selection[$i];
+                                       $parent_node[] = $selection[$i];
                                }
                        }
 
                        $_section = 'navigation';
+                       $admin = false;
                        if($app == 'admin')
                        {
+                               $admin = true;
                                if(!isset($selection[1]))
                                {
                                        $navigation = $this->get('admin');
 
-                                       foreach ( 
$GLOBALS['phpgw_info']['user']['apps'] as $_app => $app_info )
+                                       
foreach($GLOBALS['phpgw_info']['user']['apps'] as $_app => $app_info)
                                        {
                                                if(!in_array($_app, 
array('logout', 'about', 'preferences')) && isset($navigation[$_app]))
-                                                       {
-                                                               $menu[] = array
-                                                               (
-                                                               'app'           
=> 'admin',
-                                                                       'key'   
        => $_app,
-                                                                       
'is_leaf'       => count($navigation[$_app]) > 1 ? false : true,
-                                                               'children'      
=> count($navigation[$_app]) > 1 ? true : false,
-                                                                       'text'  
        => $GLOBALS['phpgw']->translation->translate($_app, array(), true),
-                                                               'url'           
=> str_replace('&amp;','&', $GLOBALS['phpgw']->link('/index.php',
-                                                                               
                array('menuaction' => 'admin.uiconfig.index', 'appname' => 
$_app)))
-
-                                                               );
-                                                       }
+                                               {
+                                                       $menu[] = array
+                                                       (
+                                                               'app' => 
'admin',
+                                                               'key' => $_app,
+                                                               'is_leaf' => 
count($navigation[$_app]) > 1 ? false : true,
+                                                               'children' => 
count($navigation[$_app]) > 1 ? true : false,
+                                                               'text' => 
$GLOBALS['phpgw']->translation->translate($_app, array(), true),
+                                                               'url' => 
str_replace('&amp;', '&', $GLOBALS['phpgw']->link('/index.php', array(
+                                                                       
'menuaction' => 'admin.uiconfig.index', 'appname' => $_app)))
+                                                       );
                                                }
+                                       }
 
-                                       return $menu;                           
+                                       return $menu;
                                }
                                else
                                {
-                                       $_section =  'admin';
-                                       $app =  $selection[1];
+                                       $_section = 'admin';
+                                       $app = $selection[1];
                                        array_shift($selection);
                                }
                        }
@@ -459,7 +459,7 @@
                        if(!$menu_gross = 
phpgwapi_cache::session_get('phpgwapi', "menu_{$app}"))
                        {
                                $menu_gross = 
execMethod("{$app}.menu.get_menu");
-                               phpgwapi_cache::session_set('phpgwapi', 
"menu_{$app}",$menu_gross);
+                               phpgwapi_cache::session_set('phpgwapi', 
"menu_{$app}", $menu_gross);
                        }
 
                        $menu_gross = $menu_gross[$_section];
@@ -467,13 +467,13 @@
                        $count_selection = count($selection);
                        if($count_selection > 1)
                        {
-                               for ($i=1;$i<count($selection);$i++)
+                               for($i = 1; $i < count($selection); $i++)
                                {
                                        if(isset($menu_gross[$selection[$i]]))
                                        {
                                                $menu_gross = 
$menu_gross[$selection[$i]];
                                        }
-                                       else if 
(isset($menu_gross['children'][$selection[$i]]))
+                                       else 
if(isset($menu_gross['children'][$selection[$i]]))
                                        {
                                                $menu_gross = 
$menu_gross['children'][$selection[$i]];
                                        }
@@ -489,13 +489,13 @@
                                $children = $menu_gross;
                        }
 
-                       $i=0;
+                       $i = 0;
                        foreach($children as $key => $vals)
                        {
-                               $vals['url'] = str_replace('&amp;','&', 
$vals['url']);
+                               $vals['url'] = str_replace('&amp;', '&', 
$vals['url']);
                                $menu[$i] = $vals;
-                               $menu[$i]['app'] = $app;
-                               $menu[$i]['key'] = implode('|', 
array_merge($parent_node,array($key)));
+                               $menu[$i]['app'] = $admin ? 'admin' : $app;
+                               $menu[$i]['key'] = implode('|', 
array_merge($parent_node, array($key)));
                                if(isset($menu[$i]['children']))
                                {
                                        $menu[$i]['is_leaf'] = false;
@@ -512,10 +512,10 @@
                        return $menu;
                }
 
-               protected static function _get_sub_menu($children = array(), 
$selection=array(),$level=0)
+               protected static function _get_sub_menu($children = array(), 
$selection = array(), $level = 0)
                {
                        $level++;
-                       $i=0;
+                       $i = 0;
                        $menu = array();
                        foreach($children as $key => $vals)
                        {
@@ -528,7 +528,7 @@
                                        $menu[$i]['this'] = true;
                                        if(isset($menu[$i]['children']))
                                        {
-                                               $menu[$i]['children'] = 
self::_get_sub_menu($menu[$i]['children'],$selection,$level);
+                                               $menu[$i]['children'] = 
self::_get_sub_menu($menu[$i]['children'], $selection, $level);
                                                $menu[$i]['is_leaf'] = false;
                                        }
                                }
@@ -559,7 +559,7 @@
                        }
                        else
                        {
-                               if(! is_array($bookmarks))
+                               if(!is_array($bookmarks))
                                {
                                        $bookmarks = array();
                                }
@@ -571,9 +571,8 @@
                        phpgwapi_cache::user_set('phpgwapi', "bookmark_menu", 
$bookmarks, $user_id);
 
                        return array
-                       (
+                               (
                                'status' => $status
                        );
                }
-
-       }
+       }
\ No newline at end of file




reply via email to

[Prev in Thread] Current Thread [Next in Thread]