<?php

/*
  * @name        JMY CMS
  * @link        https://jmy.su/
  * @copyright   Copyright (C) 2012-2025 JMY LTD
  * @license     LICENSE.txt (see attached file)
  * @version     VERSION.txt (see attached file)
  * @author      Orlov Alexsey
  */

if (!defined('ACCESS')) {
    header('Location: /');
    exit;
}
loadConfigBLOCK('stat');
global $db, $core, $lang, $statistics_conf;
$core->loadblockLang('stat');
$stats_day = time() - (3600 * 24);
$stats_week = time() - (3600 * 24 * 7);
$stats_month = time() - (3600 * 24 * 31);
$stats_year = time() - (3600 * 24 * 365);
$ddate = date('Y-m-d H:i', time());
$news_num = $core->sum_data('news');
$news_allow = $core->sum_data('news', 'active = 1');
$news_main = $core->sum_data('news', 'allow_index = 1');
$news_moder = $core->sum_data('news', 'active = 2');
$news_day = $core->sum_data('news', 'date > "' . $stats_day . '" AND active = 1');
$news_week = $core->sum_data('news', 'date > "' . $stats_week . '" AND active = 1');
$news_month = $core->sum_data('news', 'date > "' . $stats_month . '" AND active = 1');
$news_year = $core->sum_data('news', 'date > "' . $stats_year . '" AND active = 1');
$cats = $core->sum_data('categories');
$cats = $core->sum_data('content');
$cont_day = $core->sum_data('content', 'date > "' . $stats_day . '"  AND date <= "' . $ddate . '"');
$cont_week = $core->sum_data('content', 'date > "' . $stats_week . '"  AND date <= "' . $ddate . '"');
$cont_month = $core->sum_data('content', 'date > "' . $stats_month . '" AND date <= "' . $ddate . '"');
$cont_year = $core->sum_data('content', 'date > "' . $stats_year . '"  AND date <= "' . $ddate . '"');
$comm_num = $core->sum_data('comments');
$comm_day = $core->sum_data('comments', 'date > "' . $stats_week . '" AND date <= "' . $ddate . '"');
$comm_week = $core->sum_data('comments', 'date > "' . $stats_month . '" AND date <= "' . $ddate . '"');
$comm_month = $core->sum_data('comments', 'date > "' . $stats_year . '" AND date <= "' . $ddate . '"');
$comm_year = $core->sum_data('comments', 'date > "' . $stats_year . '" AND date <= "' . $ddate . '"');
$user_num = $core->sum_data('users');
$user_day = $core->sum_data('users', 'regdate > "' . $stats_week . '"');
$user_week = $core->sum_data('users', 'regdate > "' . $stats_month . '"');
$user_month = $core->sum_data('users', 'regdate > "' . $stats_year . '"');
$user_year = $core->sum_data('users', 'regdate > "' . $stats_year . '"');
$i = 0;
$query = $core->select_data('users');
if ($db->numRows($query) > 0) {
    while ($adminUser = $db->getRow($query)) {
        $user_bann = $adminUser['group'] == '5' ? $i++ : $i;
    }
}
$user_online = $core->sum_data('online');
$help_num = $core->sum_data('help');
$help_day = $core->sum_data('help', 'time > "' . $stats_week . '"');
$help_week = $core->sum_data('help', 'time > "' . $stats_month . '"');
$help_month = $core->sum_data('help', 'time > "' . $stats_year . '"');
$help_year = $core->sum_data('help', 'time > "' . $stats_year . '"');
$help_replies_num = $core->sum_data('help_replies');
$help_replies_day = $core->sum_data('help_replies', 'time > "' . $stats_week . '"');
$help_replies_week = $core->sum_data('help_replies', 'time > "' . $stats_month . '"');
$help_replies_month = $core->sum_data('help_replies', 'time > "' . $stats_year . '"');
$help_replies_year = $core->sum_data('help_replies', 'time > "' . $stats_year . '"');
/*
 * Вывод блока
 */
if ($statistics_conf['on']) {
    if ($statistics_conf['old']) {
        echo '<div style="text-align:left" class="padding"> ' . $lang['total_numb_news'] . $news_num . '</div>
<div style="text-align:left" class="padding">' . $lang['publ_numb_news'] . $news_allow . '</div>
<div style="text-align:left" class="padding">' . $lang['main_numb_news'] . $news_main . '</div>
<div style="text-align:left" class="padding">' . $lang['day_numb_news'] . $news_day . '</div>
<div style="text-align:left" class="padding"> ' . $lang['week_numb_news'] . $news_week . '</div>
<div style="text-align:left" class="padding">' . $lang['month_numb_news'] . $news_month . '</div>
<div style="text-align:left" class="padding">' . $lang['year_numb_news'] . $news_year . '</div>
<br/>
<div style="text-align:left" class="padding">' . $lang['total_numb_comments'] . $comm_num . '</div>
<div style="text-align:left" class="padding"> ' . $lang['day_numb_comments'] . $comm_day . '</div>
<div style="text-align:left" class="padding"> ' . $lang['week_numb_comments'] . $comm_week . '</div>
<div style="text-align:left" class="padding"> ' . $lang['month_numb_comments'] . $comm_month . '</div>
<div style="text-align:left" class="padding">' . $lang['year_numb_comments'] . $comm_year . '</div>
<br/>
<div style="text-align:left" class="padding">' . $lang['total_numb_user'] . $user_num . '</div>
<div style="text-align:left" class="padding">' . $lang['day_reg_user'] . $user_day . '</div>
<div style="text-align:left" class="padding"> ' . $lang['week_reg_user'] . $user_week . '</div>
<div style="text-align:left" class="padding">' . $lang['month_reg_user'] . $user_month . '</div>
<div style="text-align:left" class="padding">' . $lang['year_reg_user'] . $user_year . '</div>
<div style="text-align:left" class="padding"> ' . $lang['total_ban_user'] . $user_bann . '</div>
<div style="text-align:left" class="padding">' . $lang['total_online_user'] . $user_online . '</div>
<br/>
<div style="text-align:left" class="padding">' . $lang['total_numb_question'] . $help_num . '</div>
<div style="text-align:left" class="padding"> ' . $lang['day_numb_question'] . $help_day . '</div>
<div style="text-align:left" class="padding"> ' . $lang['week_numb_question'] . $help_week . '</div>
<div style="text-align:left" class="padding">' . $lang['month_numb_question'] . $help_month . '</div>
<div style="text-align:left" class="padding">' . $lang['year_numb_question'] . $help_year . '</div>
<br/>
<div style="text-align:left" class="padding"> ' . $lang['total_numb_reply'] . $help_replies_num . '</div>
<div style="text-align:left" class="padding"> ' . $lang['day_numb_reply'] . $help_replies_day . '</div>
<div style="text-align:left" class="padding">' . $lang['week_numb_reply'] . $help_replies_week . '</div>
<div style="text-align:left" class="padding"> ' . $lang['month_numb_reply'] . $help_replies_month . '</div>
<div style="text-align:left" class="padding">' . $lang['year_numb_reply'] . $help_replies_year . '</div>';
    } else {
        $core->tpl->loadFile('blocks/statistics');
        $core->tpl->setVar('NEWS_NUM', $news_num);
        $core->tpl->setVar('NEWS_ALLOW', $news_allow);
        $core->tpl->setVar('NEWS_MAIN', $news_main);
        $core->tpl->setVar('NEWS_MODER', $news_moder);
        $core->tpl->setVar('NEWS_DAY', $news_day);
        $core->tpl->setVar('NEWS_WEEK', $news_week);
        $core->tpl->setVar('NEWS_MONTH', $news_month);
        $core->tpl->setVar('NEWS_YEAR', $news_year);
        $core->tpl->setVar('COMM_NUM', $comm_num);
        $core->tpl->setVar('COMM_DAY', $comm_day);
        $core->tpl->setVar('COMM_WEEK', $comm_week);
        $core->tpl->setVar('COMM_MONTH', $comm_month);
        $core->tpl->setVar('COMM_YEAR', $comm_year);
        $core->tpl->setVar('USER_NUM', $user_num);
        $core->tpl->setVar('USER_BANN', $user_bann);
        $core->tpl->setVar('USER_DAY', $user_day);
        $core->tpl->setVar('USER_WEEK', $user_week);
        $core->tpl->setVar('USER_MONTH', $user_month);
        $core->tpl->setVar('USER_YEAR', $user_year);
        $core->tpl->setVar('USER_ONLINE', $user_online);
        $core->tpl->setVar('HELP_NUM', $help_num);
        $core->tpl->setVar('HELP_DAY', $help_day);
        $core->tpl->setVar('HELP_WEEK', $help_week);
        $core->tpl->setVar('HELP_MONTH', $help_month);
        $core->tpl->setVar('HELP_YEAR', $help_year);
        $core->tpl->setVar('HELP_REPLIES_NUM', $help_replies_num);
        $core->tpl->setVar('HELP_REPLIES_DAY', $help_replies_day);
        $core->tpl->setVar('HELP_REPLIES_WEEK', $help_replies_week);
        $core->tpl->setVar('HELP_REPLIES_MONTH', $help_replies_month);
        $core->tpl->setVar('HELP_REPLIES_YEAR', $help_replies_year);
        $core->tpl->end();
    }
} else {
    if ($statistics_conf['info_off']) $core->tpl->info($lang['stat_off']);
}