Skip to content
Snippets Groups Projects
Commit 5fc2e199 authored by Graham Cole's avatar Graham Cole
Browse files

sort by idle time, and split into two lists based on idleness

parent a2daf57b
No related branches found
No related tags found
No related merge requests found
<?php
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 ($hours * 3600) + ($minutes * 60) + $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;
$people[] = array(
$person = array(
"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"));
......
<div class="cbb">
<h3>Current Milliways Users</h3>
{if $people|@count < 1}
<p>No-one logged on to Milliways</p>
<p>No-one active on Milliways</p>
{else}
<ul>
{foreach name=people from=$people key=personnum item=person}
......@@ -11,3 +11,16 @@
{/if}
</div>
<div class="cbb">
<h3>Filthy Milliways Idlers</h3>
{if $idlers|@count < 1}
<p>Everyone's awake..!</p>
{else}
<ul>
{foreach name=idlers from=$idlers item=person}
<li>{$person.username} <small>({$person.idle} idle)</small></li>
{/foreach}
</ul>
{/if}
</div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment