<?php

/* DCMS Special
 * Дата последнего редактирования 18.01.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='/panel/'>" . lang('Панель управления') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
echo lang('Рефералы');
echo "</small></div><br />";

$k_post = mysql_result(mysql_query("SELECT COUNT(distinct(`url`)) FROM `user_ref`"), 0);
$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 = mysql_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 = mysql_fetch_assoc($q)) {
    echo "<div class='list-group-item-null'>\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>";
    echo "</small></div><br />";
}

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

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