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;
 }
Ejemplo n.º 3
0
        $params = array('permissionid' => $vbulletin->GPC['permissionid']);
    } else {
        if ($vbulletin->GPC_exists['permissionid'] and $vbulletin->GPC_exists['nodepermission']) {
            $groupid = $vbulletin->GPC['nodepermission']['usergroupid'];
            $nodeid = $vbulletin->GPC['nodeid'];
            $params = array('nodeid' => $nodeid, 'groupid' => $groupid);
            if (!intval($groupid) or !intval($nodeid)) {
                print_table_footer();
                print_stop_message2('invalid_usergroup_specified');
            }
        }
    }
    if ($vbulletin->GPC_exists['inherit'] and intval($vbulletin->GPC['inherit'])) {
        vB_ChannelPermission::instance()->deletePerms($params);
    } else {
        $result = vB_ChannelPermission::instance()->setPermissions($nodeid, $groupid, $_POST);
    }
    print_stop_message2('saved_channel_permissions_successfully', 'forumpermission', array('do' => 'modify', 'n' => $nodeid . '#node' . $nodeid));
}
// ###################### Start duplicator #######################
if ($_REQUEST['do'] == 'duplicate') {
    $result = vB::getDbAssertor()->assertQuery('fetchpermgroups', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED));
    $ugarr = array();
    while ($result and $result->valid()) {
        $permgroup = $result->current();
        $ugarr["{$permgroup['usergroupid']}"] = $permgroup['title'];
        $result->next();
    }
    if (!empty($ugarr)) {
        $usergrouplist = array();
        foreach ($vbulletin->usergroupcache as $usergroup) {
Ejemplo 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'));
}
Ejemplo 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();
 }