vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Tickbox vB Option Code (https://vborg.vbsupport.ru/showthread.php?t=120032)

Kirk Y 07-01-2006 04:12 AM

Tickbox vB Option Code
 
Trying to setup a vb option setting with tick boxes in it. I took some code from a setting that already had them and implemented it into my own, but now I'm getting this wacky error:

Code:

Fatal error: Unsupported operand types in \includes\adminfunctions_options.php on line 229
This is the code I'm using:

PHP Code:

<fieldset>
<
legend>options</legend>
<
input type=\"hidden\" name=\"setting[$setting[varname]][]\" value=\"0\" />
<div class=\"smallfont\"><label for=\"option1\"><input type=\"checkbox\" name=\"setting[
$setting[varname]][]\" value=\"1\" id=\"option1\" " iif(bitwise($setting['value'], 1), 'checked="checked"') . " /><b>option 1</b></label></div>
<div class=\"smallfont\"><label for=\"option2\"><input type=\"checkbox\" name=\"setting[
$setting[varname]][]\" value=\"2\" id=\"option2\" " iif(bitwise($setting['value'], 2), 'checked="checked"') . " /><b>option 2</b></label></div>
</fieldset> 

What am I missing here? TIA for any help.

Adrian Schneider 07-01-2006 06:43 AM

Set the datatype to free.

Kirk Y 07-01-2006 02:40 PM

Yeah I tried that, but then it won't save the status of the tickboxes. Same with Boolean.

Kirk Y 07-03-2006 02:54 AM

Does anyone else have an idea?

Adrian Schneider 07-03-2006 03:19 AM

You need to convert the data to an integer first, then upon retrieving the data, check to see the individual values. Bitfields make it easy....

admin_options_processing hook:

PHP Code:

if ($oldsetting['varname'] == 'yourvarname')
{
    
$bitfield 0;
    foreach (
$vbulletin->GPC['setting'][$oldsetting['varname']] AS $bitval)
    {
        
$bitfield += $bitval;
    }
    
$vbulletin->GPC['setting'][$oldsetting['varname']] = $bitfield;


Okay, now that it is an integer...

option eval code
Code:

<fieldset>
        <legend>$vbphrase[yes] / $vbphrase[no]</legend>
<input type=\"hidden\" name=\"setting[$setting[varname]][]\" value=\"0\" />
<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
<tr valign=\"top\">
        <td class=\"smallfont\" nowrap=\"nowrap\">
        <label for=\"yoursetting1\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting1\" value=\"1\" tabindex=\"1\" " . iif(bitwise($setting['value'], 1), 'checked="checked"') . " />Ratings</label><br />
        <label for=\"yoursetting2\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting2\" value=\"2\" tabindex=\"1\" " . iif(bitwise($setting['value'], 2), 'checked="checked"') . " />Entries</label><br />
        <label for=\"yoursetting4\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting4\" value=\"4\" tabindex=\"1\" " . iif(bitwise($setting['value'], 4), 'checked="checked"') . " />Last Entry</label><br />
        <label for=\"yoursetting8\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting8\" value=\"8\" tabindex=\"1\" " . iif(bitwise($setting['value'], 8), 'checked="checked"') . " />Comments</label><br />
        <label for=\"yoursetting16\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting16\" value=\"16\" tabindex=\"1\" " . iif(bitwise($setting['value'], 16), 'checked="checked"') . " />Last Comments</label><br />
        <label for=\"yoursetting32\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting32\" value=\"32\" tabindex=\"1\" " . iif(bitwise($setting['value'], 32), 'checked="checked"') . " />Views</label><br />
        <label for=\"yoursetting64\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting64\" value=\"64\" tabindex=\"1\" " . iif(bitwise($setting['value'], 64), 'checked="checked"') . " />Category</label><br />
        <label for=\"yoursetting128\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting128\" value=\"128\" tabindex=\"1\" " . iif(bitwise($setting['value'], 128), 'checked="checked"') . " />Mass Moderation</label><br />
        </td>
</tr>
</table>
</fieldset>

^ should give you an idea

Kirk Y 07-03-2006 04:48 PM

Thanks SirAdrian, I'll try that later.

Is there a reason that you've got the setting increments doubling?

Adrian Schneider 07-03-2006 06:59 PM

Here's a visual explanation...
http://www.litfuel.net/tutorials/images/800binary.gif

Kirk Y 07-03-2006 07:27 PM

Ha ha -- thanks SirAdrian, that makes sense.

One final question before the thread can be put to bed: how do I call the option?

The typical $vbulletin->options[varname] returns an array, go figure, but I'm not sure what values to use for each bit.

Adrian Schneider 07-03-2006 07:35 PM

I have this in my PHP file where I use it
PHP Code:

    var $parsingLookup = array(
        
'html' => 1,
        
'smilies' => 2,
        
'bbcode' => 4,
        
'images' => 8,
        
'lines' => 16
    
); 

PHP Code:

$entryParsing convert_bits_to_array($blog->option('parse_entry'), $blog->parsingLookup); 

PHP Code:

        $entry['body'] = $parser->do_parse($entry['body'], 
            
$entryParsing['html'],
            
$entryParsing['smilies'],
            
$entryParsing['bbcode'],
            
$entryParsing['images'],
            
$entryParsing['lines'],
            
false
        
); 

^ an example

For the values, go up by multiples of two (binary!), then make sure the values you use matchup with an array (in my case, $blog->parsingLookup).

Kirk Y 07-03-2006 07:44 PM

Thanks again for all your help and the laugh :p, I've got everything working perfectly.


All times are GMT. The time now is 12:02 AM.

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.01203 seconds
  • Memory Usage 1,758KB
  • 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
  • (2)bbcode_code_printable
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete