<?php
// Master Autoindex - Online Plugin
// ionutvmi@gmail.com 
// Sep 2012
// master-land.net


include "inc/init.php";


$links[] = mai_img("arr.gif")." Online";


include "header.php";

if($set->plugins["online_show_users"] == 0){
echo "<div class='content'>Option disabled</div>";
}else {

	$perpage=$set->perpage;

	$page=((int)$_GET['page'] == 0 ? 1 : (int)$_GET['page']);

	// get the data
	$dbary = array_reverse(unserialize(@file_get_contents(MAI_ROOT."plugins/tmp/online_dat.txt"))); 

	// sort the data so we can use it for pagination
	while(list($a,$b) = each($dbary)) $user_data[][$a]=$b;

	// set some vars
	$total = count($user_data);
	$pages=ceil($total/$perpage);
	if($page > $pages) $page=$pages;
	$start = ceil(($page - 1) * $perpage);
	$final = $start+$perpage;
	if($final > $total) $final=$total;


	echo "<div><div class='menuhead'>$total users active</div></div>";
	// looooooop
	for($i=$start; $i < $final; $i++) {

		// set some vars
		$ip=key($user_data[$i]);
		$tt=time() - $user_data[$i][$ip]['time'];
		$tp="sec";
		if ($tt>=60 && $tt<3600) {
			$tt=floor($tt / 60); 
			$tp='min'; 
		}
		// show
		echo "<div class='main_menu".($i%2==0 ? "" : "")."'>No: ".($i+1)." <br/>
		Ip: ".$ip."<br/>
		Browser: ".htmlentities($user_data[$i][$ip]['browser'])."<br/>
		$tt $tp ago
		</div>";
	}
	// pagination
	include "lib/pagination.class.php";
	$s_pages = new pag($total,$page,$perpage);
	echo "<div class='pages'>".$lang->pages.": ".$s_pages->pages."</div>";
}

include "footer.php";