From 20b3cd475c3994e48f723b0ec71a6585d5c442b8 Mon Sep 17 00:00:00 2001 From: mattf Date: Mon, 19 Jul 2021 02:07:46 +0000 Subject: [PATCH] Fixes for 24-Hour Call Count Limits with standard Auto-Alt-Dialing and ANYONE scheduled callbacks Added additional standard Auto-Alt-Dialing debug output git-svn-id: svn://192.168.202.10@3484 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/bin/AST_VDauto_dial.pl | 270 ++++++++++-- agc_2-X/trunk/bin/AST_VDhopper.pl | 510 ++++++++++++++--------- agc_2-X/trunk/bin/FastAGI_log.pl | 268 ++++++++++-- agc_2-X/trunk/docs/CALL_COUNT_LIMITS.txt | 10 +- agc_2-X/trunk/docs/TILTX_SHAKEN_API.txt | 5 +- agc_2-X/trunk/www/agc/vdc_db_query.php | 156 ++++--- 6 files changed, 920 insertions(+), 299 deletions(-) diff --git a/agc_2-X/trunk/bin/AST_VDauto_dial.pl b/agc_2-X/trunk/bin/AST_VDauto_dial.pl index 2bc2f0ff..7e2398db 100644 --- a/agc_2-X/trunk/bin/AST_VDauto_dial.pl +++ b/agc_2-X/trunk/bin/AST_VDauto_dial.pl @@ -140,9 +140,11 @@ # 210423-2241 - Fix for campaign ID underscore issue #1265 # 210606-1006 - Added TILTX features for pre-carrier call filtering # 210713-1322 - Added call_limit_24hour feature support +# 210718-0359 - Fixes for 24-Hour Call Count Limits with standard Auto-Alt-Dialing # -$build='210713-1322'; +$build='210718-0359'; +$script='AST_VDauto_dial'; ### begin parsing run-time options ### if (length($ARGV[0])>1) { @@ -257,6 +259,7 @@ if (!$VARDB_port) {$VARDB_port='3306';} if (!$VDADLOGfile) {$VDADLOGfile = "$PATHlogs/vdautodial.$year-$mon-$mday";} if (!$JAMdebugFILE) {$JAMdebugFILE = "$PATHlogs/vdad-JAM.$year-$mon-$mday";} +if (!$AADLOGfile) {$AADLOGfile = "$PATHlogs/auto-alt-dial.$year-$mon-$mday";} use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second use Time::Local; @@ -924,7 +927,7 @@ while($one_day_interval > 0) ### grab the dial_level and multiply by active agents to get your goalcalls $DBIPadlevel[$user_CIPct]=0; - $stmtA = "SELECT auto_dial_level,local_call_time,dial_timeout,dial_prefix,campaign_cid,active,campaign_vdad_exten,closer_campaigns,omit_phone_code,available_only_ratio_tally,auto_alt_dial,campaign_allow_inbound,queue_priority,dial_method,use_custom_cid,inbound_queue_no_dial,available_only_tally_threshold,available_only_tally_threshold_agents,dial_level_threshold,dial_level_threshold_agents,adaptive_dl_diff_target,dl_diff_target_method,inbound_no_agents_no_dial_container,inbound_no_agents_no_dial_threshold,cid_group_id,scheduled_callbacks_auto_reschedule,call_quota_lead_ranking,dial_timeout_lead_container,drop_call_seconds,drop_action,drop_inbound_group FROM vicidial_campaigns where campaign_id='$DBIPcampaign[$user_CIPct]'"; + $stmtA = "SELECT auto_dial_level,local_call_time,dial_timeout,dial_prefix,campaign_cid,active,campaign_vdad_exten,closer_campaigns,omit_phone_code,available_only_ratio_tally,auto_alt_dial,campaign_allow_inbound,queue_priority,dial_method,use_custom_cid,inbound_queue_no_dial,available_only_tally_threshold,available_only_tally_threshold_agents,dial_level_threshold,dial_level_threshold_agents,adaptive_dl_diff_target,dl_diff_target_method,inbound_no_agents_no_dial_container,inbound_no_agents_no_dial_threshold,cid_group_id,scheduled_callbacks_auto_reschedule,call_quota_lead_ranking,dial_timeout_lead_container,drop_call_seconds,drop_action,drop_inbound_group,call_limit_24hour_method,call_limit_24hour_scope,call_limit_24hour,call_limit_24hour_override FROM vicidial_campaigns where campaign_id='$DBIPcampaign[$user_CIPct]'"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -967,6 +970,10 @@ while($one_day_interval > 0) $DBIPdrop_call_seconds[$user_CIPct] = $aryA[28]; $DBIPdrop_action[$user_CIPct] = $aryA[29]; $DBIPdrop_inbound_group[$user_CIPct] = $aryA[30]; + $DBIPcall_limit_24hour_method[$user_CIPct] = $aryA[31]; + $DBIPcall_limit_24hour_scope[$user_CIPct] = $aryA[32]; + $DBIPcall_limit_24hour[$user_CIPct] = $aryA[33]; + $DBIPcall_limit_24hour_override[$user_CIPct] = $aryA[34]; # check for Dial Timeout Lead override if ( (length($DBIPdial_timeout_lead_container[$user_CIPct]) > 1) && ($DBIPdial_timeout_lead_container[$user_CIPct] !~ /^DISABLED$/i) ) @@ -2573,19 +2580,23 @@ while($one_day_interval > 0) $VD_auto_alt_dial = 'NONE'; $VD_auto_alt_dial_statuses=''; $VD_call_quota_lead_ranking='DISABLED'; - $stmtA="SELECT auto_alt_dial,auto_alt_dial_statuses,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc,call_quota_lead_ranking FROM vicidial_campaigns where campaign_id='$CLcampaign_id';"; + $stmtA="SELECT auto_alt_dial,auto_alt_dial_statuses,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc,call_quota_lead_ranking,call_limit_24hour_method,call_limit_24hour_scope,call_limit_24hour,call_limit_24hour_override FROM vicidial_campaigns where campaign_id='$CLcampaign_id';"; $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; - $VD_auto_alt_dial = $aryA[0]; - $VD_auto_alt_dial_statuses = $aryA[1]; - $VD_use_internal_dnc = $aryA[2]; - $VD_use_campaign_dnc = $aryA[3]; - $VD_use_other_campaign_dnc = $aryA[4]; - $VD_call_quota_lead_ranking = $aryA[5]; + $VD_auto_alt_dial = $aryA[0]; + $VD_auto_alt_dial_statuses = $aryA[1]; + $VD_use_internal_dnc = $aryA[2]; + $VD_use_campaign_dnc = $aryA[3]; + $VD_use_other_campaign_dnc = $aryA[4]; + $VD_call_quota_lead_ranking = $aryA[5]; + $VD_call_limit_24hour_method = $aryA[6]; + $VD_call_limit_24hour_scope = $aryA[7]; + $VD_call_limit_24hour = $aryA[8]; + $VD_call_limit_24hour_override = $aryA[9]; } $sthA->finish(); @@ -2909,11 +2920,15 @@ while($one_day_interval > 0) $event_string = "|$stmtA|$VD_auto_alt_dial|$VD_auto_alt_dial_statuses|$CLnew_status|$CLlead_id|$CLalt_dial"; &event_logger; if ( ($VD_auto_alt_dial_statuses =~ / $CLnew_status /) && ($CLlead_id > 0) ) { + $alt_skip_reason=''; $addr3_skip_reason=''; if ( ($VD_auto_alt_dial =~ /ALT_ONLY|ALT_AND_ADDR3|ALT_AND_EXTENDED/) && ($CLalt_dial =~ /NONE|MAIN/) ) { $alt_dial_skip=0; $VD_alt_phone=''; - $stmtA="SELECT alt_phone,gmt_offset_now,state,list_id FROM vicidial_list where lead_id='$CLlead_id';"; + $VD_phone_code=''; + $temp_24hour_phone=''; + $temp_24hour_phone_code=''; + $stmtA="SELECT alt_phone,gmt_offset_now,state,list_id,phone_code FROM vicidial_list where lead_id='$CLlead_id';"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -2925,6 +2940,7 @@ while($one_day_interval > 0) $VD_gmt_offset_now = $aryA[1]; $VD_state = $aryA[2]; $VD_list_id = $aryA[3]; + $VD_phone_code = $aryA[4]; } $sthA->finish(); $event_string = "|$stmtA|$VD_alt_phone|"; &event_logger; @@ -2977,23 +2993,40 @@ while($one_day_interval > 0) } if ($VD_alt_dnc_count < 1) { - $stmtA = "INSERT INTO vicidial_hopper SET lead_id='$CLlead_id',campaign_id='$CLcampaign_id',status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='ALT',user='',priority='25',source='A';"; - $affected_rows = $dbhA->do($stmtA); - $event_string = "-- VDH record inserted: |$affected_rows| |$stmtA|"; &event_logger; + $passed_24hour_call_count=1; + if ( ($SScall_limit_24hour > 0) && ($VD_call_limit_24hour_method =~ /PHONE_NUMBER|LEAD/) ) + { + $temp_24hour_phone = $VD_alt_phone; + $temp_24hour_phone_code = $VD_phone_code; + if ($DB > 0) {print "24-Hour Call Count Check: $SScall_limit_24hour|$VD_call_limit_24hour_method|$CLlead_id|\n";} + &check_24hour_call_count; + } + if ($passed_24hour_call_count > 0) + { + $stmtA = "INSERT INTO vicidial_hopper SET lead_id='$CLlead_id',campaign_id='$CLcampaign_id',status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='ALT',user='',priority='25',source='A';"; + $affected_rows = $dbhA->do($stmtA); + $event_string = "-- VDH record inserted: |$affected_rows| |$stmtA|"; &event_logger; + $aad_string = "$CLlead_id|$VD_alt_phone|$CLcampaign_id|ALT|25|hopper insert|"; &aad_output; + } + else + {$alt_dial_skip=1; $alt_skip_reason='24-hour call count limit failed';} } else - {$alt_dial_skip=1;} + {$alt_dial_skip=1; $alt_skip_reason='DNC check failed';} } else - {$alt_dial_skip=1;} + {$alt_dial_skip=1; $alt_skip_reason='ALT phone invalid';} if ($alt_dial_skip > 0) - {$CLalt_dial='ALT';} + { + $CLalt_dial='ALT'; + $aad_string = "$CLlead_id|$VD_alt_phone|$CLcampaign_id|ALT|0|hopper skip|$alt_skip_reason|"; &aad_output; + } } if ( ( ($VD_auto_alt_dial =~ /ADDR3_ONLY/) && ($CLalt_dial =~ /NONE|MAIN/) ) || ( ($VD_auto_alt_dial =~ /ALT_AND_ADDR3/) && ($CLalt_dial =~ /ALT/) ) ) { $addr3_dial_skip=0; $VD_address3=''; - $stmtA="SELECT address3,gmt_offset_now,state,list_id FROM vicidial_list where lead_id='$CLlead_id';"; + $stmtA="SELECT address3,gmt_offset_now,state,list_id,phone_code FROM vicidial_list where lead_id='$CLlead_id';"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -3005,6 +3038,7 @@ while($one_day_interval > 0) $VD_gmt_offset_now = $aryA[1]; $VD_state = $aryA[2]; $VD_list_id = $aryA[3]; + $VD_phone_code = $aryA[4]; } $sthA->finish(); $event_string = "|$stmtA|$VD_address3|"; &event_logger; @@ -3057,17 +3091,34 @@ while($one_day_interval > 0) } if ($VD_alt_dnc_count < 1) { - $stmtA = "INSERT INTO vicidial_hopper SET lead_id='$CLlead_id',campaign_id='$CLcampaign_id',status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='ADDR3',user='',priority='20',source='A';"; - $affected_rows = $dbhA->do($stmtA); - $event_string = "-- VDH record inserted: |$affected_rows| |$stmtA|"; &event_logger; + $passed_24hour_call_count=1; + if ( ($SScall_limit_24hour > 0) && ($VD_call_limit_24hour_method =~ /PHONE_NUMBER|LEAD/) ) + { + $temp_24hour_phone = $VD_address3; + $temp_24hour_phone_code = $VD_phone_code; + if ($DB > 0) {print "24-Hour Call Count Check: $SScall_limit_24hour|$VD_call_limit_24hour_method|$CLlead_id|\n";} + &check_24hour_call_count; + } + if ($passed_24hour_call_count > 0) + { + $stmtA = "INSERT INTO vicidial_hopper SET lead_id='$CLlead_id',campaign_id='$CLcampaign_id',status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='ADDR3',user='',priority='20',source='A';"; + $affected_rows = $dbhA->do($stmtA); + $event_string = "-- VDH record inserted: |$affected_rows| |$stmtA|"; &event_logger; + $aad_string = "$CLlead_id|$VD_address3|$CLcampaign_id|ADDR3|20|hopper insert|"; &aad_output; + } + else + {$addr3_dial_skip=1; $addr3_skip_reason='24-hour call count limit failed';} } else - {$addr3_dial_skip=1;} + {$addr3_dial_skip=1; $addr3_skip_reason='DNC check failed';} } else - {$addr3_dial_skip=1;} + {$addr3_dial_skip=1; $addr3_skip_reason='ADDR3 phone invalid';} if ($addr3_dial_skip > 0) - {$CLalt_dial='ADDR3';} + { + $CLalt_dial='ADDR3'; + if ($AGILOG) {$aad_string = "$CLlead_id|$VD_address3|$CLcampaign_id|ADDR3|0|hopper skip|$addr3_skip_reason|"; &aad_output;} + } } if ( ( ($VD_auto_alt_dial =~ /EXTENDED_ONLY/) && ($CLalt_dial =~ /NONE|MAIN/) ) || ( ($VD_auto_alt_dial =~ /ALT_AND_EXTENDED/) && ($CLalt_dial =~ /ALT/) ) || ( ($VD_auto_alt_dial =~ /ADDR3_AND_EXTENDED|ALT_AND_ADDR3_AND_EXTENDED/) && ($CLalt_dial =~ /ADDR3/) ) || ( ($VD_auto_alt_dial =~ /EXTENDED/) && ($CLalt_dial =~ /^X/) && ($CLalt_dial !~ /XLAST/) ) ) { @@ -3107,7 +3158,7 @@ while($one_day_interval > 0) while ( ($alt_dial_phones_count > 0) && ($alt_dial_phones_count > $Xlast) ) { $Xlast++; - $stmtA="SELECT alt_phone_id,phone_number,active FROM vicidial_list_alt_phones where lead_id='$CLlead_id' and alt_phone_count='$Xlast';"; + $stmtA="SELECT alt_phone_id,phone_number,active,phone_code FROM vicidial_list_alt_phones where lead_id='$CLlead_id' and alt_phone_count='$Xlast';"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -3117,6 +3168,7 @@ while($one_day_interval > 0) $VD_altdial_id = $aryA[0]; $VD_altdial_phone = $aryA[1]; $VD_altdial_active = $aryA[2]; + $VD_phone_code = $aryA[3]; } else {$Xlast=9999999999;} @@ -3178,25 +3230,43 @@ while($one_day_interval > 0) { if ($alt_dial_phones_count == $Xlast) {$Xlast = 'LAST';} - $stmtA = "INSERT INTO vicidial_hopper SET lead_id='$CLlead_id',campaign_id='$CLcampaign_id',status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='X$Xlast',user='',priority='15',source='A';"; - $affected_rows = $dbhA->do($stmtA); - $event_string = "-- VDH record inserted: |$affected_rows| |$stmtA|X$Xlast|$VD_altdial_id|"; &event_logger; - $Xlast=9999999999; + $passed_24hour_call_count=1; + if ( ($SScall_limit_24hour > 0) && ($VD_call_limit_24hour_method =~ /PHONE_NUMBER|LEAD/) ) + { + $temp_24hour_phone = $VD_altdial_phone; + $temp_24hour_phone_code = $VD_phone_code; + if ($DB > 0) {print "24-Hour Call Count Check: $SScall_limit_24hour|$VD_call_limit_24hour_method|$CLlead_id|\n";} + &check_24hour_call_count; + } + if ($passed_24hour_call_count > 0) + { + $stmtA = "INSERT INTO vicidial_hopper SET lead_id='$CLlead_id',campaign_id='$CLcampaign_id',status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='X$Xlast',user='',priority='15',source='A';"; + $affected_rows = $dbhA->do($stmtA); + $event_string = "-- VDH record inserted: |$affected_rows| |$stmtA|X$Xlast|$VD_altdial_id|"; &event_logger; + $aad_string = "$CLlead_id|$VD_altdial_phone|$CLcampaign_id|X$Xlast|15|hopper insert|"; &aad_output; + $DNC_hopper_trigger=0; + } + else + {$DNC_hopper_trigger=1;} } else + {$DNC_hopper_trigger=1;} + if ($DNC_hopper_trigger > 0) { - if ( ( ($VD_auto_alt_dial_statuses =~ / DNCC /) && ($DNCC > 0) ) || ( ($VD_auto_alt_dial_statuses =~ / DNCL /) && ($DNCL > 0) ) ) + if ( ( ($VD_auto_alt_dial_statuses =~ / DNCC /) && ($DNCC > 0) ) || ( ($VD_auto_alt_dial_statuses =~ / DNCL /) && ($DNCL > 0) ) || ( ($auto_alt_dial_statuses[$i] =~ / TFHCCL /) && ($TFHCCL > 0) ) ) { if ($alt_dial_phones_count == $Xlast) {$Xlast = 'LAST';} $stmtA = "INSERT INTO vicidial_hopper SET lead_id='$CLlead_id',campaign_id='$CLcampaign_id',status='DNC',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='X$Xlast',user='',priority='15',source='A';"; $affected_rows = $dbhA->do($stmtA); $event_string = "-- VDH record DNC inserted: |$affected_rows| |$stmtA|X$Xlast|$VD_altdial_id|"; &event_logger; + $aad_string = "$CLlead_id|$VD_altdial_phone|$CLcampaign_id|X$Xlast|15|hopper DNC insert|"; &aad_output; $Xlast=9999999999; } else { $event_string = "-- VDH record DNC not-inserted: |$affected_rows| |$stmtA|X$Xlast|$VD_altdial_id|"; &event_logger; + $aad_string = "$CLlead_id|$VD_altdial_phone|$CLcampaign_id|X$Xlast|15|hopper DNC skip|"; &aad_output; } } } @@ -5260,6 +5330,136 @@ sub temp_time_dialable_check } +sub check_24hour_call_count + { + $passed_24hour_call_count=0; + $limit_scopeSQL=''; + if ($VD_call_limit_24hour_scope =~ /CAMPAIGN_LISTS/) + { + $limit_scopeCAMP=''; + $stmtY = "SELECT list_id FROM vicidial_lists where campaign_id='$CLcampaign_id';"; + $sthY = $dbhA->prepare($stmtY) or die "preparing: ",$dbhA->errstr; + $sthY->execute or die "executing: $stmtY", $dbhA->errstr; + $sthYrows=$sthY->rows; + $rec_campLISTS=0; + while ($sthYrows > $rec_campLISTS) + { + @aryY = $sthY->fetchrow_array; + $limit_scopeCAMP .= "'$aryY[0]',"; + $rec_campLISTS++; + } + if (length($limit_scopeCAMP) < 2) {$limit_scopeCAMP="'1'";} + else {chop($limit_scopeCAMP);} + $limit_scopeSQL = "and list_id IN($limit_scopeCAMP)"; + } + if ($VD_call_limit_24hour_method =~ /PHONE_NUMBER/) + { + $stmtA="SELECT count(*) FROM vicidial_lead_24hour_calls where phone_number='$temp_24hour_phone' and phone_code='$temp_24hour_phone_code' and (call_date >= NOW() - INTERVAL 1 DAY) $limit_scopeSQL;"; + } + else + { + $stmtA="SELECT count(*) FROM vicidial_lead_24hour_calls where lead_id='$CLlead_id' and (call_date >= NOW() - INTERVAL 1 DAY) $limit_scopeSQL;"; + } + if ($DB) {print " Doing 24-Hour Call Count Check: $CLlead_id|$temp_24hour_phone_code|$temp_24hour_phone - $VD_call_limit_24hour_method|$VD_call_limit_24hour_scope\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $TFhourCOUNT=0; + $TFhourSTATE=''; + $TFhourCOUNTRY=''; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $TFhourCOUNT = ($TFhourCOUNT + $aryA[0]); + } + $sthA->finish(); + $TEMPcall_limit_24hour = $VD_call_limit_24hour; + if ($DBX) {print " 24-Hour Call Limit Count DEBUG: $TFhourCOUNT|$stmtA|\n";} + + if ( ($VD_call_limit_24hour_override !~ /^DISABLED$/) && (length($VD_call_limit_24hour_override) > 0) ) + { + $TFH_areacode = substr($temp_24hour_phone, 0, 3); + $stmtY = "SELECT state,country FROM vicidial_phone_codes where country_code='$temp_24hour_phone_code' and areacode='$TFH_areacode';"; + $sthY = $dbhA->prepare($stmtY) or die "preparing: ",$dbhA->errstr; + $sthY->execute or die "executing: $stmtY", $dbhA->errstr; + $sthYrows=$sthY->rows; + if ($sthYrows > 0) + { + @aryY = $sthY->fetchrow_array; + $TFhourSTATE = $aryY[0]; + $TFhourCOUNTRY = $aryY[1]; + } + $sthA->finish(); + + $TEMP_TFhour_OR_entry=''; + $TFH_OR_method='state_areacode'; + $stmtA = "SELECT container_entry FROM vicidial_settings_containers where container_id='$VD_call_limit_24hour_override';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($DBX) {print "$sthArows|$stmtA\n";} + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $TEMP_TFhour_OR_entry = $aryA[0]; + } + $sthA->finish(); + + if (length($TEMP_TFhour_OR_entry) > 2) + { + @container_lines = split(/\n/,$TEMP_TFhour_OR_entry); + $c=0; + foreach(@container_lines) + { + $container_lines[$c] =~ s/;.*|\r|\t//gi; + $container_lines[$c] =~ s/ => |=> | =>/=>/gi; + if (length($container_lines[$c]) > 3) + { + # define core settings + if ($container_lines[$c] =~ /^method/i) + { + $container_lines[$c] =~ s/method=>//gi; + $TFH_OR_method = $container_lines[$c]; + } + else + { + if ($container_lines[$c] =~ /^state/i) + { + $container_lines[$c] =~ s/state=>//gi; # USA,GA,4 + @TEMP_state_ARY = split(/,/,$container_lines[$c]); + + if ($TFhourCOUNTRY eq $TEMP_state_ARY[0]) + { + $TEMP_state_ARY[2] =~ s/\D//gi; + if ( ($TFhourSTATE eq $TEMP_state_ARY[1]) && (length($TEMP_state_ARY[2]) > 0) ) + { + if ($DB) {print " 24-Hour Call Count State Override Triggered: $TEMPcall_limit_24hour|$container_lines[$c]\n";} + $TEMPcall_limit_24hour = $TEMP_state_ARY[2]; + } + } + } + } + } + if ($DBX) {print " 24-Hour Call Count State Override DEBUG: |$container_lines[$c]|\n";} + $c++; + } + } + } + + if ( ($TFhourCOUNT > 0) && ($TFhourCOUNT >= $TEMPcall_limit_24hour) ) + { + $TFHCCLlead=1; + $TFHCCL++; + $passed_24hour_call_count=0; + if ($DBX) {print "Flagging 24-Hour Call Limit lead: $CLlead_id ($TFhourCOUNT >= $TEMPcall_limit_24hour) $passed_24hour_call_count\n";} + } + else + { + $passed_24hour_call_count=1; + if ($DBX) {print " 24-Hour Call Limit check passed: $CLlead_id ($TFhourCOUNT < $TEMPcall_limit_24hour) $passed_24hour_call_count\n";} + } + } + sub event_logger { if ($DB) {print "$now_date|$event_string|\n";} @@ -5288,6 +5488,18 @@ sub jam_event_logger $jam_string=''; } +sub aad_output + { + if ($SYSLOG > 0) + { + ### open the log file for writing ### + open(Aout, ">>$AADLOGfile") || die "Can't open $AADLOGfile: $!\n"; + print Aout "$now_date|$script|$aad_string\n"; + close(Aout); + } + $aad_string=''; + } + # subroutine to parse the asterisk version # and return a hash with the various part diff --git a/agc_2-X/trunk/bin/AST_VDhopper.pl b/agc_2-X/trunk/bin/AST_VDhopper.pl index 0420dc80..19e94b80 100644 --- a/agc_2-X/trunk/bin/AST_VDhopper.pl +++ b/agc_2-X/trunk/bin/AST_VDhopper.pl @@ -103,10 +103,12 @@ # 210405-1008 - Added hopper_drop_run_trigger=A option # 210407-1704 - Modified the Hopper Drop-Run process to modify the priority and source of DROPs already in the hopper # 210713-1317 - Added call_limit_24hour feature support +# 210718-0343 - Fixes for 24-Hour Call Count Limits with standard Auto-Alt-Dialing # # constants -$build = '210713-1317'; +$build = '210718-0343'; +$script='AST_VDhopper'; $DB=0; # Debug flag, set to 0 for no debug messages. Can be overriden with CLI --debug flag $US='__'; $MT[0]=''; @@ -324,6 +326,7 @@ foreach(@conf) if (!$VDHLOGfile) {$VDHLOGfile = "$PATHlogs/hopper.$year-$mon-$mday";} if (!$VDHDLOGfile) {$VDHDLOGfile = "$PATHlogs/hopper-detail.$year-$mon-$mday";} +if (!$AADLOGfile) {$AADLOGfile = "$PATHlogs/auto-alt-dial.$year-$mon-$mday";} if (!$VARDB_port) {$VARDB_port='3306';} use DBI; @@ -532,11 +535,11 @@ if ($anyone_callback_inactive_lists =~ /NO_ADD_TO_HOPPER/i) if (length($CLIcampaign)>0) { - $stmtA = "SELECT count(*) FROM vicidial_callbacks where callback_time <= '$now_date' and status='ACTIVE' and campaign_id IN('$CLIcampaign') $vcNOanyone_callback_inactive_listsSQL;"; + $stmtA = "SELECT count(*) FROM vicidial_callbacks where callback_time <= '$now_date' and status IN('ACTIVE','TFHCCL') and campaign_id IN('$CLIcampaign') $vcNOanyone_callback_inactive_listsSQL;"; } else { - $stmtA = "SELECT count(*) FROM vicidial_callbacks where callback_time <= '$now_date' and status='ACTIVE' $vcNOanyone_callback_inactive_listsSQL;"; + $stmtA = "SELECT count(*) FROM vicidial_callbacks where callback_time <= '$now_date' and status IN('ACTIVE','TFHCCL') $vcNOanyone_callback_inactive_listsSQL;"; } $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -552,11 +555,11 @@ if ($CBHOLD_count > 0) $cba=0; if (length($CLIcampaign)>0) { - $stmtA = "SELECT vicidial_callbacks.lead_id,recipient,campaign_id,vicidial_callbacks.list_id,gmt_offset_now,state,vicidial_callbacks.lead_status,vendor_lead_code FROM vicidial_callbacks,vicidial_list where callback_time <= '$now_date' and vicidial_callbacks.status='ACTIVE' and vicidial_callbacks.lead_id=vicidial_list.lead_id and vicidial_callbacks.campaign_id IN('$CLIcampaign') $vlNOanyone_callback_inactive_listsSQL;"; + $stmtA = "SELECT vicidial_callbacks.lead_id,recipient,campaign_id,vicidial_callbacks.list_id,gmt_offset_now,state,vicidial_callbacks.lead_status,vendor_lead_code,phone_number,phone_code FROM vicidial_callbacks,vicidial_list where callback_time <= '$now_date' and vicidial_callbacks.status IN('ACTIVE','TFHCCL') and vicidial_callbacks.lead_id=vicidial_list.lead_id and vicidial_callbacks.campaign_id IN('$CLIcampaign') $vlNOanyone_callback_inactive_listsSQL;"; } else { - $stmtA = "SELECT vicidial_callbacks.lead_id,recipient,campaign_id,vicidial_callbacks.list_id,gmt_offset_now,state,vicidial_callbacks.lead_status,vendor_lead_code FROM vicidial_callbacks,vicidial_list where callback_time <= '$now_date' and vicidial_callbacks.status='ACTIVE' and vicidial_callbacks.lead_id=vicidial_list.lead_id $vlNOanyone_callback_inactive_listsSQL;"; + $stmtA = "SELECT vicidial_callbacks.lead_id,recipient,campaign_id,vicidial_callbacks.list_id,gmt_offset_now,state,vicidial_callbacks.lead_status,vendor_lead_code,phone_number,phone_code FROM vicidial_callbacks,vicidial_list where callback_time <= '$now_date' and vicidial_callbacks.status IN('ACTIVE','TFHCCL') and vicidial_callbacks.lead_id=vicidial_list.lead_id $vlNOanyone_callback_inactive_listsSQL;"; } $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -576,6 +579,8 @@ if ($CBHOLD_count > 0) $CA_state[$cba] = $aryA[5]; $CA_status[$cba] = $aryA[6]; $CA_vendor_lead_code[$cba] = $aryA[7]; + $CA_phone_number[$cba] = $aryA[8]; + $CA_phone_code[$cba] = $aryA[9]; $cba++; } $cbc++; @@ -605,34 +610,27 @@ if ($CBHOLD_count > 0) $DNCL=0; ### look up callback DNC settings for campaign - $stmtA = "SELECT callback_dnc,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc FROM vicidial_campaigns where campaign_id='$CA_campaign_id[$CAu]';"; + $stmtA = "SELECT callback_dnc,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc,call_limit_24hour_method,call_limit_24hour_scope,call_limit_24hour,call_limit_24hour_override FROM vicidial_campaigns where campaign_id='$CA_campaign_id[$CAu]';"; $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; - $VD_callback_dnc = $aryA[0]; - $VD_use_internal_dnc = $aryA[1]; - $VD_use_campaign_dnc = $aryA[2]; - $VD_use_other_campaign_dnc = $aryA[3]; + $VD_callback_dnc = $aryA[0]; + $VD_use_internal_dnc = $aryA[1]; + $VD_use_campaign_dnc = $aryA[2]; + $VD_use_other_campaign_dnc = $aryA[3]; + $VD_call_limit_24hour_method = $aryA[4]; + $VD_call_limit_24hour_scope = $aryA[5]; + $VD_call_limit_24hour = $aryA[6]; + $VD_call_limit_24hour_override = $aryA[7]; } $sthA->finish(); if ($VD_callback_dnc =~ /ENABLED/i) { - $VD_phone_number=''; - ### look up lead information - $stmtA = "SELECT phone_number FROM vicidial_list where lead_id='$CA_lead_id[$CAu]';"; - $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; - $VD_phone_number = $aryA[0]; - } - $sthA->finish(); + $VD_phone_number=$CA_phone_number[$CAu]; if ( ($VD_use_internal_dnc =~ /Y/) || ($VD_use_internal_dnc =~ /AREACODE/) ) { @@ -705,15 +703,40 @@ if ($CBHOLD_count > 0) if ($DNClead < 1) { - $stmtA = "UPDATE vicidial_list set status='$CA_status[$CAu]', called_since_last_reset='N' where lead_id='$CA_lead_id[$CAu]';"; - $affected_rows = $dbhA->do($stmtA); - if ($DB) {print "Scheduled Callbacks Activated: $affected_rows\n";} - $event_string = "|CALLBACKS LISTACT|$affected_rows|"; - &event_logger; + $passed_24hour_call_count=1; + if ( ($SScall_limit_24hour > 0) && ($VD_call_limit_24hour_method =~ /PHONE_NUMBER|LEAD/) ) + { + $temp_24hour_phone = $CA_phone_number[$CAu]; + $temp_24hour_phone_code = $CA_phone_code[$CAu]; + $TEMPlead_id = $CA_lead_id[$CAu]; + $TEMPcampaign_id = $CA_campaign_id[$CAu]; + $TEMPcall_limit_24hour_method = $VD_call_limit_24hour_method; + $TEMPcall_limit_24hour_scope = $VD_call_limit_24hour_scope; + $TEMPcall_limit_24hour = $VD_call_limit_24hour; + $TEMPcall_limit_24hour_override = $VD_call_limit_24hour_override; + $TFHCCLalt=0; + if ($DB > 0) {print "24-Hour Call Count Check: $SScall_limit_24hour|$TEMPcall_limit_24hour_method|$TEMPlead_id|\n";} + &check_24hour_call_count; + } + if ($passed_24hour_call_count > 0) + { + $stmtA = "UPDATE vicidial_list set status='$CA_status[$CAu]', called_since_last_reset='N' where lead_id='$CA_lead_id[$CAu]';"; + $affected_rows = $dbhA->do($stmtA); + if ($DB) {print "Scheduled Callbacks Activated: $affected_rows\n";} + $event_string = "|CALLBACKS LISTACT|$affected_rows|"; + &event_logger; - $stmtA = "INSERT INTO $vicidial_hopper SET lead_id='$CA_lead_id[$CAu]',campaign_id='$CA_campaign_id[$CAu]',list_id='$CA_list_id[$CAu]',gmt_offset_now='$CA_gmt_offset_now[$CAu]',user='',state=\"$CA_state[$CAu]\",priority='50',source='C',vendor_lead_code=\"$CA_vendor_lead_code[$CAu]\";"; - $affected_rows = $dbhA->do($stmtA); - if ($DB) {print "ANYONE Scheduled Callback Inserted into hopper: $affected_rows|$CA_lead_id[$CAu]\n";} + $stmtA = "INSERT INTO $vicidial_hopper SET lead_id='$CA_lead_id[$CAu]',campaign_id='$CA_campaign_id[$CAu]',list_id='$CA_list_id[$CAu]',gmt_offset_now='$CA_gmt_offset_now[$CAu]',user='',state=\"$CA_state[$CAu]\",priority='50',source='C',vendor_lead_code=\"$CA_vendor_lead_code[$CAu]\";"; + $affected_rows = $dbhA->do($stmtA); + if ($DB) {print "ANYONE Scheduled Callback Inserted into hopper: $affected_rows|$CA_lead_id[$CAu]\n";} + } + else + { + $stmtA = "UPDATE vicidial_callbacks SET status='TFHCCL' where lead_id='$CA_lead_id[$CAu]';"; + $affected_rows = $dbhA->do($stmtA); + + if ($DB) {print "ANYONE Scheduled Callback NOT Inserted into hopper: 24-Hour deferred|$affected_rows|$passed_24hour_call_count|$CA_lead_id[$CAu]\n";} + } } $CAu++; } @@ -781,21 +804,26 @@ if ($hopper_dnc_count > 0) $VD_use_internal_dnc=''; $VD_use_campaign_dnc=''; $VD_use_other_campaign_dnc=''; + $alt_skip_reason=''; $addr3_skip_reason=''; $VD_alt_dial = $AAD_alt_dial[$aad]; $VD_campaign_id = $AAD_campaign_id[$aad]; $VD_lead_id = $AAD_lead_id[$aad]; ### look up auto-alt-dial settings for campaign - $stmtA = "SELECT auto_alt_dial,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc FROM vicidial_campaigns where campaign_id='$AAD_campaign_id[$aad]';"; + $stmtA = "SELECT auto_alt_dial,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc,call_limit_24hour_method,call_limit_24hour_scope,call_limit_24hour,call_limit_24hour_override FROM vicidial_campaigns where campaign_id='$AAD_campaign_id[$aad]';"; $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; - $VD_auto_alt_dial = $aryA[0]; - $VD_use_internal_dnc = $aryA[1]; - $VD_use_campaign_dnc = $aryA[2]; - $VD_use_other_campaign_dnc = $aryA[3]; + $VD_auto_alt_dial = $aryA[0]; + $VD_use_internal_dnc = $aryA[1]; + $VD_use_campaign_dnc = $aryA[2]; + $VD_use_other_campaign_dnc = $aryA[3]; + $VD_call_limit_24hour_method = $aryA[4]; + $VD_call_limit_24hour_scope = $aryA[5]; + $VD_call_limit_24hour = $aryA[6]; + $VD_call_limit_24hour_override = $aryA[7]; } $sthA->finish(); @@ -806,7 +834,7 @@ if ($hopper_dnc_count > 0) { $alt_dial_skip=0; $VD_alt_phone=''; - $stmtA="SELECT alt_phone,gmt_offset_now,state,list_id FROM vicidial_list where lead_id='$AAD_lead_id[$aad]';"; + $stmtA="SELECT alt_phone,gmt_offset_now,state,list_id,phone_code FROM vicidial_list where lead_id='$AAD_lead_id[$aad]';"; if ($DB) {$event_string = "|$stmtA|"; &event_logger;} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -819,6 +847,7 @@ if ($hopper_dnc_count > 0) $VD_gmt_offset_now = $aryA[1]; $VD_state = $aryA[2]; $VD_list_id = $aryA[3]; + $VD_phone_code = $aryA[4]; } $sthA->finish(); if (length($VD_alt_phone)>5) @@ -870,23 +899,47 @@ if ($hopper_dnc_count > 0) } if ($VD_alt_dnc_count < 1) { - $stmtA = "UPDATE $vicidial_hopper SET status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='ALT',user='',priority='25' where hopper_id='$AAD_hopper_id[$aad]';"; - $affected_rows = $dbhA->do($stmtA); - if ($DB) {$event_string = "-- VDH record updated: |$affected_rows| |$stmtA|"; &event_logger;} + $passed_24hour_call_count=1; + if ( ($SScall_limit_24hour > 0) && ($VD_call_limit_24hour_method =~ /PHONE_NUMBER|LEAD/) ) + { + $temp_24hour_phone = $VD_alt_phone; + $temp_24hour_phone_code = $VD_phone_code; + $TEMPlead_id = $AAD_lead_id[$aad]; + $TEMPcampaign_id = $AAD_campaign_id[$aad]; + $TEMPcall_limit_24hour_method = $VD_call_limit_24hour_method; + $TEMPcall_limit_24hour_scope = $VD_call_limit_24hour_scope; + $TEMPcall_limit_24hour = $VD_call_limit_24hour; + $TEMPcall_limit_24hour_override = $VD_call_limit_24hour_override; + $TFHCCLalt=1; + if ($DB > 0) {print "24-Hour Call Count Check: $SScall_limit_24hour|$TEMPcall_limit_24hour_method|$TEMPlead_id|\n";} + &check_24hour_call_count; + } + if ($passed_24hour_call_count > 0) + { + $stmtA = "UPDATE $vicidial_hopper SET status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='ALT',user='',priority='25' where hopper_id='$AAD_hopper_id[$aad]';"; + $affected_rows = $dbhA->do($stmtA); + if ($DB) {$event_string = "-- VDH record updated: |$affected_rows| |$stmtA|"; &event_logger;} + $aad_string = "$AAD_lead_id[$aad]|$VD_alt_phone|$AAD_campaign_id[$aad]|ALT|25|hopper insert|"; &aad_output; + } + else + {$alt_dial_skip=1; $alt_skip_reason='24-hour call count limit failed';} } else - {$alt_dial_skip=1;} + {$alt_dial_skip=1; $alt_skip_reason='DNC check failed';} } else - {$alt_dial_skip=1;} + {$alt_dial_skip=1; $alt_skip_reason='ALT phone invalid';} if ($alt_dial_skip > 0) - {$VD_alt_dial='ALT';} + { + $VD_alt_dial='ALT'; + $aad_string = "$AAD_lead_id[$aad]|$VD_alt_phone|$AAD_campaign_id[$aad]|ALT|0|hopper skip|$alt_skip_reason|"; &aad_output; + } } if ( ( ($VD_auto_alt_dial =~ /(ADDR3_ONLY)/) && ($VD_alt_dial =~ /NONE|MAIN/) ) || ( ($VD_auto_alt_dial =~ /(ALT_AND_ADDR3)/) && ($VD_alt_dial =~ /ALT/) ) ) { $addr3_dial_skip=0; $VD_address3=''; - $stmtA="SELECT address3,gmt_offset_now,state,list_id FROM vicidial_list where lead_id='$AAD_lead_id[$aad]';"; + $stmtA="SELECT address3,gmt_offset_now,state,list_id,phone_code FROM vicidial_list where lead_id='$AAD_lead_id[$aad]';"; if ($DB) {$event_string = "|$stmtA|"; &event_logger;} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -899,6 +952,7 @@ if ($hopper_dnc_count > 0) $VD_gmt_offset_now = $aryA[1]; $VD_state = $aryA[2]; $VD_list_id = $aryA[3]; + $VD_phone_code = $aryA[4]; } $sthA->finish(); if (length($VD_address3)>5) @@ -950,17 +1004,41 @@ if ($hopper_dnc_count > 0) } if ($VD_alt_dnc_count < 1) { - $stmtA = "UPDATE $vicidial_hopper SET status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='ADDR3',user='',priority='25' where hopper_id='$AAD_hopper_id[$aad]';"; - $affected_rows = $dbhA->do($stmtA); - if ($DB) {$event_string = "-- VDH record updated: |$affected_rows| |$stmtA|"; &event_logger;} + $passed_24hour_call_count=1; + if ( ($SScall_limit_24hour > 0) && ($VD_call_limit_24hour_method =~ /PHONE_NUMBER|LEAD/) ) + { + $temp_24hour_phone = $VD_address3; + $temp_24hour_phone_code = $VD_phone_code; + $TEMPlead_id = $AAD_lead_id[$aad]; + $TEMPcampaign_id = $VD_campaign_id; + $TEMPcall_limit_24hour_method = $VD_call_limit_24hour_method; + $TEMPcall_limit_24hour_scope = $VD_call_limit_24hour_scope; + $TEMPcall_limit_24hour = $VD_call_limit_24hour; + $TEMPcall_limit_24hour_override = $VD_call_limit_24hour_override; + $TFHCCLalt=1; + if ($DB > 0) {print "24-Hour Call Count Check: $SScall_limit_24hour|$TEMPcall_limit_24hour_method|$TEMPlead_id|\n";} + &check_24hour_call_count; + } + if ($passed_24hour_call_count > 0) + { + $stmtA = "UPDATE $vicidial_hopper SET status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='ADDR3',user='',priority='20' where hopper_id='$AAD_hopper_id[$aad]';"; + $affected_rows = $dbhA->do($stmtA); + if ($DB) {$event_string = "-- VDH record updated: |$affected_rows| |$stmtA|"; &event_logger;} + $aad_string = "$AAD_lead_id[$aad]|$VD_address3|$AAD_campaign_id[$aad]|ADDR3|20|hopper insert|"; &aad_output; + } + else + {$addr3_dial_skip=1; $addr3_skip_reason='24-hour call count limit failed';} } else - {$addr3_dial_skip=1;} + {$addr3_dial_skip=1; $addr3_skip_reason='DNC check failed';} } else - {$addr3_dial_skip=1;} + {$addr3_dial_skip=1; $addr3_skip_reason='ADDR3 phone invalid';} if ($addr3_dial_skip > 0) - {$VD_alt_dial='ADDR3';} + { + $VD_alt_dial='ADDR3'; + $aad_string = "$AAD_lead_id[$aad]|$VD_address3|$AAD_campaign_id[$aad]|ADDR3|0|hopper skip|$addr3_skip_reason|"; &aad_output; + } } if ( ( ($VD_auto_alt_dial =~ /(EXTENDED_ONLY)/) && ($VD_alt_dial =~ /NONE|MAIN/) ) || ( ($VD_auto_alt_dial =~ /(ALT_AND_EXTENDED)/) && ($VD_alt_dial =~ /ALT/) ) || ( ($VD_auto_alt_dial =~ /ADDR3_AND_EXTENDED|ALT_AND_ADDR3_AND_EXTENDED/) && ($VD_alt_dial =~ /ADDR3/) ) || ( ($VD_auto_alt_dial =~ /(EXTENDED)/) && ($VD_alt_dial =~ /X/) && ($VD_alt_dial !~ /XLAST/) ) ) { @@ -1007,7 +1085,7 @@ if ($hopper_dnc_count > 0) while ( ($alt_dial_phones_count > 0) && ($alt_dial_phones_count > $Xlast) ) { $Xlast++; - $stmtA="SELECT alt_phone_id,phone_number,active FROM vicidial_list_alt_phones where lead_id='$VD_lead_id' and alt_phone_count='$Xlast';"; + $stmtA="SELECT alt_phone_id,phone_number,active,phone_code FROM vicidial_list_alt_phones where lead_id='$VD_lead_id' and alt_phone_count='$Xlast';"; if ($DB) {$event_string = "|$stmtA|"; &event_logger;} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -1015,9 +1093,10 @@ if ($hopper_dnc_count > 0) if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; - $VD_altdial_id = $aryA[0]; - $VD_altdial_phone = $aryA[1]; - $VD_altdial_active = $aryA[2]; + $VD_altdial_id = $aryA[0]; + $VD_altdial_phone = $aryA[1]; + $VD_altdial_active = $aryA[2]; + $VD_altdial_phone_code = $aryA[3]; } else {$Xlast=9999999999;} @@ -1074,12 +1153,36 @@ if ($hopper_dnc_count > 0) { if ($alt_dial_phones_count eq '$Xlast') {$Xlast = 'LAST';} - $stmtA = "UPDATE $vicidial_hopper SET status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='X$Xlast',user='',priority='25' where hopper_id='$AAD_hopper_id[$aad]';"; - $affected_rows = $dbhA->do($stmtA); - if ($DB) {$event_string = "-- VDH record updated: |$affected_rows| |$stmtA|X$Xlast|$VD_altdial_id|"; &event_logger;} - $Xlast=9999999999; + $passed_24hour_call_count=1; + if ( ($SScall_limit_24hour > 0) && ($VD_call_limit_24hour_method =~ /PHONE_NUMBER|LEAD/) ) + { + $temp_24hour_phone = $VD_altdial_phone; + $temp_24hour_phone_code = $VD_altdial_phone_code; + $TEMPlead_id = $AAD_lead_id[$aad]; + $TEMPcampaign_id = $VD_campaign_id; + $TEMPcall_limit_24hour_method = $VD_call_limit_24hour_method; + $TEMPcall_limit_24hour_scope = $VD_call_limit_24hour_scope; + $TEMPcall_limit_24hour = $VD_call_limit_24hour; + $TEMPcall_limit_24hour_override = $VD_call_limit_24hour_override; + $TFHCCLalt=1; + if ($DB > 0) {print "24-Hour Call Count Check: $SScall_limit_24hour|$TEMPcall_limit_24hour_method|$TEMPlead_id|\n";} + &check_24hour_call_count; + } + if ($passed_24hour_call_count > 0) + { + $stmtA = "UPDATE $vicidial_hopper SET status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='X$Xlast',user='',priority='15' where hopper_id='$AAD_hopper_id[$aad]';"; + $affected_rows = $dbhA->do($stmtA); + if ($DB) {$event_string = "-- VDH record updated: |$affected_rows| |$stmtA|X$Xlast|$VD_altdial_id|"; &event_logger;} + $aad_string = "$AAD_lead_id[$aad]|$VD_altdial_phone|$AAD_campaign_id[$aad]|X$Xlast|15|hopper insert|"; &aad_output; + $Xlast=9999999999; + $DNC_hopper_trigger=0; + } + else + {$DNC_hopper_trigger=1;} } else + {$DNC_hopper_trigger=1;} + if ($DNC_hopper_trigger > 0) { if ($alt_dial_phones_count eq '$Xlast') {$Xlast = 'LAST';} @@ -1088,6 +1191,7 @@ if ($hopper_dnc_count > 0) if ($DB) {$event_string = "-- VDH record DNC updated: |$affected_rows| |$stmtA|X$Xlast|$VD_altdial_id|"; &event_logger;} $Xlast=9999999999; if ($DB) {$event_string = "-- VDH alt dial is DNC|X$Xlast|$VD_altdial_phone|"; &event_logger;} + $aad_string = "$AAD_lead_id[$aad]|$VD_altdial_phone|$AAD_campaign_id[$aad]|DNC|15|hopper insert|"; &aad_output; } } } @@ -3382,139 +3486,24 @@ foreach(@campaign_id) } } - - ## BEGIN Check for 24-Hour call count limit for this lead/phone_number - if ( ($SScall_limit_24hour > 0) && ( ($call_limit_24hour_method[$i] =~ /PHONE_NUMBER/) || ($call_limit_24hour_method[$i] =~ /LEAD/) ) ) + ## BEGIN Check for 24-Hour call count limit for this lead/phone_number + $passed_24hour_call_count=1; + if ( ($SScall_limit_24hour > 0) && ($call_limit_24hour_method[$i] =~ /PHONE_NUMBER|LEAD/) ) { - $limit_scopeSQL=''; - if ($call_limit_24hour_scope[$i] =~ /CAMPAIGN_LISTS/) - { - $limit_scopeCAMP=''; - $stmtY = "SELECT list_id FROM vicidial_lists where campaign_id='$campaign_id[$i]';"; - $sthY = $dbhA->prepare($stmtY) or die "preparing: ",$dbhA->errstr; - $sthY->execute or die "executing: $stmtY", $dbhA->errstr; - $sthYrows=$sthY->rows; - $rec_campLISTS=0; - while ($sthYrows > $rec_campLISTS) - { - @aryY = $sthY->fetchrow_array; - $limit_scopeCAMP .= "'$aryY[0]',"; - $rec_campLISTS++; - } - if (length($limit_scopeCAMP) < 2) {$limit_scopeCAMP="'1'";} - else {chop($limit_scopeCAMP);} - $limit_scopeSQL = "and list_id IN($limit_scopeCAMP)"; - } - if ($call_limit_24hour_method[$i] =~ /PHONE_NUMBER/) - { - $stmtA="SELECT count(*) FROM vicidial_lead_24hour_calls where phone_number='$phone_to_hopper[$h]' and phone_code='$phone_code_to_hopper[$h]' and (call_date >= NOW() - INTERVAL 1 DAY) $limit_scopeSQL;"; - } - else - { - $stmtA="SELECT count(*) FROM vicidial_lead_24hour_calls where lead_id='$leads_to_hopper[$h]' and (call_date >= NOW() - INTERVAL 1 DAY) $limit_scopeSQL;"; - } - if ($DB) {print " Doing 24-Hour Call Count Check: $leads_to_hopper[$h]|$phone_code_to_hopper[$h]|$phone_to_hopper[$h] - $call_limit_24hour_method[$i]|$call_limit_24hour_scope[$i]\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $TFhourCOUNT=0; - $TFhourSTATE=''; - $TFhourCOUNTRY=''; - if ($sthArows > 0) - { - @aryA = $sthA->fetchrow_array; - $TFhourCOUNT = ($TFhourCOUNT + $aryA[0]); - } - $sthA->finish(); - $TEMPcall_limit_24hour = $call_limit_24hour[$i]; - if ($DBX) {print " 24-Hour Call Limit Count DEBUG: $TFhourCOUNT|$stmtA|\n";} - - if ( ($call_limit_24hour_override[$i] !~ /^DISABLED$/) && (length($call_limit_24hour_override[$i]) > 0) ) - { - $TFH_areacode = substr($phone_to_hopper[$h], 0, 3); - $stmtY = "SELECT state,country FROM vicidial_phone_codes where country_code='$phone_code_to_hopper[$h]' and areacode='$TFH_areacode';"; - $sthY = $dbhA->prepare($stmtY) or die "preparing: ",$dbhA->errstr; - $sthY->execute or die "executing: $stmtY", $dbhA->errstr; - $sthYrows=$sthY->rows; - if ($sthYrows > 0) - { - @aryY = $sthY->fetchrow_array; - $TFhourSTATE = $aryY[0]; - $TFhourCOUNTRY = $aryY[1]; - } - $sthA->finish(); - - $TEMP_TFhour_OR_entry=''; - $TFH_OR_method='state_areacode'; - $stmtA = "SELECT container_entry FROM vicidial_settings_containers where container_id='$call_limit_24hour_override[$i]';"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($DBX) {print "$sthArows|$stmtA\n";} - if ($sthArows > 0) - { - @aryA = $sthA->fetchrow_array; - $TEMP_TFhour_OR_entry = $aryA[0]; - } - $sthA->finish(); - - if (length($TEMP_TFhour_OR_entry) > 2) - { - @container_lines = split(/\n/,$TEMP_TFhour_OR_entry); - $c=0; - foreach(@container_lines) - { - $container_lines[$c] =~ s/;.*|\r|\t//gi; - $container_lines[$c] =~ s/ => |=> | =>/=>/gi; - if (length($container_lines[$c]) > 3) - { - # define core settings - if ($container_lines[$c] =~ /^method/i) - { - $container_lines[$c] =~ s/method=>//gi; - $TFH_OR_method = $container_lines[$c]; - } - else - { - if ($container_lines[$c] =~ /^state/i) - { - $container_lines[$c] =~ s/state=>//gi; # USA,GA,4 - @TEMP_state_ARY = split(/,/,$container_lines[$c]); - - if ($TFhourCOUNTRY eq $TEMP_state_ARY[0]) - { - $TEMP_state_ARY[2] =~ s/\D//gi; - if ( ($TFhourSTATE eq $TEMP_state_ARY[1]) && (length($TEMP_state_ARY[2]) > 0) ) - { - if ($DB) {print " 24-Hour Call Count State Override Triggered: $TEMPcall_limit_24hour|$container_lines[$c]\n";} - $TEMPcall_limit_24hour = $TEMP_state_ARY[2]; - } - } - } - } - } - if ($DBX) {print " 24-Hour Call Count State Override DEBUG: |$container_lines[$c]|\n";} - $c++; - } - } - } - - if ( ($TFhourCOUNT > 0) && ($TFhourCOUNT >= $TEMPcall_limit_24hour) ) - { - $TFHCCLlead=1; - $TFHCCL++; - $stmtA = "UPDATE vicidial_list SET called_since_last_reset='D' where lead_id='$leads_to_hopper[$h]';"; - $affected_rows = $dbhA->do($stmtA); - if ($DBX) {print "Flagging 24-Hour Call Limit lead: $affected_rows $leads_to_hopper[$h] ($TFhourCOUNT >= $TEMPcall_limit_24hour)\n";} - } - else - { - if ($DBX) {print " 24-Hour Call Limit check passed: $leads_to_hopper[$h] ($TFhourCOUNT < $TEMPcall_limit_24hour)\n";} - } + $temp_24hour_phone = $phone_to_hopper[$h]; + $temp_24hour_phone_code = $phone_code_to_hopper[$h]; + $TEMPlead_id = $leads_to_hopper[$h]; + $TEMPcampaign_id = $campaign_id[$i]; + $TEMPcall_limit_24hour_method = $call_limit_24hour_method[$i]; + $TEMPcall_limit_24hour_scope = $call_limit_24hour_scope[$i]; + $TEMPcall_limit_24hour = $call_limit_24hour[$i]; + $TEMPcall_limit_24hour_override = $call_limit_24hour_override[$i]; + $TFHCCLalt=0; + if ($DB > 0) {print "24-Hour Call Count Check: $SScall_limit_24hour|$TEMPcall_limit_24hour_method|$TEMPcall_limit_24hour_scope|$TEMPlead_id|\n";} + &check_24hour_call_count; } ## END Check for 24-Hour call count limit for this lead/phone_number - $VAC_exist=0; $stmtA="SELECT count(*) FROM vicidial_auto_calls where lead_id='$leads_to_hopper[$h]';"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; @@ -3594,7 +3583,7 @@ foreach(@campaign_id) else { ##### Auto-Alt-Dial if DNCC or DNCL are set to campaign auto-alt-dial statuses, insert lead into hopper as DNC status - if ( ( ($auto_alt_dial_statuses[$i] =~ / DNCC /) && ($DNCC > 0) ) || ( ($auto_alt_dial_statuses[$i] =~ / DNCL /) && ($DNCL > 0) ) ) + if ( ( ($auto_alt_dial_statuses[$i] =~ / DNCC /) && ($DNCC > 0) ) || ( ($auto_alt_dial_statuses[$i] =~ / DNCL /) && ($DNCL > 0) ) || ( ($auto_alt_dial_statuses[$i] =~ / TFHCCL /) && ($TFHCCL > 0) ) ) { $stmtA = "INSERT INTO $vicidial_hopper (lead_id,campaign_id,status,user,list_id,gmt_offset_now,state,priority,source,vendor_lead_code) values('$leads_to_hopper[$h]','$campaign_id[$i]','DNC','','$lists_to_hopper[$h]','$gmt_to_hopper[$h]',\"$state_to_hopper[$h]\",'$hopperPRIORITY','$source_to_hopper[$h]',\"$vlc_to_hopper[$h]\");"; $affected_rows = $dbhA->do($stmtA); @@ -3661,6 +3650,141 @@ exit; ##### SUBROUTINES ##### +sub check_24hour_call_count + { + $passed_24hour_call_count=0; + $limit_scopeSQL=''; + if ($TEMPcall_limit_24hour_scope =~ /CAMPAIGN_LISTS/) + { + $limit_scopeCAMP=''; + $stmtY = "SELECT list_id FROM vicidial_lists where campaign_id='$TEMPcampaign_id';"; + $sthY = $dbhA->prepare($stmtY) or die "preparing: ",$dbhA->errstr; + $sthY->execute or die "executing: $stmtY", $dbhA->errstr; + $sthYrows=$sthY->rows; + $rec_campLISTS=0; + while ($sthYrows > $rec_campLISTS) + { + @aryY = $sthY->fetchrow_array; + $limit_scopeCAMP .= "'$aryY[0]',"; + $rec_campLISTS++; + } + if (length($limit_scopeCAMP) < 2) {$limit_scopeCAMP="'1'";} + else {chop($limit_scopeCAMP);} + $limit_scopeSQL = "and list_id IN($limit_scopeCAMP)"; + } + if ($TEMPcall_limit_24hour_method =~ /PHONE_NUMBER/) + { + $stmtA="SELECT count(*) FROM vicidial_lead_24hour_calls where phone_number='$temp_24hour_phone' and phone_code='$temp_24hour_phone_code' and (call_date >= NOW() - INTERVAL 1 DAY) $limit_scopeSQL;"; + } + else + { + $stmtA="SELECT count(*) FROM vicidial_lead_24hour_calls where lead_id='$TEMPlead_id' and (call_date >= NOW() - INTERVAL 1 DAY) $limit_scopeSQL;"; + } + if ($DB) {print " Doing 24-Hour Call Count Check: $TEMPlead_id|$temp_24hour_phone_code|$temp_24hour_phone - $TEMPcall_limit_24hour_method|$TEMPcall_limit_24hour_scope\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $TFhourCOUNT=0; + $TFhourSTATE=''; + $TFhourCOUNTRY=''; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $TFhourCOUNT = ($TFhourCOUNT + $aryA[0]); + } + $sthA->finish(); + $TEMPcall_limit_24hour = $TEMPcall_limit_24hour; + if ($DBX) {print " 24-Hour Call Limit Count DEBUG: $TFhourCOUNT|$stmtA|\n";} + + if ( ($TEMPcall_limit_24hour_override !~ /^DISABLED$/) && (length($TEMPcall_limit_24hour_override) > 0) ) + { + $TFH_areacode = substr($temp_24hour_phone, 0, 3); + $stmtY = "SELECT state,country FROM vicidial_phone_codes where country_code='$temp_24hour_phone_code' and areacode='$TFH_areacode';"; + $sthY = $dbhA->prepare($stmtY) or die "preparing: ",$dbhA->errstr; + $sthY->execute or die "executing: $stmtY", $dbhA->errstr; + $sthYrows=$sthY->rows; + if ($sthYrows > 0) + { + @aryY = $sthY->fetchrow_array; + $TFhourSTATE = $aryY[0]; + $TFhourCOUNTRY = $aryY[1]; + } + $sthA->finish(); + + $TEMP_TFhour_OR_entry=''; + $TFH_OR_method='state_areacode'; + $stmtA = "SELECT container_entry FROM vicidial_settings_containers where container_id='$TEMPcall_limit_24hour_override';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($DBX) {print "$sthArows|$stmtA\n";} + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $TEMP_TFhour_OR_entry = $aryA[0]; + } + $sthA->finish(); + + if (length($TEMP_TFhour_OR_entry) > 2) + { + @container_lines = split(/\n/,$TEMP_TFhour_OR_entry); + $c=0; + foreach(@container_lines) + { + $container_lines[$c] =~ s/;.*|\r|\t//gi; + $container_lines[$c] =~ s/ => |=> | =>/=>/gi; + if (length($container_lines[$c]) > 3) + { + # define core settings + if ($container_lines[$c] =~ /^method/i) + { + $container_lines[$c] =~ s/method=>//gi; + $TFH_OR_method = $container_lines[$c]; + } + else + { + if ($container_lines[$c] =~ /^state/i) + { + $container_lines[$c] =~ s/state=>//gi; # USA,GA,4 + @TEMP_state_ARY = split(/,/,$container_lines[$c]); + + if ($TFhourCOUNTRY eq $TEMP_state_ARY[0]) + { + $TEMP_state_ARY[2] =~ s/\D//gi; + if ( ($TFhourSTATE eq $TEMP_state_ARY[1]) && (length($TEMP_state_ARY[2]) > 0) ) + { + if ($DB) {print " 24-Hour Call Count State Override Triggered: $TEMPcall_limit_24hour|$container_lines[$c]\n";} + $TEMPcall_limit_24hour = $TEMP_state_ARY[2]; + } + } + } + } + } + if ($DBX) {print " 24-Hour Call Count State Override DEBUG: |$container_lines[$c]|\n";} + $c++; + } + } + } + + if ( ($TFhourCOUNT > 0) && ($TFhourCOUNT >= $TEMPcall_limit_24hour) ) + { + $TFHCCLlead=1; + $TFHCCL++; + $passed_24hour_call_count=0; + if ($TFHCCLalt < 1) + { + $stmtA = "UPDATE vicidial_list SET called_since_last_reset='D' where lead_id='$TEMPlead_id';"; + $affected_rows = $dbhA->do($stmtA); + } + if ($DBX) {print "Flagging 24-Hour Call Limit lead: $affected_rows $TEMPlead_id ($TFhourCOUNT >= $TEMPcall_limit_24hour) $passed_24hour_call_count\n";} + } + else + { + $passed_24hour_call_count=1; + if ($DBX) {print " 24-Hour Call Limit check passed: $TEMPlead_id ($TFhourCOUNT < $TEMPcall_limit_24hour) $passed_24hour_call_count\n";} + } + } + sub event_logger { if ($SYSLOG) @@ -3687,6 +3811,18 @@ sub detail_logger $detail_string=''; } +sub aad_output + { + if ($SYSLOG > 0) + { + ### open the log file for writing ### + open(Aout, ">>$AADLOGfile") || die "Can't open $AADLOGfile: $!\n"; + print Aout "$now_date|$script|$aad_string\n"; + close(Aout); + } + $aad_string=''; + } + sub roundup { my $n = shift; diff --git a/agc_2-X/trunk/bin/FastAGI_log.pl b/agc_2-X/trunk/bin/FastAGI_log.pl index e409b6d1..6afd0f5a 100644 --- a/agc_2-X/trunk/bin/FastAGI_log.pl +++ b/agc_2-X/trunk/bin/FastAGI_log.pl @@ -88,6 +88,7 @@ # 200318-1054 - Added code for OpenSIPs CallerIDname # 210314-1015 - Added enhanced_disconnect_logging=2 option # 210606-1007 - Added TILTX features for pre-carrier call filtering +# 210718-0358 - Fixes for 24-Hour Call Count Limits with standard Auto-Alt-Dialing # # defaults for PreFork @@ -256,6 +257,7 @@ sub process_request if (!$VARDB_port) {$VARDB_port='3306';} if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/FASTagiout.$year-$mon-$mday";} + if (!$AADLOGfile) {$AADLOGfile = "$PATHlogs/auto-alt-dial.$year-$mon-$mday";} $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") or die "Couldn't connect to database: " . DBI->errstr; @@ -1487,7 +1489,7 @@ sub process_request ############################################# ##### SYSTEM SETTINGS LOOKUP ##### - $stmtA = "SELECT enable_drop_lists,call_quota_lead_ranking,timeclock_end_of_day FROM system_settings;"; + $stmtA = "SELECT enable_drop_lists,call_quota_lead_ranking,timeclock_end_of_day,call_limit_24hour FROM system_settings;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -1497,6 +1499,7 @@ sub process_request $enable_drop_lists = $aryA[0]; $SScall_quota_lead_ranking = $aryA[1]; $timeclock_end_of_day = $aryA[2]; + $SScall_limit_24hour = $aryA[3]; } $sthA->finish(); ##### END SYSTEM SETTINGS LOOKUP ##### @@ -1734,7 +1737,7 @@ sub process_request $VD_auto_alt_dial = 'NONE'; $VD_auto_alt_dial_statuses=''; $VD_call_quota_lead_ranking='DISABLED'; - $stmtA="SELECT auto_alt_dial,auto_alt_dial_statuses,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc,call_quota_lead_ranking FROM vicidial_campaigns where campaign_id='$VD_campaign_id';"; + $stmtA="SELECT auto_alt_dial,auto_alt_dial_statuses,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc,call_quota_lead_ranking,call_limit_24hour_method,call_limit_24hour_scope,call_limit_24hour,call_limit_24hour_override FROM vicidial_campaigns where campaign_id='$VD_campaign_id';"; if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -1743,12 +1746,16 @@ sub process_request while ($sthArows > $epc_countCAMPDATA) { @aryA = $sthA->fetchrow_array; - $VD_auto_alt_dial = $aryA[0]; - $VD_auto_alt_dial_statuses = $aryA[1]; - $VD_use_internal_dnc = $aryA[2]; - $VD_use_campaign_dnc = $aryA[3]; - $VD_use_other_campaign_dnc = $aryA[4]; - $VD_call_quota_lead_ranking = $aryA[5]; + $VD_auto_alt_dial = $aryA[0]; + $VD_auto_alt_dial_statuses = $aryA[1]; + $VD_use_internal_dnc = $aryA[2]; + $VD_use_campaign_dnc = $aryA[3]; + $VD_use_other_campaign_dnc = $aryA[4]; + $VD_call_quota_lead_ranking = $aryA[5]; + $VD_call_limit_24hour_method = $aryA[6]; + $VD_call_limit_24hour_scope = $aryA[7]; + $VD_call_limit_24hour = $aryA[8]; + $VD_call_limit_24hour_override = $aryA[9]; $epc_countCAMPDATA++; } @@ -1768,12 +1775,13 @@ sub process_request # if ($AGILOG) {$agi_string = "AUTO-ALT TEST: |$VD_status|$VDL_status|$VD_auto_alt_dial_statuses|$VD_auto_alt_dial|"; &agi_output;} if ($VD_auto_alt_dial_statuses =~ / $VD_status | $VDL_status /) { + $alt_skip_reason=''; $addr3_skip_reason=''; if ($AGILOG) {$agi_string = "AUTO-ALT MATCH: |$VD_status|$VDL_status|$VD_auto_alt_dial_statuses|$VD_auto_alt_dial|$VD_alt_dial|$VD_alt_dial_log|"; &agi_output;} if ( ($VD_auto_alt_dial =~ /(ALT_ONLY|ALT_AND_ADDR3|ALT_AND_EXTENDED)/) && ($VD_alt_dial =~ /NONE|MAIN/) ) { $alt_dial_skip=0; $VD_alt_phone=''; - $stmtA="SELECT alt_phone,gmt_offset_now,state,list_id FROM vicidial_list where lead_id='$VD_lead_id';"; + $stmtA="SELECT alt_phone,gmt_offset_now,state,list_id,phone_code FROM vicidial_list where lead_id='$VD_lead_id';"; if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -1787,6 +1795,7 @@ sub process_request $VD_gmt_offset_now = $aryA[1]; $VD_state = $aryA[2]; $VD_list_id = $aryA[3]; + $VD_phone_code = $aryA[4]; $epc_countCAMPDATA++; } $sthA->finish(); @@ -1839,23 +1848,40 @@ sub process_request } if ($VD_alt_dnc_count < 1) { - $stmtA = "INSERT INTO vicidial_hopper SET lead_id='$VD_lead_id',campaign_id='$VD_campaign_id',status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='ALT',user='',priority='25',source='A';"; - $affected_rows = $dbhA->do($stmtA); - if ($AGILOG) {$agi_string = "-- VDH record inserted: |$affected_rows| |$stmtA|"; &agi_output;} + $passed_24hour_call_count=1; + if ( ($SScall_limit_24hour > 0) && ($VD_call_limit_24hour_method =~ /PHONE_NUMBER|LEAD/) ) + { + $temp_24hour_phone = $VD_alt_phone; + $temp_24hour_phone_code = $VD_phone_code; + if ($DB > 0) {print "24-Hour Call Count Check: $SScall_limit_24hour|$VD_call_limit_24hour_method|$VD_lead_id|\n";} + &check_24hour_call_count; + } + if ($passed_24hour_call_count > 0) + { + $stmtA = "INSERT INTO vicidial_hopper SET lead_id='$VD_lead_id',campaign_id='$VD_campaign_id',status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='ALT',user='',priority='25',source='A';"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDH record inserted: |$affected_rows| |$stmtA|"; &agi_output;} + if ($AGILOG) {$aad_string = "$VD_lead_id|$VD_alt_phone|$VD_campaign_id|ALT|25|hopper insert|"; &aad_output;} + } + else + {$alt_dial_skip=1; $alt_skip_reason='24-hour call count limit failed';} } else - {$alt_dial_skip=1;} + {$alt_dial_skip=1; $alt_skip_reason='DNC check failed';} } else - {$alt_dial_skip=1;} + {$alt_dial_skip=1; $alt_skip_reason='ALT phone invalid';} if ($alt_dial_skip > 0) - {$VD_alt_dial='ALT';} + { + $VD_alt_dial='ALT'; + if ($AGILOG) {$aad_string = "$VD_lead_id|$VD_alt_phone|$VD_campaign_id|ALT|0|hopper skip|$alt_skip_reason|"; &aad_output;} + } } if ( ( ($VD_auto_alt_dial =~ /(ADDR3_ONLY)/) && ($VD_alt_dial =~ /NONE|MAIN/) ) || ( ($VD_auto_alt_dial =~ /(ALT_AND_ADDR3)/) && ($VD_alt_dial =~ /ALT/) ) ) { $addr3_dial_skip=0; $VD_address3=''; - $stmtA="SELECT address3,gmt_offset_now,state,list_id FROM vicidial_list where lead_id='$VD_lead_id';"; + $stmtA="SELECT address3,gmt_offset_now,state,list_id,phone_code FROM vicidial_list where lead_id='$VD_lead_id';"; if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -1869,6 +1895,7 @@ sub process_request $VD_gmt_offset_now = $aryA[1]; $VD_state = $aryA[2]; $VD_list_id = $aryA[3]; + $VD_phone_code = $aryA[4]; $epc_countCAMPDATA++; } $sthA->finish(); @@ -1921,17 +1948,34 @@ sub process_request } if ($VD_alt_dnc_count < 1) { - $stmtA = "INSERT INTO vicidial_hopper SET lead_id='$VD_lead_id',campaign_id='$VD_campaign_id',status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='ADDR3',user='',priority='20',source='A';"; - $affected_rows = $dbhA->do($stmtA); - if ($AGILOG) {$agi_string = "-- VDH record inserted: |$affected_rows| |$stmtA|"; &agi_output;} + $passed_24hour_call_count=1; + if ( ($SScall_limit_24hour > 0) && ($VD_call_limit_24hour_method =~ /PHONE_NUMBER|LEAD/) ) + { + $temp_24hour_phone = $VD_address3; + $temp_24hour_phone_code = $VD_phone_code; + if ($DB > 0) {print "24-Hour Call Count Check: $SScall_limit_24hour|$VD_call_limit_24hour_method|$VD_lead_id|\n";} + &check_24hour_call_count; + } + if ($passed_24hour_call_count > 0) + { + $stmtA = "INSERT INTO vicidial_hopper SET lead_id='$VD_lead_id',campaign_id='$VD_campaign_id',status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='ADDR3',user='',priority='20',source='A';"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDH record inserted: |$affected_rows| |$stmtA|"; &agi_output;} + if ($AGILOG) {$aad_string = "$VD_lead_id|$VD_address3|$VD_campaign_id|ADDR3|20|hopper insert|"; &aad_output;} + } + else + {$addr3_dial_skip=1; $addr3_skip_reason='24-hour call count limit failed';} } else - {$addr3_dial_skip=1;} + {$addr3_dial_skip=1; $addr3_skip_reason='DNC check failed';} } else - {$addr3_dial_skip=1;} + {$addr3_dial_skip=1; $addr3_skip_reason='ADDR3 phone invalid';} if ($addr3_dial_skip > 0) - {$VD_alt_dial='ADDR3';} + { + $VD_alt_dial='ADDR3'; + if ($AGILOG) {$aad_string = "$VD_lead_id|$VD_address3|$VD_campaign_id|ADDR3|0|hopper skip|$addr3_skip_reason|"; &aad_output;} + } } if ( ( ($VD_auto_alt_dial =~ /(EXTENDED_ONLY)/) && ($VD_alt_dial =~ /NONE|MAIN/) ) || ( ($VD_auto_alt_dial =~ /(ALT_AND_EXTENDED)/) && ($VD_alt_dial =~ /ALT/) ) || ( ($VD_auto_alt_dial =~ /ADDR3_AND_EXTENDED|ALT_AND_ADDR3_AND_EXTENDED/) && ($VD_alt_dial =~ /ADDR3/) ) || ( ($VD_auto_alt_dial =~ /(EXTENDED)/) && ($VD_alt_dial =~ /X/) && ($VD_alt_dial !~ /XLAST/) ) ) { @@ -1973,7 +2017,7 @@ sub process_request while ( ($alt_dial_phones_count > 0) && ($alt_dial_phones_count > $Xlast) ) { $Xlast++; - $stmtA="SELECT alt_phone_id,phone_number,active FROM vicidial_list_alt_phones where lead_id='$VD_lead_id' and alt_phone_count='$Xlast';"; + $stmtA="SELECT alt_phone_id,phone_number,active,phone_code FROM vicidial_list_alt_phones where lead_id='$VD_lead_id' and alt_phone_count='$Xlast';"; if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -1981,9 +2025,10 @@ sub process_request if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; - $VD_altdial_id = $aryA[0]; - $VD_altdial_phone = $aryA[1]; - $VD_altdial_active = $aryA[2]; + $VD_altdial_id = $aryA[0]; + $VD_altdial_phone = $aryA[1]; + $VD_altdial_active = $aryA[2]; + $VD_altdial_phone_code = $aryA[3]; } else {$Xlast=9999999999;} @@ -2044,14 +2089,31 @@ sub process_request { if ($alt_dial_phones_count eq '$Xlast') {$Xlast = 'LAST';} - $stmtA = "INSERT INTO vicidial_hopper SET lead_id='$VD_lead_id',campaign_id='$VD_campaign_id',status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='X$Xlast',user='',priority='15',source='A';"; - $affected_rows = $dbhA->do($stmtA); - if ($AGILOG) {$agi_string = "-- VDH record inserted: |$affected_rows| |$stmtA|X$Xlast|$VD_altdial_id|"; &agi_output;} - $Xlast=9999999999; + $passed_24hour_call_count=1; + if ( ($SScall_limit_24hour > 0) && ($VD_call_limit_24hour_method =~ /PHONE_NUMBER|LEAD/) ) + { + $temp_24hour_phone = $VD_altdial_phone; + $temp_24hour_phone_code = $VD_altdial_phone_code; + if ($DB > 0) {print "24-Hour Call Count Check: $SScall_limit_24hour|$VD_call_limit_24hour_method|$VD_lead_id|\n";} + &check_24hour_call_count; + } + if ($passed_24hour_call_count > 0) + { + $stmtA = "INSERT INTO vicidial_hopper SET lead_id='$VD_lead_id',campaign_id='$VD_campaign_id',status='READY',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='X$Xlast',user='',priority='15',source='A';"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDH record inserted: |$affected_rows| |$stmtA|X$Xlast|$VD_altdial_id|"; &agi_output;} + if ($AGILOG) {$aad_string = "$VD_lead_id|$VD_altdial_phone|$VD_campaign_id|X$Xlast|15|hopper insert|"; &aad_output;} + $Xlast=9999999999; + $DNC_hopper_trigger=0; + } + else + {$DNC_hopper_trigger=1;} } else + {$DNC_hopper_trigger=1;} + if ($DNC_hopper_trigger > 0) { - if ( ( ($VD_auto_alt_dial_statuses =~ / DNCC /) && ($DNCC > 0) ) || ( ($VD_auto_alt_dial_statuses =~ / DNCL /) && ($DNCL > 0) ) ) + if ( ( ($VD_auto_alt_dial_statuses =~ / DNCC /) && ($DNCC > 0) ) || ( ($VD_auto_alt_dial_statuses =~ / DNCL /) && ($DNCL > 0) ) || ( ($auto_alt_dial_statuses[$i] =~ / TFHCCL /) && ($TFHCCL > 0) ) ) { if ($alt_dial_phones_count eq '$Xlast') {$Xlast = 'LAST';} @@ -2060,10 +2122,12 @@ sub process_request if ($AGILOG) {$agi_string = "-- VDH record DNC inserted: |$affected_rows| |$stmtA|X$Xlast|$VD_altdial_id|"; &agi_output;} $Xlast=9999999999; if ($AGILOG) {$agi_string = "-- VDH alt dial inserting DNC|X$Xlast|$VD_altdial_phone|"; &agi_output;} + if ($AGILOG) {$aad_string = "$VD_lead_id|$VD_altdial_phone|$VD_campaign_id|X$Xlast|15|hopper DNC insert|"; &aad_output;} } else { if ($AGILOG) {$agi_string = "-- VDH alt dial not-inserting DNC|X$Xlast|$VD_altdial_phone|"; &agi_output;} + if ($AGILOG) {$aad_string = "$VD_lead_id|$VD_altdial_phone|$VD_campaign_id|X$Xlast|15|hopper DNC skip|"; &aad_output;} } } } @@ -2433,6 +2497,136 @@ sub call_quota_logging } } +sub check_24hour_call_count + { + $passed_24hour_call_count=0; + $limit_scopeSQL=''; + if ($VD_call_limit_24hour_scope =~ /CAMPAIGN_LISTS/) + { + $limit_scopeCAMP=''; + $stmtY = "SELECT list_id FROM vicidial_lists where campaign_id='$VD_campaign_id';"; + $sthY = $dbhA->prepare($stmtY) or die "preparing: ",$dbhA->errstr; + $sthY->execute or die "executing: $stmtY", $dbhA->errstr; + $sthYrows=$sthY->rows; + $rec_campLISTS=0; + while ($sthYrows > $rec_campLISTS) + { + @aryY = $sthY->fetchrow_array; + $limit_scopeCAMP .= "'$aryY[0]',"; + $rec_campLISTS++; + } + if (length($limit_scopeCAMP) < 2) {$limit_scopeCAMP="'1'";} + else {chop($limit_scopeCAMP);} + $limit_scopeSQL = "and list_id IN($limit_scopeCAMP)"; + } + if ($VD_call_limit_24hour_method =~ /PHONE_NUMBER/) + { + $stmtA="SELECT count(*) FROM vicidial_lead_24hour_calls where phone_number='$temp_24hour_phone' and phone_code='$temp_24hour_phone_code' and (call_date >= NOW() - INTERVAL 1 DAY) $limit_scopeSQL;"; + } + else + { + $stmtA="SELECT count(*) FROM vicidial_lead_24hour_calls where lead_id='$VD_lead_id' and (call_date >= NOW() - INTERVAL 1 DAY) $limit_scopeSQL;"; + } + if ($DB) {print " Doing 24-Hour Call Count Check: $VD_lead_id|$temp_24hour_phone_code|$temp_24hour_phone - $VD_call_limit_24hour_method|$VD_call_limit_24hour_scope\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $TFhourCOUNT=0; + $TFhourSTATE=''; + $TFhourCOUNTRY=''; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $TFhourCOUNT = ($TFhourCOUNT + $aryA[0]); + } + $sthA->finish(); + $TEMPcall_limit_24hour = $VD_call_limit_24hour; + if ($DBX) {print " 24-Hour Call Limit Count DEBUG: $TFhourCOUNT|$stmtA|\n";} + + if ( ($VD_call_limit_24hour_override !~ /^DISABLED$/) && (length($VD_call_limit_24hour_override) > 0) ) + { + $TFH_areacode = substr($temp_24hour_phone, 0, 3); + $stmtY = "SELECT state,country FROM vicidial_phone_codes where country_code='$temp_24hour_phone_code' and areacode='$TFH_areacode';"; + $sthY = $dbhA->prepare($stmtY) or die "preparing: ",$dbhA->errstr; + $sthY->execute or die "executing: $stmtY", $dbhA->errstr; + $sthYrows=$sthY->rows; + if ($sthYrows > 0) + { + @aryY = $sthY->fetchrow_array; + $TFhourSTATE = $aryY[0]; + $TFhourCOUNTRY = $aryY[1]; + } + $sthA->finish(); + + $TEMP_TFhour_OR_entry=''; + $TFH_OR_method='state_areacode'; + $stmtA = "SELECT container_entry FROM vicidial_settings_containers where container_id='$VD_call_limit_24hour_override';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($DBX) {print "$sthArows|$stmtA\n";} + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $TEMP_TFhour_OR_entry = $aryA[0]; + } + $sthA->finish(); + + if (length($TEMP_TFhour_OR_entry) > 2) + { + @container_lines = split(/\n/,$TEMP_TFhour_OR_entry); + $c=0; + foreach(@container_lines) + { + $container_lines[$c] =~ s/;.*|\r|\t//gi; + $container_lines[$c] =~ s/ => |=> | =>/=>/gi; + if (length($container_lines[$c]) > 3) + { + # define core settings + if ($container_lines[$c] =~ /^method/i) + { + $container_lines[$c] =~ s/method=>//gi; + $TFH_OR_method = $container_lines[$c]; + } + else + { + if ($container_lines[$c] =~ /^state/i) + { + $container_lines[$c] =~ s/state=>//gi; # USA,GA,4 + @TEMP_state_ARY = split(/,/,$container_lines[$c]); + + if ($TFhourCOUNTRY eq $TEMP_state_ARY[0]) + { + $TEMP_state_ARY[2] =~ s/\D//gi; + if ( ($TFhourSTATE eq $TEMP_state_ARY[1]) && (length($TEMP_state_ARY[2]) > 0) ) + { + if ($DB) {print " 24-Hour Call Count State Override Triggered: $TEMPcall_limit_24hour|$container_lines[$c]\n";} + $TEMPcall_limit_24hour = $TEMP_state_ARY[2]; + } + } + } + } + } + if ($DBX) {print " 24-Hour Call Count State Override DEBUG: |$container_lines[$c]|\n";} + $c++; + } + } + } + + if ( ($TFhourCOUNT > 0) && ($TFhourCOUNT >= $TEMPcall_limit_24hour) ) + { + $TFHCCLlead=1; + $TFHCCL++; + $passed_24hour_call_count=0; + if ($DBX) {print "Flagging 24-Hour Call Limit lead: $VD_lead_id ($TFhourCOUNT >= $TEMPcall_limit_24hour) $passed_24hour_call_count\n";} + } + else + { + $passed_24hour_call_count=1; + if ($DBX) {print " 24-Hour Call Limit check passed: $VD_lead_id ($TFhourCOUNT < $TEMPcall_limit_24hour) $passed_24hour_call_count\n";} + } + } + sub agi_output { if ($AGILOG >=2) @@ -2451,6 +2645,18 @@ sub agi_output $agi_string=''; } +sub aad_output + { + if ($AGILOG > 0) + { + ### open the log file for writing ### + open(Aout, ">>$AADLOGfile") || die "Can't open $AADLOGfile: $!\n"; + print Aout "$now_date|$script|$aad_string\n"; + close(Aout); + } + $aad_string=''; + } + # subroutine to parse the asterisk version # and return a hash with the various part sub parse_asterisk_version diff --git a/agc_2-X/trunk/docs/CALL_COUNT_LIMITS.txt b/agc_2-X/trunk/docs/CALL_COUNT_LIMITS.txt index a8642678..8a5e7fde 100644 --- a/agc_2-X/trunk/docs/CALL_COUNT_LIMITS.txt +++ b/agc_2-X/trunk/docs/CALL_COUNT_LIMITS.txt @@ -1,11 +1,11 @@ -CALL COUNT LIMITS Started: 2020-11-22 Updated: 2021-07-14 +CALL COUNT LIMITS Started: 2020-11-22 Updated: 2021-07-18 This document will go over the various "Call Count Limit" features available within VICIdial, including: - Lifetime Lead Call Count Limits - Daily Call Count Limits -- 24-Hour Call Count Limits +- 24-Hour Call Count Limits (added at svn/trunk revision 3484) @@ -32,11 +32,12 @@ Daily Call Count Limits must be enabled on the "Admin -> System Settings" page(E There is also another setting on the campaign detail page related to this Daily Call Count Limit feature: Daily Call Limit Manual. If the Daily Call Count Limit is enabled, this setting will determine if manual dial calls will be counted and or restricted in the daily call count limit. The DISABLED option will not count manual dial calls or restrict them as part of the daily call count limits, only auto-dial calls would be counted restricted. If one of the COUNT options is used, then manual dial calls would be included in the daily call counts. If one of the RESTRICT options is used, then manual dial calls would be restricted as part of the daily call count limit. Default of this setting is DISABLED. NOTE: This feature may conflict with Auto-Alt-Dial features if they are enabled on a campaign. +NOTE: This feature may conflict with Lead Recycling features if they are enabled on a campaign. +NOTE: This feature will not affect ANYONE Scheduled Callbacks, they can be auto-dialed even if the resulting call will go beyond the daily call count limit. - -24-HOUR CALL COUNT LIMITS +24-HOUR CALL COUNT LIMITS (added at svn/trunk revision 3484) 24-Hour Call Count Limits must be enabled on the "Admin -> System Settings" page(Enable 24-Hour Called Count Limits) before you can configure them on a "Modify Campaign -> Detail" page. This setting will limit the number of calls that can be placed to a lead or a phone number within the last 24 hour, with the time being based on the database server-time. @@ -58,6 +59,7 @@ state => USA,GA,4 NOTE: There is no manual dial override for this feature, it will affect all normal customer calls placed within this campaign. NOTE: If you use this feature with Lead Recycling enabled and the 24-Hour call limit is reached for a recycled lead, the recycling count for that lead will reset to 0 after the 24-Hour call count limit time expires. +NOTE: If you use this feature with standard Auto-Alt-Dialing, you can add "TFHCCL" to the list of Auto-Alt-Dial statuses in your campaign if you want a rejected alternate phone number dials to trigger the dialing of the next alternate number(if available for the lead). Why was the "24-Hour Call Count Limits" feature created? diff --git a/agc_2-X/trunk/docs/TILTX_SHAKEN_API.txt b/agc_2-X/trunk/docs/TILTX_SHAKEN_API.txt index 8597987f..ba62bcb5 100644 --- a/agc_2-X/trunk/docs/TILTX_SHAKEN_API.txt +++ b/agc_2-X/trunk/docs/TILTX_SHAKEN_API.txt @@ -1,4 +1,4 @@ -TILTX STIR/SHAKEN API (Call Shaper) INTEGRATION Updated: 2021-07-15 +TILTX STIR/SHAKEN API (Call Shaper) INTEGRATION Updated: 2021-07-17 This document covers the TILTX SHAKEN (Call Shaper) API service features and how they integrate into VICIdial. @@ -31,6 +31,9 @@ REQUIREMENT 3: You will need to put a similar dialplan entry into your Carrier D 3. (YES/NO) whether to speak error messages or not, default 'NO' 4. Settings Container ID(override) to use for TILTX API settings, default 'TILTX_SHAKEN_API_KEY' if empty +NOTE: We suggest also adding a crontab entry(similar to the one below) to remove the /tmp files that are created by the TILTX API requests and responses: +0 6 * * * /usr/bin/find /tmp -maxdepth 1 -type f -mtime +0 -print | xargs rm -f + New VICIdial statuses used: (if you are subscribed to these TILTX services, which you have to pay extra for) ADCCAR - Disconnect Carrier-Defined 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 a29880f0..788b19aa 100644 --- a/agc_2-X/trunk/www/agc/vdc_db_query.php +++ b/agc_2-X/trunk/www/agc/vdc_db_query.php @@ -513,10 +513,11 @@ # 210625-1351 - Added term_reason as a dispo_call_url variable # 210705-1046 - Added User override for campaign manual_dial_filter setting # 210713-1344 - Added call_limit_24hour feature support +# 210718-0936 - Fixes for 24-Hour Call Count Limits with standard Auto-Alt-Dialing # -$version = '2.14-406'; -$build = '210713-1344'; +$version = '2.14-407'; +$build = '210718-0936'; $php_script = 'vdc_db_query.php'; $mel=1; # Mysql Error Log enabled = 1 $mysql_log_count=863; @@ -4237,7 +4238,7 @@ if ($ACTION == 'manDiaLnextCaLL') } ### 24-Hour call count limit check ### - manual_tfhccl_check($lead_id, $agent_dialed_number, $phone_code); + manual_tfhccl_check($lead_id, $agent_dialed_number, $phone_code, 0); } #### END check for 24-hour call count limit #### @@ -5928,7 +5929,7 @@ if ($ACTION == 'manDiaLonly') } ### 24-Hour call count limit check ### - manual_tfhccl_check($lead_id, $phone_number, $phone_code); + manual_tfhccl_check($lead_id, $phone_number, $phone_code, 0); } #### END check for 24-hour call count limit #### @@ -7834,7 +7835,7 @@ if ($stage == "end") if ($auto_dial_level > 0) { ### check to see if campaign has alt_dial enabled - $stmt="SELECT auto_alt_dial,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc,daily_call_count_limit,daily_limit_manual FROM vicidial_campaigns where campaign_id='$campaign';"; + $stmt="SELECT auto_alt_dial,use_internal_dnc,use_campaign_dnc,use_other_campaign_dnc,daily_call_count_limit,daily_limit_manual,call_limit_24hour_method,call_limit_24hour_scope,call_limit_24hour,call_limit_24hour_override FROM vicidial_campaigns where campaign_id='$campaign';"; $rslt=mysql_to_mysqli($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00064',$user,$server_ip,$session_name,$one_mysql_log);} if ($DB) {echo "$stmt\n";} @@ -7842,16 +7843,21 @@ if ($stage == "end") if ($VAC_mancall_ct > 0) { $row=mysqli_fetch_row($rslt); - $auto_alt_dial = $row[0]; - $use_internal_dnc = $row[1]; - $use_campaign_dnc = $row[2]; - $use_other_campaign_dnc = $row[3]; - $daily_call_count_limit = $row[4]; - $daily_limit_manual = $row[5]; + $auto_alt_dial = $row[0]; + $use_internal_dnc = $row[1]; + $use_campaign_dnc = $row[2]; + $use_other_campaign_dnc = $row[3]; + $daily_call_count_limit = $row[4]; + $daily_limit_manual = $row[5]; + $call_limit_24hour_method = $row[6]; + $call_limit_24hour_scope = $row[7]; + $call_limit_24hour = $row[8]; + $call_limit_24hour_override = $row[9]; } else {$auto_alt_dial = 'NONE';} if (preg_match("/(ALT_ONLY|ADDR3_ONLY|ALT_AND_ADDR3|ALT_AND_EXTENDED|ALT_AND_ADDR3_AND_EXTENDED|EXTENDED_ONLY)/i",$auto_alt_dial)) { + $alt_skip_reason=''; $addr3_skip_reason=''; ### check to see if lead should be alt_dialed if (strlen($alt_dial)<2) {$alt_dial = 'NONE';} @@ -7875,7 +7881,7 @@ if ($stage == "end") if ( (preg_match("/(NONE|MAIN)/i",$alt_dial)) and (preg_match("/(ALT_ONLY|ALT_AND_ADDR3|ALT_AND_EXTENDED)/i",$auto_alt_dial)) ) { $alt_dial_skip=0; - $stmt="SELECT alt_phone,gmt_offset_now,state,vendor_lead_code FROM vicidial_list where lead_id='$lead_id';"; + $stmt="SELECT alt_phone,gmt_offset_now,state,vendor_lead_code,phone_code FROM vicidial_list where lead_id='$lead_id';"; $rslt=mysql_to_mysqli($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00065',$user,$server_ip,$session_name,$one_mysql_log);} if ($DB) {echo "$stmt\n";} @@ -7888,6 +7894,7 @@ if ($stage == "end") $gmt_offset_now = $row[1]; $state = $row[2]; $vendor_lead_code = $row[3]; + $phone_code = $row[4]; } else {$alt_phone = '';} if (strlen($alt_phone)>5) @@ -7937,25 +7944,37 @@ if ($stage == "end") } if ($VD_alt_dnc_count < 1) { - ### insert record into vicidial_hopper for alt_phone call attempt - $stmt = "INSERT INTO vicidial_hopper SET lead_id='$lead_id',campaign_id='$campaign',status='HOLD',list_id='$list_id',gmt_offset_now='$gmt_offset_now',state='$state',alt_dial='ALT',user='',priority='25',source='A',vendor_lead_code=\"$vendor_lead_code\";"; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00068',$user,$server_ip,$session_name,$one_mysql_log);} + ### 24-Hour call count limit check ### + $passed_24hour_call_count = manual_tfhccl_check($lead_id, $alt_phone, $phone_code, 1); + + if ($passed_24hour_call_count > 0) + { + ### insert record into vicidial_hopper for alt_phone call attempt + $stmt = "INSERT INTO vicidial_hopper SET lead_id='$lead_id',campaign_id='$campaign',status='HOLD',list_id='$list_id',gmt_offset_now='$gmt_offset_now',state='$state',alt_dial='ALT',user='',priority='25',source='A',vendor_lead_code=\"$vendor_lead_code\";"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00068',$user,$server_ip,$session_name,$one_mysql_log);} + aad_log("$lead_id|$alt_phone|$campaign|ALT|25|hopper HOLD insert|"); + } + else + {$alt_dial_skip=1; $alt_skip_reason='24-hour call count limit failed';} } else - {$alt_dial_skip=1;} + {$alt_dial_skip=1; $alt_skip_reason='DNC check failed';} } else - {$alt_dial_skip=1;} + {$alt_dial_skip=1; $alt_skip_reason='ALT phone invalid';} if ($alt_dial_skip > 0) - {$alt_dial='ALT';} + { + $alt_dial='ALT'; + aad_log("$lead_id|$alt_phone|$campaign|ALT|0|hopper HOLD skip|$alt_skip_reason|"); + } } if ( ( (preg_match("/(ALT)/i",$alt_dial)) and (preg_match("/ALT_AND_ADDR3/i",$auto_alt_dial)) ) or ( (preg_match("/(NONE|MAIN)/i",$alt_dial)) and (preg_match("/ADDR3_ONLY/i",$auto_alt_dial)) ) ) { $addr3_dial_skip=0; - $stmt="SELECT address3,gmt_offset_now,state,vendor_lead_code FROM vicidial_list where lead_id='$lead_id';"; + $stmt="SELECT address3,gmt_offset_now,state,vendor_lead_code,phone_code FROM vicidial_list where lead_id='$lead_id';"; $rslt=mysql_to_mysqli($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00069',$user,$server_ip,$session_name,$one_mysql_log);} if ($DB) {echo "$stmt\n";} @@ -7968,6 +7987,7 @@ if ($stage == "end") $gmt_offset_now = $row[1]; $state = $row[2]; $vendor_lead_code = $row[3]; + $phone_code = $row[4]; } else {$address3 = '';} if (strlen($address3)>5) @@ -8017,19 +8037,31 @@ if ($stage == "end") } if ($VD_alt_dnc_count < 1) { - ### insert record into vicidial_hopper for address3 call attempt - $stmt = "INSERT INTO vicidial_hopper SET lead_id='$lead_id',campaign_id='$campaign',status='HOLD',list_id='$list_id',gmt_offset_now='$gmt_offset_now',state='$state',alt_dial='ADDR3',user='',priority='20',source='A',vendor_lead_code=\"$vendor_lead_code\";"; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00072',$user,$server_ip,$session_name,$one_mysql_log);} + ### 24-Hour call count limit check ### + $passed_24hour_call_count = manual_tfhccl_check($lead_id, $address3, $phone_code, 1); + + if ($passed_24hour_call_count > 0) + { + ### insert record into vicidial_hopper for address3 call attempt + $stmt = "INSERT INTO vicidial_hopper SET lead_id='$lead_id',campaign_id='$campaign',status='HOLD',list_id='$list_id',gmt_offset_now='$gmt_offset_now',state='$state',alt_dial='ADDR3',user='',priority='20',source='A',vendor_lead_code=\"$vendor_lead_code\";"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00072',$user,$server_ip,$session_name,$one_mysql_log);} + aad_log("$lead_id|$address3|$campaign|ADDR3|20|hopper HOLD insert|"); + } + else + {$addr3_dial_skip=1; $addr3_skip_reason='24-hour call count limit failed';} } else - {$addr3_dial_skip=1;} + {$addr3_dial_skip=1; $addr3_skip_reason='DNC check failed';} } else - {$addr3_dial_skip=1;} + {$addr3_dial_skip=1; $addr3_skip_reason='ADDR3 phone invalid';} if ($addr3_dial_skip > 0) - {$alt_dial='ADDR3';} + { + $alt_dial='ADDR3'; + aad_log("$lead_id|$address3|$campaign|ADDR3|0|hopper HOLD skip|$addr3_skip_reason|"); + } } # $fp = fopen ("./alt_multi_log.txt", "a"); @@ -8073,7 +8105,7 @@ if ($stage == "end") while ( ($alt_dial_phones_count > 0) and ($alt_dial_phones_count > $Xlast) ) { $Xlast++; - $stmt="SELECT alt_phone_id,phone_number,active FROM vicidial_list_alt_phones where lead_id='$lead_id' and alt_phone_count='$Xlast';"; + $stmt="SELECT alt_phone_id,phone_number,active,phone_code FROM vicidial_list_alt_phones where lead_id='$lead_id' and alt_phone_count='$Xlast';"; $rslt=mysql_to_mysqli($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00075',$user,$server_ip,$session_name,$one_mysql_log);} if ($DB) {echo "$stmt\n";} @@ -8081,9 +8113,10 @@ if ($stage == "end") if ($VLAP_detail_ct > 0) { $row=mysqli_fetch_row($rslt); - $VD_altdial_id = $row[0]; - $VD_altdial_phone = $row[1]; - $VD_altdial_active = $row[2]; + $VD_altdial_id = $row[0]; + $VD_altdial_phone = $row[1]; + $VD_altdial_active = $row[2]; + $VD_altdial_phone_code = $row[3]; } else {$Xlast=9999999999;} @@ -8137,12 +8170,23 @@ if ($stage == "end") { if ($alt_dial_phones_count == $Xlast) {$Xlast = 'LAST';} - $stmt = "INSERT INTO vicidial_hopper SET lead_id='$lead_id',campaign_id='$campaign',status='HOLD',list_id='$EA_list_id',gmt_offset_now='$EA_gmt_offset_now',state='$EA_state',alt_dial='X$Xlast',user='',priority='15',source='A',vendor_lead_code=\"$EA_vendor_lead_code\";"; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00078',$user,$server_ip,$session_name,$one_mysql_log);} + ### 24-Hour call count limit check ### + $passed_24hour_call_count = manual_tfhccl_check($lead_id, $VD_altdial_phone, $VD_altdial_phone_code, 1); + + if ($passed_24hour_call_count > 0) + { + $stmt = "INSERT INTO vicidial_hopper SET lead_id='$lead_id',campaign_id='$campaign',status='HOLD',list_id='$EA_list_id',gmt_offset_now='$EA_gmt_offset_now',state='$EA_state',alt_dial='X$Xlast',user='',priority='15',source='A',vendor_lead_code=\"$EA_vendor_lead_code\";"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00078',$user,$server_ip,$session_name,$one_mysql_log);} + aad_log("$lead_id|$VD_altdial_phone|$campaign|X$Xlast|15|hopper HOLD insert|"); + } + else + {aad_log("$lead_id|$VD_altdial_phone|$campaign|X$Xlast|0|hopper HOLD skip|24-hour call count limit failed|");} $Xlast=9999999999; } + else + {aad_log("$lead_id|$VD_altdial_phone|$campaign|X$Xlast|0|hopper HOLD skip|DNC check failed|");} } } } @@ -20350,10 +20394,12 @@ function manual_dccl_check($temp_lead_id, $temp_no_hopper, $temp_dial_only) ##### 24-Hour call count limit check ##### -function manual_tfhccl_check($temp_lead_id, $temp_phone_number, $temp_phone_code) +function manual_tfhccl_check($temp_lead_id, $temp_phone_number, $temp_phone_code, $temp_TFHCCLalt) { global $SScall_limit_24hour, $call_limit_24hour_method, $call_limit_24hour_scope, $call_limit_24hour, $call_limit_24hour_override, $campaign, $user, $link, $NOW_TIME, $mel, $server_ip, $session_name, $one_mysql_log, $SSagent_debug_logging, $startMS, $ACTION, $php_script, $stage, $lead_id, $TFhourSTATE, $TFhourCOUNTRY; + $passed_24hour_call_count=1; + #$fp = fopen ("./TFHCCLdebug_log.txt", "a"); #fwrite ($fp, "$NOW_TIME|1 |$temp_lead_id|$temp_phone_number|$temp_phone_code|$TFhourSTATE|$TFhourCOUNTRY|$SScall_limit_24hour|$call_limit_24hour_method|$call_limit_24hour_scope|$call_limit_24hour|$call_limit_24hour_override|\n"); #fclose($fp); @@ -20462,18 +20508,34 @@ function manual_tfhccl_check($temp_lead_id, $temp_phone_number, $temp_phone_code if ( ($TFhourCOUNT > 0) && ($TFhourCOUNT >= $TEMPcall_limit_24hour) ) { - $stmt = "UPDATE vicidial_list SET called_since_last_reset='D' where lead_id='$temp_lead_id';"; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00847',$user,$server_ip,$session_name,$one_mysql_log);} - $VLAEDaffected_rows = mysqli_affected_rows($link); + $passed_24hour_call_count=0; + if ($temp_TFHCCLalt < 1) + { + $stmt = "UPDATE vicidial_list SET called_since_last_reset='D' where lead_id='$temp_lead_id';"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00847',$user,$server_ip,$session_name,$one_mysql_log);} + $VLAEDaffected_rows = mysqli_affected_rows($link); - echo "NUMBER OVER 24-HOUR CALL LIMIT, TRY AGAIN\n"; - $stage .= "|24HRLIMIT|$agent_dialed_number|$temp_lead_id|$TFhourCOUNT|$TEMPcall_limit_24hour|"; - if ($SSagent_debug_logging > 0) {vicidial_ajax_log($NOW_TIME,$startMS,$link,$ACTION,$php_script,$user,$stage,$temp_lead_id,$session_name,$stmt);} - exit; + echo "NUMBER OVER 24-HOUR CALL LIMIT, TRY AGAIN\n"; + $stage .= "|24HRLIMIT|$agent_dialed_number|$temp_lead_id|$TFhourCOUNT|$TEMPcall_limit_24hour|"; + if ($SSagent_debug_logging > 0) {vicidial_ajax_log($NOW_TIME,$startMS,$link,$ACTION,$php_script,$user,$stage,$temp_lead_id,$session_name,$stmt);} + exit; + } } + else + {$passed_24hour_call_count=1;} } #### END check for 24-hour call count limit #### + return $passed_24hour_call_count; + } + +##### 24-Hour call count limit check ##### +function aad_log($aad_string) + { + global $NOW_TIME; + #$aad_fp = fopen ("./auto-alt-dial_log.txt", "a"); + #fwrite ($aad_fp, "$NOW_TIME|$aad_string|\n"); + #fclose($aad_fp); } ?>