Файл: panel/statistic.php
Строк: 104
<?php
/* DCMS S (Special)
 * Версия файла 0.0.1
 * Дата последнего редактирования 15.11.2015
 * Модифицировал densnet
 */
require_once '../sys/inc/start.php';
require_once H . 'sys/inc/compress.php';
require_once H . 'sys/inc/sess.php';
require_once H . 'sys/inc/settings.php';
require_once H . 'sys/inc/db_connect.php';
require_once H . 'sys/inc/ipua.php';
require_once H . 'sys/inc/fnc.php';
require_once H . 'sys/inc/adm_check.php';
require_once H . 'sys/inc/user.php';
user::access('adm_statistic', null, 'index.php?' . SID);
adm_check();
$set['title'] = 'Статистика сайта';
require_once H . 'sys/inc/thead.php';
title();
aut();
err();
$mod = (isset($_GET['mod'])) ? htmlspecialchars($_GET['mod']) : null;
echo "<div class = 'list-group-item'><center><b>Статистика сайта</b></center></div>";
switch ($mod) {
    default:
        echo "<div class = 'list-group-item'>";
        echo "Уникальные посещения:<br /><img src = '?mod=1&SESS=$sess' alt = 'Уникальные посетители' /><br />";
        echo "Переходы по страницам:<br /><img src = '?mod=2&SESS=$sess' alt = 'Переходы по страницам' /><br />";
        echo "Кол-во регистраций:<br /><img src = '?mod=3&SESS=$sess' alt = 'Регистрации' /><br />";
        echo "Кол-во созданных тем:<br /><img src = '?mod=4&SESS=$sess' alt = 'Новые темы в форуме' /><br />";
        echo "Кол-во сообщений в форуме:<br /><img src = '?mod=5&SESS=$sess' alt = 'Новые сообщения в форуме' />";
        echo "</div>";
        break;
    case '1':
        #создаем изображение
        $img = imagecreatetruecolor(120, 50);
        #заливаем белым
        imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
        $line_col = imagecolorallocate($img, 100, 100, 100);
        $text_col = imagecolorallocate($img, 60, 60, 60);
        $sh_col = imagecolorallocate($img, 255, 200, 200);
        $max = 0;
        for ($i = 0; $i < 100; $i++) {
            $host = @mysql_result(@mysql_query("SELECT `host_ip_ua` FROM `visit_everyday` ORDER BY `time` DESC LIMIT $i,1"), 0);
            $max = max($max, $host);
            $hosts[$i] = $host;
        }
        for ($i = 0; $i < 100; $i++) {
            $x = 119 - $i;
            $y1 = 49;
            imageline($img, $x, 0, $x, $i % 30 ? 1 : 5, $sh_col);
            $y2 = 49 - intval(40 * ($max ? ($hosts[$i] / $max) : 0));
            imageline($img, $x, $y1, $x, $y2, $line_col);
        }
        imagestring($img, 1, 3, 1, "max:$max", $text_col);
        @ob_end_clean();
        header("Content-type: image/png");
        imagepng($img);
        break;
    case '2':
        $img = imagecreatetruecolor(120, 50);
        imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
        $line_col = imagecolorallocate($img, 100, 100, 100);
        $text_col = imagecolorallocate($img, 60, 60, 60);
        $sh_col = imagecolorallocate($img, 255, 200, 200);
        $max = 0;
        for ($i = 0; $i < 100; $i++) {
            $hit = @mysql_result(@mysql_query("SELECT `hit` FROM `visit_everyday` ORDER BY `time` DESC LIMIT $i,1"), 0);
            $max = max($max, $hit);
            $hits[$i] = $hit;
        }
        for ($i = 0; $i < 100; $i++) {
            $x = 119 - $i;
            $y1 = 49;
            imageline($img, $x, 0, $x, $i % 30 ? 1 : 5, $sh_col);
            $y2 = 49 - intval(40 * ($max ? ($hits[$i] / $max) : 0));
            imageline($img, $x, $y1, $x, $y2, $line_col);
        }
        imagestring($img, 1, 3, 1, "max:$max", $text_col);
        @ob_end_clean();
        header("Content-type: image/png");
        imagepng($img);
        break;
    case '3':
        $img = imagecreatetruecolor(120, 50);
        imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
        $line_col = imagecolorallocate($img, 100, 100, 100);
        $text_col = imagecolorallocate($img, 60, 60, 60);
        $sh_col = imagecolorallocate($img, 255, 200, 200);
        $max = 0;
        for ($i = 0; $i < 100; $i++) {
            $day_start = mktime(0, 0, 0, date('m'), date('d') - $i);
            $day_finish = mktime(0, 0, 0, date('m'), date('d') - $i + 1);
            $user_t = @mysql_result(@mysql_query("SELECT COUNT(*) FROM `user` WHERE `date_reg` >= '$day_start' AND `date_reg` < '$day_finish'"), 0);
            $max = max($max, $user_t);
            $user_reg[$i] = $user_t;
        }
        for ($i = 0; $i < 100; $i++) {
            $x = 119 - $i;
            $y1 = 49;
            imageline($img, $x, 0, $x, $i % 30 ? 1 : 5, $sh_col);
            $y2 = 49 - intval(40 * ($max ? ($user_reg[$i] / $max) : 0));
            imageline($img, $x, $y1, $x, $y2, $line_col);
        }
        imagestring($img, 1, 3, 1, "max:$max", $text_col);
        @ob_end_clean();
        header("Content-type: image/png");
        imagepng($img);
        break;
    case '4':
        $img = imagecreatetruecolor(120, 50);
        imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
        $line_col = imagecolorallocate($img, 100, 100, 100);
        $text_col = imagecolorallocate($img, 60, 60, 60);
        $sh_col = imagecolorallocate($img, 255, 200, 200);
        $max = 0;
        for ($i = 0; $i < 100; $i++) {
            $day_start = mktime(0, 0, 0, date('m'), date('d') - $i);
            $day_finish = mktime(0, 0, 0, date('m'), date('d') - $i + 1);
            $forum_t = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_t` WHERE `time_create` >= '$day_start' AND `time_create` < '$day_finish'"), 0);
            $max = max($max, $forum_t);
            $forum_themes[$i] = $forum_t;
        }
        for ($i = 0; $i < 100; $i++) {
            $x = 119 - $i;
            $y1 = 49;
            imageline($img, $x, 0, $x, $i % 30 ? 1 : 5, $sh_col);
            $y2 = 49 - intval(40 * ($max ? ($forum_themes[$i] / $max) : 0));
            imageline($img, $x, $y1, $x, $y2, $line_col);
        }
        imagestring($img, 1, 3, 1, "max:$max", $text_col);
        @ob_end_clean();
        header("Content-type: image/png");
        imagepng($img);
        break;
    case '5':
        $img = imagecreatetruecolor(120, 50);
        imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
        $line_col = imagecolorallocate($img, 100, 100, 100);
        $text_col = imagecolorallocate($img, 60, 60, 60);
        $sh_col = imagecolorallocate($img, 255, 200, 200);
        $max = 0;
        for ($i = 0; $i < 100; $i++) {
            $day_start = mktime(0, 0, 0, date('m'), date('d') - $i);
            $day_finish = mktime(0, 0, 0, date('m'), date('d') - $i + 1);
            $forum_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_p` WHERE `time` >= '$day_start' AND `time` < '$day_finish'"), 0);
            $max = max($max, $forum_p);
            $forum_posts[$i] = $forum_p;
        }
        for ($i = 0; $i < 100; $i++) {
            $x = 119 - $i;
            $y1 = 49;
            imageline($img, $x, 0, $x, $i % 30 ? 1 : 5, $sh_col);
            $y2 = 49 - intval(40 * ($max ? ($forum_posts[$i] / $max) : 0));
            imageline($img, $x, $y1, $x, $y2, $line_col);
        }
        imagestring($img, 1, 3, 1, "max:$max", $text_col);
        @ob_end_clean();
        header("Content-type: image/png");
        imagepng($img);
        break;
}
if (user::access('adm_panel_show')) {
    echo "<div class = 'list-group-item'><a href = '/panel/'><span class='fa fa-arrow-left'></span> Панель управления</a></div>";
}
require_once H . 'sys/inc/tfoot.php';