LICENSE: AGPLv2 # # CHANGES # # 81026-2026 - First build # 81107-0341 - Added time range and option and 15-minute increment graph # 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';} ############################################# ##### START SYSTEM_SETTINGS LOOKUP ##### $stmt = "SELECT use_non_latin FROM system_settings;"; $rslt=mysql_query($stmt, $link); if ($DB) {echo "$stmt\n";} $qm_conf_ct = mysql_num_rows($rslt); $i=0; while ($i < $qm_conf_ct) { $row=mysql_fetch_row($rslt); $non_latin = $row[0]; $i++; } ##### END SETTINGS LOOKUP ##### ########################################### $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 from vicidial_inbound_groups;"; $rslt=mysql_query($stmt, $link); if ($DB) {echo "$stmt\n";} $groups_to_print = mysql_num_rows($rslt); $i=0; $LISTgroups[$i]='---NONE---'; $i++; $groups_to_print++; while ($i < $groups_to_print) { $row=mysql_fetch_row($rslt); $LISTgroups[$i] =$row[0]; $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 "VICIDIAL: IVR Stats\n"; 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"; echo "\n"; echo "
\n"; echo "\n"; echo "Date Range:
\n"; echo "\n"; echo " to \n"; echo "
\n"; echo "Inbound Groups: \n"; echo "\n"; echo "\n"; echo "\n"; echo "           "; echo "MODIFY | "; echo "REPORTS | "; echo "CLOSER REPORT \n"; echo "\n"; echo "
\n"; #echo "\n"; echo "Shift: \n"; echo "   \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 "VICIDIAL: IVR Stats: $group_string          $NOW_TIME\n";







##### Grab all records for the IVR for the specified time period
$stmt="select uniqueid,extension,start_time,comment_a,comment_b,comment_d 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];
	$p++;
	}

### create the call flow of all calls by uniqueid
$last_uniqueid='';
$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";}
		}
	else
		{
		$r++;
		$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 "\nCalls taken into this IVR:   $TOTALcalls\n\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]',";
			}
		$t++;
		}

	$s++;
	}


### put call flows and counts together for sorting again
$s=0;

echo "+--------+--------+--------+--------+\n";
echo "| IVR    | QUEUE  | QDROP  | QDROP% | 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 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]))
			{$FLOWdrop[$s]++;}
		$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]);

	echo "| $FLOWsummary[0] | $FLOWtotal[$s] | $FLOWdrop[$s] | $FLOWdropPCT[$s]%| $FLOWsummary[1]\n";

	$s++;
	}

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\n";
}



?>