vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Create checkbox group at your hack's options (usergroup selection for example) (https://vborg.vbsupport.ru/showthread.php?t=187470)

FractalizeR 08-06-2008 10:00 PM

Create checkbox group at your hack's options (usergroup selection for example)
 
1 Attachment(s)
Hello.

In this article I will show how to create a checkbox group in your hack's options. It's easy. Just do the following:

1. Create an option. Datatype validation type = free.

2. Enter the following code to Option code:
Code:

" . eval('$options="";
$fritems = array(
        "Test1Code" => "Test option checkbox",
        "Test2Code" => "Another test option checkbox",
);
foreach($fritems AS $fritem_id => $fritem_name)
{
        $options .= "\\t\\t<label for=\\"setting[$setting[varname]]$fritem_id\\" title=\\"item id: $fritem_id\\"><input type=\\"checkbox\\" tabindex=\\"1\\" name=\\"setting[$setting[varname]]"."[]\\" id=\\"setting[$setting[varname]][$fritem_id]\\" value=\\"$fritem_id\\"" . iif(strpos(",$setting[value],", ",$fritem_id,") !== false, \' checked="checked"\') . iif($vbulletin->debug, " title=\\"name=&quot;setting[$setting[varname]]&quot;\\"") . " />$fritem_name</label><br />\\n";
}
return "<span class=\\"smallfont\\">\\n$options\\t</span>";') . "<input type=\"hidden\" name=\"setting[$setting[varname]][]\" value=\"-1\" />

3. Save option. Now you will see your group of checkboxes. You can add more items to $fritems array. Array key will be the code of the option. Array value is the text to display near checkbox. Please note: all strings added to $fritems array should be double-quoted (because all there is inside single-quoted eval function) or, if you need single-quotes, escape them.


4. Now create a admin_options_processing hook with the following code:
PHP Code:

if (is_array($settings['my_setting_name']))
{
    
$settings['my_setting_name'] = implode(','$settings['my_setting_name']);



5. That's all. Now $vbulletin->settings['my_setting_name'] will be a string like "Test1Code,Test1Code" depending on what user checked at options page.

A little moment on option text localization. Instead of
PHP Code:

$fritems = array(
    
"Test1Code" => "Test option checkbox",
    
"Test2Code" => "Another test option checkbox",
); 

you can write
PHP Code:

$fritems = array(
    
"Test1Code" => $settingphrase["my_setting_phrase_name1"],
    
"Test2Code" => $settingphrase["my_setting_phrase_name2"]
); 

Just create phrases at VBulletin settings group with names my_setting_phrase_name1 and my_setting_phrase_name1:

Code:

<phrasetype name="vBulletin Settings" fieldname="vbsettings">
        <phrase name="my_setting_phrase_name1" date="1218041520" username="FractalizeR" version=""><![CDATA[Test option checkbox]]></phrase>
        <phrase name="my_setting_phrase_name2" date="1218040714" username="FractalizeR" version=""><![CDATA[Another test option checkbox]]></phrase>
</phrasetype>

Now a small example on how to list all usergroups and allow user to check some usergroups (take this text to Option code):

Code:

" . eval('$options ="";
foreach($vbulletin->usergroupcache AS $usergroupid => $usergroup)
{
        $options .= "\\t\\t<label for=\\"setting[$setting[varname]]$usergroupid\\" title=\\"usergroupid: $usergroupid\\"><input type=\\"checkbox\\" tabindex=\\"1\\" name=\\"setting[$setting[varname]]"."[]\\" id=\\"setting[$setting[varname]]$usergroupid\\" value=\\"$usergroupid\\"" . iif(strpos(",$setting[value],", ",$usergroupid,") !== false, \' checked="checked"\') . iif($vbulletin->debug, " title=\\"name=&quot;setting[$setting[varname]]&quot;\\"") . " />$usergroup[title]</label><br />\\n";
}
return "<span class=\\"smallfont\\">\\n$options\\t</span>";') . "<input type=\"hidden\" name=\"setting[$setting[varname]][]\" value=\"-1\" />

All comments are welcome!

Stagehandspace 08-14-2008 04:06 PM

Just what i been looking for, shame I havent got a clue..lol..:(

cool tut tho' :)

ZomgStuff 08-15-2008 03:23 PM

Can you provide a screenshot of how this would look?

FractalizeR 08-15-2008 05:18 PM

Attached to post

Reeve of shinra 08-15-2008 05:20 PM

/bookmarked

this is handy to have!

Antivirus 08-23-2008 04:32 PM

Fractalizer, very nice! I am wondering however why you don't just loop through each usergroup and call vbulletin's print_checkbox_row() function to handle the checkbox creation. It's located within adminfunctions.php :)

FractalizeR 08-23-2008 06:33 PM

Quote:

Originally Posted by Antivirus (Post 1605225)
Fractalizer, very nice! I am wondering however why you don't just loop through each usergroup and call vbulletin's print_checkbox_row() function to handle the checkbox creation. It's located within adminfunctions.php :)

I am not sure :) May be because this method was extracted from one hack a long time ago. And after some time I extended it a bit and decided to publish a how-to.

veenuisthebest 09-24-2008 06:04 AM

Thanks for this tutorial.

in step 4 i.e.

PHP Code:

if (is_array($settings['my_setting_name']))
{
    
$settings['my_setting_name'] = implode(','$settings['my_setting_name']);


What to write in place of "my_setting_name"and how to check which options are checked from within php page.

I also wanted to know how to use this option code
bitfield:nocache|allowedbbcodesfull

This bitfield type code automatically generates a set of check boxes of allowed bbcodes to choose from. Now how to implement onto our page.

Thank you

FractalizeR 09-24-2008 08:39 AM

my_setting_name is the setting name you provided when creating setting. As for bitfield - I am not sure it is supported. Where is this example from?

veenuisthebest 09-24-2008 09:13 AM

thanks for your reply !

alright so $settings['my_setting_name'] is the field setting name, fine.

1. And in the option code I see "setting[$setting[varname]", does varname needs to be replaced by something ?

2. How do I check for the checked options from the php page ? Like for boolean we do :-

PHP Code:

if($vbulletin->options['mysetting_enable']
{
        
enabled true;
}
else
{
        
enabled false;


How to achieve similar for checkbox ?

3. umm.. not sure what you mean by bitfield supported. See in admincp->Social Group Options and Album Options and Visitor Message options. They all have a setting of "Allowed BBCODES", their option code is set to bitfield:nocache|allowedbbcodesfull and it automatically outputs a set of checkboxes of bbcodes.
I did the same and it works but as in my 2nd ques, how do I check it ?

Thank you


All times are GMT. The time now is 10:25 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02415 seconds
  • Memory Usage 1,756KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (5)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete