#!/usr/local/Hughes/bin/lite
echo ("Tether Call Report\n");
$sock=msqlConnect();
if ($sock<0) {echo("ERROR : $ERRMSG\n");}
if (msqlSelectDB($sock,"tether_calls")<0) {echo("ERROR : $ERRMSG\n");}
if (msqlQuery($sock,"select user from sessions order by user")<0) {echo("ERROR : $ERRMSG\n");}
$res=msqlStoreResult();
$count=msqlNumRows($res);
$i = 0;
$j = 0;
$row=msqlFetchRow($res);
$name[0]=$row[0];
while ($i < $count)
      {
      $row=msqlFetchRow($res);
      $i = $i + 1;
      if ($name[$j] != $row[0])
         {
         $j = $j + 1;
         $name[$j] = $row[0];
         }
      }
msqlFreeResult($res);
$numusers=# $name;
echo ("Active users:\t\t$numusers\n");
if (msqlQuery($sock,"select duration from sessions")<0) {echo("ERROR : $ERRMSG\n");}
$res=msqlStoreResult();
$numcalls = msqlNumRows($res);
echo ("Number of calls:\t$numcalls\n");
$total_time = 0;
$row=msqlFetchRow($res);
$shortest = (int)$row[0];
$longest = (int)$row[0];
$i = 1;
while ($i < $numcalls)
	{
	$row=msqlFetchRow($res);
	$i = $i + 1;
	$dur = (int)$row[0];
	if ($dur < $shortest)
		{
		$shortest = $dur;
		}
	if ($dur > $longest)
		{
		$longest = $dur;
		}
	$total_time = $total_time + $dur;
	}
$total_time = $total_time / 60;
$longest = $longest / 60;
$ave_call = $total_time/$numcalls;
$total_time = $total_time / 60;
echo ("Total time:\t\t$total_time hours\n");
echo ("Average time:\t\t$ave_call minutes\n");
echo ("Shortest call:\t\t$shortest seconds\n");
echo ("Longest call:\t\t$longest minutes\n");
msqlFreeResult($res);
msqlClose($sock);
