<?php

include './core.php';

list( $stats['staffcount'] ) = $MySQL->query_first( "SELECT COUNT(*) FROM server.accounts WHERE rank > 6" );
list( $stats['allcount'] ) = $MySQL->query_first( "SELECT COUNT(*) FROM server.accounts" );

//$max_online_file = file( "max_online.txt" );
//$stats['max_online'] = $max_online_file[0];

$stats['newest_member'] = $MySQL->query_first( "SELECT name FROM server.accounts ORDER BY register_time DESC");

$MySQL->query( "DELETE FROM sessions WHERE expire <= ".time() );
list( $stats['hp_online'] ) = $MySQL->query_first( "SELECT COUNT(*) FROM sessions" );

$members_online_res = $MySQL->query( "SELECT server.accounts.name AS account_name FROM sessions, server.accounts WHERE sessions.accountid != 0 && sessions.accountid = server.accounts.accountid" );
$members_online_a = array();
while( $row = $MySQL->fetch_array( $members_online_res ) )
{
	$members_online_a[] = $row['account_name'];
}
$stats['members_online'] = implode( ', ', $members_online_a );

$stats['guest_count'] = $stats['hp_online'] - count( $members_online_a );

$stats['date'] = date("d-m-Y");
$Smarty->assign( 'stats', $stats );

$page['content'] = $Smarty->fetch( 'statistics.tpl' );

$Smarty->assign( 'page', $page );
$Smarty->display( 'main.tpl' );

?>