PDA

View Full Version : PHP not working in module (vBadvanced CMPS v3.0.1+vBulletin 3.6.8)


X672
03-19-2010, 11:43 AM
Hello :)

I have also posted this on the vBadvanced CMPS forum a couple of days ago but it seems no one can help me there, hopefully someone here can :)

I have this PHP file I would like to run in a module (vBadvanced CMPS v3.0.1+vBulletin 3.6.8) on our Lord of the Rings Online kinship page but I can't get it to work and I don't know why.
It works fine if I just open it in the web browser but as soon as I put it in a module I get errors.

The PHP file get data from another database (EQdkp-plus) (http://www.x672.net/the-forgotten/eqdkp/)

http://x672.net/the-forgotten/modules/raid_tracker.php


<?php
/******************************
* EQDKP HomepageTools 1.1.0
* (c) 2006 - 2007 by kompsoft media
* Licensed under the GNU GPL.
* See COPYING for full terms.
* ------------------
* $Id: raid_tracker.php 290 2007-06-14 14:12:12Z wallenium $
******************************/

include_once('config.php');
include_once('include/hptools.class.php');
include_once('language/'.$config['language'].'.php');

$hpt = new HomepageTools($htdb['host'], $htdb['user'], $htdb['pass'], $htdb['datab'], $htdb['prefix'], $config, $htlang);
echo $hpt->event_tracker();

?>


the config.php file.


<?php
/******************************
* EQDKP HomepageTools 1.1.0
* (c) 2006 - 2007 by kompsoft media
* Licensed under the GNU GPL.
* See COPYING for full terms.
* ------------------
* $Id: config.php 296 2007-06-15 22:42:51Z wallenium $
******************************/

/******************************
* General Settings
******************************/
$htdb['host'] = "mysql.hosted.servetheworld.net:3306"; // Host
$htdb['user'] = "X672net_eclipse"; // Username of SQL
$htdb['pass'] = "Password removed"; // User Password
$htdb['datab'] = "X672net_eqdkp"; // database
$htdb['prefix'] = "eqdkp_"; // database prefix

// if in the same database as the CMS you want to include this script
// set it to 0! If not, you might get errors because of closing the
// database table.
$config['other_table'] = 0;

/******************************
* TIME SETTINGS
******************************/
$config['local'] = "de_DE"; // Local settings
$config['strftime'] = "%d.%m.%Y, %H:%M"; // time format of strftime()

/******************************
* GLOBAL SETTINGS
******************************/
// URL to DKP
$config['url'] = "http://www.x672.net/the-forgotten/eqdkp/";
// Path to itemstats
$config['is_path'] = "./eqdkp/itemstats";
// Path to homepagetools
$config['ht_path'] = "http://www.x672.net/the-forgotten/modules";
//Language
$config['language'] = "english";
// The Rest
$config['is_plus'] = 1; // EQDKP PLUS 0.4.3.x oder h?her?
$config['sort'] = "ASC"; // ASC = Ascending, DESC = descending
$config['is_img_path'] = "./"; // Path to the images, if you 're using ustom paths' (with ending slash)
$config['newwindow'] = 1; // Open Links in new window?

/******************************
* ITEM TRACKER
******************************/
$config['limit_by'] = "days"; // LIMIT BY:? (days, items, raid, dkp)
$config['item_number'] = 10; //How many days/items/raid (see option above) of raiding do you wish to show? (1 or more)

// settings :D
$config['showdays'] = 1; // Do you want to see the date of the raid? (1=yes 0=no)
$config['showheader'] = 1; // Do you want to see Name of each Raid?? (1=yes 0=no)*/
$config['uberloot'] = 2; // What loot should show. 0=green and above(default), 1=blue and above, 2=epic and above
$config['showwinner'] = 0; // Do you want to see who won the loot (1=yes 0=no)
$config['linkitem'] = 1; // Do you want to link to the item dkp page from the block? (1=yes 0=no)
$config['showDKP'] = 0; // Do you want to show the DKP Value at the list? (1=yes 0=no)
$config['textcolor'] = 0; // Show only the colored item name, no popup

/******************************
* RAID TRACKER
******************************/
$config['limit'] = "3"; // set the amount of entries to show
$config['link_calendar'] = 0; // Show a Link to the listraids.php
$config['show_tooltip'] = 1; // Show Tooltip with more information

/******************************
* BOSS TRACKER
******************************/
$config['view_kill_times'] = 0; // Do you want to see how often a boss was killing? (1=yes 0=down/waiting)

?>


So I got the raid_tracker.php to work but when I try to put it inside a module I just get this when I go to the kinship page. (www.x672.net/the-forgotten/) (vBulletin 3.6.8)
EQdkp-plus have it's own database that the PHP file is connecting to and is not the same one I use for vBadvanced CMPS v3.0.1


Database error in vBulletin 3.6.8:

Invalid SQL:

SELECT IF(votenum >= 1, votenum, 0) AS votenum, IF(votenum >= 1 AND votenum != 0, votetotal / votenum, 0) AS voteavg, votetotal, threadid, firstpostid
FROM mst_thread AS thread
WHERE visible = 1
AND open != 10
AND (thread.forumid IN(8)

)

ORDER BY dateline DESC
LIMIT 5;

MySQL Error : Table 'X672net_eqdkp.mst_thread' doesn't exist Error Number : 1146
Date : Tuesday, March 16th 2010 @ 09:29:11 AM
Script : http://x672.net/the-forgotten/
Referrer : http://x672.net/the-forgotten/
IP Address : XXX.XXX.XXX.XXX
Username : Gattsu
Classname : vB_Database


I have very limited PHP/vB skills so any help at all would be appreciated :)

Anseur
03-19-2010, 09:41 PM
I think we need to see the contents of the hptools.class.php to help you as well.

My knowledge of php is not great, but I can see roughly what is happening. Your script is trying to find a table called 'X672net_eqdkp.mst_thread' I guess X672net_eqdkp is your database, and mst_thread is a table in that database. Yet the script is trying to find a table with the name of both of them together.

Do you need the data to be in a module that is on an existing vB Advanced page (like the homepage?) or can it be on it's own vba page as the sole content?

I suspeect if you need it on your homepage, the script is going to have to be re-written a little, as what is happening at the moment tells me it's trying to find this table in your vb database instead of your eqdkp one, but I would need to see that other PHP file to be sure.

X672
03-20-2010, 10:03 AM
On it's own http://x672.net/the-forgotten/modules/raid_tracker.php is working just fine but it's then I try to put it in a module on my front page on the kinship page www.x672.net/the-forgotten/ that I get the error (Database error in vBulletin 3.6.8:).

X672net_eqdkp, that's the database for our EQdkp page.

mst_thread is a table in our vbulletine database.


<?php
/******************************
* EQDKP HomepageTools 1.1.0
* (c) 2006 - 2007 by kompsoft media
* Licensed under the GNU GPL.
* See COPYING for full terms.
* ------------------
* $Id: hptools.class.php 303 2007-06-17 23:18:43Z wallenium $
******************************/

class HomepageTools{

function HomepageTools($et_host, $et_user, $et_pass, $et_database, $et_prefix, $config, $etlanguage){
$this->config = $config;
$this->dbhost = $et_host;
$this->dbuser = $et_user;
$this->dbpass = $et_pass;
$this->database = $et_database;
$this->dbprefix = $et_prefix;
$this->htlanguage = $etlanguage;
}

/************************************
* Raidplan Event Tracker
************************************/

function event_tracker(){
setlocale (LC_TIME, $time['local']);
$htdb = @mysql_pconnect($this->dbhost, $this->dbuser, $this->dbpass);
if(!$htdb){
die($this->htlanguage['ht_no_data']);
}

mysql_select_db($this->database);
$etsql = "SELECT * FROM `".$this->dbprefix."raidplan_raids` WHERE raid_date > ".time()." ORDER BY `raid_date` ".$this->config['sort']." LIMIT ".$this->config['limit'];
$results = mysql_query($etsql);
$num_results = mysql_affected_rows();

if ($num_results == 0 || !$num_results){
return $this->htlanguage['ht_noraids'];
}

// stylesheet:
$overlibpath = str_replace("/", "\/", $this->config['is_path']);
$output = '<script>
if(typeof(window.overlib) == "undefined") {
document.write("<scr" + "ipt language=\'JavaScript\' type=\'text\/javascript\' src=\''.$overlibpath.'\/overlib\/overlib.js\'><\/scr" + "ipt>");
}
</script>';

$output .= ("<link REL=StyleSheet HREF='".$this->config['ht_path']."/css/hptools.css' TYPE='text/css' MEDIA=screen />");
$output .= "<div id='raidtable'>";

$windowthingy = ($this->config['newwindow'] == 1) ? "target='blank'" : "";
for($i =0; $i<$num_results; $i++){
$row = mysql_fetch_array($results);
// count the signed in members
$sql_count = "SELECT count(*) FROM ".$this->dbprefix."raidplan_raid_attendees WHERE attendees_subscribed=1 AND raid_id=" . $row['raid_id'];
if (!($count_result = mysql_query($sql_count))) { die($this->htlanguage['ht_error_noraid']); }
$count_signin = mysql_fetch_array($count_result);
// count the confirmed members
$sql_count = "SELECT count(*) FROM ".$this->dbprefix."raidplan_raid_attendees WHERE attendees_subscribed=0 AND raid_id=" . $row['raid_id'];
if (!($count_result = mysql_query($sql_count))) { die($this->htlanguage['ht_error_noraid']); }
$count_confirmed = mysql_fetch_array($count_result);
// count the signedout members
$sql_count = "SELECT count(*) FROM ".$this->dbprefix."raidplan_raid_attendees WHERE attendees_subscribed=2 AND raid_id=" . $row['raid_id'];
if (!($count_result = mysql_query($sql_count))) { die($this->htlanguage['ht_error_noraid']); }
$count_signedout = mysql_fetch_array($count_result);
// count the not shure members
$sql_count = "SELECT count(*) FROM ".$this->dbprefix."raidplan_raid_attendees WHERE attendees_subscribed=3 AND raid_id=" . $row['raid_id'];
if (!($count_result = mysql_query($sql_count))) { die($this->htlanguage['ht_error_noraid']); }
$count_notshure = mysql_fetch_array($count_result);
// count the total sum
$tssql = "SELECT raid_attendees FROM `".$this->dbprefix."raidplan_raids` WHERE raid_id='".$row['raid_id']."'";
if (!($count_result = mysql_query($tssql))) { die($this->htlanguage['ht_error_noraid']); }
$count_total = mysql_fetch_array($count_result);
$count_summ = $count_confirmed[0] + $count_signin[0];

// overlib
if($this->config['show_tooltip'] == 1){
$ht_overlib = "onmouseover=\"return overlib('<div class=\'httooltiphead\'>".$this->htlanguage['ht_information']."</div><div class=\'httooltipdiv\'>".$this->htlanguage['ht_note'].": ".$row['raid_note']."<br/>".$this->htlanguage['ht_raidleader'].": ".$row['raid_leader']."</div>',VAUTO,HAUTO,FULLHTML);\" onmouseout='return nd();'";
}else{
$ht_overlib = "";
}

// Output
$output .= " <a ".$windowthingy." href='".$this->config['url']."/plugins/raidplan/viewraid.php?r=". stripslashes($row['raid_id'])."' ".$ht_overlib." class='htlink_vr'>". stripslashes($row['raid_name']) ."</a> (<font class='summ'>".$count_summ."</font>/<font class='signedout'>".$count_signedout[0]."</font>/<font class='notshure'>".$count_notshure[0]."</font>/<font class='total'>".$count_total[0]."</font>)<br>";
$output .= "<div class='ht_time'>".strftime($this->config['strftime'], $row['raid_date'])."</div><br/>";
}
if($this->config['other_table'] == 1){
mysql_close($htdb);
}

if($this->config['link_calendar'] == 1){
$output .= "<br/><center><a ".$windowthingy." href='".$this->config['url']."/plugins/raidplan/listraids.php' class='htlink_lr'>". $this->htlanguage['ht_raidsummery']."</a></center>";
}
$output .= "</div>";
return $output;
}

/************************************
* Item Tracker
************************************/

function item_tracker(){
// debug thing to fetch all the stupid SQL Errors because of the EQDKP Plus globals
if (!$dbhost or !$dbname or !$dbuser or !$dbpass){
$dbhost = $this->dbhost;
$dbname = $this->database;
$dbuser = $this->dbuser;
$dbpass = $this->dbpass;
$table_prefix = $this->dbprefix;
$debug = 1;
}

// connect to database
$htdb = @mysql_pconnect($this->dbhost, $this->dbuser, $this->dbpass);
if(!$htdb){
die($this->htlanguage['ht_no_data']);
}
mysql_select_db($this->database);

// if PLUS, get the image path
if($this->config['is_plus'] == 1){
// Read the PLUS config
$csql = 'SELECT * FROM '.$this->dbprefix.'plus_config';
if (!($settings_result = mysql_query($csql))) { die('Could not obtain configuration data'); }
while($roww = mysql_fetch_array($settings_result)) {
$conf_plus[$roww['config_name']] = $roww['config_value'];
}
define('ICON_STORE_LOCATION', $conf_plus['pk_is_icon_loc']);
define('ICON_EXTENSION', $conf_plus['pk_is_icon_ext']);
}

// after that, include the itemstats thing...
// LOad Itemstats
$ht_itemstats_file = $this->config['is_path']."/eqdkp_itemstats.php";
if (@file_exists($ht_itemstats_file)) {
include_once($ht_itemstats_file);
}else{
die($this->htlanguage['ht_no_itemstats']);
}
$content = ""; // init the content var
setlocale (LC_TIME, $this->config['local']);

$isql = "SELECT MAX(item_date) as item_date, MAX(raid_id) as raid_id FROM ".$this->dbprefix."items";
$results = mysql_query($isql);
$maxdate = @mysql_fetch_array($results);
if (!$maxdate['item_date']){
return $this->htlanguage['ht_noitems'];
}
$startdate = ((floor($maxdate['item_date']/86400))*86400)-(($this->config['item_number']-1)*86400);
$ssql = "SELECT i.*, r.raid_name, r.raid_date
FROM ".$this->dbprefix."items i, ".$this->dbprefix."raids r
WHERE i.raid_id = r.raid_id";
if ($this->config['limit_by'] == "days"){
$ssql .= " AND i.item_date >= ".$startdate;
$ssql .= " AND i.item_date > 1";
$ssql .= " ORDER BY i.item_date ".$this->config['sort'];
$ssql .= " LIMIT ".$this->config['item_number'];
}elseif ($this->config['limit_by'] == "raid") {
$ssql .= " AND i.raid_id >= ".floor(($maxdate['raid_id']-$this->config['item_number'])+1);
$ssql .= " AND i.item_date > 1";
$ssql .= " ORDER BY i.item_date ".$this->config['sort'];
} elseif ($this->config['limit_by'] == "items"){
$ssql .= " ORDER BY i.item_date ".$this->config['sort'];
//$ssql .= " LIMIT ".$this->config['item_number'];
} elseif ($this->config['limit_by'] == "dkp"){
$ssql .= " ORDER BY i.item_value ".$this->config['sort'];
$ssql .= " LIMIT ".$this->config['item_number'];
}
$ssql .= ";";

$result = mysql_query($ssql);
$currentraid = 0;
$content .= "<link REL=StyleSheet HREF='".$this->config['is_path']."/templates/itemstats.css' TYPE='text/css' MEDIA=screen />";
$overlibpath = str_replace("/", "\/", $this->config['is_path']);
$content .= '<script>
if(typeof(window.overlib) == "undefined") {
document.write("<scr" + "ipt language=\'JavaScript\' type=\'text\/javascript\' src=\''.$overlibpath.'\/overlib\/overlib.js\'><\/scr" + "ipt>");
}
</script>';
$content .= ("<link REL=StyleSheet HREF='".$this->config['ht_path']."/css/hptools.css' TYPE='text/css' MEDIA=screen />");
$content .= "<div id='itemtable'>"; // Start the content layout in the block

if($this->config['showDKP'] == 1){
// get the name of the points saved in eqdkp database
$dkpsql = "SELECT config_value FROM ".$this->dbprefix."config WHERE config_name='dkp_name'";
$dkp_results = mysql_query($dkpsql);
$dkppname = @mysql_fetch_array($dkp_results);
}

//Check for Item Color and only displays based on variable above
$item_stats = new ItemStats();
if (!$item_stats){
echo "Error with Itemstats";
break;
}

$itemarray = array();
$ii = 1;
while($ii <= $this->config['item_number']){
$row = mysql_fetch_array($result);
$item_color = $item_stats->getItemColor($row['item_name']);
switch ($item_color) {
case "greyname": $itemlevel=0; break;
case "whitename": $itemlevel=0; break;
case "greenname": $itemlevel=1; break;
case "bluename": $itemlevel=2; break;
default: $itemlevel=3;
}
if ($itemlevel > $this->config['uberloot'] && isset($row['item_name'])) {
$itemarray[$row['item_id']] = array(
'item_name' => $row['item_name'],
'raid_id' => $row['raid_id'],
'raid_date' => $row['raid_date'],
'raid_name' => $row['raid_name'],
'item_value' => $row['item_value'],
'item_buyer' => $row['item_buyer'],
'item_level' => $itemlevel,
'item_color' => $item_color,
);
$ii++;
}
} // end while
foreach ($itemarray as $itemid => $itembody) {
$content .= "<div class='itemrow'>";
// Print the Raid Name if new raid
If ($currentraid <> $itembody['raid_id']){
if ($this->config['showheader'] == 1 and $itembody['raid_date'] > 1){
If ($this->config['showdays'] == 0) {
$content .= "<div class='itemraid'><a href='".$this->config['url']."/viewraid.php?s=&r=".$itembody['raid_id']."' target=blank ><img src='".$this->config['is_img_path']."img/lastpost.gif' /></a>".$itembody['raid_name']."</div>";
} else {
$content .= "<div class='itemraid'><a href='".$this->config['url']."/viewraid.php?s=&r=".$itembody['raid_id']."' target=blank ><img src='".$this->config['is_img_path']."img/lastpost.gif' /></a>".$itembody['raid_name']." ".strftime($this->config['strftime'],$itembody['raid_date'])."</div>";
}
}
$currentraid = $itembody['raid_id'];
}

if($this->config['showDKP'] == 1){
// get the name of the points saved in eqdkp database
$dkpvalue = "(".round($itembody['item_value'])." ".$dkppname['config_value'].")";
} else {
$dkpvalue = "";
}

// Passes the item name to the itemstats file for parsing and formatting
if ($this->config['linkitem'] == 1) {
$windowthingy = ($this->config['newwindow'] == 1) ? "target='blank'" : "";
if ($this->config['textcolor'] == 1){
$itemcontentthingy = "<span class='".$itembody['item_color']."'>".$itembody['item_name']."</span>";
}else{
$itemcontentthingy = itemstats_decorate_name($itembody['item_name']);
}
$content .= "<a ".$windowthingy." href='".$this->config['url']."/viewitem.php?i=".$itemid."'>".$itemcontentthingy."</a>";
} else {
$content .= itemstats_decorate_name($itembody['item_name']);
}

// Displays the winner of the item
if ($this->config['showwinner'] == 1) {
$content .="<div class='itemwinner'>".$this->htlanguage['ht_wonby'].": <a href='".$this->config['url']."/viewmember.php?s=&name=".$itembody['item_buyer']."' target=blank >".$itembody['item_buyer']."</a> ".$dkpvalue."</div>";
}else {
$content .= "<div class='itemwinner'>".$dkpvalue."</div>";
}
$content .= "</div>";
}//end foreach

$content .= "</div>";
if($this->config['other_table'] == 1){
mysql_close($htdb);
};
return $content;
}

/************************************
* Boss Tracker (written by Bigdaddy)
************************************/

function boss_tracker(){
$htdb = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpass);
if(!$htdb){
die($this->htlanguage['ht_no_data']);
}
mysql_select_db($this->database);
$bsql = "SELECT config_name FROM ".$this->dbprefix."bc_config WHERE config_value=1";
$result = mysql_query($bsql);
$progress = "<div id='bosstable'>"; //init Progress
while($row = mysql_fetch_array($result)){
$zone = split('[_]', $row[0]);;
$pz_search = "pz_".$zone[1];
$pz_sql = "SELECT config_value FROM ".$this->dbprefix."bb_config WHERE config_name='$pz_search'";
$pz_result = mysql_query($pz_sql);
while($pz_row = mysql_fetch_array($pz_result)){
$pz_name1 = explode(", ", $pz_row[0]);
$pz_name = substr($pz_name1[0],1,(strlen($pz_name1[0])-2));
$progress .= "<div class='ht_pz_name'>".$pz_name."</div>";

Switch($zone[1]){
Default:
$pb_search = array();break;
Case "kara":
$pb_search = array("pb_attumen","pb_moroes","pb_maiden","pb_opera","pb_curator","pb_illhoof","pb_aran","pb_chess","pb_netherspite","pb_malchezaar","pb_nightbane");break;
Case "maglair":
$pb_search = array("pb_magtheridon");break;
Case "gruuls":
$pb_search = array("pb_maulgar","pb_gruul");break;
Case "serpent":
$pb_search = array("pb_hydross","pb_karathress","pb_morogrim","pb_leotheras","pb_lurker","pb_vashj");break;
Case "eye":
$pb_search = array("pb_alar","pb_vreaver","pb_solarian","pb_kaelthas");break;
Case "hyjal":
$pb_search = array("pb_winterchill","pb_anetheron","pb_kazrogal","pb_azgalor","pb_archimonde");break;
Case "temple":
$pb_search = array("pb_najentus","pb_supremus","pb_akama","pb_gorefiend","pb_essence","pb_bloodboil","pb_shahraz","pb_council","pb_illidan");break;
}

for($i = 0; $i < count($pb_search); $i++) {
$pb_sql = "SELECT config_value FROM ".$this->dbprefix."bb_config WHERE config_name='$pb_search[$i]'";
$pb_result = mysql_query($pb_sql);
while($pb_row = mysql_fetch_array($pb_result)){
$pb_name1 = explode(", ", $pb_row[0]);
$pb_name = substr($pb_name1[0],1,(strlen($pb_name1[0])-2));
$progress .= "<div class='ht_ps_name'>".$pb_name." ";
$count = 0; // Count init
for($_i = 0; $_i < count($pb_name1); $_i++) {
// Hier muss dann gez?hlt werden.....
$_sql = "SELECT * FROM ".$this->dbprefix."raids WHERE raid_note=$pb_name1[$_i]";
$_result = mysql_query($_sql);
$count += @mysql_num_rows($_result);
}
if($this->config['view_kill_times'] == 1) {
$progress .= $count."x</div>";
}else{
if($count > 0) {
$progress .= "<div class='ht_progress_down'>".$this->htlanguage['ht_bt_down']."</div>";
}else{
$progress .= "<div class='ht_progress_waiting'>".$this->htlanguage['ht_bt_waiting']."</div>";
}
}
}
}
}
}
if($this->config['other_table'] == 1){
mysql_close($htdb);
}
$progress .= "</div>";
return $progress;
}
}
?>

Marco van Herwaarden
03-20-2010, 12:38 PM
If you have questions/problems with a modification or style, then please post in the thread (or support forum/board) about that modification/style. Best chance to receive a reply from either the author or another member using the same modification/style.

Anseur
03-20-2010, 05:41 PM
I'm afraid I think this custom code will need re-writing to be used as a vba module.

You could likley intergrate it as a PHP page with vba intergration features, but this would only give it you on it's own standalone page, not as a module. If you don't know any PHP, your going to need to hire someone to do this for you. There is a forum on this board to posts requests (paid or unpaid) for that purpose.

It might only be a 30min job for someone very adept at PHP, but I'm still a n00b at PHP or I would of taken a look for you.

kh99
03-20-2010, 06:15 PM
I think the problem is that the code is doing a "mysql_select_db" on a connection that vbulletin later tries to use (thinking it's still set to the vbulletin db). You could try to "cheat" by changing the setting to:

$htdb['datab'] = whatever your vbulletin db is
$htdb['prefix'] = "'X672net_eqdkp.eqdkp_";

This might work (based on a quick glance at the code) and avoids changing code. If it doesn't work you could try changing the code so it doesn't use mysql_select_db but instead puts the database name on each table reference (which you could probably do with a search and replace), and/or use the vbulletin db class instead of calling mysql calls.

X672
03-20-2010, 10:31 PM
Thanks for all the help, thing I will take a look at the paid part of the forum as I have very little knowledge but right now I'm going to finish my beer and take a look at this again tomorrow :)