<?require ('../config.php');

$wel_stat =mysql_query("SELECT
(SELECT price FROM tb_config WHERE item='click' and howmany='1') click,
(SELECT price FROM tb_config WHERE item='mail_clic' and howmany='1') mail,
(SELECT price FROM tb_config WHERE item='mail_refclic' and howmany='1') mailref,
(SELECT price FROM tb_config WHERE item='auto_click' and howmany='1') auto,
(SELECT price FROM tb_config WHERE item='click1' and howmany='1') clck1,
(SELECT price FROM tb_config WHERE item='payment' and howmany='1') pay,
(SELECT count(id) FROM tb_users WHERE joindate='".date("d.m.Y", time()-86400)."') vchera,
(SELECT sum(amount) FROM tb_history WHERE date='".date("d-m-Y")."') todaypaid,
(SELECT sum(amount) FROM tb_history WHERE date='".date("d-m-Y", strtotime('-1 day'))."') yesterdaypaid,
(SELECT sum(amount) FROM tb_history WHERE date='".date("d-m-Y", strtotime('-2 day'))."') twodaysagopaid,
(SELECT count(id) FROM `tb_payme`)  tot1,
(SELECT count(id) FROM `tb_history`) tot2,
(select sum(money) from tb_users where user_status='user') deneg,
(select sum(visits) from tb_users) ret,
(SELECT COUNT(id) FROM tb_users) user,
(SELECT COUNT(id) FROM tb_users WHERE joindate='".date("d.m.Y")."') suser,
(SELECT sum(amount) FROM tb_history) totalpaid,
(SELECT COUNT(id) FROM spisok_adv) reklamadat
") ;

$wel_rez = mysql_fetch_assoc($wel_stat);

$zap = "<?PHP \r\n ";
$zap .= "\$clck = \"".$wel_rez["click"]."\"; \r\n ";
$zap .= "\$clck1 = \"".$wel_rez["clck1"]."\"; \r\n ";
$zap .= "\$mail = \"".$wel_rez["mail"]."\"; \r\n ";
$zap .= "\$mailref = \"".$wel_rez["mailref"]."\"; \r\n ";
$zap .= "\$auto = \"".$wel_rez["auto"]."\"; \r\n ";
$zap .= "\$pay = \"".$wel_rez["pay"]."\"; \r\n ";
$zap .= "\$vchera = \"".number_format($wel_rez["vchera"], 0, '.', '`')."\"; \r\n ";
$zap .= "\$todaypaid = \"".number_format($wel_rez["todaypaid"], 0, '.', '`')."\"; \r\n ";
$zap .= "\$yesterdaypaid = \"".number_format($wel_rez["yesterdaypaid"], 0, '.', '`')."\"; \r\n ";
$zap .= "\$twodaysagopaid = \"".number_format($wel_rez["twodaysagopaid"], 0, '.', '`')."\"; \r\n ";
$zap .= "\$tot1 = \"".number_format($wel_rez["tot1"], 0, '.', '`')."\"; \r\n ";
$zap .= "\$tot2 = \"".number_format($wel_rez["tot2"], 0, '.', '`')."\"; \r\n ";
$zap .= "\$deneg = \"".number_format($wel_rez["deneg"], 0, '.', '`')."\"; \r\n ";
$zap .= "\$ret = \"".number_format($wel_rez["ret"], 0, '.', '`')."\"; \r\n ";
$zap .= "\$user_ch = \"".number_format($wel_rez["user"], 0, '.', '`')."\"; \r\n ";$zap .= "\$suser = \"".$wel_rez["suser"]."\"; \r\n ";
$zap .= "\$totalpaid = \"".number_format($wel_rez["totalpaid"], 0, '.', '`')."\"; \r\n ";
$zap .= "\$reklamadata = \"".number_format($wel_rez["reklamadat"], 0, '.', '`')."\"; \r\n ";
$zap .= "?>";

$handler = fopen('../kech/file_stats.php', "w");
           fwrite($handler, $zap);
           fclose($handler);

?>