<?php defined( '_BIGNIGHT_EXEC' ) or die( 'Restricted access' );?>
<?php
	global $user;
	require_once("include/admin_profile.php");
?>
<?php

	$DB = DB::Open();
	$limit = get_page_limit();
	$sql = "SELECT SQL_CALC_FOUND_ROWS u.*, r.rank, COUNT(e.username) AS cnt_events, COUNT(s.subscriber) AS cnt_subs
			FROM users u 
				LEFT JOIN 
					events e ON e.username=u.username 
				LEFT JOIN 
					subscriptions s ON u.username=s.host 
				LEFT JOIN
					ranks r ON u.permissions=r.id
			WHERE u.permissions>0
			GROUP BY u.username ORDER BY u.username ASC {$limit};";
	$result = $DB->qry($sql);
	$total = $DB->qry("SELECT FOUND_ROWS();",3);
	if ($DB->numrows()===0){
		echo "No users found";
	} else {
		display_users($result,$total);
	}
	
?>