07-14-2016, 12:47 PM
hi how can i hide link from side menu for a group of users
thank's
thank's
The following warnings occurred: | ||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
how to hide link
|
07-14-2016, 12:47 PM
hi how can i hide link from side menu for a group of users
thank's
07-14-2016, 01:29 PM
It sounds like you are wanting to use a negative logic. Here's how you need to think of this...
When you are on the admin dashboard, you see that there is a place at the top that says how many permission levels and you can manage them. When you click on manage them and click on administrator, you are taken to a page that shows you the id of that permission level. You're going to need that permission level id for your hiding feature. Normally, we SHOW links if someone is a permission level. In the regular navigation.php we have this setup to show the admin dashboard only to admins. Code: <?php if (checkMenu(2,$user->data()->id)){ //Links for permission level 2 (default admin) ?> Code: <?php } // is user an admin ?> In your case, you want to figure out which permission level you want to NOT show, let's say it's an id of 3. At the top of your navigation page in the custom php section, you need to write a query to check the db to see if your user is part of that particular permission group. Code: $id = $user->data()->id; Code: $permLev = 3; //the permission level you don't want to see the menu item. Code: $query = $db->query("SELECT * FROM user_permission_matches WHERE user_id = $id AND permission_id = $permLev"); Code: $amIbanned = $query->count(); //If this count comes back as 1, that user is part of the group. If zero, then not. So, now for your menu... Code: <?php if $amIbanned = 0 { ?> Code: <?php } ?> If that's not exactly it, it's really close. There might be a different way to do it, but I don't think the checkmenu helper function can be turned around in reverse.
07-15-2016, 10:57 AM
Got It, Thank you.
10-05-2016, 04:18 AM
ejaw you find the solution ?
11-02-2016, 01:51 PM
I added this function to us_helpers
/*************************************/ function checkLinkAccess($id,$page_id) { $db = DB::getInstance(); global $user; //Grant access if master user $access = 0; if ($access == 0){ $query = $db->query("SELECT user_permission_matches.user_id FROM user_permission_matches LEFT JOIN permission_page_matches ON permission_page_matches.permission_id = user_permission_matches.permission_id WHERE permission_page_matches.page_id='$page_id' AND user_permission_matches.user_id='$id'"); $results = $query->count(); if($results>0){ return true; }else{ return false; } } } /**********************/ then i use : <?php if(checkLinkAccess($user->data()->id,'83')) { ?> [*] link1 <?php } ?> 83 is the page ID
11-07-2016, 12:39 AM
Ideally you want to make these changes in usersc/includes/custom_functions.php
We update the us_helpers.php file pretty often with bug fixes and new features. Copying that function over there won't affect its performance.
03-14-2017, 10:13 PM
is this great but how can i show some links if the user is not longed in
thanks sire
03-15-2017, 04:22 AM
Sure...so if you want to show a link (or anything) only if the user is logged in, wrap the whole thing in this.
Code: if($user->isLoggedIn()){ Code: //your code here Code: } // close if statement. You can also do Code: if(!$user->isLoggedIn()){ Code: //your code here Code: } If you only want to show code to users who are not logged in.
03-19-2017, 05:37 AM
ok i am trying to have the nav bar to show different links to the different permission groups
like admin, user, and gest
03-19-2017, 07:20 AM
sire, check the original navigation.php file. There you have <php> code for showing content only to certain groups (like showing admin dashboard only to admins)
Code: <pre> Code: <!-- Here goes navigation for every visitor (logged, not logged, admins, not admins... --> This code should be somewhat familiar with navigation.php. Try to add yourself <ul> and <li> classes and check if you can get the navigation you want. You should only change the navigation.php file in usersc/includes folder NOT in users/includes! Also check bootstrap navbar to see how you can easily make navigation with buttons, links, dropdown menus and combine these two codes together. |