<?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;
}
global $db, $config, $core, $includ_chart_conf, $lang;
loadConfig('includ_chart');
loadLang('includ_chart');
$array_day = "";
$array_views = "";
$array_people = "";
$final_array = array();
if ($_SERVER['QUERY_STRING'] == 'url=includ_chart/counter' || $_SERVER['QUERY_STRING'] == 'url=/counter') set_title(array($lang['counter_visits']));
$del_time = $core->row_data('counter_stat');
if (date('d.m.Y') == $del_time['del_date']) $core->del_data('counter_stat', 'del_date ="' . $del_time['del_date'] . '"');
$get_info_stats = $core->select_data('counter_stat', 'date >="' . date('d.m.Y') . '"', 'date DESC');
$array_date = array();
$array_all = array();
while ($row = $db->getRow($get_info_stats)) {
    $array_date[] = $row["date"];
    $array_all[] = $row;
}
$new_array_date = array_unique($array_date);
foreach ($new_array_date as $key_date) {
    $i = 0;
    $sum = 0;
    foreach ($array_all as $key_all) {
        if ($key_date == $key_all["date"]) {
            $sum = $sum + $key_all["views"];
            $i++;
        }
    }
    $final_array[] = array($key_date, $i, $sum);
}
foreach ($final_array as $rows) {
    $array_views = $rows[2];
    $array_people = $rows[1];
}
$this->setVar('counter_views', formatCounter($array_views));
$this->setVar('counter_people', formatCounter($array_people));