<?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;\"> <img src=\"frmimg/error.png\" align='top'> Ошибка! Просмотр не засчитан</span>";
exit();
}

if(isset($_SESSION["iduser"])){

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

$captcha = md5(strtolower($_POST['code']));
$ver = strtolower($_SESSION["texto"]);

if(!isset($_GET["ds"])){
$ad_exist = mysql_num_rows(mysql_query("SELECT * FROM `tb_ads_p` WHERE `id`='$adse' AND `paused`<>'1' AND `modered`='1'"));

if($ad_exist < 1){
echo "<span style=\"color: #ff0000;\"> <img src=\"frmimg/error.png\" align='top'> Ссылка не существует</span>";
exit();
}
?>	
<form action='photo_hunter_wives_1.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>
</tr></table>
</td></tr></table>	
<?PHP
exit();
}

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

$sql = mysql_query("SELECT `data` FROM `tb_visits_1` WHERE `idus` = '".$_SESSION["iduser"]."' AND `ident`= '$adse'") or die(mysql_error());  
if(mysql_num_rows($sql) > 0){
$row = mysql_fetch_assoc($sql);
$time = $row["data"];
}else{ $time = 0;}
$crok1 = date(time());
$crok2 = date($time + 86400);

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

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

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

if ($referer_visit > 0){
mysql_query("UPDATE `tb_visits_1` SET `data`='$crok1' WHERE `idus`= '".$_SESSION["iduser"]."' AND `ident`='$adse'") or die(mysql_error());
}else{
mysql_query("INSERT INTO `tb_visits_1` (`idus`,`ident`,`data`) VALUES( '".$_SESSION["iduser"]."','$adse','$crok1')") or die(mysql_error());
}

mysql_query("UPDATE `tb_ads_p` SET `plan`=`plan`+'1',`balance`=`balance`-'".$myrowz["price"]."' WHERE `id`='$adse'");	

require_once('moneyfortimer.php');
if($_SESSION["timer"]==20) $oplata = $payfor20;
if($_SESSION["timer"]==30) $oplata = $payfor30;
if($_SESSION["timer"]==40) $oplata = $payfor40;
if($_SESSION["timer"]==50) $oplata = $payfor50;
if($_SESSION["timer"]==60) $oplata = $payfor60;

$referer = mysql_result(mysql_query("SELECT `referer` FROM `b_users` WHERE `username`='$user'"),0,0);
$pol = $_SESSION["iduser"];

mysql_query("UPDATE `b_users` SET `photo`=`photo`+'1', `money`=`money`+'0.07' WHERE `id`='$pol'");	
	
	
$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`='3'");

//Конкурс баллы
$sql = mysql_query("SELECT `username` FROM `b_users` WHERE `id`='".$_SESSION["iduser"]."'");
if(mysql_num_rows($sql) > 0){
$res = mysql_fetch_assoc($sql);
mysql_query("INSERT INTO `b_comp_day` (`user`,`count`,`type`,`data`) VALUES ('".$_SESSION["iduser"]."','1','3','".time()."')") or die(mysql_error());
}
//Конкурс баллы

if($refback > 0) {$opl_rb =  " + ".$refback.$sitevalname;}
echo "<span style=\"color: #00dd00;\">&nbsp;<img src=\"frmimg/ok.png\" align='top'> Вам зачислено <b>{$oplata}{$sitevalname}{$opl_rb}</b></span>";
?>

<?
}else{
echo "<span style=\"color: #ff0000;\">&nbsp;<img src=\"frmimg/error.png\" align='top'> Вы уже просматривали эту ссылку!</span>";
}
}else{
echo "<span style=\"color: #ff0000;\">&nbsp;<img src=\"frmimg/error.png\" align='top'> Ошибка! Просмотр не засчитан</span>";
}?>
<script type="text/javascript">
window.top.location.replace("ok.php");
</script> <?
}else{
echo "<span style=\"color: #ff0000;\"><img src=\"frmimg/error.png\" align='top'> Вам необходимо авторизоваться</span>";
}
?>