Community Forums

[MOD] - 1.3.4 Admin Menu Controller Access Support

Free manual modifications can be contributed here. Modifications are manual snippets of code that are pasted into the forums for others to use.

[MOD] - 1.3.4 Admin Menu Controller Access Support

Postby hazpotts » Mon Feb 08, 2010 12:48 pm

I altered the admin menu controller so that it would only output menu items that the current user has permission for, is this useful to anyone else? Just thought I would share.
The language file variable names need to relate properly to their counterparts in $full_menu, template file needs $menu_items in the appropriate place as well.

Code: Select all
class ControllerCommonMenu extends Controller { 
   protected function index() {
        $this->load->language('common/menu');

      $this->data['text_help'] = $this->language->get('text_help');
      $this->data['text_support'] = $this->language->get('text_support');
         $this->data['text_documentation'] = $this->language->get('text_documentation');
      $this->data['text_opencart'] = $this->language->get('text_opencart');
      
      $full_menu = array(
         'admin' => array(
            'common/home',
            'shop',
            'configuration' => array(
               'setting/setting',
               'users' => array(
                  'user/user',
                  'user/user_permission'
               ),
               'localisation' => array(
                  'localisation/language',
                  'localisation/currency',
                  'localisation/stock_status',
                  'localisation/order_status',
                  'localisation/country',
                  'localisation/zone',
                  'localisation/geo_zone',
                  'localisation/tax_class',
                  'localisation/measurement_class',
                  'localisation/weight_class'
               ),
               'tool/error_log',
               'tool/backup'
            ),
            'common/logout'
         ),
         'catalog' => array(
            'catalog/category',
            'catalog/product',
            'catalog/manufacturer',
            'catalog/download',
            'catalog/review',
            'catalog/information',
            'catalog/featured'
         ),
         'extension' => array(
            'extension/module',
            'extension/shipping',
            'extension/payment',
            'extension/total',
            'extension/feed'
         ),
         'customers' => array(
            'customer/customer',
            'customer/customer_group',
            'customer/order',
            'customer/coupon',
            'customer/contact'
         ),
         'reports' => array(
            'report/sale',
            'report/viewed',
            'report/purchased'
         )
      );
      
      $this->data['menu_items'] = $this->outputMenu($full_menu);
      
      $this->data['logged'] = $this->user->isLogged();
      
      $this->id       = 'menu';
      $this->template = 'common/menu.tpl';
         
         $this->render();
     }
     
     function outputMenu($array, $level = 1, $output = "") {
      if (is_array($array)) {
         foreach ($array as $key => $value) {
            if (is_array($value)) {
               if ($level == 1) {
                  $parent = '<li id="' . $key . '"><a class="top">' . $this->language->get('text_' . $key) . '</a><ul>' . "\n";
               }
               else {
                  $parent = '<li><a class="parent">' . $this->language->get('text_' . $key) . '</a><ul>' . "\n";
               }
               $newoutput = $this->outputMenu($value, 2, $output);
               if ($newoutput != $output) {
                  $output .= $parent;
                  $output = $this->outputMenu($value, 2, $output);
                  $output .= "</ul></li>" . "\n";
               }
            }
            elseif ($value == 'shop') {
               $output .= '<li><a href="' . HTTP_CATALOG . '">' . $this->language->get('text_shop') . '</a></li>' . "\n";
            }
            elseif ($value == 'common/home' || $value == 'common/logout') {
               $part = explode('/', $value);
               $output .= '<li><a href="' . $this->url->http($value) . '">' . $this->language->get('text_' . @$part[1]) . '</a></li>' . "\n";
            }
            else {
               $part = explode('/', $value);
               if ($this->user->hasPermission('access', @$part[0] . '/' . @$part[1])) {
                  $output .= '<li><a href="' . $this->url->http($value) . '">' . $this->language->get('text_' . @$part[1]) . '</a></li>' . "\n";
               }
            }
         }
      }
      return $output;
   }
}


Comments/critique?
hazpotts
 
Posts: 4
Joined: Mon Feb 08, 2010 12:41 pm

Re: Admin Menu Controller

Postby hazpotts » Mon Feb 08, 2010 5:01 pm

Someone moved this thread, but I don't see that it is a General Support issue, it's a code snippet offering additional functionality... ???
Last edited by Qphoria on Mon Feb 08, 2010 5:27 pm, edited 1 time in total.
Reason: Agreed. We have a "move-happy" mod on staff. I've moved it to contributions now and change the title to mark the [MOD] status.
hazpotts
 
Posts: 4
Joined: Mon Feb 08, 2010 12:41 pm

Re: Admin Menu Controller

Postby i2Paq » Mon Feb 08, 2010 6:53 pm

hazpotts wrote:Someone moved this thread, but I don't see that it is a General Support issue, it's a code snippet offering additional functionality... ???


My bad, it was my intention to put it in the Contributions section but I made a mistake and could not find it anymore :-\

Thanks Q!
Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________
Our FREE search: Find your answer FAST!.

First Things First: Opencart Check List.
Documentation: Our Documentation section.
BUGs?: Known BUGS for All OC Versions.

Problemen met de BTW?: [How to] BTW + Verzend & betaalmethodes.
User avatar
i2Paq
Global Moderator
 
Posts: 9767
Joined: Mon Nov 09, 2009 11:00 am
Location: Winkel - The Netherlands

Re: [MOD] - 1.4.0 Admin Menu Controller Access Support

Postby DannyMacD » Fri Feb 19, 2010 4:47 pm

this is a great mod but im unsure where to install this? can you point me in the right direction please?

thank you :)
DannyMacD
 
Posts: 471
Joined: Thu Jun 25, 2009 10:39 pm

Re: [MOD] - 1.4.0 Admin Menu Controller Access Support

Postby hazpotts » Tue Mar 02, 2010 9:49 pm

admin > controller > common > menu.php

I didn't get a notification of your reply, hope this still helps!
hazpotts
 
Posts: 4
Joined: Mon Feb 08, 2010 12:41 pm

Re: [MOD] - 1.4.0 Admin Menu Controller Access Support

Postby Qphoria » Tue Mar 02, 2010 9:52 pm

There is no separate menu in 1.4.0 so i have no idea what this is for
Image Image
Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
User avatar
Qphoria
Administrator
 
Posts: 18210
Joined: Mon Jul 21, 2008 7:02 pm
Donate to Qphoria

Re: [MOD] - 1.4.0 Admin Menu Controller Access Support

Postby hazpotts » Thu Apr 15, 2010 11:18 am

I didn't label this 1.4.0, it was for 1.3.4, my bad for not putting that on though I guess, my first attempt to contribute to anything, go easy...

In 1.4.x it would be used in header.php, but I assume it would need editting, I will post an update, if someone could edit my orginal post with it when I do that would be great.
hazpotts
 
Posts: 4
Joined: Mon Feb 08, 2010 12:41 pm

Re: [MOD] - 1.4.0 Admin Menu Controller Access Support

Postby i2Paq » Thu Apr 15, 2010 12:09 pm

hazpotts wrote:I didn't label this 1.4.0, it was for 1.3.4, my bad for not putting that on though I guess, my first attempt to contribute to anything, go easy...

In 1.4.x it would be used in header.php, but I assume it would need editting, I will post an update, if someone could edit my orginal post with it when I do that would be great.



Changed the title to 1.3.4
Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________
Our FREE search: Find your answer FAST!.

First Things First: Opencart Check List.
Documentation: Our Documentation section.
BUGs?: Known BUGS for All OC Versions.

Problemen met de BTW?: [How to] BTW + Verzend & betaalmethodes.
User avatar
i2Paq
Global Moderator
 
Posts: 9767
Joined: Mon Nov 09, 2009 11:00 am
Location: Winkel - The Netherlands

Re: [MOD] - 1.3.4 Admin Menu Controller Access Support

Postby mfrerebeau » Wed Sep 01, 2010 5:32 pm

Hello,

I'm trying to do the same on 1.4.8b menu... But I don't get it on this forum...
Do you have a way to follow for do this ?
Or an other topic that I miss ??

I'm going to try to use this code
Code: Select all
this->user->hasPermission('access', '<the good right>')

in header.tpl and I'll see...
Single we go faster, together we go more away...
User avatar
mfrerebeau
 
Posts: 21
Joined: Fri Aug 13, 2010 9:29 am
Location: France

Re: [MOD] - 1.3.4 Admin Menu Controller Access Support

Postby DannyMacD » Sun Sep 05, 2010 7:37 pm

was there any luck getting this to work? i have now moved over to 1.4.9 and still would love this feature :)

thanks
DannyMacD
 
Posts: 471
Joined: Thu Jun 25, 2009 10:39 pm

Re: [MOD] - 1.3.4 Admin Menu Controller Access Support

Postby Mint_Sauce » Mon Sep 27, 2010 10:53 am

I would love to have this functionality too, thanks for the contribution.
Mint_Sauce
 
Posts: 12
Joined: Fri Sep 10, 2010 1:01 pm


Return to Modifications

Who is online

Users browsing this forum: No registered users and 11 guests

Hosted by Arvixe Web Hosting