/*
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
*/
include("includes/standardconfig.php");
include("includes/class.auth.php");
include("includes/MobileDetect.php");
$auth = new Auth();
$auth->CheckAuth();
$detect = new \Detection\MobileDetect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
if (preg_match("|Mozilla/5.0 (X11; Linux x86_64)|",$detect->getUserAgent())) $deviceType='phone';
if ($deviceType != 'computer')
header("Location: https://m.gtbd.us/");
if (empty($_REQUEST['Page'])) $_REQUEST['Page'] = 0;
$start = ($_REQUEST['Page'] * $perPage);
$_REQUEST['Search'] = (isset($_REQUEST['Search']) ? str_replace("%20"," ",$_REQUEST['Search']) : "");
$origPerPage = $perPage;
$perPage = $perPage * 2;
$halfBillboards = array();
$addQ = "";
if (isset($_REQUEST['CatID']) and !empty($_REQUEST['CatID'])) {
$addQ .= " And CategoryID=".$_REQUEST['CatID'];
}
if (isset($_REQUEST['RegionID']) and !empty($_REQUEST['RegionID'])) {
$addQ .= " And RegionID=".$_REQUEST['RegionID'];
}
$pathinfo = (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : "");
$params = preg_split('|/|', $pathinfo, -1, PREG_SPLIT_NO_EMPTY);
if (!empty($params) && !preg_match("/\?/",$params[0])) {
$_REQUEST['Search'] = ($params[0] == 'index.php' ? (!empty($params[1]) ? $params[1] : "") : $params[0]);
}
$_REQUEST['Search'] = str_replace("%20"," ",$_REQUEST['Search']);
if (!empty($_REQUEST['Search'])) {
$addQ = "AND (";
$searchTerms = explode(" ",$_REQUEST['Search']);
$myS = 0;
foreach ($searchTerms as $term) {
if ($myS > 0) $addQ .= " OR ";
$addQ .= "Keyword like '%".addslashes($term)."%' ";
$myS++;
}
if (is_numeric($_REQUEST['Search'])) $addQ .= " or BillboardID='".$_REQUEST['Search']."' ";
$addQ .= " or Username='".$_REQUEST['Search']."')";
}
$q = "select
billboards.*, Concat(BillboardFile,'?',unix_timestamp(NOW())) as BillboardFile
from
billboards
left join
billboard_categories using (BillboardID)
left join
billboard_regions using (BillboardID)
left join
( select BillboardID, group_concat(Keyword separator ' ') as Keyword from billboard_keywords group by BillboardID) as t1 using (BillboardID)
left join
clients using (ClientID)
where
Active='Y'
".$addQ."
".(!empty($_REQUEST['Let']) ? "and BillboardIdentifier like '".$_REQUEST['Let'].(!empty($_REQUEST['SL']) ? $_REQUEST['SL'] : "")."%'" : "")."
group by
BillboardID
Order By
DisplayOrder";
$r = $dbh->prepare($q);
$r->execute();
$rowCounter = 0;
$myCounter = 0;
$subCount = 0;
$prevBB = "";
while ($billBoard = $r->fetch()) {
if ($rowCounter >= $start) { break; }
if ((strtoupper($billBoard['BillboardType']) == 'HALF' && $subCount%2 == 0)) {
} else if ((strtoupper($billBoard['BillboardType']) == 'HALF')) {
$rowCounter++;
} else if ((strtoupper($billBoard['BillboardType']) == 'FULL') && $subCount%2 != 0) {
$rowCounter++;
if ($rowCounter >= $start) { break; }
$rowCounter++;
} else {
$rowCounter++;
}
if ((strtoupper($billBoard['BillboardType']) == 'HALF') || ((strtoupper($billBoard['BillboardType']) == 'FULL') && $subCount%2 != 0)) {
$subCount++;
}
$myCounter++;
}
$start = $myCounter;
$CategoryList = "\r\n";
$q = "select * from categories order by CategoryName";
$r = $dbh->prepare($q);
$r->execute();
while ($c = $r->fetch()) {
$CategoryList .= "\r\n";
}
$RegionList = "';
}
if ($prevReg != $c['RegionType']) {
$RegionList .= "";
$CategoryList = "\r\n";
$q = "select * from categories order by CategoryName";
$r = $dbh->prepare($q);
$r->execute();
while ($c = $r->fetch()) {
$CategoryList .= "\r\n";
}
$q = "select *, Concat(BillboardFile,'?',unix_timestamp(NOW())) as BillboardFile from billboards where BillboardIdentifier = 'YBBH' order by Rand()";
$r = $dbh->prepare($q);
$r->execute();
while ($c = $r->fetch()) {
$ybbHere[$c['BillboardType']][] = $c;
}
$q = "select
billboards.*, Concat(BillboardFile,'?',unix_timestamp(NOW())) as BillboardFile
from
billboards
left join
billboard_categories using (BillboardID)
left join
billboard_regions using (BillboardID)
left join
( select BillboardID, group_concat(Keyword separator ' ') as Keyword from billboard_keywords group by BillboardID) as t1 using (BillboardID)
left join
clients using (ClientID)
where
Active='Y'
".$addQ."
".(!empty($_REQUEST['Let']) ? "and BillboardIdentifier like '".$_REQUEST['Let'].(!empty($_REQUEST['SL']) ? $_REQUEST['SL'] : "")."%'" : "")."
group by
BillboardID
Order By
DisplayOrder
limit
".$start.", ".($perPage);
$r = $dbh->prepare($q);
$r->execute() or die($q);;
$allBillboards = array();
$numRows = 0;
$hasMore = 0;
$isFull = 0;
while ($c = $r->fetch()) {
$allBillboards[] = $c;
}
$ct = 0;
$subCount = 0;
$billboardContent = "";
$prevBB = "";
$toUse = array();
$rowCount = 0;
$myCount = 0;
foreach ($allBillboards as $billBoard) {
$q = "insert into billboards_impressions (BillboardID, IPAddress, Seen, Browser, Count) VALUES (".$billBoard['BillboardID'].", '".$_SERVER['REMOTE_ADDR']."', CURDATE(), '".
substr($_SERVER['HTTP_USER_AGENT'],0,189)."', 1) On Duplicate Key Update Count=Count+1";
$dbh->query($q);
$billboardInfo = array();
if ((strtoupper($billBoard['BillboardType']) == 'HALF' && $subCount%2 == 0)) {
$myRow = file_get_contents("templates/leftHalf.tmpl");
$myWidth = 618;
$billboardContent .= buildBillboardRow($billBoard,$myRow);
} else if ((strtoupper($billBoard['BillboardType']) == 'HALF')) {
$myWidth = 618;
$myRow = file_get_contents("templates/rightHalf.tmpl");
$billboardContent .= buildBillboardRow($billBoard,$myRow);
$rowCount++;
} else if ((strtoupper($billBoard['BillboardType']) == 'FULL') && $subCount%2 != 0) {
$myWidth = 618;
$myRow = file_get_contents("templates/rightHalf.tmpl");
$j = rand(0,count($ybbHere['Half'])-1);
$billboardContent .= buildBillboardRow($ybbHere['Half'][$j],$myRow);
$rowCount++;
if ($rowCount >= $origPerPage) { $hasMore = 1; break; }
$myWidth = 1241;
$myRow = file_get_contents("templates/full.tmpl");
$billboardContent .= buildBillboardRow($billBoard,$myRow);
$rowCount++;
} else {
$rowCount++;
$myWidth = 1241;
$myRow = file_get_contents("templates/full.tmpl");
$billboardContent .= buildBillboardRow($billBoard,$myRow);
}
if ($rowCount >= $origPerPage) { $hasMore = 1; break; }
if ((strtoupper($billBoard['BillboardType']) == 'HALF') || ((strtoupper($billBoard['BillboardType']) == 'FULL') && $subCount%2 != 0)) {
$subCount++;
}
}
if ($rowCount < $origPerPage) {
if ($subCount%2 != 0) {
$myWidth = 618;
$myRow = file_get_contents("templates/rightHalf.tmpl");
$j = rand(0,count($ybbHere['Half'])-1);
$billboardContent .= buildBillboardRow($ybbHere['Half'][$j],$myRow);
} else {
$myWidth = 1241;
$myRow = file_get_contents("templates/full.tmpl");
$j = rand(0,count($ybbHere['Full'])-1);
$billboardContent .= buildBillboardRow($ybbHere['Full'][$j],$myRow);
}
}
$letterBox = "";
for ($i=0;$i".$letter."";
}
if (isset($_REQUEST['Let'])) {
$row = file_get_contents("templates/subLetterRow.tmpl");
$myInfo = array();
$subLetterBox = "";
foreach ($letterArray as $letter) {
$subLetterBox .= $row;
$myInfo['TopLetter'] = $_REQUEST['Let'];
$myInfo['Letter'] = $letter;
$myInfo['subPage'] = 'index.php?Let='.$_REQUEST['Let'].(!empty($_REQUEST['CatID']) ? "&CatID=".$_REQUEST['CatID'] : "").
(!empty($_REQUEST['RegionID']) ? "&RegionID=".$_REQUEST['RegionID'] : "").(!empty($_REQUEST['Search']) ? "&Search=".$_REQUEST['Search'] : "")."&SL=".$letter;
$subLetterBox = preg_replace_callback(
'//',
function ($matches) {
global $myInfo;
return $myInfo[$matches[1]];
},
$subLetterBox
);
}
} else {
$subLetterBox = "";
}
$aspectRatio = 1396;
$content = array();
if ($_REQUEST['Page'] > 0) $content['displayPrev'] = 'block';
else $content['displayPrev'] = 'none';
if ($hasMore) $content['displayNext'] = 'block';
else $content['displayNext'] = 'none';
$content['nextPage'] = "index.php?".(!empty($_REQUEST['Let']) ? "Let=".$_REQUEST['Let']."&" : "").
(!empty($_REQUEST['SL']) ? "SL=".$_REQUEST['SL']."&" : "").
(!empty($_REQUEST['CatID']) ? "CatID=".$_REQUEST['CatID']."&" : "").
(!empty($_REQUEST['RegionID']) ? "RegionID=".$_REQUEST['RegionID']."&" : "").
(!empty($_REQUEST['Search']) ? "Search=".$_REQUEST['Search']."&" : "").
"&Page=".($_REQUEST['Page']+1);
$content['prevPage'] = "index.php?".(!empty($_REQUEST['Let']) ? "Let=".$_REQUEST['Let']."&" : "").
(!empty($_REQUEST['SL']) ? "SL=".$_REQUEST['SL']."&" : "").
(!empty($_REQUEST['CatID']) ? "CatID=".$_REQUEST['CatID']."&" : "").
(!empty($_REQUEST['RegionID']) ? "RegionID=".$_REQUEST['RegionID']."&" : "").
(!empty($_REQUEST['Search']) ? "Search=".$_REQUEST['Search']."&" : "").
"&Page=".($_REQUEST['Page']-1);
$content['letterBox'] = $letterBox;
$content['subLetterBox'] = $subLetterBox;
if ($isFull) $content['isFullPage'] = '100%';
else $content['isFullPage'] = '100%';
$content['billboardContent'] = $billboardContent;
$c = getBackground();
$backgroundImage = $c['BackgroundFile'];
$backgroundColor = $c['BackgroundColor'];
$backgroundAdName = $c['BackgroundAdName'];
$backgroundURL = $c['BackgroundURL'];
$backgroundID = $c['BackgroundID'];
$borderColor = $c['BorderColor'];
$content['backgroundImage'] = $backgroundImage;
$content['backgroundID'] = $backgroundID;
$content['backgroundURL'] = $backgroundURL;
$content['backgroundColor'] = $backgroundColor;
$content['BorderColor'] = $borderColor;
$content['backgroundAdName'] = $backgroundAdName;
$content['hideMobileOnly'] = 'hideMobile';
$content['adWidth'] = 16.5;
if ($deviceType != "computer") {
$content['hideMobileOnly'] = '';
$content['adWidth'] = 18.45;
}
$content['isLoggedIn'] = 'false';
if ($auth->loggedIn) {
$content['isLoggedIn'] = 'true';
}
$content['time'] = time();
$content['CategoryList'] = $CategoryList;
$content['RegionList'] = $RegionList;
$content['copyYear'] = date('Y');
$text = file_get_contents("templates/mainTemplate2.tmpl");
$text = str_replace("!!SEARCH!!",(!empty($_REQUEST['Search']) ? $_REQUEST['Search'] : ''), $text);
$text = preg_replace_callback(
'//',
function ($matches) {
global $content;
return $content[$matches[1]];
},
$text
);
if (preg_match("/AMPP/i",$_SERVER['HTTP_USER_AGENT'])) {
$text .= "";
} else {
$text .= "";
}
if ($backgroundURL != '') {
$text .= "";
}
echo $text;
function getBillboardInfo($BillboardID) {
global $dbh;
if (empty($BillboardID)) return;
$q = "select
BillboardID, BillboardTargetName, BillboardType, BillboardIdentifier, Concat(BillboardFile,'?',unix_timestamp(NOW())) as BillboardFile, b.*
from
billboards
left join
clients using (ClientID)
left join
billboard_information b using (BillboardID)
where
BillboardID = ".$BillboardID;
$r = $dbh->prepare($q);
$r->execute() or die(printArr($q));
$c = $r->fetch();
if (!empty($c)) {
$c['Buttons'] = array();
$q2 = "select * from billboard_buttons where BillboardID = ".$BillboardID." and ButtonExpiration > NOW() and Approved='Y' and Active='Y'";
$r2 = $dbh->prepare($q2);
$r2->execute() or die($q2);
while ($c2 = $r2->fetch()) {
$c['Buttons'][$c2['ButtonNumber']] = $c2;
}
}
return $c['Buttons'];
}
function buildBillboardRow($billBoard, $myRow) {
global $myWidth, $billboardInfo;
$billboardInfo['BillboardBorder'] = 'doBorder';
$billBoard['Buttons'] = getBillboardInfo($billBoard['BillboardID']);
$buttonContent = "";
if (!preg_match("/AMPP/i",$_SERVER['HTTP_USER_AGENT'])) {
for ($i=1;$i<5;$i++) {
if (!empty($billBoard['Buttons'][$i])) {
$buttonContent .= "";
} else {
$buttonContent .= "";
}
$buttonContent .= $i;
$buttonContent .= "";
}
$billboardInfo['Buttons'] = $buttonContent;
$billboardInfo['leftButtons'] = $buttonContent;
$buttonContent = "";
for ($i=5;$i<9;$i++) {
if (!empty($billBoard['Buttons'][$i])) {
$buttonContent .= "";
} else {
$buttonContent .= "";
}
$buttonContent .= $i;
$buttonContent .= "";
}
$billboardInfo['rightButtons'] = $buttonContent;
} else {
$billboardInfo['Buttons'] = $billboardInfo['leftButtons'] = $billboardInfo['rightButtons'] = " ";
}
$billboardInfo['isSpacer'] = "";
if (empty(substr($billBoard['BillboardIdentifier'],0,1))) $billboardInfo['isSpacer'] = "_imageSpacer";
$billboardInfo['BillboardFile'] = (!empty(substr($billBoard['BillboardIdentifier'],0,1)) ? $billBoard['ClientID']."/".$billBoard['BillboardFile'] : "spacer.png");
$billboardInfo['Billboard'] = "";
$billboardInfo['Billboard'] .= "";
$billboardInfo['Billboard'] .= '';
$myRow = preg_replace_callback(
'//',
function ($matches) {
global $billboardInfo;
return $billboardInfo[$matches[1]];
},
$myRow
);
return $myRow;
}
function getBackground() {
global $dbh;
$q = "select
BackgroundID,
Concat(BackgroundFile,'?',unix_timestamp(NOW())) as BackgroundFile,
BackgroundColor,
BackgroundURL,
BackgroundAdName,
BorderColor
from
backgrounds
Where
Active='Y'
and Approved='Y'
order by
RAND()
Limit 1";
$r = $dbh->prepare($q);
$r->execute();
$c = $r->fetch();
// if (!empty($_COOKIE['seenBackgrounds'])) {
// $seenBackgrounds = unserialize($_COOKIE['seenBackgrounds']);
// if (!in_array($backgroundID,$seenBackgrounds)) {
// $q = "update backgrounds set UniqueImpressions=UniqueImpressions+1 where BackgroundID=".$backgroundID;
// $dbh->query($q);
// $seenBackgrounds[] = $backgroundID;
// }
// setcookie('seenBackgrounds',serialize($seenBackgrounds));
// }
// setcookie('seenBackgrounds',serialize($seenBackgrounds));
$q = "update backgrounds set Impressions=Impressions+1 where BackgroundID=".$c['BackgroundID'];
$dbh->query($q);
return $c;
}