<?php

/***************************************************************************

 bannerclick.php
 ----------------
 copyright : (C) 2002-2003 The ezContents Development Team

 ***************************************************************************/

/***************************************************************************
 The ezContents Development Team offers no warranties on this script.
 The owner/licensee of the script is solely responsible for any problems
 caused by installation of the script or use of the script.

 All copyright notices regarding ezContents must remain intact on the
 scripts and in the HTML for the scripts.

 For more info on ezContents,
 visit http://www.ezcontents.org/

/***************************************************************************

/***************************************************************************
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the License which can be found within the
 *	zipped package.
 *
 ***************************************************************************/

$GLOBALS["rootdp"] = './';
require_once ($GLOBALS["rootdp"]."include/config.php");
require_once ($GLOBALS["rootdp"]."include/db.php");
require_once ($GLOBALS["rootdp"]."include/session.php");


// Retrieve data for the banner that the viewer has clicked on,
//	update the number of clicks, and redirect the viewer to the
//	appropriate web page
if ($HTTP_GET_VARS["id"] != '') {
	$BannerUrl = GetBannerData($HTTP_GET_VARS["id"]);
	if ($BannerUrl != '') {
		Header("Location: ".$BannerUrl);
	}
} // if ($HTTP_GET_VARS["id"] != '')




// Retrieve the data for this banner
function GetBannerData($BannerID)
{
	$strQuery = "SELECT bannerurl,clicks FROM ".$GLOBALS["eztbBanners"]." WHERE bannerid='".$BannerID."'";
	$result = dbRetrieve($strQuery,true,0,0);
	if ($rs = dbFetch($result)) {
		$BannerUrl = trim($rs["bannerurl"]);
		UpdateClicks($BannerID);
	} // if ($rs = dbFetch($result))
	dbFreeResult($result);
	return $BannerUrl;
} // function GetBannerData()


// Update the 'clicks' count
function UpdateClicks($BannerID)
{
	$strQuery = "UPDATE ".$GLOBALS["eztbBanners"]." SET clicks=clicks+1 WHERE bannerid='".$BannerID."'";
	$result = dbExecute($strQuery,true);
	dbCommit();
} // function UpdateClicks()

?>
