<? require('assets/php/loader.php'); ?>
<?
$bwStats = getCallsInQueue("BW");
$pcStats = getCallsInQueue("PC|Powercode");
?>
<div class="leftColumn">
    <div class="innerColumn contentContainer round darkBg">
        <h1>Bertram</h1>
        <h2>Calls In Queue</h2>
        <div class="callNumber" id="bwCalls"><?= $bwStats["calls"] ?></div>
        <h2>Max Wait Time</h2>
        <div class="waitTime" id="bwWait"><?= $bwStats["wait"] ?></div>
    </div>
    <div class="innerColumn contentContainer round darkBg">
        <h1>Powercode</h1>
        <h2>Calls In Queue</h2>
        <div class="callNumber" id="pcCalls"><?= $pcStats["calls"] ?></div>
        <h2>Max Wait Time</h2>
        <div class="waitTime" id="pcWait"><?= $pcStats["wait"] ?></div>
    </div>
</div>
<div class="floatLeft round darkBg specialFuckers">
    <h1>Extensions</h1>
    <table border="0" cellpadding="3" cellspacing="0" width="100%" id="extensionList">
        <TR class="tableHeader">
            <TD align="left" width="35%">Agent</TD>
            <TD align="left" width="25%">Status</TD>
            <TD align="left">Call Time</TD>
            <TD align="left">Avg</TD>
            <TD align="left">Calls</TD>
        </TR>
        <?
        $extensions = newGetExtensionDetails();
        ?>
        <?
        for ($i = 0; $i < count($extensions); $i++) {
            ?>
            <tr>
                <td align="left" class="<? if ($extensions[$i]["Status"] == "Available") {
                    echo "available";
                } else {
                    echo "busy";
                } ?>">
                    <?= $extensions[$i]["Extension"] ?> <?= $extensions[$i]["FirstName"] ?>
                </td>
                <td align="left" class="<? if ($extensions[$i]["Status"] == "Available") {
                    echo "available";
                } else {
                    echo "busy";
                } ?>">
                    <? if ($extensions[$i]["Status"] == "Available") {
                        echo "Available";
                    } else {
                        echo $extensions[$i]["ExternalParty"];
                    } ?>
                </td>
                <td align="left" class="<? if ($extensions[$i]["Status"] == "Available") {
                    echo "available";
                } else {
                    echo "busy";
                } ?>">
                    <? if ($extensions[$i]["TimeOnCall"]) {
                        echo $extensions[$i]["TimeOnCall"];
                    } else {
                        echo "&nbsp;";
                    } ?>
                </td>
                <td class="tableStats" align="left">
                    <?= $extensions[$i]["AveTimeOnCall"] ?>
                </td>
                <td class="tableStats" align="left">
                    <?= $extensions[$i]["CallCount"] ?>
                </td>
            </tr>
        <? } ?>
    </table>
</div>
<div class="clear">
    <!-- -->
</div>
<div class="round darkBg queueList">
	<span>
		Bertram Support: 992
	</span>
    <span>
		Bertram Billing: 991
	</span>
    <span>
		Bertram Sales: 993
	</span>
    <span>
		Powercode Support: 831
	</span>
    <span>
		Powercode Sales: 830
	</span>
    <span id="onCallPerson">
	<?
    $onCall = getOnCall();
    $onCall = json_decode($onCall);
    $entries = $onCall->entries;
    $obj = $entries[0];
    $user = $obj->user;
    $name = $user->name;
    ?>
        On Call: <?= $name ?>
	</span>
</div>
<div class="stats darkBg round">
    <h2>Message Center</h2>
    <div id="messages">
        <?
        $messages = getMessages();
        if (is_array($messages)) {
            foreach ($messages as $message) {
                $outputMessage = $message["Message"];
                $outputTimestamp = $message["Timestamp"];
                echo "<span class=\"greyText\">$outputTimestamp:</span> $outputMessage<BR>";
            }
        } else {
            echo "No messages";
        }
        ?>
    </div>
</div>
<div class="stats darkBg round">
    <div class="floatLeft2">
        <h2>Queued Call Detail</h2>
        <table border="0" cellspacing="2">
            <tr>
                <TD class="blueText" width="150">Queue</TD>
                <TD width="250" class="blueText">Number</TD>
                <TD width="200" class="blueText">Time Waiting</TD>
            </tr>
        </table>
        <table border="0" cellspacing="2" id="queuedCalls">
            <?
            $queuedCalls = getQueuedCalls();
            for ($i = 0; $i < count($queuedCalls); $i++) {
                $QueueName = $queuedCalls[$i]["QueueName"];
                $ExternalParty = $queuedCalls[$i]["ExternalParty"];
                $TimeInQueue = $queuedCalls[$i]["TimeInQueue"];
                ?>
                <TR>
                    <TD width="150">
                        <?= $QueueName ?>
                    </TD>
                    <TD width="250" class="greyText">
                        <?= $ExternalParty ?>
                    </TD>
                    <TD width=200 class=greyText>
                        <?= $TimeInQueue ?>
                    </TD>
                </TR>
            <? } ?>
        </table>
    </div>
    <div class="floatLeft3">
        <h2>Leaderboard</h2>
        <table border="0" cellpadding="4" cellspacing="0" id="leaderBoard">
            <TR>
                <TD class="blueText" width="250">Agent</TD>
                <TD class="blueText" width="75">Calls</TD>
                <TD class="blueText">Avg Time</TD>
            </TR>
            <?
            $leaderBoard = getLeaderboard();
            for ($i = 0; $i < count($leaderBoard); $i++) {
                $FirstName = $leaderBoard[$i]["FirstName"];
                $CallCount = $leaderBoard[$i]["CallCount"];
                $AveTimeOnCall = $leaderBoard[$i]["AveTimeOnCall"];
                $medal = "medal_gold_1.png";
                if ($i == 1) {
                    $medal = "medal_silver_1.png";
                } elseif ($i == 2) {
                    $medal = "medal_bronze_1.png";
                }
                ?>
                <tr class="leaderboardStats">
                    <TD>
                        <img src="assets/images/icons/<?= $medal ?>"> <?= $FirstName ?>
                    </TD>
                    <TD>
                        <?= $CallCount ?>
                    </TD>
                    <TD>
                        <?= $AveTimeOnCall ?>
                    </TD>
                </tr>
                <?
            }
            ?>
        </table>
    </div>
    <div class="floatRightAlignLeft">
        <h2>Overall Statistics</h2>
        <table border="0" cellspacing="2">
            <tr>
                <TD width=150 class=blueText>Queue</TD>
                <TD width=150 class=blueText>Service Level</TD>
                <TD width=150 class=blueText>Abandoned</TD>
                <TD width=150 class=blueText>Total Calls</TD>
            </tr>
        </table>
        <table border="0" cellspacing="2" id="percentages">
            <?
            $BWSL = calculateServiceLevel("BW");
            $BWAbandon = calculateAbandonmentRate("BW");
            $totalCallsBW = calculateNumberCalls("BW");
            ?>
            <TR>
                <TD width="150">Bertram</TD>
                <TD width="150"><?= $BWSL ?>%</TD>
                <TD width="150"><?= $BWAbandon ?>%</TD>
                <TD width="150"><?= $totalCallsBW ?></TD>
            </TR>
            <?
            $PCSL = calculateServiceLevel("PC|Powercode");
            $PCAbandon = calculateAbandonmentRate("PC|Powercode");
            $totalCallsPC = calculateNumberCalls("PC|Powercode");
            ?>
            <TR>
                <TD width="150">Powercode</TD>
                <TD width="150"><?= $PCSL ?>%</TD>
                <TD width="150"><?= $PCAbandon ?>%</TD>
                <TD width="150"><?= $totalCallsPC ?></TD>
            </TR>
        </table>
    </div>
    <div class="clear">
        <!-- -->
    </div>

</div>

