Page 1 of 1

[MOD] - 1.3.4 Admin Menu Controller Access Support

Posted: Mon Feb 08, 2010 8:48 pm
by hazpotts
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?

Re: Admin Menu Controller

Posted: Tue Feb 09, 2010 1:01 am
by hazpotts
Someone moved this thread, but I don't see that it is a General Support issue, it's a code snippet offering additional functionality... ???

Re: Admin Menu Controller

Posted: Tue Feb 09, 2010 2:53 am
by i2Paq
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!

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

Posted: Sat Feb 20, 2010 12:47 am
by DannyMacD
this is a great mod but im unsure where to install this? can you point me in the right direction please?

thank you :)

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

Posted: Wed Mar 03, 2010 5:49 am
by hazpotts
admin > controller > common > menu.php

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

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

Posted: Wed Mar 03, 2010 5:52 am
by Qphoria
There is no separate menu in 1.4.0 so i have no idea what this is for

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

Posted: Thu Apr 15, 2010 7:18 pm
by hazpotts
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.

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

Posted: Thu Apr 15, 2010 8:09 pm
by i2Paq
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

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

Posted: Thu Sep 02, 2010 1:32 am
by mfrerebeau
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...

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

Posted: Mon Sep 06, 2010 3:37 am
by DannyMacD
was there any luck getting this to work? i have now moved over to 1.4.9 and still would love this feature :)

thanks

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

Posted: Mon Sep 27, 2010 6:53 pm
by Mint_Sauce
I would love to have this functionality too, thanks for the contribution.