PDA

View Full Version : I need some help with these files.


Parker Clack
10-30-2005, 02:54 PM
I have a banner rotation system that I am using with vB version 2.xx and I want to port it over to 3.5

How would I write the following to work with 3.5?

<?php
error_reporting(7);
require('./global.php');
$timenow = time();
$boarduser = $bbuserinfo['userid'];

if(isset($bannerid))
{
$banner = $DB_site->query_first("SELECT * FROM banner WHERE id='$bannerid'");
$url = $banner['redirector_url'];

if (!empty($boarduser))
{
$DB_site->query("UPDATE banner SET userclicks=userclicks+1 WHERE id='$bannerid'");

// is there a user in the table who still has clicked?
$clickeduser = $DB_site->query_first("SELECT * FROM userclicks WHERE userid='$boarduser' AND bannerid='$bannerid'");
$clickeduser = $clickeduser['userid'];
if(!empty($clickeduser))
$DB_site->query("UPDATE userclicks SET clicks=clicks+1 WHERE userid='$boarduser' AND bannerid='$bannerid'");
else
$DB_site->query("INSERT INTO userclicks (userid, bannerid, clicks) VALUES ('$boarduser', '$bannerid', '1')");
}
else
$DB_site->query("UPDATE banner SET guestclicks=guestclicks+1 WHERE id='$bannerid'");

header("Location:$url");
}
else
echo ("Please Include an ID!");
?>

and

<?php

$noheader=1;

//require("./global.php");

set_magic_quotes_runtime(0);

@error_reporting(7);

// ###################### Start init #######################

unset($dbservertype);

//load config
require('./admin/config.php');

// init db **********************
// load db class
$dbservertype = strtolower($dbservertype);
$dbclassname="./admin/db_$dbservertype.php";
require($dbclassname);

$DB_site=new DB_Sql_vb;

$DB_site->appname='vBulletin';
$DB_site->appshortname='vBulletin (forum)';
$DB_site->database=$dbname;
$DB_site->server=$servername;
$DB_site->user=$dbusername;
$DB_site->password=$dbpassword;

$DB_site->connect();

$dbpassword="";
$DB_site->password="";
// end init db

if(isset($bannerid))
{
$banner = $DB_site->query_first("SELECT * FROM banner WHERE id='$bannerid'");
$url = $banner['url_to_banner'];

$update = $DB_site->query("UPDATE banner SET views=views+1 WHERE id='$bannerid'");

header("Location:$url");
}
else
echo ("Please Include an ID!");
?>

Thanks for any help you can give.

Parker

Paul M
10-30-2005, 03:37 PM
Change $bbuserinfo to $vbulletin->userinfo and $DB_site to $vbulletin->db and you should be most of the way there.

Parker Clack
10-30-2005, 10:52 PM
For the first file does this look ok?

<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'click');


// ######################### REQUIRE BACK-END ############################
require('./global.php');

$timenow = time();
$boarduser = $vbulletin->userinfo['userid'];

if(isset($bannerid))

{
$banner = $vbulletin->db->query_first("SELECT * FROM " . TABLE_PREFIX . "banner WHERE id='$bannerid'");
$url = $banner['redirector_url'];

if (!empty($boarduser))
{
$vbulletin->db->query("UPDATE banner SET " . TABLE_PREFIX . "userclicks=userclicks+1 WHERE id='$bannerid'");

// is there a user in the table who still has clicked?
$clickeduser = $vbulletin->db->query_first("SELECT * FROM " . TABLE_PREFIX . "userclicks WHERE userid='$boarduser' AND bannerid='$bannerid'");
$clickeduser = $clickeduser['userid'];
if(!empty($clickeduser))
$vbulletin->db->query_first("UPDATE " . TABLE_PREFIX . "userclicks SET clicks=clicks+1 WHERE userid='$boarduser' AND bannerid='$bannerid'");
else
$vbulletin->db->query_first("INSERT INTO " . TABLE_PREFIX . "userclicks (userid, bannerid, clicks) VALUES ('$boarduser', '$bannerid', '1')");
}
else
$vbulletin->db->query_first("UPDATE banner SET " . TABLE_PREFIX . "guestclicks=guestclicks+1 WHERE id='$bannerid'");

header("Location:$url");
}
else
echo ("Please Include an ID!");
?>

and for the second

<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'view');

// ###################### Start init #######################

require("../includes/config.php");
$servername=$config['MasterServer']['servername'];
$dbusername=$config['MasterServer']['username'];
$dbpassword=$config['MasterServer']['password'];
$dbname=$config['Database']['dbname'];
$db=mysql_connect($servername,$dbusername,$dbpassw ord) or die("Can't open connection to MySQL");

mysql_select_db($dbname) or die("Can't select database");


if(isset($bannerid))
{
$banner = $vbulletin->db->query_first("SELECT * FROM " . TABLE_PREFIX . "banner WHERE id='$bannerid'");
$url = $banner['url_to_banner'];

$update = $vbulletin->db->query_first("UPDATE " . TABLE_PREFIX . "banner SET views=views+1 WHERE id='$bannerid'");

header("Location:$url");
}
else
echo ("Please Include an ID!");
?>

Thanks

Parker Clack
11-02-2005, 06:18 PM
I am having a problem with $bannerid from a link

For example

http://www.mysite.com/click.php?bannerid=50

The click and view files do not see the number 50 and so therefore return the "Please include ID".

Any ideas on what could be happening here?

Thanks,
Parker