function print_channels($permissions, $inheritance = array(), $channels = false, $indent = '	')
{
    global $vbulletin, $imodcache, $npermscache, $vbphrase;
    if ($channels === false) {
        $channels = vB_Api::instanceInternal('search')->getChannels(false, array('include_protected' => true, 'no_perm_check' => true));
    }
    foreach ($channels as $nodeid => $node) {
        // make a copy of the current permissions set up
        $perms = $permissions;
        // make a copy of the inheritance set up
        $inherit = $inheritance;
        // echo channel title and links
        if (!defined('ONLYID') or $nodeid == ONLYID) {
            echo "{$indent}<ul class=\"lsq\">\n";
            echo "{$indent}<li><b><a name=\"node{$nodeid}\" href=\"forum.php?" . vB::getCurrentSession()->get('sessionurl') . "do=edit&amp;n={$nodeid}\">{$node['htmltitle']}</a></b>";
            if ($node['parentid'] != 0) {
                echo " <b><span class=\"smallfont\">(" . construct_link_code($vbphrase['reset'], "forumpermission.php?" . vB::getCurrentSession()->get('sessionurl') . "do=quickset&amp;type=reset&amp;n={$nodeid}&amp;hash=" . CP_SESSIONHASH) . construct_link_code($vbphrase['deny_all'], "forumpermission.php?" . vB::getCurrentSession()->get('sessionurl') . "do=quickset&amp;type=deny&amp;n={$nodeid}&amp;hash=" . CP_SESSIONHASH) . ")</span></b>";
            }
            // get moderators
            if (is_array($imodcache["{$nodeid}"])) {
                echo "<span class=\"smallfont\"><br /> - <i>" . $vbphrase['moderators'] . ":";
                foreach ($imodcache["{$nodeid}"] as $moderator) {
                    // moderator username and links
                    echo " <a href=\"moderator.php?" . vB::getCurrentSession()->get('sessionurl') . "do=edit&amp;moderatorid={$moderator['moderatorid']}\">{$moderator['username']}</a>";
                }
                echo "</i></span>";
            }
            echo "{$indent}\t<ul class=\"usergroups\">\n";
        }
        $nplink = "";
        foreach ($vbulletin->usergroupcache as $usergroupid => $usergroup) {
            if ($inherit["{$usergroupid}"] == 'col-c') {
                $inherit["{$usergroupid}"] = 'col-i';
            }
            // if there is a custom permission for the current usergroup, use it
            if (isset($npermscache["{$nodeid}"]["{$usergroupid}"]) and $node['parentid'] != 0 and vB_ChannelPermission::compareDefaultChannelPermissions($nodeid, $usergroupid, $npermscache["{$nodeid}"]["{$usergroupid}"])) {
                $inherit["{$usergroupid}"] = 'col-c';
                $perms["{$usergroupid}"] = $npermscache[$nodeid][$usergroupid]['forumpermissions'];
                $nplink = 'np=' . $npermscache[$nodeid][$usergroupid]['permissionid'];
            } else {
                $nplink = "n={$nodeid}&amp;u={$usergroupid}";
            }
            // work out display style
            $liStyle = '';
            if (isset($inherit["{$usergroupid}"])) {
                $liStyle = " class=\"{$inherit[$usergroupid]}\"";
            } else {
                $liStyle = " class=\"col-g\"";
            }
            if (!($perms["{$usergroupid}"] & $vbulletin->bf_ugp_forumpermissions['canview'])) {
                $liStyle .= " style=\"list-style:circle\"";
            }
            if (!defined('ONLYID') or $nodeid == ONLYID) {
                echo "{$indent}\t<li{$liStyle}>" . construct_link_code($vbphrase['edit'], "forumpermission.php?" . vB::getCurrentSession()->get('sessionurl') . "do=edit&amp;{$nplink}") . $usergroup['title'] . "</li>\n";
            }
        }
        if (!defined('ONLYID') or $nodeid == ONLYID) {
            echo "{$indent}\t</ul><br />\n";
        }
        if (defined('ONLYID') and $nodeid == ONLYID) {
            echo "{$indent}</li>\n";
            echo "{$indent}</ul>\n";
            return;
        }
        if (!empty($node['channels'])) {
            print_channels($perms, $inherit, $node['channels'], "{$indent}\t");
        }
        if (!defined('ONLYID') or $nodeid == ONLYID) {
            echo "{$indent}</li>\n";
        }
        unset($inherit);
        if (!defined('ONLYID') or $nodeid == ONLYID) {
            echo "{$indent}</ul>\n";
        }
        if (!defined('ONLYID') and $node['parentid'] == -1) {
            echo "<hr size=\"1\" />\n";
        }
    }
}
Example #2
0
function print_channels($parentid = 0, $indent = "\t")
{
    global $vbulletin, $imodcache, $accesscache, $vbphrase;
    // check to see if we need to do the queries
    if (!is_array($imodcache)) {
        require_once DIR . '/includes/functions_forumlist.php';
        cache_moderators();
    }
    if ($parentid === 0) {
        $channels = vB_Api::instanceInternal('search')->getChannels(false);
    } else {
        $channels = vB_Api::instanceInternal('search')->getChannels(true);
        if (empty($channels["{$parentid}"]) or empty($channels["{$parentid}"]['channels'])) {
            return;
        }
        $channels = $channels["{$parentid}"]['channels'];
    }
    // check to see if this channel actually exists / has children
    foreach ($channels as $nodeid => $node) {
        echo "{$indent}<ul class=\"lsq\">\n";
        // node title and links
        echo "{$indent}<li><b><a name=\"node{$nodeid}\" href=\"forum.php?" . vB::getCurrentSession()->get('sessionurl') . "do=edit&amp;n={$nodeid}\">{$node['htmltitle']}</a> <span class=\"smallfont\">(" . construct_link_code($vbphrase['reset'], "accessmask.php?" . vB::getCurrentSession()->get('sessionurl') . "do=resetchannel&amp;n={$nodeid}&amp;hash=" . CP_SESSIONHASH) . ")</span></b>";
        // get moderators
        if (is_array($imodcache["{$nodeid}"])) {
            echo "<span class=\"smallfont\"><br /> - <i>" . $vbphrase['moderators'] . ":";
            foreach ($imodcache["{$nodeid}"] as $moderator) {
                // moderator username and links
                echo " <a href=\"moderator.php?" . vB::getCurrentSession()->get('sessionurl') . "do=edit&amp;moderatorid={$moderator['moderatorid']}\">{$moderator['username']}</a>";
            }
            echo "</i></span>";
        }
        $allaccessmasks = 0;
        $forbidden = '';
        $permitted = '';
        $deny = $accesscache["{$nodeid}"]['0'];
        $permit = $accesscache["{$nodeid}"]['1'];
        /*echo "<pre>--$nodeid--\n";
        		print_r($accesscache["$nodeid"]);
        		echo '</pre>';*/
        if (is_array($deny)) {
            $forbidden = "{$indent}\t<li class=\"am-deny\"><b>" . construct_phrase($vbphrase['access_denied_x_users'], $deny['count']) . '</b>' . construct_link_code($vbphrase['display_users'], "accessmask.php?" . vB::getCurrentSession()->get('sessionurl') . "&do=edit&n={$nodeid}&accessmask={$deny['accessmask']}") . "</li>\n";
            $allaccessmasks = $deny['count'];
        }
        if (is_array($permit)) {
            $permitted = "{$indent}\t<li class=\"am-grant\"><b>" . construct_phrase($vbphrase['access_granted_x_users'], $permit['count']) . '</b>' . construct_link_code($vbphrase['display_users'], "accessmask.php?" . vB::getCurrentSession()->get('sessionurl') . "&do=edit&n={$nodeid}&accessmask={$permit['accessmask']}") . "</li>\n";
            $allaccessmasks = $allaccessmasks + $permit['count'];
        }
        if ($allaccessmasks > 0) {
            echo "{$indent}\t<ul class=\"usergroups\">\n";
            echo "{$indent}\t<li>" . construct_phrase($vbphrase['x_access_masks_set'], $allaccessmasks) . ' ' . construct_link_code('<b>' . $vbphrase['display_all_users'] . '</b>', "accessmask.php?" . vB::getCurrentSession()->get('sessionurl') . "&do=edit&n={$nodeid}&accessmask=2") . "</li>";
            echo $permitted;
            echo $forbidden;
            echo "{$indent}\t</ul><br />\n";
        } else {
            echo "{$indent}\t\n";
            echo "{$indent}\t<br />\n";
        }
        print_channels($nodeid, "{$indent}\t");
        echo "{$indent}</li>\n";
        echo "{$indent}</ul>\n";
        if ($node['parentid'] == 0) {
            echo "<hr size=\"1\" />\n";
        }
    }
}