LICENSE: AGPLv2 # # CHANGES # 81026-2026 - First build # 81107-0341 - Added time range and option and 15-minute increment graph # 81107-1148 - Added average times and totals # 81108-0922 - Added no-callerID and unique caller counts # 90310-2056 - Admin header # 90508-0644 - Changed to PHP long tags # 91112-0719 - Added in-group names to select list # 100214-1421 - Sort menu alphabetically # 100301-1401 - Added popup date selector # 100712-1324 - Added system setting slave server option # require("dbconnect.php"); $PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; $PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; $PHP_SELF=$_SERVER['PHP_SELF']; if (isset($_GET["group"])) {$group=$_GET["group"];} elseif (isset($_POST["group"])) {$group=$_POST["group"];} if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} if (isset($_GET["end_date"])) {$end_date=$_GET["end_date"];} elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];} if (isset($_GET["shift"])) {$shift=$_GET["shift"];} elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} if (isset($_GET["submit"])) {$submit=$_GET["submit"];} elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} if (isset($_GET["DB"])) {$DB=$_GET["DB"];} elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} $PHP_AUTH_USER = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_USER); $PHP_AUTH_PW = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_PW); if (strlen($shift)<2) {$shift='ALL';} $report_name = 'Inbound IVR Report'; $db_source = 'M'; ############################################# ##### START SYSTEM_SETTINGS LOOKUP ##### $stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db FROM system_settings;"; $rslt=mysql_query($stmt, $link); if ($DB) {echo "$stmt\n";} $qm_conf_ct = mysql_num_rows($rslt); if ($qm_conf_ct > 0) { $row=mysql_fetch_row($rslt); $non_latin = $row[0]; $outbound_autodial_active = $row[1]; $slave_db_server = $row[2]; $reports_use_slave_db = $row[3]; } ##### END SETTINGS LOOKUP ##### ########################################### if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) { mysql_close($link); $use_slave_server=1; $db_source = 'S'; require("dbconnect.php"); echo "\n"; } $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level >= 7 and view_reports='1';"; if ($DB) {echo "|$stmt|\n";} if ($non_latin > 0) {$rslt=mysql_query("SET NAMES 'UTF8'");} $rslt=mysql_query($stmt, $link); $row=mysql_fetch_row($rslt); $auth=$row[0]; if( (strlen($PHP_AUTH_USER)<2) or (strlen($PHP_AUTH_PW)<2) or (!$auth)) { Header("WWW-Authenticate: Basic realm=\"VICI-PROJECTS\""); Header("HTTP/1.0 401 Unauthorized"); echo "Invalid Username/Password: |$PHP_AUTH_USER|$PHP_AUTH_PW|\n"; exit; } $NOW_DATE = date("Y-m-d"); $NOW_TIME = date("Y-m-d H:i:s"); $STARTtime = date("U"); if (!isset($group)) {$group = '';} if (!isset($query_date)) {$query_date = "$NOW_DATE 00:00:00";} if (!isset($end_date)) {$end_date = "$NOW_DATE 23:23:59";} $stmt="select group_id,group_name from vicidial_inbound_groups order by group_id;"; $rslt=mysql_query($stmt, $link); if ($DB) {echo "$stmt\n";} $groups_to_print = mysql_num_rows($rslt); $i=0; $LISTgroups[$i]='CALLMENU'; $LISTgroups_names[$i]='IVR'; $i++; $groups_to_print++; $LISTgroups[$i]='XMLPULL'; $LISTgroups_names[$i]='Dynamic Application'; $i++; $groups_to_print++; while ($i < $groups_to_print) { $row=mysql_fetch_row($rslt); $LISTgroups[$i] = $row[0]; $LISTgroups_names[$i] = $row[1]; $i++; } $i=0; $group_string='|'; $group_ct = count($group); while($i < $group_ct) { $group_string .= "$group[$i]|"; $group_SQL .= "'$group[$i]',"; $groupQS .= "&group[]=$group[$i]"; $i++; } if ( (ereg("--NONE--",$group_string) ) or ($group_ct < 1) ) { $group_SQL = "''"; # $group_SQL = "group_id IN('')"; } else { $group_SQL = eregi_replace(",$",'',$group_SQL); # $group_SQL = "group_id IN($group_SQL)"; } $stmt="select vsc_id,vsc_name from vicidial_status_categories;"; $rslt=mysql_query($stmt, $link); if ($DB) {echo "$stmt\n";} $statcats_to_print = mysql_num_rows($rslt); $i=0; while ($i < $statcats_to_print) { $row=mysql_fetch_row($rslt); $vsc_id[$i] = $row[0]; $vsc_name[$i] = $row[1]; $vsc_count[$i] = 0; $i++; } ?>
\n"; echo "| ";
if ($DB > 0)
{
echo " \n"; echo "$group_ct|$group_string|$group_SQL\n"; echo " \n"; echo "$shift|$query_date|$end_date\n"; echo " \n"; } echo "\n\n"; echo " \n\n";
if ($groups_to_print < 1)
{
echo "\n\n";
echo "PLEASE SELECT AN IN-GROUP AND DATE RANGE ABOVE AND CLICK SUBMIT\n";
}
else
{
echo "IVR Stats Report: $query_date_BEGIN to $query_date_END $NOW_TIME\n";
echo " $group_string\n";
$TOTALcalls=0;
$NOCALLERIDcalls=0;
$UNIQUEcallers=0;
$totFLOWivr_time=0;
$totFLOWtotal_time=0;
##### Grab all records for the IVR for the specified time period
$stmt="select uniqueid,extension,start_time,comment_a,comment_b,comment_d,UNIX_TIMESTAMP(start_time),phone_ext from live_inbound_log where start_time >= '$query_date_BEGIN' and start_time <= '$query_date_END' and comment_a IN($group_SQL) order by uniqueid,start_time;";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$logs_to_print = mysql_num_rows($rslt);
$p=0;
while ($p < $logs_to_print)
{
$row=mysql_fetch_row($rslt);
$uniqueid[$p] = $row[0];
$extension[$p] = $row[1];
$start_time[$p] = $row[2];
$comment_a[$p] = $row[3];
$comment_b[$p] = $row[4];
$comment_d[$p] = $row[5];
$epoch[$p] = $row[6];
$phone_ext[$p] = $row[7];
$p++;
}
### create the call flow of all calls by uniqueid
$last_uniqueid='';
$first_epoch='';
$last_epoch='';
$p=0;
$r=-1;
while ($p < $logs_to_print)
{
if ($DB > 0) {echo "$p|$uniqueid[$p]|$comment_b[$p]";}
if ($last_uniqueid === "$uniqueid[$p]")
{
$unique_calls[$r] .= "----------$comment_b[$p]";
if ($DB > 0) {echo " $r|$unique_calls[$r]\n";}
$last_epoch[$r]=$epoch[$p];
}
else
{
$r++;
$caller_id[$r]=$phone_ext[$p];
if (strlen($phone_ext[$p])<2)
{$NOCALLERIDcalls++;}
else
{
if (!ereg("_$phone_ext[$p]_",$unique_callerIDs))
{
$unique_callerIDs .= "_$phone_ext[$p]_";
$UNIQUEcallers++;
}
}
$first_epoch[$r]=$epoch[$p];
$last_epoch[$r]=$epoch[$p];
$unique_calls[$r] = $comment_b[$p];
$FLOWuniqueid[$r] = "$uniqueid[$p]";
$last_uniqueid = "$uniqueid[$p]";
if ($DB > 0) {echo " $r|$unique_calls[$r]\n";}
}
$p++;
}
### sort call flows for counting
$RAWunique_calls = $unique_calls;
if ($logs_to_print > 0)
{sort($unique_calls);}
### count each unique call flow
$last_Suniqueid='';
$p=-1;
$s=0;
while ($s <= $r)
{
if ($DB > 0) {echo "$s|$unique_calls[$s]\n";}
if ($last_Suniqueid === "$unique_calls[$s]")
{
$STunique_calls_count[$p]++;
}
else
{
$p++;
$STunique_calls[$p] = $unique_calls[$s];
$last_Suniqueid = "$unique_calls[$s]";
$STunique_calls_count[$p]=1;
}
$s++;
}
### put call flows and counts together for sorting again
$TOTALcalls=0;
$s=0;
while ($s <= $p)
{
$TOTALcalls = ($TOTALcalls + $STunique_calls_count[$s]);
$STunique_calls_count[$s] = sprintf("%07s", $STunique_calls_count[$s]);
$FLOWunique_calls[$s] = "$STunique_calls_count[$s]__________$STunique_calls[$s]";
$s++;
}
#### PRINT TOTAL CALLS INTO THIS IVR
echo "\n";
echo "Calls taken into this IVR: $TOTALcalls\n";
echo "Calls with no CallerID: $NOCALLERIDcalls\n";
echo "Unique Callers: $UNIQUEcallers\n";
echo "\n";
### sort call flows for counting
if ($p > 0)
{rsort($FLOWunique_calls);}
### put call flows and counts together for sorting again
$RUC_ct = count($RAWunique_calls);
$s=0;
while ($s <= $p)
{
$FLOWsummary = explode('__________',$FLOWunique_calls[$s]);
$FLOWsummary[0] = ($FLOWsummary[0] + 0);
$t=0;
while ($t < $RUC_ct)
{
if ($FLOWsummary[1] === "$RAWunique_calls[$t]")
{
$FLOWunique_calls_list[$s] .= "'$FLOWuniqueid[$t]',";
if ($last_epoch[$t] <= $first_epoch[$t]) {$last_epoch[$t] = ($first_epoch[$t] + 5);}
else {$last_epoch[$t] = ($last_epoch[$t] + 10);}
$FLOWivr_time[$s] = ($FLOWivr_time[$s] + ($last_epoch[$t] - $first_epoch[$t]));
}
$t++;
}
$s++;
}
### put call flows and counts together for sorting again
$s=0;
echo "+--------+--------+--------+--------+------+------+\n";
echo "| | | QUEUE | QUEUE | IVR | TOTAL|\n";
echo "| IVR | QUEUE | DROP | DROP | AVG | AVG |\n";
echo "| CALLS | CALLS | CALLS | PERCENT| TIME | TIME | CALL PATH\n";
echo "+--------+--------+--------+--------+------+------+------------\n";
while ($s <= $p)
{
$vcl_statuses = $MT;
$FLOWdrop[$s]=0;
$FLOWtotal[$s]=0;
$FLOWdropPCT[$s]=0;
$FLOWsummary = explode('__________',$FLOWunique_calls[$s]);
$FLOWsummary[0] = ($FLOWsummary[0] + 0);
$FLOWunique_calls_list[$s] = preg_replace("/,$/","",$FLOWunique_calls_list[$s]);
##### Grab all records for the IVR for the specified time period
$stmt="select status,length_in_sec from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id IN($group_SQL) and uniqueid IN($FLOWunique_calls_list[$s]);";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$vcl_statuses_to_print = mysql_num_rows($rslt);
$w=0;
while ($w < $vcl_statuses_to_print)
{
$row=mysql_fetch_row($rslt);
$vcl_statuses[$w] = $row[0];
if ( (ereg("DROP",$vcl_statuses[$w])) or (ereg("XDROP",$vcl_statuses[$w])) )
{$FLOWdrop[$s]++;}
$FLOWclose_time[$s] = ($FLOWclose_time[$s] + $row[1]);
$FLOWtotal[$s]++;
$w++;
}
if ( ($FLOWtotal[$s] > 0) and ($FLOWdrop[$s] > 0) )
{
$FLOWdropPCT[$s] = ( ($FLOWdrop[$s] / $FLOWtotal[$s]) * 100);
$FLOWdropPCT[$s] = round($FLOWdropPCT[$s], 2);
}
$FLOWsummary[0] = sprintf("%6s", $FLOWsummary[0]);
$FLOWtotal[$s] = sprintf("%6s", $FLOWtotal[$s]);
$FLOWdrop[$s] = sprintf("%6s", $FLOWdrop[$s]);
$FLOWdropPCT[$s] = sprintf("%6s", $FLOWdropPCT[$s]);
$FLOWsummary[1] = ereg_replace('----------',' / ',$FLOWsummary[1]);
$FLOWtotal_time[$s] = ($FLOWivr_time[$s] + $FLOWclose_time[$s]);
$avgFLOWivr_time[$s] = ($FLOWivr_time[$s] / $FLOWsummary[0]);
$avgFLOWivr_time[$s] = round($avgFLOWivr_time[$s], 0);
$avgFLOWivr_time[$s] = sprintf("%4s", $avgFLOWivr_time[$s]);
$avgFLOWtotal_time[$s] = ($FLOWtotal_time[$s] / $FLOWsummary[0]);
$avgFLOWtotal_time[$s] = round($avgFLOWtotal_time[$s], 0);
$avgFLOWtotal_time[$s] = sprintf("%4s", $avgFLOWtotal_time[$s]);
$totFLOWtotal_time = ($totFLOWtotal_time + $FLOWtotal_time[$s]);
$totFLOWivr_time = ($totFLOWivr_time + $FLOWivr_time[$s]);
$totFLOWtotal = ($totFLOWtotal + $FLOWtotal[$s]);
$totFLOWdrop = ($totFLOWdrop + $FLOWdrop[$s]);
echo "| $FLOWsummary[0] | $FLOWtotal[$s] | $FLOWdrop[$s] | $FLOWdropPCT[$s]%| $avgFLOWivr_time[$s] | $avgFLOWtotal_time[$s] | $FLOWsummary[1]\n";
$s++;
}
$TOTALcalls = sprintf("%6s", $TOTALcalls);
$totFLOWtotal = sprintf("%6s", $totFLOWtotal);
$totFLOWdrop = sprintf("%6s", $totFLOWdrop);
if ( ($totFLOWivr_time > 0) and ($TOTALcalls > 0) )
{$TavgFLOWivr_time = ($totFLOWivr_time / $TOTALcalls);}
$TavgFLOWivr_time = round($TavgFLOWivr_time, 0);
$TavgFLOWivr_time = sprintf("%4s", $TavgFLOWivr_time);
if ( ($totFLOWtotal_time > 0) and ($TOTALcalls > 0) )
{$TavgFLOWtotal_time = ($totFLOWtotal_time / $TOTALcalls);}
$TavgFLOWtotal_time = round($TavgFLOWtotal_time, 0);
$TavgFLOWtotal_time = sprintf("%4s", $TavgFLOWtotal_time);
if ( ($totFLOWtotal < 1) or ($totFLOWdrop < 1) )
{$totFLOWdropPCT = '0';}
else
{
$totFLOWdropPCT = (($totFLOWdrop / $totFLOWtotal) * 100);
$totFLOWdropPCT = round($totFLOWdropPCT, 0);
}
$totFLOWdropPCT = sprintf("%5s", $totFLOWdropPCT);
echo "+--------+--------+--------+--------+------+------+------------\n";
echo "| $TOTALcalls | $totFLOWtotal | $totFLOWdrop | $totFLOWdropPCT% | $TavgFLOWivr_time | $TavgFLOWtotal_time |\n";
echo "+--------+--------+--------+--------+------+------+\n";
##############################
######### TIME STATS
echo "\n";
echo "---------- TIME STATS\n";
echo "\n";
$hi_hour_count=0;
$last_full_record=0;
$i=0;
$h=0;
while ($i <= 96)
{
$stmt="select count(*) from live_inbound_log where start_time >= '$query_date $h:00:00' and start_time <= '$query_date $h:14:59' and comment_a IN($group_SQL) and comment_b='START';";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$row=mysql_fetch_row($rslt);
$hour_count[$i] = $row[0];
if ($hour_count[$i] > $hi_hour_count) {$hi_hour_count = $hour_count[$i];}
if ($hour_count[$i] > 0) {$last_full_record = $i;}
$i++;
$stmt="select count(*) from live_inbound_log where start_time >= '$query_date $h:15:00' and start_time <= '$query_date $h:29:59' and comment_a IN($group_SQL) and comment_b='START';";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$row=mysql_fetch_row($rslt);
$hour_count[$i] = $row[0];
if ($hour_count[$i] > $hi_hour_count) {$hi_hour_count = $hour_count[$i];}
if ($hour_count[$i] > 0) {$last_full_record = $i;}
$i++;
$stmt="select count(*) from live_inbound_log where start_time >= '$query_date $h:30:00' and start_time <= '$query_date $h:44:59' and comment_a IN($group_SQL) and comment_b='START';";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$row=mysql_fetch_row($rslt);
$hour_count[$i] = $row[0];
if ($hour_count[$i] > $hi_hour_count) {$hi_hour_count = $hour_count[$i];}
if ($hour_count[$i] > 0) {$last_full_record = $i;}
$i++;
$stmt="select count(*) from live_inbound_log where start_time >= '$query_date $h:45:00' and start_time <= '$query_date $h:59:59' and comment_a IN($group_SQL) and comment_b='START';";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$row=mysql_fetch_row($rslt);
$hour_count[$i] = $row[0];
if ($hour_count[$i] > $hi_hour_count) {$hi_hour_count = $hour_count[$i];}
if ($hour_count[$i] > 0) {$last_full_record = $i;}
$i++;
$h++;
}
if ($hi_hour_count < 1)
{$hour_multiplier = 0;}
else
{
$hour_multiplier = (100 / $hi_hour_count);
#$hour_multiplier = round($hour_multiplier, 0);
}
echo "\n";
echo "GRAPH IN 15 MINUTE INCREMENTS OF TOTAL CALLS TAKEN INTO THIS IVR\n";
$k=1;
$Mk=0;
$call_scale = '0';
while ($k <= 102)
{
if ($Mk >= 5)
{
$Mk=0;
if ( ($k < 1) or ($hour_multiplier <= 0) )
{$scale_num = 100;}
else
{
$scale_num=($k / $hour_multiplier);
$scale_num = round($scale_num, 0);
}
$LENscale_num = (strlen($scale_num));
$k = ($k + $LENscale_num);
$call_scale .= "$scale_num";
}
else
{
$call_scale .= " ";
$k++; $Mk++;
}
}
echo "+------+-------------------------------------------------------------------------------------------------------+-------+\n";
#echo "| HOUR | GRAPH IN 15 MINUTE INCREMENTS OF TOTAL INCOMING CALLS FOR THIS GROUP | TOTAL |\n";
echo "| HOUR |$call_scale| TOTAL |\n";
echo "+------+-------------------------------------------------------------------------------------------------------+-------+\n";
$ZZ = '00';
$i=0;
$h=4;
$hour= -1;
$no_lines_yet=1;
while ($i <= 96)
{
$char_counter=0;
$time = ' ';
if ($h >= 4)
{
$hour++;
$h=0;
if ($hour < 10) {$hour = "0$hour";}
$time = "+$hour$ZZ+";
}
if ($h == 1) {$time = " 15 ";}
if ($h == 2) {$time = " 30 ";}
if ($h == 3) {$time = " 45 ";}
$Ghour_count = $hour_count[$i];
if ($Ghour_count < 1)
{
if ( ($no_lines_yet) or ($i > $last_full_record) )
{
$do_nothing=1;
}
else
{
$hour_count[$i] = sprintf("%-5s", $hour_count[$i]);
echo "|$time|";
$k=0; while ($k <= 102) {echo " "; $k++;}
echo "| $hour_count[$i] |\n";
}
}
else
{
$no_lines_yet=0;
$Xhour_count = ($Ghour_count * $hour_multiplier);
$Yhour_count = (99 - $Xhour_count);
$hour_count[$i] = sprintf("%-5s", $hour_count[$i]);
echo "|$time|";
$k=0; while ($k <= $Xhour_count) {echo "*"; $k++; $char_counter++;}
echo "*X"; $char_counter++;
$k=0; while ($k <= $Yhour_count) {echo " "; $k++; $char_counter++;}
while ($char_counter <= 101) {echo " "; $char_counter++;}
echo "| $hour_count[$i] |\n";
}
$i++;
$h++;
}
echo "+------+-------------------------------------------------------------------------------------------------------+-------+\n\n";
$ENDtime = date("U");
$RUNtime = ($ENDtime - $STARTtime);
echo "\nRun Time: $RUNtime seconds|$db_source\n";
}
?>
|