<?php

$qcalls = 0;
$queue = "";
if(isset($_POST['queue'])){ $queue = $_POST['queue']; }

  require_once('./phpagi/phpagi-asmanager.php');

  $asm = new AGI_AsteriskManager();
  if($asm->connect())
  {
    $result = $asm->Command("queue show $queue");
  }
  $asm->disconnect();

// ECHO THE CALLS WAITING

   echo "Calls waiting<br /><br />";

    if(!strpos($result['data'], ':'))
      echo $peer['data'];
    else
    {
      $data = array();
      echo "<table class='table table-condensed table-striped'>";
      echo "<tr class='heading-medium';><td>Position</td><td>Call wait time</td></tr>";

      foreach(explode("\n", $result['data']) as $line)
      {

         if (preg_match("/wait/i", $line)) {
          $pieces2 = preg_split('/ +/', $line);
          echo "<tr>";
          echo "<td class='medium';>".trim($pieces2[1], ".")." </td> ";
          echo "<td class='medium';>".trim($pieces2[4], ",")." </td> ";
          echo "</tr>";
      }

      }
      echo "</table>";
    }

echo "</td><td>";

?>
