<?
session_start();
require('config.php');
include('funciones.php');

if($_SESSION["endtime"]>time())
{
	echo "<span style=\"border: medium none; padding: 0pt; font-size: 10pt; font-family: Verdana; font-weight: bold; vertical-align: top; color: #ff0000;\">&nbsp;<img src=\"images/error.png\" align=\"middle\">&nbsp;Ошибка! Просмотр не засчитан</span>";
	exit();
}

if(isset($_SESSION["username"]) && isset($_SESSION["password"]))
{


	$user=text($_SESSION["username"]);
$checkuser = mysql_query("SELECT login FROM seelf_autoclicker WHERE login='$user'");
$username_exist = mysql_num_rows($checkuser);

if ($username_exist==2) {
echo "<br /><center><div class='error' style='width:500px;'>Вы нажали на ссылку для автокликеров 2 раза! Ваш Аккаунт Заблокирован!!!</div></center>";
exit();
}
	if(preg_match("|^[\d]*$|",$_SESSION['ad']))
	{
		$adse=intval($_SESSION["ad"]);
	}else{
		echo "<span style=\"border: medium none; padding: 0pt; font-size: 10pt; font-family: Verdana; font-weight: bold; vertical-align: top; color: #ff0000;\">&nbsp;<img src=\"images/error.png\" align=\"middle\">&nbsp;Ошибка! Просмотр не засчитан</span>";
		exit();
	}

	$res=mysql_query("select dopsec from tb_ads1 where id='$adse'");
	$res=mysql_fetch_assoc($res);

	if($res["dopsec"]=='2')
	{

		$captcha=strtolower($_POST["code"]);
		$ver=strtolower($_SESSION["texto"]);
unset($_SESSION["texto"]);
	}


	if(!isset($_GET["ds"]))
	{
		$checkad = mysql_query("SELECT id FROM tb_ads1 WHERE id='$adse' and tipo='ads'");
		$ad_exist = mysql_num_rows($checkad);

		if ($ad_exist<1)
		{
			echo "<span style=\"border: medium none; padding: 0pt; font-size: 10pt; font-family: Verdana; font-weight: bold; vertical-align: top; color: #ff0000;\">&nbsp;<img src=\"images/error.png\" align=\"middle\">&nbsp;Ссылка не существует</span>";
			exit();
		}

		if($res["dopsec"]=='2')
		{
			?>
			 <form action='vls1.php?view=ok&ds=clicked' method='post'>
      <table border="0" cellpadding="0" cellspacing="0" align="left" style="padding:3px 0px 0px 3px;"><tr>
      <td valign="top" style="padding-right:4px">
      <img src="image.php?<?php echo $res; ?>" class="imgcap" alt="" /></td>
      <td valign="top"><input type="hidden" name="code" value="0">
       <input class="serfnum" name="code" value="1" onclick="vernum(this.form,1); submit();" type="submit">
       <input class="serfnum" name="code" value="2" onclick="vernum(this.form,2); submit();" type="submit">
       <input class="serfnum" name="code" value="3" onclick="vernum(this.form,3); submit();" type="submit">
       <input class="serfnum" name="code" value="4" onclick="vernum(this.form,4); submit();" type="submit"><br />
       <input class="serfnum" name="code" value="5" onclick="vernum(this.form,5); submit();" type="submit">
       <input class="serfnum" name="code" value="6" onclick="vernum(this.form,6); submit();" type="submit">
       <input class="serfnum" name="code" value="7" onclick="vernum(this.form,7); submit();" type="submit">
       <input class="serfnum" name="code" value="8" onclick="vernum(this.form,8); submit();" type="submit"></td>
     </tr></table>
</form><?

			exit();
	}

	}

	if(!isset($_GET["ds"]) or ($_GET["ds"]=='clicked' and $ver==$captcha))
	{
		$adse=intval($_SESSION["ad"]);

		$querye = mysql_query("SELECT * FROM tb_ads1 WHERE user = '$user' and ident= '$adse'") or die(mysql_error());
		$rowe = mysql_fetch_assoc($querye);

		$time=$rowe['visitime'];

		$crok1 = date(time());
		$crok2 = date($time + 86400);

		if($crok1 >= $crok2)
		{
			$checkvisit = mysql_query("SELECT * FROM tb_ads1 WHERE user='$user' and ident='$adse'");
			$referer_visit = mysql_num_rows($checkvisit);

			$sqlz = "SELECT * FROM tb_ads1 WHERE id='$adse'";
			$resultz = mysql_query($sqlz);
			$myrowz = mysql_fetch_assoc($resultz);
			$numero=$myrowz["members"];

			$jo=$myrowz["plan"];

			if ($numero >= $jo)
			{
				echo "<span style=\"border: medium none; padding: 0pt; font-size: 10pt; font-family: Verdana; font-weight: bold; vertical-align: top; color: #ff0000;\">&nbsp;<img src=\"images/error.png\" align=\"middle\">&nbsp;Ссылка не существует</span>";
				exit();
			}

			if ($referer_visit>0)
			{
				$queryzx = "UPDATE tb_ads1 SET visitime='$crok1' WHERE user='$user' and ident='$adse' and tipo='visit'";
				mysql_query($queryzx) or die(mysql_error());
			}else{
				$queryzz = "INSERT INTO tb_ads1 (user, tipo, ident, visitime) VALUES('$user','visit','$adse','$crok1')";
				mysql_query($queryzz) or die(mysql_error());
			}

			$sqlzd = "SELECT * FROM tb_users WHERE username='$user'";
			$resultzd = mysql_query($sqlzd);
			$myrowzd = mysql_fetch_assoc($resultzd);
			$juaz=$myrowzd["referer"];

  $multic=$myrowzd["blockpay"];
  if($multic==1)
  {
  echo "<span style=\"border: medium none; padding: 0pt; font-size: 10pt; font-family: Verdana; font-weight: bold; vertical-align: top; color: #ff0000;\"> <img src=\"images/error.png\" align=\"middle\"> Вы нарушили правила системы и не можете больше зарабатывать!</span>";
  exit();
  }


			$sqlex = "UPDATE tb_ads1 SET members='$numero'+1 WHERE id='$adse'";
			$resultex = mysql_query($sqlex);

			$sqlze = "SELECT * FROM tb_users WHERE username='$user'";
			$resultze = mysql_query($sqlze);
			$myrowze = mysql_fetch_assoc($resultze);

			$visitas=$myrowze["visits"];
			$dinero=$myrowze["money"];
			$level=$myrowze["account"];

			if($level!='V.I.P.')
			{
				$sqlzdu = "SELECT * FROM tb_config1 WHERE item='click' and howmany='1'";
			}else{
				$sqlzdu = "SELECT * FROM tb_config1 WHERE item='vipclick' and howmany='1'";
			}

			$resultzdu = mysql_query($sqlzdu);
			$myrowzdu = mysql_fetch_assoc($resultzdu);

			include('moneyfortimer.php');
$timer=$_SESSION["timer"];
  if($timer == 5) $elprecio=$payfor5;
  if($timer == 10) $elprecio=$payfor10;
  if($timer == 15) $elprecio=$payfor15;

			$sqlexzz = "UPDATE tb_users SET visits='$visitas'+1, money='$dinero'+'$elprecio' WHERE username='$user'";
			$resultexzz = mysql_query($sqlexzz);

         $refer_kon=mysql_query("SELECT id
                  FROM still_konkurs_ref
                  WHERE idref=(SELECT id FROM tb_users WHERE username=(SELECT referer FROM tb_users WHERE username='$user')) and vid='2'
                  and time_start < '".time()."' and time_start+(time_end*86400) > '".time()."' LIMIT 1");
                  if(mysql_num_rows($refer_kon) > 0){
                    $rk = mysql_fetch_assoc($refer_kon);

                    $top_kon=mysql_query("SELECT id
                    FROM still_top_kon WHERE idk='".$rk["id"]."' and  idu=(SELECT id FROM tb_users WHERE username='$user') LIMIT 1");
                    if(mysql_num_rows($top_kon) > 0){
                      $tk = mysql_fetch_assoc($top_kon);

                      mysql_query("UPDATE still_top_kon SET danie=danie+'1' WHERE id='".$tk["id"]."'");

                    }else{

                      mysql_query("insert into still_top_kon (idu,danie,idk) values ((SELECT id FROM tb_users WHERE username='$user'),'1','".$rk["id"]."')");

                    }

                  }

			$res=mysql_query("select * from tb_comp where param='3'");
			if(mysql_num_rows($res)>0)
			{
				while($row=mysql_fetch_assoc($res))
				{
					$id=$row["id"];
					$lidertype=$row["lidername"];
					$t=time();
					$sd=strtotime($row["startdate"]);
					$ed=strtotime($row["enddate"]);
					if($t>$sd && $t<$ed)
					{
						if($lidertype=='1')
						{
							$res1=mysql_query("select wmid from tb_users where username='$user'");
							if(mysql_num_rows($res1)>0){$res1=mysql_fetch_assoc($res1); $lidername=$res1["wmid"];}else{$lidername='';}
						}else{
							$lidername=$user;
						}
						if($lidername!='')
						{
							$res1=mysql_query("select * from tb_compdata where idk='$id' and user='$lidername'");
							if(mysql_num_rows($res1)>0)
							{
								$res1=mysql_fetch_assoc($res1);
								$resvalue=$res1["resvalue"]+1;
								mysql_query("update tb_compdata set resvalue='$resvalue' where id='".$res1["id"]."'");
							}else{
								mysql_query("insert into tb_compdata (idk,user,resvalue) values ('$id','$lidername','1')");
							}
						}
					}
				}
			}

echo "
<table>
<tr>
<td><img src=\"images/ok.png\" align=\"absmiddle\" style='padding-right: 3px'></td><td><span style='color:green; font-size: 10pt;'> Спасибо за посещение!</span><br /><span style='color:#818181; font-size: 8pt;'> Просмотр засчитан!</span></td></tr></table>";
		?>
<script type="text/javascript">
window.top.location.replace("<?=$_SESSION["urlsite"]; ?>");
</script> 
		<? }else{
			echo "<span style=\"border: medium none; padding: 0pt; font-size: 10pt; font-family: Verdana; font-weight: bold; vertical-align: top; color: #ff0000;\">&nbsp;<img src=\"images/error.png\" align=\"middle\">&nbsp;Вы уже просматривали эту ссылку!</span>";
		}
	}else{
		echo "<span style=\"border: medium none; padding: 0pt; font-size: 10pt; font-family: Verdana; font-weight: bold; vertical-align: top; color: #ff0000;\">&nbsp;<img src=\"images/error.png\" align=\"middle\">&nbsp;Ошибка! Просмотр не засчитан</span>";
	}
	mysql_close($con);
}else{

	$juaz=date("n/j/Y H:i:s", $crok1);
	$juaze=date("n/j/Y H:i:s", $crok2);

	echo "<span style=\"border: medium none; padding: 0pt; font-size: 10pt; font-family: Verdana; font-weight: bold; vertical-align: top; color: #ff0000;\">&nbsp;<img src=\"images/error.png\" align=\"middle\">&nbsp;Вам необходимо авторизоваться</span>";
}
?>
<?php
$a = rand(1,20);
$b = rand(1,20);
$_SESSION["itog"] = $a + $b;
?>