Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Create checkbox group at your hack's options (usergroup selection for example)
FractalizeR's Avatar
FractalizeR
Join Date: Oct 2005
Posts: 368

 

Russia, Moscow
Show Printable Version Email this Page Subscription
FractalizeR FractalizeR is offline 08-06-2008, 10:00 PM

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!
Attached Images
File Type: jpg Demo.jpg (52.8 KB, 0 views)
Reply With Quote
  #12  
Old 09-24-2008, 11:06 AM
FractalizeR's Avatar
FractalizeR FractalizeR is offline
 
Join Date: Oct 2005
Location: Russia, Moscow
Posts: 368
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by veenuisthebest View Post
1. And in the option code I see "setting[$setting[varname]", does varname needs to be replaced by something ?
No, leave it as is. This is for VBulletin Debug mode.

Quote:
Originally Posted by veenuisthebest View Post
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 ?
Your $vbulletin->options['my_setting_name'] will contain comma delimited list of checked options. explode it and use.

Quote:
Originally Posted by veenuisthebest View Post
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
This is VBulletin internal feature I never used.
Reply With Quote
  #13  
Old 09-26-2008, 07:10 PM
veenuisthebest's Avatar
veenuisthebest veenuisthebest is offline
 
Join Date: Mar 2008
Location: India
Posts: 1,416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for your replies.

Can you please tell me what to do after creating the plugin at admin_options_processing hook.

Is this correct ?

PHP Code:
if(explode(','$vbulletin->options['show_settings']))
{
        
$showchecked true;
}
else
{
        
$showchecked false;

What I want to achieve is quite simple but i am not able to figure it out.

See.. I am showing 3 radio buttons via template. Simple !

Now.. I have created 3 checkboxes (corresponding to radio buttons) so that whichever is checked THAT radio button would show. How do I achieve this ? What should I wrap around my radio button code in template so that the corresponding one shows only when it is allowed (checked in admincp).

Thank you
Reply With Quote
  #14  
Old 09-29-2008, 08:50 AM
FractalizeR's Avatar
FractalizeR FractalizeR is offline
 
Join Date: Oct 2005
Location: Russia, Moscow
Posts: 368
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$radioboxesToShow explode(','$vbulletin->options['my_radioboxes_to_show']);
if(isset(
$radioboxesToShow['radio_1'])) {
   
$show['radio_1'] = true;

Something like this I think. Emded all your radios in templates surrounded by if condition="show[radio_1]"
Reply With Quote
  #15  
Old 09-30-2008, 02:09 PM
veenuisthebest's Avatar
veenuisthebest veenuisthebest is offline
 
Join Date: Mar 2008
Location: India
Posts: 1,416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

oh i still can't get it to work. See this is all what I had done:-

1. I created a setting $vbulletin->options['vin_mysetting'], Free datatype, with the following option code:-

Code:
" . eval('$options=""; 
$fritems = array(
	"option1" => "First Radio",
	"option2" => "Second Radio",
	"option3" => "Third Radio",
);
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\" />
2. Then I created a hook at admin_options_processing with the following code:-

PHP Code:
if (is_array($settings['vin_mysetting']))
{
    
$settings['vin_mysetting'] = implode(','$settings['vin_mysetting']);

3. Then in my file.php I did this (taking just "option1" for now.) :-

PHP Code:
$radioboxesToShow explode(','$vbulletin->options['vin_mysetting']);
if(isset(
$radioboxesToShow['option1'])) {
   
$show['option1'] = true;

4. Then at atlast, in the associated template, I did this:-

HTML Code:
<if condition="$show['option1']">
	<input type="radio" name="radiotype" value="0"/>My First Radio<br />
</if>

It never shows up now, whether checked or unchecked !

Thank you
Reply With Quote
  #16  
Old 11-03-2008, 10:50 AM
Bravo Bravo is offline
 
Join Date: Nov 2006
Posts: 67
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the info, Ive been in need of this type of info... now I just need to figure out how to create options in the UserGroup and User settings
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:43 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04411 seconds
  • Memory Usage 2,314KB
  • Queries Executed 21 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_code
  • (1)bbcode_html
  • (8)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (6)post_thanks_box
  • (1)post_thanks_box_bit
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (6)post_thanks_postbit_info
  • (5)postbit
  • (1)postbit_attachment
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete