<?php if(!defined('FastCore')){exit('Oops!');} ?>

<h3>Источники регистраций</h3>
<div class="btn-group mb-2 text-uppercase">
<a class="btn btn-outline-dark" href="/<?=$adm;?>/referers">За 24 часа</a>
<a class="btn btn-outline-dark" href="/<?=$adm;?>/referers/all">За все время</a>
</div>
<table class="table table-bordered table-striped text-center bg-white">
<thead>
<tr>
	<th>#</th>
	<th>Источник</th>
	<th>DEP</th>
	<th>Регистраций</th>
</tr>
</thead>
<tbody>
<?PHP

if (isset($pg->segment[2]) && $pg->segment[2] == 'all') {
	$refs = $db->query('SELECT refsite, COUNT(*) AS `id` FROM db_users WHERE `id` GROUP BY refsite ORDER BY `id` DESC  LIMIT 500')->fetchAll();
}
else {
	$time=time()-86400;
	$refs = $db->query('SELECT refsite, COUNT(*) AS `id` FROM db_users WHERE reg > '.$time.' GROUP BY refsite ORDER BY `id` DESC LIMIT 100')->fetchAll();
}
$i=1;
foreach ($refs as $r) {
$ref = $r['refsite'];
if ($pg->segment[2] == 'all') {
 $sumdep = $db->query("SELECT SUM(`sum_in`) AS `sum` FROM db_users WHERE refsite = '$ref'")->fetchArray();
} else {
 $sumdep = $db->query("SELECT DATE(FROM_UNIXTIME(`reg`)) AS daily, SUM(`sum_in`) AS `sum` FROM db_users WHERE refsite = '$ref' GROUP BY DATE(FROM_UNIXTIME(`reg`))")->fetchArray();
}
?>
<tr>
<td><b><?=$i; ?> </b></td>
<td><b><?=$ref; ?></b> </td>
<td><b><?=round($sumdep['sum'],2); ?></b>  {!VAL!}</td>
<td><b><?=$r['id']; ?></b> </td>
</tr>
<?php
$i++;
}
?>
</table>