vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Plugin Help Pretty-Please (https://vborg.vbsupport.ru/showthread.php?t=249953)

midnz 09-05-2010 07:34 AM

Plugin Help Pretty-Please
 
Thank-you to anyone who reads this with a view to helping me. I'm stuck :confused:

I'm trying to get a home-made addon that I used on my old 3.6.8 board to work on my 4.0.6 board. Everything works except one plugin that calculates the values of table rows to show total debits ($totaldebits), total credits ($totalcredits) and overall total ($totaltotal).

Values are entered in admincp fields and display on a table. Negative values entered in the admincp fields display within the Debit column & Balance column whereas positive values display within the Credit column & Balance column. I use the following to achieve that:
Sample of table ROW code:
PHP Code:

  </td>
    <
td class="alt1"><vb:if condition="$vboptions[vcaccounts_Row_1_Value]<0">{vb:raw vboptions.vcaccounts_Row_1_Value}<vb:else /> </vb:if></td>
    <
td class="alt1"><vb:if condition="$vboptions[vcaccounts_Row_1_Value]>0">{vb:raw vboptions.vcaccounts_Row_1_Value}<vb:else /> </vb:if></td>
    <
td class="alt1">{vb:raw vboptions.vcaccounts_Row_1_Value}</td>
  </
tr

Admincp Fields:
http://img5.imageshack.us/img5/5761/accountsadmincp.jpg

Table Result:
http://img709.imageshack.us/img709/9...ountstable.jpg

The old plugin (for 3.6.8) automatically calculated the totals of the Debit, Credit and Balance columns and looks like this:
PHP Code:

if (THIS_SCRIPT=='Accounts') {
$totaltotal $vbulletin->options['don_field1']+$vbulletin->options['don_field2']+$vbulletin->options['don_field3']+$vbulletin->options['don_field4']+$vbulletin->options['don_field5']+$vbulletin->options['don_field6']+$vbulletin->options['don_field7']+$vbulletin->options['don_field8']+$vbulletin->options['don_field9']+$vbulletin->options['don_field10'];
$totaltotal round($totaltotal2);
$totaldebits 0;
if(
$vbulletin->options['don_field1']<0) {
$totaldebits += $vbulletin->options['don_field1']; } else {
$totalcredits += $vbulletin->options['don_field1'];
}
if(
$vbulletin->options['don_field2']<0) {
$totaldebits += $vbulletin->options['don_field2']; } else {
$totalcredits += $vbulletin->options['don_field2'];
}
if(
$vbulletin->options['don_field3']<0) {
$totaldebits += $vbulletin->options['don_field3']; } else {
$totalcredits += $vbulletin->options['don_field3'];
}
if(
$vbulletin->options['don_field4']<0) {
$totaldebits += $vbulletin->options['don_field4']; } else {
$totalcredits += $vbulletin->options['don_field4'];
}
if(
$vbulletin->options['don_field5']<0) {
$totaldebits += $vbulletin->options['don_field5']; } else {
$totalcredits += $vbulletin->options['don_field5'];
}
if(
$vbulletin->options['don_field6']<0) {
$totaldebits += $vbulletin->options['don_field6']; } else {
$totalcredits += $vbulletin->options['don_field6'];
}
if(
$vbulletin->options['don_field7']<0) {
$totaldebits += $vbulletin->options['don_field7']; } else {
$totalcredits += $vbulletin->options['don_field7'];
}
if(
$vbulletin->options['don_field8']<0) {
$totaldebits += $vbulletin->options['don_field8']; } else {
$totalcredits += $vbulletin->options['don_field8'];
}
if(
$vbulletin->options['don_field9']<0) {
$totaldebits += $vbulletin->options['don_field9']; } else {
$totalcredits += $vbulletin->options['don_field9'];
}
if(
$vbulletin->options['don_field10']<0) {
$totaldebits += $vbulletin->options['don_field10']; } else {
$totalcredits += $vbulletin->options['don_field10'];
} } 

The new plugin for 4.0.6 currently looks like this and doesn't seem to work: (currently=many edits/trials)
PHP Code:

       <plugin active="1" product="vbulletin" executionorder="40">
        <
title><![CDATA[VC_Accounts Totals]]></title>
        <
hookname>misc_start</hookname>
        <
phpcode>if (THIS_SCRIPT=='vcaccounts') {
$totaltotal $vbulletin->options['vcaccounts_Row_1_Value']+$vbulletin->options['vcaccounts_Row_2_Value']+$vbulletin->options['vcaccounts_Row_3_Value']+$vbulletin->options['vcaccounts_Row_4_Value']+$vbulletin->options['vcaccounts_Row_5_Value']+$vbulletin->options['vcaccounts_Row_6_Value']+$vbulletin->options['vcaccounts_Row_7_Value']+$vbulletin->options['vcaccounts_Row_8_Value'];
$totaltotal round($totaltotal2);
$totaldebits 0;
if(
$vbulletin->options['vcaccounts_Row_1_Value']&lt;0) {
$totaldebits += $vbulletin->options['vcaccounts_Row_1_Value']; } else {
$totalcredits += $vbulletin->options['vcaccounts_Row_1_Value'];
}
if(
$vbulletin->options['vcaccounts_Row_2_Value']&lt;0) {
$totaldebits += $vbulletin->options['vcaccounts_Row_2_Value']; } else {
$totalcredits += $vbulletin->options['vcaccounts_Row_2_Value'];
}
if(
$vbulletin->options['vcaccounts_Row_3_Value']&lt;0) {
$totaldebits += $vbulletin->options['vcaccounts_Row_3_Value']; } else {
$totalcredits += $vbulletin->options['vcaccounts_Row_3_Value'];
}
if(
$vbulletin->options['vcaccounts_Row_4_Value']&lt;0) {
$totaldebits += $vbulletin->options['vcaccounts_Row_4_Value']; } else {
$totalcredits += $vbulletin->options['vcaccounts_Row_4_Value'];
}
if(
$vbulletin->options['vcaccounts_Row_5_Value']&lt;0) {
$totaldebits += $vbulletin->options['vcaccounts_Row_5_Value']; } else {
$totalcredits += $vbulletin->options['vcaccounts_Row_5_Value'];
}
if(
$vbulletin->options['vcaccounts_Row_6_Value']&lt;0) {
$totaldebits += $vbulletin->options['vcaccounts_Row_6_Value']; } else {
$totalcredits += $vbulletin->options['vcaccounts_Row_6_Value'];
}
if(
$vbulletin->options['vcaccounts_Row_7_Value']&lt;0) {
$totaldebits += $vbulletin->options['vcaccounts_Row_7_Value']; } else {
$totalcredits += $vbulletin->options['vcaccounts_Row_7_Value'];
}
if(
$vbulletin->options['vcaccounts_Row_8_Value']&lt;0) {
$totaldebits += $vbulletin->options['vcaccounts_Row_8_Value']; } else {
$totalcredits += $vbulletin->options['vcaccounts_Row_8_Value'];
} }
        </
phpcode>
    </
plugin

I've registered what I think should be registered:
Code:

    $templater->register('totaldebits', $totaldebits);
    $templater->register('totalcredits', $totalcredits);
    $templater->register('totaltotal', $totaltotal);

The Totals Row of my table looks like this:
PHP Code:

  <tr>
    <
th class="alt3" style="width:25%">{vb:rawphrase vcaccounts_table_totals}</th>
    <
th class="alt3" style="width:15%">{vb:var vboptions.vcaccounts_currency_symbol}{vb:raw totaldebits}</th>
    <
th class="alt3" style="width:15%">{vb:var vboptions.vcaccounts_currency_symbol}{vb:raw totalcredits}</th>
    <
th class="alt3" style="width:15%">{vb:var vboptions.vcaccounts_currency_symbol}{vb:raw totaltotal}</th>
  </
tr

Note: It's all in an .xml document. I don't know if that matters but thought I'd mention it just in case. It all installs okay except for that plugin refusing to work for me.

I've tried using different Hook Locations but with no success. I'm guessing there is something wrong with my 4.0.6 plugin and was hoping someone might be able to spot something obvious and push me in the right direction.

Lynne 09-05-2010 02:30 PM

There is more to registering a variable than just what you wrote above. That one part is correct for that part. But, we'd need to see the whole thing in order to see that you did it correctly.

midnz 09-05-2010 06:30 PM

Quote:

Originally Posted by Lynne (Post 2094137)
There is more to registering a variable than just what you wrote above. That one part is correct for that part. But, we'd need to see the whole thing in order to see that you did it correctly.

Hi Lynne and thanks for your attention :) .

At present the list of variables are all bunched up together on my .xml document between </templates> and <plugins>.
PHP Code:

</templates>
    
$templater->register('vcaccounts_table_title'$vcaccounts_table_title);
    
$templater->register('vcaccounts_table_title'$vcaccounts_table_subtitle);
    
$templater->register('vcaccounts_currency'$vcaccounts_currency);
    
$templater->register('vcaccounts_date'$vcaccounts_date);
    
$templater->register('vcaccounts_donthanks'$vcaccounts_donthanks);
    
$templater->register('vcaccounts_donators'$vcaccounts_donators);
    
$templater->register('vcaccounts_Row_1_Value'$vcaccounts_Row_1_Value);
    
$templater->register('vcaccounts_Row_2_Value'$vcaccounts_Row_2_Value);
    
$templater->register('vcaccounts_Row_3_Value'$vcaccounts_Row_3_Value);
    
$templater->register('vcaccounts_Row_4_Value'$vcaccounts_Row_4_Value);
    
$templater->register('vcaccounts_Row_5_Value'$vcaccounts_Row_5_Value);
    
$templater->register('vcaccounts_Row_6_Value'$vcaccounts_Row_6_Value);
    
$templater->register('vcaccounts_Row_7_Value'$vcaccounts_Row_7_Value);
    
$templater->register('vcaccounts_Row_8_Value'$vcaccounts_Row_8_Value);
    
$templater->register('totaldebits'$totaldebits);
    
$templater->register('totalcredits'$totalcredits);
    
$templater->register('totaltotal'$totaltotal);
    
print_output($templater->render());
  <
plugins

I've experimented with placing them at the bottom of the main template, within a plugin and even at the bottom of the .php file. Everything else seems to function properly except those 3 $totals or/and the associated plugin.

[S]I've attached the .xml and .php files in case that might assist with spotting what I've done wrong.[/S] Removed attachment.

Lynne 09-05-2010 08:41 PM

That shouldn't be all either. Here are the basic steps - create the template, register the variables, render the template:
PHP Code:

$newTemplate vB_Template::create('someTemplate');
    
$newTemplate->register('variable1'$somearray);
    
$newTemplate->register('variable2'$variabletwo);
$newTemplate->render(); 

You are missing at least the first step.

midnz 09-05-2010 10:53 PM

Thanks very much indeed Lynne. The plugin now calculates my table rows as it should. Awesome!
Now I've just got to reinstall my test board after experimenting to find the best Hook for that plugin and turning my entire board white hehehe.

midnz 09-09-2010 09:12 AM

I thought I'd post here because my question relates to this same project. I hope that is okay.

I've 99.9% completed what I wanted to achieve. The only remaining issue that I'm unsure of how to fix is:
- How do I enable the parsing of either BBCode or HTML that is entered in to a text field in the AdminCP and outputted to a table cell in my custom php page?

http://img188.imageshack.us/img188/3...rslisttext.jpg

http://img40.imageshack.us/img40/549...tfieldques.jpg

I didn't do anything special with my 3.6.8 version to be able to achieve parsing HTML in the same circumstances (although BBCode didn't work there):

http://img266.imageshack.us/img266/4408/368c.jpg

Lynne 09-09-2010 02:25 PM

Look at the API (in Quick Links) for functions that deal with html and bbcode. I'm sure you'll find it in there.

midnz 09-10-2010 05:38 PM

Quote:

Originally Posted by Lynne (Post 2095855)
Look at the API (in Quick Links) for functions that deal with html and bbcode. I'm sure you'll find it in there.

Thanks again Lynne :). I found the problem and resolved it. I had typed {vb:var vboptions..... instead of {vb:raw vboptions.... .

100% working now
THE END :D


All times are GMT. The time now is 01:10 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.01313 seconds
  • Memory Usage 1,849KB
  • 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
  • (6)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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