The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to hide link
#1
hi how can i hide link from side menu for a group of users
thank's
  Reply
#2
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) ?>
//whatever you want to show
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 { ?>
menu link here
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.


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


thanks
sire
  Reply
#8
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.
  Reply
#9
ok i am trying to have the nav bar to show different links to the different permission groups
like admin, user, and gest
  Reply
#10
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)

[Image: Navigation.PNG?dl=0]

Code:
<pre>
Code:
<!-- 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.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)