Show or hide Home page buttons according to group, but without hiding the links-navmenu.

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
lramirez
Veteran Member
Posts:114
Joined: 2019-11-01 23:23

Show or hide Home page buttons according to group, but without hiding the links-navmenu.

Post by lramirez » 2025-12-10 22:45

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?
n1.png
n1.png (33.11 KiB) Viewed 3974 times
n2.png
n2.png (12.04 KiB) Viewed 3974 times
n3.png
n3.png (60.4 KiB) Viewed 3974 times
Thanks
Luis Ramirez R.

saymaad
AppGini Super Hero
AppGini Super Hero
Posts:131
Joined: 2024-06-03 16:17

Re: Show or hide Home page buttons according to group, but without hiding the links-navmenu.

Post by saymaad » 2025-12-11 04:04

Hello lramirez,

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
?>
-Saymaad

User avatar
lramirez
Veteran Member
Posts:114
Joined: 2019-11-01 23:23

Re: Show or hide Home page buttons according to group, but without hiding the links-navmenu.

Post by lramirez » 2025-12-11 13:55

Okay, I'll try it and see... thanks
Luis Ramirez R.

User avatar
lramirez
Veteran Member
Posts:114
Joined: 2019-11-01 23:23

Re: Show or hide Home page buttons according to group, but without hiding the links-navmenu.

Post by lramirez » 2026-01-14 02:28

Excellent... thank you... it works very well... although I made a few minor adjustments according to my project... but it worked... great! :D :D :D
Luis Ramirez R.

peebee
AppGini Super Hero
AppGini Super Hero
Posts:367
Joined: 2013-03-21 04:37

Re: Show or hide Home page buttons according to group, but without hiding the links-navmenu.

Post by peebee » 2026-01-14 23:27

There is also an excellent tutorial on this subject available on the Appgini blog:

https://blog.appgini.com/appgini/preven ... n-appgini/

Post Reply