<?php
require_once(dirname(__FILE__).'/../config.php');
$GET_IP			=	$prepare->get_client_ip();

$geolocation      = ip2c_geolocation($GET_IP);
$ip['ADDRESS']	=	$GET_IP;


//*** GEOLOCATION ***//
$ip['CONTINENT_CODE']		=	$geolocation['continentCode'];
$ip['CONTINENT_NAME']		=	$geolocation['continentName'];
$ip['COUNTRY_CODE_2']		=	$geolocation['countryCode2'];
$ip['COUNTRY_CODE_3']		=	$geolocation['countryCode3'];
$ip['COUNTRY_NAME']			=	$geolocation['countryName'];
$ip['COUNTRY_LAT']			=	$geolocation['countryLatitude'];
$ip['COUNTRY_LONG']			=	$geolocation['countryLongitude'];

$ip['REGION_NAME']			=	$geolocation['regionName'];
$ip['CITY_NAME']			=	$geolocation['cityName'];
$ip['CITY_LAT']				=	$geolocation['cityLatitude'];
$ip['CITY_LONG']			=	$geolocation['cityLongitude'];




//*** GET ALL VARIABLES ***//
$counter		=	$prepare->sanitize( $_GET['ct'], 'input' );	//*** COUNTER, PREVEND DUBLICATE AD ***//
$slot			=	$prepare->sanitize( $_GET['s'], 'input' );	//*** SLOT ID ***//
$client			=	$prepare->sanitize( $_GET['c'], 'input' );	//*** AD PUB ID ***//
$string			=	$prepare->sanitize( $_GET['st'], 'input' );	//*** STRING ***//
$stringExplode	=	explode(',',$string);						//*** CREATE ARRAY ***//
$refer			=	$prepare->sanitize( $_GET['rf'], 'input' );	//*** REFERER ***//
$domain			=	$prepare->sanitize( $_GET['lh'], 'input' );	//*** LOCATION HOST ***//

$slotInfo	=	$db->Query("SELECT `pau_channel_id`, `pau_language_id`, `pau_size`, `pau_size_type`, `pau_adult`, `paud_title`, `paud_link`, `paud_text`, `paud_background`, `paud_border`, `pas_width`, `pas_height` FROM publishers_ad_units left join publishers_ad_units_design on publishers_ad_units_design.paud_ad_unit_id = publishers_ad_units.pau_id left join publishers_ads_size on publishers_ads_size.pas_id = publishers_ad_units.pau_size where pau_id=?","i",$slot);


//*** CLEAN STRING - TOP KEYWORDS ***//
$counting = $prepare->getPhraseCount($string,1,6);
$blockKeywords = array(
			"or",
			"the",
			"you",
			"me",
			"by",
			"with",
			"will",
			"these",
			"just",
			"that",
			"this",
			"can",
			""
						);
$keywordsSQL	=	' aauk_keyword = \'' . $stringExplode['0'] . '\'';
$i = 0;
$lmt = "3";
foreach ($counting as $key => $value) {
if(
	( strlen($key)>$lmt or strlen($key) == $lmt ) 
	and (!in_array($key, $blockKeywords))
	){
			$type = 'or';
			$keywordsSQL .= "  ".$type." aauk_keyword = '".$key."' ";
$i++;
		}
}
$country	=	$db->Query("SELECT `country_id` FROM countries where country_name=? limit 1","s",$ip['COUNTRY_NAME']);
$countrySQL	=	" aau_target_country = '".$country['0']['country_id']."' or aau_target_country = '0' ";

//*** AD TYPES ***//
/*
	1 : TEXT / BANNER AD
	2 : ONLY TEXT AD
	3 : ONLY BANNER AD
*/

//*** GENERATE LIMIT SQL ***//
	$limitSQL	=	" LIMIT 1";
//*** END LIMIT SQL ***//



//** DON'T SHOW THE LATEST 2 SECONDS VIEWED ADS **//
$NOW		=	strtotime("+2 seconds");
$MAX_TIME	=	strtotime("-2 seconds");

$LATEST_IDS	=	$db->Query("SELECT `aav_ad_id` FROM advertisers_ad_views where aav_ip=? and aav_date>? and aav_date<?","sii",$GET_IP,$MAX_TIME,$NOW);
$z	=	0;
foreach ( $LATEST_IDS as $IDF ) {

	if ( $IDF['aav_ad_id'] > 0 ) {
			if ( $z== 0 ) {
				$ftF	=	' and ';
			} else {
				$ftF	=	'';
			}
			
			if ( $z> 0 ) {
				$ft	=	' and ';
			}


					$idsSQL .= $ftF.$ft." aau_id!='" . $IDF['aav_ad_id'] . "' ";
		$z++;
	}
}
//******************* END *******************//












if ( $slotInfo['0']['pau_size_type'] == 1 ) {//*** IF WE DON'T NEED TO VALIDATE THE AD TYPE ONLY THE AD SIZE ***//	

	$width	=	$slotInfo['0']['pas_width'];
	$height	=	$slotInfo['0']['pas_height'];

	$ad	=	$db->Query("SELECT `aau_target_url`, `aau_user_id`, `aau_id`, `aau_campaign`, `aau_title`, `aau_summary`, `aau_summary_2`, `aau_type`, `aau_file`, `aauk_keyword`, `aauk_price` FROM advertisers_ad_units left join advertisers_campaigns on advertisers_campaigns.adv_campaign_id = advertisers_ad_units.aau_campaign left join advertisers_sizes on advertisers_sizes.adv_sizes_id = advertisers_ad_units.aau_size left join advertisers_ad_units_keywords on advertisers_ad_units_keywords.aauk_ad_id = advertisers_ad_units.aau_id left join advertisers_profiles on advertisers_profiles.adv_profile_user_id = advertisers_ad_units.aau_user_id where aau_status=? and adv_campaign_status=? and adv_campaign_daily_budget>adv_campaign_daily_spent and adv_profile_deposits > aauk_price and ( ( adv_sizes_width =? and adv_sizes_height=? ) or aau_type=? ) and ( " . $keywordsSQL . " ) and ( " . $countrySQL . " ) ".$idsSQL." order by COALESCE(aauk_price, 0) DESC ".$limitSQL,"iiiii",1,1,$width,$height,1);








	if ( $ad['0']['aau_type'] == '1' ) {

//*** GENERATE REDIRECT URL ***//
$URL_USER			=	$ad['0']['aau_user_id']; 	//*** ADVERTISER USER ID ***//
$URL_AD_ID			=	$ad['0']['aau_id'];			//*** AD ID ***//
$URL_KEYWORD		=	$ad['0']['aauk_keyword'];	//*** KEYWORD ***//
$URL_KEYWORD_PRICE	=	$ad['0']['aauk_price'];		//*** KEYWORD PRICE ***//
$URL_TARGET			=	$ad['0']['aau_target_url'];	//*** TARGET URL ***//
$HTTP_DOMAIN		=	$prepare->addhttp ( $domain );
$HTTP_REFERER		=	$prepare->addhttp ( $refer );
$URL_DOMAIN			=	$prepare->get_domain( $HTTP_DOMAIN );//*** DOMAIN WHERE THE AD WAS CLICKED ***//
$URL_REFERER		=	$prepare->get_domain( $HTTP_REFERER );//*** DOMAIN WHERE THE AD WAS CLICKED ***//
$URL_CAMPAIGN		=	$ad['0']['aau_campaign'];

$URL	=	'user=' . $URL_USER . '&ad_id=' . $URL_AD_ID . '&keyword=' . $URL_KEYWORD . '&keyword_price=' . $URL_KEYWORD_PRICE . '&url_target=' . $URL_TARGET . '&slot=' . $slot . '&channel_id=' . $slotInfo['0']['pau_channel_id'] . '&client=' . $client . '&referer=' . $URL_REFERER . '&domain=' . $URL_DOMAIN . '&campaign=' . $URL_CAMPAIGN;



$FULL_URL	=	base64_encode( $URL );
//*** END GENERATE REDIRECT URL ***//


if ( $slotInfo['0']['pas_width'] == '728' && $slotInfo['0']['pas_height'] == '90' ) {
	echo '
	<style>
	#ad-design-div-728_90{background:#fff;border-radius:0;padding:5px;line-height:25px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:716px;height:78px}
	#ad-design-div-728_90 #title-color-preview{color:#00f;font-size:31px;line-height:30px;text-decoration:none}
	#ad-design-div-728_90 #link-color-preview{color:#0e8f0e;font-size:15px}
	#ad-design-div-728_90 #text-color-preview{color:#333;font-size:17px;margin-bottom:5px}
	#ad-design-div-728_90 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-728_90 #button-color-preview{background:#3f9f3f;color:#fff;width:125px;height:50px;font-size:50px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:48px;text-align:center;cursor:pointer;position:absolute;right:11px;top:21px}
	#ad-design-div-728_90 a{text-decoration:none}
	#ad-design-div-728_90 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-728_90 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-728_90 #button-report:hover{opacity:.9}
	#ad-design-div-728_90 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '468' && $slotInfo['0']['pas_height'] == '60' ) {
	echo '
	<style>
	#ad-design-div-468_60{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:462px;height:54px}
	#ad-design-div-468_60 #title-color-preview{color:#00f;font-size:21px;line-height:21px;text-decoration:none}
	#ad-design-div-468_60 #link-color-preview{color:#0e8f0e;font-size:12px;line-height:15px}
	#ad-design-div-468_60 #text-color-preview{color:#333;font-size:14px}

	#ad-design-div-468_60 #button-report img{height:9px}
	#ad-design-div-468_60 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-468_60 #button-color-preview{background:#3f9f3f;color:#fff;width:85px;height:35px;font-size:30px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:38px;text-align:center;cursor:pointer;position:absolute;right:11px;top:5px}
	#ad-design-div-468_60 a{text-decoration:none}
	#ad-design-div-468_60 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-468_60 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-468_60 #button-report:hover{opacity:.9}
	#ad-design-div-468_60 .no-underline:hover { text-decoration:none; }
	</style>';
}

if ( $slotInfo['0']['pas_width'] == '160' && $slotInfo['0']['pas_height'] == '60' ) {
	echo '
	<style>
	#ad-design-div-160_60{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:154px;height:54px}
	#ad-design-div-160_60 #title-color-preview{color:#00f;font-size:13px;line-height:13px;text-decoration:none;text-align:center;}
	#ad-design-div-160_60 #link-color-preview{color:#0e8f0e;font-size:11px;line-height:10px}
	#ad-design-div-160_60 #text-color-preview{color:#333;font-size:14px;display:none;}
	#ad-design-div-160_60 #button-color-preview{background:#3f9f3f;color:#fff;width:85px;height:17px;font-size:19px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:18px;text-align:center;cursor:pointer;position:absolute;right:41px;top:40px}
	#ad-design-div-160_60 #button-report img{height:9px}
	#ad-design-div-160_60 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-160_60 a{text-decoration:none}
	#ad-design-div-160_60 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-160_60 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-160_60 #button-report:hover{opacity:.9}
	#ad-design-div-160_60 .no-underline:hover { text-decoration:none; }
	</style>';
}



if ( $slotInfo['0']['pas_width'] == '120' && $slotInfo['0']['pas_height'] == '600' ) {
	echo '
	<style>
	#ad-design-div-120_600{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:114px;height:594px}
	#ad-design-div-120_600 #title-color-preview{color:#00f;font-size:30px;line-height:35px;text-decoration:none;text-align:center;}
	#ad-design-div-120_600 #link-color-preview{color:#0e8f0e;font-size:18px;line-height:20px;text-align:center;margin-top:15px;margin-bottom:15px;}
	#ad-design-div-120_600 #text-color-preview{color:#333;font-size:22px;line-height: 30px;text-align: center;}
	#ad-design-div-120_600 #button-color-preview{background:#3f9f3f;color:#fff;width:110px;height:50px;font-size:50px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:48px;text-align:center;cursor:pointer;position:absolute;right:5px;bottom:19px}
	#ad-design-div-120_600 #button-report img{height:9px}
	#ad-design-div-120_600 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-120_600 a{text-decoration:none}
	#ad-design-div-120_600 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-120_600 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-120_600 #button-report:hover{opacity:.9}
	#ad-design-div-120_600 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '160' && $slotInfo['0']['pas_height'] == '600' ) {
	echo '
	<style>
	#ad-design-div-160_600{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:154px;height:594px}
	#ad-design-div-160_600 #title-color-preview{color:#00f;font-size:37px;line-height:35px;text-decoration:none;text-align:center;margin-top:15px;}
	#ad-design-div-160_600 #link-color-preview{color:#0e8f0e;font-size:18px;line-height:20px;text-align:center;margin-top:15px;margin-bottom:15px;}
	#ad-design-div-160_600 #text-color-preview{color:#333;font-size:26px;line-height: 35px;text-align: center;margin-top: 25px;}
	#ad-design-div-160_600 #button-color-preview{background:#3f9f3f;color:#fff;width:137px;height:50px;font-size:50px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:48px;text-align:center;cursor:pointer;position:absolute;right:12px;bottom:19px}
	#ad-design-div-160_600 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-160_600 a{text-decoration:none}
	#ad-design-div-160_600 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-160_600 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-160_600 #button-report:hover{opacity:.9}
	#ad-design-div-160_600 .no-underline:hover { text-decoration:none; }
	</style>';
}




if ( $slotInfo['0']['pas_width'] == '120' && $slotInfo['0']['pas_height'] == '240' ) {
	echo '
	<style>
	#ad-design-div-120_240{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:114px;height:234px}
	#ad-design-div-120_240 #title-color-preview{color:#00f;font-size:15px;line-height:15px;text-decoration:none;text-align:center;margin-top:5px}
	#ad-design-div-120_240 #link-color-preview{color:#0e8f0e;font-size:13px;line-height:15px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-120_240 #text-color-preview{color:#333;font-size:14px;line-height:17px;text-align:center;margin-top:10px}
	#ad-design-div-120_240 #button-color-preview{background:#3f9f3f;color:#fff;width:96px;height:50px;font-size:50px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:48px;text-align:center;cursor:pointer;position:absolute;right:12px;bottom:19px}
	#ad-design-div-120_240 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-120_240 a{text-decoration:none}
	#ad-design-div-120_240 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-120_240 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-120_240 #button-report:hover{opacity:.9}
	#ad-design-div-120_240 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '336' && $slotInfo['0']['pas_height'] == '280' ) {
	echo '
	<style>
	#ad-design-div-336_280{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:330px;height:274px}
	#ad-design-div-336_280 #title-color-preview{color:#00f;font-size:31px;line-height:29px;text-decoration:none;text-align:center;margin-top:5px}
	#ad-design-div-336_280 #link-color-preview{color:#0e8f0e;font-size:20px;line-height:21px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-336_280 #text-color-preview{color:#333;font-size:24px;line-height:34px;text-align:center;margin-top:10px;margin-bottom:5px;}
	#ad-design-div-336_280 #button-color-preview{background:#3f9f3f;color:#fff;width:186px;height:60px;font-size:60px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:57px;text-align:center;cursor:pointer}
	#ad-design-div-336_280 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-336_280 a{text-decoration:none}
	#ad-design-div-336_280 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-336_280 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-336_280 #button-report:hover{opacity:.9}
	#ad-design-div-336_280 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '300' && $slotInfo['0']['pas_height'] == '250' ) {
	echo '
	<style>
	#ad-design-div-300_250{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:294px;height:244px}
	#ad-design-div-300_250 #title-color-preview{color:#00f;font-size:26px;line-height:23px;text-decoration:none;text-align:center;margin-top:5px}
	#ad-design-div-300_250 #link-color-preview{color:#0e8f0e;font-size:20px;line-height:21px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-300_250 #text-color-preview{color:#333;font-size:20px;line-height:28px;text-align:center;margin-top:10px;margin-bottom:5px;}
	#ad-design-div-300_250 #button-color-preview{background:#3f9f3f;color:#fff;width:186px;height:60px;font-size:60px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:57px;text-align:center;cursor:pointer}
	#ad-design-div-300_250 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-300_250 a{text-decoration:none}
	#ad-design-div-300_250 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-300_250 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-300_250 #button-report:hover{opacity:.9}
	#ad-design-div-300_250 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '250' && $slotInfo['0']['pas_height'] == '250' ) {
	echo '
	<style>
	#ad-design-div-250_250{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:244px;height:244px}
	#ad-design-div-250_250 #title-color-preview{color:#00f;font-size:21px;line-height:22px;text-decoration:none;text-align:center;margin-top:5px}
	#ad-design-div-250_250 #link-color-preview{color:#0e8f0e;font-size:17px;line-height:16px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-250_250 #text-color-preview{color:#333;font-size:17px;line-height:28px;text-align:center;margin-top:10px;margin-bottom:5px;}
	#ad-design-div-250_250 #button-color-preview{background:#3f9f3f;color:#fff;width:186px;height:60px;font-size:60px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:57px;text-align:center;cursor:pointer}
	#ad-design-div-250_250 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-250_250 a{text-decoration:none}
	#ad-design-div-250_250 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-250_250 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-250_250 #button-report:hover{opacity:.9}
	#ad-design-div-250_250 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '200' && $slotInfo['0']['pas_height'] == '200' ) {
	echo '
	<style>
	#ad-design-div-200_200{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:194px;height:194px}
	#ad-design-div-200_200 #title-color-preview{color:#00f;font-size:18px;line-height:19px;text-decoration:none;text-align:center;margin-top:5px}
	#ad-design-div-200_200 #link-color-preview{color:#0e8f0e;font-size:13px;line-height:16px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-200_200 #text-color-preview{color:#333;font-size:14px;line-height:19px;text-align:center;margin-top:10px;margin-bottom:5px;}
	#ad-design-div-200_200 #button-color-preview{background:#3f9f3f;color:#fff;width:186px;height:40px;font-size:50px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:39px;text-align:center;cursor:pointer}
	#ad-design-div-200_200 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-200_200 a{text-decoration:none}
	#ad-design-div-200_200 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-200_200 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-200_200 #button-report:hover{opacity:.9}
	#ad-design-div-200_200 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '180' && $slotInfo['0']['pas_height'] == '150' ) {
	echo '
	<style>
	#ad-design-div-180_150{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:174px;height:144px}
	#ad-design-div-180_150 #title-color-preview{color:#00f;font-size:17px;line-height:18px;text-decoration:none;text-align:center;margin-top:5px}
	#ad-design-div-180_150 #link-color-preview{color:#0e8f0e;font-size:12px;line-height:7px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-180_150 #text-color-preview{color:#333;font-size:13px;line-height:15px;text-align:center;margin-top:10px;margin-bottom:5px;}
	#ad-design-div-180_150 #button-color-preview{background:#3f9f3f;color:#fff;width:126px;height:30px;font-size:40px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:31px;text-align:center;cursor:pointer}
	#ad-design-div-180_150 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-180_150 a{text-decoration:none}
	#ad-design-div-180_150 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-180_150 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-180_150 #button-report:hover{opacity:.9}
	#ad-design-div-180_150 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '125' && $slotInfo['0']['pas_height'] == '125' ) {
	echo '
	<style>
	#ad-design-div-125_125{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:119px;height:119px}
	#ad-design-div-125_125 #title-color-preview{color:#00f;font-size:14px;line-height:15px;text-decoration:none;text-align:center;}
	#ad-design-div-125_125 #link-color-preview{color:#0e8f0e;font-size:12px;line-height:20px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-125_125 #text-color-preview{color:#333;font-size:13px;line-height:15px;text-align:center;margin-top:10px;margin-bottom:5px;display:none;}
	#ad-design-div-125_125 #button-color-preview{background:#3f9f3f;color:#fff;width:96px;height:27px;font-size:30px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:27px;text-align:center;cursor:pointer}
	#ad-design-div-125_125 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-125_125 a{text-decoration:none}
	#ad-design-div-125_125 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-125_125 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-125_125 #button-report:hover{opacity:.9}
	#ad-design-div-125_125 .no-underline:hover { text-decoration:none; }
	</style>';
}


echo '
<div id="ad-design-div-' . $slotInfo['0']['pas_width'] . '_' . $slotInfo['0']['pas_height'] . '" style="border: 1px solid rgb(199, 199, 199); background: rgb(250, 250, 250);">
	<a target="_top" href="' . HTTP_SERVER_WEBSITE . 'pagead/redirect?c=' . $FULL_URL . '">
		<div id="title-color-preview" style="color: rgb(255, 0, 0);">' . $ad['0']['aau_title'] . '</div>
	</a>
	<a target="_top" href="' . HTTP_SERVER_WEBSITE . 'pagead/redirect?c=' . $FULL_URL . '">
		<div id="link-color-preview" style="color: rgb(28, 71, 28);">' . $ad['0']['aau_url'] . '</div>
	</a>
	<div id="text-color-preview" style="color: rgb(41, 48, 148);">' . $ad['0']['aau_summary'] . ' ' . $ad['0']['aau_summary_2'] . '</div>
	<a class="no-underline" target="_top" href="' . HTTP_SERVER_WEBSITE . 'pagead/redirect?c=' . $FULL_URL . '">
		<div id="button-color-preview" style="color: rgb(250, 250, 250); background: rgb(28, 71, 28);">&gt;</div>
	</a>
	<a id="button-report" target="_new" href="'. HTTP_REPORT_URL .'?r='.$FULL_URL.'"><img src="'. HTTP_SERVER_WEBSITE . 'templates/' . WEBSITE_TEMPLATE . '/assets/images/report.png"/></a>
</div>
';

	}

	if ( $ad['0']['aau_type'] == '2' ) {

//*** GENERATE REDIRECT URL ***//
$URL_USER			=	$ad['0']['aau_user_id']; 	//*** ADVERTISER USER ID ***//
$URL_AD_ID			=	$ad['0']['aau_id'];			//*** AD ID ***//
$URL_KEYWORD		=	$ad['0']['aauk_keyword'];	//*** KEYWORD ***//
$URL_KEYWORD_PRICE	=	$ad['0']['aauk_price'];		//*** KEYWORD PRICE ***//
$URL_TARGET			=	$ad['0']['aau_target_url'];	//*** TARGET URL ***//
$HTTP_DOMAIN		=	$prepare->addhttp ( $domain );
$HTTP_REFERER		=	$prepare->addhttp ( $refer );
$URL_DOMAIN			=	$prepare->get_domain( $HTTP_DOMAIN );//*** DOMAIN WHERE THE AD WAS CLICKED ***//
$URL_REFERER		=	$prepare->get_domain( $HTTP_REFERER );//*** DOMAIN WHERE THE AD WAS CLICKED ***//
$URL_CAMPAIGN		=	$ad['0']['aau_campaign'];

$URL	=	'user=' . $URL_USER . '&ad_id=' . $URL_AD_ID . '&keyword=' . $URL_KEYWORD . '&keyword_price=' . $URL_KEYWORD_PRICE . '&url_target=' . $URL_TARGET . '&slot=' . $slot . '&channel_id=' . $slotInfo['0']['pau_channel_id'] . '&client=' . $client . '&referer=' . $URL_REFERER . '&domain=' . $URL_DOMAIN . '&campaign=' . $URL_CAMPAIGN;


$FULL_URL	=	base64_encode( $URL );
//*** END GENERATE REDIRECT URL ***//


	echo '
	<style>
	#button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#button-report:hover{opacity:.9}
	</style>
	';

	echo '<a target="_top" href="' . HTTP_SERVER_WEBSITE . 'pagead/redirect?c=' . $FULL_URL . '"><img src="'.HTTP_SERVER_WEBSITE_UPLOADS_BANNER_ADS.$ad['0']['aau_file'].'"/></a>
	<a id="button-report" target="_new" href="'. HTTP_REPORT_URL .'?r='.$FULL_URL.'"><img src="'. HTTP_SERVER_WEBSITE . 'templates/' . WEBSITE_TEMPLATE . '/assets/images/report.png"/></a>';

	}


}

if ( $slotInfo['0']['pau_size_type'] == 2 ) { //*** IF WE NEED TO HAVE ONLY TEXT ADS ***//

	$width	=	$slotInfo['0']['pas_width'];
	$height	=	$slotInfo['0']['pas_height'];

	$ad	=	$db->Query("SELECT `aau_target_url`, `aau_user_id`, `aau_id`, `aau_campaign`, `aau_title`, `aau_summary`, `aau_summary_2`, `aau_url`, `aauk_keyword`, `aauk_price` FROM advertisers_ad_units left join advertisers_campaigns on advertisers_campaigns.adv_campaign_id = advertisers_ad_units.aau_campaign left join advertisers_ad_units_keywords on advertisers_ad_units_keywords.aauk_ad_id = advertisers_ad_units.aau_id left join advertisers_profiles on advertisers_profiles.adv_profile_user_id = advertisers_ad_units.aau_user_id where aau_status=? and adv_campaign_status=? and adv_campaign_daily_budget>adv_campaign_daily_spent and adv_profile_deposits > aauk_price and aau_type=? and ( " . $keywordsSQL . " ) and ( " . $countrySQL . " ) ".$idsSQL."  order by COALESCE(aauk_price, 0) DESC ".$limitSQL,"iii",1,1,1);

//*** GENERATE REDIRECT URL ***//
$URL_USER			=	$ad['0']['aau_user_id']; 	//*** ADVERTISER USER ID ***//
$URL_AD_ID			=	$ad['0']['aau_id'];			//*** AD ID ***//
$URL_KEYWORD		=	$ad['0']['aauk_keyword'];	//*** KEYWORD ***//
$URL_KEYWORD_PRICE	=	$ad['0']['aauk_price'];		//*** KEYWORD PRICE ***//
$URL_TARGET			=	$ad['0']['aau_target_url'];	//*** TARGET URL ***//
$HTTP_DOMAIN		=	$prepare->addhttp ( $domain );
$HTTP_REFERER		=	$prepare->addhttp ( $refer );
$URL_DOMAIN			=	$prepare->get_domain( $HTTP_DOMAIN );//*** DOMAIN WHERE THE AD WAS CLICKED ***//
$URL_REFERER		=	$prepare->get_domain( $HTTP_REFERER );//*** DOMAIN WHERE THE AD WAS CLICKED ***//
$URL_CAMPAIGN		=	$ad['0']['aau_campaign'];

$URL	=	'user=' . $URL_USER . '&ad_id=' . $URL_AD_ID . '&keyword=' . $URL_KEYWORD . '&keyword_price=' . $URL_KEYWORD_PRICE . '&url_target=' . $URL_TARGET . '&slot=' . $slot . '&channel_id=' . $slotInfo['0']['pau_channel_id'] . '&client=' . $client . '&referer=' . $URL_REFERER . '&domain=' . $URL_DOMAIN . '&campaign=' . $URL_CAMPAIGN;


$FULL_URL	=	base64_encode( $URL );
//*** END GENERATE REDIRECT URL ***//


if ( $slotInfo['0']['pas_width'] == '728' && $slotInfo['0']['pas_height'] == '90' ) {
	echo '
	<style>
	#ad-design-div-728_90{background:#fff;border-radius:0;padding:5px;line-height:25px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:716px;height:78px}
	#ad-design-div-728_90 #title-color-preview{color:#00f;font-size:31px;line-height:30px;text-decoration:none}
	#ad-design-div-728_90 #link-color-preview{color:#0e8f0e;font-size:15px}
	#ad-design-div-728_90 #text-color-preview{color:#333;font-size:17px;margin-bottom:5px}
	#ad-design-div-728_90 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-728_90 #button-color-preview{background:#3f9f3f;color:#fff;width:125px;height:50px;font-size:50px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:48px;text-align:center;cursor:pointer;position:absolute;right:11px;top:21px}
	#ad-design-div-728_90 a{text-decoration:none}
	#ad-design-div-728_90 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-728_90 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-728_90 #button-report:hover{opacity:.9}
	#ad-design-div-728_90 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '468' && $slotInfo['0']['pas_height'] == '60' ) {
	echo '
	<style>
	#ad-design-div-468_60{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:462px;height:54px}
	#ad-design-div-468_60 #title-color-preview{color:#00f;font-size:21px;line-height:21px;text-decoration:none}
	#ad-design-div-468_60 #link-color-preview{color:#0e8f0e;font-size:12px;line-height:15px}
	#ad-design-div-468_60 #text-color-preview{color:#333;font-size:14px}

	#ad-design-div-468_60 #button-report img{height:9px}
	#ad-design-div-468_60 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-468_60 #button-color-preview{background:#3f9f3f;color:#fff;width:85px;height:35px;font-size:30px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:38px;text-align:center;cursor:pointer;position:absolute;right:11px;top:5px}
	#ad-design-div-468_60 a{text-decoration:none}
	#ad-design-div-468_60 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-468_60 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-468_60 #button-report:hover{opacity:.9}
	#ad-design-div-468_60 .no-underline:hover { text-decoration:none; }
	</style>';
}

if ( $slotInfo['0']['pas_width'] == '160' && $slotInfo['0']['pas_height'] == '60' ) {
	echo '
	<style>
	#ad-design-div-160_60{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:154px;height:54px}
	#ad-design-div-160_60 #title-color-preview{color:#00f;font-size:13px;line-height:13px;text-decoration:none;text-align:center;}
	#ad-design-div-160_60 #link-color-preview{color:#0e8f0e;font-size:11px;line-height:10px}
	#ad-design-div-160_60 #text-color-preview{color:#333;font-size:14px;display:none;}
	#ad-design-div-160_60 #button-color-preview{background:#3f9f3f;color:#fff;width:85px;height:17px;font-size:19px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:18px;text-align:center;cursor:pointer;position:absolute;right:41px;top:40px}
	#ad-design-div-160_60 #button-report img{height:9px}
	#ad-design-div-160_60 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-160_60 a{text-decoration:none}
	#ad-design-div-160_60 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-160_60 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-160_60 #button-report:hover{opacity:.9}
	#ad-design-div-160_60 .no-underline:hover { text-decoration:none; }
	</style>';
}



if ( $slotInfo['0']['pas_width'] == '120' && $slotInfo['0']['pas_height'] == '600' ) {
	echo '
	<style>
	#ad-design-div-120_600{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:114px;height:594px}
	#ad-design-div-120_600 #title-color-preview{color:#00f;font-size:30px;line-height:35px;text-decoration:none;text-align:center;}
	#ad-design-div-120_600 #link-color-preview{color:#0e8f0e;font-size:18px;line-height:20px;text-align:center;margin-top:15px;margin-bottom:15px;}
	#ad-design-div-120_600 #text-color-preview{color:#333;font-size:22px;line-height: 30px;text-align: center;}
	#ad-design-div-120_600 #button-color-preview{background:#3f9f3f;color:#fff;width:110px;height:50px;font-size:50px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:48px;text-align:center;cursor:pointer;position:absolute;right:5px;bottom:19px}
	#ad-design-div-120_600 #button-report img{height:9px}
	#ad-design-div-120_600 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-120_600 a{text-decoration:none}
	#ad-design-div-120_600 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-120_600 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-120_600 #button-report:hover{opacity:.9}
	#ad-design-div-120_600 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '160' && $slotInfo['0']['pas_height'] == '600' ) {
	echo '
	<style>
	#ad-design-div-160_600{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:154px;height:594px}
	#ad-design-div-160_600 #title-color-preview{color:#00f;font-size:37px;line-height:35px;text-decoration:none;text-align:center;margin-top:15px;}
	#ad-design-div-160_600 #link-color-preview{color:#0e8f0e;font-size:18px;line-height:20px;text-align:center;margin-top:15px;margin-bottom:15px;}
	#ad-design-div-160_600 #text-color-preview{color:#333;font-size:26px;line-height: 35px;text-align: center;margin-top: 25px;}
	#ad-design-div-160_600 #button-color-preview{background:#3f9f3f;color:#fff;width:137px;height:50px;font-size:50px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:48px;text-align:center;cursor:pointer;position:absolute;right:12px;bottom:19px}
	#ad-design-div-160_600 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-160_600 a{text-decoration:none}
	#ad-design-div-160_600 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-160_600 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-160_600 #button-report:hover{opacity:.9}
	#ad-design-div-160_600 .no-underline:hover { text-decoration:none; }
	</style>';
}




if ( $slotInfo['0']['pas_width'] == '120' && $slotInfo['0']['pas_height'] == '240' ) {
	echo '
	<style>
	#ad-design-div-120_240{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:114px;height:234px}
	#ad-design-div-120_240 #title-color-preview{color:#00f;font-size:15px;line-height:15px;text-decoration:none;text-align:center;margin-top:5px}
	#ad-design-div-120_240 #link-color-preview{color:#0e8f0e;font-size:13px;line-height:15px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-120_240 #text-color-preview{color:#333;font-size:14px;line-height:17px;text-align:center;margin-top:10px}
	#ad-design-div-120_240 #button-color-preview{background:#3f9f3f;color:#fff;width:96px;height:50px;font-size:50px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:48px;text-align:center;cursor:pointer;position:absolute;right:12px;bottom:19px}
	#ad-design-div-120_240 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-120_240 a{text-decoration:none}
	#ad-design-div-120_240 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-120_240 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-120_240 #button-report:hover{opacity:.9}
	#ad-design-div-120_240 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '336' && $slotInfo['0']['pas_height'] == '280' ) {
	echo '
	<style>
	#ad-design-div-336_280{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:330px;height:274px}
	#ad-design-div-336_280 #title-color-preview{color:#00f;font-size:31px;line-height:29px;text-decoration:none;text-align:center;margin-top:5px}
	#ad-design-div-336_280 #link-color-preview{color:#0e8f0e;font-size:20px;line-height:21px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-336_280 #text-color-preview{color:#333;font-size:24px;line-height:34px;text-align:center;margin-top:10px;margin-bottom:5px;}
	#ad-design-div-336_280 #button-color-preview{background:#3f9f3f;color:#fff;width:186px;height:60px;font-size:60px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:57px;text-align:center;cursor:pointer}
	#ad-design-div-336_280 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-336_280 a{text-decoration:none}
	#ad-design-div-336_280 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-336_280 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-336_280 #button-report:hover{opacity:.9}
	#ad-design-div-336_280 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '300' && $slotInfo['0']['pas_height'] == '250' ) {
	echo '
	<style>
	#ad-design-div-300_250{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:294px;height:244px}
	#ad-design-div-300_250 #title-color-preview{color:#00f;font-size:26px;line-height:23px;text-decoration:none;text-align:center;margin-top:5px}
	#ad-design-div-300_250 #link-color-preview{color:#0e8f0e;font-size:20px;line-height:21px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-300_250 #text-color-preview{color:#333;font-size:20px;line-height:28px;text-align:center;margin-top:10px;margin-bottom:5px;}
	#ad-design-div-300_250 #button-color-preview{background:#3f9f3f;color:#fff;width:186px;height:60px;font-size:60px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:57px;text-align:center;cursor:pointer}
	#ad-design-div-300_250 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-300_250 a{text-decoration:none}
	#ad-design-div-300_250 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-300_250 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-300_250 #button-report:hover{opacity:.9}
	#ad-design-div-300_250 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '250' && $slotInfo['0']['pas_height'] == '250' ) {
	echo '
	<style>
	#ad-design-div-250_250{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:244px;height:244px}
	#ad-design-div-250_250 #title-color-preview{color:#00f;font-size:21px;line-height:22px;text-decoration:none;text-align:center;margin-top:5px}
	#ad-design-div-250_250 #link-color-preview{color:#0e8f0e;font-size:17px;line-height:16px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-250_250 #text-color-preview{color:#333;font-size:17px;line-height:28px;text-align:center;margin-top:10px;margin-bottom:5px;}
	#ad-design-div-250_250 #button-color-preview{background:#3f9f3f;color:#fff;width:186px;height:60px;font-size:60px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:57px;text-align:center;cursor:pointer}
	#ad-design-div-250_250 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-250_250 a{text-decoration:none}
	#ad-design-div-250_250 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-250_250 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-250_250 #button-report:hover{opacity:.9}
	#ad-design-div-250_250 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '200' && $slotInfo['0']['pas_height'] == '200' ) {
	echo '
	<style>
	#ad-design-div-200_200{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:194px;height:194px}
	#ad-design-div-200_200 #title-color-preview{color:#00f;font-size:18px;line-height:19px;text-decoration:none;text-align:center;margin-top:5px}
	#ad-design-div-200_200 #link-color-preview{color:#0e8f0e;font-size:13px;line-height:16px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-200_200 #text-color-preview{color:#333;font-size:14px;line-height:19px;text-align:center;margin-top:10px;margin-bottom:5px;}
	#ad-design-div-200_200 #button-color-preview{background:#3f9f3f;color:#fff;width:186px;height:40px;font-size:50px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:39px;text-align:center;cursor:pointer}
	#ad-design-div-200_200 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-200_200 a{text-decoration:none}
	#ad-design-div-200_200 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-200_200 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-200_200 #button-report:hover{opacity:.9}
	#ad-design-div-200_200 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '180' && $slotInfo['0']['pas_height'] == '150' ) {
	echo '
	<style>
	#ad-design-div-180_150{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:174px;height:144px}
	#ad-design-div-180_150 #title-color-preview{color:#00f;font-size:17px;line-height:18px;text-decoration:none;text-align:center;margin-top:5px}
	#ad-design-div-180_150 #link-color-preview{color:#0e8f0e;font-size:12px;line-height:7px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-180_150 #text-color-preview{color:#333;font-size:13px;line-height:15px;text-align:center;margin-top:10px;margin-bottom:5px;}
	#ad-design-div-180_150 #button-color-preview{background:#3f9f3f;color:#fff;width:126px;height:30px;font-size:40px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:31px;text-align:center;cursor:pointer}
	#ad-design-div-180_150 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-180_150 a{text-decoration:none}
	#ad-design-div-180_150 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-180_150 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-180_150 #button-report:hover{opacity:.9}
	#ad-design-div-180_150 .no-underline:hover { text-decoration:none; }
	</style>';
}


if ( $slotInfo['0']['pas_width'] == '125' && $slotInfo['0']['pas_height'] == '125' ) {
	echo '
	<style>
	#ad-design-div-125_125{background:#fff;border-radius:0;padding:2px;word-break:break-word;font-family:Roboto;font-style:normal;font-weight:300;width:119px;height:119px}
	#ad-design-div-125_125 #title-color-preview{color:#00f;font-size:14px;line-height:15px;text-decoration:none;text-align:center;}
	#ad-design-div-125_125 #link-color-preview{color:#0e8f0e;font-size:12px;line-height:20px;text-align:center;margin-top:5px;margin-bottom:5px}
	#ad-design-div-125_125 #text-color-preview{color:#333;font-size:13px;line-height:15px;text-align:center;margin-top:10px;margin-bottom:5px;display:none;}
	#ad-design-div-125_125 #button-color-preview{background:#3f9f3f;color:#fff;width:96px;height:27px;font-size:30px;font-weight:bold;border-radius:5px;float:none;margin:auto;line-height:27px;text-align:center;cursor:pointer}
	#ad-design-div-125_125 #button-color-preview:hover{opacity:.8}
	.row{margin-left:-15px;margin-right:-15px}
	#ad-design-div-125_125 a{text-decoration:none}
	#ad-design-div-125_125 a:hover{text-decoration:underline;opacity:.8}
	#ad-design-div-125_125 #button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#ad-design-div-125_125 #button-report:hover{opacity:.9}
	#ad-design-div-125_125 .no-underline:hover { text-decoration:none; }
	</style>';
}


echo '
<div id="ad-design-div-' . $slotInfo['0']['pas_width'] . '_' . $slotInfo['0']['pas_height'] . '" style="border: 1px solid rgb(199, 199, 199); background: rgb(250, 250, 250);">
	<a target="_top" href="' . HTTP_SERVER_WEBSITE . 'pagead/redirect?c=' . $FULL_URL . '">
		<div id="title-color-preview" style="color: rgb(255, 0, 0);">' . $ad['0']['aau_title'] . '</div>
	</a>
	<a target="_top" href="' . HTTP_SERVER_WEBSITE . 'pagead/redirect?c=' . $FULL_URL . '">
		<div id="link-color-preview" style="color: rgb(28, 71, 28);">' . $ad['0']['aau_url'] . '</div>
	</a>
	<div id="text-color-preview" style="color: rgb(41, 48, 148);">' . $ad['0']['aau_summary'] . ' ' . $ad['0']['aau_summary_2'] . '</div>
	<a class="no-underline" target="_top" href="' . HTTP_SERVER_WEBSITE . 'pagead/redirect?c=' . $FULL_URL . '">
		<div id="button-color-preview" style="color: rgb(250, 250, 250); background: rgb(28, 71, 28);">&gt;</div>
	</a>
	<a id="button-report" target="_new" href="'. HTTP_REPORT_URL .'?r='.$FULL_URL.'"><img src="'. HTTP_SERVER_WEBSITE . 'templates/' . WEBSITE_TEMPLATE . '/assets/images/report.png"/></a>
</div>
';


}

if ( $slotInfo['0']['pau_size_type'] == 3 ) { //*** IF WE NEED TO HAVE ONLY BANNER ADS ***//

	$width	=	$slotInfo['0']['pas_width'];
	$height	=	$slotInfo['0']['pas_height'];

	$ad	=	$db->Query("SELECT `aau_user_id`, `aau_id`, `aau_campaign`, `aau_target_url`, `aau_file`, `aau_user_id`, `aauk_keyword`, `aauk_price` FROM advertisers_ad_units left join advertisers_campaigns on advertisers_campaigns.adv_campaign_id = advertisers_ad_units.aau_campaign left join advertisers_sizes on advertisers_sizes.adv_sizes_id = advertisers_ad_units.aau_size left join advertisers_ad_units_keywords on advertisers_ad_units_keywords.aauk_ad_id = advertisers_ad_units.aau_id left join advertisers_profiles on advertisers_profiles.adv_profile_user_id = advertisers_ad_units.aau_user_id where aau_status=? and adv_campaign_status=? and adv_campaign_daily_budget>adv_campaign_daily_spent and adv_profile_deposits > aauk_price and ( adv_sizes_width =? and adv_sizes_height=? ) and ( " . $keywordsSQL . " ) and ( " . $countrySQL . " ) ".$idsSQL."  order by COALESCE(aauk_price, 0) DESC ".$limitSQL,"iiii",1,1,$width,$height);

//*** GENERATE REDIRECT URL ***//
$URL_USER			=	$ad['0']['aau_user_id']; 	//*** ADVERTISER USER ID ***//
$URL_AD_ID			=	$ad['0']['aau_id'];			//*** AD ID ***//
$URL_KEYWORD		=	$ad['0']['aauk_keyword'];	//*** KEYWORD ***//
$URL_KEYWORD_PRICE	=	$ad['0']['aauk_price'];		//*** KEYWORD PRICE ***//
$URL_TARGET			=	$ad['0']['aau_target_url'];	//*** TARGET URL ***//
$HTTP_DOMAIN		=	$prepare->addhttp ( $domain );
$HTTP_REFERER		=	$prepare->addhttp ( $refer );
$URL_DOMAIN			=	$prepare->get_domain( $HTTP_DOMAIN );//*** DOMAIN WHERE THE AD WAS CLICKED ***//
$URL_REFERER		=	$prepare->get_domain( $HTTP_REFERER );//*** DOMAIN WHERE THE AD WAS CLICKED ***//
$URL_CAMPAIGN		=	$ad['0']['aau_campaign'];

$URL	=	'user=' . $URL_USER . '&ad_id=' . $URL_AD_ID . '&keyword=' . $URL_KEYWORD . '&keyword_price=' . $URL_KEYWORD_PRICE . '&url_target=' . $URL_TARGET . '&slot=' . $slot . '&channel_id=' . $slotInfo['0']['pau_channel_id'] . '&client=' . $client . '&referer=' . $URL_REFERER . '&domain=' . $URL_DOMAIN . '&campaign=' . $URL_CAMPAIGN;


$FULL_URL	=	base64_encode( $URL );
//*** END GENERATE REDIRECT URL ***//

	echo '
	<style>
	#button-report{position:absolute;bottom:1px;right:1px;opacity:.5}
	#button-report:hover{opacity:.9}
	</style>
	';


	echo '<a target="_top" href="' . HTTP_SERVER_WEBSITE . 'pagead/redirect?c=' . $FULL_URL . '"><img src="'.HTTP_SERVER_WEBSITE_UPLOADS_BANNER_ADS.$ad['0']['aau_file'].'"/></a>
	<a id="button-report" target="_new" href="'. HTTP_REPORT_URL .'?r='.$FULL_URL.'"><img src="'. HTTP_SERVER_WEBSITE . 'templates/' . WEBSITE_TEMPLATE . '/assets/images/report.png"/></a>';


}



//**** START TRACKING IMPRESSIONS / VIEWS ****//
if ( !empty ( $ad ) ) {

	//*** advertisers_ad_units_statistics ***//
	$db->NoQuery("update advertisers_ad_units_statistics set aaus_impressions=aaus_impressions+1 where aaus_ad_id=?","i",$ad['0']['aau_id']);

	//*** advertisers_campaigns_statistics ***//
	$db->NoQuery("update advertisers_campaigns_statistics set acs_impressions=acs_impressions+1 where acs_campaign_id=?","i",$ad['0']['aau_campaign']);

	$aav_ad_id		=	$ad['0']['aau_id'];
	$aav_word		=	$ad['0']['aauk_keyword'];
	$aav_value		=	$ad['0']['aauk_price'];
	$HTTP_DOMAIN	=	$prepare->addhttp ( $domain );
	$aav_domain		=	$prepare->get_domain( $HTTP_DOMAIN );



	if ( !empty ( $ip['ADDRESS'] ) ) {
		$aav_ip			=	$ip['ADDRESS'];
	} else {
		$aav_ip			=	"unknown";
	}

	if ( !empty ( $ip['COUNTRY_NAME'] ) ) {
		$aav_country	=	$ip['COUNTRY_NAME'];
	} else {
		$aav_country	=	"unknown";
	}

	if ( !empty ( $ip['REGION_NAME'] ) ) {
		$aav_county	=	$ip['REGION_NAME'];
	} else {
		$aav_county	=	"unknown";
	}

	if ( !empty ( $ip['CITY_NAME'] ) ) {
		$aav_city	=	$ip['CITY_NAME'];
	} else {
		$aav_city	=	"unknown";
	}

	$aav_date		=	strtotime("now");
	
	$db->NoQuery("INSERT INTO advertisers_ad_views VALUES(NULL,?,?,?,?,?,?,?,?,?)","sssssssss",$aav_ad_id,$aav_word,$aav_value,$aav_domain,$aav_ip,$aav_country,$aav_county,$aav_city,$aav_date);

	if ( !empty ( $slotInfo ) ) {
		//*** publishers_ad_units_statistics ***//
		$db->NoQuery("update publishers_ad_units_statistics set paus_impressions=paus_impressions+1 where paus_ad_id=?","i",$slot);

	$pav_ad_id		=	$slot;
	$pav_word		=	$ad['0']['aauk_keyword'];
	$pav_value		=	$ad['0']['aauk_price'];
	$HTTP_DOMAIN	=	$prepare->addhttp ( $domain );
	$pav_domain		=	$prepare->get_domain( $HTTP_DOMAIN );



	if ( !empty ( $ip['ADDRESS'] ) ) {
		$pav_ip			=	$ip['ADDRESS'];
	} else {
		$pav_ip			=	"unknown";
	}

	if ( !empty ( $ip['COUNTRY_NAME'] ) ) {
		$pav_country	=	$ip['COUNTRY_NAME'];
	} else {
		$pav_country	=	"unknown";
	}

	if ( !empty ( $ip['REGION_NAME'] ) ) {
		$pav_county	=	$ip['REGION_NAME'];
	} else {
		$pav_county	=	"unknown";
	}

	if ( !empty ( $ip['CITY_NAME'] ) ) {
		$pav_city	=	$ip['CITY_NAME'];
	} else {
		$pav_city	=	"unknown";
	}

	$pav_date		=	strtotime("now");
	
	$db->NoQuery("INSERT INTO publisher_ad_views VALUES(NULL,?,?,?,?,?,?,?,?,?)","sssssssss",$pav_ad_id,$pav_word,$pav_value,$pav_domain,$pav_ip,$pav_country,$pav_county,$pav_city,$pav_date);




		//*** publisher_channels_statistics ***//
		$db->NoQuery("update publisher_channels_statistics set pcs_impressions=pcs_impressions+1 where pcs_channel_id=?","i",$slotInfo['0']['pau_channel_id']);

	}

}
//**** END TRACKING / VIEWS ****//





?>