fix viewcalls
[scannr.git] / calls.json.php
blob:a/calls.json.php -> blob:b/calls.json.php
--- a/calls.json.php
+++ b/calls.json.php
@@ -2,7 +2,7 @@
 include('common.inc.php');
 function getTGIDValuesByHour($TGID, $timeFrom, $timeTo) {
     global $conn;
-    $sth = $conn->prepare( 'select min(call_timestamp) as time, count(*), min(length), max(length), avg(length), stddev(length) from recordings
+    $sth = $conn->prepare( 'select tgid, min(call_timestamp) as time, count(*), min(length), max(length), avg(length), stddev(length) from recordings
             group by tgid, date_trunc(\'hour\', call_timestamp) order by time');
 
     $sth->execute( );
@@ -62,13 +62,17 @@
 }
 
 
-if ($action == "graph") {
+if (strpos($action,"graph") !== false) {
     $values = getTGIDValuesByHour($TGID, $timefrom, $timeto);
     $label = $TGID;
     $data = Array();
     $tzoffset = get_timezone_offset("UTC");
     foreach ($values as $value) {
-        $data[] = Array((strtotime($value['time']) + $tzoffset) * 1000, intval($value['avg']));
+        if ($action == "graphlength") {
+        $data[$value['tgid']][] = Array((strtotime($value['time']) + $tzoffset) * 1000, intval($value['avg']));
+        } else if ($action == "graphcount") {
+            $data[$value['tgid']][] = Array((strtotime($value['time']) + $tzoffset) * 1000, intval($value['count']));
+        }
     }
    echo json_encode(Array("label" => $label, "data" => $data,
             "previous" => Array(
@@ -82,5 +86,7 @@
     );
 }
 
+
+
 ?>