fix viewcalls
[scannr.git] / viewcalls.php
blob:a/viewcalls.php -> blob:b/viewcalls.php
<?php <?php
include('common.inc.php'); include('common.inc.php');
$tgid = 44028; $tgid = 44028;
  $from = (isset($_REQUEST['from']) ? $_REQUEST['from'] : strtotime("2012-09-12"));
  $to = (isset($_REQUEST['to']) ? $_REQUEST['to'] : strtotime("2012-12-12"));
include_header("fdds"); include_header("fdds");
  $sth = $conn->prepare('select distinct date_trunc(\'day\', call_timestamp) as rdate from recordings order by rdate');
   
  $sth->execute();
  foreach ($sth->fetchAll() as $row) {
  echo '<a href="?from=' . strtotime($row['rdate']) . '&amp;to=' . strtotime($row['rdate'] . ' +1 day') . '">' . $row['rdate'] . '</a> <br>';
  }
   
?> ?>
<div class="span12"> <div class="span12">
   
<table width="100%" height="375px"><tr><td valign="middle"><span class="arrow-w" style="font-size:2em;">&lt;</span></td><td width="95%"><div id="placeholder" style="width:100%;height:375px;"></div></td><td valign="middle"><span class="arrow-e" style="font-size:2em;">&gt;</span></td></tr></table> <table width="100%" height="775px">
<script> <tr>
  <td valign="middle"><span class="arrow-w" style="font-size:2em;">&lt;</span></td>
  <td width="95%">
  <div id="placeholder" style="width:100%;height:575px;"></div>
  </td>
  <td valign="middle"><span class="arrow-e" style="font-size:2em;">&gt;</span></td>
  </tr>
  </table>
  <script>
var data = []; var data = [];
var plot; var plot;
var options = { var options = {
lines: { show: true }, lines: { show: true },
points: { show: true }, points: { show: true },
xaxis: { mode: "time" }, xaxis: {
crosshair: { mode: "x" }, mode: 'time',
  labelsAngle: 45
  },
  selection: { mode: 'x', fps: 30 },
series: { series: {
lines: { show: true }, lines: { show: true },
points: { show: true } points: { show: true }
}, },
grid: { hoverable: true, clickable: true } mouse: {
  track: true,
  relative: true
  }
}; };
$(function () { $(function () {
// graph // graph
   
   
var placeholder = document.getElementById("placeholder");  
   
var plot = Flotr.draw(placeholder, data, options);  
   
$("#placeholder").bind("plothover", function (event, pos, item) {  
   
if (item) {  
if (previousPoint != item.dataIndex) {  
previousPoint = item.dataIndex;  
   
$("#tooltip").remove();  
var x = item.datapoint[0].toFixed(2),  
y = item.datapoint[1].toFixed(2);  
var d = new Date();  
d.setTime(x);  
var time = d.getDate() + "-" + (d.getMonth()+1) + "-" + d.getFullYear()  
+ " " + d.getUTCHours() + ':'+ (d.getUTCMinutes().toString().length == 1 ? '0'+ d.getMinutes(): d.getUTCMinutes());  
   
showTooltip(item.pageX, item.pageY, var placeholder = document.getElementById("placeholder");
item.series.label + " at " + time + " = " + y);  
} drawGraph(options);
   
  // Hook into the 'flotr:select' event.
  Flotr.EventAdapter.observe(placeholder, 'flotr:select', function (area) {
   
  // Draw graph with new area
  graph = drawGraph({
  xaxis: {min: area.x1, max: area.x2, mode: 'time', labelsAngle: 45},
  yaxis: {min: area.y1, max: area.y2}
  });
  });
   
  // When graph is clicked, draw the graph with default area.
  Flotr.EventAdapter.observe(placeholder, 'flotr:click', function () {
  drawGraph();
  });
   
   
  getData('<?php echo $tgid; ?>', '<?php echo $from ?>', '<?php echo $to ?>');
   
  });
   
  // Draw graph with default options, overwriting with passed options
  function drawGraph(opts) {
   
  // Clone the options, so the 'options' variable always keeps intact.
  var o = Flotr._.extend(Flotr._.clone(options), opts || {});
   
  // Return a new graph.
  return Flotr.draw(
  placeholder,
  data,
  o
  );
  }
   
   
  function onDataReceived(series) {
  data = []
  for (var key in series.data) {
  data[data.length] = {label: key, data: series.data[key]};
} }
else { drawGraph(options);
$("#tooltip").remove(); }
previousPoint = null; function getData(sensorID, from, to) {
} $.ajax({
  url: "<?php echo $basePath; ?>calls.json.php?action=graphcount&tgid=" + sensorID + "&from=" + from + "&to=" + to,
}); method: 'GET',
  dataType: 'json',
getData('<?php echo $tgid; ?>','<?php echo strtotime("10/10/2012") ?>','<?php echo strtotime("10/21/2012") ?>'); success: onDataReceived
  });
}); }
   
function onDataReceived(series) {  
data =[]  
data[data.length] = series;  
   
plot =Flotr.draw(placeholder, data, options);  
}  
function getData(sensorID,from,to) {  
$.ajax({  
url: "<?php echo $basePath; ?>calls.json.php?action=graph&tgid="+sensorID+"&from="+from+"&to="+to,  
method: 'GET',  
dataType: 'json',  
success: onDataReceived  
});  
}  
   
function showTooltip(x, y, contents) {  
$('<div id="tooltip">' + contents + '</div>').css( {  
position: 'absolute',  
display: 'none',  
top: y + 5,  
left: x + 5,  
border: '1px solid #fdd',  
padding: '2px',  
'background-color': '#fee',  
opacity: 0.80  
}).appendTo("body").fadeIn(200);  
}  
   
   
</script> </script>
</div> </div>
<?php <?php
include_footer(); include_footer();
?> ?>