<?
### Версия ПО (ДМ) 1.0.0.0 ( (c)2018 MISOFT Продукт защищен регистрацией патента и авторских прав! www.misoft.studio )
######################################################################################################################

  session_start();
  if ( !isset( $_SESSION['iduser'] ) ) exit();
  ///if ( $_SERVER['HTTP_REFERER'] != 'https://'.$config_site['site_url'].'/serfing' ) exit();
  define( 'MISOFT', true );
  define( 'ROOT_DIR', $_SERVER['DOCUMENT_ROOT'] );
  include_once ROOT_DIR . '/engine/config.php';
  include_once ROOT_DIR . '/engine/function.php';

  if ( !$config_user['activate'] ) {
    echo '<div class="error" style="width: 90%; margin: 10px auto; text-align: center">Для продолжения, Вам необходимо активировать свой аккаунт.<br /><a href="https://'.$config_site['site_url'].'/profile" class="a_box" >перейти в аккаунт</a></div>';
    exit();
  }

  #Определяем страну 
  $regcode = find_country();

  $get_serf = mysql_query( "SELECT * FROM dynlink t1  WHERE t1.paused = 1 and t1.id = '" . ( int ) $_GET['id'] . "' and NOT EXISTS ( SELECT ident FROM dynlink_temp t2 WHERE t1.id = t2.ident and t2.iduser = '" . $_SESSION['iduser'] . "' ) and id IN (SELECT id FROM dynlink WHERE geo_ru = '".$regcode."' OR geo_ua = '".$regcode."' OR geo_by = '".$regcode."' OR geo_kz = '".$regcode."' OR geo_ge = '".$regcode."' OR geo_md = '".$regcode."' OR geo_am = '".$regcode."' OR geo_tj = '".$regcode."' OR geo_az = '".$regcode."' OR geo_uz = '".$regcode."' OR geo_pt = '".$regcode."' OR geo_es = '".$regcode."' OR geo_ee = '".$regcode."' OR geo_lv = '".$regcode."' OR geo_lt = '".$regcode."' OR geo_us = '".$regcode."' OR geo_gb = '".$regcode."' OR geo_fr = '".$regcode."' OR geo_de = '".$regcode."' OR geo_cn = '".$regcode."' OR geo_it = '".$regcode."' OR geo_all = '".$regcode."') LIMIT 1" );

  if ( mysql_num_rows( $get_serf ) < 1 ) {
    exit();
  } else {

  $get_serf_row = mysql_fetch_array( $get_serf );

  #если стоит функция только для свободных рефералов
  if ( $get_serf_row['freeid'] and $config_user['referer'] != 0 ) exit();

  #Проверяем на разрушение фрейма
  $getframe = check_frame( $get_serf_row['url'] );
  if ( $getframe == 'no' ) {
    $dyn_url = '';
  } else {
    $dyn_url = $get_serf_row['url'];
  }

  switch ( $get_serf_row['timer'] ) {
    case 0: $serf_timer = '10'; $stymer = $config['dyn10']; break;
    case 1: $serf_timer = '20'; $stymer = $config['dyn20']; break;
    case 2: $serf_timer = '30'; $stymer = $config['dyn30']; break;
    case 3: $serf_timer = '40'; $stymer = $config['dyn40']; break;
    case 4: $serf_timer = '50'; $stymer = $config['dyn50']; break;
    case 5: $serf_timer = '60'; $stymer = $config['dyn60']; break;
    case 6: $serf_timer = '70'; $stymer = $config['dyn70']; break;
    case 7: $serf_timer = '80'; $stymer = $config['dyn80']; break;
    case 8: $serf_timer = '90'; $stymer = $config['dyn90']; break;
    case 9: $serf_timer = '100'; $stymer = $config['dyn100']; break;
    case 10: $serf_timer = '125'; $stymer = $config['dyn125']; break;
    case 11: $serf_timer = '150'; $stymer = $config['dyn150']; break;
    case 12: $serf_timer = '200'; $stymer = $config['dyn200']; break;
    case 13: $serf_timer = '250'; $stymer = $config['dyn250']; break;
    case 14: $serf_timer = '300'; $stymer = $config['dyn300']; break;
  }

  if ( $get_serf_row['balance'] < $get_serf_row['obper'] * $config['obper'] + $get_serf_row['active_window'] * $config['active_window'] + $get_serf_row['vip'] * $config['vipdyn'] + $stymer and $get_serf_row['testdrive'] == 0 ) {
    exit();
  }

  #Запрещаем просмотр серфинга в несколько окон
  function dynurl () {
    if ( strpos( $_SERVER['REQUEST_URI'], 'standard' ) == 1 ) {
	  if ( $_SESSION['timer_serf'] > time() ) {
		exit();
	  }
    }
  }

  dynurl();

  ### Captha RLD 1.1 (release - misoft 2018.06.17)
  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);

  unset($_SESSION["captcha_keystring"]);
  unset($_SESSION["codes"]);

  $_SESSION["captcha_keystring"] = $codes1[$rnd_nomer];
  $_SESSION["codes"] = $codes2[$rnd_nomer];

  $ans_id = rand(5, 15);
  $ans_id1 = rand(1, 150);

  ?>
	<!DOCTYPE html>
	<html>
	  <head>
		<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
		<title><?=$config_site['sitename']?> - система раскрутки сайтов</title>
		<link rel="icon" href="https://<?=$config_site['site_url']?>/favicon.ico" type="image/x-icon" />
		<link rel="shortcut icon" href="https://<?=$config_site['site_url']?>/favicon.ico" type="image/x-icon" />
		<link media="all" type="text/css" rel="stylesheet" href="https://<?=$config_site['site_url']?>/theme/css/style.css" />
		<link href="https://<?=$config_site['site_url']?>/dist/css/bootstrap.css" rel="stylesheet">
		<link rel="stylesheet" href="/font-awesome/css/font-awesome.min.css">
		<script type="text/javascript" src="https://<?=$config_site['site_url']?>/dist/js/bootstrap.js"></script>
		<script type="text/javascript" src="https://<?=$config_site['site_url']?>/theme/js/jquery.js"></script>
		<script type="text/javascript">
		  ///высота браузера
		  function windowHeight() {
			return document.compatMode=='CSS1Compat'?document.documentElement.clientHeight:document.body.clientHeight;
		  }

		  $(document).ready(function() {
			$('#framesite').css({height: windowHeight () - 78});
		  });

		  var tm, act;
		  var t = <?=$serf_timer?>;
		  var tg = -0;
		  var tgs = 100/<?=$serf_timer?>;
		  var window_active = <?=$get_serf_row['active_window']?>;
		  clearInterval(tm);
		  var active = false, inactive = false;
		  $(window).focus(function(){active = false}).blur(function(){active = true});
		  function iframe_time() {
			if (t > 0) {
			  if ( window_active == 1 ) {
				if ( navigator.userAgent.indexOf('Opera') != -1 ) {
				  inactive = ((typeof window.hasFocus != 'undefined' ? window.hasFocus() : active) ? true : false);
				} else {
				  if(document.hasFocus()) {
					inactive = false;
					active = false;
				  } else {
					inactive = true;
					active = true;
				  }
				}
				
				if ( !inactive ) {
				  active = false;
				}
				
				if ( active == true ) {
				  $('#timer').html('Таймер не активен!  <button type="button" class="btn btn-warning btn-sm">активировать</button>').addClass('t_active');
				  return;
				}
			  }
			  t--;
			  tg++;
			  var tge = tg*tgs;
			
			  $('#timer').html('<div class="frameoptomizator"><div  class="progress" style="width: 200px; height: 10px;"><div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="'+tg+'" aria-valuemin="0" aria-valuemax="<?=$serf_timer?>" style="width: '+tge+'%;" ></div></div><div class="framefix">ждем <b>'+t+' </b>секунд</div></div>').addClass('t_active');
			} else
			if (t == 0) {
			  clearInterval(tm);
			  $('#timer').html('').removeClass('t_active');
			  $('#timer').fadeOut();
			  $('#capcha').fadeIn();
			}
		  }

		  function start_time() {
			act = setInterval('onactive()', 1000);
		  }

		  function onactive() {
			if (window_active == 1) {
			  if ( navigator.userAgent.indexOf('Opera') != -1 ) {
				inactive = ((typeof window.hasFocus != 'undefined' ? window.hasFocus() : active) ? true : false);
			  } else {
				if(document.hasFocus()) {
				  inactive = false;
				  active = false;
				} else {
				  inactive = true;
				  active = true;
				}
			  }
				
			  if ( !inactive ) {
				clearInterval(act);
				tm = setInterval('iframe_time();', 1000);
				<? unset( $_SESSION['timer_serf'] ); $_SESSION['timer_serf'] = time() + $serf_timer; ?>
			  }
			} else {
			  clearInterval(act);
			  tm = setInterval('iframe_time();', 1000);
			 <? unset( $_SESSION['timer_serf'] ); $_SESSION['timer_serf'] = time() + $serf_timer; ?>
			}
		  }

		  function serf_ok0() {
			$.post('ajax_update.php?func=serf_ok', {
			  id: <?=( int ) $_GET['id']?>,
			  answer : $('#answer<?=$ans_id?>_0').val(),
			  num : $('#num<?=$ans_id1?>_0').val()
			}, function(data) {
			  if (data.ok == 1) {
				$('#capcha').fadeOut();
				$('#timer').fadeIn();
				$('#timer').html(data.text);
			  } else {
				window.location.href = '<?=$get_serf_row['url']?>';
			  }
			}, 'json');
			return false;
		  }

		  function serf_ok1() {
			$.post('ajax_update.php?func=serf_ok', {
			  id: <?=( int ) $_GET['id']?>,
			  answer : $('#answer<?=$ans_id?>_1').val(),
			  num : $('#num<?=$ans_id1?>_1').val()
			}, function(data) {
			  if (data.ok == 1) {
				$('#capcha').fadeOut();
				$('#timer').fadeIn();
				$('#timer').html(data.text);
			  } else {
				window.location.href = '<?=$get_serf_row['url']?>';
			  }
			}, 'json');
			return false;
		  }

		  function serf_ok2() {
			$.post('ajax_update.php?func=serf_ok', {
			  id: <?=( int ) $_GET['id']?>,
			  answer : $('#answer<?=$ans_id?>_2').val(),
			  num : $('#num<?=$ans_id1?>_2').val()
			}, function(data) {
			  if (data.ok == 1) {
				$('#capcha').fadeOut();
				$('#timer').fadeIn();
				$('#timer').html(data.text);
			  } else {
				window.location.href = '<?=$get_serf_row['url']?>';
			  }
			}, 'json');
			return false;
		  }

		  function serf_ok3() {
			$.post('ajax_update.php?func=serf_ok', {
			  id: <?=( int ) $_GET['id']?>,
			  answer : $('#answer<?=$ans_id?>_3').val(),
			  num : $('#num<?=$ans_id1?>_3').val()
			}, function(data) {
			  if (data.ok == 1) {
				$('#capcha').fadeOut();
				$('#timer').fadeIn();
				$('#timer').html(data.text);
			  } else {
				window.location.href = '<?=$get_serf_row['url']?>';
			  }
			}, 'json');
			return false;
		  }

		  function serf_ok4() {
			$.post('ajax_update.php?func=serf_ok', {
			  id: <?=( int ) $_GET['id']?>,
			  answer : $('#answer<?=$ans_id?>_4').val(),
			  num : $('#num<?=$ans_id1?>_4').val()
			}, function(data) {
			  if (data.ok == 1) {
				$('#capcha').fadeOut();
				$('#timer').fadeIn();
				$('#timer').html(data.text);
			  } else {
				window.location.href = '<?=$get_serf_row['url']?>';
			  }
			}, 'json');
			return false;
		  }
		</script>
      </head>
	  <style type="text/css">
		body {
		  padding: 0px;
		  margin: 0px;
		  height: 100%;
		  overflow: hidden;
		}
		#timer {
		  position: relative;
		  height: 60px;
		  width: 300px;
		  padding-left: 40px;
		  padding-top: 9px;
		  display: inline-block;
		  line-height: 60px;
		  font-size: 14px;
		}
	  </style>
	  <body onload="start_time();">
		<iframe src="<?=$dyn_url?>" width="100%" id="framesite" frameborder="0" scrolling="yes" name="framesite"></iframe>
		<div class="serf_top_panel">
		  <div id="timer" style="display: ;"><i class="fa fa-spinner fa-spin" aria-hidden="true"></i> Подождите, сайт загружается...</div>
		  <table border="0" cellpadding="0" cellspacing="0" id="capcha" class="iframe_table_captha">
			<tr>
			  <td rowspan="2" style="padding-right: 15px;">
				<img src="/engine/captha/serf_captha/?<?=session_name()?>=<?=session_id()?>" id="captcha-image" align="middle" alt="" class="image_serf_captha" onclick="document.getElementById('captcha-image').src = '/engine/captha/serf_captha/?<?=session_name()?>=<?=session_id()?>)?rid=' + Math.random();" />&nbsp;
				
			  </td>
			  <td colspan="5">
				<span style="color: #444; font-family: Verdana; font-size: 13px;">Выберите правильный вариант:</span>
			  </td>
			</tr>
			<tr>
			  <? $k_num=0;
			   foreach($codes1 as $c): ?>
			    <? echo '<td>
				<input type="hidden" id="answer'.$ans_id.'_'.$k_num.'" value="'.$c.'">
				<input type="hidden" id="num'.$ans_id1.'_'.$k_num.'" value="'.md5($codes2["$k_num"]).'">
				<input type="submit" onclick="serf_ok'.$k_num.'();return false" value="'.$c.'" class="btn btn-secondary btn-sm" style="margin-right: 1px;">
			    </td>';
			    $k_num++;
			   endforeach;
			  ?>
			</tr>
		  </table>
		  <div style="position: absolute; right: 50px; top: 8px;"><? include_once ROOT_DIR . '/engine/banner/rotator.php';?></div>
		</div>
	  </body>
	</html>
<? } ?>