From 5fc2e1998808b6628ab2471bf545282bd027dbf3 Mon Sep 17 00:00:00 2001 From: Graham Cole <chckens@sucs.org> Date: Wed, 13 Feb 2008 20:48:15 +0000 Subject: [PATCH] sort by idle time, and split into two lists based on idleness --- components/milliways.php | 37 ++++++++++++++++++++++++++++++++++++- templates/milliways.tpl | 15 ++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/components/milliways.php b/components/milliways.php index e5440c5..7ca7213 100644 --- a/components/milliways.php +++ b/components/milliways.php @@ -1,17 +1,52 @@ <?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")); diff --git a/templates/milliways.tpl b/templates/milliways.tpl index 8927fe4..8170155 100644 --- a/templates/milliways.tpl +++ b/templates/milliways.tpl @@ -1,7 +1,7 @@ <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> + -- GitLab