<?php session_start();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=cp1251">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<link rel="stylesheet" type="text/css" href="style.css">
<title><?php echo $_SERVER["HTTP_HOST"];?> >> Автоматический серфинг</title>
</head>
<body oncontextmenu="javascript:return false" onUnLoad="window.parent.opener.i--" onload="do_count();">
<script type="text/javascript" src="dir.js"></script>
<noscript><meta http-equiv="refresh" content="0;url=JavaScript.php"></noscript>
<?php
if(isset($_SESSION["username"]) && isset($_SESSION["password"])) {
	require('../config.php');
	require('../funciones.php');

	$username = text($_SESSION["username"]);
	$laip = getRealIP();

	$sql = mysql_query("SELECT `price` FROM `tb_config` WHERE `item`='auto_timer_ot' AND `howmany`='1'");
	$auto_timer_ot = mysql_result($sql,0,0);

	$sql = mysql_query("SELECT `price` FROM `tb_config` WHERE `item`='auto_timer_cena' AND `howmany`='1'");
	$cena_add_timer = mysql_result($sql,0,0);

	$sql = mysql_query("SELECT `price` FROM `tb_config` WHERE `item`='auto_click' AND `howmany`='1'");
	$click = mysql_result($sql,0,0);

	if(isset($_GET["st"]) && isset($_GET["b"]) && intval($_GET["b"])==1) {
		$id = (isset($_GET["st"])) ? intval($_GET["st"]) : false;

		if($id>0) {
			$sql_id = mysql_query("SELECT * FROM `seelf_auto` WHERE `id`='$id' AND `status`='pay'");
			if(mysql_num_rows($sql_id)>0) {
				$sql_v = mysql_query("SELECT * FROM `seelf_auto_vis` WHERE `username`='$username' AND `type`='claims' AND `ident`='$id'") or die(mysql_error());
				if(mysql_num_rows($sql_v)>0) {
					mysql_query("UPDATE `seelf_auto` SET `claims`=`claims`+1 WHERE `id`='$id' AND `status`='pay'") or die(mysql_error());
					mysql_query("UPDATE `seelf_auto_vis` SET `date`='".time()."', `ip`='$laip', `money`='0.0000' WHERE `username`='$username' AND `type`='claims' AND `ident`='$id'") or die(mysql_error());
				}else{
					mysql_query("UPDATE `seelf_auto` SET `claims`=`claims`+1 WHERE `id`='$id' AND `status`='pay'") or die(mysql_error());
					mysql_query("INSERT INTO `seelf_auto_vis` (`username`, `type`, `ident`, `date`, `ip`, `money`) VALUES('$username', 'claims', '".$id."', '".time()."', '$laip', '0.0000')") or die(mysql_error());
				}
			}
		}
	}

	if(isset($_GET["st"]) && !isset($_GET["b"]) && isset($_GET["cap"]) && intval($_GET["cap"])>=0) {
		$id = (isset($_GET["st"])) ? intval($_GET["st"]) : false;
		$cap = (isset($_GET["cap"])) ? intval($_GET["cap"]) : false;

		if($id>0 && isset($_SESSION["endtmr_auto"]) && intval($_SESSION["endtmr_auto"]) <= time()) {

            require('../karera/setup_status.php');

			$sql_id = mysql_query("SELECT * FROM `seelf_auto` WHERE `id`='$id' AND `status`='pay'");
			if(mysql_num_rows($sql_id)>0) {
				$rowid = mysql_fetch_assoc($sql_id);

				$plan = $rowid["plan"];
				$members = $rowid["members"];
				$timer = $rowid["timer"];
				$url = $rowid["url"];
				$description = $rowid["description"];

				$_SESSION["hash1"] = md5(text($id.$plan.$members.$timer.$_SESSION["endtmr_auto"]));

				if($captcha>0 && !isset($_GET["answer"]) && !isset($_GET["num"])) {
					function get_codes1($num,$len) {
						for($y=0;$y<$num;$y++) {
							$codes[]=substr(strtoupper(md5(mt_rand(1000,1000000000))),0,$len);
						}
						return $codes;
					}

					function get_codes2($num) {
						for($y=0;$y<$num;$y++) {
							$codes[]=mt_rand(123456789,999999999999999999);
						}
						return $codes;
					}

					$codes1 = get_codes1(5,3);
					$codes2 = get_codes2(5);

					$rnd_nomer = mt_rand(0,count($codes1)-1);

					$_SESSION["captcha_keystring"] = $codes1[$rnd_nomer];
					$_SESSION["codes"] = $codes2[$rnd_nomer];
					$_SESSION["hash2"] = md5(text($id.$plan.$members.$timer.$captcha.$_SESSION["endtmr_auto"]));

					echo '<table border="1" style="width: 100%; height: 72px; border-collapse: collapse; border: 1px solid #000; border-bottom:1px;" cellpadding="0" cellspacing="0">';
					echo '<tr align="center">';
						echo '<th width="240" align="center" bgcolor="#D1EEEE" height="15px" style="border-bottom: 0 px solid;">Выберите правильный вариант:</th>';
						echo '<th align="center" bgcolor="#D1EEEE" height="15px" style="border-bottom: 0 px solid;">Информация о ссылке</th>';
						echo '<th width="220" align="center" bgcolor="#D1EEEE" height="15px" style="border-bottom: 0 px solid;">Действия</th>';

					echo '</tr>';
					echo '<tr>';
						echo '<td align="center"><table border="0" cellpadding="0" cellspacing="0"><tr align="center">';
						$k_num=0;
						foreach($codes1 as $c):
							echo '<td align="center">';
							echo '<form action="" method="GET" target="_self">';
							echo '<input type="hidden" name="st" value="'.$id.'">';
							echo '<input type="hidden" name="cap" value="'.$captcha.'">';
							echo '<input type="hidden" name="answer" value="'.$c.'">';
							echo '<input type="hidden" name="num" value="'.md5($codes2["$k_num"]).'">';
							echo '<input type="submit" value="'.$c.'" class="submit">';
							echo '</form>';
							echo '</td>';
						$k_num++;
						endforeach;
						echo '</tr></table></td>';
						echo '<td style="font-size: 80%; padding: 0 5px; 0 5px;"><b>Описание:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$description.'<br><b>Адрес сайта:</b>&nbsp;&nbsp;<a href="'.$url.'" target="_blank">'.$url.'</a></td>';
					echo '</tr>';
					echo '</table>';
					exit();
				}else{
				}
				if($plan>$members) {
					if($captcha>0) {
						if(isset($_GET["answer"]) && isset($_SESSION["captcha_keystring"]) && isset($_GET["num"]) && isset($_SESSION["hash1"]) && isset($_SESSION["hash2"]) && md5(strtoupper(limpiar($_GET["answer"])))==md5(strtoupper($_SESSION["captcha_keystring"])) && strtoupper(limpiar($_GET["num"]))==strtoupper(md5($_SESSION["codes"])) && strtoupper($_SESSION["hash1"])==strtoupper($_SESSION["hash2"])) {
							unset($_SESSION["captcha_keystring"]);
							unset($_SESSION["hash1"]);
							unset($_SESSION["hash2"]);
							unset($_SESSION["codes"]);

							$cena_click = round((($timer - $auto_timer_ot) * $cena_add_timer + $click),4);

							$sql_v = mysql_query("SELECT * FROM `seelf_auto_vis` WHERE `username`='$username' AND `type`='visit' AND `ident`='$id'") or die(mysql_error());
							if(mysql_num_rows($sql_v)>0) {
								$rowv = mysql_fetch_assoc($sql_v);

								$date_visit = $rowv["date"];
								$crok1 = time();
								$crok2 = ($date_visit + (24 * 60 * 60));

								if($crok1 >= $crok2) {
									mysql_query("UPDATE `seelf_auto` SET `limit_now`=`limit_now`-1, `members`=`members`+1 WHERE `id`='$id' AND `status`='pay'") or die(mysql_error());
									mysql_query("UPDATE `seelf_auto_vis` SET `date`='".time()."', `ip`='$laip', `money`='$cena_click' WHERE `username`='$username' AND `type`='visit' AND `ident`='$id'") or die(mysql_error());

                                  $referer = mysql_query("SELECT * FROM `tb_users` WHERE `username` = '$username'");
                                  $refer = mysql_fetch_assoc($referer);

                                  if($refer["referer"] != ""){

                                    $referer1 = mysql_query("SELECT * FROM `tb_users` WHERE `username` = '".$refer["referer"]."'");
                                    $refer1 = mysql_fetch_assoc($referer1);

                                    $doxod_ref1 = $cena_click * ($st_users[$refer1["ball_status"]]["dox_ref"]/100);

                                    mysql_query("UPDATE tb_users
                                    SET `referalvisits` = `referalvisits` + '1', `money` = `money` + '$doxod_ref1'
                                    WHERE username='".$refer["referer"]."'");

                                    if($refer1["referer"] != ""){

                                      $referer2 = mysql_query("SELECT * FROM `tb_users` WHERE `username` = '".$refer1["referer"]."'");
	                                  $refer2 = mysql_fetch_assoc($referer2);

	                                  $doxod_ref2 = $cena_click * ($st_users[$refer2["ball_status"]]["dox_ref2"]/100);

                                      mysql_query("UPDATE `tb_users`
                                      SET `referalvisits2` = `referalvisits2` + '1', `money` = `money` + '$doxod_ref2'
                                      WHERE `username` = '".$refer1["referer"]."'");

                                    }

                                  }

									mysql_query("UPDATE `tb_users` SET `visits`=`visits`+1, `doxod` = `doxod` + '$doxod_ref1' + '$doxod_ref2', `money`=`money`+'$cena_click' WHERE `username`='$username'") or die(mysql_error());

								}else{
									echo '<script>window.parent.frames["site"].location.replace("/");</script>';
								}
							}else{
								mysql_query("UPDATE `seelf_auto` SET `limit_now`=`limit_now`-1, `members`=`members`+1 WHERE `id`='$id' AND `status`='pay'") or die(mysql_error());
								mysql_query("INSERT INTO `seelf_auto_vis` (`username`, `type`, `ident`, `date`, `ip`, `money`) VALUES('$username', 'visit', '".$id."', '".time()."', '$laip', '$cena_click')") or die(mysql_error());

                                $referer = mysql_query("SELECT * FROM `tb_users` WHERE `username` = '$username'");
                                $refer = mysql_fetch_assoc($referer);

                                if($refer["referer"] != ""){

                                  $referer1 = mysql_query("SELECT * FROM `tb_users` WHERE `username` = '".$refer["referer"]."'");
                                  $refer1 = mysql_fetch_assoc($referer1);

                                  $doxod_ref1 = $cena_click * ($st_users[$refer1["ball_status"]]["dox_ref"]/100);

                                  mysql_query("UPDATE tb_users
                                  SET `referalvisits` = `referalvisits` + '1', `money` = `money` + '$doxod_ref1'
                                  WHERE username='".$refer["referer"]."'");

                                  if($refer1["referer"] != ""){

                                    $referer2 = mysql_query("SELECT * FROM `tb_users` WHERE `username` = '".$refer1["referer"]."'");
	                                $refer2 = mysql_fetch_assoc($referer2);

	                                $doxod_ref2 = $cena_click * ($st_users[$refer2["ball_status"]]["dox_ref2"]/100);

                                    mysql_query("UPDATE `tb_users`
                                    SET `referalvisits2` = `referalvisits2` + '1', `money` = `money` + '$doxod_ref2'
                                    WHERE `username` = '".$refer1["referer"]."'");

                                  }

                                }

								mysql_query("UPDATE `tb_users` SET `visits`=`visits`+1, `money`=`money`+'$cena_click' WHERE `username`='$username'") or die(mysql_error());

								echo '<script>window.parent.frames["site"].location.replace("/");</script>';
							}
						}else{
							unset($_SESSION["captcha_keystring"]);
							unset($_SESSION["hash1"]);
							unset($_SESSION["hash2"]);
							unset($_SESSION["codes"]);

							$sql_v = mysql_query("SELECT * FROM `seelf_auto_vis` WHERE `username`='$username' AND `type`='visit' AND `ident`='$id'") or die(mysql_error());
							if(mysql_num_rows($sql_v)>0) {
								mysql_query("UPDATE `seelf_auto_vis` SET `date`='".time()."', `ip`='$laip', `money`='0.0000' WHERE `username`='$username' AND `type`='visit' AND `ident`='$id'") or die(mysql_error());
							}else{
								mysql_query("INSERT INTO `seelf_auto_vis` (`username`, `type`, `ident`, `date`, `ip`, `money`) VALUES('$username', 'visit', '".$id."', '".time()."', '$laip', '0.0000')") or die(mysql_error());
							}
						}
					}else{
						$cena_click = round((($timer - $auto_timer_ot) * $cena_add_timer + $click),4);

						$sql_v = mysql_query("SELECT * FROM `seelf_auto_vis` WHERE `username`='$username' AND `type`='visit' AND `ident`='$id'") or die(mysql_error());
						if(mysql_num_rows($sql_v)>0) {
							$rowv = mysql_fetch_assoc($sql_v);

							$date_visit = $rowv["date"];
							$crok1 = time();
							$crok2 = ($date_visit + (24 * 60 * 60));

							if($crok1 >= $crok2) {
								mysql_query("UPDATE `seelf_auto` SET `limit_now`=`limit_now`-1, `members`=`members`+1 WHERE `id`='$id' AND `status`='pay'") or die(mysql_error());
								mysql_query("UPDATE `seelf_auto_vis` SET `date`='".time()."', `ip`='$laip', `money`='$cena_click' WHERE `username`='$username' AND `type`='visit' AND `ident`='$id'") or die(mysql_error());

                                $referer = mysql_query("SELECT * FROM `tb_users` WHERE `username` = '$username'");
                                $refer = mysql_fetch_assoc($referer);

                                if($refer["referer"] != ""){

                                  $referer1 = mysql_query("SELECT * FROM `tb_users` WHERE `username` = '".$refer["referer"]."'");
                                  $refer1 = mysql_fetch_assoc($referer1);

                                  $doxod_ref1 = $cena_click * ($st_users[$refer1["ball_status"]]["dox_ref"]/100);

                                  mysql_query("UPDATE tb_users
                                  SET `referalvisits` = `referalvisits` + '1', `money` = `money` + '$doxod_ref1'
                                  WHERE username='".$refer["referer"]."'");

                                  if($refer1["referer"] != ""){

                                    $referer2 = mysql_query("SELECT * FROM `tb_users` WHERE `username` = '".$refer1["referer"]."'");
	                                $refer2 = mysql_fetch_assoc($referer2);

	                                $doxod_ref2 = $cena_click * ($st_users[$refer2["ball_status"]]["dox_ref2"]/100);

                                    mysql_query("UPDATE `tb_users`
                                    SET `referalvisits2` = `referalvisits2` + '1', `money` = `money` + '$doxod_ref2'
                                    WHERE `username` = '".$refer1["referer"]."'");

                                  }

                                }

								mysql_query("UPDATE `tb_users` SET `visits`=`visits`+1, `money`=`money`+'$cena_click' WHERE `username`='$username'") or die(mysql_error());

							}else{
								echo '<script>window.parent.frames["site"].location.replace("/");</script>';
							}
						}else{
							mysql_query("UPDATE `seelf_auto` SET `limit_now`=`limit_now`-1, `members`=`members`+1 WHERE `id`='$id' AND `status`='pay'") or die(mysql_error());
							mysql_query("INSERT INTO `seelf_auto_vis` (`username`, `type`, `ident`, `date`, `ip`, `money`) VALUES('$username', 'visit', '".$id."', '".time()."', '$laip', '$cena_click')") or die(mysql_error());

                                $referer = mysql_query("SELECT * FROM `tb_users` WHERE `username` = '$username'");
                                $refer = mysql_fetch_assoc($referer);

                                if($refer["referer"] != ""){

                                  $referer1 = mysql_query("SELECT * FROM `tb_users` WHERE `username` = '".$refer["referer"]."'");
                                  $refer1 = mysql_fetch_assoc($referer1);

                                  $doxod_ref1 = $cena_click * ($st_users[$refer1["ball_status"]]["dox_ref"]/100);

                                  mysql_query("UPDATE tb_users
                                  SET `referalvisits` = `referalvisits` + '1', `money` = `money` + '$doxod_ref1'
                                  WHERE username='".$refer["referer"]."'");

                                  if($refer1["referer"] != ""){

                                    $referer2 = mysql_query("SELECT * FROM `tb_users` WHERE `username` = '".$refer1["referer"]."'");
	                                $refer2 = mysql_fetch_assoc($referer2);

	                                $doxod_ref2 = $cena_click * ($st_users[$refer2["ball_status"]]["dox_ref2"]/100);

                                    mysql_query("UPDATE `tb_users`
                                    SET `referalvisits2` = `referalvisits2` + '1', `money` = `money` + '$doxod_ref2'
                                    WHERE `username` = '".$refer1["referer"]."'");

                                  }

                                }

							mysql_query("UPDATE `tb_users` SET `visits`=`visits`+1, `money`=`money`+'$cena_click' WHERE `username`='$username'") or die(mysql_error());

							echo '<script>window.parent.frames["site"].location.replace("/");</script>';
						}
					}
				}else{
					mysql_query("UPDATE `seelf_auto` SET `status`='end' WHERE `id`='$id' AND `status`='pay'") or die(mysql_error());

					echo '<script>window.parent.frames["site"].location.replace("/");</script>';
				}
			}else{
				echo '<script>window.parent.frames["site"].location.replace("/");</script>';
			}
		}else{
			echo '<script>window.parent.frames["site"].location.replace("/");</script>';
		}
	}

	$sql = mysql_query("SELECT `id`, `timer`,  `url`, `description` FROM `seelf_auto` WHERE `status`='pay' AND `limit_now`>'0' AND `id` NOT IN (SELECT `ident` FROM `seelf_auto_vis` WHERE `username`='$username' AND `date`>='".(time()-24*60*60)."') ORDER BY `id` DESC");
	if(mysql_num_rows($sql)>0) {
		$row = mysql_fetch_assoc($sql);
		$id = $row["id"];
		$timer = $row["timer"];
		$url = $row["url"];
		$description = $row["description"];

		$cena_click = round((($timer - $auto_timer_ot) * $cena_add_timer + $click),4);
		$date_now = strtotime(DATE("d.m.Y"));

		$sql_pay = mysql_query("SELECT `id` FROM `seelf_auto_vis` WHERE `username`='$username' AND `type`='visit' AND `date`>'$date_now'") or die(mysql_error());
		$kolvo_s = mysql_num_rows($sql_pay);

            $sql_suma = mysql_query("SELECT sum(`money`) FROM `seelf_auto_vis` WHERE `username`='$username' AND `type`='visit' AND `date`>'$date_now'") or die(mysql_error());
            $suma_s = mysql_result($sql_suma,0,0);
		?>
		<script type="text/javascript" language="JavaScript">
			var counter=1+parseInt(<?php echo $timer;?>);
			var flag=0;

			function do_count(){
				<?php $_SESSION["endtmr_auto"] = ($timer + time());?>
				if(flag==0) {
					counter--;
					document.getElementById('begin').innerHTML='';
				}
				if(flag==1) {
					document.getElementById('begin').innerHTML='[Запустить таймер]';
				}

				if(counter>=0) {
					document.getElementById('tmr').innerHTML=''+counter+'';
					setTimeout("do_count()",1000);
				}
				if(counter<0){
					window.parent.frames['head'].location.replace("<?php echo $_SERVER['PHP_SELF'];?>?st=<?php echo $id;?>&cap=<?php echo $captcha;?>");
				}
			}
		</script>
		<table border="1" style="width: 100%; height: 72px; border-collapse: collapse; border: 1px solid #000; border-bottom:1px;" cellpadding="0" cellspacing="0">
		<tr>
		<th width="160" height="15px" align="center" bgcolor="#cccccc" style="border-bottom: 1 px solid #94FFB8;">Таймер</th>
		<th width="220" height="15px" align="center" bgcolor="#cccccc" style="border-bottom: 1 px solid; #94FFB8">Мини статистика</th>
		<th height="15px" align="center" bgcolor="#cccccc" style="border-bottom: 1 px solid; #94FFB8">Информация о рекламной компании</th>
		<th width="220" height="15px" align="center" bgcolor="#cccccc" style="border-bottom: 1 px solid; #94FFB8"></th>
		</tr>
		<tr>
		<td align="center" style="border-bottom: 1 px solid #94FFB8;">Ждите <span id="tmr" style="color: #FF0000;"></span> секунд <span id="begin" style="color: #ff0000;"></span><a href="start_auto.php?st=<?php echo $id;?>&amp;b=1" onmouseover="window.status=''; return true" onmouseout="window.status=''; return false">Заблокировать ссылку</a></td>
		<td style="font-size: 80%; padding: 0 5px; 0 5px;"> Стоимость просмотра: <b style="color: #000;"><?php echo $cena_click;?></b> руб.<br>Просмотрено ссылок сегодня: <b style="color: #000;"><?php echo $kolvo_s;?></b><BR> Заработано сегодня: <b><? echo $suma_s;?> руб. </b> </td>
		<td style="font-size: 80%; padding: 0 5px; 0 5px;"> <b>Описание:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $description;?><br><b>Адрес сайта:</b>&nbsp;&nbsp;<a href="<?php echo $row["url"];?>" target="_blank"><?php echo $url;?></a></td>
		<td style="font-size: 80%; padding: 0 5px; 0 5px;"><center>

<!--LiveInternet counter--><script type="text/javascript"><!--
document.write("<a href='http://www.liveinternet.ru/click' "+
"target=_blank><img src='//counter.yadro.ru/hit?t14.6;r"+
escape(document.referrer)+((typeof(screen)=="undefined")?"":
";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?
screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+
";"+Math.random()+
"' alt='' title='LiveInternet: показано число просмотров за 24"+
" часа, посетителей за 24 часа и за сегодня' "+
"border='0' width='88' height='31'><\/a>")
//--></script><!--/LiveInternet-->

          </center>
           </td>
		</tr>
		</table>
		<script type="text/javascript" language="JavaScript">
		  window.parent.document.title="<?php echo $_SERVER["HTTP_HOST"];?> >> Автоматический серфинг >> <?php echo $description;?>";
		  window.parent.frames['site'].location.replace("<?php echo $url;?>");
		  window.parent.frames['head'].onblur = new Function('this.flag = 1;');
		  window.parent.frames['head'].onfocus = new Function('this.flag = 0;');
		</script>
		<?php
	}else{
		echo '<script type="text/javascript" language="JavaScript">window.parent.frames["site"].location.replace("end.php");</script>';
	}
}else{
echo '<br><center><b style="color: #FF0000;">Ошибка! Для просмотра ссылок в авто-серфинге необходимо авторизоваться.</b></center>';
echo '<script type="text/javascript" language="JavaScript">window.parent.frames["site"].location.replace("end.php");</script>';
}
?>
</body>
</html>