<?php
/**
* ****************************************************************************************
* Copyright (c) 2015 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: cdr_json.php 61 2015-11-12 03:08:40Z reddawg $
*
* ***************************************************************************************
*/
/* Main include info */
ini_set ( 'include_path', $_SERVER ['DOCUMENT_ROOT'] . "/include/" );
include ("config.php");
$ubF->session->Validate_JSON ( 'U_V_', 1 );
// MrOlsen (2015-10-12) NOTE: I'm going to return no results if any required fields are missing
if ( !isset ( $ubF->data ['start'] ) )
$ubF->data ['start'] = date ( "m/d/Y H:i:s", time () - (60 * 60 * 2) );
if ( !isset ( $ubF->data ['end'] ) )
$ubF->data ['end'] = date ( "m/d/Y H:i:s" );
$d_range = "(calldate BETWEEN '" . date ( "Y-m-d H:i:s", strtotime ( $ubF->data ['start'] ) ) . "' AND '" . date ( "Y-m-d H:i:s", strtotime ( $ubF->data ['end'] ) ) . "')";
$query = "SELECT calldate,src,dst,dcontext,dstchannel,billsec,disposition,voice_file,todid,codec_read,codec_write,voip_server,accountcode,useragent,lastapp,uniqueid FROM cdr_master WHERE accountcode = '" . $ubF->session->account_code . "' AND $d_range";
system("echo '" . $ubF->session->account_code . "' >> /tmp/CDR.log");
$result =$ubF->DB['cdr']->query ( $query );
$ubF->session->account_code = strtolower ( $ubF->session->account_code );
$json_out = '{"authenticated":' . $ubF->session->auth_data ['authenticated'] . ',"data":[';
if ( $result->num_rows > 0 ) {
$cpN = 1;
while ( $qData = $result->fetch_row () ) {
if ( $qData [13] != "" )
$agt = " Agent: " . $qData [13] . " ID: " . $qData [15];
else
$agt = " ID: " . $qData [15];
if ( is_numeric ( $qData [1] ) && strlen ( $qData [1] ) >= 7 )
$qData [1] = $ubF->libs['voip']->formatPhoneNumber ( $qData [1] );
if ( is_numeric ( $qData [2] ) && strlen ( $qData [2] ) >= 7 )
$qData [2] = $ubF->libs['voip']->formatPhoneNumber ( $qData [2] );
if ( is_numeric ( $qData [8] ) && strlen ( $qData [8] ) >= 7 )
$qData [8] = $ubF->libs['voip']->formatPhoneNumber ( $qData [8] );
if ( strlen ( $qData [7] ) >= 5 ) {
$qData [7] = addslashes ( "<div id=\"cp_container_" . $cpN . "\" class=\"cp-container\"><div class=\"cp-buffer-holder\"><div class=\"cp-buffer-1\"></div><div class=\"cp-buffer-2\"></div></div><div class=\"cp-progress-holder\"><div class=\"cp-progress-1\"></div><div class=\"cp-progress-2\"></div></div><div class=\"cp-circle-control\"></div><ul class=\"cp-controls\"><li><a class=\"cp-play\" tabindex=\"1\">play</a></li><li><a class=\"cp-pause\" style=\"display:none;\" tabindex=\"1\">pause</a></li></ul><a style=\"position: relative;left: 35px;top: 4px;\" id=\"aF" . $cpN . "\" href=\"/data/call_files/" . $qData [7] . "\" download>Save</a></div>" );
$cpN++;
}
else
$qData [7] = "No Recording";
if ( (substr ( $qData [3], -4 ) == "-out") || (substr ( $qData [3], -7 ) == "-out-nm") ) {
$json_out .= '["' . $qData [0] . '","<p style=\"margin:0px;\" title=\"Codec: ' . $qData [9] . $agt . '\">' . $qData [1] . '</p>","' . $qData [8] . '","<p style=\"margin:0px;\" title=\"Codec: ' . $qData [10] . '\">' . $qData [2] . '</p>","' . gmdate ( "H:i:s", $qData [5] ) . '","' . $qData [6] . '","' . $qData [7] . '","' . $qData [11] . '"],';
}
else if ( $qData [3] == "uc-voicemail" ) {
$json_out .= '["' . $qData [0] . '","<p style=\"margin:0px;\" title=\"Codec: ' . $qData [9] . $agt . '\">' . $qData [1] . '</p>","' . $qData [8] . '","VM: ' . $qData [2] . '","' . gmdate ( "H:i:s", $qData [5] ) . '","' . $qData [6] . '","' . $qData [7] . '","' . $qData [11] . '"],';
}
else {
if ( $qData [14] == "Queue" || $qData [14] == "Dial" ) {
$pattern = '@^(?:SIP/' . $qData [12] . ')?([^-]+)@i';
preg_match ( $pattern, $qData [4], $dsts );
$qData [2] = $dsts [1];
$ctx = " Context: " . $qData [3];
unset ( $pattern );
unset ( $dsts );
}
else {
$ctx = "";
}
$json_out .= '["' . $qData [0] . '","<p style=\"margin:0px;\" title=\"Codec: ' . $qData [9] . '\">' . $qData [1] . '</p>","' . $qData [8] . '","<p style=\"margin:0px;\" title=\"Codec: ' . $qData [10] . $ctx . $agt . '\">' . $qData [2] . '","' . gmdate ( "H:i:s", $qData [5] ) . '","' . $qData [6] . '","' . $qData [7] . '","' . $qData [11] . '"],';
}
unset ( $qData );
}
$result->free ();
}
else
$json_out .= '["No Results","No Results","No Results","No Results","No Results","No Results","No Results","No Results"],';
header ( 'Content-type: application/json' );
print rtrim ( $json_out, ',' ) . ']}';
?>