From beb7c9124897271c8868deba475421401d462f6f Mon Sep 17 00:00:00 2001 From: mattf Date: Tue, 20 Oct 2009 10:03:39 +0000 Subject: [PATCH] Added ability to use Remote Agents with all inbound next-agent-call settings Added ability to use DNCC and DNCL as Auto-Alt-Dial statuses Fixed DNC scrubbing under some auto-alt-dial circumstances Other small bug fixes git-svn-id: svn://192.168.202.10@1245 3d104415-ff17-0410-8863-d5cf3c621b8a --- UPGRADE | 5 + agi/agi-VDAD_ALL_outbound.agi | 2 +- bin/AST_VDhopper.pl | 389 +++++++++++++- bin/AST_VDremote_agents.pl | 779 +++++++++++++++-------------- bin/FastAGI_log.pl | 51 +- extras/MySQL_AST_CREATE_tables.sql | 7 +- extras/upgrade_2.2.0.sql | 6 + www/agc/vdc_db_query.php | 85 +++- 8 files changed, 899 insertions(+), 425 deletions(-) diff --git a/UPGRADE b/UPGRADE index 6e02f221..b3263421 100644 --- a/UPGRADE +++ b/UPGRADE @@ -259,6 +259,11 @@ NOTE: Upgrading from 1.1.12-3 to 2.0.1 is at the bottom - Must have User "Agent Choose Territories" enabled - Leads must have the owner field set to desired territory +63. Added ability to use Remote Agents with all inbound next-agent-call settings + +64. Added ability to use DNCC and DNCL as Auto-Alt-Dial statuses + + diff --git a/agi/agi-VDAD_ALL_outbound.agi b/agi/agi-VDAD_ALL_outbound.agi index 7b6cff3a..41c5e586 100644 --- a/agi/agi-VDAD_ALL_outbound.agi +++ b/agi/agi-VDAD_ALL_outbound.agi @@ -553,7 +553,7 @@ if ($affected_rows > 0) $TTS_text[$s] =~ s/--A--last_local_call_time--B--/$TTS_last_local_call_time/gi; $TTS_text[$s] =~ s/--A--rank--B--/$TTS_rank/gi; $TTS_text[$s] =~ s/--A--owner--B--/$TTS_owner/gi; - $TTS_text[$s] =~ s/[^,\.\<\>\'\/\=\_ 0-9a-zA-Z]//gi; + $TTS_text[$s] =~ s/[^,\.\<\>\'\/\=\_\-\: 0-9a-zA-Z]//gi; $TTS_textRAW[$s] = $TTS_text[$s]; $TTS_text[$s] =~ s/ /\\ /gi; $TTS_text[$s] =~ s/\./\\./gi; diff --git a/bin/AST_VDhopper.pl b/bin/AST_VDhopper.pl index 5b61b1e0..64215307 100644 --- a/bin/AST_VDhopper.pl +++ b/bin/AST_VDhopper.pl @@ -59,6 +59,7 @@ # 90809-0347 - Quick fix for null list_id loading when no active campaign lists # 90904-1612 - Added timezone ordering # 90907-2132 - Fixed order issues +# 91020-0054 - Fixed Auto-alt-dial DNC issues # # constants @@ -336,6 +337,7 @@ if ($inactive_lists_count > 0) } } + ### BEGIN Change CBHOLD status leads to CALLBK if their vicidial_callbacks time has passed $stmtA = "SELECT count(*) FROM vicidial_callbacks where callback_time <= '$now_date' and status='ACTIVE';"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; @@ -362,11 +364,11 @@ if ($CBHOLD_count > 0) $update_leads .= "'$lead_ids[$cbc]',"; if ($recipient =~ /ANYONE/) { - $CA_lead_id[$cba] = $aryA[0]; - $CA_campaign_id[$cba] = $aryA[2]; - $CA_list_id[$cba] = $aryA[3]; - $CA_gmt_offset_now[$cba] = $aryA[4]; - $CA_state[$cba] = $aryA[5]; + $CA_lead_id[$cba] = $aryA[0]; + $CA_campaign_id[$cba] = $aryA[2]; + $CA_list_id[$cba] = $aryA[3]; + $CA_gmt_offset_now[$cba] = $aryA[4]; + $CA_state[$cba] = $aryA[5]; $cba++; } $cbc++; @@ -407,15 +409,344 @@ if ($CBHOLD_count > 0) ### END Change CBHOLD status leads to CALLBK if their vicidial_callbacks time has passed +### BEGIN Auto-Alt-Dial DNC check and update or delete +### Find out how many leads in the hopper are set to DNC status +$hopper_dnc_count=0; +$stmtA = "SELECT count(*) from $vicidial_hopper where status='DNC';"; +$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; + $hopper_dnc_count = $aryA[0]; + if ($DB) {print " hopper DNC count: $hopper_dnc_count\n";} + if ($DBX) {print " |$stmtA|\n";} + } +$sthA->finish(); +if ($hopper_dnc_count > 0) + { + $event_string = "|hopper DNC count: $hopper_dnc_count||"; + &event_logger; + + ### Gather all DNC statused vicidial_hopper entries + $stmtA = "SELECT hopper_id,lead_id,alt_dial,campaign_id FROM $vicidial_hopper where status='DNC';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $aad=0; + while ($sthArows > $aad) + { + @aryA = $sthA->fetchrow_array; + $AAD_hopper_id[$aad] = $aryA[0]; + $AAD_lead_id[$aad] = $aryA[1]; + $AAD_alt_dial[$aad] = $aryA[2]; + $AAD_campaign_id[$aad] = $aryA[3]; + $aad++; + } + $sthA->finish(); + + ### Go through all DNC statused vicidial_hopper entries and look for next number. If found, set the next phone number, alt dial and change status to READY + $aad=0; + while ($sthArows > $aad) + { + $auto_alt_dial=''; + $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 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]; + } + $sthA->finish(); + + $event_string = "|DNC record: $AAD_lead_id[$aad]|$AAD_campaign_id[$aad]|$VD_auto_alt_dial|$AAD_alt_dial[$aad]"; + &event_logger; + + 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='$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; + $sthArows=$sthA->rows; + $epc_countCAMPDATA=0; + while ($sthArows > $epc_countCAMPDATA) + { + @aryA = $sthA->fetchrow_array; + $VD_alt_phone = $aryA[0]; + $VD_alt_phone =~ s/\D//gi; + $VD_gmt_offset_now = $aryA[1]; + $VD_state = $aryA[2]; + $VD_list_id = $aryA[3]; + $epc_countCAMPDATA++; + } + $sthA->finish(); + if (length($VD_alt_phone)>5) + { + if ($VD_use_internal_dnc =~ /Y/) + { + $stmtA="SELECT count(*) FROM vicidial_dnc where phone_number='$VD_alt_phone';"; + if ($DB) {$event_string = "|$stmtA|"; &event_logger;} + $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_alt_dnc_count = $aryA[0]; + } + $sthA->finish(); + } + else {$VD_alt_dnc_count=0;} + if ($VD_use_campaign_dnc =~ /Y/) + { + $stmtA="SELECT count(*) FROM vicidial_campaign_dnc where phone_number='$VD_alt_phone' and campaign_id='$VD_campaign_id';"; + if ($DB) {$event_string = "|$stmtA|"; &event_logger;} + $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_alt_dnc_count = ($VD_alt_dnc_count + $aryA[0]); + } + $sthA->finish(); + } + 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;} + } + else + {$alt_dial_skip=1;} + } + else + {$alt_dial_skip=1;} + if ($alt_dial_skip > 0) + {$VD_alt_dial='ALT';} + } + 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]';"; + if ($DB) {$event_string = "|$stmtA|"; &event_logger;} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $epc_countCAMPDATA=0; + while ($sthArows > $epc_countCAMPDATA) + { + @aryA = $sthA->fetchrow_array; + $VD_address3 = $aryA[0]; + $VD_address3 =~ s/\D//gi; + $VD_gmt_offset_now = $aryA[1]; + $VD_state = $aryA[2]; + $VD_list_id = $aryA[3]; + $epc_countCAMPDATA++; + } + $sthA->finish(); + if (length($VD_address3)>5) + { + if ($VD_use_internal_dnc =~ /Y/) + { + $stmtA="SELECT count(*) FROM vicidial_dnc where phone_number='$VD_address3';"; + if ($DB) {$event_string = "|$stmtA|"; &event_logger;} + $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_alt_dnc_count = $aryA[0]; + } + $sthA->finish(); + } + else {$VD_alt_dnc_count=0;} + if ($VD_use_campaign_dnc =~ /Y/) + { + $stmtA="SELECT count(*) FROM vicidial_campaign_dnc where phone_number='$VD_address3' and campaign_id='$VD_campaign_id';"; + if ($DB) {$event_string = "|$stmtA|"; &event_logger;} + $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_alt_dnc_count = ($VD_alt_dnc_count + $aryA[0]); + } + $sthA->finish(); + } + 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;} + } + else + {$addr3_dial_skip=1;} + } + else + {$addr3_dial_skip=1;} + if ($addr3_dial_skip > 0) + {$VD_alt_dial='ADDR3';} + } + 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/) ) ) + { + if ($VD_alt_dial =~ /ADDR3/) {$Xlast=0;} + else + {$Xlast = $VD_alt_dial;} + $Xlast =~ s/\D//gi; + if (length($Xlast)<1) + {$Xlast=0;} + $VD_altdialx=''; + $stmtA="SELECT gmt_offset_now,state,list_id FROM vicidial_list where lead_id='$VD_lead_id';"; + if ($DB) {$event_string = "|$stmtA|"; &event_logger;} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $epc_countCAMPDATA=0; + while ($sthArows > $epc_countCAMPDATA) + { + @aryA = $sthA->fetchrow_array; + $VD_gmt_offset_now = $aryA[0]; + $VD_state = $aryA[1]; + $VD_list_id = $aryA[2]; + $epc_countCAMPDATA++; + } + $sthA->finish(); + $alt_dial_phones_count=0; + $stmtA="SELECT count(*) FROM vicidial_list_alt_phones 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; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $alt_dial_phones_count = $aryA[0]; + } + $sthA->finish(); + + if ($alt_dial_phones_count <= $Xlast) + { + $stmtA = "DELETE FROM vicidial_hopper where hopper_id='$AAD_hopper_id[$aad]';"; + $affected_rows = $dbhA->do($stmtA); + if ($DB) {$event_string = "-- VDH record DNC deleted: |$affected_rows| |$stmtA|X$Xlast|$VD_altdial_id|"; &event_logger;} + } + + 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';"; + if ($DB) {$event_string = "|$stmtA|"; &event_logger;} + $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_altdial_id = $aryA[0]; + $VD_altdial_phone = $aryA[1]; + $VD_altdial_active = $aryA[2]; + } + else + {$Xlast=9999999999;} + $sthA->finish(); + + if ($VD_altdial_active =~ /Y/) + { + if ($VD_use_internal_dnc =~ /Y/) + { + $stmtA="SELECT count(*) FROM vicidial_dnc where phone_number='$VD_altdial_phone';"; + if ($DB) {$event_string = "|$stmtA|"; &event_logger;} + $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_alt_dnc_count = $aryA[0]; + } + $sthA->finish(); + } + else {$VD_alt_dnc_count=0;} + if ($VD_use_campaign_dnc =~ /Y/) + { + $stmtA="SELECT count(*) FROM vicidial_campaign_dnc where phone_number='$VD_altdial_phone' and campaign_id='$VD_campaign_id';"; + if ($DB) {$event_string = "|$stmtA|"; &event_logger;} + $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_alt_dnc_count = ($VD_alt_dnc_count + $aryA[0]); + } + $sthA->finish(); + } + if ($VD_alt_dnc_count < 1) + { + 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; + } + else + { + if ($alt_dial_phones_count eq '$Xlast') + {$Xlast = 'LAST';} + $stmtA = "UPDATE vicidial_hopper SET status='DNC',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 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;} + } + } + } + } + if ($VD_alt_dial =~ /XLAST/) + { + $stmtA = "DELETE FROM vicidial_hopper where hopper_id='$AAD_hopper_id[$aad]';"; + $affected_rows = $dbhA->do($stmtA); + if ($DB) {$event_string = "-- VDH record DNC deleted: |$affected_rows| |$stmtA|X$Xlast|$VD_altdial_id|"; &event_logger;} + } + + + + + + + + + $aad++; + } + } +### END Auto-Alt-Dial DNC check and update or delete + + + @campaign_id=@MT; if ($CLIcampaign) { - $stmtA = "SELECT campaign_id,lead_order,hopper_level,auto_dial_level,local_call_time,lead_filter_id,use_internal_dnc,dial_method,available_only_ratio_tally,adaptive_dropped_percentage,adaptive_maximum_level,dial_statuses,list_order_mix,use_campaign_dnc,drop_lockout_time,no_hopper_dialing from vicidial_campaigns where campaign_id='$CLIcampaign';"; + $stmtA = "SELECT campaign_id,lead_order,hopper_level,auto_dial_level,local_call_time,lead_filter_id,use_internal_dnc,dial_method,available_only_ratio_tally,adaptive_dropped_percentage,adaptive_maximum_level,dial_statuses,list_order_mix,use_campaign_dnc,drop_lockout_time,no_hopper_dialing,auto_alt_dial_statuses from vicidial_campaigns where campaign_id='$CLIcampaign';"; } else { - $stmtA = "SELECT campaign_id,lead_order,hopper_level,auto_dial_level,local_call_time,lead_filter_id,use_internal_dnc,dial_method,available_only_ratio_tally,adaptive_dropped_percentage,adaptive_maximum_level,dial_statuses,list_order_mix,use_campaign_dnc,drop_lockout_time,no_hopper_dialing from vicidial_campaigns where active='Y';"; + $stmtA = "SELECT campaign_id,lead_order,hopper_level,auto_dial_level,local_call_time,lead_filter_id,use_internal_dnc,dial_method,available_only_ratio_tally,adaptive_dropped_percentage,adaptive_maximum_level,dial_statuses,list_order_mix,use_campaign_dnc,drop_lockout_time,no_hopper_dialing,auto_alt_dial_statuses from vicidial_campaigns where active='Y';"; } $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -443,6 +774,7 @@ while ($sthArows > $rec_count) $use_campaign_dnc[$rec_count] = $aryA[13]; $drop_lockout_time[$rec_count] = $aryA[14]; $no_hopper_dialing[$rec_count] = $aryA[15]; + $auto_alt_dial_statuses[$rec_count] = $aryA[16]; $rec_count++; } @@ -708,7 +1040,7 @@ foreach(@campaign_id) { if (length($state_rules[$b])>1) { - $stmtA = "SELECT * from vicidial_state_call_times where state_call_time_id='$state_rules[$b]';"; + $stmtA = "SELECT state_call_time_id,state_call_time_state,state_call_time_name,state_call_time_comments,sct_default_start,sct_default_stop,sct_sunday_start,sct_sunday_stop,sct_monday_start,sct_monday_stop,sct_tuesday_start,sct_tuesday_stop,sct_wednesday_start,sct_wednesday_stop,sct_thursday_start,sct_thursday_stop,sct_friday_start,sct_friday_stop,sct_saturday_start,sct_saturday_stop from vicidial_state_call_times where state_call_time_id='$state_rules[$b]';"; if ($DBX) {print " |$stmtA|\n";} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -1022,7 +1354,7 @@ foreach(@campaign_id) ##### BEGIN lead recycling parsing and prep ### - $stmtA = "SELECT * from vicidial_lead_recycle where campaign_id='$campaign_id[$i]' and active='Y';"; + $stmtA = "SELECT recycle_id,campaign_id,status,attempt_delay,attempt_maximum,active from vicidial_lead_recycle where campaign_id='$campaign_id[$i]' and active='Y';"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -1131,14 +1463,12 @@ foreach(@campaign_id) $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) + if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; $hopper_ready_count = $aryA[0]; if ($DB) {print " hopper READY count: $hopper_ready_count\n";} if ($DBX) {print " |$stmtA|\n";} - $rec_count++; } $sthA->finish(); $event_string = "|$campaign_id[$i]|$hopper_level[$i]|$hopper_ready_count|$local_call_time[$i]||"; @@ -1262,14 +1592,12 @@ foreach(@campaign_id) $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) + if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; $campaign_leads_to_call[$i] = "$aryA[0]"; if ($DB) {print " leads to call count: $campaign_leads_to_call[$i]\n";} if ($DBX) {print " |$stmtA|\n";} - $rec_count++; } $sthA->finish(); @@ -1279,14 +1607,12 @@ foreach(@campaign_id) $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) + if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; $NEW_campaign_leads_to_call[$i] = "$aryA[0]"; if ($DB) {print " NEW leads to call count: $NEW_campaign_leads_to_call[$i]\n";} if ($DBX) {print " |$stmtA|\n";} - $rec_count++; } $sthA->finish(); } @@ -1645,6 +1971,8 @@ foreach(@campaign_id) if ($leads_to_hopper[$h] != '0') { $DNClead=0; + $DNCC=0; + $DNCL=0; if ($use_internal_dnc[$i] =~ /Y/) { if ($DB) {print " Doing DNC Check: $phone_to_hopper[$h] - $use_internal_dnc[$i]\n";} @@ -1652,16 +1980,15 @@ foreach(@campaign_id) $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) + if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; $DNClead = "$aryA[0]"; - $rec_count++; } $sthA->finish(); if ($DNClead != '0') { + $DNCL++; $stmtA = "UPDATE vicidial_list SET status='DNCL' where lead_id='$leads_to_hopper[$h]';"; $affected_rows = $dbhA->do($stmtA); if ($DBX) {print "Flagging DNC lead: $affected_rows $phone_to_hopper[$h]\n";} @@ -1674,16 +2001,15 @@ foreach(@campaign_id) $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) + if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; $DNClead = "$aryA[0]"; - $rec_count++; } $sthA->finish(); if ($DNClead != '0') { + $DNCC++; $stmtA = "UPDATE vicidial_list SET status='DNCC' where lead_id='$leads_to_hopper[$h]';"; $affected_rows = $dbhA->do($stmtA); if ($DBX) {print "Flagging DNC lead: $affected_rows $phone_to_hopper[$h] $campaign_id[$i]\n";} @@ -1700,6 +2026,21 @@ foreach(@campaign_id) &detail_logger; } } + 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 =~ / DNCC /) && ($DNCC > 0) ) || ( ($auto_alt_dial_statuses =~ / DNCC /) && ($DNCL > 0) ) ) + { + $stmtA = "INSERT INTO $vicidial_hopper (lead_id,campaign_id,status,user,list_id,gmt_offset_now,state,priority) values('$leads_to_hopper[$h]','$campaign_id[$i]','DNC','','$lists_to_hopper[$h]','$gmt_to_hopper[$h]','$state_to_hopper[$h]','0');"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "LEAD INSERTED AS DNC: $affected_rows|$leads_to_hopper[$h]|\n";} + if ($DB_detail) + { + $detail_string = "|$campaign_id[$i]|$leads_to_hopper[$h]|$phone_to_hopper[$h]|$state_to_hopper[$h]|$gmt_to_hopper[$h]|$status_to_hopper[$h]|$modify_to_hopper[$h]|$user_to_hopper[$h]|"; + &detail_logger; + } + } + } } $h++; } diff --git a/bin/AST_VDremote_agents.pl b/bin/AST_VDremote_agents.pl index 7d6e1916..6c83f6d6 100644 --- a/bin/AST_VDremote_agents.pl +++ b/bin/AST_VDremote_agents.pl @@ -1,16 +1,13 @@ #!/usr/bin/perl # -# AST_VDremote_agents.pl version 2.0.5 *DBI-version* -# -# DESCRIPTION: -# uses Net::MySQL to keep remote agents logged in to the VICIDIAL system +# AST_VDremote_agents.pl version 2.2.0 *DBI-version* # # SUMMARY: # This program was designed for people using the Asterisk PBX with VICIDIAL # -# For the client to use VICIDIAL with remote agents, this must always be running +# To use VICIDIAL with remote agents, this must always be running # -# It is recommended that you run this program on the local Asterisk machine +# This program must be run on each local Asterisk machine that has Remote Agents # # This script is to run perpetually querying every second to update the remote # agents that should appear to be logged in so that the calls can be transferred @@ -19,7 +16,7 @@ # It is good practice to keep this program running by placing the associated # KEEPALIVE script running every minute to ensure this program is always running # -# Copyright (C) 2008 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2009 Matt Florell LICENSE: AGPLv2 # # CHANGELOG: # 50215-0954 - First version of script @@ -27,7 +24,6 @@ # 60807-1003 - Changed to DBI # - Changed to use /etc/astguiclient.conf for configs # 60814-1726 - Added option for no logging to file -# 60814-1726 - Added option for no logging to file # 61012-1025 - Added performance testing options # 61110-1443 - Added user_level from vicidial_user record into vicidial_live_agents # 70213-1306 - Added queuemetrics logging @@ -38,57 +34,57 @@ # 81007-1746 - Added debugX output for count statements and changed to if from while # 81026-1246 - Added better logging of calls and fixed the DROP bug # 90808-0247 - Added agent last_state_change field +# 91013-1128 - Added full inbound compatibility with vicidial_live_inbound_agents table # ### begin parsing run-time options ### if (length($ARGV[0])>1) -{ + { $i=0; while ($#ARGV >= $i) - { - $args = "$args $ARGV[$i]"; - $i++; - } - - if ($args =~ /--help/i) - { - print "allowed run time options:\n [-t] = test\n [-v] = verbose debug messages\n [--delay=XXX] = delay of XXX seconds per loop, default 2 seconds\n\n"; - } - else - { - if ($args =~ /--delay=/i) { - @data_in = split(/--delay=/,$args); + $args = "$args $ARGV[$i]"; + $i++; + } + if ($args =~ /--help/i) + { + print "allowed run time options:\n [-t] = test\n [-v] = verbose debug messages\n [--delay=XXX] = delay of XXX seconds per loop, default 2 seconds\n\n"; + } + else + { + if ($args =~ /--delay=/i) + { + @data_in = split(/--delay=/,$args); $loop_delay = $data_in[1]; print " LOOP DELAY OVERRIDE!!!!! = $loop_delay seconds\n\n"; $loop_delay = ($loop_delay * 1000); - } + } else - { - $loop_delay = '2000'; - } + { + $loop_delay = '2000'; + } if ($args =~ /--debug/i) - { - $DB=1; - print "\n-----DEBUGGING -----\n\n"; - } + { + $DB=1; + print "\n-----DEBUGGING -----\n\n"; + } if ($args =~ /--debugX/i) - { - $DBX=1; - print "\n----- SUPER-DUPER DEBUGGING -----\n\n"; - } + { + $DBX=1; + print "\n----- SUPER-DUPER DEBUGGING -----\n\n"; + } if ($args =~ /-t/i) - { - $TEST=1; - $T=1; + { + $TEST=1; + $T=1; + } } } -} else -{ -print "no command line options set\n"; + { + print "no command line options set\n"; $loop_delay = '2000'; -} + } ### end parsing run-time options ### @@ -101,7 +97,7 @@ $local_AMP = '@'; $agents = '@agents'; # default path to astguiclient configuration file: -$PATHconf = '/etc/astguiclient.conf'; +$PATHconf = '/etc/astguiclient.conf'; open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; @conf = ; @@ -142,7 +138,7 @@ foreach(@conf) $server_ip = $VARserver_ip; # Asterisk server IP - &get_time_now; # update time/date variables +&get_time_now; # update time/date variables if (!$VDRLOGfile) {$VDRLOGfile = "$PATHlogs/remoteagent.$year-$mon-$mday";} if (!$VARDB_port) {$VARDB_port='3306';} @@ -154,49 +150,47 @@ $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VA or die "Couldn't connect to database: " . DBI->errstr; ### Grab Server values from the database - $stmtA = "SELECT vd_server_logs,local_gmt,ext_context FROM servers where server_ip = '$VARserver_ip';"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $DBvd_server_logs = "$aryA[0]"; - $DBSERVER_GMT = "$aryA[1]"; - $ext_context = "$aryA[2]"; - if ($DBvd_server_logs =~ /Y/) {$SYSLOG = '1';} - else {$SYSLOG = '0';} - if (length($DBSERVER_GMT)>0) {$SERVER_GMT = $DBSERVER_GMT;} - $rec_count++; - } - $sthA->finish(); +$stmtA = "SELECT vd_server_logs,local_gmt,ext_context FROM servers where server_ip = '$VARserver_ip';"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; +$rec_count=0; +while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $DBvd_server_logs = $aryA[0]; + $DBSERVER_GMT = $aryA[1]; + $ext_context = $aryA[2]; + if ($DBvd_server_logs =~ /Y/) {$SYSLOG = '1';} + else {$SYSLOG = '0';} + if (length($DBSERVER_GMT)>0) {$SERVER_GMT = $DBSERVER_GMT;} + $rec_count++; + } +$sthA->finish(); - &get_time_now; # update time/date variables +&get_time_now; # update time/date variables - $event_string='PROGRAM STARTED||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||'; - &event_logger; # writes to the log and if debug flag is set prints to STDOUT +$event_string='PROGRAM STARTED||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||'; +&event_logger; # writes to the log and if debug flag is set prints to STDOUT - $event_string='LOGGED INTO MYSQL SERVER ON 1 CONNECTION|'; - &event_logger; +$event_string='LOGGED INTO MYSQL SERVER ON 1 CONNECTION|'; +&event_logger; $one_day_interval = 12; # 1 month loops for one year while($one_day_interval > 0) -{ - - $endless_loop=5760000; # 30 days minutes at XXX seconds per loop - - while($endless_loop > 0) { + $endless_loop=5760000; # 30 days minutes at XXX seconds per loop + while($endless_loop > 0) + { &get_time_now; $VDRLOGfile = "$PATHlogs/remoteagent.$year-$mon-$mday"; if ($endless_loop =~ /0$|5$/) - { - ### Grab Server values from the database + { + ### Grab Server values from the database $stmtA = "SELECT vd_server_logs FROM servers where server_ip = '$VARserver_ip';"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -204,139 +198,163 @@ while($one_day_interval > 0) $rec_count=0; while ($sthArows > $rec_count) { - @aryA = $sthA->fetchrow_array; - $DBvd_server_logs = "$aryA[0]"; - if ($DBvd_server_logs =~ /Y/) {$SYSLOG = '1';} - else {$SYSLOG = '0';} - $rec_count++; + @aryA = $sthA->fetchrow_array; + $DBvd_server_logs = $aryA[0]; + if ($DBvd_server_logs =~ /Y/) {$SYSLOG = '1';} + else {$SYSLOG = '0';} + $rec_count++; } $sthA->finish(); - ############################################# - ##### START QUEUEMETRICS LOGGING LOOKUP ##### - $stmtA = "SELECT enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_log_id FROM system_settings;"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $enable_queuemetrics_logging = "$aryA[0]"; - $queuemetrics_server_ip = "$aryA[1]"; - $queuemetrics_dbname = "$aryA[2]"; - $queuemetrics_login = "$aryA[3]"; - $queuemetrics_pass = "$aryA[4]"; - $queuemetrics_log_id = "$aryA[5]"; - $rec_count++; - } - $sthA->finish(); - ##### END QUEUEMETRICS LOGGING LOOKUP ##### - ########################################### - - - - ### delete call records that are LIVE for over 10 minutes and last_update_time < '$PDtsSQLdate' - $stmtA = "DELETE FROM vicidial_live_agents where server_ip='$server_ip' and status IN('PAUSED') and extension LIKE \"R/%\";"; - $affected_rows = $dbhA->do($stmtA); - - $event_string = "| lagged call vla agent DELETED $affected_rows"; - &event_logger; - - ##### grab number of calls today in this campaign and increment - $stmtA="SELECT calls_today FROM vicidial_live_agents WHERE extension LIKE \"R/%\";"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $vla_cc_ct=$sthA->rows; - if ($vla_cc_ct > 0) - { - @aryA = $sthA->fetchrow_array; - $calls_today = "$aryA[0]"; - $rec_count++; - } - else - {$calls_today ='0';} - $calls_today++; - $sthA->finish(); - - @QHlive_agent_id=@MT; - @QHlead_id=@MT; - @QHuniqueid=@MT; - @QHuser=@MT; - @QHcall_type=@MT; - ##### grab number of calls today in this campaign and increment - $stmtA = "SELECT vla.live_agent_id,vla.lead_id,vla.uniqueid,vla.user,vac.call_type FROM vicidial_live_agents vla,vicidial_auto_calls vac where vla.server_ip='$server_ip' and vla.status IN('QUEUE') and vla.extension LIKE \"R/%\" and vla.uniqueid=vac.uniqueid and vla.channel=vac.channel;"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $vla_qh_ct=$sthA->rows; - $w=0; - while ($vla_qh_ct > $w) - { - @aryA = $sthA->fetchrow_array; - $QHlive_agent_id[$w] = "$aryA[0]"; - $QHlead_id[$w] = "$aryA[1]"; - $QHuniqueid[$w] = "$aryA[2]"; - $QHuser[$w] = "$aryA[3]"; - $QHcall_type[$w] = "$aryA[4]"; - $w++; - } - $sthA->finish(); - - $w=0; - while ($vla_qh_ct > $w) - { - $stmtA = "UPDATE vicidial_live_agents set status='INCALL',last_call_time='$SQLdate',comments='REMOTE',calls_today='$calls_today',last_state_change='$SQLdate' where live_agent_id='$QHlive_agent_id[$w]';"; - $Aaffected_rows = $dbhA->do($stmtA); - - $stmtB = "UPDATE vicidial_list set status='XFER',user='$QHuser[$w]' where lead_id='$QHlead_id[$w]';"; - $Baffected_rows = $dbhA->do($stmtB); - - if ($QHcall_type[$w] =~ /IN/) + ############################################# + ##### START QUEUEMETRICS LOGGING LOOKUP ##### + $stmtA = "SELECT enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_log_id FROM system_settings;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) { - $stmtC = "UPDATE vicidial_closer_log set status='XFER',user='$QHuser[$w]',comments='REMOTE' where lead_id='$QHlead_id[$w]' order by call_date desc limit 1;"; - $Caffected_rows = $dbhA->do($stmtC); + @aryA = $sthA->fetchrow_array; + $enable_queuemetrics_logging = $aryA[0]; + $queuemetrics_server_ip = $aryA[1]; + $queuemetrics_dbname = $aryA[2]; + $queuemetrics_login = $aryA[3]; + $queuemetrics_pass = $aryA[4]; + $queuemetrics_log_id = $aryA[5]; + $rec_count++; } - else + $sthA->finish(); + ##### END QUEUEMETRICS LOGGING LOOKUP ##### + ########################################### + + + ##### grab paused remote agents on this server, then we will delete them + @VLApausedUSER = @MT; + $stmtA = "SELECT user FROM vicidial_live_agents where server_ip='$server_ip' and status IN('PAUSED') and extension LIKE \"R/%\";"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $vla_PAUSED_ct=$sthA->rows; + $r=0; + while ($vla_PAUSED_ct > $r) { - $stmtC = "UPDATE vicidial_log set status='XFER',user='$QHuser[$w]',comments='REMOTE' where uniqueid='$QHuniqueid[$w]';"; - $Caffected_rows = $dbhA->do($stmtC); + @aryA = $sthA->fetchrow_array; + $VLApausedUSER[$r] = $aryA[0]; + $r++; + } + $sthA->finish(); + + $r=0; + $VLAaffected_rows=0; + $VLIAaffected_rows=0; + $VLAaffected_rowsTOTAL=0; + $VLIAaffected_rowsTOTAL=0; + while ($vla_PAUSED_ct > $r) + { + ### delete vicidial_live_agents records for paused remote users + $stmtA = "DELETE FROM vicidial_live_agents where user='$VLApausedUSER[$r]' and server_ip='$server_ip' and status IN('PAUSED') and extension LIKE \"R/%\";"; + $VLAaffected_rows = $dbhA->do($stmtA); + ### delete vicidial_live_inbound_agents records for paused remote users + $stmtA = "DELETE FROM vicidial_live_inbound_agents where user='$VLApausedUSER[$r]';"; + $VLIAaffected_rows = $dbhA->do($stmtA); + $VLAaffected_rowsTOTAL = ($VLAaffected_rows + $VLAaffected_rowsTOTAL); + $VLIAaffected_rowsTOTAL = ($VLIAaffected_rows + $VLIAaffected_rowsTOTAL); + $r++; } - $event_string = "| QUEUEd listing UPDATEd |$Aaffected_rows|$Baffected_rows|$Caffected_rows| |$QHlive_agent_id[$w]|$QHlead_id[$w]|$QHuniqueid[$w]|$QHuser[$w]|$QHcall_type[$w]|"; - &event_logger; + if ( ($VLAaffected_rowsTOTAL > 0) || ($VLIAaffected_rowsTOTAL > 0) ) + { + $event_string = "| lagged call vla agent DELETED: $VLAaffected_rowsTOTAL|$VLIAaffected_rowsTOTAL"; + &event_logger; + } - $w++; + @QHlive_agent_id=@MT; + @QHlead_id=@MT; + @QHuniqueid=@MT; + @QHuser=@MT; + @QHcall_type=@MT; + @QHcampaign_id=@MT; + ##### grab number of QUEUE calls right now and update + $stmtA = "SELECT vla.live_agent_id,vla.lead_id,vla.uniqueid,vla.user,vac.call_type,vac.campaign_id FROM vicidial_live_agents vla,vicidial_auto_calls vac where vla.server_ip='$server_ip' and vla.status IN('QUEUE') and vla.extension LIKE \"R/%\" and vla.uniqueid=vac.uniqueid and vla.channel=vac.channel;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $vla_qh_ct=$sthA->rows; + $w=0; + while ($vla_qh_ct > $w) + { + @aryA = $sthA->fetchrow_array; + $QHlive_agent_id[$w] = $aryA[0]; + $QHlead_id[$w] = $aryA[1]; + $QHuniqueid[$w] = $aryA[2]; + $QHuser[$w] = $aryA[3]; + $QHcall_type[$w] = $aryA[4]; + $QHcampaign_id[$w] = $aryA[5]; + $w++; + } + $sthA->finish(); + + $w=0; + while ($vla_qh_ct > $w) + { + $stmtA = "UPDATE vicidial_live_agents set status='INCALL',last_call_time='$SQLdate',comments='REMOTE',calls_today=(calls_today + 1),last_state_change='$SQLdate' where live_agent_id='$QHlive_agent_id[$w]';"; + $Aaffected_rows = $dbhA->do($stmtA); + + $stmtB = "UPDATE vicidial_list set status='XFER',user='$QHuser[$w]' where lead_id='$QHlead_id[$w]';"; + $Baffected_rows = $dbhA->do($stmtB); + + if ($QHcall_type[$w] =~ /IN/) + { + $stmtC = "UPDATE vicidial_closer_log set status='XFER',user='$QHuser[$w]',comments='REMOTE' where lead_id='$QHlead_id[$w]' and uniqueid='$QHuniqueid[$w]' and campaign_id='$QHcampaign_id[$w]' limit 1;"; + $Caffected_rows = $dbhA->do($stmtC); + + $stmtD = "UPDATE vicidial_live_inbound_agents set calls_today=(calls_today + 1),last_call_time='$SQLdate' where user='$QHuser[$w]' and group_id='$QHcampaign_id[$w]';"; + $Daffected_rows = $dbhA->do($stmtD); + + $stmtE = "UPDATE vicidial_inbound_group_agents set calls_today=(calls_today + 1) where user='$QHuser[$w]' and group_id='$QHcampaign_id[$w]';"; + $Eaffected_rows = $dbhA->do($stmtE); + } + else + { + $stmtC = "UPDATE vicidial_log set status='XFER',user='$QHuser[$w]',comments='REMOTE' where uniqueid='$QHuniqueid[$w]';"; + $Caffected_rows = $dbhA->do($stmtC); + + $Daffected_rows=0; + $Eaffected_rows=0; + } + + $event_string = "| QUEUEd listing UPDATEd: |$Aaffected_rows|$Baffected_rows|$Caffected_rows|$Daffected_rows|$Eaffected_rows| |$QHlive_agent_id[$w]|$QHlead_id[$w]|$QHuniqueid[$w]|$QHuser[$w]|$QHcall_type[$w]|$QHcampaign_id[$w]|"; + &event_logger; + + $w++; + } + + #@psoutput = `/bin/ps -f --no-headers -A`; + @psoutput = `/bin/ps -o "%p %a" --no-headers -A`; + + $running_listen = 0; + + $i=0; + foreach (@psoutput) + { + chomp($psoutput[$i]); + + @psline = split(/\/usr\/bin\/perl /,$psoutput[$i]); + + if ($psline[1] =~ /AST_manager_li/) {$running_listen++;} + + $i++; + } + + if (!$running_listen) + { + $endless_loop=0; + $one_day_interval=0; + print "\nPROCESS KILLED NO LISTENER RUNNING... EXITING\n\n"; + } + + if($DB){print "checking to see if listener is dead |$running_listen|\n";} } - #@psoutput = `/bin/ps -f --no-headers -A`; - @psoutput = `/bin/ps -o "%p %a" --no-headers -A`; - - $running_listen = 0; - - $i=0; - foreach (@psoutput) - { - chomp($psoutput[$i]); - - @psline = split(/\/usr\/bin\/perl /,$psoutput[$i]); - - if ($psline[1] =~ /AST_manager_li/) {$running_listen++;} - - $i++; - } - - if (!$running_listen) - { - $endless_loop=0; - $one_day_interval=0; - print "\nPROCESS KILLED NO LISTENER RUNNING... EXITING\n\n"; - } - - if($DB){print "checking to see if listener is dead |$running_listen|\n";} - } - - - $user_counter=0; $DELusers=''; @DBuser_start=@MT; @@ -357,10 +375,11 @@ while($one_day_interval > 0) @VD_random=@MT; @autocallexists=@MT; @calllogfinished=@MT; - ############################################################################### - ###### first grab all of the ACTIVE remote agents information from the database - ############################################################################### - $stmtA = "SELECT * FROM vicidial_remote_agents where status IN('ACTIVE') and server_ip='$server_ip' order by user_start;"; + + ############################################################################### + ###### first, grab all of the ACTIVE remote agents information from the database + ############################################################################### + $stmtA = "SELECT remote_agent_id,user_start,number_of_lines,server_ip,conf_exten,status,campaign_id,closer_campaigns FROM vicidial_remote_agents where status IN('ACTIVE') and server_ip='$server_ip' order by user_start;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -369,33 +388,33 @@ while($one_day_interval > 0) while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $user_start = "$aryA[1]"; - $number_of_lines = "$aryA[2]"; - $conf_exten = "$aryA[4]"; - $campaign_id = "$aryA[6]"; - $closer_campaigns = "$aryA[7]"; + $user_start = $aryA[1]; + $number_of_lines = $aryA[2]; + $conf_exten = $aryA[4]; + $campaign_id = $aryA[6]; + $closer_campaigns = $aryA[7]; - $y=0; - while ($y < $number_of_lines) + $y=0; + while ($y < $number_of_lines) + { + $random = int( rand(9999999)) + 10000000; + $user_id = ($user_start + $y); + $DBuser_start[$user_counter] = $user_start; + $DBremote_user[$user_counter] = $user_id; + $DBremote_server_ip[$user_counter] = $server_ip; + $DBremote_campaign[$user_counter] = $campaign_id; + $DBremote_conf_exten[$user_counter] = $conf_exten; + if ($conf_exten =~ /999999999999/) { - $random = int( rand(9999999)) + 10000000; - $user_id = ($user_start + $y); - $DBuser_start[$user_counter] = "$user_start"; - $DBremote_user[$user_counter] = "$user_id"; - $DBremote_server_ip[$user_counter] = "$server_ip"; - $DBremote_campaign[$user_counter] = "$campaign_id"; - $DBremote_conf_exten[$user_counter] = "$conf_exten"; - if ($conf_exten =~ /999999999999/) - { - $TESTrun++; - $DBremote_conf_exten[$user_counter] = ($user_counter + 8600051); - } - $DBremote_closer[$user_counter] = "$closer_campaigns"; - $DBremote_random[$user_counter] = "$random"; - - $y++; - $user_counter++; + $TESTrun++; + $DBremote_conf_exten[$user_counter] = ($user_counter + 8600051); } + $DBremote_closer[$user_counter] = $closer_campaigns; + $DBremote_random[$user_counter] = $random; + + $y++; + $user_counter++; + } $rec_count++; } @@ -403,11 +422,10 @@ while($one_day_interval > 0) if ($DB) {print STDERR "$user_counter live remote agents ACTIVE\n";} - - ############################################################################### - ###### second grab all of the INACTIVE remote agents information from the database - ############################################################################### - $stmtA = "SELECT * FROM vicidial_remote_agents where status IN('INACTIVE') and server_ip='$server_ip' order by user_start;"; + ############################################################################### + ###### second, grab all of the INACTIVE remote agents information from the database + ############################################################################### + $stmtA = "SELECT remote_agent_id,user_start,number_of_lines,server_ip,conf_exten,status,campaign_id,closer_campaigns FROM vicidial_remote_agents where status IN('INACTIVE') and server_ip='$server_ip' order by user_start;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -415,26 +433,25 @@ while($one_day_interval > 0) while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $Duser_start = "$aryA[1]"; - $Dnumber_of_lines = "$aryA[2]"; - $w=0; - while ($w < $Dnumber_of_lines) - { - $Duser_id = ($Duser_start + $w); - $DELusers .= "R/$Duser_id|"; - $w++; - } + $Duser_start = "$aryA[1]"; + $Dnumber_of_lines = "$aryA[2]"; + $w=0; + while ($w < $Dnumber_of_lines) + { + $Duser_id = ($Duser_start + $w); + $DELusers .= "R/$Duser_id|"; + $w++; + } $rec_count++; } $sthA->finish(); -# if ($DBX) {print STDERR "INACTIVE remote agents: |$DELusers|\n";} + # if ($DBX) {print STDERR "INACTIVE remote agents: |$DELusers|\n";} - - ############################################################################### - ###### third traverse array of remote agents to be active and insert or update - ###### in vicidial_live_agents table - ############################################################################### + ############################################################################### + ###### third, traverse array of remote agents to be active and insert or update + ###### in vicidial_live_agents and vicidial_live_inbound_agents tables + ############################################################################### $h=0; foreach(@DBremote_user) { @@ -470,7 +487,7 @@ while($one_day_interval > 0) if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; - $loginexistsALL[$h] = "$aryA[0]"; + $loginexistsALL[$h] = $aryA[0]; } $sthA->finish(); @@ -509,7 +526,7 @@ while($one_day_interval > 0) while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $DBuser_level[$h] = "$aryA[0]"; + $DBuser_level[$h] = $aryA[0]; $rec_count++; } $sthA->finish(); @@ -526,7 +543,7 @@ while($one_day_interval > 0) if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; - $LSC_count = "$aryA[0]"; + $LSC_count = $aryA[0]; } $sthA->finish(); @@ -559,41 +576,92 @@ while($one_day_interval > 0) } } } + ##### If there are selected inbound/closer groups, gather in-group rankings and insert/update if needed + @TEMPingroups=@MT; + $TEMPagentINGROUPS=''; + if (length($DBremote_closer[$h]) > 1) + { + $TEMPagentINGROUPS = $DBremote_closer[$h]; + $TEMPagentINGROUPS =~ s/-$//gi; + @TEMPingroups = split(/ /,$TEMPagentINGROUPS); + $s=0; + foreach(@TEMPingroups) + { + if (length($TEMPingroups[$s]) > 1) + { + $TEMPagentWEIGHT=0; + $TEMPagentCALLS=0; + $TEMPexistsVLIA=0; + # grab the group weight and calls today of the agent in each in-group + $DBuser_level[$h]='1'; + $stmtA = "SELECT group_weight,calls_today FROM vicidial_inbound_group_agents where user='$DBuser_start[$h]' and group_id='$TEMPingroups[$s]';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArowsVIGA=$sthA->rows; + if ($sthArowsVIGA > 0) + { + @aryA = $sthA->fetchrow_array; + $TEMPagentWEIGHT = $aryA[0]; + $TEMPagentCALLS = $aryA[1]; + } + $sthA->finish(); + + $stmtA = "SELECT count(*) FROM vicidial_live_inbound_agents where user='$DBremote_user[$h]' and group_id='$TEMPingroups[$s]' and group_weight='$TEMPagentWEIGHT';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArowsVLIA=$sthA->rows; + if ($sthArowsVLIA > 0) + { + @aryA = $sthA->fetchrow_array; + $TEMPexistsVLIA = $aryA[0]; + } + $sthA->finish(); + + if ($TEMPexistsVLIA < 1) + { + $stmtA = "INSERT IGNORE INTO vicidial_live_inbound_agents SET user='$DBremote_user[$h]', group_id='$TEMPingroups[$s]', group_weight='$TEMPagentWEIGHT', calls_today='$TEMPagentCALLS', last_call_time='$SQLdate', last_call_finish='$SQLdate' ON DUPLICATE KEY UPDATE group_weight='$TEMPagentWEIGHT';"; + $affected_rows = $dbhA->do($stmtA); + if ( ($DBX) && ($affected_rows > 0) ) {print STDERR "$DBremote_user[$h] VLIA UPDATE: $affected_rows|$TEMPingroups[$s]|$TEMPagentWEIGHT\n";} + } + } + $s++; + } + } } $h++; } - ############################################################################### - ###### fourth validate that the calls that the vicidial_live_agents are on are not dead - ###### and if they are wipe out the values and set the agent record back to READY - ############################################################################### + ############################################################################### + ###### fourth, validate that the calls that the vicidial_live_agents are on are not dead + ###### and if they are wipe out the values and set the agent record back to READY + ############################################################################### $stmtA = "SELECT user,extension,status,uniqueid,callerid,lead_id,campaign_id FROM vicidial_live_agents where extension LIKE \"R/%\" and server_ip='$server_ip' and uniqueid > 10;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; $rec_count=0; - $z=0; + $z=0; while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $VDuser = "$aryA[0]"; - $VDextension = "$aryA[1]"; - $VDstatus = "$aryA[2]"; - $VDuniqueid = "$aryA[3]"; - $VDcallerid = "$aryA[4]"; - $VDlead_id = "$aryA[5]"; - $VDcampaign_id = "$aryA[6]"; + $VDuser = $aryA[0]; + $VDextension = $aryA[1]; + $VDstatus = $aryA[2]; + $VDuniqueid = $aryA[3]; + $VDcallerid = $aryA[4]; + $VDlead_id = $aryA[5]; + $VDcampaign_id = $aryA[6]; $VDrandom = int( rand(9999999)) + 10000000; - $VD_user[$z] = "$VDuser"; - $VD_extension[$z] = "$VDextension"; - $VD_status[$z] = "$VDstatus"; - $VD_uniqueid[$z] = "$VDuniqueid"; - $VD_callerid[$z] = "$VDcallerid"; - $VD_lead_id[$z] = "$VDlead_id"; - $VD_campaign_id[$z] = "$VDcampaign_id"; - $VD_random[$z] = "$VDrandom"; + $VD_user[$z] = $VDuser; + $VD_extension[$z] = $VDextension; + $VD_status[$z] = $VDstatus; + $VD_uniqueid[$z] = $VDuniqueid; + $VD_callerid[$z] = $VDcallerid; + $VD_lead_id[$z] = $VDlead_id; + $VD_campaign_id[$z] = $VDcampaign_id; + $VD_random[$z] = $VDrandom; $z++; $rec_count++; @@ -611,7 +679,7 @@ while($one_day_interval > 0) if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; - $autocallexists[$z] = "$aryA[0]"; + $autocallexists[$z] = $aryA[0]; } $sthA->finish(); @@ -642,7 +710,7 @@ while($one_day_interval > 0) while ($sthBrows > $rec_count) { @aryB = $sthB->fetchrow_array; - $logintime = "$aryB[0]"; + $logintime = $aryB[0]; $rec_count++; } $sthB->finish(); @@ -722,17 +790,14 @@ while($one_day_interval > 0) - - - - ############################################################################### - ###### last, wait for a little bit and repeat the loop - ############################################################################### + ############################################################################### + ###### last, wait for a little bit and repeat the loop + ############################################################################### ### sleep for X seconds before beginning the loop again usleep(1*$loop_delay*1000); - $endless_loop--; + $endless_loop--; if($DB){print STDERR "\nloop counter: |$endless_loop|\n";} ### putting a blank file called "VDAD.kill" in the directory will automatically safely kill this program @@ -745,28 +810,25 @@ while($one_day_interval > 0) } $bad_grabber_counter=0; + } - } + if($DB){print "DONE... Exiting... Goodbye... See you later... Not really, initiating next loop...\n";} - - if($DB){print "DONE... Exiting... Goodbye... See you later... Not really, initiating next loop...\n";} - - $event_string='HANGING UP|'; - &event_logger; + $event_string='HANGING UP|'; + &event_logger; $one_day_interval--; + } -} - - $event_string='CLOSING DB CONNECTION|'; - &event_logger; +$event_string='CLOSING DB CONNECTION|'; +&event_logger; $dbhA->disconnect(); - if($DB){print "DONE... Exiting... Goodbye... See you later... Really I mean it this time\n";} +if($DB){print "DONE... Exiting... Goodbye... See you later... Really I mean it this time\n";} exit; @@ -779,112 +841,105 @@ exit; - - - - +##### SUBROUTINES ##### sub get_time_now #get the current date and time and epoch for logging call lengths and datetimes -{ -$secX = time(); + { + $secX = time(); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secX); $LOCAL_GMT_OFF = $SERVER_GMT; $LOCAL_GMT_OFF_STD = $SERVER_GMT; if ($isdst) {$LOCAL_GMT_OFF++;} -$GMT_now = ($secX - ($LOCAL_GMT_OFF * 3600)); + $GMT_now = ($secX - ($LOCAL_GMT_OFF * 3600)); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_now); if ($hour < 10) {$hour = "0$hour";} if ($min < 10) {$min = "0$min";} if ($DB) {print "TIME DEBUG: $LOCAL_GMT_OFF_STD|$LOCAL_GMT_OFF|$isdst| GMT: $hour:$min\n";} -($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); -$year = ($year + 1900); -$mon++; -if ($mon < 10) {$mon = "0$mon";} -if ($mday < 10) {$mday = "0$mday";} -if ($hour < 10) {$Fhour = "0$hour";} -if ($min < 10) {$min = "0$min";} -if ($sec < 10) {$sec = "0$sec";} + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + $year = ($year + 1900); + $mon++; + if ($mon < 10) {$mon = "0$mon";} + if ($mday < 10) {$mday = "0$mday";} + if ($hour < 10) {$Fhour = "0$hour";} + if ($min < 10) {$min = "0$min";} + if ($sec < 10) {$sec = "0$sec";} -$now_date_epoch = time(); -$now_date = "$year-$mon-$mday $hour:$min:$sec"; + $now_date_epoch = time(); + $now_date = "$year-$mon-$mday $hour:$min:$sec"; $CIDdate = "$mon$mday$hour$min$sec"; $tsSQLdate = "$year$mon$mday$hour$min$sec"; $SQLdate = "$year-$mon-$mday $hour:$min:$sec"; $filedate = "$year-$mon-$mday"; -$FDtarget = ($secX + 10); -($Fsec,$Fmin,$Fhour,$Fmday,$Fmon,$Fyear,$Fwday,$Fyday,$Fisdst) = localtime($FDtarget); -$Fyear = ($Fyear + 1900); -$Fmon++; -if ($Fmon < 10) {$Fmon = "0$Fmon";} -if ($Fmday < 10) {$Fmday = "0$Fmday";} -if ($Fhour < 10) {$Fhour = "0$Fhour";} -if ($Fmin < 10) {$Fmin = "0$Fmin";} -if ($Fsec < 10) {$Fsec = "0$Fsec";} + $FDtarget = ($secX + 10); + ($Fsec,$Fmin,$Fhour,$Fmday,$Fmon,$Fyear,$Fwday,$Fyday,$Fisdst) = localtime($FDtarget); + $Fyear = ($Fyear + 1900); + $Fmon++; + if ($Fmon < 10) {$Fmon = "0$Fmon";} + if ($Fmday < 10) {$Fmday = "0$Fmday";} + if ($Fhour < 10) {$Fhour = "0$Fhour";} + if ($Fmin < 10) {$Fmin = "0$Fmin";} + if ($Fsec < 10) {$Fsec = "0$Fsec";} $FDtsSQLdate = "$Fyear$Fmon$Fmday$Fhour$Fmin$Fsec"; -$BDtarget = ($secX - 10); -($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) = localtime($BDtarget); -$Byear = ($Byear + 1900); -$Bmon++; -if ($Bmon < 10) {$Bmon = "0$Bmon";} -if ($Bmday < 10) {$Bmday = "0$Bmday";} -if ($Bhour < 10) {$Bhour = "0$Bhour";} -if ($Bmin < 10) {$Bmin = "0$Bmin";} -if ($Bsec < 10) {$Bsec = "0$Bsec";} + $BDtarget = ($secX - 10); + ($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) = localtime($BDtarget); + $Byear = ($Byear + 1900); + $Bmon++; + if ($Bmon < 10) {$Bmon = "0$Bmon";} + if ($Bmday < 10) {$Bmday = "0$Bmday";} + if ($Bhour < 10) {$Bhour = "0$Bhour";} + if ($Bmin < 10) {$Bmin = "0$Bmin";} + if ($Bsec < 10) {$Bsec = "0$Bsec";} $BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec"; -$PDtarget = ($secX - 30); -($Psec,$Pmin,$Phour,$Pmday,$Pmon,$Pyear,$Pwday,$Pyday,$Pisdst) = localtime($PDtarget); -$Pyear = ($Pyear + 1900); -$Pmon++; -if ($Pmon < 10) {$Pmon = "0$Pmon";} -if ($Pmday < 10) {$Pmday = "0$Pmday";} -if ($Phour < 10) {$Phour = "0$Phour";} -if ($Pmin < 10) {$Pmin = "0$Pmin";} -if ($Psec < 10) {$Psec = "0$Psec";} + $PDtarget = ($secX - 30); + ($Psec,$Pmin,$Phour,$Pmday,$Pmon,$Pyear,$Pwday,$Pyday,$Pisdst) = localtime($PDtarget); + $Pyear = ($Pyear + 1900); + $Pmon++; + if ($Pmon < 10) {$Pmon = "0$Pmon";} + if ($Pmday < 10) {$Pmday = "0$Pmday";} + if ($Phour < 10) {$Phour = "0$Phour";} + if ($Pmin < 10) {$Pmin = "0$Pmin";} + if ($Psec < 10) {$Psec = "0$Psec";} $PDtsSQLdate = "$Pyear$Pmon$Pmday$Phour$Pmin$Psec"; -$XDtarget = ($secX - 120); -($Xsec,$Xmin,$Xhour,$Xmday,$Xmon,$Xyear,$Xwday,$Xyday,$Xisdst) = localtime($XDtarget); -$Xyear = ($Xyear + 1900); -$Xmon++; -if ($Xmon < 10) {$Xmon = "0$Xmon";} -if ($Xmday < 10) {$Xmday = "0$Xmday";} -if ($Xhour < 10) {$Xhour = "0$Xhour";} -if ($Xmin < 10) {$Xmin = "0$Xmin";} -if ($Xsec < 10) {$Xsec = "0$Xsec";} + $XDtarget = ($secX - 120); + ($Xsec,$Xmin,$Xhour,$Xmday,$Xmon,$Xyear,$Xwday,$Xyday,$Xisdst) = localtime($XDtarget); + $Xyear = ($Xyear + 1900); + $Xmon++; + if ($Xmon < 10) {$Xmon = "0$Xmon";} + if ($Xmday < 10) {$Xmday = "0$Xmday";} + if ($Xhour < 10) {$Xhour = "0$Xhour";} + if ($Xmin < 10) {$Xmin = "0$Xmin";} + if ($Xsec < 10) {$Xsec = "0$Xsec";} $XDSQLdate = "$Xyear-$Xmon-$Xmday $Xhour:$Xmin:$Xsec"; -$TDtarget = ($secX - 600); -($Tsec,$Tmin,$Thour,$Tmday,$Tmon,$Tyear,$Twday,$Tyday,$Tisdst) = localtime($TDtarget); -$Tyear = ($Tyear + 1900); -$Tmon++; -if ($Tmon < 10) {$Tmon = "0$Tmon";} -if ($Tmday < 10) {$Tmday = "0$Tmday";} -if ($Thour < 10) {$Thour = "0$Thour";} -if ($Tmin < 10) {$Tmin = "0$Tmin";} -if ($Tsec < 10) {$Tsec = "0$Tsec";} + $TDtarget = ($secX - 600); + ($Tsec,$Tmin,$Thour,$Tmday,$Tmon,$Tyear,$Twday,$Tyday,$Tisdst) = localtime($TDtarget); + $Tyear = ($Tyear + 1900); + $Tmon++; + if ($Tmon < 10) {$Tmon = "0$Tmon";} + if ($Tmday < 10) {$Tmday = "0$Tmday";} + if ($Thour < 10) {$Thour = "0$Thour";} + if ($Tmin < 10) {$Tmin = "0$Tmin";} + if ($Tsec < 10) {$Tsec = "0$Tsec";} $TDSQLdate = "$Tyear-$Tmon-$Tmday $Thour:$Tmin:$Tsec"; - -} - - - + } sub event_logger -{ -if ($DB) {print "$now_date|$event_string|\n";} -if ($SYSLOG) { - ### open the log file for writing ### - open(Lout, ">>$VDRLOGfile") - || die "Can't open $VDRLOGfile: $!\n"; - print Lout "$now_date|$event_string|\n"; - close(Lout); + if ($DB) {print "$now_date|$event_string|\n";} + if ($SYSLOG) + { + ### open the log file for writing ### + open(Lout, ">>$VDRLOGfile") + || die "Can't open $VDRLOGfile: $!\n"; + print Lout "$now_date|$event_string|\n"; + close(Lout); + } + $event_string=''; } -$event_string=''; -} diff --git a/bin/FastAGI_log.pl b/bin/FastAGI_log.pl index 2a63766b..dc127e00 100644 --- a/bin/FastAGI_log.pl +++ b/bin/FastAGI_log.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# FastAGI_log.pl version 2.0.5 *DBI-version* +# FastAGI_log.pl version 2.2.0 *DBI-version* # # Experimental Deamon using perl Net::Server that runs as FastAGI to reduce load # replaces the following AGI scripts: @@ -49,6 +49,7 @@ # 90630-2253 - Added Sangoma CDP pre-Answer call processing # 90814-0810 - Added extra logging for vicidial_log in some cases # 90815-0750 - Fixed extra vicidial_log logging +# 91020-0055 - Fixed several bugs with auto-alt-dial, DNC and extended alt number dialing # @@ -1023,10 +1024,10 @@ 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_auto_alt_dial = $aryA[0]; + $VD_auto_alt_dial_statuses = $aryA[1]; + $VD_use_internal_dnc = $aryA[2]; + $VD_use_campaign_dnc = $aryA[3]; $epc_countCAMPDATA++; } $sthA->finish(); @@ -1045,11 +1046,11 @@ sub process_request while ($sthArows > $epc_countCAMPDATA) { @aryA = $sthA->fetchrow_array; - $VD_alt_phone = "$aryA[0]"; + $VD_alt_phone = $aryA[0]; $VD_alt_phone =~ s/\D//gi; - $VD_gmt_offset_now = "$aryA[1]"; - $VD_state = "$aryA[2]"; - $VD_list_id = "$aryA[3]"; + $VD_gmt_offset_now = $aryA[1]; + $VD_state = $aryA[2]; + $VD_list_id = $aryA[3]; $epc_countCAMPDATA++; } $sthA->finish(); @@ -1065,7 +1066,7 @@ sub process_request if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; - $VD_alt_dnc_count = "$aryA[0]"; + $VD_alt_dnc_count = $aryA[0]; } $sthA->finish(); } @@ -1111,11 +1112,11 @@ sub process_request while ($sthArows > $epc_countCAMPDATA) { @aryA = $sthA->fetchrow_array; - $VD_address3 = "$aryA[0]"; + $VD_address3 = $aryA[0]; $VD_address3 =~ s/\D//gi; - $VD_gmt_offset_now = "$aryA[1]"; - $VD_state = "$aryA[2]"; - $VD_list_id = "$aryA[3]"; + $VD_gmt_offset_now = $aryA[1]; + $VD_state = $aryA[2]; + $VD_list_id = $aryA[3]; $epc_countCAMPDATA++; } $sthA->finish(); @@ -1131,7 +1132,7 @@ sub process_request if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; - $VD_alt_dnc_count = "$aryA[0]"; + $VD_alt_dnc_count = $aryA[0]; } $sthA->finish(); } @@ -1182,9 +1183,9 @@ sub process_request while ($sthArows > $epc_countCAMPDATA) { @aryA = $sthA->fetchrow_array; - $VD_gmt_offset_now = "$aryA[1]"; - $VD_state = "$aryA[2]"; - $VD_list_id = "$aryA[3]"; + $VD_gmt_offset_now = $aryA[0]; + $VD_state = $aryA[1]; + $VD_list_id = $aryA[2]; $epc_countCAMPDATA++; } $sthA->finish(); @@ -1197,7 +1198,7 @@ sub process_request if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; - $alt_dial_phones_count = "$aryA[0]"; + $alt_dial_phones_count = $aryA[0]; } $sthA->finish(); @@ -1261,18 +1262,24 @@ sub process_request $Xlast=9999999999; } else - {if ($AGILOG) {$agi_string = "-- VDH alt dial is DNC|X$Xlast|$VD_altdial_phone|"; &agi_output;}} + { + 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='DNC',list_id='$VD_list_id',gmt_offset_now='$VD_gmt_offset_now',state='$VD_state',alt_dial='X$Xlast',user='',priority='15';"; + $affected_rows = $dbhA->do($stmtA); + 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 is DNC|X$Xlast|$VD_altdial_phone|"; &agi_output;} + } } } } } ##### END AUTO ALT PHONE DIAL SECTION ##### } - } } $dbhA->disconnect(); - } } ################################################################### diff --git a/extras/MySQL_AST_CREATE_tables.sql b/extras/MySQL_AST_CREATE_tables.sql index e66cc4cd..6db9e663 100644 --- a/extras/MySQL_AST_CREATE_tables.sql +++ b/extras/MySQL_AST_CREATE_tables.sql @@ -314,7 +314,7 @@ CREATE TABLE vicidial_hopper ( hopper_id INT(9) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL, lead_id INT(9) UNSIGNED NOT NULL, campaign_id VARCHAR(8), -status ENUM('READY','QUEUE','INCALL','DONE','HOLD') default 'READY', +status ENUM('READY','QUEUE','INCALL','DONE','HOLD','DNC') default 'READY', user VARCHAR(20), list_id BIGINT(14) UNSIGNED NOT NULL, gmt_offset_now DECIMAL(4,2) DEFAULT '0.00', @@ -1252,7 +1252,8 @@ calls_today SMALLINT(5) UNSIGNED default '0', last_call_time DATETIME, last_call_finish DATETIME, index (group_id), -index (group_weight) +index (group_weight), +unique index vlia_user_group_id (user, group_id) ); CREATE TABLE vicidial_campaign_agents ( @@ -1947,7 +1948,7 @@ CREATE INDEX phone_number on vicidial_closer_log (phone_number); CREATE INDEX date_user on vicidial_closer_log (call_date,user); CREATE INDEX comment_a on live_inbound_log (comment_a); -UPDATE system_settings SET db_schema_version='1176',db_schema_update_date=NOW(); +UPDATE system_settings SET db_schema_version='1177',db_schema_update_date=NOW(); GRANT RELOAD ON *.* TO cron@'%'; GRANT RELOAD ON *.* TO cron@localhost; diff --git a/extras/upgrade_2.2.0.sql b/extras/upgrade_2.2.0.sql index d2a5283b..7ad24645 100644 --- a/extras/upgrade_2.2.0.sql +++ b/extras/upgrade_2.2.0.sql @@ -585,3 +585,9 @@ index (event_date) ); UPDATE system_settings SET db_schema_version='1176',db_schema_update_date=NOW(); + +CREATE UNIQUE INDEX vlia_user_group_id ON vicidial_live_inbound_agents (user, group_id); + +ALTER TABLE vicidial_hopper MODIFY status ENUM('READY','QUEUE','INCALL','DONE','HOLD','DNC') default 'READY'; + +UPDATE system_settings SET db_schema_version='1177',db_schema_update_date=NOW(); diff --git a/www/agc/vdc_db_query.php b/www/agc/vdc_db_query.php index 914a5ead..24b7d792 100644 --- a/www/agc/vdc_db_query.php +++ b/www/agc/vdc_db_query.php @@ -217,10 +217,11 @@ # 90924-1544 - Added List callerid override option # 90930-1638 - Added agent_territories feature # 91012-0535 - Fixed User territory no-hopper dial bug +# 91019-1224 - Fixed auto-alt-dial DNC issues # -$version = '2.2.0-126'; -$build = '91012-0535'; +$version = '2.2.0-127'; +$build = '91019-1224'; $mel=1; # Mysql Error Log enabled = 1 $mysql_log_count=256; $one_mysql_log=0; @@ -872,7 +873,7 @@ if ($users_to_parse > 0) ### place the call by inserting into vicidial_manager ################################################################################ if ($ACTION == 'manDiaLnextCaLL') -{ + { $MT[0]=''; $row=''; $rowx=''; $channel_live=1; @@ -1824,14 +1825,13 @@ if ($ACTION == 'manDiaLnextCaLL') $LeaD_InfO .= $owner . "\n"; echo $LeaD_InfO; - - } + } else - { - echo "HOPPER EMPTY\n"; + { + echo "HOPPER EMPTY\n"; + } } } -} ################################################################################ @@ -4350,12 +4350,15 @@ if ($ACTION == 'updateDISPO') if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00154',$user,$server_ip,$session_name,$one_mysql_log);} } - $stmt="SELECT auto_alt_dial_statuses from vicidial_campaigns where campaign_id='$campaign';"; + $stmt="SELECT auto_alt_dial_statuses,use_internal_dnc,use_campaign_dnc from vicidial_campaigns where campaign_id='$campaign';"; $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00155',$user,$server_ip,$session_name,$one_mysql_log);} $row=mysql_fetch_row($rslt); + $VC_auto_alt_dial_statuses = $row[0]; + $use_internal_dnc = $row[1]; + $use_campaign_dnc = $row[2]; - if ( ($auto_dial_level > 0) and (ereg(" $dispo_choice ",$row[0])) ) + if ( ($auto_dial_level > 0) and (ereg(" $dispo_choice ",$VC_auto_alt_dial_statuses)) ) { $stmt = "select count(*) from vicidial_hopper where lead_id='$lead_id' and status='HOLD';"; if ($DB) {echo "$stmt\n";} @@ -4365,10 +4368,66 @@ if ($ACTION == 'updateDISPO') if ($row[0] > 0) { - $stmt="UPDATE vicidial_hopper set status='READY' where lead_id='$lead_id' and status='HOLD' limit 1;"; - if ($format=='debug') {echo "\n";} + ##### Check for alt phone number in DNC list if applicable + $UD_DNC_campaign=0; + $UD_DNC_internal=0; + $vh_phone=''; + $stmt="SELECT phone_number FROM vicidial_hopper where lead_id='$lead_id' and status='HOLD';"; $rslt=mysql_query($stmt, $link); - if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00157',$user,$server_ip,$session_name,$one_mysql_log);} + if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00XXX',$user,$server_ip,$session_name,$one_mysql_log);} + if ($DB) {echo "$stmt\n";} + $ud_record_ct = mysql_num_rows($rslt); + if ($ud_record_ct > 0) + { + $row=mysql_fetch_row($rslt); + $vh_phone = $row[0]; + } + + if (eregi('Y',$use_internal_dnc)) + { + $stmt="SELECT count(*) FROM vicidial_dnc where phone_number='$vh_phone';"; + $rslt=mysql_query($stmt, $link); + if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00XXX',$user,$server_ip,$session_name,$one_mysql_log);} + if ($DB) {echo "$stmt\n";} + $ud_record_ct = mysql_num_rows($rslt); + if ($ud_record_ct > 0) + { + $row=mysql_fetch_row($rslt); + $UD_DNC_internal = $row[0]; + } + } + + if (eregi('Y',$use_campaign_dnc)) + { + $stmt="SELECT count(*) FROM vicidial_campaign_dnc where campaign_id='$campaign' and phone_number='$vh_phone';"; + $rslt=mysql_query($stmt, $link); + if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00XXX',$user,$server_ip,$session_name,$one_mysql_log);} + if ($DB) {echo "$stmt\n";} + $ud_record_ct = mysql_num_rows($rslt); + if ($ud_record_ct > 0) + { + $row=mysql_fetch_row($rslt); + $UD_DNC_campaign = $row[0]; + } + } + + if ( ($UD_DNC_campaign > 0) or ($UD_DNC_internal > 0) ) + { + if ( ( (ereg(" DNCC ",$VC_auto_alt_dial_statuses)) and ($UD_DNC_campaign > 0) ) or ( (ereg(" DNCL ",$VC_auto_alt_dial_statuses)) and ($UD_DNC_internal > 0) ) ) + { + $stmt="UPDATE vicidial_hopper set status='DNC' where lead_id='$lead_id' and status='HOLD' limit 1;"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_query($stmt, $link); + if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00157',$user,$server_ip,$session_name,$one_mysql_log);} + } + } + else + { + $stmt="UPDATE vicidial_hopper set status='READY' where lead_id='$lead_id' and status='HOLD' limit 1;"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_query($stmt, $link); + if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00157',$user,$server_ip,$session_name,$one_mysql_log);} + } } } else