<?php
// CONNECT TO DB
include('include/config.php');
include('lang/global.php');
// BASIC FUNCTIONS
include("include/functions.php");
// GET IP
$uip = getIP();
function getCurlData($url)
{
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, $url);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_TIMEOUT, 10);
		curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16");
		$curlData = curl_exec($curl);
		curl_close($curl);
		return $curlData;
}
?>
<link rel="icon" type="image/png" href="<?php echo"$mainurl";?>uploads/images/<?php echo $logoimageresultF; ?>">
<link href="include/fontawesome/css/font-awesome.css" rel="stylesheet" type="text/css" />
<style>
#id64 {
	position:fixed !important;
	position:absolute;
	top:0px;
	top:expression((t=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop)+"px");
	left:-2px;
	width:103%;
	height:102%;
	background-color:#fff;
	opacity:.95;filter:alpha(opacity=95);
	display:block;
	padding:20% 0
}
#id64 *{
	text-align:center;
	margin:0 auto;
	display:block;
	filter:none;
	font:bold 14px Verdana,Arial,sans-serif;
	text-decoration:none
}
#id64 ~ *{
	display:none
}
</style>
<div id="id64"><div>Please enable / Bitte aktiviere JavaScript!<br>Veuillez activer / Por favor activa el Javascript!</div></div>
<script>
	window.document.getElementById("id64").parentNode.removeChild(window.document.getElementById("id64"));
	(function(l,m){
		function n(a){
			a&&id64.nextFunction()
		}
		var h=l.document,p=["i","s","u"];
		n.prototype={
			rand:function(a){
				return Math.floor(Math.random()*a)
			},
			getElementBy:function(a,b){
				return a?h.getElementById(a):h.getElementsByTagName(b)
			},
			getStyle:function(a){
				var b=h.defaultView;
				return b&&b.getComputedStyle?b.getComputedStyle(a,null):a.currentStyle
			},
			deferExecution:function(a){
				setTimeout(a,250)
			},
			insert:function(a,b){
				var e=h.createElement("div"),
					d=h.body,
					c=d.childNodes.length,
					g=d.style,
					f=0,
					k=0;
				if("id64"==b){
					e.setAttribute("id",b);
					g.margin=g.padding=0;
					g.height="100%";
					for(c=this.rand(c);
					f<c;
					f++)1==d.childNodes[f].nodeType&&(k=Math.max(k,parseFloat(this.getStyle(d.childNodes[f]).zIndex)||0));
					k&&(e.style.zIndex=k+1);c++
				}
				e.innerHTML=a;
				d.insertBefore(e,d.childNodes[c-1])
			},
			displayMessage:function(a){
				var b=this;
				a="abisuq".charAt(b.rand(5));
				b.insert("<"+a+'><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbAAAABCBAMAAADETZ6/AAAAG1BMVEX8/PzIyMgAAADIyMgAAADIyMgAAADIyMgAAAA1KCrAAAAI/ElEQVRoge1Wy3biyg4tSHgMcb4A/AWs5XwAa+EPYOKMmcDYM2fILP7ss7ceVbYxJOmb7tP3XioctyxpS9olVfmE8FiP9XesPM/XYZrf8Ziu+eu+ErYe9R2Hj6PyEbcfXHmWIUO+uu0x3fDXfY3Pr6yufw/Vz/n1gF9cCK+/u5Vlwwr+m4jl6NwUj6kO59oS5kjJl5x2mKYbvrEO99FZJZJCHqEaxyn1UDTlKwlISP47iOX5RohNNy9Ilr2sZTjzzI4AhI1OI0x4oO6J1eE+YiVchaTWOEqsh1LTy2alSfn4eWJZlmnfMhznCVJBnjDnWqtbTTd+zDL85WoSTfRhQ2AyhquJDpk5bzxOQsF5ssoJYdKccX/HKOoTrcNwoH8cxSmFWLTutE4panVlz4cRXpSYRU7O3TjuzICedBV+zxkzYmjdC+ZtEzCKmJUs6xOb2JQmYj2fa2LJ+QYxGf0s+93EeP55T2zk9s/9w4JJ0WrWUtA0f5HZkR52faY4YSsRIjE4i0aIdVB5xlyeJLcSsvCzS7dLbypUlvP0Q5jyBGhFouGth4LyNZogt41eockn8EWc0yiuyS3eihElAnKt5C7dWMfWP0xMDzpnaoLHJFvhJPMNI6IOrplQk2WTVTYR51X0mQYOsGro7KHpLBp56aAsF4wuhJ/v2E+s3Fv3v7Ymsb2P9ViP9X+zyrLk85Z1TCxHrMOAXM+7ETOUHX0/1HPZd7xRyddWWbwiQrlV6LAW6rti2VN2rMOAUtp+xAxlRz8I1Q04QI/murcAQLVPW4UOa7kixseTK59GiW3j7hYj5j9I7Hm/5QxwhJ7LckfJbTtYVbODY6ljJs78yeQQtSvLhCIxQ3HqLKAKkZijylcJuFNBB0c0sO85tTRpsG8TK8tCYE9lsQ2v+wIRX72GV7ApmKNgDfut+Gjp9hPnEo+IEj1RwqF8KsVHBA1aomRHlTsKjL6zE6GmggFRmGSXYN8nls6YjSLjmUnYYOMK1moboOmRV7nRGY8iobaOkuZAoEkEI/a676GiT/CAjF08l3sZJmZ62v7qGesRw/KJx4SU5f6ZmtJ9dF/Fc6vOOkFDlE0dmGC9+tFSYhHlzt0poDPHkQ1n9r2F/T6x7aBjRZFK3OMNGtThnbWTUNgGw1kUV6hEDC+JmNCIqJjimthezkBR/DIxGyq5HXhiMTJ2HHAytnLKtxS2pfoYsa3NJIdqG0JEScAy+CjqJVA+J2JFuY+ocmfOpc/2s2sUJwJxozfwXWLce7vtGFre9hpFb8US474jMbmlkFWcxVcuw/1W+2goCagoVqt34L4zilvVaMdezdmEnc6CwPdy8ZbesW/yCk+cIHkETA8keXMb9ommAgJF8THnBNXddJTHIqoQiJgK/6xFDVFPW3N2QStQePDsv9Sxx3qsx3qsP7Hmx3+7gs+WV3iWX1yUzzDNz+OQczUWbMT57hL/sRTjSW/DozW5sUJhceAvYSDPTyYMc5zwG6rPYdz5yqenOHwBFZNex4vwaKUg5KTC8+GK2Ow+sXDVMPGbfULsajd+iliqp3LXykzzIzjOMX0yk9pfJ3am7mz7PT9DHzVnIOYQ5GV+Dg5HHD4kcdTAZ35UlFX2du6kQORjcoagzr2kgpozDkMl+DFIGUHLOVoKbSah1dla1x3F+entGGaVbSx8TtTMT5U8gIAwO1ex7ecD48z5sB1VjficBfpmnI8UPAUjR2cVoqMljSg5DhEupbIMEd5OlQaMxNiz4zUxHMNz8GNFnxM1OpAQ3mCodCBYIstmHDjqZEaN7i0wGlDqlc5oCo18kIBWBp17SSNKiTncj32lZ+zUiczeVWii7VmfGNbB70GNSI1MFh5vpzjpsvf4Y5zOeZZp4ED4eZaAIXU4KJ9gxGIZfvpSUkdF50Mi5kdRiGnNSgy7UlXVWMeq6uD3oG0VNDO0HsKAmGwQ46TTLpoeMcLvEItl9Il1UZ8SE2fBs3IeSvwNzxiPcvxwQTxRw+OL0HCWo8x/jJjF6RA7aAD66EXlQ3WUrDrAB41sAVU4DJImFDURrlzkRhFihNN5dnCuZ6Y/6pjZTSU3zOkwvBVFg+E9khtQc/dhrrk2Kc7iQczqo9Oh/cfUVZ6issgeUMpwYjFpB4VtdfjcLufKb8RKnbVktoT9m1UzjJkIB2pAHI+ZzQE0hyppKjgLKkQfj5M+darRh2zirFLj7JBSUMCAzTyglBG/cJ5UR1GcD1WCV/o4qDATePXpd/XPrbGv8PX60gf9L1uj/wc6XH9NHx7rsR4Lq23by0C1vNIMHW7a23HtpWNdjvvcinw713jS6N82zTBTe6UZJvu4Fb6t7/mrddznVuTRXIPM3YDRH9phpra+l/tWMsEs/g1ii9vEOHxtnMC2XkDTsgdt6JsE2gLctjLFfFyCOPNlKRBDmfOlQ+y9NWLqvLwkZ42jkaFvB7kU315gukgKEQwVQqonEWvbj5rDt4wTKJmb94tw7pvE3LQfy4/3y/KjkUcrzou2qb3/inLnDrHL+0V8CJc4KYXG0cih5aOby5rRYIsXraR4pyAoDyj1dIg1TbP8qJfQ19pTIY6efVD33jNpeJjaJnAvQ4O/Fj78p9Y9iSh3TsmIUvICZ5xa4PDROBqZ9qaXS/Hmc4komBZ1CkiP7ijyBTRcI3vPRi7lr2uyIUYyrJo7gClEDg+km4c/wnWUKHTOWPq9SxzZe+bSOEvrYT3M5cESyoRO2MEoXhHT6pp3Dndzixj6XC84rrhU+8QUBbtNT9N8Row+FmeUGHPZcN0ltuiPotQThEKXGOY8cKeiKd0tMC15o1wk9BJ18OvBf4wYUfY9ESGdMcyWj2utcQxucUTzkW5lz2V1LZUPUSbYbMv8a6KmS2zZcpg7xFCd7FadTLhBbBv1pvpg6xvQZT7YlqoJhjJvEfxaw9Q1fgc2FsfgFkciN+mLEHPpy0X5hCR4Uk3DqLb99hHg4DhVUS2a2lRuahvPRtOikf9wazQLPmpxXKggKPOmsLCXRW1+quG0LxyucSRy3fkyeS6LtdCqFkmwpIKK2b+1xr+9/9H6wsf3l9c/Kz1S/0QTusYAAAAASUVORK5CYII=" height="66" width="432" alt="" />'+("</"+a+">"),"id64");
				h.addEventListener&&b.deferExecution(function(){
					b.getElementBy("id64").addEventListener("DOMNodeRemoved",function(){
						b.displayMessage()
					},!1)
				})
			},
			i:function(){
				for(var a="ad300top,adRight1,ad_sitebar,adv_config,quigo,topad_right,turnAD,ad,ads,adsense".split(","),b=a.length,e="",d=this,c=0,g="abisuq".charAt(d.rand(5));c<b;c++)d.getElementBy(a[c])||(e+="<"+g+' id="'+a[c]+'"></'+g+">");
				d.insert(e);d.deferExecution(function(){
					for(c=0;c<b;c++)
					if(null==d.getElementBy(a[c]).offsetParent||"none"==d.getStyle(d.getElementBy(a[c])).display)
					return d.displayMessage("#"+a[c]+"("+c+")");d.nextFunction()
				})
			},
			s:function(){
				var a={'pagead2.googlesyndic':'google_ad_client','js.adscale.de/getads':'adscale_slot_id','get.mirando.de/miran':'adPlaceId'},b=this,e=b.getElementBy(0,"script"),d=e.length-1,c,g,f,k;h.write=null;
				for(h.writeln=null;0<=d;--d)
				if(c=e[d].src.substr(7,20),a[c]!==m){
					f=h.createElement("script");f.type="text/javascript";
					f.src=e[d].src;g=a[c];
					l[g]=m;
					f.onload=f.onreadystatechange=function(){
						k=this;
						l[g]!==m||k.readyState&&"loaded"!==k.readyState&&"complete"!==k.readyState||(l[g]=f.onload=f.onreadystatechange=null,e[0].parentNode.removeChild(f))
					};
					e[0].parentNode.insertBefore(f,e[0]);b.deferExecution(function(){
						if(l[g]===m)
						return b.displayMessage(f.src);
						b.nextFunction()
					});
					return
				}
				b.nextFunction()
			},
			u:function(){
				var a=".ie/ads/,.net/adj;,/adblock26.,/adbutler/ad,/adinjector.,/adiquity.,/adnet.,/ads/preroll_,/adtextmpu2.,/searchads/ad".split(","),b=this,e=b.getElementBy(0,"img"),d,c;
				e[0]!==m&&e[0].src!==m&&(d=new Image,d.onload=function(){
					c=this;
					c.onload=null;
					c.onerror=function(){
						p=null;b.displayMessage(c.src)
					};
					c.src=e[0].src+"#"+a.join("")
				},
				d.src=e[0].src);
				b.deferExecution(function(){
					b.nextFunction()
				})
			},
			nextFunction:function(){
				var a=p[0];
				a!==m&&(p.shift(),this[a]())
			}
		};
		l.id64=id64=new n;
		h.addEventListener?l.addEventListener("load",n,!1):l.attachEvent("onload",n)
	})
	(window);
</script>

<?php
//CHECK IF CAPTCHA ENABLED
$RCactive3 = "SELECT `rcactive` FROM `settings`";
$RCactive2 = mysql_query($RCactive3) or die($RCactive3."<br/><br/>".mysql_error());
$RCactive = mysql_result($RCactive2, 0);
if ($RCactive == 1){
	//CHECK CAPTCHA SITE KEY
	$RCsite3 = "SELECT `rcsitekey` FROM `settings`";
	$RCsite2 = mysql_query($RCsite3) or die($RCsite3."<br/><br/>".mysql_error());
	$RCsite = mysql_result($RCsite2, 0);
	//CHECK CAPTCHA SECRET KEY
	$RCsecret3 = "SELECT `rcsecretkey` FROM `settings`";
	$RCsecret2 = mysql_query($RCsecret3) or die($RCsecret3."<br/><br/>".mysql_error());
	$RCsecret = mysql_result($RCsecret2, 0);
	$lang = 'en';
}

//CHECK IF CAPTCHA ENABLED
$checkcaptchastatus1 = "SELECT `smactive` FROM `settings`";
$checkcaptchastatus2 = mysql_query($checkcaptchastatus1) or die($checkcaptchastatus1."<br/><br/>".mysql_error());
$checkcaptchastatus = mysql_result($checkcaptchastatus2, 0);
if ($checkcaptchastatus == 1){
	//CHECK CAPTCHA C-KEY
	$captchac1 = "SELECT `smckey` FROM `settings`";
	$captchac2 = mysql_query($captchac1) or die($captchac1."<br/><br/>".mysql_error());
	$captchac = mysql_result($captchac2, 0);
	//CHECK CAPTCHA V-KEY
	$captchav1 = "SELECT `smvkey` FROM `settings`";
	$captchav2 = mysql_query($captchav1) or die($captchav1."<br/><br/>".mysql_error());
	$captchav = mysql_result($captchav2, 0);
	//CHECK CAPTCHA H-KEY
	$captchah1 = "SELECT `smhkey` FROM `settings`";
	$captchah2 = mysql_query($captchah1) or die($captchah1."<br/><br/>".mysql_error());
	$captchah = mysql_result($captchah2, 0);
	
}

if ($checkcaptchastatus == 1 && $RCactive == 1){
	$luck = rand(0,1);
	if ($luck == 1){
		$RCactive = 1;
		$checkcaptchastatus = 0;
	}else{
		$RCactive = 0;
		$checkcaptchastatus = 1;
	}
}

$code = checkerr($_GET['code']);
$code = mysql_real_escape_string($code);

// SEARCH CODE
$query = mysql_query("SELECT * FROM items WHERE code='$code'");
$numrows = mysql_num_rows($query);
$qqf = mysql_fetch_array($query);
// ADTYPE
$adctype = $qqf['advtype'];
// GET URL TO NEED REDIRECT
$urlto = $qqf['url'];
$itemuser = $qqf['username'];
// USER IP
$ip = $_SERVER['REMOTE_ADDR'];
$ip_number = sprintf("%u", ip2long($ip));

$country_query  = "SELECT `country_name` FROM `ip2country` WHERE `begin_ip_num`<=$ip_number AND `end_ip_num`>=$ip_number";
$country_exec = mysql_query($country_query);
$ccode_array = @mysql_fetch_array($country_exec);
$country_name = $ccode_array['country_name'];

// IF COULN'T FOUND USER COUNTRY SET ALL
if($country_name == '') {

$country_name = 'all';

} 

$getvalues = mysql_query("SELECT * FROM countrylist WHERE country='$country_name'");
$fgvalues = mysql_fetch_array($getvalues);
$getvaluesall = mysql_query("SELECT * FROM countrylist WHERE country='all'");
$allworldvalues = mysql_fetch_array($getvaluesall);
?>

<?php
// FOR INTERSTITIAL ADS
if($adctype == 'interstitial') {
// FIND RADOM AD && CREDITS MUST BE MORE THAN 1 && CUSTOM COUNTRY
$checkforads = mysql_query("SELECT * FROM ads WHERE adtype='interstitial' AND countries='$country_name' AND credits > 1 AND active = '1' AND approved = '1' ORDER BY RAND()");
$numcrows = mysql_num_rows($checkforads); 

      if($numcrows != 0) {
        $fetchurl = mysql_fetch_array($checkforads);

        $url = $fetchurl['url'];
        $adid = $fetchurl['id'];
		$advprice = $fgvalues['ppvadv'];
		$pubprice = $fgvalues['ppv'];
		$revenue = $advprice - $pubprice;
		$selectrevenue = mysql_query("SELECT * FROM revenue WHERE id=1");
		$revenuerows = mysql_num_rows($selectrevenue);
		if ($revenuerows == 0) {
			mysql_query("INSERT INTO revenue (revenue) VALUES('$revenue')");
		}
		else if ($revenuerows != 0) {
			$oldrevenue = $selectrevenue['revenue'];
			$newrevenue = $oldrevenue + $revenue;
			mysql_query("UPDATE revenue SET revenue=$newrevenue WHERE id=1");
		}
		
		
           $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
             }
       }
      else
       {
// FIND RADOM AD && CREDITS MUST BE MORE THAN 1 && ALL COUNTRIES
$checkforads2 = mysql_query("SELECT * FROM ads WHERE adtype='interstitial' AND countries='all' AND credits > 1 AND active = '1' AND approved = '1' ORDER BY RAND()");
       $fetchurl = mysql_fetch_array($checkforads2);

        $url = $fetchurl['url'];
        $adid = $fetchurl['id'];
		$advprice = $allworldvalues['ppvadv'];
		$pubprice = $allworldvalues['ppv'];
		$revenue = $advprice - $pubprice;
		$selectrevenue = mysql_query("SELECT * FROM revenue WHERE id=1");
		$revenuerows = mysql_num_rows($selectrevenue);
		if ($revenuerows == 0) {
			mysql_query("INSERT INTO revenue (revenue) VALUES('$revenue')");
		}
		else if ($revenuerows != 0) {
			$oldrevenue = $selectrevenue['revenue'];
			$newrevenue = $oldrevenue + $revenue;
			mysql_query("UPDATE revenue SET revenue=$newrevenue WHERE id=1");
		}
		
          $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
              }

       }

}elseif($adctype == 'banner') {// FOR BANNER ADS
	if ($checkcaptchastatus == 0){
		if($adctype == 'banner') {

// FIND RADOM AD && CREDITS MUST BE MORE THAN 1 && CUSTOM COUNTRY
$checkforads = mysql_query("SELECT * FROM ads WHERE adtype='banner' AND countries='$country_name' AND credits > 1 AND active = '1' AND approved = '1' ORDER BY RAND()");
$numcrows = mysql_num_rows($checkforads); 

      if($numcrows != 0) {
        $fetchurl = mysql_fetch_array($checkforads);

        $url = $fetchurl['url'];
        $imageurl = $fetchurl['imageurl'];
        $adid = $fetchurl['id'];
		$advprice = $fgvalues['ppvbadv'];
		$pubprice = $fgvalues['ppvb'];
		$revenue = $advprice - $pubprice;
		$selectrevenue = mysql_query("SELECT * FROM revenue WHERE id=1");
		$revenuerows = mysql_num_rows($selectrevenue);
		if ($revenuerows == 0) {
			mysql_query("INSERT INTO revenue (revenue) VALUES('$revenue')");
		}
		else if ($revenuerows != 0) {
			$oldrevenue = $selectrevenue['revenue'];
			$newrevenue = $oldrevenue + $revenue;
			mysql_query("UPDATE revenue SET revenue=$newrevenue WHERE id=1");
		}


         $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits-1 WHERE id=$advid");

             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");
			 
			 $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
               $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");
			  }
       }
	   // FIND RADOM AD && CREDITS MUST BE MORE THAN 1 && ALL COUNTRIES
      else
       {

$checkforads2 = mysql_query("SELECT * FROM ads WHERE adtype='banner' AND countries='all' AND credits > 1 AND active = '1' AND approved = '1' ORDER BY RAND()");
       $fetchurl = mysql_fetch_array($checkforads2);

        $url = $fetchurl['url'];
        $imageurl = $fetchurl['imageurl'];
        $adid = $fetchurl['id']; 
		$advprice = $allworldvalues['ppvbadv'];
		$pubprice = $allworldvalues['ppvb'];
		$revenue = $advprice - $pubprice;
		$selectrevenue = mysql_query("SELECT * FROM revenue WHERE id=1");
		$revenuerows = mysql_num_rows($selectrevenue);
		if ($revenuerows == 0) {
			mysql_query("INSERT INTO revenue (revenue) VALUES('$revenue')");
		}
		else if ($revenuerows != 0) {
			$oldrevenue = $selectrevenue['revenue'];
			$newrevenue = $oldrevenue + $revenue;
			mysql_query("UPDATE revenue SET revenue=$newrevenue WHERE id=1");
		}

  $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits-1 WHERE id=$advid");

             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");

            $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }

               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
                $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");

              }






       }
}
	}
}elseif($adctype == 'video') {
	
// FIND RADOM AD && CREDITS MUST BE MORE THAN 1 && CUSTOM COUNTRY
$checkforads = mysql_query("SELECT * FROM ads WHERE adtype='video' AND countries='$country_name' AND credits > 1 AND active = '1' AND approved = '1' ORDER BY RAND() LIMIT 1");
$numcrows = mysql_num_rows($checkforads); 

      if($numcrows != 0) {
        $fetchurl = mysql_fetch_array($checkforads);

        $clicktourl = $fetchurl['url'];
        $videourl = $fetchurl['imageurl'];
        $adid = $fetchurl['id'];
		$vidtype = "mp4";
		$vidurl = $videourl;
		$clickto = $clicktourl;
		$advprice = $fgvalues['cpvvideo'];
		$pubprice = $fgvalues['ppvvideo'];
		$revenue = $advprice - $pubprice;
		$selectrevenue = mysql_query("SELECT * FROM revenue WHERE id=1");
		$revenuerows = mysql_num_rows($selectrevenue);
		if ($revenuerows == 0) {
			mysql_query("INSERT INTO revenue (revenue) VALUES('$revenue')");
		}
		else if ($revenuerows != 0) {
			$oldrevenue = $selectrevenue['revenue'];
			$newrevenue = $oldrevenue + $revenue;
			mysql_query("UPDATE revenue SET revenue=$newrevenue WHERE id=1");
		}
		
		
           $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
              }
       }
      else
       {
// FIND RADOM AD && CREDITS MUST BE MORE THAN 1 && ALL COUNTRIES
$checkforads2 = mysql_query("SELECT * FROM ads WHERE adtype='video' AND countries='all' AND credits > 1 AND active = '1' AND approved = '1' ORDER BY RAND() LIMIT 5");
       $fetchurl = mysql_fetch_array($checkforads2);

        $clicktourl = $fetchurl['url'];
        $videourl = $fetchurl['imageurl'];
        $adid = $fetchurl['id'];
		$vidtype = "mp4";
		$vidurl = $videourl;
		$clickto = $clicktourl;
		$advprice = $allworldvalues['cpvvideo'];
		$pubprice = $allworldvalues['ppvvideo'];
		$revenue = $advprice - $pubprice;
		$selectrevenue = mysql_query("SELECT * FROM revenue WHERE id=1");
		$revenuerows = mysql_num_rows($selectrevenue);
		if ($revenuerows == 0) {
			mysql_query("INSERT INTO revenue (revenue) VALUES('$revenue')");
		}
		else if ($revenuerows != 0) {
			$oldrevenue = $selectrevenue['revenue'];
			$newrevenue = $oldrevenue + $revenue;
			mysql_query("UPDATE revenue SET revenue=$newrevenue WHERE id=1");
		}
		
          $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
              }

       }

}elseif($adctype == 'none') {// FOR LINK WITHOUT AD

// SIMPLY REDIRECT
if (false === strpos($urlto, '://')) {
    $urlto = 'http://' . $urlto;
}

  echo"<script type='text/javascript'>window.location.replace('$urlto'); </script>";
}else {
	echo"<script type='text/javascript'>window.location.replace('$mainurl'); </script>";
}
?>


<html>
<head>
<title><?php echo"$title"?></title>
<script type="text/javascript">
// 5 SECOND COUNTER
var timer = 6;

function countdown() {
  timer--;
  var countdownArea = document.getElementById("area");
  countdownArea.innerHTML = timer;
  // WAIT PLEASE LOADING
  if (timer == 6) {
    // time to show the button!
    countdownArea.innerHTML = "<input align='right' class='skipp' value='<?php echo $a263; ?> ...' name='submit' type='submit'>";
  }
   // 5TH SECOND
  if (timer == 5) {
    // time to show the button!
    countdownArea.innerHTML = "<input align='right' class='skipp' value='<?php echo $a263; ?> 5s' name='submit' type='submit'>";
  }
   // 4TH SECOND
  if (timer == 4) {
    // time to show the button!
    countdownArea.innerHTML = "<input align='right' class='skipp' value='<?php echo $a263; ?> 4s' name='submit' type='submit'>";
  }
   // 3TH SECOND
  if (timer == 3) {
    // time to show the button!
    countdownArea.innerHTML = "<input align='right' class='skipp' value='<?php echo $a263; ?> 3s' name='submit' type='submit'>";
  }
   // 2TH SECOND
  if (timer == 2) {
    // time to show the button!
    countdownArea.innerHTML = "<input align='right' class='skipp' value='<?php echo $a263; ?> 2s' name='submit' type='submit'>";
  }
   // 1TH SECOND
  if (timer == 1) {
    // time to show the button!
    countdownArea.innerHTML = "<input align='right' class='skipp' value='<?php echo $a263; ?> 1s' name='submit' type='submit'>";
  }
 // NOW IT WILL BE BUTTON WITH REDIRECT
  if (timer == 0) {
    // time to show the button!
    countdownArea.innerHTML = "<form method='POST'><input align='right' class='skipp' value='<?php echo $a094; ?>' name='image' type='submit'></form>";
  } else {
    // calling this function again in 1000 microseconds (1 second)
    setTimeout('countdown()', 1000);
  }
}
</script>
<style type="text/css">
.class1 A:link {text-decoration: none}
.class1 A:visited {text-decoration: none}
.class1 A:active {text-decoration: none}
.class1 A:hover {text-decoration: none}

.class2 A:link {text-decoration: none}
.class2 A:visited {text-decoration: none}
.class2 A:active {text-decoration: none}
.class2 A:hover {text-decoration: none}
  
.skipp{
font-size: 23px;
font-weight: 600;
max-width: 350px;
min-width: 190px;
height: 46px;
margin-left: 5px;
border: 1px solid #007EC3;
cursor: pointer;
border-radius: 6px;
background-color: #D9F2FF;
background-image: -moz-linear-gradient(center top , #D9F2FF, #C6EAFE);
box-shadow: 0px 1px 1px #FFF inset;
color: #1CAFFF;
}

.skipp:hover{
	font-size: 23px;
font-weight: 600;
max-width: 350px;
min-width: 190px;
height: 46px;
margin-left: 5px;
border: 1px solid #007EC3;
cursor: pointer;
border-radius: 6px;
background-color: #1CAFFF;
background-image: -moz-linear-gradient(center top , #1CAFFF, #008AD5);
box-shadow: 0px 1px 1px #FFF inset;
color: #FFF;
}

.skipp:active{
	font-size: 23px;
font-weight: 600;
max-width: 350px;
min-width: 190px;
height: 46px;
margin-left: 5px;
border: 1px solid #FFF;
cursor: pointer;
border-radius: 6px;
background-color: #1CAFFF;
background-image: -moz-linear-gradient(center top , #008AD5, #008AD5);
box-shadow: 0px 1px 1px #FFF inset;
color: #FFF;
}
</style>
<link href='http://fonts.googleapis.com/css?family=Chau+Philomene+One' rel='stylesheet' type='text/css'>
</head>
<!-- DON'T DELETE THIS LINE !-->
<body onload="countdown();" style="margin:0; padding:0;">
<?php
if (mysql_real_escape_string($_POST['complete'])) {
	if ($checkcaptchastatus == 1 || $RCactive == 1){
	if ($RCsite === '' || $RCsecret === ''){
		die("WHEN YOU GOT THIS MESSAGE, IT'S BECAUSE WE ARE DEVELOPING GOOGLE reCAPTCHA NOW, Error: Prazdne veliciny");
	}
	$recaptcha=$_POST['g-recaptcha-response'];
	$solvemediaresponde = $_POST["adcopy_response"];
	if (isset($_POST["captchaservice"])) {
			$captchaservice = $_POST["captchaservice"];
			if ($captchaservice == 'solvemedia'){
					if (empty($solvemediaresponde)){
						echo"<script type='text/javascript'>window.location.replace('$mainurl$code'); </script>";
					}
			}else if ($captchaservice == 'recaptcha'){
					if (empty($recaptcha)){
						echo"<script type='text/javascript'>window.location.replace('$mainurl$code'); </script>";
					}
			}
	}
	if(!empty($recaptcha))
	{
		$google_url = "https://www.google.com/recaptcha/api/siteverify";
		$secret = $RCsecret;
		$ip = $_SERVER['REMOTE_ADDR'];
		$url = $google_url."?secret=".$secret."&response=".$recaptcha."&remoteip=".$ip;
		$res = getCurlData($url);
		$res = json_decode($res, true);
		if($res['success'])
		{
			//process form here
			$adid = mysql_real_escape_string($_POST['hidden']);
			// INTERSTITIAL AD
			if($adctype == 'interstitial') {
				if($numcrows != 0) {
					$querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
					$rowip = mysql_num_rows($querycheck);
					
					if ($rowip == 0) {
						// UPDATE VIEWS AND DECREASE CREDITS
						$adowner = $fetchurl['owner'];
						$advid = $fetchurl['id'];
						$updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
						$updateadc = mysql_query("UPDATE ads SET credits=credits-1 WHERE id=$advid");
 
						$qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
						$qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

						$ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
						$ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
						$addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");
						$querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
						$rowip = mysql_num_rows($querycheck);

						if ($rowip == 0) {
							$adowner = $fetchurl['owner'];
							$referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
							$referalfetchR = mysql_fetch_array($referalcheckR);
							$referalnameR = $referalfetchR['refid']; 
							if ($referalnameR != "") {
								$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
								$sa = mysql_fetch_array($settings);
								$ppr = $revenue * $sa['ppvr'];
								$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
								$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
								$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
								$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
								$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
							}
			 
							$referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
							$referalfetch = mysql_fetch_array($referalcheck);
							$referalname = $referalfetch['refid']; 

							if ($referalname != "") {
								$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
								$sa = mysql_fetch_array($settings);
								$ppr = $revenue * $sa['ppvr'];
								$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
								$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
								$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
								$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
								$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
								$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
							}
						}
						// GRAPHS AND CHARTS
						$graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
						$hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
						$viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
						$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");
					}
				}
				else
				{
					$querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
					$rowip = mysql_num_rows($querycheck);

					if ($rowip == 0) {

						$adowner = $fetchurl['owner'];
						$advid = $fetchurl['id'];
						$updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
						$updateadc = mysql_query("UPDATE ads SET credits=credits-1 WHERE id=$advid");
			
						$qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
						$qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");
			
						$ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
						$ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
						$addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");
						$querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
						$rowip = mysql_num_rows($querycheck);

						if ($rowip == 0) {
							$adowner = $fetchurl['owner'];
							$referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
							$referalfetchR = mysql_fetch_array($referalcheckR);
							$referalnameR = $referalfetchR['refid']; 

							if ($referalnameR != "") {
								$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
								$sa = mysql_fetch_array($settings);
								$ppr = $revenue * $sa['ppvr'];
								$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
								$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
								$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
								$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
								$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
							}
			 
							$referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
							$referalfetch = mysql_fetch_array($referalcheck);
							$referalname = $referalfetch['refid']; 

							if ($referalname != "") {
								$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
								$sa = mysql_fetch_array($settings);
								$ppr = $revenue * $sa['ppvr'];
								$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
								$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
								$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
								$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
								$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
								$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
							}
						}
						$graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
						$hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
						$viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
						$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");
					}
				}
			}else if($adctype == 'video') {
				if($numcrows != 0) {
					$querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
					$rowip = mysql_num_rows($querycheck);
					if ($rowip == 0) {
						// UPDATE VIEWS AND DECREASE CREDITS
						$adowner = $fetchurl['owner'];
						$advid = $fetchurl['id'];
						$updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
						$updateadc = mysql_query("UPDATE ads SET credits=credits - '1' WHERE id=$advid");
			
						$qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
						$qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");
			
						$ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
						$ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
						$addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");
			
						$referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
						$referalfetch = mysql_fetch_array($referalcheck);
						$referalname = $referalfetch['refid']; 
						// UPDATING BALANCES
						if ($referalname != "") {
							$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
							$sa = mysql_fetch_array($settings);

							$ppr = $pubprice * $sa['ppvr'];
							$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
							$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$referalname'");
							$addupearnings = mysql_query("UPDATE members SET refearnings=refearnings + $ppr WHERE username='$itemuser'");
							$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
							$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
							$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
							$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");

						}
						// GRAPHS AND CHARTS
						$graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
						$hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
						$viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
						$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");

					}
				}
				else
				{
					$querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
					$rowip = mysql_num_rows($querycheck);

					if ($rowip == 0) {
						$adowner = $fetchurl['owner'];
						$advid = $fetchurl['id'];
						$updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
						$updateadc = mysql_query("UPDATE ads SET credits=credits - '1' WHERE id=$advid");
			
						$qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
						$qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");
			
						$ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
						$ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
						$addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");
			
						$referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
						$referalfetch = mysql_fetch_array($referalcheck);
						$referalname = $referalfetch['refid']; 
						// UPDATING BALANCES
						if ($referalname != "") {
							$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
							$sa = mysql_fetch_array($settings);

							$ppr = $pubprice * $sa['ppvr'];
							$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
							$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$referalname'");
							$addupearnings = mysql_query("UPDATE members SET refearnings=refearnings + $ppr WHERE username='$itemuser'");
							$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
							$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
							$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
							$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
						}

						$graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
						$hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
						$viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
						$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");
					}
				}
			}else if($adctype == 'none') {// SHORTENED LINK WOTHOUT ANY ADS
				$qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
				$qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

				if (false === strpos($urlto, '://')) {
					$urlto = 'http://' . $urlto;
				}
				echo"<script type='text/javascript'>window.location.replace('$urlto'); </script>";
			}
			if($numrows == '1'){
			
			if (false === strpos($urlto, '://')) {
				$urlto = 'http://' . $urlto;
			}
			echo"<script type='text/javascript'>window.location.replace('$urlto'); </script>";
			}else // IF NOT FOUNT SHORTENED LINK IN DB
				header( 'Location: home' ) ;
		}else{
			//handle incorrect answer
				echo"<script type='text/javascript'>window.location.replace('$mainurl$code'); </script>";
		}
	}else{
	require_once("include/solvemedialib.php");
	$privkey = $captchav;
	$hashkey = $captchah;
	$solvemedia_response = solvemedia_check_answer($privkey,
						$_SERVER["REMOTE_ADDR"],
						$_POST["adcopy_challenge"],
						$_POST["adcopy_response"],
						$hashkey);
	if (!$solvemedia_response->is_valid) {
		//handle incorrect answer
		echo"<script type='text/javascript'>window.location.replace('$mainurl$code'); </script>";
	}
	else{
	//process form here

$adid = mysql_real_escape_string($_POST['hidden']);
// INTERSTITIAL AD
if($adctype == 'interstitial') {

      if($numcrows != 0) {


           $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {
// UPDATE VIEWS AND DECREASE CREDITS
             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits-1 WHERE id=$advid");
 
             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");
			 $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
              }
				// GRAPHS AND CHARTS
               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
                $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");

              }
       }
      else
       {
          $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits-1 WHERE id=$advid");

             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");
			 $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
              }
               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
                $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");
              }
       }
}else 
if($adctype == 'video') {

      if($numcrows != 0) {


           $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {
// UPDATE VIEWS AND DECREASE CREDITS
             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits - '1' WHERE id=$advid");
 
             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");

             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 
// UPDATING BALANCES
              if ($referalname != "") {

                $settings = mysql_query("SELECT * FROM settings WHERE id='1'");
                $sa = mysql_fetch_array($settings);

               $ppr = $pubprice * $sa['ppvr'];
               $addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
               $addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$referalname'");
               $addupearnings = mysql_query("UPDATE members SET refearnings=refearnings + $ppr WHERE username='$itemuser'");
               $graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
               $hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
               $viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
               $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");

                }
// GRAPHS AND CHARTS
               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
                $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");

              }
       }
      else
       {
          $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits - '1' WHERE id=$advid");

             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");

             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 
// UPDATING BALANCES
              if ($referalname != "") {

                $settings = mysql_query("SELECT * FROM settings WHERE id='1'");
                $sa = mysql_fetch_array($settings);

               $ppr = $pubprice * $sa['ppvr'];
               $addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
               $addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$referalname'");
               $addupearnings = mysql_query("UPDATE members SET refearnings=refearnings + $ppr WHERE username='$itemuser'");
               $graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
               $hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
               $viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
               $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");

                }

               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
                $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");
              }
       }
}else // SHORTENED LINK WOTHOUT ANY ADS
if($adctype == 'none') {

$qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
$qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

if (false === strpos($urlto, '://')) {
    $urlto = 'http://' . $urlto;
}

  echo"<script type='text/javascript'>window.location.replace('$urlto'); </script>";
}
if($numrows == '1'){

if (false === strpos($urlto, '://')) {
    $urlto = 'http://' . $urlto;
}
  echo"<script type='text/javascript'>window.location.replace('$urlto'); </script>";
}// IF NOT FOUNT SHORTENED LINK IN DB
else
 header( 'Location: home' ) ;
}
}
}
}else if (mysql_real_escape_string($_POST['image'])) {
	if ($checkcaptchastatus == 0 && $RCactive == 0){
		
	//process form here

$adid = mysql_real_escape_string($_POST['hidden']);
// INTERSTITIAL AD
if($adctype == 'interstitial') {

      if($numcrows != 0) {


           $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {
// UPDATE VIEWS AND DECREASE CREDITS
             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits-1 WHERE id=$advid");
 
             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");
			 $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
              }
				// GRAPHS AND CHARTS
               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
                $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");

              }
       }
      else
       {
          $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits-1 WHERE id=$advid");

             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");
			 $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
              }
               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
                $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");
              }
       }
}else 
if($adctype == 'video') {

      if($numcrows != 0) {


           $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {
// UPDATE VIEWS AND DECREASE CREDITS
             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits - '1' WHERE id=$advid");
 
             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");

             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 
// UPDATING BALANCES
              if ($referalname != "") {

                $settings = mysql_query("SELECT * FROM settings WHERE id='1'");
                $sa = mysql_fetch_array($settings);

               $ppr = $pubprice * $sa['ppvr'];
               $addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
               $addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$referalname'");
               $addupearnings = mysql_query("UPDATE members SET refearnings=refearnings + $ppr WHERE username='$itemuser'");
               $graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
               $hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
               $viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
               $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");

                }
// GRAPHS AND CHARTS
               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
                $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");

              }
       }
      else
       {
          $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits - '1' WHERE id=$advid");

             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");

             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 
// UPDATING BALANCES
              if ($referalname != "") {

                $settings = mysql_query("SELECT * FROM settings WHERE id='1'");
                $sa = mysql_fetch_array($settings);

               $ppr = $pubprice * $sa['ppvr'];
               $addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
               $addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$referalname'");
               $addupearnings = mysql_query("UPDATE members SET refearnings=refearnings + $ppr WHERE username='$itemuser'");
               $graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
               $hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
               $viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
               $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");

                }

               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
                $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");
              }
       }
}else // SHORTENED LINK WOTHOUT ANY ADS
if($adctype == 'none') {

$qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
$qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

if (false === strpos($urlto, '://')) {
    $urlto = 'http://' . $urlto;
}

  echo"<script type='text/javascript'>window.location.replace('$urlto'); </script>";
}
if($numrows == '1'){

if (false === strpos($urlto, '://')) {
    $urlto = 'http://' . $urlto;
}
  echo"<script type='text/javascript'>window.location.replace('$urlto'); </script>";
}// IF NOT FOUNT SHORTENED LINK IN DB
else
 header( 'Location: home' ) ;
	}else{
?>
<div style="width: auto; margin:0 0;">
<form id="formsubmitcaptcha" style='max-height:0px' method='POST'>
<table width='100%' style='border-bottom: 0px solid rgb(28, 175, 255); background-color: rgb(28, 175, 255); max-height: 100%; height: 100%; min-height: 100%;'>
	<tr>
		<td width='100%'>
			<center>
			<a target="_blank" href="<?php echo $mainurl; ?>">
				<img src="uploads/images/<?php 
					// LOAD NAME OF SMALL IMAGE FROM DATABASE AND PRINT HIS NAME
					$logo = mysql_query("SELECT * FROM images WHERE id='1'");
					$logor = mysql_fetch_array($logo);
					$logoimage = $logor['smallerimage'];
					echo $logoimage;
				?>">
			</a></br></br></br>
			<?php 
				if ($checkcaptchastatus == 1){
				?>
					<input type="hidden" name="captchaservice" value="solvemedia">
				<?php
					require_once("include/solvemedialib.php");			//include the Solve Media library 
					echo solvemedia_get_html("$captchac");	//outputs the widget
				}else if ($RCactive == 1){
				?>
				<input type="hidden" name="captchaservice" value="recaptcha">
				<div class="g-recaptcha" data-sitekey="<?php echo $RCsite; ?>"></div>
				<script type="text/javascript"
						src="https://www.google.com/recaptcha/api.js?hl=<?php echo $lang; ?>">
				</script>
				<?php
				}
				?>
			</br></br></br>
			<div id='areav' style='height:45px' > 
				<input class='skipp' value='<?php echo $a094;?>' name='complete' type='submit'>
			</div>
			</center>
		</td>
	</tr>
</table>
</form>
<?php
}
}else{
	if($adctype == 'banner') {
		if ($checkcaptchastatus == 1 || $RCactive == 1){
			if (!empty($_POST["banner"])) {
					if ($RCsite === '' || $RCsecret === ''){
		die("WHEN YOU GOT THIS MESSAGE, IT'S BECAUSE WE ARE DEVELOPING GOOGLE reCAPTCHA NOW, Error: Prazdne veliciny");
	}
	$recaptcha=$_POST['g-recaptcha-response'];
	$solvemediaresponde = $_POST["adcopy_response"];
	if (isset($_POST["captchaservice"])) {
			$captchaservice = $_POST["captchaservice"];
			if ($captchaservice == 'solvemedia'){
					if (empty($solvemediaresponde)){
						echo"<script type='text/javascript'>window.location.replace('$mainurl$code'); </script>";
					}
			}else if ($captchaservice == 'recaptcha'){
					if (empty($recaptcha)){
						echo"<script type='text/javascript'>window.location.replace('$mainurl$code'); </script>";
					}
			}
	}
	if(!empty($recaptcha))
	{
		$google_url = "https://www.google.com/recaptcha/api/siteverify";
		$secret = $RCsecret;
		$ip = $_SERVER['REMOTE_ADDR'];
		$url = $google_url."?secret=".$secret."&response=".$recaptcha."&remoteip=".$ip;
		$res = getCurlData($url);
		$res = json_decode($res, true);
		if($res['success'])
		{
			
			if($adctype == 'banner') {

// FIND RADOM AD && CREDITS MUST BE MORE THAN 1 && CUSTOM COUNTRY
$checkforads = mysql_query("SELECT * FROM ads WHERE adtype='banner' AND countries='$country_name' AND credits > 1 AND active = '1' AND approved = '1' ORDER BY RAND()");
$numcrows = mysql_num_rows($checkforads); 

      if($numcrows != 0) {
        $fetchurl = mysql_fetch_array($checkforads);

        $url = $fetchurl['url'];
        $imageurl = $fetchurl['imageurl'];
        $adid = $fetchurl['id'];
		$advprice = $fgvalues['ppvbadv'];
		$pubprice = $fgvalues['ppvb'];
		$revenue = $advprice - $pubprice;
		$selectrevenue = mysql_query("SELECT * FROM revenue WHERE id=1");
		$revenuerows = mysql_num_rows($selectrevenue);
		if ($revenuerows == 0) {
			mysql_query("INSERT INTO revenue (revenue) VALUES('$revenue')");
		}
		else if ($revenuerows != 0) {
			$oldrevenue = $selectrevenue['revenue'];
			$newrevenue = $oldrevenue + $revenue;
			mysql_query("UPDATE revenue SET revenue=$newrevenue WHERE id=1");
		}


         $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits-1 WHERE id=$advid");

             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");
			 
			 $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
               $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");
			  }
       }
	   // FIND RADOM AD && CREDITS MUST BE MORE THAN 1 && ALL COUNTRIES
      else
       {

$checkforads2 = mysql_query("SELECT * FROM ads WHERE adtype='banner' AND countries='all' AND credits > 1 AND active = '1' AND approved = '1' ORDER BY RAND()");
       $fetchurl = mysql_fetch_array($checkforads2);

        $url = $fetchurl['url'];
        $imageurl = $fetchurl['imageurl'];
        $adid = $fetchurl['id']; 
		$advprice = $allworldvalues['ppvbadv'];
		$pubprice = $allworldvalues['ppvb'];
		$revenue = $advprice - $pubprice;
		$selectrevenue = mysql_query("SELECT * FROM revenue WHERE id=1");
		$revenuerows = mysql_num_rows($selectrevenue);
		if ($revenuerows == 0) {
			mysql_query("INSERT INTO revenue (revenue) VALUES('$revenue')");
		}
		else if ($revenuerows != 0) {
			$oldrevenue = $selectrevenue['revenue'];
			$newrevenue = $oldrevenue + $revenue;
			mysql_query("UPDATE revenue SET revenue=$newrevenue WHERE id=1");
		}

  $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits-1 WHERE id=$advid");

             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");

            $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }

               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
                $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");

              }






       }
}
		?>
		<div style="width: auto; margin:0 0;">
	<?php  
	echo"<iframe scrolling='auto' id='site' allowtransparency='true' src='$urlto' style='-webkit-box-sizing: border-box; width:100%; height:85.2%' frameborder='0'></iframe></div>";
	?>
<table width='100%' style='border-bottom: 0px solid rgb(28, 175, 255); background-color: rgb(28, 175, 255); max-height: 12%; height: 12%; min-height: 12%;'>
	<tr>
		<td width='5%'>
			<a target="_blank" href="<?php echo $mainurl; ?>">
				<img src="uploads/images/<?php 
					// LOAD NAME OF SMALL IMAGE FROM DATABASE AND PRINT HIS NAME
					$logo = mysql_query("SELECT * FROM images WHERE id='1'");
					$logor = mysql_fetch_array($logo);
					$logoimage = $logor['smallerimage'];
					echo $logoimage;
				?>">
			</a>
		</td>
		<td width='35%'>
			<?php 
			echo"<a href='{$url}'><img style='margin-left: 0px;' src='{$imageurl}'></a>";
			?>
		</td>
		<td width='60%'>
			<input onclick="javascript:location.href='<?php echo $urlto; ?>'" type='submit' style='margin-left: 45%;' class='skipp' value='X' name='image'></a>
		</td>
	</tr>
</table>
		<?php
		}else{
			//handle incorrect answer
				echo"<script type='text/javascript'>window.location.replace('$mainurl$code'); </script>";
		}
		}else{
			require_once("include/solvemedialib.php");
			$privkey = $captchav;
			$hashkey = $captchah;
			$solvemediaresponde = $_POST["adcopy_response"];
			$solvemedia_response = solvemedia_check_answer($privkey,
								$_SERVER["REMOTE_ADDR"],
								$_POST["adcopy_challenge"],
								$_POST["adcopy_response"],
								$hashkey);
			if (!$solvemedia_response->is_valid) {
				//handle incorrect answer
				echo"<script type='text/javascript'>window.location.replace('$mainurl$code'); </script>";
			}
			else{
			if($adctype == 'banner') {

// FIND RADOM AD && CREDITS MUST BE MORE THAN 1 && CUSTOM COUNTRY
$checkforads = mysql_query("SELECT * FROM ads WHERE adtype='banner' AND countries='$country_name' AND credits > 1 AND active = '1' AND approved = '1' ORDER BY RAND()");
$numcrows = mysql_num_rows($checkforads); 

      if($numcrows != 0) {
        $fetchurl = mysql_fetch_array($checkforads);

        $url = $fetchurl['url'];
        $imageurl = $fetchurl['imageurl'];
        $adid = $fetchurl['id'];
		$advprice = $fgvalues['ppvbadv'];
		$pubprice = $fgvalues['ppvb'];
		$revenue = $advprice - $pubprice;
		$selectrevenue = mysql_query("SELECT * FROM revenue WHERE id=1");
		$revenuerows = mysql_num_rows($selectrevenue);
		if ($revenuerows == 0) {
			mysql_query("INSERT INTO revenue (revenue) VALUES('$revenue')");
		}
		else if ($revenuerows != 0) {
			$oldrevenue = $selectrevenue['revenue'];
			$newrevenue = $oldrevenue + $revenue;
			mysql_query("UPDATE revenue SET revenue=$newrevenue WHERE id=1");
		}


         $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits-1 WHERE id=$advid");

             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");
			 
			 $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
               $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");
			  }
       }
	   // FIND RADOM AD && CREDITS MUST BE MORE THAN 1 && ALL COUNTRIES
      else
       {

$checkforads2 = mysql_query("SELECT * FROM ads WHERE adtype='banner' AND countries='all' AND credits > 1 AND active = '1' AND approved = '1' ORDER BY RAND()");
       $fetchurl = mysql_fetch_array($checkforads2);

        $url = $fetchurl['url'];
        $imageurl = $fetchurl['imageurl'];
        $adid = $fetchurl['id']; 
		$advprice = $allworldvalues['ppvbadv'];
		$pubprice = $allworldvalues['ppvb'];
		$revenue = $advprice - $pubprice;
		$selectrevenue = mysql_query("SELECT * FROM revenue WHERE id=1");
		$revenuerows = mysql_num_rows($selectrevenue);
		if ($revenuerows == 0) {
			mysql_query("INSERT INTO revenue (revenue) VALUES('$revenue')");
		}
		else if ($revenuerows != 0) {
			$oldrevenue = $selectrevenue['revenue'];
			$newrevenue = $oldrevenue + $revenue;
			mysql_query("UPDATE revenue SET revenue=$newrevenue WHERE id=1");
		}

  $querycheck = mysql_query("SELECT * FROM ipcheck WHERE url='$code' AND ip='$uip'");
           $rowip = mysql_num_rows($querycheck);

             if ($rowip == 0) {

             $adowner = $fetchurl['owner'];
             $advid = $fetchurl['id'];
             $updateads = mysql_query("UPDATE advertisers SET date7=date7 + '1' WHERE username='$adowner'");
			 $updateadc = mysql_query("UPDATE ads SET credits=credits-1 WHERE id=$advid");

             $qstats = mysql_query("UPDATE stats SET svlinks7=svlinks7 + '1' WHERE id='1'");
             $qstatss = mysql_query("UPDATE stats SET tsvlinks=tsvlinks + '1' WHERE id='1'");

             $ipadd = mysql_query("INSERT INTO ipcheck (url,ip) VALUES  ('$code','$uip')");
             $ipadd2 = mysql_query("INSERT INTO totalip (url,ip,username) VALUES  ('$code','$uip','$session_username')");
             $addin = mysql_query("UPDATE members SET balance=balance + $pubprice WHERE username='$itemuser'");

            $adowner = $fetchurl['owner'];
			 $referalcheckR = mysql_query("SELECT * FROM advertisers WHERE username='$adowner'");
             $referalfetchR = mysql_fetch_array($referalcheckR);
             $referalnameR = $referalfetchR['refid']; 

              if ($referalnameR != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalnameR'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$adowner'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalnameR'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalnameR'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
			 
             $referalcheck = mysql_query("SELECT * FROM members WHERE username='$itemuser'");
             $referalfetch = mysql_fetch_array($referalcheck);
             $referalname = $referalfetch['refid']; 

              if ($referalname != "") {
					$settings = mysql_query("SELECT * FROM settings WHERE id='1'");
					$sa = mysql_fetch_array($settings);
					$ppr = $revenue * $sa['ppvr'];
					$addbalref = mysql_query("UPDATE members SET balance=balance + $ppr WHERE username='$referalname'");
					$addupearnings = mysql_query("UPDATE members SET uplineearnings=uplineearnings + $ppr WHERE username='$itemuser'");
					$graphupp = mysql_query("UPDATE members SET rdate7=rdate7+1 WHERE username='$referalname'");
					$hitupdatee = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$referalname'");
					$viewsupdatee = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
					$earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $ppr WHERE code='$code'");
                }
               $graphup = mysql_query("UPDATE members SET date7=date7+1 WHERE username='$itemuser'");
               $hitupdate = mysql_query("UPDATE members SET tstats=tstats+1 WHERE username='$itemuser'");
               $viewsupdate = mysql_query("UPDATE items SET views=views + 1 WHERE code='$code'");
                $earningsupdatee = mysql_query("UPDATE items SET mearned=mearned + $pubprice WHERE code='$code'");
              }
       }
}
		?>
		<div style="width: auto; margin:0 0;">
	<?php  
	echo"<iframe scrolling='auto' id='site' allowtransparency='true' src='$urlto' style='-webkit-box-sizing: border-box; width:100%; height:85.2%' frameborder='0'></iframe></div>";
	?>
<table width='100%' style='border-bottom: 0px solid rgb(28, 175, 255); background-color: rgb(28, 175, 255); max-height: 12%; height: 12%; min-height: 12%;'>
	<tr>
		<td width='5%'>
			<a target="_blank" href="<?php echo $mainurl; ?>">
				<img src="uploads/images/<?php 
					// LOAD NAME OF SMALL IMAGE FROM DATABASE AND PRINT HIS NAME
					$logo = mysql_query("SELECT * FROM images WHERE id='1'");
					$logor = mysql_fetch_array($logo);
					$logoimage = $logor['smallerimage'];
					echo $logoimage;
				?>">
			</a>
		</td>
		<td width='35%'>
			<?php 
			echo"<a href='{$url}'><img style='margin-left: 0px;' src='{$imageurl}'></a>";
			?>
		</td>
		<td width='60%'>
			<input onclick="javascript:location.href='<?php echo $urlto; ?>'" type='submit' style='margin-left: 45%;' class='skipp' value='X' name='image'></a>
		</td>
	</tr>
</table>
		<?php
		}
		}
		}
		else{
		?>
		<div style="width: auto; margin:0 0;">
		<form id="formsubmitcaptcha" style='max-height:0px' method='POST'>
		<table width='100%' style='border-bottom: 0px solid rgb(28, 175, 255); background-color: rgb(28, 175, 255); max-height: 100%; height: 100%; min-height: 100%;'>
		<tr>
			<td width='100%'>
				<center>
				<a target="_blank" href="<?php echo $mainurl; ?>">
					<img src="uploads/images/<?php 
						// LOAD NAME OF SMALL IMAGE FROM DATABASE AND PRINT HIS NAME
						$logo = mysql_query("SELECT * FROM images WHERE id='1'");
						$logor = mysql_fetch_array($logo);
						$logoimage = $logor['smallerimage'];
						echo $logoimage;
					?>">
				</a></br></br></br>
				<?php 
				if ($checkcaptchastatus == 1){
				?>
					<input type="hidden" name="captchaservice" value="solvemedia">
				<?php
					require_once("include/solvemedialib.php");			//include the Solve Media library 
					echo solvemedia_get_html("$captchac");	//outputs the widget
				}else if ($RCactive == 1){
				?>
				<input type="hidden" name="captchaservice" value="recaptcha">
				<div class="g-recaptcha" data-sitekey="<?php echo $RCsite; ?>"></div>
				<script type="text/javascript"
						src="https://www.google.com/recaptcha/api.js?hl=<?php echo $lang; ?>">
				</script>
				<?php
				}
				?></br></br></br>
				<div id='areav' style='height:45px' > 
							<input class='skipp' value='<?php echo $a094;?>' name='banner' type='submit'>
				</div>
				</center>
			</td>
			</tr>
		</table>
		</form>
	<?php
		}
		}else{
		?>
		<div style="width: auto; margin:0 0;">
			<?php  
				echo"<iframe scrolling='auto' id='site' allowtransparency='true' src='$urlto' style='-webkit-box-sizing: border-box; width:100%; height:85.2%' frameborder='0'></iframe></div>";
			?>
<table width='100%' style='border-bottom: 0px solid rgb(28, 175, 255); background-color: rgb(28, 175, 255); max-height: 12%; height: 12%; min-height: 12%;'>
	<tr>
		<td width='5%'>
			<a target="_blank" href="<?php echo $mainurl; ?>">
				<img src="uploads/images/<?php 
					// LOAD NAME OF SMALL IMAGE FROM DATABASE AND PRINT HIS NAME
					$logo = mysql_query("SELECT * FROM images WHERE id='1'");
					$logor = mysql_fetch_array($logo);
					$logoimage = $logor['smallerimage'];
					echo $logoimage;
				?>">
			</a>
		</td>
		<td width='35%'>
			<?php 
			echo"<a href='{$url}'><img style='margin-left: 0px;' src='{$imageurl}'></a>";
			?>
		</td>
		<td width='60%'>
			<input onclick="javascript:location.href='<?php echo $urlto; ?>'" type='submit' style='margin-left: 45%;' class='skipp' value='X' name='image'></a>
		</td>
	</tr>
</table>
		<?php
		}
	}else{
	?>
<div style="width: auto; margin:0 0;">
<?php  
	/// BANNER IFRAME WITH SHORTENED LINK
	if($adctype == 'banner') {
		echo"<iframe scrolling='auto' id='site' allowtransparency='true' src='$urlto' style='-webkit-box-sizing: border-box; width:100%; height:85.2%' frameborder='0'></iframe></div>";
	}else if($adctype == 'interstitial') {/// INTERSTITIAL IFRAME WITH AD
		echo"<iframe scrolling='auto' src='$url' id='site' allowtransparency='true' style='width:100%;height:88%;max-height:88%;display:block;visibility:visible;' frameborder='0'></iframe></div>";
	}else if($adctype == 'video') {/// VIDEO PLAYER WITH AD?>
		<div class="cont" id="container1">&nbsp;</div>
	<?php }?>
<table width='100%' style='border-bottom: 0px solid rgb(28, 175, 255); background-color: rgb(28, 175, 255); max-height: 12%; height: 12%; min-height: 12%;'>
	<tr>
		<td width='5%'>
			<a target="_blank" href="<?php echo $mainurl; ?>">
				<img src="uploads/images/<?php 
					// LOAD NAME OF SMALL IMAGE FROM DATABASE AND PRINT HIS NAME
					$logo = mysql_query("SELECT * FROM images WHERE id='1'");
					$logor = mysql_fetch_array($logo);
					$logoimage = $logor['smallerimage'];
					echo $logoimage;
				?>">
			</a>
		</td>
		<td width='35%'>
			<?php 
			// BANNER ADS HERE
			if($adctype == 'banner') {
				// IMAGE LOADER
				echo"<a href='{$url}'><img style='margin-left: 0px;' src='{$imageurl}'></a>";
			}else if($adctype == 'interstitial') {
				echo"&nbsp;";
			}else if($adctype == 'video') {
				?>
				<div id='watchad' align='left' style='height:45px'>
					<button onclick="manualfunc()" id="PlayPauseButton" align='right' style='min-width: 60px;' class='skipp' type="button"><i class="fa fa-play"></i> / <i class="fa fa-pause"></i></button>
					<button onclick="setmute()" id="muteButton" align='right' style='min-width: 60px;' class='skipp' type="button"><i class="fa fa-volume-up"></i> / <i class="fa fa-volume-off"></i></button>
				</div>
				<?php
			}?>
		</td>
		<td width='60%'>
			<?php 
			if($adctype == 'banner') {
				?>
				<input onclick="javascript:location.href='<?php echo $urlto; ?>'" type='submit' style='margin-left: 45%;' class='skipp' value='X' name='image'></a>
				<?php
			}else if($adctype == 'interstitial') {
				echo"<div id='area' align='right' style='height:45px'><input align='right' class='skipp' value='$a263 ...' name='submit' type='submit'></div>";
			}else if($adctype == 'video') {
				?>
				<div id='areav' align='right' style='height:45px' > 
					<button onclick="location.reload()" align='right' style='min-width: 60px;' class='skipp' type="button"><i class="fa fa-refresh"></i></button>
					<input onclick="window.open('<?php echo $clickto; ?>')" align='right' class='skipp' value='<?php echo $a015;?>' name='submit' type='submit'>
					<button onclick="manualfunc()" id="buttonv" align='right' style='min-width: 60px;' class='skipp' type="button"><i class="fa fa-circle-o-notch fa-spin"></i> Play</button>
				</div>
				<?php
			}?>
		</td>
	</tr>
</table>
<?php if($adctype == 'video') {?>
<script type="text/javascript" src="player/jwplayer.js"></script>
<?php
$qDURATION3 = "SELECT `viddur` FROM `settings` WHERE `id` = '1'";
$rDURATION2 = mysql_query($qDURATION3) or die($qDURATION3."<br/><br/>".mysql_error());
$videodurationskip = mysql_result($rDURATION2, 0);
?>
<script type="text/javascript">
jwplayer.key="N8zhkmYvvRwOhz4aTGkySoEri4x+9pQwR7GHIQ==";

jwplayer("container1").setup({
  image: "player/image.jpg",
  file: "player/video.mp4",
  skin: "vapor",
  wmode: "transparent",
  screencolor: "1CAFFF",
  width: "100%",
  controls: "false",
  height: "88%",
  primary: "html",
  advertising: {
    client: 'vast',
	'skipoffset':5,
    tag: "player/ads/ad.php?vidtype=<?php echo $vidtype; ?>&vidurl=<?php echo $vidurl; ?>&clickto=<?php echo $clickto; ?>"
  }
});

var controlfirst = 0;
var duration = 0;
var skip = 0;
var rotate = 0;
jwplayer().onAdTime(function(event) {
  var remaining = Math.round(event.duration-event.position);
  if (controlfirst < 1) {
	duration = remaining;
  }
  controlfirst++;
  if (duration > <?php echo $videodurationskip;?>){
	  var skiptime = <?php echo $videodurationskip;?>;
  }else{
	  var skiptime = duration-1;
  }
  var progress = document.getElementById("progress");
  var countdownArea = document.getElementById("areav");
  var BVideo = document.getElementById("buttonv");
  skip = (duration - remaining);
  skiptext = (skiptime - skip);
  if (rotate == 0) {
	BVideo.innerHTML = '<i class="fa fa-circle-o-notch"></i> '+skiptext+' <?php echo $a036;?>';
	rotate = 1;
  }else if (rotate == 1) {
	BVideo.innerHTML = '<i class="fa fa-circle-o-notch fa-rotate-90"></i> '+skiptext+' <?php echo $a036;?>';
	rotate = 2;
  }else if (rotate == 2) {
	BVideo.innerHTML = '<i class="fa fa-circle-o-notch fa-rotate-180"></i> '+skiptext+' <?php echo $a036;?>';
	rotate = 3;
  }else if (rotate == 3) {
	BVideo.innerHTML = '<i class="fa fa-circle-o-notch fa-rotate-270"></i> '+skiptext+' <?php echo $a036;?>';
	rotate = 0;
  }
  if (skip > skiptime) {
	countdownArea.innerHTML = "<form style='max-height:0px' method='POST'><button onclick='location.reload(true); return false;' align='right' style='min-width: 60px;' class='skipp' type='button'><i class='fa fa-refresh'></i></button><input onclick='window.open(&#34;<?php echo $clickto; ?>&#34;)' align='right' class='skipp' value='<?php echo $a015;?>' name='submit' type='submit'><input align='right' class='skipp' value='<?php echo $a094;?>' name='image' type='submit'></form>";
  }
});

window.onPause = function () {
  var progress = document.getElementById("progress");
  progress.value = "Paused";
}; 

var vis = (function(){
	var stateKey, eventKey, keys = {
		hidden: "visibilitychange",
		webkitHidden: "webkitvisibilitychange",
		mozHidden: "mozvisibilitychange",
		msHidden: "msvisibilitychange"
	};
	for (stateKey in keys) {
		if (stateKey in document) {
			eventKey = keys[stateKey];
			break;
		}
	}
	return function(c) {
		if (c) document.addEventListener(eventKey, c);
		return !document[stateKey];
	}
})();

vis(function(){
	document.title = vis() ? 'Ready' : 'Paused';
});

// to set the initial state
document.title = vis() ? 'Ready' : 'Paused';

var t=setInterval(runFunction,200);
var manualpush = 0;

function manualfunc() {
	if (jwplayer().getState() === 'PAUSED') {//PLAY
		jwplayer().play();
		manualpush = 0;
	}else if (jwplayer().getState() === 'IDLE') {//PLAY
		jwplayer().play();
		manualpush = 0;
	}else if (jwplayer().getState() === 'PLAYING') {//PAUSE
		jwplayer().play();
		manualpush = 1;
	}
}

function setmute() {
	if (jwplayer().getMute() === true) {//NO SOUND - MUTED
		jwplayer().setMute(false);
	}else if (jwplayer().getMute() === false) {//SOUND - UNMUTED
		jwplayer().setMute(true);
	}
}
function runFunction() {
	if (document.title === 'Ready') {
		if (jwplayer().getState() === 'PAUSED') {//PLAY
			if (manualpush === 0) {
				jwplayer().play();
			}
		}else if (jwplayer().getState() === 'IDLE') {//PLAY
			jwplayer().play();
		}
	} else if (document.title === 'Paused') {//PAUSE
		if (jwplayer().getState() === 'PLAYING') {
				jwplayer().play();
		}
	}
	
	if (jwplayer().getMute() === true) {//NO SOUND - MUTED
		document.getElementById('muteButton').innerHTML='<i class="fa fa-volume-off"></i>';
	}else if (jwplayer().getMute() === false) {//SOUND - UNMUTED
		document.getElementById('muteButton').innerHTML='<i class="fa fa-volume-up"></i>';
	}
	
	if (jwplayer().getState() === 'PAUSED') {//PAUSED
		document.getElementById('PlayPauseButton').innerHTML='<i class="fa fa-play"></i>';
	}else if (jwplayer().getState() === 'IDLE') {//IDLE
		document.getElementById('PlayPauseButton').innerHTML='<i class="fa fa-play"></i>';
	}else if (jwplayer().getState() === 'PLAYING') {//PLAYING
		document.getElementById('PlayPauseButton').innerHTML='<i class="fa fa-pause"></i>';
	}
}
</script>
<?php }?>
<?php }?>
<?php }?>
</body>
</html>