<?PHP
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php'); //единственное подключение к бд!о закрытии соединения можно забыть аш до самого футера до тега </html>
$nowdate = date('d.m.Y'); //задаём дату
$nowtime = date(time()); //задаём время
require_once($_SERVER['DOCUMENT_ROOT'].'/funciones.php');//подключаем функции
require_once($_SERVER['DOCUMENT_ROOT'].'/blocks/inf.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/sfbstat.php');

$id_user = (isset($_SESSION["iduser"]) && preg_match("|^[\d]{1,11}$|", trim($_SESSION["iduser"]))) ? intval(trim($_SESSION["iduser"])) : false;
$referer = mysql_num_rows(mysql_query("SELECT `referer` FROM `b_users` WHERE `id` = '$id_user'"));
$skid = mysql_result(mysql_query("SELECT `skidka` FROM `b_users` WHERE `id`='$id_user'"),0,0);
if($lastupd + 600 < time()){
///в один запрос

$ld = date("d.m.Y", time()-86400);
$res = mysql_fetch_array(mysql_query("SELECT 
(SELECT price FROM tb_config WHERE item='spam') spam,
(select price from tb_config where item='runblock') runblock,
(select price from tb_config where item='runacc') runacc,
(select price from tb_config where item='ban88') ban88,
(SELECT price FROM tb_config WHERE item='cloudwm') cloudwm,
(SELECT price FROM tb_config WHERE item='mprice') mprice,
(SELECT price FROM tb_config WHERE item='mobper') mobper,
(SELECT price FROM tb_config WHERE item='mhighlight') mhighlight,
(SELECT price FROM tb_config WHERE item='mtimer') mtimer,
(SELECT price FROM tb_config WHERE item='cloudma') cloudma,
(SELECT price FROM tb_config WHERE item='ddosperiod') ddosperiod,
(SELECT price FROM tb_config WHERE item='hits') hits,
(SELECT price FROM tb_config WHERE item='payment' AND howmany='1') minpay,
(SELECT price FROM tb_config WHERE item='advbanner') advbanner,
(SELECT price FROM tb_config WHERE item='advbanner300') advbanner300,
(SELECT price FROM tb_config WHERE item='advbanner100') advbanner100,
(SELECT price FROM tb_config WHERE item='advstatlink') advstatlink,
(SELECT price FROM tb_config WHERE item='obperehod') obperehod,
(SELECT price FROM tb_config WHERE item='act') act,
(SELECT price FROM tb_config WHERE item='mfahldyn') mfahldyn,
(SELECT price FROM tb_config WHERE item='hldyn') hldyn,
(SELECT price FROM tb_config WHERE item='adblock') adblock,
(SELECT price FROM tb_config WHERE item='taskminprice') taskminprice,
(SELECT price FROM tb_config WHERE item='taskmincount') taskmincount,
(SELECT price FROM tb_config WHERE item='textads') textads,
(SELECT price FROM tb_config WHERE item='timer5') timer5,
(SELECT price FROM tb_config WHERE item='wmframeads') wmframeads,
(SELECT price FROM tb_config WHERE item='frameads') frameads,
(SELECT price FROM tb_config WHERE item='chatmess') chatmess,
(SELECT price FROM tb_config WHERE item='dopsec') dopsec,
(SELECT price FROM tb_config WHERE item='leftblock') leftblock,
(SELECT price FROM tb_config WHERE item='vipblock') vipblock,
(SELECT price FROM tb_config WHERE item='vipcount') vipcount,
(SELECT price FROM tb_config WHERE item='wmchatads') wmchatads,
(select price from tb_config where item='refmax' and howmany='0') refmax0,
(select price from tb_config where item='refmax' and howmany='1') refmax1,
(SELECT price FROM tb_config WHERE item='refbirjcomm') refbirjcomm,
(SELECT price FROM tb_config WHERE item='refbirjminclick') refbirjminclick,
(SELECT price FROM tb_config WHERE item='captcha') captcha,
(SELECT price FROM tb_config WHERE item='taskcomm') taskcomm,
(SELECT price FROM tb_config WHERE item='taskhl') taskhl,
(SELECT price FROM tb_config WHERE item='refererbonus') refererbonus,
(SELECT price FROM tb_config WHERE item='actwin') actwin,
(SELECT count(id) FROM b_users WHERE joindate='$nowdate') newtoday,
(SELECT count(id) FROM b_users WHERE joindate='$ld') vchera,
(SELECT sum(visits) FROM b_users) allvis,
(SELECT sum(amount) FROM tb_history) totalpaid,
(SELECT count(id) FROM tb_payme) waitpay,
(SELECT sum(money) FROM b_users WHERE user_status='user') moneytoaccs,
(SELECT count(id) FROM tb_history) viplat,
(SELECT count(id) FROM b_users) nasvsego,
(SELECT price FROM tb_config WHERE item='mpay') mpay,
(SELECT `price` FROM `b_config` WHERE `name`='activ') b_activ,
(SELECT `price` FROM `b_config` WHERE `name`='click') b_click,
(SELECT `price` FROM `b_config` WHERE `name`='mails') b_mails,
(SELECT `price` FROM `b_config` WHERE `name`='task') b_task,
(SELECT `price` FROM `b_config` WHERE `name`='referal') b_referal,
(SELECT `price` FROM `b_config` WHERE `name`='payout') b_payout,
(SELECT `price` FROM `b_config` WHERE `name`='payout_ref') b_payout_ref,
(SELECT `price` FROM `b_config` WHERE `name`='noactiv') b_noactiv,
(SELECT `price` FROM `b_config` WHERE `name`='bad_task') b_bad_task,
(SELECT `price` FROM `b_config` WHERE `name`='wm_out') wm_out,
(SELECT `price` FROM `b_config` WHERE `name`='qw_out') qw_out,
(SELECT `price` FROM `b_config` WHERE `name`='ym_out') ym_out,
(SELECT `price` FROM `b_config` WHERE `name`='lp_out') lp_out,
(SELECT `price` FROM `b_config` WHERE `name`='pm_out') pm_out,
(SELECT `price` FROM `b_config` WHERE `name`='py_out') py_out,
(SELECT `price` FROM `b_config` WHERE `name`='wm_pay') wm_pay,
(SELECT `price` FROM `b_config` WHERE `name`='qw_pay') qw_pay,
(SELECT `price` FROM `b_config` WHERE `name`='ym_pay') ym_pay,
(SELECT `price` FROM `b_config` WHERE `name`='lp_pay') lp_pay,
(SELECT `price` FROM `b_config` WHERE `name`='pm_pay') pm_pay,
(SELECT `price` FROM `b_config` WHERE `name`='py_pay') py_pay,
(SELECT `price` FROM `b_config` WHERE `name`='rk_pay') rk_pay,
(SELECT `price` FROM `b_config` WHERE `name`='ik_pay') ik_pay,
(SELECT `price` FROM `b_config` WHERE `name`='zp_pay') zp_pay,
(SELECT `price` FROM `b_config` WHERE `name`='wo_pay') wo_pay,
(SELECT `price` FROM `b_config` WHERE `name`='ref_box') ref_box,
(SELECT `price` FROM `b_config` WHERE `name`='auto_moder') auto_moder,
(SELECT `price` FROM `b_config` WHERE `name`='viptask') viptask,
(SELECT username FROM b_users WHERE user_status='admin' order by id desc limit 1) admin LIMIT 1"));
$newtoday = $res["newtoday"];

$b_activ = $res["b_activ"];
$b_click = $res["b_click"];
$b_mails = $res["b_mails"];
$b_task = $res["b_task"];
$b_referal = $res["b_referal"];
$b_payout = $res["b_payout"];
$b_payout_ref = $res["b_payout_ref"];
$b_noactiv = $res["b_noactiv"];
$b_bad_task = $res["b_bad_task"];

// вкл.- откл. платёжных систем для вывода
$wm_out = $res["wm_out"];
$qw_out = $res["qw_out"];
$ym_out = $res["ym_out"];
$lp_out = $res["lp_out"];
$pm_out = $res["pm_out"];
$py_out = $res["py_out"];
// вкл.- откл. платёжных систем для оплаты
$wm_pay = $res["wm_pay"];
$qw_pay = $res["qw_pay"];
$ym_pay = $res["ym_pay"];
$lp_pay = $res["lp_pay"];
$pm_pay = $res["pm_pay"];
$py_pay = $res["py_pay"];
$rk_pay = $res["rk_pay"];
$ik_pay = $res["ik_pay"];
$zp_pay = $res["zp_pay"];
$wo_pay = $res["wo_pay"];

$ref_box = $res["ref_box"];
$auto_moder = $res["auto_moder"];
$viptask = $res["viptask"];

$mpay = $res["mpay"];
$allvis=$res["allvis"];
if($res["totalpaid"]=='') $res["totalpaid"]="0.00";
$totalpaid=round($res["totalpaid"],2);
$waitpay=$res["waitpay"];

if($res["moneytoaccs"]=='') $res["moneytoaccs"]="0.00";
$moneytoaccs = round($res["moneytoaccs"],2);
$viplat=$res["viplat"];
$admin=$res["admin"];
$spam=$res["spam"];
$cloudwm=$res["cloudwm"];
$cloudma=$res["cloudma"];
$mprice=$res["mprice"];
$pmhighlight=$res["mhighlight"];
$pmobper=$res["mobper"];
$pmtimer=$res["mtimer"];
$runblock=$res["runblock"];
$runacc=$res["runacc"];
$ban88=$res["ban88"];
$period=$res["ddosperiod"];
$obperehod=$res["obperehod"];
$act=$res["act"];
$hits=$res["hits"];
$minpay=$res["minpay"];
$advbanner=$res["advbanner"];
$advbanner300=$res["advbanner300"];
$advbanner100=$res["advbanner100"];
$advstatlink=$res["advstatlink"];
$hldyn=$res["hldyn"];
$mfahldyn=$res["mfahldyn"];
$adblock=$res["adblock"];
$textads=$res["textads"];
$taskminprice=$res["taskminprice"];
$taskmincount=$res["taskmincount"];
$timer5=$res["timer5"];
$wmframeads=$res["wmframeads"];
$frameads=$res["frameads"];
$vhatmess=$res["chatmess"];
$dopsec=$res["dopsec"];
$leftblock=$res["leftblock"];
$vipblock=$res["vipblock"];
$vipcount=$res["vipcount"];
$wmchatads=$res["wmchatads"];
$refmax0=$res["refmax0"];
$refmax1=$res["refmax1"];
$refbirjcomm=$res["refbirjcomm"];
$refbirjminclick=$res["refbirjminclick"];
$captcha=$res["captcha"];
$taskcomm=$res["taskcomm"];
$taskhl=$res["taskhl"];
$vchera=$res["vchera"];
$refererbonus=$res["refererbonus"];
$actwin=$res["actwin"];
$sql1=mysql_query("SELECT * FROM `tb_site` WHERE `id`='1'") or die(mysql_error());
$o = mysql_fetch_assoc($sql1);
$sitename = $o["sitename"];
$sitewmid = $o["wmid"];
$siteicq = $o["icq"];
$siteemail = $o["email"];
$sitepurse = $o["purse"];
$siteval = $o["valuta"];
$x2 = $o["x2"];
$sitevalname = $o["valutaname"];
$sitestartdate = $o["startdate"];
$merchant = $o["merchant"];
$payvisits = $o["visits"];
$sitehost=$_SERVER["HTTP_HOST"];
$siteurl="http://$sitehost";
$nasvsego=$res["nasvsego"];
require_once('moneyfortimer.php');
}

if(isset($_SESSION["username"])){
$sql2=mysql_query("SELECT * FROM `b_users` WHERE id='$id_user'") or die(mysql_error());
$byme = mysql_fetch_array($sql2);
$passwd = $byme["password"];
//кошельки
$wmid = $byme["wmid"];
$pemail = $byme["pemail"];
define("MY_WMID", $byme["wmid"]);
define("MY_WM_PURSE", $byme["pemail"]);
define("MY_QW_PURSE", str_replace("+","", $byme["qw_purse"]));
define("MY_YM_PURSE", $byme["ym_purse"]);
define("MY_LP_PURSE", str_replace("+","", $byme["lp_purse"]));
define("MY_PM_PURSE", $byme["pm_purse"]);
define("MY_PY_PURSE", $byme["py_purse"]);
//кошельки
$new_rb = $byme["new_rb"];
$referer = $byme["referer"];
$referer2 = $byme["referer2"];
$country=$byme["country"];
$user_status = $byme["user_status"];
$visits=$byme["visits"];
$maccess=$byme["mailaccess"];
$family=$byme["family"];
$vibor=$byme["vibor"];
$doing=$byme["doing"];
$obrr = mysql_query("SELECT 
(SELECT count(id) FROM `b_users` WHERE `referer`='$id_user') refov,
(SELECT count(id) FROM `b_users` WHERE `referer2`='$id_user') refov2,
(SELECT sum(visits) FROM `b_users` WHERE `referer`='$id_user') visitov1");
$obrr = mysql_fetch_assoc($obrr);
$referalvisits = $obrr["visitov1"];
if($referalvisits == NULL) $referalvisits=0;
$referals = $obrr["refov"];
$referals2 = $obrr["refov2"];
$money = round($byme["money"],2);
$r_money = $byme["r_money"];
$paid=$byme["paid"];
$email=$byme["email"];
$joindate=$byme["joindate"];
$lastlogdate=$byme["lastlogdate"];
$lastiplog=$byme["lastiplog"];
$avatar=$byme["avatar"];
$avatar="avp/$avatar";
$reyting = $byme["reyting"];

$add_test_price = mysql_result(mysql_query("SELECT `price` FROM `b_config` WHERE `name`='add_test_price'"),0);
$pay_test_price = mysql_result(mysql_query("SELECT `price` FROM `b_config` WHERE `name`='pay_test_price'"),0);
$textblockkk = mysql_num_rows(mysql_query("SELECT `text` FROM `still_auto_refbek` WHERE `id_us` = '".$_SESSION["iduser"]."'"));
$inboxcount = mysql_num_rows(mysql_query("SELECT `id` FROM `b_mails` WHERE `read` > '4' AND `toid` = '$id_user' AND `todl`='0'"));
$pod = mysql_num_rows(mysql_query("SELECT `id` FROM `nano_podarok` WHERE `komu` = '".$_SESSION["iduser"]."'"));
$all_dyn_p = mysql_num_rows(mysql_query("SELECT `id` FROM `tb_ads_p` WHERE `paused`='0' AND `balance`>'payforad' AND `modered`='1' AND `id` NOT IN (SELECT `ident` FROM `tb_visits_1` WHERE `idus`='".$_SESSION["iduser"]."' AND `data`>='".(time()-24*60*60)."')"));
$all_dyn = mysql_num_rows(mysql_query("SELECT `id` FROM `tb_ads` WHERE `paused`='0' AND `balance`>'price' AND `modered`='1' AND `id` NOT IN (SELECT `ident` FROM `tb_visits` WHERE `idus`='".$_SESSION["iduser"]."' AND `data`>='".(time()-24*60*60)."')"));
$all_mail = mysql_num_rows(mysql_query("SELECT `id` FROM `seo_paymails` WHERE `paused`='0' AND `balance`>'0' AND `modered`='1' AND `id` NOT IN (SELECT `ident` FROM `seo_paymailsviews` WHERE `fromid`='".$_SESSION["iduser"]."' AND `time`>='".(time()-24*60*60)."')"));
$all_task = mysql_num_rows(mysql_query("SELECT `id` FROM `seo_tasks` WHERE `modered`='1' AND `paused`='0' AND `balance`>'0'"));
$all_test = mysql_num_rows(mysql_query("SELECT `id` FROM `b_tests` WHERE `modered`='1' AND `paused`='0' AND `balance`>'price' AND `id` NOT IN (SELECT `ident` FROM `b_tests_view` WHERE `id_us`='".$_SESSION["iduser"]."' AND `date`>='".(time()-24*60*60)."')"));
$ref_kon = mysql_num_rows(mysql_query("SELECT `id` FROM `b_ref_comp` WHERE `status` = '1' AND `id_user` = '$referer'"));
}

if($lastupd+600<time()){

$d0=strtotime($sitestartdate);
$d1=time();
$d=($d1-$d0)/(24*3600);
$vozrast=ceil($d);

//**статистики разобраны**//
$printnew = mysql_fetch_array(mysql_query("SELECT `data`, `newstext`, `tema`, `id` FROM `tb_news` ORDER BY `id` DESC LiMIT 1"));
$datenew=$printnew["data"];
$textnew=$printnew["newstext"];
$temanew=$printnew["tema"];
$newid=$printnew["id"];
$newcomms=mysql_num_rows(mysql_query("SELECT `id` FROM `afbcomments` WHERE `idnew`='$newid'"));
}
//последнюю новость вывели
if($lastupd+600<time()){
$lastupd=time();
$content_stats = "<?PHP\n
\$lastupd = \"{$lastupd}\";\n

\$b_activ = \"{$b_activ}\";\n
\$b_click = \"{$b_click}\";\n
\$b_mails = \"{$b_mails}\";\n
\$b_task = \"{$b_task}\";\n
\$b_referal = \"{$b_referal}\";\n
\$b_payout = \"{$b_payout}\";\n
\$b_payout_ref = \"{$b_payout_ref}\";\n
\$b_noactiv = \"{$b_noactiv}\";\n
\$b_bad_task = \"{$b_bad_task}\";\n

\$wm_out = \"{$wm_out}\";\n
\$qw_out = \"{$qw_out}\";\n
\$ym_out = \"{$ym_out}\";\n
\$lp_out = \"{$lp_out}\";\n
\$pm_out = \"{$pm_out}\";\n
\$py_out = \"{$py_out}\";\n

\$wm_pay = \"{$wm_pay}\";\n
\$qw_pay = \"{$qw_pay}\";\n
\$ym_pay = \"{$ym_pay}\";\n
\$lp_pay = \"{$lp_pay}\";\n
\$pm_pay = \"{$pm_pay}\";\n
\$py_pay = \"{$py_pay}\";\n
\$rk_pay = \"{$rk_pay}\";\n
\$ik_pay = \"{$ik_pay}\";\n
\$zp_pay = \"{$zp_pay}\";\n
\$wo_pay = \"{$wo_pay}\";\n
\$add_test_price = \"{$add_test_price}\";\n
\$pay_test_price = \"{$pay_test_price}\";\n
\$ref_box = \"{$ref_box}\";\n
\$auto_moder = \"{$auto_moder}\";\n
\$viptask = \"{$viptask}\";\n

\$spam = \"{$spam}\";\n
\$period = \"{$period}\";\n
\$hits = \"{$hits}\";\n
\$minpay = \"{$minpay}\";\n
\$advbanner = \"{$advbanner}\";\n
\$advbanner300 = \"{$advbanner300}\";\n
\$advbanner100 = \"{$advbanner100}\";\n
\$advstatlink = \"{$advstatlink}\";\n
\$hldyn = \"{$hldyn}\";\n
\$mfahldyn = \"{$mfahldyn}\";\n
\$adblock = \"{$adblock}\";\n
\$textads = \"{$textads}\";\n
\$taskminprice = \"{$taskminprice}\";\n
\$taskmincount = \"{$taskmincount}\";\n
\$timer5 = \"{$timer5}\";\n
\$wmframeads = \"{$wmframeads}\";\n
\$frameads = \"{$frameads}\";\n
\$chatmess = \"{$chatmess}\";\n
\$dopsec = \"{$dopsec}\";\n
\$leftblock = \"{$leftblock}\";\n
\$vipblock = \"{$vipblock}\";\n
\$vipcount = \"{$vipcount}\";\n
\$wmchatads = \"{$wmchatads}\";\n
\$refmax0 = \"{$refmax0}\";\n
\$refmax1 = \"{$refmax1}\";\n
\$refbirjcomm = {$refbirjcomm};\n
\$refbirjminclick = \"{$refbirjminclick}\";\n
\$captcha = \"{$captcha}\";\n
\$taskcomm = \"{$taskcomm}\";\n
\$taskhl = \"{$taskhl}\";\n
\$sitename = \"{$sitename}\";\n
\$sitewmid = \"{$sitewmid}\";\n
\$siteemail = \"{$siteemail}\";\n
\$sitepurse = \"{$sitepurse}\";\n
\$siteval = \"{$siteval}\";\n
\$x2 = \"{$x2}\";\n
\$rpass1 = \"{$rpass1}\";\n
\$rpass2 = \"{$rpass2}\";\n
\$rlogin = \"{$rlogin}\";\n
\$sitevalname = \"{$sitevalname}\";\n
\$sitestartdate = \"{$sitestartdate}\";\n
\$merchant = \"{$merchant}\";\n
\$payvsits = \"{$payvisits}\";\n
\$siteurl = \"{$siteurl}\";\n
\$newtoday = \"{$newtoday}\";\n
\$allvis = \"{$allvis}\";\n
\$totalpaid = \"{$totalpaid}\";\n
\$waitpay = \"{$waitpay}\";\n
\$moneytoaccs = \"{$moneytoaccs}\";\n
\$viplat = \"{$viplat}\";\n
\$admin = \"{$admin}\";\n
\$vozrast = \"{$vozrast}\";\n
\$datenew = \"{$datenew}\";\n
\$textnew = \"{$textnew}\";\n
\$temanew = \"{$temanew}\";\n
\$newid =  \"{$newid}\";\n
\$refererbonus = \"{$refererbonus}\";\n
\$actwin = \"{$actwin}\";\n
\$cloudwm = \"{$cloudwm}\";\n
\$siteicq = \"{$siteicq}\";\n
\$ban88 = \"{$ban88}\";\n
\$runblock = \"{$runblock}\";\n
\$payfor10 = \"{$payfor10}\";\n
\$payfor20 = \"{$payfor20}\";\n
\$payfor30 = \"{$payfor30}\";\n
\$payfor40 = \"{$payfor40}\";\n
\$payfor50 = \"{$payfor50}\";\n
\$payfor60 = \"{$payfor60}\";\n
\$dyn10 = \"{$dyn10}\";\n
\$dyn20 = \"{$dyn20}\";\n
\$dyn30 = \"{$dyn30}\";\n
\$dyn40 = \"{$dyn40}\";\n
\$dyn50 = \"{$dyn50}\";\n
\$dyn60 = \"{$dyn60}\";\n
\$mpay = \"{$mpay}\";\n
\$runacc = \"{$runacc}\";\n
\$nasvsego = \"{$nasvsego}\";\n
\$vchera = \"{$vchera}\";\n
\$newcomms = \"{$newcomms}\";\n
\$obperehod = \"{$obperehod}\";\n
\$act = \"{$act}\";\n
\$mprice = \"{$mprice}\";\n
\$pmhighlight = \"{$pmhighlight}\";\n
\$pmtimer = \"{$pmtimer}\";\n
\$pmobper = \"{$pmobper}\";\n
?>";

$fstats = @fopen("sfbstat.php","w+");
@fwrite($fstats,$content_stats);
@fclose($fstats);
}
?>