require($_SERVER["DOCUMENT_ROOT"]."/_includes/global_prepend.php");
require($_SERVER["DOCUMENT_ROOT"]."/_includes/functions.php");
header("content-type: application/x-javascript");
$adserve_security_on = true; // set to true when ready to launch. these next few lines keep people from embedding our adserve code.
$adserve_security_warning = false; // should always be false.
if($adserve_security_on) {
if(substr($current_referer, 7, 25) != "www.chattanoogabridge.com") {
$adserve_security_warning = true;
}
if(($adserve_security_warning)&&(substr($current_referer, 7, 21) != "chattanoogabridge.com")) {
exit();
}
}
function grab_300x250_ad_js() {
$rand = rand(1,2);
if ($rand == 1)
echo " document.write('
')\n";
if ($rand == 2)
echo " document.write('
')\n";
}
function grab_300x100_ad_js() {
$rand = rand(1,2);
if ($rand == 1)
echo " document.write('
')\n";
if ($rand == 2)
echo " document.write('
')\n";
}
$current_datetime = date('Y-m-d H:i:s');
$current_date = date('Y-m-d');
$day_begin = $current_date.' 00:00:00';
$day_end = $current_datetime.' 23:59:59';
$adtype = $_REQUEST["adtype"];
if((!$adtype)||($adtype != "300x250" && $adtype != "300x100")) {
exit;
}
if($adtype == "300x250") {
$ad_width = "300";
$ad_height = "250";
}
if($adtype == "300x100") {
$ad_width = "300";
$ad_height = "100";
}
$query_adserve = "SELECT DISTINCT a1.*, COUNT(a2.adid) AS todays_impressions FROM ads a1
LEFT JOIN adimpressions a2 ON a1.adid=a2.adid && a2.dateadded <= '$day_end' && a2.dateadded >= '$day_begin'
WHERE a1.adtype = '$adtype' && a1.startdate <= '$day_end' && a1.enddate >= '$day_begin' && a1.status = 'active'
GROUP BY a1.adid ORDER BY todays_impressions ASC LIMIT 1 ";
$result_adserve = mysql_query($query_adserve);
$numrows_adserve = mysql_num_rows($result_adserve);
while ($row = mysql_fetch_array($result_adserve)) {
$adid = $row['adid'];
$destination = $row['destination'];
$urlencoded_destination = urlencode($destination);
$clickTag = "http://www.chattanoogabridge.com/click?adid=".$adid."&dest=".$destination;
$clickTag = urlencode($clickTag);
$graphic_path = $row['graphic_path'];
$graphic_type = $row['graphic_type'];
$graphic_code = $row['graphic_code'];
$title = $row['title'];
$title = stripslashes(htmlspecialchars(strip_tags(htmlDecode($title)), ENT_QUOTES));
$display_url = $row['display_url'];
if(($graphic_type == "flash")&&($graphic_code)) {
echo " document.write('".$graphic_code."');document.write('