<?php

/* DCMS Special
 * Дата последнего редактирования 13.10.2016
 * Модифицировал densnet
 */

foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'adm_check', 'user') as $inc) {
    require_once "../sys/inc/$inc.php";
}

access('adm_ref', null, 'index.php?' . SID);
adm_check();

$set['title'] = lang('Рефералы');

require_once H . 'sys/inc/thead.php';

aut();

#Навигация
echo "<div class='list-group-item-null list-group-item-grey'><small>";
echo "<a href='/' class='hint--right' data-hint='" . lang('На главную') . "'><i class='fa fa-home fa-lg'></i></a> <i class='fa fa-angle-right fa-fw'></i> ";
echo "<a href='" . DIR_PANEL . "'>" . lang('Панель управления') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
echo lang('Рефералы');
echo "</small></div><br />";

$kp = $db->super_query("SELECT COUNT(distinct(`url`)) as count FROM `user_ref`");
$k_post = $kp['count'];
$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];

if ($k_post == 0) {
    $doc->NoResult();
}

$q = $db->query("SELECT COUNT(`url`) AS `count`, MAX(`time`) AS `time`, `url` FROM `user_ref` GROUP BY `url` ORDER BY `count` DESC LIMIT $start, $set[p_str]");
while ($ref = $db->get_row($q)) {
    echo "<div class='list-group-item-null-mini list-group-item-grey dop'>\n";
    echo "URL: <a target='_blank' href='/go.php?go=" . base64_encode("http://$ref[url]") . "'>" . htmlentities($ref['url']) . "</a><br />\n";
    echo "Переходов: $ref[count]<br />";
    echo "Последний: " . date::time($ref['time']);
    echo "</div>";
}

if ($k_page > 1) {
    str("?", $k_page, $page);
}

require_once H . 'sys/inc/tfoot.php';
