function yday($time)
{
    return $time - 24 * 3600;
}
$yday_start = yday(mktime(0, 0, 0));
$yday_end = yday(mktime(23, 59, 59));
$data->setTimePeriod($yday_start, $yday_end);
echo "<h1>Data For Campaign: " . $camp . "</h1>\n";
?>
<table border="1">
    <tr>
        <th>Agent Name</th>
        <th>First Login</th>
        <th>Last Activity</th>
        <th>Time Difference</th>
    </tr>
    <?php 
foreach ($data->fetchData()->getAgents() as $agent) {
    $data->setAgent($agent);
    echo "<tr>\n";
    echo "<td>" . $agent . "</td>\n";
    $start = $data->fetchData()->getLoginTimes();
    echo "<td>" . date("H:i:s", $start) . "</td>\n";
    $end = $data->fetchData()->getLastActivity();
    echo "<td>" . date("H:i:s", $end) . "</td>\n";
    echo "<td>" . gmdate("H:i:s", $end - $start) . "</td>\n";
    echo "</tr>\n";
}
?>
</table>
 <tr>
     <th>Dispo Name</th>
     <th>Total Calls</th>
     <th>Percentage of Total</th>
     <th>Average Talk Time</th>
     <th>Average Hold Time</th>
     <th>Average Dispo Time</th>
     <th>Average Dead Time</th>
     <th>Average Handle Time</th>
     <th>Average Wrap Time</th>
 </tr>
 <?php 
 $total = $data->byInbound()->byQueue($queue)->getTotalAnswered();
 foreach ($data->byInbound()->byQueue($queue)->getTotalByDispo() as $d => $c) {
     echo "<tr>\n";
     echo "<td>" . $data->fetchData()->getDispoName($d) . "</td>\n";
     echo "<td>" . $c . "</td>\n";
     echo "<td>" . @round($c / $total * 100) . "</td>\n";
     echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->byQueue($queue)->byDispo($d)->getAVGTalkTime()) . "</td>\n";
     echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->byQueue($queue)->byDispo($d)->getAVGHoldTime()) . "</td>\n";
     echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->byQueue($queue)->byDispo($d)->getAVGDispoTime()) . "</td>\n";
     echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->byQueue($queue)->byDispo($d)->getAVGDeadTime()) . "</td>\n";
     echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->byQueue($queue)->byDispo($d)->getAVGHandleTime()) . "</td>\n";
     echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->byQueue($queue)->byDispo($d)->getAVGWrapTime()) . "</td>\n";
     echo "</tr>\n";
 }
 echo "<tr>\n";
 echo "<td><b>Total</b></td>\n";
 echo "<td>" . $total . "</td>\n";
 echo "<td>100%</td>\n";
 echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->byQueue($queue)->getAVGTalkTime()) . "</td>\n";
$data->setTimePeriod($yday_start, $yday_end);
echo "<h1>Data For Campaign: " . $camp . "</h1>\n";
?>
<table border="1">
    <tr>
        <th>Agent Name</th>
        <th>Calls Answered</th>
        <th>Average Talk Time</th>
        <th>Average Park Time</th>
        <th>Average Dispo Time</th>
        <th>Average Dead Time</th>
        <th>Average Handle Time</th>
        <th>Average Wrap Time</th>
    </tr>
<?php 
foreach ($data->fetchData()->getAgents() as $agent) {
    $data->setAgent($agent);
    echo "<tr>\n";
    echo "<td>" . $agent . "</td>\n";
    echo "<td>" . $data->byInbound()->byQueue($data->byInbound()->queues)->getTotalAnswered() . "</td>\n";
    echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->getAVGTalkTime()) . "</td>\n";
    echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->getAVGHoldTime()) . "</td>\n";
    echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->getAVGDispoTime()) . "</td>\n";
    echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->getAVGDeadTime()) . "</td>\n";
    echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->getAVGHandleTime()) . "</td>\n";
    echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->getAVGWrapTime()) . "</td>\n";
    echo "</tr>\n";
}
$data->setAgent(NULL);
echo "<tr>\n";
echo "<td><b>Total</b></td>\n";
<?php

require "../config.php";
$camp = @$_GET['camp'] != "" ? $_GET['camp'] : 'CS';
$data = new Campaign($camp);
$yday_start = mktime(0, 0, 0) - 24 * 3600;
$yday_end = mktime(23, 59, 59) - 24 * 3600;
$data->setTimePeriod($yday_start, $yday_end);
echo "<h1>Data For Campaign: " . $camp . "</h1>\n";
foreach ($data->fetchData()->getAgents() as $agent) {
    $data->setAgent($agent);
    echo "<h2>Agent: " . $agent . "</h2>\n";
    ?>
<table border="1">
    <tr>
        <th>Dispo Name</th>
        <th>Total Calls</th>
        <th>Percentage of Total</th>
        <th>Average Talk Time</th>
        <th>Average Hold Time</th>
        <th>Average Dispo Time</th>
        <th>Average Dead Time</th>
        <th>Average Handle Time</th>
        <th>Average Wrap Time</th>
    </tr>
    <?php 
    $queues = $data->byInbound()->queues;
    if (($key = array_search("AGENTDIRECT", $queues)) !== false) {
        unset($queues[$key]);
    }
    $total = $data->byInbound()->byQueue($queues)->getTotalAnswered();
        <th>Direct %</th>
        <th>Calls Answered</th>
        <th>% Answered</th>
        <th>% SLA of Ans</th>
        <th>OOH</th>
        <th>% OOH</th>
        <th>Drop</th>
        <th>% Drop</th>
        <th>Avg Handle</th>
        <th>Avg Wait</th>
        <th>Avg Wrap</th>
    </tr>
    <?php 
foreach ($data->byInbound()->queues as $queue) {
    echo "<tr>\n";
    echo "<td>" . $data->fetchData()->getQueueName($queue) . "</td>\n";
    echo "<td>" . $data->byInbound()->byQueue($queue)->getTotalOffered() . "</td>\n";
    echo "<td>" . $data->byInbound()->byQueue($queue)->getTotalDirectOffered() . "</td>\n";
    echo "<td>" . @round($data->byInbound()->byQueue($queue)->getTotalDirectOffered() / $data->byInbound()->byQueue($queue)->getTotalOffered() * 100) . "%</td>\n";
    echo "<td>" . $data->byInbound()->byQueue($queue)->getTotalAnswered() . "</td>\n";
    echo "<td>" . @round($data->byInbound()->byQueue($queue)->getTotalAnswered() / $data->byInbound()->byQueue($queue)->getTotalOffered() * 100) . "%</td>\n";
    echo "<td>N/A</td>\n";
    echo "<td>" . $data->byInbound()->byQueue($queue)->getTotalOOH() . "</td>\n";
    echo "<td>" . @round($data->byInbound()->byQueue($queue)->getTotalOOH() / $data->byInbound()->byQueue($queue)->getTotal() * 100) . "%</td>\n";
    echo "<td>" . $data->byInbound()->byQueue($queue)->getTotalDrop() . "</td>\n";
    echo "<td>" . @round($data->byInbound()->byQueue($queue)->getTotalDrop() / $data->byInbound()->byQueue($queue)->getTotalOffered() * 100) . "%</td>\n";
    echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->byQueue($queue)->getAVGHandleTime()) . "</td>\n";
    echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->byQueue($queue)->getAVGWaitTime()) . "</td>\n";
    echo "<td>" . gmdate("H:i:s", (int) $data->byInbound()->fetchCallTimes()->byQueue($queue)->getAVGWrapTime()) . "</td>\n";
    echo "</tr>\n";
}