";
if ($edate != "" && $sdate != "") {
echo "Showing entries between $sdate (incl) and $edate (excl).";
} else if ($edate != "") {
echo "Showing entries before $edate (excl).";
} else if ($sdate != "") {
echo "Showing entries after $sdate (incl).";
}
echo "";
}
$db = pg_pconnect($dbspec);
$where = "WHERE 1=1";
if ($n_direction == 1) $where = $where." AND incoming='f'";
if ($n_direction == 2) $where = $where." AND incoming='t'";
if ($sdate != "") $where = $where." AND _timestamp >= '$sdate'";
if ($edate != "") $where = $where." AND _timestamp < '$edate'";
$q = pg_query($db, "SELECT CASE WHEN SUBSTRING(remote_msn FROM 1 FOR 3)='".$local_prefix."' THEN SUBSTRING(TRIM(remote_msn) FROM 4) ELSE TRIM(remote_msn) END, CASE WHEN incoming='t' THEN 'Incoming' ELSE 'Outgoing' END, participant, TO_CHAR(_timestamp, 'DD.MM.YYYY HH24:MI'), CASE WHEN duration > 60 THEN duration/60||'m '||duration%60||'s' ELSE duration||'s' END FROM pgets_accounting ".$where." ORDER BY _timestamp ".$order);
$num = pg_numrows($q);
if ($num == 0) {
echo "