PDA

View Full Version : Plugin Help Pretty-Please


midnz
09-05-2010, 07:34 AM
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:
</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/902/accountstable.jpg

The old plugin (for 3.6.8) automatically calculated the totals of the Debit, Credit and Balance columns and looks like this:
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($totaltotal, 2);
$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)
<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($totaltotal, 2);
$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:
$templater->register('totaldebits', $totaldebits);
$templater->register('totalcredits', $totalcredits);
$templater->register('totaltotal', $totaltotal);

The Totals Row of my table looks like this:
<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
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>.
</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.

I've attached the .xml and .php files in case that might assist with spotting what I've done wrong. 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:
$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/3628/admincpdonatorslisttext.jpg

http://img40.imageshack.us/img40/5497/vcaccountstextfieldques.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
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