Skip to content
Snippets Groups Projects
milliways.php 1.45 KiB
Newer Older
function parseIdleTime($idletime) {
	$idlearray = preg_split("/[hms]/",$idletime);
	if (strstr('h', $idletime)) {
		$hours = $idlearray[0];
		$minutes = $idlearray[1];
		$seconds = 0;
	} elseif (strstr('m', $idletime)) {
		$hours = 0;
		$minutes = $idlearray[0];
		$seconds = $idlearray[1];
	} else {
		$hours = 0;
		$minutes = 0;
		$seconds = $idlearray[0];
	}

	return (intval($hours * 3600)) + (intval($minutes) * 60) + intval($seconds);

}

function compare_idletime($a, $b) {
	return strnatcmp($a['idleseconds'], $b['idleseconds']);
}

exec("/usr/bin/mw -who", $wholist, $ret);
$people = array();
foreach ($wholist as $person) {
    $pid = strtok($person, " ");
    if ($pid == "" || $pid == "Name" || substr($pid,0,5)=="-----") continue;
	"username" => trim(substr($person, 1, 16)),
	"idle"     => trim(substr($person, 18, 6)),
	"idleseconds" => parseIdleTime(trim(substr($person, 18, 6))),
	"what"     => substr($person,25));
	if ($person['idleseconds'] > 3600) {
		$idlers[] = $person;
	} else {
		$people[] = $person;
	}
usort($people, 'compare_idletime');
usort($idlers, 'compare_idletime');


$smarty->assign("people",$people);
$smarty->assign("idlers",$idlers);
$output = $smarty->fetch($base."templates/milliways.tpl");
$smarty->assign("title", "Milliways");
$smarty->assign("body", file_get_contents($base."static/fragments/Milliways.txt"));
$smarty->assign("secondary", $output);
$smarty->assign("refresh", 120);
?>