Post by hazpotts » Mon Feb 08, 2010 8: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?

Newbie

Posts

Joined
Mon Feb 08, 2010 8:41 pm

Post by hazpotts » Tue Feb 09, 2010 1:01 am

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 Tue Feb 09, 2010 1:27 am, 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.

Newbie

Posts

Joined
Mon Feb 08, 2010 8:41 pm

Post by i2Paq » Tue Feb 09, 2010 2:53 am

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!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by DannyMacD » Sat Feb 20, 2010 12:47 am

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

thank you :)

Active Member

Posts

Joined
Fri Jun 26, 2009 6:39 am

Post by hazpotts » Wed Mar 03, 2010 5:49 am

admin > controller > common > menu.php

I didn't get a notification of your reply, hope this still helps!

Newbie

Posts

Joined
Mon Feb 08, 2010 8:41 pm

Post by Qphoria » Wed Mar 03, 2010 5:52 am

There is no separate menu in 1.4.0 so i have no idea what this is for

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by hazpotts » Thu Apr 15, 2010 7:18 pm

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.

Newbie

Posts

Joined
Mon Feb 08, 2010 8:41 pm

Post by i2Paq » Thu Apr 15, 2010 8: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!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by mfrerebeau » Thu Sep 02, 2010 1:32 am

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
New member

Posts

Joined
Fri Aug 13, 2010 5:29 pm
Location - France

Post by DannyMacD » Mon Sep 06, 2010 3:37 am

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

thanks

Active Member

Posts

Joined
Fri Jun 26, 2009 6:39 am

Post by Mint_Sauce » Mon Sep 27, 2010 6:53 pm

I would love to have this functionality too, thanks for the contribution.

Newbie

Posts

Joined
Fri Sep 10, 2010 9:01 pm
Who is online

Users browsing this forum: Semrush [Bot] and 6 guests