Back to vBulletin 3 Articles

Coding in Vbulletin 3.x Tips
by deathemperor 14 Feb 2005

Quick 1st Tip:

Inserting new Vbulletin Settings by running a php script.

sample code:

PHP Code:
function setting_add($title$description$varname$value$defaultvalue$optioncode$displayorder,$grouptitle)
{
    global 
$DB_site;
    
$DB_site->query("INSERT INTO " TABLE_PREFIX "phrase (phraseid, languageid, varname, text, phrasetypeid) VALUES (NULL, '0', 'setting_" $varname "_title', '" addslashes($title) ."', '5000')");
    
$DB_site->query("INSERT INTO " TABLE_PREFIX "phrase (phraseid, languageid, varname, text, phrasetypeid) VALUES (NULL, '0',  'setting_" $varname "_desc', '" addslashes($description) ."', '5000')");
    
$DB_site->query("INSERT INTO " TABLE_PREFIX "setting (varname, grouptitle, value, defaultvalue, optioncode, displayorder, advanced, volatile) VALUES ('$varname', '$grouptitle', '$value', '$defaultvalue', '$optioncode', '$displayorder', '0', '0')");


To run this function use:

PHP Code:
setting_add('Setting title''Setting Descritption''varname''value''defaultvalue''typeofHTMLcode''displayorder','grouptitle'); 
Setting title: The tile of the setting.
Setting Descritption: The discription of the setting.
varname: varname is cancloseboard => $vboptions['cancloseboard'].
value: the default value.
defaultvalue: MySQL default value.
displayorder: the displayorder of the setting.
grouptitle: if you want to have a brand new setting, then use a different value with vbulletin default grouptitle, it will be a child setting if you use a existed value.

This is the most simple way to add a new setting AFAIK. just a 1st quick tips, there will be more, soon.

2nd Tip: Adding Usergroup Permission.

This is simple, you need to edit 2 file: init.php and admincp/usergroup.php

in init.php find:

PHP Code:
// ----------------------------------------------------------
// ###  END PLUGIN USERGROUP PERMISSIONS BITFIELDS HERE   ### 
ABOVE THIS, ADD:

PHP Code:
$_BITFIELD['usergroup']['permissionname'] = array(
    
'candothis'   => 1,
    
'candothat'   => 2,
    
'canviewthis'    => 4,
    
'canviewthat'        => 8,
    
'candownloadthis'   => 16,
    
'candownloadthat'  => 32
); 
This is for a absolute new permission, if you need a new permission for "permissionname" just add a new value like 'onemore' => 64, you can notice that the number get double.

in admincp/Usergroup.php find:

PHP Code:
print_table_header($vbphrase['forum_viewing_permissions']); 
Add above:

PHP Code:
    print_table_header('Permission Name');
    
print_yes_no_row('Can do This''usergroup[candothis]'$ug_bitfield['canviewsong']);
    
print_yes_no_row('Can do that''usergroup[candothat]'$ug_bitfield['candownload']);
    
print_yes_no_row('Can view this''usergroup[canviewthis]'$ug_bitfield['canviewthis']);
    
print_yes_no_row('Can view that''usergroup[canviewthat]'$ug_bitfield['canviewthat']);
    
print_yes_no_row('Can download this''usergroup[candownloadthis]'$ug_bitfield['candownloadthis']);
    
print_yes_no_row('Can download that''usergroup[candownloadthat]'$ug_bitfield['candownloadthat']);
    
print_table_break(); 
of course this can be change for the place of the permission if you know what to do.

to check for permission in php vb files, use:

PHP Code:
    if (!($permissions['permissionname'] & candothis))
    {
        
print_no_permission();
    } 
OR

PHP Code:
    if (!($permissions['permissionname'] & 1))
    {
        
print_no_permission();
    } 
Either of the way will check the usergroup permission that if you candothis or not, if not show the no permission page. Same for other, with candownloadthat you can use either candownloadthat or 32.

Some notes: If you use a totally new usergroup permission like the example above you will then need to run some queries:

this must be run:

SQL Query: (how to run queries)
ALTER TABLE `usergroup`	ADD COLUMN `permissionname` int(10) unsigned NOT NULL DEFAULT 0


This is optional to add default permission for some usergroup:

SQL Query: (how to run queries)
UPDATE usergroup SET jukeboxpermissions=63 WHERE usergroupid IN (5,6,7)

this query set the admin, mod, smod usergroup to have full permission, the number 63 = 1 + 2 + 4 + 6 + 8 + 16 + 32, so if you want a usergroup to have full permission, just total all the number in that permission, and to disable any permission you extract that number. Admin will have candothis and candothat set to no if they're 60.

For a exist permission you need to run no queries
Simple place a new value with the correct number below the vb based permission.

Example:

PHP Code:
$_BITFIELD['usergroup']['calendarpermissions'] = array(
    
'canviewcalendar'    => 1,
    
'canpostevent'       => 2,
    
'caneditevent'       => 4,
    
'candeleteevent'     => 8,
    
'canviewothersevent' => 16,
        
'candoeverything' => 32
); 
in usergroup permission find

PHP Code:
        print_yes_no_row($vbphrase['can_view_others_events'], 'usergroup[canviewothersevent]'$ug_bitfield['canviewothersevent']); 

ADD BELOW

PHP Code:
    print_yes_no_row('Can Do anything''usergroup[cansearchevent]'$ug_bitfield['cansearchevent']); 
The above example add a new permission: candoeverything in calendarpermissions

I hope I am not just trying to be complex.

Next: Forum permission.

vblts.ru supports vBulletin®, 2022-2024