vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   [How-to] Add a multiselect field in vBulletin options (https://vborg.vbsupport.ru/showthread.php?t=191666)

Coroner 09-22-2008 10:00 PM

[How-to] Add a multiselect field in vBulletin options
 
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

Stoebi 10-10-2008 04:38 PM

This is great. Thank you very much for sharing :)


Regards,

Stoebi

Blackhat 10-28-2008 01:52 PM

can this be used in the user cp > options to make a "forum chooser" and which hook should I use?

ReCom 11-24-2008 08:31 AM

A setting with datatype "bitfield" can create a group of checkboxes (multiselection) in vBulletin Options.

Coroner 07-18-2009 08:14 AM

1 Attachment(s)
I didn't mean a forumchooser (Selectrow) or a multiple checkbox.

See image for the "multiselect field" what I mean.

Simon Lloyd 10-09-2013 12:07 AM

The chooser code is great but i am unsure how to call it in a plug in, normally i'd have the user enter the forum id's and use something like $allowedforums = explode(",", $vbulletin->options['sens_forumid']);
if (in_array($threadinfo['forumid'], $allowedforums))

How do i use the information of the selected forums creating a multiselect like this?

ozzy47 10-09-2013 12:13 AM

I believe what you are after is something this.

Code:

    if(in_array($GLOBALS['forumid'], explode(',', $vbulletin->options['MY_OPTION_NAME'])))
    {
      Your Code Here
    }


Simon Lloyd 10-09-2013 12:14 AM

That works with the above?

ozzy47 10-09-2013 12:17 AM

It should, the code I provided, works in my mods that I have a forum chooser in options, via a multi select field.

Simon Lloyd 10-09-2013 12:23 AM

Hmmm, i tried a variation of the code i provided and it didnt work, the code you provided gives an error
Quote:

Parse error: syntax error, unexpected T_IF in /home/thecodec/public_html/forumz/showthread.php(112) : eval()'d code on line 31
--------------- Added [DATE]1381281909[/DATE] at [TIME]1381281909[/TIME] ---------------

Errrr.....ummmm, guess who added an extra F to his own IF function!!!

My apologies!


All times are GMT. The time now is 08:30 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.01557 seconds
  • Memory Usage 1,761KB
  • 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
  • (1)bbcode_code_printable
  • (3)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