function print_channel_permission_rows($customword, $channelpermission = array(), $extra = '')
{
    global $vbphrase;
    print_label_row("<b>{$customword}</b>", '
		<input type="button" class="button" value="' . $vbphrase['all_yes'] . '" onclick="' . iif($extra != '', 'if (js_set_custom()) { ') . ' js_check_all_option(this.form, 1);' . iif($extra != '', ' }') . '" class="button" />
		<input type="button" class="button" value=" ' . $vbphrase['all_no'] . ' " onclick="' . iif($extra != '', 'if (js_set_custom()) { ') . ' js_check_all_option(this.form, 0);' . iif($extra != '', ' }') . '" class="button" />
		<!--<input type="submit" class="button" value="Okay" class="button" />-->
	', 'tcat', 'middle');
    // Load permissions
    require_once DIR . '/includes/class_bitfield_builder.php';
    $bitvalues = array('forumpermissions', 'forumpermissions2', 'moderatorpermissions', 'createpermissions');
    $permFields = vB_ChannelPermission::fetchPermFields();
    $permPhrases = vB_ChannelPermission::fetchPermPhrases();
    if (empty($channelpermission)) {
        // we need the defaults to be displayed
        $channelpermission = vB_ChannelPermission::instance()->fetchPermissions(1);
        $channelpermission = current($channelpermission);
    }
    foreach ($permFields as $permField => $type) {
        //Do the non-bitmap fields first.
        switch ($type) {
            case vB_ChannelPermission::TYPE_HOURS:
            case vB_ChannelPermission::TYPE_COUNT:
                $permvalue = $channelpermission[$permField];
                print_input_row($vbphrase[$permPhrases[$permField]], $permField, $permvalue, true, 35, 0, '', false, 'channelPerm_' . $permField);
                break;
            case vB_ChannelPermission::TYPE_BOOL:
                $permvalue =& $channelpermission[$permField];
                print_yes_no_row($vbphrase[$permPhrases[$permField]], $permField, $permvalue, $extra);
                break;
        }
    }
    //now do the bitmaps
    foreach ($permFields as $permField => $type) {
        if ($type == vB_ChannelPermission::TYPE_BITMAP) {
            if ($permField !== 'forumpermissions2') {
                print_table_header($vbphrase[$permPhrases[$permField]]);
            }
            foreach ($channelpermission['bitfields'][$permField] as $permBit) {
                if ($permBit['used']) {
                    if (empty($permBit['phrase']) and $permField == 'moderatorpermissions') {
                        $permBit['phrase'] = "moderator_add_edit_" . $permBit['name'] . "_title";
                    }
                    if ($permField == 'moderatorpermissions' and $permBit['name'] == 'canopenclose') {
                        $helpOptions = array('prefix' => $permField);
                    } else {
                        $helpOptions = array();
                    }
                    print_yes_no_row(isset($vbphrase[$permBit['phrase']]) ? $vbphrase[$permBit['phrase']] : $permBit['phrase'], $permField . '[' . $permBit['name'] . ']', $permBit['set'], $extra, $helpOptions);
                }
            }
        }
    }
    // Legacy Hook 'admin_nperms_form' Removed //
}
 /**
  * Returns singleton instance of self.
  *
  * @return vB_ChannelPermission		- Reference to singleton instance of the type handler
  */
 public static function instance()
 {
     if (!isset(self::$instance)) {
         $class = __CLASS__;
         self::$instance = new $class();
     }
     return self::$instance;
 }
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";
        }
    }
}
Esempio n. 4
0
    $siteLibrary->saveHeaderNavbar(1, $siteNavs);
    $ug_bitfield['createpermissions']['vbforum_channel'] = $ugpermissions['forumpermissions']['cancreateblog'];
    vB_ChannelPermission::instance()->setPermissions($blogChannel, $resultUg, $ug_bitfield);
    /*
     * End of section 'create channel' for blog/socialgroup
     */
    // Album channel
    $albumChannel = vB_Api::instanceInternal('node')->fetchAlbumChannel();
    $albumPerms = vB_ChannelPermission::instance()->fetchPermissions($albumChannel, $resultUg);
    $bitfields = vB_ChannelPermission::instance()->fetchPermSettings();
    if ($ugpermissions['albumpermissions']['canviewalbum']) {
        $albumPerms[$resultUg]['forumpermissions'] |= intval($bitfields['forumpermissions']['canview']['value']);
    } else {
        $albumPerms[$resultUg]['forumpermissions'] &= ~intval($bitfields['forumpermissions']['canview']['value']);
    }
    vB_ChannelPermission::instance()->setPermissions($albumChannel, $resultUg, $albumPerms[$resultUg]);
    print_stop_message2(array('saved_usergroup_x_successfully', htmlspecialchars_uni($vbulletin->GPC['usergroup']['title'])), 'usergroup', array('do' => 'modify'));
}
// ###################### Start Remove #######################
if ($_REQUEST['do'] == 'remove') {
    if ($vbulletin->GPC['usergroupid'] < 8) {
        print_stop_message2('cant_delete_usergroup');
    } else {
        print_delete_confirmation('usergroup', $vbulletin->GPC['usergroupid'], 'usergroup', 'kill', 'usergroup', 0, construct_phrase($vbphrase['all_members_of_this_usergroup_will_revert'], $vbulletin->usergroupcache['2']['title']));
    }
}
// ###################### Start Kill #######################
if ($_POST['do'] == 'kill') {
    vB_Api::instanceInternal('usergroup')->delete($vbulletin->GPC['usergroupid']);
    print_stop_message2('deleted_usergroup_successfully', 'usergroup', array('do' => 'modify'));
}
Esempio n. 5
0
 protected function import()
 {
     if (empty($this->parsedXML['channel'])) {
         $this->parsedXML['channel'] = array();
     }
     $this->checkRoutes();
     $this->checkParents();
     $channels = is_array($this->parsedXML['channel'][0]) ? $this->parsedXML['channel'] : array($this->parsedXML['channel']);
     //On an upgrade from Pre-vB5 the datastore won't exist yet. So we can't get the bitfields from there.
     $parsedRaw = vB_Xml_Import::parseFile(DIR . '/includes/xml/bitfield_vbulletin.xml');
     $forumpermissions = $forumpermissions2 = $moderatorpermissions = $createpermissions = $adminpermissions = $albumpermissions = $socialgrouppermissions = array();
     foreach ($parsedRaw['bitfielddefs']['group'] as $group) {
         if ($group['name'] == 'ugp') {
             foreach ($group['group'] as $bfgroup) {
                 switch ($bfgroup['name']) {
                     case 'forumpermissions':
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $forumpermissions[$bitfield['name']] = intval($bitfield['value']);
                         }
                         break;
                     case 'forumpermissions2':
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $forumpermissions2[$bitfield['name']] = intval($bitfield['value']);
                         }
                         break;
                     case 'adminpermissions':
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $adminpermissions[$bitfield['name']] = intval($bitfield['value']);
                         }
                         break;
                     case 'albumpermissions':
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $albumpermissions[$bitfield['name']] = intval($bitfield['value']);
                         }
                         break;
                     case 'createpermissions':
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $createpermissions[$bitfield['name']] = intval($bitfield['value']);
                         }
                         break;
                     case 'socialgrouppermissions':
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $socialgrouppermissions[$bitfield['name']] = intval($bitfield['value']);
                         }
                 }
             }
         } else {
             if ($group['name'] == 'misc') {
                 foreach ($group['group'] as $bfgroup) {
                     if ($bfgroup['name'] == 'moderatorpermissions') {
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $moderatorpermissions[$bitfield['name']] = intval($bitfield['value']);
                         }
                     }
                 }
             }
         }
     }
     $this->bf_administratorpermissions = $adminpermissions;
     $this->bf_moderatorpermissions = $moderatorpermissions;
     $this->bf_forumpermissions = $forumpermissions;
     $this->bf_forumpermissions2 = $forumpermissions2;
     $this->bf_albumpermissions = $albumpermissions;
     $this->bf_socialgrouppermissions = $socialgrouppermissions;
     $this->contenttypes = $createpermissions;
     $usergroups = vB::getDbAssertor()->assertQuery('usergroup', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT));
     foreach ($usergroups as $usergroup) {
         if ($usergroup['systemgroupid'] == vB_Api_UserGroup::CHANNEL_MEMBER_SYSGROUPID) {
             $blogMemberGroupId = $usergroup['usergroupid'];
         } else {
             if ($usergroup['systemgroupid'] == vB_Api_UserGroup::CHANNEL_MEMBER_SYSGROUPID) {
                 $sgMemberGroupId = $usergroup['usergroupid'];
             } else {
                 if ($usergroup['systemgroupid'] == vB_Api_UserGroup::CHANNEL_OWNER_SYSGROUPID) {
                     $channelOwnerGroupId = $usergroup['usergroupid'];
                 }
             }
         }
     }
     $registeredGroupId = 2;
     $unRegisteredGroupId = 1;
     $rootPerms = $this->buildRootPerms();
     $sgperms = array();
     foreach ($rootPerms as $ug => $value) {
         foreach ($value as $perms => $bitvalue) {
             if ($perms === 'socialgrouppermissions') {
                 $sgperms[$ug]['socialgrouppermissions'] = $bitvalue;
                 unset($rootPerms[$ug]['socialgrouppermissions']);
                 break;
             }
         }
     }
     $channelLib = vB_Library::instance('content_channel');
     $channelPerm = vB_ChannelPermission::instance();
     foreach ($channels as $channel) {
         if (isset($channel['installonly'])) {
             if (defined('VB_AREA') and VB_AREA != 'Install' and $channel['installonly']) {
                 // this channel is only added during install, so skip it
                 continue;
             }
             unset($channel['installonly']);
         }
         $data = array_merge($channel, $channel['node']);
         unset($data['node']);
         if (isset($channel['node']['routeguid']) and isset($this->referencedRoutes[$channel['node']['routeguid']])) {
             $data['routeid'] = $this->referencedRoutes[$channel['node']['routeguid']];
         }
         if (isset($channel['node']['parentguid']) and !empty($channel['node']['parentguid']) and ($parentId = $this->referencedParents[$channel['node']['parentguid']] or $parentId = vB_Xml_Import::getImportedId(vB_Xml_Import::TYPE_CHANNEL, $channel['node']['parentguid']))) {
             $data['parentid'] = $parentId;
         }
         $channelId = 0;
         $condition = array('guid' => $channel['guid']);
         // TODO: after talking with Ed, we decided it might be best not to allow node removal at all. Need to confirm with Kevin
         if ($oldChannel = $this->db->getRow('vBForum:channel', $condition)) {
             $channelId = $oldChannel['nodeid'];
         }
         if (empty($channelId)) {
             // We cannot use the API method for adding the root channel, since it requires a parentid.
             if (!isset($data['parentid'])) {
                 $channelContentTypeId = vB_Api::instanceInternal('contenttype')->fetchContentTypeIdFromClass('Channel');
                 $userId = vB::getCurrentSession()->get('userid');
                 // get all columns but the key
                 $channelTable = $this->db->fetchTableStructure('vbforum:channel');
                 $channelTableColumns = array_diff($channelTable['structure'], array($channelTable['key']));
                 $nodeTable = $this->db->fetchTableStructure('vbforum:node');
                 $nodeTableColumns = array_diff($nodeTable['structure'], array($nodeTable['key'], $channelTable['key']));
                 // insert root node
                 $nodeValues = array('userid' => $userId, 'contenttypeid' => $channelContentTypeId);
                 foreach ($nodeTableColumns as $col) {
                     if (isset($channel['node'][$col])) {
                         $nodeValues[$col] = $channel['node'][$col];
                     }
                 }
                 if (isset($data['routeid'])) {
                     $nodeValues['routeid'] = $data['routeid'];
                 }
                 $channelId = $this->db->insertIgnore('vBForum:node', $nodeValues);
                 if (is_array($channelId)) {
                     $channelId = array_pop($channelId);
                 }
                 // continue only if the node could be inserted
                 if ($channelId) {
                     $values = array();
                     foreach ($channelTableColumns as $col) {
                         if (isset($channel[$col])) {
                             $values[$col] = $channel[$col];
                         }
                     }
                     $values['nodeid'] = $channelId;
                     $this->db->insert('vBForum:channel', $values);
                 }
                 // insert in closure
                 $this->db->insert('vBForum:closure', array('parent' => $channelId, 'child' => $channelId, 'depth' => 0));
                 foreach ($rootPerms as $groupPerm) {
                     $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $groupPerm, true);
                 }
             } else {
                 $response = $channelLib->add($data, array('nodeonly' => true, 'skipFloodCheck' => true, 'skipNotification' => true, 'skipDupCheck' => true));
                 $channelId = $response['nodeid'];
             }
         } else {
             /* Apparently routeid gets changed every update .... */
             if (isset($channel['node']['routeguid']) and isset($this->referencedRoutes[$channel['node']['routeguid']])) {
                 $data['routeid'] = $this->referencedRoutes[$channel['node']['routeguid']];
             }
         }
         if (is_array($channelId)) {
             $channelId = array_pop($channelId);
         }
         /* VBV-2536, $oldChannel check. This is to stop the
         			import blindly resetting permissions on every update */
         if (!$oldChannel and !empty($channelId)) {
             /* We don't know what usergroups exist currently. There may be the groups 1-8 we create on a new install,
             			 or there may not. If a group exists it may have a different meaning from what we create on a new install.
             			So here's what we have decided:
             			1) At root if there is at least one forum permission record:
             				a) you get any permissions you have in any existing root forum.
             				b) If you have "albumpermissions -> canalbum" you can create albums and photos.
             				c) If you have adminpermissions->canadminforums you can create channels.
             				d) If you can forumpermissions->canpostnew you can create all the other types
             			2) If the forumpermissions doesn't exist or is empty, treat this as a new install. Take the permissions
             				from the xml file, taking the id as systemgroupid.
             			3) At root everybody can create private messages.
             			4) 	For the blog and social groups channels, we have newly created usergroups with systemgroupid. Those two channels
             			are specified in the xml file.
             			5) For all other usergroups in those two channels-
             				a) if you have moderator permission canmoderateposts, no record. Just inherit.
             				b) otherwise, get your root permissions plus channel
             			6) For the report channel- if you have moderator permission canmoderateposts anywhere on the site
             				you inherit permissions. Otherwise you have none.
             			*/
             vB_Xml_Import::setImportedId(vB_Xml_Import::TYPE_CHANNEL, $channel['guid'], $channelId);
             switch ($data['guid']) {
                 case vB_Channel::DEFAULT_BLOG_PARENT:
                     foreach ($rootPerms as $groupPerm) {
                         $thisPerm = $groupPerm;
                         if ($groupPerm['createpermissions'] > 0) {
                             $thisPerm['createpermissions'] = $groupPerm['createpermissions'] | $this->contenttypes['vbforum_channel'];
                         }
                         //These four groups should not be able to start threads in the blog and social group channels.
                         if ($groupPerm['groupid'] == $blogMemberGroupId or $groupPerm['groupid'] == $sgMemberGroupId or $groupPerm['groupid'] == $registeredGroupId or $groupPerm['groupid'] == $unRegisteredGroupId) {
                             $thisPerm['forumpermissions'] = $thisPerm['forumpermissions'] & ~$forumpermissions['canpostnew'];
                             // but they should be able to reply to others' threads
                             $thisPerm['forumpermissions'] |= $forumpermissions['canreply'];
                             $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_text'];
                             $thisPerm['forumpermissions2'] |= $forumpermissions2['cancomment'];
                         }
                         //Let the channel owner configure his/her channel
                         if ($groupPerm['groupid'] == $channelOwnerGroupId) {
                             $thisPerm['forumpermissions2'] |= $forumpermissions2['canconfigchannel'] | $forumpermissions2['candeletechannel'];
                             $thisPerm['forumpermissions'] |= $forumpermissions2['canuploadchannelicon'] | $forumpermissions2['candeletechannel'];
                         }
                         $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $thisPerm, true);
                     }
                     break;
                 case vB_Channel::DEFAULT_SOCIALGROUP_PARENT:
                     foreach ($rootPerms as $groupPerm) {
                         $thisPerm = $groupPerm;
                         if ($groupPerm['createpermissions'] > 0) {
                             $thisPerm['createpermissions'] = $groupPerm['createpermissions'] | $this->contenttypes['vbforum_channel'];
                             if ($groupPerm['systemgroupid'] == vB_Api_UserGroup::CHANNEL_OWNER_SYSGROUPID or $groupPerm['systemgroupid'] == vB_Api_UserGroup::CHANNEL_MODERATOR_SYSGROUPID or $groupPerm['systemgroupid'] == vB_Api_UserGroup::CHANNEL_MEMBER_SYSGROUPID or $groupPerm['systemgroupid'] == vB_Api_UserGroup::ADMINISTRATOR or $groupPerm['systemgroupid'] == vB_Api_UserGroup::SUPER_MODERATOR) {
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_text'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_report'];
                                 //$thisPerm['createpermissions'] |= $this->contenttypes['vbforum_calendar'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_gallery'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_poll'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_attach'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_photo'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_privatemessage'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_video'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_link'];
                             } else {
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_text'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_report'];
                                 //$thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_calendar'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_gallery'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_poll'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_attach'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_photo'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_privatemessage'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_video'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_link'];
                             }
                             $rootPerms[$groupPerm['groupid']] = $thisPerm;
                         }
                         //These four groups should not be able to start threads in the blog and social group channels.
                         if ($groupPerm['groupid'] == $blogMemberGroupId or $groupPerm['groupid'] == $sgMemberGroupId or $groupPerm['groupid'] == $registeredGroupId or $groupPerm['groupid'] == $unRegisteredGroupId) {
                             $thisPerm['forumpermissions'] = $thisPerm['forumpermissions'] & ~$forumpermissions['canpostnew'];
                             $thisPerm['forumpermissions2'] |= $forumpermissions2['cancomment'];
                         }
                         //Let the channel owner configure his/her channel
                         if ($groupPerm['groupid'] == $channelOwnerGroupId) {
                             $thisPerm['forumpermissions2'] |= $forumpermissions2['canconfigchannel'] | $forumpermissions2['candeletechannel'];
                         }
                         $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $thisPerm, true);
                     }
                     foreach ($sgperms as $index => $sgperm) {
                         $thisPerm = $rootPerms[$index];
                         if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['cancreategroups']) {
                             $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_channel'];
                         } else {
                             $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_channel'];
                         }
                         foreach ($this->bf_forumpermissions as $name => $bitfield) {
                             switch ($name) {
                                 case 'canreply':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canpostmessage']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                         $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_text'];
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'canview':
                                 case 'canviewthreads':
                                 case 'canviewothers':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canviewgroups']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'caneditpost':
                                 case 'candeletepost':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canmanagemessages']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'canpostnew':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['cancreatediscussion']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                         $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_text'];
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'canpostattachment':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canupload']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                         $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_photo'];
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'canjoin':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canjoingroups']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'candeletethread':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canmanagediscussions']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'canuploadchannelicon':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canuploadgroupicon']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'cananimatedchannelicon':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['cananimategroupicon']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 default:
                             }
                         }
                         foreach ($this->bf_forumpermissions2 as $name => $bitfield) {
                             switch ($name) {
                                 case 'canconfigchannel':
                                     if ($index == vB_Api_UserGroup::CHANNEL_OWNER_SYSGROUPID or $index == vB_Api_UserGroup::ADMINISTRATOR or $index == vB_Api_UserGroup::SUPER_MODERATOR) {
                                         if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['caneditowngroups']) {
                                             $thisPerm['forumpermissions2'] |= $bitfield;
                                         } else {
                                             $rootPerms[$index]['forumpermissions2'] &= ~$bitfield;
                                             $thisPerm['forumpermissions2'] &= ~$bitfield;
                                         }
                                     }
                                     break;
                                 case 'candeletechannel':
                                 case 'canmanageownchannels':
                                     if ($index == vB_Api_UserGroup::CHANNEL_OWNER_SYSGROUPID or $index == vB_Api_UserGroup::ADMINISTRATOR or $index == vB_Api_UserGroup::SUPER_MODERATOR) {
                                         if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canmanageowngroups']) {
                                             $thisPerm['forumpermissions2'] |= $bitfield;
                                         } else {
                                             $rootPerms[$index]['forumpermissions2'] &= ~$bitfield;
                                             $thisPerm['forumpermissions2'] &= ~$bitfield;
                                         }
                                     }
                                     break;
                                 default:
                             }
                         }
                         $channelPerm->setPermissions($channelId, $index, $thisPerm, true);
                     }
                     break;
                 case vB_Channel::REPORT_CHANNEL:
                     foreach ($rootPerms as $groupPerm) {
                         if ($groupPerm['adminpermissions'] > 0) {
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $groupPerm, true);
                         } elseif ($groupPerm['systemgroupid'] == vB_Api_UserGroup::MODERATOR) {
                             // Moderators group do not have any admin permissions by default, but they should at least
                             // be able to view reports - VBV-7955
                             $modPerms = $this->fetchEmptyPermissions();
                             $modPerms['forumpermissions'] |= $forumpermissions['canview'] | $forumpermissions['canviewthreads'] | $forumpermissions['canviewothers'];
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $modPerms, true);
                         } else {
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $this->fetchEmptyPermissions(), true);
                         }
                     }
                     break;
                 case vB_Channel::INFRACTION_CHANNEL:
                     foreach ($rootPerms as $groupPerm) {
                         if ($groupPerm['adminpermissions'] > 0) {
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $groupPerm, true);
                         } elseif ($groupPerm['systemgroupid'] == vB_Api_UserGroup::MODERATOR) {
                             // Moderators group do not have any admin permissions by default, but they should at least
                             // be able to view reports - VBV-7955
                             $modPerms = $this->fetchEmptyPermissions();
                             $modPerms['forumpermissions'] |= $forumpermissions['canview'] | $forumpermissions['canviewthreads'] | $forumpermissions['canviewothers'];
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $modPerms, true);
                         } else {
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $this->fetchEmptyPermissions(), true);
                         }
                     }
                     break;
                 case vB_Channel::DEFAULT_ARTICLE_PARENT:
                     foreach ($rootPerms as $groupPerm) {
                         unset($groupPerm['permissionid']);
                         if ($groupPerm['systemgroupid'] == vB_Api_UserGroup::ADMINISTRATOR) {
                             $groupPerm['createpermissions'] |= $this->contenttypes['vbforum_text'] | $this->contenttypes['vbforum_gallery'] | $this->contenttypes['vbforum_poll'] | $this->contenttypes['vbforum_attach'] | $this->contenttypes['vbforum_photo'] | $this->contenttypes['vbforum_video'] | $this->contenttypes['vbforum_link'];
                             $groupPerm['forumpermissions2'] |= $this->bf_forumpermissions2['canalwaysview'];
                             $groupPerm['forumpermissions'] |= $this->bf_forumpermissions['canpostnew'];
                             $groupPerm['edit_time'] = 24 * 365;
                             $groupPerm['bf_forumpermissions2'] |= $this->bf_forumpermissions2['canpublish'];
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $groupPerm, true);
                         } else {
                             if ($groupPerm['systemgroupid'] != vB_Api_UserGroup::BANNED and $groupPerm['systemgroupid'] != vB_Api_UserGroup::UNREGISTERED_SYSGROUPID) {
                                 $groupPerm['createpermissions'] = $this->contenttypes['vbforum_text'] | $this->contenttypes['vbforum_gallery'] | $this->contenttypes['vbforum_poll'] | $this->contenttypes['vbforum_attach'] | $this->contenttypes['vbforum_photo'] | $this->contenttypes['vbforum_video'];
                                 $groupPerm['forumpermissions'] &= ~$this->bf_forumpermissions['canpostnew'];
                                 $groupPerm['forumpermissions'] |= $this->bf_forumpermissions['canview'] | $this->bf_forumpermissions['canviewthreads'] | $this->bf_forumpermissions['canviewothers'];
                                 $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $groupPerm, true);
                             } else {
                                 if ($groupPerm['systemgroupid'] == vB_Api_UserGroup::REGISTERED_SYSGROUPID) {
                                     $defaultPerms = $groupPerm;
                                 }
                             }
                         }
                     }
                     //insert record for cms authors
                     $defaultPerms['createpermissions'] |= $this->contenttypes['vbforum_text'] | $this->contenttypes['vbforum_report'] | $this->contenttypes['vbforum_gallery'] | $this->contenttypes['vbforum_poll'] | $this->contenttypes['vbforum_attach'] | $this->contenttypes['vbforum_photo'] | $this->contenttypes['vbforum_privatemessage'] | $this->contenttypes['vbforum_video'] | $this->contenttypes['vbforum_link'];
                     $defaultPerms['forumpermissions2'] |= $this->bf_forumpermissions2['canalwaysview'] | $this->bf_forumpermissions2['cangetimgattachment'];
                     $defaultPerms['forumpermissions'] |= $this->bf_forumpermissions['canpostnew'] | $this->bf_forumpermissions['canseedelnotice'] | $this->bf_forumpermissions['cangetattachment'] | $this->bf_forumpermissions['canview'] | $this->bf_forumpermissions['canviewthreads'] | $this->bf_forumpermissions['canviewothers'] | $this->bf_forumpermissions['canpostattachment'] | $this->bf_forumpermissions['cantagown'];
                     $defaultPerms['forumpermissions2'] &= ~$this->bf_forumpermissions2['canpublish'];
                     $defaultPerms['edit_time'] = 24 * 365;
                     $channelPerm->setPermissions($channelId, $this->authorGroupid, $defaultPerms, true);
                     //and for cms editors.
                     $defaultPerms['forumpermissions'] |= $this->bf_forumpermissions['followforummoderation'] | $this->bf_forumpermissions['cantagothers'];
                     $defaultPerms['forumpermissions2'] |= $this->bf_forumpermissions2['canpublish'] | $this->bf_forumpermissions2['caneditothers'];
                     $channelPerm->setPermissions($channelId, $this->editorGroupId, $defaultPerms, true);
                     break;
                     //If it's anything else we don't set permissions.
             }
         }
     }
     $channelPerm->buildDefaultChannelPermsDatastore();
 }
 public function getChannelPerm($usergroupid, $permissiongroup, $permission, $channelid)
 {
     if ($permissiongroup == 'moderatorpermissions') {
         $bf_ugp = $this->datastore->getValue('bf_misc_' . $permissiongroup);
     } else {
         $bf_ugp = $this->datastore->getValue('bf_ugp_' . $permissiongroup);
     }
     if (!isset($this->channelPermissions[$usergroupid])) {
         $this->loadChannelPermissions($usergroupid);
         $this->validateInfractionPermissions($usergroupid, $channelid);
     }
     if (empty($this->permissionsFrom)) {
         $this->permissionsFrom = vB::getDatastore()->getValue('vBUgChannelPermissionsFrom');
     }
     // We might have gotten an integer;
     if (is_numeric($permission)) {
         $permission = strtolower(vB_Types::instance()->getContentTypePackage($permission) . '_' . vB_Types::instance()->getContentTypeClass($permission));
     } else {
         $permission = strtolower($permission);
     }
     if (!isset($this->channelPermissions[$usergroupid][$channelid]) and isset($this->permissionsFrom[$usergroupid]) and isset($this->permissionsFrom[$usergroupid][$channelid])) {
         $channelid = $this->permissionsFrom[$usergroupid][$channelid];
     }
     if (isset($bf_ugp[$permission]) and isset($this->channelPermissions[$usergroupid][$channelid])) {
         switch ($permissiongroup) {
             case 'forumpermissions':
                 return $bf_ugp[$permission] & $this->channelPermissions[$usergroupid][$channelid]['forumpermissions'];
                 break;
             case 'forumpermissions2':
                 return $bf_ugp[$permission] & $this->channelPermissions[$usergroupid][$channelid]['forumpermissions2'];
                 break;
             case 'createpermissions':
                 //We might have gotten an integer;
                 if (is_numeric($permission)) {
                     $permission = strtolower(vB_Types::instance()->getContentTypePackage($permission) . '_' . vB_Types::instance()->getContentTypeClass($permission));
                 } else {
                     $permission = strtolower($permission);
                 }
                 return $bf_ugp[$permission] & $this->channelPermissions[$usergroupid][$channelid]['createpermissions'];
                 break;
             case 'moderatorpermissions':
                 if ($usergroupid == 1) {
                     return false;
                 }
                 return $bf_ugp[$permission] & intval($this->channelPermissions[$usergroupid][$channelid]['moderatorpermissions']);
                 break;
             default:
                 return false;
         }
         // switch
     } else {
         $permFields = vB_ChannelPermission::fetchPermFields();
         if (isset($permFields[$permission]) and $permFields[$permission] != vB_ChannelPermission::TYPE_BITMAP and isset($this->channelPermissions[$usergroupid][$channelid])) {
             return $this->channelPermissions[$usergroupid][$channelid][$permission];
         }
         return false;
     }
 }