<?php
/******************************************************************************************
Copyright (c) 2013, 2014 Christopher W. Olsen <cwolsen@ubixtechnologies.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of
conditions, the following disclaimer and the list of authors. Redistributions in binary
form must reproduce the above copyright notice, this list of conditions, the following
disclaimer and the list of authors in the documentation and/or other materials provided
with the distribution. Neither the name of the uBix Cube Project nor the names of its
contributors may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
$Id: fop.php 931 2017-09-07 19:18:33Z reddawg $
*****************************************************************************************/
/* Main include info */
ini_set('include_path',$_SERVER['DOCUMENT_ROOT'] . "/include/");
include("config.php");
/* Main defines */
$data['tpl']->define(array("index" => "voip/fop.html"));
$data['session']->Validate('U_V_', 1);
//$query = "SELECT * FROM voip_ext WHERE account_number = '" . $data['session']->account_number . "' ORDER BY ext";
//$result = $data['ubix_db']->query($query);
//$query = "SELECT name FROM sippeers WHERE accountcode = '" . $data['session']->voip_code . "' ORDER BY name";
//$query = "SELECT name, talk_today, calls_today, voicemail FROM sip_stats_view WHERE accountcode = '" . $data['session']->voip_code . "' AND regseconds > " . time() . " ORDER BY name";
$query = "SELECT name, talk_today, calls_today, voicemail FROM sip_stats_view WHERE accountcode = '" . $data['session']->voip_code . "' ORDER BY name";
$result = $data['voip_db']->query($query);
$extensions = "";
while ($qData = $result->fetch_assoc()) {
$query = "SELECT clid_num, dialstring, unix_timestamp(created) as call_time FROM `call` WHERE (channel_src LIKE 'SIP/" . $qData['name'] . "%' OR channel_dst LIKE 'SIP/" . $qData['name'] . "%') AND status IS NULL ORDER BY created DESC LIMIT 1";
$eres = $data['at_db']->query($query);
$clen = 0;
if ($eres->num_rows == 1) {
$eData = $eres->fetch_assoc();
$clen = time() - $eData['call_time'];
}
else
$eData['clid_num'] = "";
if ($clen > 600)
$eC = "grey";
if ($clen > 300)
$eC = "grey";
if ($clen > 0)
$eC = "blue";
else
$eC = "green";
if ($qData['voicemail'] > 0)
$extensions .= "<div id='ext_shell' class='ext_" . $eC . "_vm'>\n";
else
$extensions .= "<div id='ext_shell' class='ext_" . $eC . "'>\n";
$extensions .= " <div class='ext_icon'>\n";
$extensions .= " <div class='ext_text'>" . $qData['display'] . "</div>\n";
if ($qData['voicemail'] > 0)
$extensions .= " <div class='ext_vmn'>" . $qData['voicemail'] . "</div>\n";
else
$extensions .= " <div> </div>\n";
$extensions .= " </div>\n";
$extensions .= " <div class='ext_detail'>\n";
$extensions .= " <div class='ext_fullname'>" . $qData['name'] . "</div>\n";
if ($qData['calls_today'] == 0)
$extensions .= " <div class='clear'><font style='font-size:10px;'>No Calls Today</font></div>\n";
else
$extensions .= " <div class='clear'><font style='font-size:10px;'>" . $qData['calls_today'] . " Calls, " . gmdate("H:i:s", $qData['talk_today']) . " Time</font></div>\n";
if ($eData['clid_num'] == "")
$extensions .= " <div class='ext_status'>No Active Call</div>\n";
else
if ($data['session']->voip_code = "hhs") {
if ($eData['dialstring'] != "") {
$eData['clid_num'] = substr($eData['dialstring'], 1, 11);
$extensions .= " <div id='call_inbound' class='ext_status_active'><a href=\"/voip/hhs.php?data[number]=" . substr($eData['clid_num'],-10) . "\" target=\"_HHS\">" . $eData['clid_num'] . "</a> " . gmdate("H:i:s", $clen) . "</div>\n";
}
else {
$extensions .= " <div id='call_outbound' class='ext_status_active'><a href=\"/voip/hhs.php?data[number]=" . substr($eData['clid_num'],-10) . "\" TARGET=\"_HHS\">" . $eData['clid_num'] . "</a> " . gmdate("H:i:s", $clen) . "</div>\n";
}
}
else {
if ($eData['dialstring'] != "" || ($eData['dialstring'] == $qData['ext']))
$extensions .= " <div id='call_inbound' class='ext_status_active'>" . $eData['clid_num'] . " " . gmdate("H:i:s", $clen) . "</div>\n";
else {
$eData['clid_num'] = substr($eData['dialstring'], 1, 10);
$extensions .= " <div id='call_outbound' class='ext_status_active'>" . $eData['clid_num'] . " " . gmdate("H:i:s", $clen) . "</div>\n";
}
}
if ($eres)
$eres->free();
$extensions .= " </div>\n";
$extensions .= "</div>\n";
}
$data['tpl']->assign("EXTENSIONS", $extensions);
/* Parse and print */
$data['tpl']->parse("INDEX", array("index"));
$data['tpl']->FastPrint("INDEX");
?>