<?php
/**
* ****************************************************************************************
* Copyright (c) 2013 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: reports.php 939 2017-09-07 20:10:45Z reddawg $
*
* ***************************************************************************************
*/
/* Main include info */
ini_set ( 'include_path', $_SERVER ['DOCUMENT_ROOT'] . "/include/" );
include ("config.php");
/* Assign the page title */
$ubF->tpl->assign ( "PAGE_TITLE", "Dialer - Reports" );
/* Main defines */
$ubF->tpl->define ( array (
"index" => "user/wrapper/default.html"
) );
$ubF->tpl->define ( array (
"menu" => "user/dialer/menu.html"
) );
$ubF->tpl->define ( array (
"body" => "user/dialer/reports.html"
) );
$ubF->session->Validate ( 'U_D_', 1 );
/* Broadcast Report */
if ( !isset ( $form_data ['start_date'] ) )
$form_data ['start_date'] = date ( "Y-m-d", time () - 10000 );
if ( !isset ( $form_data ['end_date'] ) )
$form_data ['end_date'] = date ( "Y-m-d", time () - 10000 );
$query = "SELECT campaign_id,campaign_name,user_group FROM vicidial_campaigns WHERE user_group = '" . $ubF->session->press1_group . "'";
$result = $data ['as-dialer-002']->query ( $query );
$campaigns = "<option value=\"0\">Select Campaign</option>";
while ( $qData = $result->fetch_assoc () ) {
if ( in_array ( $qData ['campaign_id'], $form_data ['dialer_cid'] ) )
$campaigns .= "<option value=\"" . $qData ['campaign_id'] . "\" selected>" . $qData ['campaign_name'] . "</option>\n";
else
$campaigns .= "<option value=\"" . $qData ['campaign_id'] . "\">" . $qData ['campaign_name'] . "</option>\n";
}
$result->free ();
$rows = "";
$total_calls = 0;
$total_time = 0;
$total_tac = 0;
$total_tat = 0;
if ( isset ( $form_data ['dialer_cid'] ) && $form_data ['dialer_cid'] != 0 ) {
$query = "SELECT status,status_name FROM vicidial_statuses";
$result = $data ['as-dialer-002']->query ( $query );
while ( $qData = $result->fetch_assoc () ) {
$status [$qData ['status']] = $qData ['status_name'];
}
foreach ( $form_data ['dialer_cid'] as $key ) {
if ( $key != 0 )
if ( !isset ( $cid_where ) )
$cid_where = "campaign_id = '" . $key . "'";
else
$cid_where .= " OR campaign_id = '" . $key . "'";
}
$query = "SELECT status,SUM(length_in_sec) AS total_time,COUNT(*) AS total_calls FROM vicidial_log WHERE call_date >= '" . $form_data ['start_date'] . " 00:00:00' AND call_date <= '" . $form_data ['end_date'] . " 23:59:59' AND " . $cid_where . " GROUP BY status ORDER BY status ASC";
$result = $data ['as-dialer-002']->query ( $query );
while ( $qData = $result->fetch_assoc () ) {
$total_calls += $qData ['total_calls'];
$total_time += $qData ['total_time'];
if ( $qData ['status'] == "SVYEXT" || $qData ['status'] == "XFER" ) {
$total_tac += $qData ['total_calls'];
$total_tat += $qData ['total_time'];
}
$rows .= "<tr><td>" . $qData ['status'] . "</td><td>" . $status [$qData ['status']] . "</td><td>" . $qData ['total_calls'] . "</td><td>" . secondsToTime ( $qData ['total_time'] ) . "</td><td>" . gmdate ( "i:s", $qData ['total_time'] / $qData ['total_calls'] ) . "</td>";
$rows .= "<td>$" . $ubF->session->press1_cpm . "</td><td>$" . number_format ( ($qData ['total_time'] / 60) * $ubF->session->press1_cpm, 2 ) . "</tr>\n";
}
$result->free ();
}
$ubF->tpl->assign ( "ROWS", $rows );
$ubF->tpl->assign ( "CAMPAIGNS", $campaigns );
$ubF->tpl->assign ( "START_DATE", $form_data ['start_date'] );
$ubF->tpl->assign ( "END_DATE", $form_data ['end_date'] );
$ubF->tpl->assign ( "TOTAL_CALLS", $total_calls );
$ubF->tpl->assign ( "TOTAL_DROP", $total_drop );
$ubF->tpl->assign ( "TRANSFERED_TOTAL", $total_tac );
$ubF->tpl->assign ( "AVERAGE_TRANSFERED_CALL", secondsToTime ( $total_tat / $total_tac ) );
$ubF->tpl->assign ( "AVERAGE_CALL", secondsToTime ( $total_time / $total_calls ) );
$ubF->tpl->assign ( "TOTAL_TIME", secondsToTime ( $total_time ) );
$ubF->tpl->assign ( "TOTAL_COST", number_format ( ($total_time / 60) * $ubF->session->press1_cpm, 2 ) );
/* Parse and print */
$ubF->tpl->parse ( "MENU", array (
"menu"
) );
$ubF->tpl->parse ( "BODY", array (
"body"
) );
$ubF->tpl->parse ( "INDEX", array (
"index"
) );
$ubF->tpl->FastPrint ( "INDEX" );
function secondsToTime ( $t, $f = ':' ) {
return sprintf ( "%02d%s%02d%s%02d", floor ( $t / 3600 ), $f, ($t / 60) % 60, $f, $t % 60 );
}
?>