Post by ollie007 » Fri Jun 24, 2011 9:40 pm

How to check that the person logged into Admin is in particular usergroup?
<?php if ($user_groups) { ?>
<?php foreach ($user_groups as $user_group) { ?>

<?php echo $user_group['user_group_id']== ??????? ; ?>

New member

Posts

Joined
Fri Jun 10, 2011 1:56 am

Post by fido-x » Sat Jun 25, 2011 12:52 pm

If you want to find out which user group a logged in user is a member of, you will need to add a new db query to the model, as there is no query there for the purpose.

Add the following to the end of "admin/model/user/user.php":

Code: Select all

public function getUserGroup($user_id) {
    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "user u LEFT JOIN " . DB_PREFIX . "user_group ug ON (u.user_group_id = ug.user_group_id) WHERE u.user_id = '" . (int)$user_id . "'");
    return $query->row['name'];
} 
Then, in the controller of the file you wish to display this information (eg. for the dashboard page this is "admin/controller/common/home.php"), insert the following:

Code: Select all

$this->load->model('user/user');
$this->data['user_group'] = $this->model_user_user->getUserGroup($this->user->getId()); 
Then, in the template file (admin/view/template/common/home.tpl), you can use:

Code: Select all

<?php echo $user_group; ?>
to display the name of the user group the logged in user is a member of.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by ollie007 » Sat Jun 25, 2011 1:21 pm

but the person logged in has to be checked to verify whether he can see the admin functions or not?

i just want to hide the menus for people in groups not admin

if there is no query for that how can i grab the name of the logged in user??

eg if logged in user is "administrator" show all menus in template....if logged in user is in vendor group, show catalogue and sales ONLY?

New member

Posts

Joined
Fri Jun 10, 2011 1:56 am

Post by fido-x » Sat Jun 25, 2011 1:43 pm

Ah right, I see. Your original question gets answered, but you're not happy with that answer, so you change the question.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by rph » Sat Jun 25, 2011 2:16 pm

No good deed goes unpunished. ;)

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by fido-x » Sat Jun 25, 2011 2:47 pm

OK, forget what I posted before.

Make a copy of your "admin/view/template/common/header.tpl" and remove the links to items you don't want the "non-top admin" users to see.

Insert this query into the model (admin/model/user/user.php):

Code: Select all

public function getUserGroupId($user_id) {
    $query = $this->db->query("SELECT DISTINCT user_group_id FROM " . DB_PREFIX . "user WHERE user_id = '" . (int)$user_id . "'");
    return $query->row['user_group_id'];
} 
Then in "admin/controller/header.php", find the following:

Code: Select all

$this->template = 'common/header.tpl'; 
and replace with:

Code: Select all

$this->load->model('user/user');
if ($this->model_user_user->getUserGroupId($this->user->getId()) == 1) {
    $this->template = 'common/header.tpl';
} else {
    $this->template = 'common/new_header.tpl';
} 

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by ollie007 » Sat Jun 25, 2011 3:04 pm

ok, thanks

i give it a shot tonight ;)

New member

Posts

Joined
Fri Jun 10, 2011 1:56 am

Post by ollie007 » Sat Jun 25, 2011 3:10 pm

there has gotta BE AN EASIER way than that lol

how about with an "IF" statement and catching the session for the logged in usergroup?

New member

Posts

Joined
Fri Jun 10, 2011 1:56 am

Post by mberlant » Sat Jun 25, 2011 7:55 pm

Is there a reason that the advice rendered more than two months ago in this post did not work for the OP? If so, why not post the discrepancy there instead of in a new thread? If not, why not use the Search (Search for "admin hide permission".) button first?

Please use proper English at all times, so that all members may understand you.


User avatar
Active Member

Posts

Joined
Sun Mar 13, 2011 8:33 pm

Post by brunobrunobruno » Sat Feb 02, 2013 2:31 am

Thanks fido-x , helps me a lot , thank you very much


Posts

Joined
Wed Jan 23, 2013 10:09 pm
Who is online

Users browsing this forum: Amazon [Bot] and 10 guests