Hi, could someone give me some ideas for the following:
I have 3 groups: A, B, and C.
I have 9 buttons on the Home page.
I want that when user A enters the Home page, they only see buttons 1, 2, 3...; when user B enters the Home page, they only see buttons 4, 5, and 6; and when user C enters the Home page, they only see buttons 7, 8, and 9.
I want to point out that this is only for the Home page, not for the links-navmenu, since there I need everyone to see all the buttons.
Is it only possible to do this through `/hooks/links-home`, or could I do it through a function in `header-extra` or `footer-extra`?
And I need it to look like the attached images. Could someone give me some ideas or tell me if it's possible?
Thanks
Show or hide Home page buttons according to group, but without hiding the links-navmenu.
Re: Show or hide Home page buttons according to group, but without hiding the links-navmenu.
Hello lramirez,
Inside
-Saymaad
Inside
hooks/header-extras.php post the following code, and adjust the groupMap and unmapped groups behavior as per your preference:Code: Select all
<?php
$script_name = basename($_SERVER['PHP_SELF']);
if($script_name == 'index.php'){
$mi = getMemberInfo();
$user_group = $mi['group'];
$is_admin = $mi['admin'];
?>
<script>
$j(function(){
var userGroup = <?php echo json_encode($user_group); ?>;
var isAdmin = <?php echo json_encode($is_admin ? 1 : 0); ?> === 1;
// === CONFIG: map your exact group and table names (spaces allowed).
// The script will convert "Sales Return" -> "#sales_return-tile" as per AppGini Convention
var groupMap = {
"Admins": [ ], // admins will see all tiles anyway
"A": ["1", "2", "3"],
"B": ["4", "5", "6"],
"C": ["7", "8", "9"]
};
// find candidate tiles: any element whose id ends with -tile but exclude nav/menu containers
var candidates = $j('[id$="-tile"]').filter(function(){
var $t = $j(this);
// exclude common nav/sidebar containers so navmenu remains untouched
if($t.closest('#navmenu, .navmenu, vertical-nav, .navbar').length) return false;
return true;
});
// if admin, show all and exit
if(isAdmin){
return;
}
// get allowed simple names for this group
var allowedNames = groupMap[userGroup] || [];
// If you want unmapped groups to see nothing, keep this behavior.
// If you prefer unmapped groups to see all, change the next block accordingly.
if(allowedNames.length === 0){
candidates.hide();
return;
}
// build selectors from allowedNames: replace spaces with underscores, prefix #, append -tile
var allowedSelectors = allowedNames.map(function(name){
var id = name.replace(/\s+/g, '_');
return '#' + id.toLowerCase() + '-tile';
});
// hide all candidates first
candidates.hide();
// show only those matching allowedSelectors; log missing selectors for debugging
allowedSelectors.forEach(function(sel){
try{
var matched = candidates.filter(sel);
if(matched.length) matched.show();
else if(window.console) console.warn('Homepage tile not found for selector', sel);
} catch(e){
if(window.console) console.warn('Invalid selector generated', sel, e);
}
});
});
</script>
<?php
} // end index.php check
?>Re: Show or hide Home page buttons according to group, but without hiding the links-navmenu.
Okay, I'll try it and see... thanks
Luis Ramirez R.
Re: Show or hide Home page buttons according to group, but without hiding the links-navmenu.
Excellent... thank you... it works very well... although I made a few minor adjustments according to my project... but it worked... great!

Luis Ramirez R.
Re: Show or hide Home page buttons according to group, but without hiding the links-navmenu.
There is also an excellent tutorial on this subject available on the Appgini blog:
https://blog.appgini.com/appgini/preven ... n-appgini/
https://blog.appgini.com/appgini/preven ... n-appgini/
