This forum is archived. Posts are preserved for historical reference. For current help, join us on Discord.

how to hide link

In Documentation · Started by ejaw on 2016-07-14 12:47 pm · 33316 views · 14 replies

hi how can i hide link from side menu for a group of users
thank's
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.
<?php if (checkMenu(2,$user->data()->id)){  //Links for permission level 2 (default admin) ?>
//whatever you want to show
<?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.
$id = $user->data()->id;
$permLev = 3; //the permission level you don't want to see the menu item.
$query = $db->query("SELECT * FROM user_permission_matches  WHERE user_id = $id AND permission_id = $permLev");
$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...
<?php if $amIbanned = 0 { ?>
menu link here
<?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.


Got It, Thank you.
ejaw you find the solution ?
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
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.
is this great but how can i show some links if the user is not longed in


thanks
sire
Sure...so if you want to show a link (or anything) only if the user is logged in, wrap the whole thing in this.
if($user->isLoggedIn()){
//your code here
}  // close if statement.

You can also do
if(!$user->isLoggedIn()){
//your code here
}

If you only want to show code to users who are not logged in.
ok i am trying to have the nav bar to show different links to the different permission groups
like admin, user, and gest
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>
<!-- Here goes navigation for every visitor (logged, not logged, admins, not admins... -->

<!--------------------------------------------------------------------------------------->
<?php if($user->isLoggedIn()){?>
   <!-- Here goes navigation only for logged visitors ----------------------------------->

   <!------------------------------------------------------------------------------------>
   
   <?php if (checkMenu(2,$user->data()->id)){?>
      <!-- Here goes navigation only for admins (visitors with permission level 2) ------>

      <!--------------------------------------------------------------------------------->
   <?php }?>

   <?php if (checkMenu(1,$user->data()->id)){?>
      <!-- Here goes navigation only for users (visitors with permission level 1) ------->

      <!--------------------------------------------------------------------------------->
   <?php }?>
<?php }else{?>
   <!-- Here goes navigation only for users who are not logged in ----------------------->

   <!------------------------------------------------------------------------------------>
<?php }?>
</pre>


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.
Ok, can't modify post above with correct image.

thanks Jug

its just giving me the err

Parse error: syntax error, unexpected 'else' (T_ELSE) in (weblinkhere) on line 20
Nope. I believe code is OK. Have you tried to implement it on your userspice?

Otherwise, just delete else{ from the line 20 and everything below line 20 and check again.
i did what you said now it says

Parse error: syntax error, unexpected end of file in ...navigation.php on line 52

this is the ennd of the pages
<pre>
    <!-- End left navigation items -->

    <?php
?>
</pre>
ok i got it to work i found out i had <?php {?> and not <?php }?> (i had to talk to my duck)
thank you jug !!