Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles

Reply
 
Thread Tools
[How-to] Add a multiselect field in vBulletin options
Coroner
Join Date: Feb 2008
Posts: 797

I start for about 25 years with an TI and learned Basic. Next was an Commodere 64, Amiga. On Amiga I learned Assembler and wrote some Games. Many years later again, I learned myself (without book ...) php,html and javascript. Then I wrote some small

Germany
Show Printable Version Email this Page Subscription
Coroner Coroner is offline 09-22-2008, 10:00 PM

I wrote this article 'cause I didn't found anything else but it was needed for mod I wrote.

Before I start - will have to say this is an example for a forumchooser.

In our product under options, create an option like this:
PHP Code:
<setting varname="your_setting_varname" displayorder="1">
 <
datatype>free</datatype>
 <
optioncode>multiselect:eval
$options construct_forum_chooser_options(1);</optioncode>
 <
defaultvalue>0</defaultvalue>
</
setting
I'll use: multiselect:eval.

Ok, we finished our first part and need 2 new plugins.

The first plugin we used is admin_options_print.
PHP Code:
    <plugin active="1" product="yourproduct">
      <
title>expand options for multiselect</title>
      <
hookname>admin_options_print</hookname>
      <
phpcode><![CDATA[if (preg_match ('#^(multiselect):(eval)(\r\n|\n|\r)(.*)$#siU'$setting['optioncode'], $matches))
{
 
$options null;
 eval (
$setting['optiondata']);
 
// this is for multiselect options
 
$title $description;
 
$array construct_forum_chooser_options (0);
 
$selected explode (','$setting['value']);
 
$name .= "[]";
 
$htmlise 0;
 
$size 10;
 
$multiple true;
 global 
$vbulletin;
 
$uniqueid fetch_uniqueid_counter ();
 
$select "<div id=\"ctrl_$name\"><select name=\"$name\" id=\"sel_{$name}_$uniqueid\" tabindex=\"1\" class=\"bginput\"" iif($size" size=\"$size\"") . iif($multiple' multiple="multiple"') . iif($vbulletin->debug" title=\"name=&quot;$name&quot;\"") . ">\n";
 
$select .= construct_select_options ($array$selected$htmlise);
 
$select .= "</select></div>\n";
 
print_label_row ($title$select'''top'$name);
 
$handled true;
}]]></
phpcode>
    </
plugin
See the code above and take a look at this three lines:
$array = construct_forum_chooser_options (0);
$selected = explode (',', $setting['value']);
$name .= "[]";
The 1st line are our options array, filled with information coming from the function "construct_forum_chooser_options(0)". If you wanna have your own, create an array with your options.
2nd line: our value (saved later in the options will implode by a comma like: 5,8,11,26,.. we need to explode this value to get the selected values back.
3rd line: this is needed for multiselect

The next plugin is called: admin_options_processing.
PHP Code:
<plugin active="1" product="yourproduct">
      <
title>save our multiselect values</title>
      <
hookname>admin_options_processing</hookname>
      <
phpcode><![CDATA[
if (
preg_match ('/multiselect/i'$oldsetting['optioncode']))
{
 if (
is_array ($settings["$oldsetting[varname]"])) $settings["$oldsetting[varname]"] = implode (','$settings["$oldsetting[varname]"]);
}]]></
phpcode>
    </
plugin
This plugin will implode our selected values with a comma.

Regards
Reply With Quote
  #12  
Old 10-09-2013, 12:26 AM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok here is how I do a forum chooser.

First create the option, and in the field, Option Code add the following:
Code:
"; $forums = array(0 => $vbphrase['none']);
if (is_array($vbulletin->forumcache))
{
  foreach($vbulletin->forumcache AS $forumid => $forum)
  {
  $forums["$forum[forumid]"] = construct_depth_mark($forum['depth'], '--') . ' ' . $forum['title'];
  }
}
$right = "<select name=\"setting[$setting[varname]][]\" id=\"".$setting[varname]."\" tabindex=\"1\" class=\"bginput\" size=\"20\" style=\"width:300px;\" multiple=\"multiple\">\n";
$right .= construct_select_options($forums, explode(',',$vbulletin->options[$setting[varname]]), false);
$right .= "</select>\n"; $null = "
Then you will need to do the plugin for admin_options_processing
Code:
    $setforums = 'VARNAME FOR YOUR SETTING';
    if ($oldsetting['varname'] == $setforums)
    {
       if (in_array(0, $settings[$setforums]))
       {
          $settings[$setforums] = '0';
       }
       else
       {
           $settings[$setforums] = implode(',',$settings[$setforums]);
       }
    }
    $setforums = '';
Then you can use the code I provided earlier.
Reply With Quote
  #13  
Old 10-09-2013, 12:35 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Lol, thanks, did you see my note?
Reply With Quote
  #14  
Old 10-09-2013, 12:37 AM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Not until well after I had replied.
Reply With Quote
  #15  
Old 06-20-2015, 09:45 AM
Easy5s.net Easy5s.net is offline
 
Join Date: Jun 2011
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ozzy47 View Post
Ok here is how I do a forum chooser.

First create the option, and in the field, Option Code add the following:
Code:
"; $forums = array(0 => $vbphrase['none']);
if (is_array($vbulletin->forumcache))
{
  foreach($vbulletin->forumcache AS $forumid => $forum)
  {
  $forums["$forum[forumid]"] = construct_depth_mark($forum['depth'], '--') . ' ' . $forum['title'];
  }
}
$right = "<select name=\"setting[$setting[varname]][]\" id=\"".$setting[varname]."\" tabindex=\"1\" class=\"bginput\" size=\"20\" style=\"width:300px;\" multiple=\"multiple\">\n";
$right .= construct_select_options($forums, explode(',',$vbulletin->options[$setting[varname]]), false);
$right .= "</select>\n"; $null = "
Then you will need to do the plugin for admin_options_processing
Code:
    $setforums = 'VARNAME FOR YOUR SETTING';
    if ($oldsetting['varname'] == $setforums)
    {
       if (in_array(0, $settings[$setforums]))
       {
          $settings[$setforums] = '0';
       }
       else
       {
           $settings[$setforums] = implode(',',$settings[$setforums]);
       }
    }
    $setforums = '';
Then you can use the code I provided earlier.


Code:
    $setforums = 'check_forums';
    if ($oldsetting['varname'] == $setforums)
    {
       if (in_array(0, $settings[$setforums]))
       {
          $settings[$setforums] = '0';
       }
       else
       {
           $settings[$setforums] = implode(',',$settings[$setforums]);
       }
    }
    $setforums = '';
i user hook newthread_start with code

Code:
	if (in_array($foruminfo['forumid'], explode(',', $vbulletin->options['check_forums'])))
	{
		if ($vbulletin->userinfo['dola'] < $vbulletin->options['newthread_dola'])
		{
			eval(standard_error(fetch_error('no_dola')));
		}
	}
but not work
Reply With Quote
Reply

Thread Tools

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 08:16 AM.


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.03855 seconds
  • Memory Usage 2,291KB
  • Queries Executed 22 (?)
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
  • (6)bbcode_code
  • (3)bbcode_php
  • (1)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
  • (5)post_thanks_box
  • (1)post_thanks_box_bit
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (5)post_thanks_postbit_info
  • (4)postbit
  • (5)postbit_onlinestatus
  • (5)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_postinfo_query
  • fetch_postinfo
  • 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_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete