<?PHP
session_start();
?>
<style type="text/css" media="all">
.captcha {
   margin-left: 1px;
   position: relative;
   top: 10px;
   vertical-align: bottom;
}
.captcha font{
   font-family:arial;
   font-weight: bold;
   color:#2cbde9;
   font-size:14px;
}

.capfont{
   font-family:arial;
   font-weight: bold;
   color:#2cbde9;
   font-size:14px;
}

input.regnum {
background-color: #ea4b4b;
border: medium none;
color: #ffffff;
cursor: pointer;
display: inline-block;
font: 12px Tahoma,Arial,sans-serif;
margin: 1px;
outline: medium none;
padding: 0 0 2px;
text-align: center;
text-decoration: none;
text-shadow: 0 0 2px #fff;
vertical-align: middle;
width: 25px;
}

input.regnum:hover {
    background-position: left bottom;
}
.tbl {
background: none repeat scroll 0 0 #6d74a4;
padding: 5px;
width: 100%;
}
span {
background:#fff;padding:7px 17px;border-radius:8px;
-webkit-box-shadow: 0 0 2px 2px rgba(120, 180, 94, 0.5) inset;
box-shadow: 0 0 2px 2px rgba(120, 180, 94, 0.5) inset;
}
</style>
<?PHP

if($_SESSION["endtime"]>time()){
echo "<span style=\"color: #ff0000;\">&nbsp;<img src=\"frmimg/error.png\" align='top'> Ошибка! Просмотр не засчитан</span>";
exit();
}
if(isset($_SESSION["iduser"])){

if(isset($_SESSION['ad'])) {
$adse = (isset($_SESSION["ad"]) && preg_match("|^[\d]{1,11}$|", trim($_SESSION["ad"]))) ? intval(trim($_SESSION["ad"])) : false;
}else{
echo "<span style=\"color: #ff0000;\">&nbsp;<img src=\"frmimg/error.png\" align='top'> Ошибка! Просмотр не засчитан</span>";
exit();
}

$captcha = md5(strtolower(strip_tags(stripslashes($_POST['code']))));
$ver = strtolower(strip_tags(stripslashes($_SESSION["texto"])));
	
if(!isset($_GET["ds"])){
$ad_exist = mysql_num_rows(mysql_query("SELECT `id` FROM `seo_paymails` WHERE `id`='$adse' AND `paused`<>'1' AND `modered`='1'"));

if ($ad_exist < 1){
echo "<span style=\"color: #ff0000;\">&nbsp;<img src=\"frmimg/error.png\" align='top'> Ссылка не существует</span>";
exit();
}
?>
<form action='vlsmail.php?view=ok&ds=clicked' method='post'>
<table class="tbl" cellpadding="0" cellspacing="0" align="center"><tr>
<td align="center">
<img src="image.php" class="imgcap" /></td>
<td width="10px"></td>
<td>
<input type="hidden" name="code" value="0">
<input class="regnum" name="code" value="1" onclick="vernum(this.form,1); submit();" type="submit">
<input class="regnum" name="code" value="2" onclick="vernum(this.form,2); submit();" type="submit">
<input class="regnum" name="code" value="3" onclick="vernum(this.form,3); submit();" type="submit">
<input class="regnum" name="code" value="4" onclick="vernum(this.form,4); submit();" type="submit"><br />
<input class="regnum" name="code" value="5" onclick="vernum(this.form,5); submit();" type="submit">
<input class="regnum" name="code" value="6" onclick="vernum(this.form,6); submit();" type="submit">
<input class="regnum" name="code" value="7" onclick="vernum(this.form,7); submit();" type="submit">
<input class="regnum" name="code" value="8" onclick="vernum(this.form,8); submit();" type="submit"></td>
</tr></table>
</form>
</td>
<td align="right" style="padding:0 30px 17px 0;"><? include('inc/rotator.php'); ?></td>
</tr></table>
</td></tr></table>		
<?
exit();
}
if(!isset($_GET["ds"]) OR ($_GET["ds"] == 'clicked' AND $ver == $captcha)){
$adse = (isset($_SESSION["ad"]) && preg_match("|^[\d]{1,11}$|", trim($_SESSION["ad"]))) ? intval(trim($_SESSION["ad"])) : false;

$sql = mysql_query("SELECT `time` FROM `seo_paymailsviews` WHERE `fromid` = '".$_SESSION["iduser"]."' AND `ident`= '$adse'") or die(mysql_error());
if(mysql_num_rows($sql) > 0){
$row = mysql_fetch_assoc($sql);
$time = $row["time"];
}else{ $time = 0;}

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

if($crok1 >= $crok2){
$referer_visit = mysql_num_rows(mysql_query("SELECT * FROM `seo_paymailsviews` WHERE `fromid`='".$_SESSION["iduser"]."' AND `ident`='$adse'"));

$resultz = mysql_query("SELECT `balance`, `price` FROM seo_paymails WHERE id='$adse'");        
$myrowz = mysql_fetch_array($resultz);
$numero = intval($myrowz["balance"]/$myrowz["price"]);

if($numero == 0){
echo "<span style=\"color: #ff0000;\"> <img src=\"frmimg/error.png\" align='top'> Ссылка не существует</span>";
exit();
}

if($referer_visit > 0){
mysql_query("UPDATE `seo_paymailsviews` SET `time`='$crok1' WHERE `fromid`='".$_SESSION["iduser"]."' AND `ident`='$adse'") or die(mysql_error());
}else{
mysql_query("INSERT INTO `seo_paymailsviews` (`fromid`,`ident`,`time`) VALUES('".$_SESSION["iduser"]."','$adse','$crok1')") or die(mysql_error());
}
			
mysql_query("UPDATE `seo_paymails` SET `plan`=`plan`+'1',`balance`=`balance`-'".$myrowz["price"]."' WHERE `id`='$adse'");

$elprecio = mysql_result(mysql_query("SELECT price FROM tb_config WHERE item='mpay'"),0);

$resultze = mysql_query("SELECT `referer`, `visits`, `money` FROM `b_users` WHERE `id`='".$_SESSION["iduser"]."'") or die(mysql_error());     
$myrowze = mysql_fetch_assoc($resultze);
if($myrowze["referer"] > 0){
$ref_reyt = mysql_result(mysql_query("SELECT `reyting` FROM `b_users` WHERE `id`='".$myrowze["referer"]."'"),0,0);
$pl_r_r1 = user_status($ref_reyt,3);
$refelprecio = $elprecio*$pl_r_r1/100;
mysql_query("UPDATE `b_users` SET `money`=`money`+'$refelprecio' WHERE `id`='".$myrowze["referer"]."'") or die(mysql_error());
if($referer2 > 0){
$ref2_reyt = mysql_result(mysql_query("SELECT `reyting` FROM `b_users` WHERE `id`='$referer2'"),0,0);
$pl_r_r2 = user_status($ref2_reyt,3);
$pay_r2 = $elprecio*ref_ot2($pl_r_r2)/100;
mysql_query("UPDATE `b_users` SET `money`=`money`+'$pay_r2' WHERE `id`='$referer2'");
}
#общий конкурс от реферера
$sql_cr = mysql_query("SELECT `id` FROM `b_ref_comp` WHERE `status`='1' AND `id_user`='".$myrowze["referer"]."' AND `start_comp`<='".time()."' AND `type`='4'") or die(mysql_error());
if(mysql_num_rows($sql_cr) > 0){
$row_cr = mysql_fetch_assoc($sql_cr);
mysql_query("INSERT INTO `b_ref_comp_data` SET `id_comp`='".$row_cr["id"]."', `id_user`='".$_SESSION["iduser"]."', `count`='2', `time`='".time()."' ON DUPLICATE KEY UPDATE `count`=`count`+'2'") or die(mysql_error());
}
#общий конкурс от реферера
}else{$refelprecio = 0;}

mysql_query("UPDATE `b_users` SET `visits`=`visits`+'1', `money`=`money`+'$elprecio', `toref`=`toref`+'$refelprecio', `reyting`=`reyting`+'$b_mails' WHERE `id`='".$_SESSION["iduser"]."'") or die(mysql_error());
	
$varstr = date("w");
$day = NULL;
if($varstr==1) $day = 'mon';
if($varstr==2) $day = 'tue';
if($varstr==3) $day = 'wed';
if($varstr==4) $day = 'thu';
if($varstr==5) $day = 'fri';
if($varstr==6) $day = 'sat';
if($varstr==0) $day = 'sun';

mysql_query("UPDATE `b_statistic` SET `total`=`total`+'1', `".$day."`=`".$day."`+'1' WHERE `user_id`='".$_SESSION["iduser"]."' AND `typ`='2'") or die(mysql_error());
echo "<span style=\"color: #00dd00;\"><img src=\"frmimg/ok.png\" align='top'> Вам зачислено $elprecio $sitevalname</span>";
}else{
echo "<span style=\"color: #ff0000;\"><img src=\"frmimg/error.png\" align='top'> Вы уже просматривали эту ссылку!</span>";
}
}else{
echo "<span style=\"color: #ff0000;\">;<img src=\"frmimg/error.png\" align='top'> Ошибка! Просмотр не засчитан</span>";
}
$obper=mysql_result(mysql_query("SELECT `obper` FROM `seo_paymails` WHERE `id`='$adse'"),0,0);
if($obper == 1){
?>
<script type="text/javascript">
alert('Рекламодатель пожелал принудительный переход на сайт после просмотра!');
window.top.location.replace("<?=$_SESSION["urlsite"]; ?>");
</script>
<?PHP
}
}else{
echo "<span style=\"color: #ff0000;\"> <img src=\"frmimg/error.png\" align='top'> Вам необходимо авторизоваться</span>";
}
?>