<?php
include_once ('./core/base.php');
falseauth();
include_once ('./core/head.php');

if($u['partner_utm'] != ''){

echo '<div class="b">';

echo '<div class="title">Партнерка</div>';

echo '<div class="event"><center>Здесь вы можете видеть пользователей, которые зарегистрировались по вашей UTM метке "<b>'.$u['partner_utm'].'</b>".</center></div>';
$all_enters = $base -> query('SELECT * FROM `utm` WHERE `utm_source` = "'.$u['partner_utm'].'"') -> num_rows;
$all_users = $base -> query('SELECT * FROM `users` WHERE `utm_source` = "'.$u['partner_utm'].'"') -> num_rows;
$all_donats = $base -> query('SELECT SUM(donated) AS `sum` FROM `users` WHERE `utm_source` = "'.$u['partner_utm'].'"') -> fetch_assoc();
echo '<div class="event"><center>
Всего переходов: <b>'.$all_enters.'</b><br/>
<div class="only_line"></div>
Всего пользователей: <b>'.$all_users.'</b><br/>
<div class="only_line"></div>
Сумма донатов: <b>'.$all_donats['sum'].'</b> RUB
</center></div>';

echo '<table class="table table-common" style="margin-top: 5px; border-collapse: collapse; text-align: left; font-size: 14px;">';

echo '<tr><td>Пользователь</td><td>Сумма доната</td></tr>';

$count = $base -> query('SELECT * FROM `users` WHERE `utm_source` = "'.$u['partner_utm'].'"') -> num_rows;
$k_page = k_page($count,15);
$page = page($k_page);
$start = 15 * $page - 15;
$sql = $base -> query("SELECT * FROM `users` WHERE `utm_source` = '".$u['partner_utm']."' ORDER BY `donated` DESC LIMIT $start,15");
if($count > 0){
	while($user = $sql -> fetch_assoc()){
		echo '<tr><td><a href="/user/'.$user['id'].'/">'.name($user['id']).'</a></td><td><b>'.$user['donated'].'</b> RUB</td></tr>';
	}
	if($count > '15'){
		echo str('?',$k_page,$page);
	}
}else{
	echo '<br/><center>Пользователей ещё нет.</center>';
}

echo '</table>';

echo '<a class="btn" href="/"><img src="/images/icons/back.png"> Назад</a>';
echo '</div>';

}else{
	header('Location: /');
	exit;
}


include_once ('./core/foot.php');
?>