PDA

View Full Version : EQDKP in the postbit


sifo
10-13-2007, 05:11 PM
I am trying to add a field in the postbit to display the users current DKP. I am somewhat of a novice but I have been learning rather quickly. The way my site is set up is that the EQDKP site and the vBulletin forums are separate MYSQL databases.

The way I envision this working is that I create a new User Profile Field through the Admin CP. It is just a string. My users enter their userid from our DKP site into that field. With this string entered into the 'fieldXX' (field6 for my board), I can use that string to index my array and extract the pertinent data to calculate the current DKP.

The code below works properly by itself but I don't have enough knowledge to incorporate it into vBulletin. I'm not sure if this is too much of a bother to even worry about or if it would take just a few lines in the right place - any help would be greatly appreciated.


<?php

mysql_connect("myserver.net","myusername","mypassword") or die(mysql_error());

mysql_select_db("mydatabase") or die(mysql_error());

// $dkpname is the string that will come from 'fieldXX' which is a user defined profile field to display in the postbit

$yourdkpname = mysql_query("SELECT * FROM eqdkp_members
WHERE member_name= '$dkpname'") or die(mysql_error());

$data = mysql_fetch_array($yourdkpname);

$yourdkp = $data['member_earned'] - $data['member_spent'] + $data['member_adjustment'];

// $yourdkp is the current dkp that I want to be displayed in the postbit

?>

Analogpoint
10-13-2007, 07:49 PM
To test this, just put the code you posted in a plugin that is fired on the global_start hook, then put $yourdkp in your postbit template (or postbit_legacy if that's the one you're using).

But please sanitize your database inputs. Do you know what would happen if someone entered this as their DKP userid?

joeblow'; drop table eqdkp_members; --

At least do this before your query.

$dkpname = mysql_real_escape_string($dkpname);

sifo
10-15-2007, 12:48 AM
I believe I have done everything you suggested. However, $yourdkp doesn't seem to be displaying. I have tried entering a manual value for $yourdkp and bypassed the database query in the plugin and I still don't get a value displayed.

This is what I entered in the postbit:

<if condition="$post['field6']">Current DKP: $yourdkp<else />Current DKP: N/A</if>


Thanks for your help!

Kiint
10-15-2007, 02:02 PM
I haven't really looked at your code, but this is what I use on my site in the profile of each person, I have a page that has this code:


$result = $db->query("SELECT * FROM " . TABLE_PREFIX . "`eqdkp_items`
LEFT JOIN eqdkp_raids ON eqdkp_items.raid_id=eqdkp_raids.raid_id
WHERE `item_buyer` = \"".$chardata[fname]."\"
ORDER BY `item_date` DESC");
$ii = $db->num_rows($result);
while($loot = $db->fetch_array($result)) {
$lootdate = date("D, F j, Y, g:i a", $loot[item_date]);
eval('$loothistory .= "' . fetch_template('roster_profile_loot') . '";');
}
$db->free_result($result);


Then a template called 'roster_profile_loot' with the following in it:


<tr>
<td class="alt1" align="left">
<a href="http://www.yoursite.com/eqdkp/viewitem.php?s=&i=$loot[item_id]" target="_blank">$loot[item_name]</a></td>
<td class="alt2" align="left">
<a href="http://www.yoursite.com/eqdkp/viewraid.php?s=&r=$loot[raid_id]" target="_blank">$loot[raid_name]</a></td>
<td class="alt1" align="left">
$lootdate
</td>
</tr>


Hope this helps a little :)

sifo
10-15-2007, 03:05 PM
That is definitely something I'd like to try and add in the future. I guess my real sticking point right now is how do I make a variable from a plugin to be passed/available for use in the postbit template?

Thanks again.

Analogpoint
10-15-2007, 06:48 PM
That is definitely something I'd like to try and add in the future. I guess my real sticking point right now is how do I make a variable from a plugin to be passed/available for use in the postbit template?

Thanks again.

What hook location is your plugin using?

Both the hook evaluation and template evaluation have to be in the same scope. If either one is in a function, it's not going to work.

If you do this, it'll work:

Plugin code:
$GLOBALS['somevar'] = 'Hey';

In the template:
Here's my variable: $GLOBALS[somevar]

sifo
10-16-2007, 09:14 AM
I got it to work properly... thanks for all of the help here!

Eikinskjaldi
10-16-2007, 01:44 PM
In mysql you can prepend the table with the database name.

In other words, you can use the vbulletin mysql object, you dont have to make another, and you can join, call, whatever across databases.

select db1.table1.field1,db2.table2.field2....

Oll1
12-22-2007, 12:58 AM
if you are unable to print out the mysql data from eqdkp - this will work:

in plugin:

$my_dkp = $vbulletin->userinfo[fieldX];

(Remember: NO <?php & ?> Tags !!!!!!!)

in template:

$my_dkp

works fine for me