<?php
if (!$user->auth()){
	$core->GoToPage("/login.lm");
	die();
}
$c_u = $db->Count("users","WHERE `sid` = '".$id."' AND `lastVisit` > '".(time()-300)."'");
$c_g = $db->Count("hosts","WHERE `sid` = '".$id."' AND `timelast` > '".(time()-300)."'");
$c_o = $c_u+$c_g;
$stats = $db->getObject("SELECT * FROM `stats` WHERE `sid` = '".$user->uid."'");
if ($stats == NULL){
	$max_line = max(1, $c_o);
	echo '<script>console.warn("Error get data stats...");</script>';
} else {
	$max_line = max(1, $c_o, $stats->c_u, $stats->c_g, $stats->l_u, $stats->l_g, $stats->a_u, $stats->a_g);
}
$max_line += round(($max_line * 0.05), 0);

?>
<script>
c3.generate({
	    bindto: '#piminoff_ds',
	    data: {
			x: 'x',
			
			columns: [
				['x', 'Сейчас', 'Сегодня', 'Вчера', 'За все время'],
				['Пользователи', <?=$c_u?>, <?=$stats->c_u?>, <?=$stats->l_u?>, <?=$stats->a_u?>],
				['Гости', <?=$c_g?>, <?=$stats->c_g?>, <?=$stats->l_g?>, <?=$stats->a_g?>]
			],
			type: 'bar'
	    },
	    axis: {
		x: {
		    type: 'category',
		},

		y: {
		    max: <?=$max_line?>,
		    tick: 5,
			format: d3.format(".2f")
		}

	    },

	    legend: {
		show: true,
		position: 'inset'
	    },

	    color: {
		pattern: ['#1abc9c', '#3498db']
	    }

	});
</script>