<?php 
if (!defined('NTLCMS')) die('<center><b>Restricted access</b></center>');			

/* Суперадмин */
function ADMINS(){
$user = DB :: run() -> query("select (`login`) from `users` where `admin` = ? order by `id` asc limit 1", array(1)) -> fetch(PDO::FETCH_OBJ);
return $user -> login;
}
/* Счетчик юзеров */
function USERS(){
$total = DB :: run() -> querySingle("select count(`id`) from `users`");
$new = DB :: run() -> querySingle("select count(`id`) from `users` where `regdate` > ?", array(TIME - 86400));
if ($new > 0)
$total .= '/<span style="color:red">+'.$new.'</span>';
return $total;
}
/* Счетчик юзеров */
function USERLIST(){
$cnt = DB :: run() -> querySingle("select count(`id`) from `users`");
return $cnt;
}

/* Счетчик чата */
function CHAT(){
$total = DB :: run() -> querySingle("select count(`id`) from `chat`");
$new = DB :: run() -> querySingle("select count(`id`) from `chat` where `date` > ?", array(TIME - 86400));
if ($new > 0)
$total .= '/<span style="color:red">+'.$new.'</span>';
return $total;
}

/* Счетчик ссылок */
function COUNTLINK(){
global $_USER;
$cntlink = DB :: run() -> querySingle("select count(*) from `sites` left join `click` on `click`.`login` = '".checkout($_USER['login'])."' and `click`.`url` = `sites`.`url` where `sites`.`login` != '".checkout($_USER['login'])."' and `sites`.`active` = '1' and `sites`.`status` = '1' and `click`.`url` is null");
return (int)$cntlink;
}

/* Счетчик ссылок */
function COUNTAUTO(){
global $_USER;
$cntlink = DB :: run() -> querySingle("select count(*) from `sites` left join `click` on `click`.`login` = '".checkout($_USER['login'])."' and `click`.`url` = `sites`.`url` where `sites`.`login` != '".checkout($_USER['login'])."' and `sites`.`active` = '1' and `sites`.`status` = '1' and `sites`.`auto` = '1' and `click`.`url` is null");
return (int)$cntlink;
}

/* Мои гости */
function MYGUESTS(){
global $_USER;
$count_guests = DB :: run() -> querySingle("select (`id`) from `guests` where `kogo` = '".$_USER['login']."'");
$count_new_guests = DB :: run() -> querySingle("select (`id`) from `guests` where `kogo` = '".$_USER['login']."' and `status` = '1'");
if($count_new_guests > 0){
$count_guests_new = '/<span style="color:red">+'.$count_new_guests.'</span>';
}
return $count_guests . $count_guests_new;
}

/* Новости сайта */
function NEWS(){
    if (@filemtime(FOLDER.'/cache/news.dat') < TIME - 1){
        $total = DB :: run() -> query("select (`date`) from `news` where `id` order by `id` desc limit 1") -> fetch(PDO::FETCH_OBJ);
        $date = ($total && !empty($total->date) && $total->date > 0) ? date('d.m.Y', $total->date) : 'Нет новостей';
        file_put_contents(FOLDER.'/cache/news.dat', $date, LOCK_EX);
    } 
    return file_get_contents(FOLDER.'/cache/news.dat');
}

/* Мини-Чатик */
function CHATS(){
if (@filemtime(FOLDER.'/cache/chat.dat') < TIME - 10){
$total = DB :: run() -> querySingle("select count(`id`) from `chat`");
file_put_contents(FOLDER.'/cache/chat.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/chat.dat');
} 

/* Пользователи */
function USERLISTS(){
if (@filemtime(FOLDER.'/cache/users.dat') < TIME - 10){
$total = DB :: run() -> querySingle("select count(`id`) from `users`");
file_put_contents(FOLDER.'/cache/users.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/users.dat');
} 

/* Переходов сегодня */
function GODAY(){
if (@filemtime(FOLDER.'/cache/goday.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select sum(`click_day`) from `users`");
file_put_contents(FOLDER.'/cache/goday.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/goday.dat');
} 

/* Средств на счетах */
function SYSMONEY(){
if (@filemtime(FOLDER.'/cache/sysmoney.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select sum(`balans`) from `users`");
file_put_contents(FOLDER.'/cache/sysmoney.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/sysmoney.dat');
} 

/* Выплачено средств */
function OUTMONEY(){
if (@filemtime(FOLDER.'/cache/outmoney.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select sum(`money`) from `payment` where `status` = ?", array('on'));
file_put_contents(FOLDER.'/cache/outmoney.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/outmoney.dat');
} 

/* Ваши отзывы */
function REVIEWS(){
if (@filemtime(FOLDER.'/cache/reviews.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `reviews`");
file_put_contents(FOLDER.'/cache/reviews.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/reviews.dat');
} 

/* Новые юзеры */
function NEW_USERS(){
if (@filemtime(FOLDER.'/cache/new.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `users` where `regdate` > ?", array(TIME - 86400));
file_put_contents(FOLDER.'/cache/new.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/new.dat');
} 

/* Онлайн юзеров */
function USERS_ONLINE(){
if (@filemtime(FOLDER.'/cache/online.dat') < TIME - 1){
$total = DB :: run() -> querySingle("select count(`id`) from `users` where `login` <> '' and `ontime` > ?", array(TIME - 180));
file_put_contents(FOLDER.'/cache/online.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/online.dat');
} 

/* Онлайн чата */
function CHAT_ONLINE(){
if (@filemtime(FOLDER.'/cache/chatonline.dat') < TIME - 1){
$total = DB :: run() -> querySingle("select count(`id`) from `users` where `where` = 'chat' and `ontime` > ?", array(TIME - 180));
file_put_contents(FOLDER.'/cache/chatonline.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/chatonline.dat');
} 

/* Онлайн гостей */
function GUEST_ONLINE(){
if (@filemtime(FOLDER.'/cache/guest.dat') < TIME - 1){
$total = DB :: run() -> querySingle("select count(`id`) from `session`");
file_put_contents(FOLDER.'/cache/guest.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/guest.dat');
} 

/* Администрация */
function ADMINLIST(){
if (@filemtime(FOLDER.'/cache/adminlist.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `users` where `admin` = ?", array(1));
file_put_contents(FOLDER.'/cache/adminlist.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/adminlist.dat');
} 

/* Забаненных */
function BANLIST(){
if (@filemtime(FOLDER.'/cache/banlist.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `ban`");
file_put_contents(FOLDER.'/cache/banlist.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/banlist.dat');
} 

/* Рефералов */
function ALLREFERALS(){
if (@filemtime(FOLDER.'/cache/referals.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `ref`");
file_put_contents(FOLDER.'/cache/referals.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/referals.dat');
} 

/* Справка по смайлам */
function TOTALSMILES(){
if (@filemtime(FOLDER.'/cache/smiles.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `smiles`");
file_put_contents(FOLDER.'/cache/smiles.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/smiles.dat');
} 

/* Площадок всего */
function SITEALL(){
if (@filemtime(FOLDER.'/cache/siteall.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `sites`");
file_put_contents(FOLDER.'/cache/siteall.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/siteall.dat');
} 

/* Площадки активные */
function SITEACTIVE(){
if (@filemtime(FOLDER.'/cache/siteactive.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `sites` where `status` = ?", array(1));
file_put_contents(FOLDER.'/cache/siteactive.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/siteactive.dat');
} 

/* Площадки забаненные */
function SITEBLOCK(){
if (@filemtime(FOLDER.'/cache/siteblock.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `sites` where `status` = ?", array(3));
file_put_contents(FOLDER.'/cache/siteblock.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/siteblock.dat');
} 

/* Площадки на модерации */
function SITEMOD(){
if (@filemtime(FOLDER.'/cache/sitemod.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `sites` where `status` = ?", array(2));
file_put_contents(FOLDER.'/cache/sitemod.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/sitemod.dat');
} 

/* Переходов сегодня */
function CLICK_DAY(){
if (@filemtime(FOLDER.'/cache/clickday.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select sum(`click_day`) from `users`");
file_put_contents(FOLDER.'/cache/clickday.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/clickday.dat');
} 

/* Переходов всего */
function CLICK_ALL(){
if (@filemtime(FOLDER.'/cache/clickall.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select sum(`click_all`) from `users`");
file_put_contents(FOLDER.'/cache/clickall.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/clickall.dat');
} 

/* В активе */
function CREDIT(){
if (@filemtime(FOLDER.'/cache/credit.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select sum(`credit`) from `users`");
file_put_contents(FOLDER.'/cache/credit.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/credit.dat');
} 

/* В банке */
function BANK(){
if (@filemtime(FOLDER.'/cache/bank.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select sum(`bank`) from `users`");
file_put_contents(FOLDER.'/cache/bank.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/bank.dat');
} 
/* Ставки на бирже */
function EXCHANGES(){
if (@filemtime(FOLDER.'/cache/exchanges.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `exchange`");
file_put_contents(FOLDER.'/cache/exchanges.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/exchanges.dat');
} 

/* Заработано сегодня */
function DAYPROFIT(){
if (@filemtime(FOLDER.'/cache/dayprofit.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select sum(`myprofit`) from `users`");
file_put_contents(FOLDER.'/cache/dayprofit.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/dayprofit.dat');
} 

/* Введено средств */
function INMONEY(){
if (@filemtime(FOLDER.'/cache/inmoney.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select sum(`summa`) from `money_in`");
file_put_contents(FOLDER.'/cache/inmoney.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/inmoney.dat');
} 

/* Мерчант ввод */
function INMERCHANT(){
if (@filemtime(FOLDER.'/cache/merchant.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select sum(`summa`) from `merchant`");
file_put_contents(FOLDER.'/cache/merchant.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/merchant.dat');
} 

/* Ожидают ввод */
function INPAYMENT(){
if (@filemtime(FOLDER.'/cache/inpayment.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `inmoney`");
file_put_contents(FOLDER.'/cache/inpayment.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/inpayment.dat');
} 

/* Ожидают ввод (сумма) */
function INPAYMENTS(){
if (@filemtime(FOLDER.'/cache/inpayments.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select sum(`money`) from `inmoney`");
file_put_contents(FOLDER.'/cache/inpayments.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/inpayments.dat');
} 

/* Ожидают вывод */
function OUTPAYMENT(){
if (@filemtime(FOLDER.'/cache/outpayment.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `payment` where `status` = ?", array('moder'));
file_put_contents(FOLDER.'/cache/outpayment.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/outpayment.dat');
} 

/* Ожидают вывод (сумма) */
function OUTPAYMENTS(){
if (@filemtime(FOLDER.'/cache/outpayments.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select sum(`money`) from `payment` where `status` = ?", array('moder'));
file_put_contents(FOLDER.'/cache/outpayments.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/outpayments.dat');
} 

/* Посл.выплата */
function OLD_PAYMENT(){
if (@filemtime(FOLDER.'/cache/oldpayment.dat') < TIME - 180){
$total = DB :: run() -> query("select * from `payment` where `status` = ? order by `date` desc limit 1", array('on')) -> fetch(PDO::FETCH_OBJ);
file_put_contents(FOLDER.'/cache/oldpayment.dat', date('d.m.Y H:i', $total -> date), LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/oldpayment.dat');
} 
################################################################################

/* Рейтинг по кликам */
function DAY_RATE(){
if (@filemtime(FOLDER.'/cache/dayrate.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `users` where `click_day` <> '' and `id` <> '0'");
file_put_contents(FOLDER.'/cache/dayrate.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/dayrate.dat');
} 

/* Рейтинг по рефералам */
function REF_RATE(){
if (@filemtime(FOLDER.'/cache/refrate.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `users` where `ref` <> '' and `id` <> '0'");
file_put_contents(FOLDER.'/cache/refrate.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/refrate.dat');
} 

/* Рейтинг по балансу */
function MONEY_RATE(){
if (@filemtime(FOLDER.'/cache/moneyrate.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `users` where `balans` <> '' and `id` <> '0'");
file_put_contents(FOLDER.'/cache/moneyrate.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/moneyrate.dat');
} 

/* Нас посетили */
function LAST_RATE(){
if (@filemtime(FOLDER.'/cache/lastrate.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `users` where `lasttime` > '".mktime(0, 0, 1, date('m'), date('d'), date('Y'))."'");
file_put_contents(FOLDER.'/cache/lastrate.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/lastrate.dat');
} 

/* Рейтинг в чате */
function CHAT_RATE(){
if (@filemtime(FOLDER.'/cache/chatrate.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `users` where `postchat` <> '' and `id` <> '0'");
file_put_contents(FOLDER.'/cache/chatrate.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/chatrate.dat');
} 

/* Рейтинг по активу */
function ACTIV_RATE(){
if (@filemtime(FOLDER.'/cache/activrate.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `users` where `credit` <> '' and `id` <> '0'");
file_put_contents(FOLDER.'/cache/activrate.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/activrate.dat');
} 

/* Рейтинг по банку */
function BANK_RATE(){
if (@filemtime(FOLDER.'/cache/bankrate.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `users` where `bank` <> '' and `id` <> '0'");
file_put_contents(FOLDER.'/cache/bankrate.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/bankrate.dat');
} 

/* Рейтинг по недопереходам */
function BAD_RATE(){
if (@filemtime(FOLDER.'/cache/badrate.dat') < TIME - 180){
$total = DB :: run() -> querySingle("select count(`id`) from `users` where `badclick` <> '' and `id` <> '0'");
file_put_contents(FOLDER.'/cache/badrate.dat', $total, LOCK_EX);
} 
return file_get_contents(FOLDER.'/cache/badrate.dat');
}			
?>