<?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: index.php 940 2017-09-07 20:12:42Z reddawg $
*
* ***************************************************************************************
*/
/* Main include info */
ini_set ( 'include_path', $_SERVER ['DOCUMENT_ROOT'] . "/include/" );
include ("config.php");
/* Assign the page title */
$ubF->tpl->assign ( "PAGE_TITLE", "CDR" );
/* Main defines */
$ubF->tpl->define ( array (
"index" => "index/index_cdr.html"
) );
$ubF->tpl->define ( array (
"body" => "user/cdr/cdr.html"
) );
$ubF->session->ValidateCDR ();
if ( !isset ( $form_data ['start'] ) )
$form_data ['start'] = date ( "m/d/Y" );
if ( !isset ( $form_data ['end'] ) )
$form_data ['end'] = date ( "m/d/Y" );
$d_range = "(calldate BETWEEN '" . date ( "Y-m-d 00:00:00", strtotime ( $form_data ['start'] ) ) . "' AND '" . date ( "Y-m-d 23:59:59", strtotime ( $form_data ['end'] ) ) . "')";
$ext = $ubF->session->CDR_ext;
$f_ext = "AND (dst LIKE '" . $ext . "' or src LIKE '" . $ext . "')";
if ( !isset ( $form_data ['s_cat'] ) )
$form_data ['s_cat'] = 1;
if ( !isset ( $form_data ['s_order'] ) || $form_data ['s_order'] == 1 )
$sORD = "DESC";
else
$sORD = "ASC";
$ubF->tpl->assign ( "S_CAT", $form_data ['s_cat'] );
$ubF->tpl->assign ( "S_ORDER", $form_data ['s_order'] );
switch ( $form_data ['s_cat'] ) {
case '1' :
$s_order = "calldate $sORD";
break;
case '2' :
$s_order = "src $sORD";
break;
case '3' :
$s_order = "todid $sORD";
break;
case '4' :
$s_order = "dst $sORD";
break;
case '5' :
$s_order = "disposition $sORD";
break;
case '6' :
$s_order = "voip_server $sORD";
break;
case '7' :
$s_order = "billsec $sORD";
break;
case '8' :
$s_order = "codec_read $sORD";
break;
case '9' :
$s_order = "codec_write $sORD";
break;
default :
$s_order = "calldate $sORD";
}
$query = "SELECT calldate,src,dst,dstchannel,billsec,disposition,uniqueid,voice_file,todid,codec_read,codec_write,voip_server,accountcode FROM cdr_master WHERE accountcode = '" . $ubF->session->CDR_accountcode . "' AND $d_range $f_ext ORDER BY $s_order";
$result =$ubF->DB['cdr']->query ( $query );
$rows = "";
$total_talk = 0.00;
$ubF->session->voip_code = strtolower ( $ubF->session->voip_code );
while ( $qData = $result->fetch_assoc () ) {
if ( strlen ( $qData ['src'] ) == 10 || strlen ( $qData ['src'] ) == 11 )
$qData ['src'] = $data->libs['ubf']->localize_us_number ( $qData ['src'] );
if ( strlen ( $qData ['dst'] ) == 10 || strlen ( $qData ['dst'] ) == 11 )
$qData ['dst'] = $data->libs['ubf']->localize_us_number ( $qData ['dst'] );
if ( strlen ( $qData ['voice_file'] ) >= 5 )
$aFile = "<a href=\"/data/call_files/" . $qData ['voice_file'] . "\" target=\"_mp3\">Listen</a>";
else
$aFile = "No Recording";
if ( $qData ['dst'] == $ubF->session->voip_code . "-in" ) {
$dst = sscanf ( $qData ['dstchannel'], "SIP/" . $ubF->session->voip_code . "%d" );
$rows .= "<tr><td>" . $qData ['calldate'] . "</td><td>" . $qData ['src'] . "</td><td>" . $qData ['todid'] . "</td><td>" . $dst [0] . "</td><td>" . $qData ['billsec'] . "s</td><td>" . $qData ['disposition'] . "</td><td>$aFile</td></tr>\n";
}
else {
if ( $qData ['accountcode'] == 'ubt' ) {
switch ( $qData ['dst'] ) {
case 's' :
$dst = "Greeting";
break;
case '3' :
$dst = "Sales";
break;
case '4' :
$dst = "Billing";
break;
case '5' :
$dst = "uBix Cube Platform";
break;
case '6' :
$dst = "VoIP/Dialer";
break;
case '7' :
$dst = "Help Desk";
break;
default :
$dst = $qData ['dst'];
}
}
else
$dst = $qData ['dst'];
$rows .= "<tr><td>" . $qData ['calldate'] . "</td><td>" . $qData ['src'] . "</td><td>" . $qData ['todid'] . "</td><td>" . $dst . "</td><td>" . $qData ['billsec'] . "s</td><td>" . $qData ['disposition'] . "</td><td>$aFile</td></tr>\n";
}
$total_talk += $qData ['billsec'];
}
$ubF->tpl->assign ( "ROWS", $rows );
$ubF->tpl->assign ( "TOTAL_CALLS", $result->num_rows );
$ubF->tpl->assign ( "TOTAL_TALK", number_format ( $total_talk / 60, 2 ) );
$ubF->tpl->assign ( "START", $form_data ['start'] );
$ubF->tpl->assign ( "END", $form_data ['end'] );
$ubF->tpl->assign ( "EXT", $form_data ['ext'] );
/* Parse and print */
$ubF->tpl->assign ( "MENU", "" );
$ubF->tpl->assign ( "USER_MENU", "" );
$ubF->tpl->assign ( "_USER_INFO", "" );
// $data['tpl']->parse("MENU", array("menu"));
$ubF->tpl->parse ( "BODY", array (
"body"
) );
$ubF->tpl->parse ( "INDEX", array (
"index"
) );
$ubF->tpl->FastPrint ( "INDEX" );
?>