<?php
session_start();
define('FastCore',true);
define('TIME', time());
define('BASE_DIR', $_SERVER['DOCUMENT_ROOT']);
function get_codek_ckick($dek) {
$codek[1] = array(1 => '2', 2 => '6', 3 => '3', 4 => '4', 5 => '5', 6 => '1', 7 => '7', 8 => '8');
$codek[2] = array(1 => '3', 2 => '2', 3 => '8', 4 => '4', 5 => '5', 6 => '7', 7 => '6', 8 => '1');
$codek[3] = array(1 => '8', 2 => '2', 3 => '4', 4 => '7', 5 => '5', 6 => '6', 7 => '3', 8 => '1');
if (isset($codek[$dek])) return $codek[$dek];
return false;
}
if (!isset($_SESSION['uid'])) { exit('1'); }
if (isset($_POST['cnt']) && isset($_POST['num']) && isset($_SESSION['view']) && $_POST['cnt'] == $_SESSION['view']['cnt'])
{
$num = (int)$_POST['num'];
if ($num)
{
$minus = TIME - $_SESSION['view']['timestart'];
if ($minus < $_SESSION['view']['timer']) exit('2');
$codek = get_codek_ckick($_SESSION['view']['codek_click']);
foreach ($codek as $k => $v)
{
if ($v == $num)
{
$num = $k;
break;
}
}
if ($num == $_SESSION['view']['captcha']) {
# Система
spl_autoload_register(function ($lfc) {
require_once (BASE_DIR.'/core/'.$lfc.'.php');
});
# Класс конфига
$config = new config;
$func = new func;
$time = time();
# Удаляем клик за 24/12 часа если время прошло
//$db->query("DELETE FROM db_surfv_click WHERE id = '".$_SESSION['view']['id']."' AND time_end > '".time()."'");
# Ищем пользователя
$usid = $_SESSION['uid'];
$user_info = $db->query("SELECT * FROM `db_users` WHERE id = ?",$usid)->fetchArray();
$rid = $user_info['rid'];
$num_rows = $db->query("SELECT * FROM db_surfv WHERE id = '".$_SESSION['view']['id']."' and balance >= price_click AND status = '1' LIMIT 1")->numRows();
if ($num_rows > 0) {
$num24 = $db->query('SELECT link, time_end FROM db_surfv_views WHERE link = '.$_SESSION['view']['id'].' AND uid = '.$_SESSION['uid'].' AND time_end > '.$time.'')->numRows();
if ($num24 >= 1) exit('<div class="blockerror">Повторный просмотр пока не доступен!</div>');
$result = $db->query("SELECT * FROM db_surfv WHERE id = '".$_SESSION['view']['id']."' and balance >= price_click LIMIT 1")->fetchArray();
$move = $result['url'];
$id = $result['id'];
if ($id != $_SESSION['view']['id']) exit('<div class="blockerror">ERROR!!!</div>');
$params = $db->query("SELECT * FROM db_surfv WHERE id = '".$id."' LIMIT 1")->fetchArray();
$timend = time()+60*60*$params['reply'];
# Цена
$price = $result['price_click'];
$price = number_format($price,6); // спишет
$payUser = $result['per_click'];
$payUser = number_format($payUser,6); // начислит
$payRef = number_format(0.000200,6);
$adEarn = $price-$payUser;
# Записываем что просмотрена ссылка
$num_rows_click = $db->query("SELECT id, link FROM db_surfv_views WHERE uid = '".$_SESSION['uid']."' and link = '".$id."' LIMIT 1")->numRows();
if ($num_rows_click >= 1)
{
$db->query("INSERT INTO db_surfv_views (`link`, `time_add`,`time_end`, `uid`) VALUES (?,?,?,?)",array($id,$time,$timend, $_SESSION['uid']));
}
else
{
$db->query("INSERT INTO db_surfv_views (`link`, `time_add`,`time_end`, `uid`) VALUES (?,?,?,?)",array($id,$time,$timend,$_SESSION['uid']));
}
# Обновляем пользователя
$db->query('UPDATE db_users SET `surf_view` = `surf_view` + 1, `money_p` = `money_p` + ?, `surf_earn` = `surf_earn` + ? WHERE id = ?', array($payUser, $payUser, $usid));
# Обновляем рефовода
$db->query('UPDATE db_users SET money_p = money_p + '.$payRef.', income = income + '.$payRef.', ref_views = ref_views + 1 WHERE id = '.$rid.'');
# Обноляем площадку
$db->query('UPDATE db_surfv SET views = views +1, balance = balance -'.$price.' WHERE id = '.$id.'');
# Пишем в статистику
$db->query("UPDATE `db_stats` SET `views` = `views` + 1 WHERE `id` = '1'");
/* LogStats */
$cDate = date("Ymd",time());
$dateNow = strtotime($cDate." 00:00:00");
$dateEnd = strtotime($cDate." 23:59:59");
$db->query('SELECT * FROM db_logstat WHERE date_add >= '.$dateNow.' AND date_add <= '.$dateEnd.' ORDER BY id DESC LIMIT 1');
if ($db->numRows() == 0) {
$db->query('INSERT INTO db_logstat (date_add) VALUES (?)', array($dateNow));
}
else {
$db->query('UPDATE db_logstat SET surf_view = surf_view + 1, surf_earn = surf_earn + '.$payUser.', surf_adm = surf_adm +'.$adEarn.' WHERE date_add >= '.$dateNow.'');
}
/* end LogStats */
// Успешный просмотр, удаляем сессию
unset($_SESSION['view']);
exit('OK;'.$payUser.';'.$move.'');
}
else
{
exit(3);
}
}
else
{
exit('<div class="blockerror">Ошибка!<br /><span>Неверно решена задача!</span></div>');
}
}
else if ($num == 0)
{
$codek_new = rand(1, 3);
$_SESSION['view']['codek_click'] = $codek_new;
$codek = get_codek_ckick($codek_new);
$rand = rand(1000000, 9999999);
?>
<div class="clocktable">
<div class="captcha-img"><img src="/assets/captcha/captcha-st/captcha.php?sid=<?php echo $rand; ?>" alt="Капча..."></div>
<div class="captcha-code" nowrap="nowrap">
<?php
for($n = 1; $n<=8; $n++)
{
if ($n == 5) echo '<br />';
?>
<span class="serfnum" onclick="vernum(<?php echo $codek[$n] ?>);"><?php echo $n; ?></span>
<?php
}
?>
</div>
</div>
<?php
}
else { exit('4'); }
}
else { exit('5'); }
?>