From 83df37c8ff0dd77c3481f40e03533b869d2fb089 Mon Sep 17 00:00:00 2001 From: mattf Date: Wed, 27 Dec 2017 12:47:35 +0000 Subject: [PATCH] Added List Override setting for Default Transfer Group Added caching of inbound call stats for adapt script git-svn-id: svn://192.168.202.10@2876 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/UPGRADE | 2 + agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl | 25 +- agc_2-X/trunk/bin/AST_VDadapt.pl | 1375 +++++++++++++++-- .../trunk/extras/MySQL_AST_CREATE_tables.sql | 20 +- agc_2-X/trunk/extras/upgrade_2.14.sql | 19 + agc_2-X/trunk/www/agc/vdc_db_query.php | 22 +- agc_2-X/trunk/www/agc/vicidial.php | 6 +- agc_2-X/trunk/www/vicidial/admin.php | 57 +- agc_2-X/trunk/www/vicidial/help.php | 6 + 9 files changed, 1428 insertions(+), 104 deletions(-) diff --git a/agc_2-X/trunk/UPGRADE b/agc_2-X/trunk/UPGRADE index 314e34f9..8bedae03 100644 --- a/agc_2-X/trunk/UPGRADE +++ b/agc_2-X/trunk/UPGRADE @@ -238,6 +238,8 @@ OTHER CHANGES: 61. Added Agent Screen Time Report campaign option, to display agent time statistics in the agent screen for the current day. +62. Added List Override setting for Default Transfer Group + diff --git a/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl b/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl index 99c2add5..08251f51 100644 --- a/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl +++ b/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl @@ -125,9 +125,10 @@ # 170916-1009 - Added Asterisk 13 'h' exten for dialplan generation and triggering of AMI2 scripts # 170920-2214 - Added expired_lists_inactive option, checks once per hour # 171010-2254 - Added process debug with --DebugXXX flag and screen logging +# 171221-1628 - Added rolling of vicidial_ingroup_hour_counts records # -$build = '171010-2254'; +$build = '171221-1628'; $DB=0; # Debug flag $teodDB=0; # flag to log Timeclock End of Day processes to log file @@ -1347,6 +1348,28 @@ if ($timeclock_end_of_day_NOW > 0) $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; } + # roll vicidial_ingroup_hour_counts + if (!$Q) {print "\nProcessing vicidial_ingroup_hour_counts table...\n";} + $stmtA = "INSERT IGNORE INTO vicidial_ingroup_hour_counts_archive SELECT * from vicidial_ingroup_hour_counts where date_hour < '$today_start';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows inserted into vicidial_ingroup_hour_counts_archive table \n";} + + $rv = $sthA->err(); + if (!$rv) + { + $stmtA = "DELETE FROM vicidial_ingroup_hour_counts WHERE date_hour < '$today_start';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows deleted from vicidial_ingroup_hour_counts table \n";} + + $stmtA = "optimize table vicidial_ingroup_hour_counts;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + } ##### BEGIN max stats end of day process ##### # set OPEN max stats records to CLOSING for processing diff --git a/agc_2-X/trunk/bin/AST_VDadapt.pl b/agc_2-X/trunk/bin/AST_VDadapt.pl index 61f308ee..0c1a4011 100644 --- a/agc_2-X/trunk/bin/AST_VDadapt.pl +++ b/agc_2-X/trunk/bin/AST_VDadapt.pl @@ -45,14 +45,17 @@ # 160515-2016 - Added code for new UK OFCOM drop calculations # 161102-1029 - Fixed QM partition problem # 170724-2352 - Added option for cached hour counts for vicidial_log entries per campaign and carrier log totals +# 171221-1049 - Added caching of inbound call stats # + # constants $DB=0; # Debug flag, set to 0 for no debug messages, On an active system this will generate lots of lines of output per minute $US='__'; $MT[0]=''; $run_check=1; # concurrency check $VLhour_counts=1; # use cached hour counts for vicidial_log entries per campaign +$VCLhour_counts=1; # use cached hour counts for vicidial_closer_log entries per in-group ##### table definitions(used to force index usage for better performance): $vicidial_log = 'vicidial_log FORCE INDEX (call_date) '; @@ -3140,113 +3143,1177 @@ sub calculate_drops_inbound } # TODAY CALL AND DROP STATS - $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date';"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) + ## BEGIN CACHED HOURLY ANALYSIS: INBOUND CALLS + if ($VCLhour_counts > 0) { - @aryA = $sthA->fetchrow_array; - $iVCScalls_today[$p] = $aryA[0]; + $secH = time(); + ($HRsec,$HRmin,$HRhour,$HRmday,$HRmon,$HRyear,$HRwday,$HRyday,$HRisdst) = localtime(time); + $HRyear = ($HRyear + 1900); + $HRmon++; + $HRhour_test = $HRhour; + if ($HRmon < 10) {$HRmon = "0$HRmon";} + if ($HRmday < 10) {$HRmday = "0$HRmday";} + if ($HRhour < 10) {$HRhour = "0$HRhour";} + $VCL_today = "$HRyear-$HRmon-$HRmday"; + $VCL_current_hour_date = "$HRyear-$HRmon-$HRmday $HRhour:00:00"; + $VCL_day_start_date = "$HRyear-$HRmon-$HRmday 00:00:00"; + $VCL_current_hour_calls=0; + + ### get date-time of start of next hour ### + $VCL_next_hour = ($secH + (60 * 60)); + ($NHsec,$NHmin,$NHhour,$NHmday,$NHmon,$NHyear,$NHwday,$NHyday,$NHisdst) = localtime($VCL_next_hour); + $NHyear = ($NHyear + 1900); + $NHmon++; + if ($NHmon < 10) {$NHmon = "0$NHmon";} + if ($NHmday < 10) {$NHmday = "0$NHmday";} + $VCL_next_hour_date = "$NHyear-$NHmon-$NHmday $NHhour:00:00"; + + if ($DBX > 1) {print "STARTING CACHED HOURLY TOTAL INBOUND CALLS: |$VCL_current_hour_date|$VCL_next_hour_date|\n";} + + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_current_hour_date';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CURRENT HOUR CALLS: |$sthArows|$VCL_current_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_current_hour_date',type='CALLS',next_hour='$VCL_next_hour_date',last_update=NOW(),calls='$VCL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT count(*) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='CALLS' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} + + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='CALLS' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; + } + $sthA->finish(); + $iVCScalls_today[$p] = ($VCHC_cache_calls + $VCL_current_hour_calls); + if ($DBX) {print "VCLHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($iVCScalls_today[$p])|$stmtA|\n";} + } + else + { + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='CALLS' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $iVCScalls_today[$p] = ($iVCScalls_today[$p] + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCLHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$iVCScalls_today[$p]|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VCL_this_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_today $j:00:00' and call_date < '$VCL_today $j_next:00:00';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_this_hour_calls = $aryA[0]; + $iVCScalls_today[$p] = ($iVCScalls_today[$p] + $VCL_this_hour_calls); + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR QUERY: |$sthArows|$VCL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_today $j:00:00',type='CALLS',next_hour='$VCL_today $j_next:00:00',last_update=NOW(),calls='$VCL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $iVCScalls_today[$p] = ($iVCScalls_today[$p] + $VCL_current_hour_calls); + } + } + else + { + # midnight hour, so total is only current hour stats + $iVCScalls_today[$p] = $VCL_current_hour_calls; + if ($DBX) {print "VCLHC MIDNIGHT HOUR: |$iVCScalls_today[$p]|\n";} + } + } + ## END CACHED HOURLY ANALYSIS: INBOUND CALLS + else + { + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $iVCScalls_today[$p] = $aryA[0]; + } + $sthA->finish(); } - $sthA->finish(); if ($iVCScalls_today[$p] > 0) { # TODAY ANSWERS - $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) + ## BEGIN CACHED HOURLY ANALYSIS: INBOUND CALLS ANSWERS + if ($VCLhour_counts > 0) { - @aryA = $sthA->fetchrow_array; - $iVCSanswers_today[$p] = $aryA[0]; - } - $sthA->finish(); - - # TODAY DROPS - $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and status IN('DROP','XDROP');"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($DBX > 0) {print "$stmtA\n";} - if ($sthArows > 0) - { - @aryA = $sthA->fetchrow_array; - $iVCSdrops_today[$p] = $aryA[0]; - if ($iVCSdrops_today[$p] > 0) + $VCL_current_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_current_hour_date' and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) { - $iVCSdrops_today_pct[$p] = ( ($iVCSdrops_today[$p] / $iVCScalls_today[$p]) * 100 ); - $iVCSdrops_today_pct[$p] = sprintf("%.2f", $iVCSdrops_today_pct[$p]); - if ($iVCSanswers_today[$p] < 1) {$iVCSanswers_today[$p] = 1;} - $iVCSdrops_answers_today_pct[$p] = ( ($iVCSdrops_today[$p] / $iVCSanswers_today[$p]) * 100 ); - $iVCSdrops_answers_today_pct[$p] = sprintf("%.2f", $iVCSdrops_answers_today_pct[$p]); + @aryA = $sthA->fetchrow_array; + $VCL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CURRENT HOUR CALLS ANSWERS: |$sthArows|$VCL_current_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_current_hour_date',type='ANSWERS',next_hour='$VCL_next_hour_date',last_update=NOW(),calls='$VCL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT count(*) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='ANSWERS' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} + + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='ANSWERS' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; + } + $sthA->finish(); + $iVCSanswers_today[$p] = ($VCHC_cache_calls + $VCL_current_hour_calls); + if ($DBX) {print "VCLHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($iVCSanswers_today[$p])|$stmtA|\n";} + } + else + { + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='ANSWERS' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $iVCSanswers_today[$p] = ($iVCSanswers_today[$p] + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCLHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$iVCSanswers_today[$p]|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VCL_this_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_today $j:00:00' and call_date < '$VCL_today $j_next:00:00' and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_this_hour_calls = $aryA[0]; + $iVCSanswers_today[$p] = ($iVCSanswers_today[$p] + $VCL_this_hour_calls); + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR QUERY: |$sthArows|$VCL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_today $j:00:00',type='ANSWERS',next_hour='$VCL_today $j_next:00:00',last_update=NOW(),calls='$VCL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $iVCSanswers_today[$p] = ($iVCSanswers_today[$p] + $VCL_current_hour_calls); + } + } + else + { + # midnight hour, so total is only current hour stats + $iVCSanswers_today[$p] = $VCL_current_hour_calls; + if ($DBX) {print "VCLHC MIDNIGHT HOUR: |$iVCSanswers_today[$p]|\n";} } } - $sthA->finish(); + ## END CACHED HOURLY ANALYSIS: INBOUND CALLS ANSWERS + else + { + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $iVCSanswers_today[$p] = $aryA[0]; + } + $sthA->finish(); + } + + # TODAY DROPS + ## BEGIN CACHED HOURLY ANALYSIS: INBOUND CALLS DROPS + if ($VCLhour_counts > 0) + { + $VCL_current_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_current_hour_date' and status IN('DROP','XDROP');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CURRENT HOUR CALLS DROPS: |$sthArows|$VCL_current_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_current_hour_date',type='DROPS',next_hour='$VCL_next_hour_date',last_update=NOW(),calls='$VCL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT count(*) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='DROPS' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} + + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='DROPS' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; + } + $sthA->finish(); + $iVCSdrops_today[$p] = ($VCHC_cache_calls + $VCL_current_hour_calls); + if ($DBX) {print "VCLHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($iVCSdrops_today[$p])|$stmtA|\n";} + } + else + { + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='DROPS' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $iVCSdrops_today[$p] = ($iVCSdrops_today[$p] + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCLHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$iVCSdrops_today[$p]|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VCL_this_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_today $j:00:00' and call_date < '$VCL_today $j_next:00:00' and status IN('DROP','XDROP');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_this_hour_calls = $aryA[0]; + $iVCSdrops_today[$p] = ($iVCSdrops_today[$p] + $VCL_this_hour_calls); + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR QUERY: |$sthArows|$VCL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_today $j:00:00',type='DROPS',next_hour='$VCL_today $j_next:00:00',last_update=NOW(),calls='$VCL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $iVCSdrops_today[$p] = ($iVCSdrops_today[$p] + $VCL_current_hour_calls); + } + } + else + { + # midnight hour, so total is only current hour stats + $iVCSdrops_today[$p] = $VCL_current_hour_calls; + if ($DBX) {print "VCLHC MIDNIGHT HOUR: |$iVCSdrops_today[$p]|\n";} + } + } + ## END CACHED HOURLY ANALYSIS: INBOUND CALLS DROPS + else + { + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and status IN('DROP','XDROP');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($DBX > 0) {print "$stmtA\n";} + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $iVCSdrops_today[$p] = $aryA[0]; + } + $sthA->finish(); + } + + if ($iVCSdrops_today[$p] > 0) + { + $iVCSdrops_today_pct[$p] = ( ($iVCSdrops_today[$p] / $iVCScalls_today[$p]) * 100 ); + $iVCSdrops_today_pct[$p] = sprintf("%.2f", $iVCSdrops_today_pct[$p]); + if ($iVCSanswers_today[$p] < 1) {$iVCSanswers_today[$p] = 1;} + $iVCSdrops_answers_today_pct[$p] = ( ($iVCSdrops_today[$p] / $iVCSanswers_today[$p]) * 100 ); + $iVCSdrops_answers_today_pct[$p] = sprintf("%.2f", $iVCSdrops_answers_today_pct[$p]); + } # TODAY ANSWER PERCENT OF HOLD SECONDS one and two - $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and queue_seconds <= $answer_sec_pct_rt_stat_one and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) + ## BEGIN CACHED HOURLY ANALYSIS: INBOUND CALLS HOLD SECONDS 1 + if ($VCLhour_counts > 0) { - @aryA = $sthA->fetchrow_array; - $answer_sec_pct_rt_stat_one_PCT[$p] = $aryA[0]; - } - $sthA->finish(); + $VCL_current_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_current_hour_date' and queue_seconds <= $answer_sec_pct_rt_stat_one and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CURRENT HOUR CALLS HOLD SECONDS 1: |$sthArows|$VCL_current_hour_calls|$stmtA|\n";} - $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and queue_seconds <= $answer_sec_pct_rt_stat_two and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) - { - @aryA = $sthA->fetchrow_array; - $answer_sec_pct_rt_stat_two_PCT[$p] = $aryA[0]; + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_current_hour_date',type='HOLDSEC1',next_hour='$VCL_next_hour_date',last_update=NOW(),calls='$VCL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT count(*) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HOLDSEC1' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} + + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HOLDSEC1' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; + } + $sthA->finish(); + $answer_sec_pct_rt_stat_one_PCT[$p] = ($VCHC_cache_calls + $VCL_current_hour_calls); + if ($DBX) {print "VCLHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($answer_sec_pct_rt_stat_one_PCT[$p])|$stmtA|\n";} + } + else + { + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HOLDSEC1' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $answer_sec_pct_rt_stat_one_PCT[$p] = ($answer_sec_pct_rt_stat_one_PCT[$p] + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCLHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$answer_sec_pct_rt_stat_one_PCT[$p]|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VCL_this_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_today $j:00:00' and call_date < '$VCL_today $j_next:00:00' and queue_seconds <= $answer_sec_pct_rt_stat_one and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_this_hour_calls = $aryA[0]; + $answer_sec_pct_rt_stat_one_PCT[$p] = ($answer_sec_pct_rt_stat_one_PCT[$p] + $VCL_this_hour_calls); + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR QUERY: |$sthArows|$VCL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_today $j:00:00',type='HOLDSEC1',next_hour='$VCL_today $j_next:00:00',last_update=NOW(),calls='$VCL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $answer_sec_pct_rt_stat_one_PCT[$p] = ($answer_sec_pct_rt_stat_one_PCT[$p] + $VCL_current_hour_calls); + } + } + else + { + # midnight hour, so total is only current hour stats + $answer_sec_pct_rt_stat_one_PCT[$p] = $VCL_current_hour_calls; + if ($DBX) {print "VCLHC MIDNIGHT HOUR: |$answer_sec_pct_rt_stat_one_PCT[$p]|\n";} + } + } + ## END CACHED HOURLY ANALYSIS: INBOUND CALLS HOLD SECONDS 1 + else + { + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and queue_seconds <= $answer_sec_pct_rt_stat_one and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $answer_sec_pct_rt_stat_one_PCT[$p] = $aryA[0]; + } + $sthA->finish(); + } + + ## BEGIN CACHED HOURLY ANALYSIS: INBOUND CALLS HOLD SECONDS 2 + if ($VCLhour_counts > 0) + { + $VCL_current_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_current_hour_date' and queue_seconds <= $answer_sec_pct_rt_stat_two and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CURRENT HOUR CALLS HOLD SECONDS 2: |$sthArows|$VCL_current_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_current_hour_date',type='HOLDSEC2',next_hour='$VCL_next_hour_date',last_update=NOW(),calls='$VCL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT count(*) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HOLDSEC2' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} + + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HOLDSEC2' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; + } + $sthA->finish(); + $answer_sec_pct_rt_stat_two_PCT[$p] = ($VCHC_cache_calls + $VCL_current_hour_calls); + if ($DBX) {print "VCLHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($answer_sec_pct_rt_stat_two_PCT[$p])|$stmtA|\n";} + } + else + { + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HOLDSEC2' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $answer_sec_pct_rt_stat_two_PCT[$p] = ($answer_sec_pct_rt_stat_two_PCT[$p] + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCLHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$answer_sec_pct_rt_stat_two_PCT[$p]|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VCL_this_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_today $j:00:00' and call_date < '$VCL_today $j_next:00:00' and queue_seconds <= $answer_sec_pct_rt_stat_two and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_this_hour_calls = $aryA[0]; + $answer_sec_pct_rt_stat_two_PCT[$p] = ($answer_sec_pct_rt_stat_two_PCT[$p] + $VCL_this_hour_calls); + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR QUERY: |$sthArows|$VCL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_today $j:00:00',type='HOLDSEC2',next_hour='$VCL_today $j_next:00:00',last_update=NOW(),calls='$VCL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $answer_sec_pct_rt_stat_two_PCT[$p] = ($answer_sec_pct_rt_stat_two_PCT[$p] + $VCL_current_hour_calls); + } + } + else + { + # midnight hour, so total is only current hour stats + $answer_sec_pct_rt_stat_two_PCT[$p] = $VCL_current_hour_calls; + if ($DBX) {print "VCLHC MIDNIGHT HOUR: |$answer_sec_pct_rt_stat_two_PCT[$p]|\n";} + } + } + ## END CACHED HOURLY ANALYSIS: INBOUND CALLS HOLD SECONDS 2 + else + { + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and queue_seconds <= $answer_sec_pct_rt_stat_two and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $answer_sec_pct_rt_stat_two_PCT[$p] = $aryA[0]; + } + $sthA->finish(); } - $sthA->finish(); # TODAY TOTAL HOLD TIME FOR ANSWERED CALLS - $stmtA = "SELECT sum(queue_seconds) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) + ## BEGIN CACHED HOURLY ANALYSIS: INBOUND CALLS HOLD SEC ANSWERED + if ($VCLhour_counts > 0) { - @aryA = $sthA->fetchrow_array; - if ($aryA[0] > 0) - {$hold_sec_answer_calls[$p] = $aryA[0];} + $VCL_current_hour_calls=0; + $stmtA = "SELECT sum(queue_seconds) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_current_hour_date' and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CURRENT HOUR CALLS HOLD SECONDS OF ANSWERED CALLS: |$sthArows|$VCL_current_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_current_hour_date',type='HDSECANS',next_hour='$VCL_next_hour_date',last_update=NOW(),calls='$VCL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT sum(calls) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HDSECANS' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} + + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HDSECANS' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; + } + $sthA->finish(); + $hold_sec_answer_calls[$p] = ($VCHC_cache_calls + $VCL_current_hour_calls); + if ($DBX) {print "VCLHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($hold_sec_answer_calls[$p])|$stmtA|\n";} + } + else + { + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HDSECANS' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $hold_sec_answer_calls[$p] = ($hold_sec_answer_calls[$p] + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCLHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$hold_sec_answer_calls[$p]|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VCL_this_hour_calls=0; + $stmtA = "SELECT sum(queue_seconds) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_today $j:00:00' and call_date < '$VCL_today $j_next:00:00' and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_this_hour_calls = $aryA[0]; + $hold_sec_answer_calls[$p] = ($hold_sec_answer_calls[$p] + $VCL_this_hour_calls); + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR QUERY: |$sthArows|$VCL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_today $j:00:00',type='HDSECANS',next_hour='$VCL_today $j_next:00:00',last_update=NOW(),calls='$VCL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $hold_sec_answer_calls[$p] = ($hold_sec_answer_calls[$p] + $VCL_current_hour_calls); + } + } + else + { + # midnight hour, so total is only current hour stats + $hold_sec_answer_calls[$p] = $VCL_current_hour_calls; + if ($DBX) {print "VCLHC MIDNIGHT HOUR: |$hold_sec_answer_calls[$p]|\n";} + } + } + ## END CACHED HOURLY ANALYSIS: INBOUND CALLS HOLD SEC ANSWERED + else + { + $stmtA = "SELECT sum(queue_seconds) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + if ($aryA[0] > 0) + {$hold_sec_answer_calls[$p] = $aryA[0];} + } + $sthA->finish(); } - $sthA->finish(); # TODAY TOTAL HOLD TIME FOR DROP CALLS - $stmtA = "SELECT sum(queue_seconds) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and status IN('DROP','XDROP');"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) + ## BEGIN CACHED HOURLY ANALYSIS: INBOUND CALLS HOLD TIME DROPS + if ($VCLhour_counts > 0) { - @aryA = $sthA->fetchrow_array; - if ($aryA[0] > 0) - {$hold_sec_drop_calls[$p] = $aryA[0];} + $VCL_current_hour_calls=0; + $stmtA = "SELECT sum(queue_seconds) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_current_hour_date' and status IN('DROP','XDROP');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CURRENT HOUR CALLS HOLD SECONDS OF DROPPED CALLS: |$sthArows|$VCL_current_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_current_hour_date',type='HDSECDRP',next_hour='$VCL_next_hour_date',last_update=NOW(),calls='$VCL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT sum(calls) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HDSECDRP' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} + + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HDSECDRP' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; + } + $sthA->finish(); + $hold_sec_drop_calls[$p] = ($VCHC_cache_calls + $VCL_current_hour_calls); + if ($DBX) {print "VCLHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($hold_sec_drop_calls[$p])|$stmtA|\n";} + } + else + { + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HDSECDRP' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $hold_sec_drop_calls[$p] = ($hold_sec_drop_calls[$p] + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCLHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$hold_sec_drop_calls[$p]|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VCL_this_hour_calls=0; + $stmtA = "SELECT sum(queue_seconds) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_today $j:00:00' and call_date < '$VCL_today $j_next:00:00' and status IN('DROP','XDROP');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_this_hour_calls = $aryA[0]; + $hold_sec_drop_calls[$p] = ($hold_sec_drop_calls[$p] + $VCL_this_hour_calls); + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR QUERY: |$sthArows|$VCL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_today $j:00:00',type='HDSECDRP',next_hour='$VCL_today $j_next:00:00',last_update=NOW(),calls='$VCL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $hold_sec_drop_calls[$p] = ($hold_sec_drop_calls[$p] + $VCL_current_hour_calls); + } + } + else + { + # midnight hour, so total is only current hour stats + $hold_sec_drop_calls[$p] = $VCL_current_hour_calls; + if ($DBX) {print "VCLHC MIDNIGHT HOUR: |$hold_sec_drop_calls[$p]|\n";} + } + } + ## END CACHED HOURLY ANALYSIS: INBOUND CALLS HOLD TIME DROPS + else + { + $stmtA = "SELECT sum(queue_seconds) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and status IN('DROP','XDROP');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + if ($aryA[0] > 0) + {$hold_sec_drop_calls[$p] = $aryA[0];} + } + $sthA->finish(); } - $sthA->finish(); # TODAY TOTAL QUEUE TIME FOR QUEUE CALLS - $stmtA = "SELECT sum(queue_seconds) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date';"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) + ## BEGIN CACHED HOURLY ANALYSIS: INBOUND CALLS HOLD SEC ALL + if ($VCLhour_counts > 0) { - @aryA = $sthA->fetchrow_array; - if ($aryA[0] > 0) - {$hold_sec_queue_calls[$p] = $aryA[0];} + $VCL_current_hour_calls=0; + $stmtA = "SELECT sum(queue_seconds) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_current_hour_date';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CURRENT HOUR CALLS HOLD SECONDS OF ALL CALLS: |$sthArows|$VCL_current_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_current_hour_date',type='HDSECALL',next_hour='$VCL_next_hour_date',last_update=NOW(),calls='$VCL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT sum(calls) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HDSECALL' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} + + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HDSECALL' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; + } + $sthA->finish(); + $hold_sec_queue_calls[$p] = ($VCHC_cache_calls + $VCL_current_hour_calls); + if ($DBX) {print "VCLHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($hold_sec_queue_calls[$p])|$stmtA|\n";} + } + else + { + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='HDSECALL' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $hold_sec_queue_calls[$p] = ($hold_sec_queue_calls[$p] + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCLHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$hold_sec_queue_calls[$p]|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VCL_this_hour_calls=0; + $stmtA = "SELECT sum(queue_seconds) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_today $j:00:00' and call_date < '$VCL_today $j_next:00:00';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_this_hour_calls = $aryA[0]; + $hold_sec_queue_calls[$p] = ($hold_sec_queue_calls[$p] + $VCL_this_hour_calls); + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR QUERY: |$sthArows|$VCL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_today $j:00:00',type='HDSECALL',next_hour='$VCL_today $j_next:00:00',last_update=NOW(),calls='$VCL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $hold_sec_queue_calls[$p] = ($hold_sec_queue_calls[$p] + $VCL_current_hour_calls); + } + } + else + { + # midnight hour, so total is only current hour stats + $hold_sec_queue_calls[$p] = $VCL_current_hour_calls; + if ($DBX) {print "VCLHC MIDNIGHT HOUR: |$hold_sec_queue_calls[$p]|\n";} + } + } + ## END CACHED HOURLY ANALYSIS: INBOUND CALLS HOLD SEC ALL + else + { + $stmtA = "SELECT sum(queue_seconds) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + if ($aryA[0] > 0) + {$hold_sec_queue_calls[$p] = $aryA[0];} + } + $sthA->finish(); } - $sthA->finish(); } @@ -3305,17 +4372,147 @@ sub calculate_drops_inbound if (length($CATstatusesSQL)>2) { # FIND STATUSES IN STATUS CATEGORY - $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and status IN($CATstatusesSQL);"; - # if ($DBX) {print "|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) + ## BEGIN CACHED HOURLY ANALYSIS: INBOUND CALLS + if ($VCLhour_counts > 0) { - @aryA = $sthA->fetchrow_array; - $VSCtally = $aryA[0]; + $VCL_current_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_current_hour_date' and status IN($CATstatusesSQL);"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CURRENT HOUR CALLS CATEGORY $VSCcategory: |$sthArows|$VCL_current_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_current_hour_date',type='C_$VSCcategory',next_hour='$VCL_next_hour_date',last_update=NOW(),calls='$VCL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT count(*) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='C_$VSCcategory' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} + + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='C_$VSCcategory' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; + } + $sthA->finish(); + $VSCtally = ($VCHC_cache_calls + $VCL_current_hour_calls); + if ($DBX) {print "VCLHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($VSCtally)|$stmtA|\n";} + } + else + { + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_ingroup_hour_counts where group_id='$group_id[$p]' and type='C_$VSCcategory' and date_hour >= '$VCL_day_start_date' and date_hour < '$VCL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $VSCtally = ($VSCtally + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCLHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$VSCtally|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VCL_this_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date >= '$VCL_today $j:00:00' and call_date < '$VCL_today $j_next:00:00' and status IN($CATstatusesSQL);"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCL_this_hour_calls = $aryA[0]; + $VSCtally = ($VSCtally + $VCL_this_hour_calls); + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR QUERY: |$sthArows|$VCL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_ingroup_hour_counts SET group_id='$group_id[$p]',date_hour='$VCL_today $j:00:00',type='C_$VSCcategory',next_hour='$VCL_today $j_next:00:00',last_update=NOW(),calls='$VCL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VCL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $VSCtally = ($VSCtally + $VCL_current_hour_calls); + } + } + else + { + # midnight hour, so total is only current hour stats + $VSCtally = $VCL_current_hour_calls; + if ($DBX) {print "VCLHC MIDNIGHT HOUR: |$VSCtally|\n";} + } + } + ## END CACHED HOURLY ANALYSIS: INBOUND CALLS + else + { + $stmtA = "SELECT count(*) from $vicidial_closer_log where campaign_id='$group_id[$p]' and call_date > '$VDL_date' and status IN($CATstatusesSQL);"; + # if ($DBX) {print "|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VSCtally = $aryA[0]; + } + $sthA->finish(); } - $sthA->finish(); } $g++; if ($DBX) {print " $group_id[$p]|$VSCcategory|$VSCtally|$CATstatusesSQL|\n";} diff --git a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql index 76e7a8b4..04308d3e 100644 --- a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql +++ b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql @@ -1023,7 +1023,8 @@ local_call_time VARCHAR(10) NOT NULL DEFAULT 'campaign', web_form_address_three TEXT, status_group_id VARCHAR(20) default '', user_new_lead_limit SMALLINT(5) default '-1', -inbound_list_script_override VARCHAR(20) +inbound_list_script_override VARCHAR(20), +default_xfer_group VARCHAR(20) default '---NONE---' ) ENGINE=MyISAM; CREATE TABLE vicidial_statuses ( @@ -3795,6 +3796,19 @@ index (date_hour), unique index vclhc_hour (date_hour, type) ) ENGINE=MyISAM; +CREATE TABLE vicidial_ingroup_hour_counts ( +group_id VARCHAR(20), +date_hour DATETIME, +next_hour DATETIME, +last_update DATETIME, +type VARCHAR(22) default 'CALLS', +calls INT(9) UNSIGNED default '0', +hr TINYINT(2) default '0', +index (group_id), +index (date_hour), +unique index vihc_ingr_hour (group_id, date_hour, type) +) ENGINE=MyISAM; + CREATE TABLE vicidial_inbound_survey_log ( uniqueid VARCHAR(50) NOT NULL, lead_id INT(9) UNSIGNED NOT NULL, @@ -4018,6 +4032,8 @@ CREATE TABLE vicidial_campaign_hour_counts_archive LIKE vicidial_campaign_hour_c CREATE TABLE vicidial_carrier_hour_counts_archive LIKE vicidial_carrier_hour_counts; +CREATE TABLE vicidial_ingroup_hour_counts_archive LIKE vicidial_ingroup_hour_counts; + CREATE TABLE user_call_log_archive LIKE user_call_log; ALTER TABLE user_call_log_archive MODIFY user_call_log_id INT(9) UNSIGNED NOT NULL; @@ -4100,4 +4116,4 @@ INSERT INTO vicidial_settings_containers(container_id,container_notes,container_ UPDATE system_settings set vdc_agent_api_active='1'; -UPDATE system_settings SET db_schema_version='1528',db_schema_update_date=NOW(),reload_timestamp=NOW(); +UPDATE system_settings SET db_schema_version='1529',db_schema_update_date=NOW(),reload_timestamp=NOW(); diff --git a/agc_2-X/trunk/extras/upgrade_2.14.sql b/agc_2-X/trunk/extras/upgrade_2.14.sql index ceafb93c..f3b4868d 100644 --- a/agc_2-X/trunk/extras/upgrade_2.14.sql +++ b/agc_2-X/trunk/extras/upgrade_2.14.sql @@ -449,3 +449,22 @@ UPDATE system_settings SET db_schema_version='1527',db_schema_update_date=NOW() ALTER TABLE vicidial_campaigns MODIFY get_call_launch ENUM('NONE','SCRIPT','WEBFORM','WEBFORMTWO','WEBFORMTHREE','FORM','PREVIEW_WEBFORM','PREVIEW_WEBFORMTWO','PREVIEW_WEBFORMTHREE') default 'NONE'; UPDATE system_settings SET db_schema_version='1528',db_schema_update_date=NOW() where db_schema_version < 1528; + +CREATE TABLE vicidial_ingroup_hour_counts ( +group_id VARCHAR(20), +date_hour DATETIME, +next_hour DATETIME, +last_update DATETIME, +type VARCHAR(22) default 'CALLS', +calls INT(9) UNSIGNED default '0', +hr TINYINT(2) default '0', +index (group_id), +index (date_hour), +unique index vihc_ingr_hour (group_id, date_hour, type) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_ingroup_hour_counts_archive LIKE vicidial_ingroup_hour_counts; + +ALTER TABLE vicidial_lists ADD default_xfer_group VARCHAR(20) default '---NONE---'; + +UPDATE system_settings SET db_schema_version='1529',db_schema_update_date=NOW() where db_schema_version < 1529; diff --git a/agc_2-X/trunk/www/agc/vdc_db_query.php b/agc_2-X/trunk/www/agc/vdc_db_query.php index 9daeb145..0a32de39 100644 --- a/agc_2-X/trunk/www/agc/vdc_db_query.php +++ b/agc_2-X/trunk/www/agc/vdc_db_query.php @@ -442,10 +442,11 @@ # 171124-1158 - Added max_inbound_calls_outcome options # 171130-0314 - Added agent_screen_time_display option # 171204-1528 - Fixes for custom field duplicate fields +# 171224-1222 - Added List default_xfer_group override # -$version = '2.14-336'; -$build = '171204-1528'; +$version = '2.14-337'; +$build = '171224-1222'; $php_script = 'vdc_db_query.php'; $mel=1; # Mysql Error Log enabled = 1 $mysql_log_count=700; @@ -3804,7 +3805,7 @@ if ($ACTION == 'manDiaLnextCaLL') ##### BEGIN check for postal_code and phone time zones if alert enabled $post_phone_time_diff_alert_message=''; - $stmt="SELECT post_phone_time_diff_alert,local_call_time,owner_populate FROM vicidial_campaigns where campaign_id='$campaign';"; + $stmt="SELECT post_phone_time_diff_alert,local_call_time,owner_populate,default_xfer_group FROM vicidial_campaigns where campaign_id='$campaign';"; $rslt=mysql_to_mysqli($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00414',$user,$server_ip,$session_name,$one_mysql_log);} if ($DB) {echo "$stmt\n";} @@ -3815,6 +3816,7 @@ if ($ACTION == 'manDiaLnextCaLL') $post_phone_time_diff_alert = $row[0]; $local_call_time = $row[1]; $owner_populate = $row[2]; + $default_xfer_group = $row[3]; } if ( ($post_phone_time_diff_alert == 'ENABLED') or (preg_match("/OUTSIDE_CALLTIME/",$post_phone_time_diff_alert)) ) { @@ -4009,7 +4011,7 @@ if ($ACTION == 'manDiaLnextCaLL') ### check if there is a list_id override if (strlen($list_id) > 1) { - $stmt = "SELECT campaign_cid_override,web_form_address,web_form_address_two,web_form_address_three,list_description FROM vicidial_lists where list_id='$list_id';"; + $stmt = "SELECT campaign_cid_override,web_form_address,web_form_address_two,web_form_address_three,list_description,default_xfer_group FROM vicidial_lists where list_id='$list_id';"; $rslt=mysql_to_mysqli($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00245',$user,$server_ip,$session_name,$one_mysql_log);} if ($DB) {echo "$stmt\n";} @@ -4022,6 +4024,9 @@ if ($ACTION == 'manDiaLnextCaLL') $LISTweb_form_address_two = $row[2]; $LISTweb_form_address_three = $row[3]; $list_description = $row[4]; + $LISTdefault_xfer_group = $row[5]; + if ( (strlen($LISTdefault_xfer_group)>0) and (!preg_match("/---NONE---/",$LISTdefault_xfer_group)) ) + {$default_xfer_group = $LISTdefault_xfer_group;} } } @@ -5055,6 +5060,7 @@ if ($ACTION == 'manDiaLnextCaLL') $LeaD_InfO .= $entry_date . "\n"; $LeaD_InfO .= $status_group_gather_data . "\n"; $LeaD_InfO .= $call_date . "\n"; + $LeaD_InfO .= $default_xfer_group . "\n"; echo $LeaD_InfO; } @@ -8147,7 +8153,7 @@ if ($ACTION == 'VDADcheckINCOMING') ### Check for List ID override settings if (strlen($list_id)>0) { - $stmt = "SELECT xferconf_a_number,xferconf_b_number,xferconf_c_number,xferconf_d_number,xferconf_e_number,web_form_address,web_form_address_two,list_name,web_form_address_three,list_description,status_group_id from vicidial_lists where list_id='$list_id';"; + $stmt = "SELECT xferconf_a_number,xferconf_b_number,xferconf_c_number,xferconf_d_number,xferconf_e_number,web_form_address,web_form_address_two,list_name,web_form_address_three,list_description,status_group_id,default_xfer_group from vicidial_lists where list_id='$list_id';"; if ($DB) {echo "$stmt\n";} $rslt=mysql_to_mysqli($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00281',$user,$server_ip,$session_name,$one_mysql_log);} @@ -8175,6 +8181,8 @@ if ($ACTION == 'VDADcheckINCOMING') {$VDCL_group_web_three = $row[8];} $list_description = $row[9]; $status_group_gather_data = status_group_gather($row[10],'LIST'); + if ( (strlen($row[11]) > 0) and (!preg_match("/---NONE---/",$row[11])) ) + {$VDCL_default_xfer_group = $row[11];} } } @@ -8293,7 +8301,7 @@ if ($ACTION == 'VDADcheckINCOMING') $status_group_gather_data = status_group_gather($row[27],'INGROUP'); - $stmt = "SELECT campaign_script,xferconf_a_dtmf,xferconf_a_number,xferconf_b_dtmf,xferconf_b_number,default_group_alias,timer_action,timer_action_message,timer_action_seconds,start_call_url,dispo_call_url,xferconf_c_number,xferconf_d_number,xferconf_e_number,timer_action_destination from vicidial_campaigns where campaign_id='$campaign';"; + $stmt = "SELECT campaign_script,xferconf_a_dtmf,xferconf_a_number,xferconf_b_dtmf,xferconf_b_number,default_group_alias,timer_action,timer_action_message,timer_action_seconds,start_call_url,dispo_call_url,xferconf_c_number,xferconf_d_number,xferconf_e_number,timer_action_destination,default_xfer_group from vicidial_campaigns where campaign_id='$campaign';"; if ($DB) {echo "$stmt\n";} $rslt=mysql_to_mysqli($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00181',$user,$server_ip,$session_name,$one_mysql_log);} @@ -8329,6 +8337,8 @@ if ($ACTION == 'VDADcheckINCOMING') {$VDCL_xferconf_e_number = $row[13];} if (strlen($VDCL_timer_action_destination) < 1) {$VDCL_timer_action_destination = $row[14];} + if ( (strlen($row[15]) > 0) and (!preg_match("/---NONE---/",$row[15])) ) + {$VDCL_default_xfer_group = $row[15];} if ( ( (preg_match('/NONE/',$VDCL_ingroup_script)) and (strlen($VDCL_ingroup_script) < 5) ) or (strlen($VDCL_ingroup_script) < 1) ) { diff --git a/agc_2-X/trunk/www/agc/vicidial.php b/agc_2-X/trunk/www/agc/vicidial.php index e4c3258e..6f398baa 100644 --- a/agc_2-X/trunk/www/agc/vicidial.php +++ b/agc_2-X/trunk/www/agc/vicidial.php @@ -574,10 +574,11 @@ # 171126-1140 - Added ability to use EMAILinbound_message script variable # 171130-0226 - Added agent_screen_time_display option # 171214-2018 - Added PREVIEW_ get_call_launch options +# 171224-1244 - Added List default_xfer_group override # -$version = '2.14-544c'; -$build = '171214-2018'; +$version = '2.14-545c'; +$build = '171224-1244'; $mel=1; # Mysql Error Log enabled = 1 $mysql_log_count=87; $one_mysql_log=0; @@ -9149,6 +9150,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) entry_date = MDnextResponse_array[57]; status_group_statuses_data = MDnextResponse_array[58]; last_call_date = MDnextResponse_array[59]; + LIVE_default_xfer_group = MDnextResponse_array[60]; // build statuses list for disposition screen VARstatuses = []; diff --git a/agc_2-X/trunk/www/vicidial/admin.php b/agc_2-X/trunk/www/vicidial/admin.php index 3f55f4fc..a87c9cdf 100644 --- a/agc_2-X/trunk/www/vicidial/admin.php +++ b/agc_2-X/trunk/www/vicidial/admin.php @@ -4214,12 +4214,13 @@ else # 171126-1413 - Changes to allow for Email groups to display script tab on get_call_launch # 171130-0036 - Added agent_screen_time_display campaign setting # 171214-2045 - Added PREVIEW_ options for get_call_launch +# 171224-1220 - Added List default_xfer_group override # # make sure you have added a user to the vicidial_users MySQL table with at least user_level 9 to access this page the first time -$admin_version = '2.14-645a'; -$build = '171214-2045'; +$admin_version = '2.14-646a'; +$build = '171224-1220'; $STARTtime = date("U"); $SQLdate = date("Y-m-d H:i:s"); @@ -14725,7 +14726,7 @@ if ($ADD==411) echo "
"._QXZ("LIST MODIFIED").": $list_id\n"; - $stmt="UPDATE vicidial_lists set list_name='$list_name',campaign_id='$campaign_id',active='$active',list_description='$list_description',list_changedate='$SQLdate',reset_time='$reset_time',agent_script_override='$agent_script_override',inbound_list_script_override='$inbound_list_script_override',campaign_cid_override='$campaign_cid_override',am_message_exten_override='$am_message_exten_override',drop_inbound_group_override='$drop_inbound_group_override',xferconf_a_number='$xferconf_a_number',xferconf_b_number='$xferconf_b_number',xferconf_c_number='$xferconf_c_number',xferconf_d_number='$xferconf_d_number',xferconf_e_number='$xferconf_e_number',web_form_address='" . mysqli_real_escape_string($link, $web_form_address) . "',web_form_address_two='" . mysqli_real_escape_string($link, $web_form_address_two) . "',time_zone_setting='$time_zone_setting',inventory_report='$inventory_report',expiration_date='$expiration_date',na_call_url='" . mysqli_real_escape_string($link, $na_call_url) . "',local_call_time='$local_call_time',web_form_address_three='" . mysqli_real_escape_string($link, $web_form_address_three) . "',status_group_id='$status_group_id',user_new_lead_limit='$user_new_lead_limit' where list_id='$list_id';"; + $stmt="UPDATE vicidial_lists set list_name='$list_name',campaign_id='$campaign_id',active='$active',list_description='$list_description',list_changedate='$SQLdate',reset_time='$reset_time',agent_script_override='$agent_script_override',inbound_list_script_override='$inbound_list_script_override',campaign_cid_override='$campaign_cid_override',am_message_exten_override='$am_message_exten_override',drop_inbound_group_override='$drop_inbound_group_override',xferconf_a_number='$xferconf_a_number',xferconf_b_number='$xferconf_b_number',xferconf_c_number='$xferconf_c_number',xferconf_d_number='$xferconf_d_number',xferconf_e_number='$xferconf_e_number',web_form_address='" . mysqli_real_escape_string($link, $web_form_address) . "',web_form_address_two='" . mysqli_real_escape_string($link, $web_form_address_two) . "',time_zone_setting='$time_zone_setting',inventory_report='$inventory_report',expiration_date='$expiration_date',na_call_url='" . mysqli_real_escape_string($link, $na_call_url) . "',local_call_time='$local_call_time',web_form_address_three='" . mysqli_real_escape_string($link, $web_form_address_three) . "',status_group_id='$status_group_id',user_new_lead_limit='$user_new_lead_limit',default_xfer_group='$default_xfer_group' where list_id='$list_id';"; $rslt=mysql_to_mysqli($stmt, $link); ## QC Addition for Audited Comments @@ -25349,7 +25350,7 @@ if ($ADD==311) } } - $stmt="SELECT vicidial_lists.list_id,list_name,campaign_id,active,list_description,list_changedate,list_lastcalldate,reset_time,agent_script_override,campaign_cid_override,am_message_exten_override,drop_inbound_group_override,xferconf_a_number,xferconf_b_number,xferconf_c_number,xferconf_d_number,xferconf_e_number,web_form_address,web_form_address_two,time_zone_setting,inventory_report,IFNULL(audit_comments,0),expiration_date,DATE_FORMAT(expiration_date,'%Y%m%d'),na_call_url,local_call_time,web_form_address_three,status_group_id,user_new_lead_limit,inbound_list_script_override from vicidial_lists left outer join vicidial_lists_custom on vicidial_lists.list_id=vicidial_lists_custom.list_id where vicidial_lists.list_id='$list_id' $LOGallowed_campaignsSQL;"; + $stmt="SELECT vicidial_lists.list_id,list_name,campaign_id,active,list_description,list_changedate,list_lastcalldate,reset_time,agent_script_override,campaign_cid_override,am_message_exten_override,drop_inbound_group_override,xferconf_a_number,xferconf_b_number,xferconf_c_number,xferconf_d_number,xferconf_e_number,web_form_address,web_form_address_two,time_zone_setting,inventory_report,IFNULL(audit_comments,0),expiration_date,DATE_FORMAT(expiration_date,'%Y%m%d'),na_call_url,local_call_time,web_form_address_three,status_group_id,user_new_lead_limit,inbound_list_script_override,default_xfer_group from vicidial_lists left outer join vicidial_lists_custom on vicidial_lists.list_id=vicidial_lists_custom.list_id where vicidial_lists.list_id='$list_id' $LOGallowed_campaignsSQL;"; $rslt=mysql_to_mysqli($stmt, $link); if ($DB) {echo "$stmt\n";} @@ -25383,6 +25384,7 @@ if ($ADD==311) $status_group_id = $row[27]; $user_new_lead_limit = $row[28]; $inbound_list_script_override = $row[29]; + $default_xfer_group = $row[30]; # grab names of global statuses and statuses in the selected campaign $stmt="SELECT status,status_name,selectable,human_answered,category,sale,dnc,customer_contact,not_interested,unworkable,scheduled_callback,completed,min_sec,max_sec,answering_machine from vicidial_statuses order by status;"; @@ -25592,6 +25594,49 @@ if ($ADD==311) $sglinkE=''; } + ##### get in-groups listings for dynamic transfer group pulldown list menu + $xfer_groupsSQL=''; + $stmt="SELECT closer_campaigns,xfer_groups from vicidial_campaigns where campaign_id='$campaign_id' $LOGallowed_campaignsSQL;"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $closer_campaigns = $row[0]; + $closer_campaigns = preg_replace("/ -$/","",$closer_campaigns); + $groups = explode(" ", $closer_campaigns); + $xfer_groups = $row[1]; + $xfer_groups = preg_replace("/ -$/","",$xfer_groups); + $XFERgroups = explode(" ", $xfer_groups); + $xfer_groupsSQL = preg_replace("/^ | -$/","",$xfer_groups); + $xfer_groupsSQL = preg_replace("/ /","','",$xfer_groupsSQL); + $xfer_groupsSQL = "WHERE group_id IN('$xfer_groupsSQL')"; + + $nxLOGadmin_viewable_groupsSQL = $LOGadmin_viewable_groupsSQL; + if (strlen($xfer_groupsSQL) < 6) + {$nxLOGadmin_viewable_groupsSQL = $whereLOGadmin_viewable_groupsSQL;} + + $stmt="SELECT group_id,group_name from vicidial_inbound_groups $xfer_groupsSQL $nxLOGadmin_viewable_groupsSQL order by group_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + $Xgroups_to_print = mysqli_num_rows($rslt); + $Xgroups_menu=''; + $Xgroups_selected=0; + $o=0; + while ($Xgroups_to_print > $o) + { + $rowx=mysqli_fetch_row($rslt); + $Xgroups_menu .= "\n"; + $o++; + } + if ($Xgroups_selected < 1) + {$Xgroups_menu .= "\n";} + else + {$Xgroups_menu .= "\n";} + + echo "$sglinkB"._QXZ("Status Group Override")."$sglinkE: $NWB#lists-xferconf_a_dtmf$NWE\n"; + echo ""._QXZ("Default Transfer Group").": $NWB#lists-default_xfer_group$NWE\n"; + if ($SSuser_new_lead_limit > 0) { $stmt="SELECT no_hopper_dialing from vicidial_campaigns where campaign_id='$campaign_id' $LOGallowed_campaignsSQL;"; diff --git a/agc_2-X/trunk/www/vicidial/help.php b/agc_2-X/trunk/www/vicidial/help.php index 5ddf1076..20074820 100644 --- a/agc_2-X/trunk/www/vicidial/help.php +++ b/agc_2-X/trunk/www/vicidial/help.php @@ -145,6 +145,7 @@ # 171124-1045 - Added campaigns-max_inbound_calls_outcome entry # 171124-1353 = Added campaigns-manual_auto_next_options entry # 171130-0048 - Added agent_screen_time_display entry +# 171224-1027 - Added lists-default_xfer_group entry # require("dbconnect_mysqli.php"); @@ -2221,6 +2222,11 @@ if ($SSqc_features_active > 0)
- +
+ +
+ - +