2006-05-12 snapshot

git-svn-id: svn://192.168.202.10@7 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2006-07-07 15:21:52 +00:00
parent 2598ae9ec2
commit 487f7108d4
74 changed files with 10930 additions and 1055 deletions
+459 -73
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# AST_VDhopper.pl version 0.7
# AST_VDhopper.pl version 0.9
#
# DESCRIPTION:
# uses Net::MySQL to update the VICIDIAL leads hopper for the new streamlined
@@ -32,12 +32,16 @@
# 60320-0932 - Added inactive lead list hopper deletion (Thanks Vic Jolin)
# 60322-1030 - Added super debug output
# 60418-0947 - Added lead filter per campaign
# 60509-1416 - Rewrite of local_call_time functions
# 60511-1150 - Added inserts into vicidial_campaign_stats table
#
# constants
$DB=0; # Debug flag, set to 0 for no debug messages, On an active system this will generate lots of lines of output per minute
$US='__';
$MT[0]='';
#$vicidial_hopper='TEST_vicidial_hopper'; # for testing
$vicidial_hopper='vicidial_hopper';
# options
$insert_auto_CB_to_hopper = 1; # set to 1 to automatically insert ANYONE callbacks into the hopper
@@ -52,6 +56,7 @@ if ($hour < 10) {$Fhour = "0$hour";}
if ($min < 10) {$min = "0$min";}
if ($sec < 10) {$sec = "0$sec";}
$now_date = "$year-$mon-$mday $hour:$min:$sec";
$VDL_date = "$year-$mon-$mday 00:00:01";
if (!$VDHLOGfile) {$VDHLOGfile = "/home/cron/hopper.$year-$mon-$mday";}
@@ -127,7 +132,7 @@ if (!$DB_port) {$DB_port='3306';}
sleep(1); ### sleep for 5 seconds to stagger cron script load
use lib './lib', '../lib';
#use lib './lib', '../lib';
use Net::MySQL;
@@ -170,7 +175,7 @@ $GMT_now = ($secX - ($LOCAL_GMT_OFF * 3600));
if ($wipe_hopper_clean)
{
$stmtA = "DELETE from vicidial_hopper;";
$stmtA = "DELETE from $vicidial_hopper;";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
if ($DB) {print "Hopper Wiped Clean: $affected_rows\n";}
@@ -201,7 +206,7 @@ if ($DB) {print "Inactive Lists: $inactive_lists_count\n";}
if ($inactive_lists_count > 0)
{
chop($inactive_lists);
$stmtA = "DELETE from vicidial_hopper where list_id IN($inactive_lists);";
$stmtA = "DELETE from $vicidial_hopper where list_id IN($inactive_lists);";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
if ($DB) {print "Inactive List Leads Deleted: $affected_rows |$stmtA|\n";}
@@ -278,7 +283,7 @@ if ($CBHOLD_count > 0)
$CAu=0;
foreach(@CA_lead_id)
{
$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]';";
$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]';";
$dbhA->query("$stmtA");
$CAu++;
}
@@ -326,88 +331,455 @@ if ($dbhA->has_selected_record)
$i=0;
foreach(@campaign_id)
{
##### calculate what gmt_offset_now values are within the allowed local_call_time setting
$GMT_allowed = '';
### close out MySQL connection and re-connect to start new connection ###
# $dbhA->close();
# my $dbhA = '';
if ($local_call_time[$i] =~ /24hours/)
{
$p='13';
while ($p > -13)
### Make sure this file is in a libs path or put the absolute path to it
# require("/home/cron/AST_SERVER_conf.pl"); # local configuration file
# if (!$DB_port) {$DB_port='3306';}
# use Net::MySQL;
# my $dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port")
# or die "Couldn't connect to database: $DB_server - $DB_database\n";
$VCSdialable_leads=0;
$VCScalls_today=0;
$VCSdrops_today=0;
$VCSdrops_today_pct=0;
$vicidial_log = 'vicidial_log';
$stmtA = "SELECT dialable_leads from vicidial_campaign_stats where campaign_id='$campaign_id[$i]';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
$iter=$dbhA->create_record_iterator;
$rec_count=0;
while ( $record = $iter->each)
{
$tz = sprintf("%.2f", $p); $GMT_allowed .= "'$tz',";
$p = ($p - 0.25);
$VCSdialable_leads = "$record->[0]";
}
}
if ($local_call_time[$i] =~ /9am-9pm/)
{
$p='13';
while ($p > -13)
}
$stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_date';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
$iter=$dbhA->create_record_iterator;
$rec_count=0;
while ( $record = $iter->each)
{
$GMT_test = ($GMT_now + ($p * 3600));
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_test);
if ( ($hour >= 9) && ($hour <= 20) ){$tz = sprintf("%.2f", $p); $GMT_allowed .= "'$tz',";}
$p = ($p - 0.25);
$VCScalls_today = "$record->[0]";
}
}
if ($local_call_time[$i] =~ /9am-5pm/)
}
if ($VCScalls_today > 0)
{
$p='13';
while ($p > -13)
{
$GMT_test = ($GMT_now + ($p * 3600));
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_test);
if ( ($hour >= 9) && ($hour <= 16) ){$tz = sprintf("%.2f", $p); $GMT_allowed .= "'$tz',";}
$p = ($p - 0.25);
}
$stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_date' and status IN('DROP','XDROP');";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
$iter=$dbhA->create_record_iterator;
$rec_count=0;
while ( $record = $iter->each)
{
$VCSdrops_today = "$record->[0]";
if ($VCSdrops_today > 0)
{
$VCSdrops_today_pct = ( ($VCSdrops_today / $VCScalls_today) * 100 );
$VCSdrops_today_pct = sprintf("%.2f", $VCSdrops_today_pct);
}
}
}
}
if ($local_call_time[$i] =~ /12pm-5pm/)
$stmtA = "UPDATE vicidial_campaign_stats SET calls_today='$VCScalls_today',drops_today='$VCSdrops_today',drops_today_pct='$VCSdrops_today_pct' where campaign_id='$campaign_id[$i]';";
$dbhA->query("$stmtA");
##### BEGIN calculate what gmt_offset_now values are within the allowed local_call_time setting ###
$g=0;
$p='13';
$GMT_gmt[0] = '';
$GMT_hour[0] = '';
$GMT_day[0] = '';
if ($DBX) {print "\n |GMT-DAY-HOUR| ";}
while ($p > -13)
{
$p='13';
while ($p > -13)
{
$GMT_test = ($GMT_now + ($p * 3600));
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_test);
if ( ($hour >= 12) && ($hour <= 16) ){$tz = sprintf("%.2f", $p); $GMT_allowed .= "'$tz',";}
$p = ($p - 0.25);
}
$pzone = ($GMT_now + ($p * 3600));
($psec,$pmin,$phour,$pmday,$pmon,$pyear,$pday,$pyday,$pisdst) = localtime($pzone);
$phour=($phour * 100);
$tz = sprintf("%.2f", $p);
$GMT_gmt[$g] = "$tz";
$GMT_day[$g] = "$pday";
$GMT_hour[$g] = ($phour + $pmin);
$p = ($p - 0.25);
if ($DBX) {print "|$GMT_gmt[$g]-$GMT_day[$g]-$GMT_hour[$g]|";}
$g++;
}
if ($local_call_time[$i] =~ /12pm-9pm/)
if ($DBX) {print "\n";}
$stmtA = "SELECT * FROM vicidial_call_times where call_time_id='$local_call_time[$i]';";
if ($DBX) {print " |$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
$p='13';
while ($p > -13)
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$GMT_test = ($GMT_now + ($p * 3600));
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_test);
if ( ($hour >= 12) && ($hour <= 20) ){$tz = sprintf("%.2f", $p); $GMT_allowed .= "'$tz',";}
$p = ($p - 0.25);
}
}
if ($local_call_time[$i] =~ /5pm-9pm/)
{
$p='13';
while ($p > -13)
{
$GMT_test = ($GMT_now + ($p * 3600));
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_test);
if ( ($hour >= 17) && ($hour <= 20) ){$tz = sprintf("%.2f", $p); $GMT_allowed .= "'$tz',";}
$p = ($p - 0.25);
$Gct_default_start = "$record->[3]";
$Gct_default_stop = "$record->[4]";
$Gct_sunday_start = "$record->[5]";
$Gct_sunday_stop = "$record->[6]";
$Gct_monday_start = "$record->[7]";
$Gct_monday_stop = "$record->[8]";
$Gct_tuesday_start = "$record->[9]";
$Gct_tuesday_stop = "$record->[10]";
$Gct_wednesday_start = "$record->[11]";
$Gct_wednesday_stop = "$record->[12]";
$Gct_thursday_start = "$record->[13]";
$Gct_thursday_stop = "$record->[14]";
$Gct_friday_start = "$record->[15]";
$Gct_friday_stop = "$record->[16]";
$Gct_saturday_start = "$record->[17]";
$Gct_saturday_stop = "$record->[18]";
$Gct_state_call_times = "$record->[19]";
}
}
$GMT_allowed .= "'99'";
$ct_states = '';
$ct_state_gmt_SQL = '';
$del_state_gmt_SQL = '';
$ct_srs=0;
$b=0;
if (length($Gct_state_call_times)>2)
{
@state_rules = split(/\|/,$Gct_state_call_times);
$ct_srs = ($#state_rules - 2);
}
while($ct_srs >= $b)
{
if (length($state_rules[$b])>1)
{
$stmtA = "SELECT * from vicidial_state_call_times where state_call_time_id='$state_rules[$b]';";
if ($DBX) {print " |$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
$iter=$dbhA->create_record_iterator;
while ( $record = $iter->each)
{
$Gstate_call_time_id = "$record->[0]";
$Gstate_call_time_state = "$record->[1]";
$Gsct_default_start = "$record->[4]";
$Gsct_default_stop = "$record->[5]";
$Gsct_sunday_start = "$record->[6]";
$Gsct_sunday_stop = "$record->[7]";
$Gsct_monday_start = "$record->[8]";
$Gsct_monday_stop = "$record->[9]";
$Gsct_tuesday_start = "$record->[10]";
$Gsct_tuesday_stop = "$record->[11]";
$Gsct_wednesday_start = "$record->[12]";
$Gsct_wednesday_stop = "$record->[13]";
$Gsct_thursday_start = "$record->[14]";
$Gsct_thursday_stop = "$record->[15]";
$Gsct_friday_start = "$record->[16]";
$Gsct_friday_stop = "$record->[17]";
$Gsct_saturday_start = "$record->[18]";
$Gsct_saturday_stop = "$record->[19]";
$ct_states .="'$Gstate_call_time_state',";
}
}
$r=0;
$state_gmt='';
$del_state_gmt='';
while($r < $g)
{
if ($GMT_day[$r]==0) #### Sunday local time
{
if (($Gsct_sunday_start==0) and ($Gsct_sunday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gsct_sunday_start) and ($GMT_hour[$r]<$Gsct_sunday_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
}
if ($GMT_day[$r]==1) #### Monday local time
{
if (($Gsct_monday_start==0) and ($Gsct_monday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gsct_monday_start) and ($GMT_hour[$r]<$Gsct_monday_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
}
if ($GMT_day[$r]==2) #### Tuesday local time
{
if (($Gsct_tuesday_start==0) and ($Gsct_tuesday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gsct_tuesday_start) and ($GMT_hour[$r]<$Gsct_tuesday_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
}
if ($GMT_day[$r]==3) #### Wednesday local time
{
if (($Gsct_wednesday_start==0) and ($Gsct_wednesday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gsct_wednesday_start) and ($GMT_hour[$r]<$Gsct_wednesday_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
}
if ($GMT_day[$r]==4) #### Thursday local time
{
if (($Gsct_thursday_start==0) and ($Gsct_thursday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gsct_thursday_start) and ($GMT_hour[$r]<$Gsct_thursday_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
}
if ($GMT_day[$r]==5) #### Friday local time
{
if (($Gsct_friday_start==0) and ($Gsct_friday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gsct_friday_start) and ($GMT_hour[$r]<$Gsct_friday_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
}
if ($GMT_day[$r]==6) #### Saturday local time
{
if (($Gsct_saturday_start==0) and ($Gsct_saturday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gsct_saturday_start) and ($GMT_hour[$r]<$Gsct_saturday_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
else
{$del_state_gmt.="'$GMT_gmt[$r]',";}
}
}
$r++;
}
$state_gmt = "$state_gmt'99'";
$del_state_gmt = "$del_state_gmt'99'";
$ct_state_gmt_SQL .= "or (state='$Gstate_call_time_state' and gmt_offset_now IN($state_gmt)) ";
$del_state_gmt_SQL .= "or (state='$Gstate_call_time_state' and gmt_offset_now IN($del_state_gmt)) ";
}
$b++;
}
if (length($ct_states)>2)
{
$ct_states =~ s/,$//gi;
$ct_statesSQL = "and state NOT IN($ct_states)";
}
else
{
$ct_statesSQL = "";
}
$r=0;
$default_gmt='';
$del_default_gmt='';
while($r < $g)
{
if ($GMT_day[$r]==0) #### Sunday local time
{
if (($Gct_sunday_start==0) and ($Gct_sunday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gct_sunday_start) and ($GMT_hour[$r]<$Gct_sunday_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
}
if ($GMT_day[$r]==1) #### Monday local time
{
if (($Gct_monday_start==0) and ($Gct_monday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gct_monday_start) and ($GMT_hour[$r]<$Gct_monday_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
}
if ($GMT_day[$r]==2) #### Tuesday local time
{
if (($Gct_tuesday_start==0) and ($Gct_tuesday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gct_tuesday_start) and ($GMT_hour[$r]<$Gct_tuesday_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
}
if ($GMT_day[$r]==3) #### Wednesday local time
{
if (($Gct_wednesday_start==0) and ($Gct_wednesday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gct_wednesday_start) and ($GMT_hour[$r]<$Gct_wednesday_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
}
if ($GMT_day[$r]==4) #### Thursday local time
{
if (($Gct_thursday_start==0) and ($Gct_thursday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gct_thursday_start) and ($GMT_hour[$r]<$Gct_thursday_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
}
if ($GMT_day[$r]==5) #### Friday local time
{
if (($Gct_friday_start==0) and ($Gct_friday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gct_friday_start) and ($GMT_hour[$r]<$Gct_friday_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
}
if ($GMT_day[$r]==6) #### Saturday local time
{
if (($Gct_saturday_start==0) and ($Gct_saturday_stop==0))
{
if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
else
{
if ( ($GMT_hour[$r]>=$Gct_saturday_start) and ($GMT_hour[$r]<$Gct_saturday_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
else
{$del_default_gmt.="'$GMT_gmt[$r]',";}
}
}
$r++;
}
$default_gmt = "$default_gmt'99'";
$del_default_gmt = "$del_default_gmt'99'";
$all_gmtSQL = "(gmt_offset_now IN($default_gmt) $ct_statesSQL) $ct_state_gmt_SQL";
$del_gmtSQL = "(gmt_offset_now IN($del_default_gmt) $ct_statesSQL) $del_state_gmt_SQL";
##### END calculate what gmt_offset_now values are within the allowed local_call_time setting ###
if ($DB) {print "Starting hopper run for $campaign_id[$i] campaign- GMT: $local_call_time[$1] $GMT_allowed HOPPER: $hopper_level[$i] \n";}
if ($DB) {print "Starting hopper run for $campaign_id[$i] campaign- GMT: $local_call_time[$i] HOPPER: $hopper_level[$i] \n";}
### Delete the DONE leads if there are any
$stmtA = "DELETE from vicidial_hopper where campaign_id='$campaign_id[$i]' and status IN('DONE');";
$stmtA = "DELETE from $vicidial_hopper where campaign_id='$campaign_id[$i]' and status IN('DONE');";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
if ($DB) {print " hopper DONE cleared: $affected_rows\n";}
if ($DBX) {print " |$stmtA|\n";}
### Delete the leads that are out of GMT time range if there are any
$stmtA = "DELETE from vicidial_hopper where campaign_id='$campaign_id[$i]' and gmt_offset_now NOT IN($GMT_allowed);";
$stmtA = "DELETE from $vicidial_hopper where campaign_id='$campaign_id[$i]' and ($del_gmtSQL);";
$dbhA->query("$stmtA");
my $affected_rows = $dbhA->get_affected_rows_length;
if ($DB) {print " hopper GMT BAD cleared: $affected_rows\n";}
@@ -415,7 +787,7 @@ foreach(@campaign_id)
### Find out how many leads are in the hopper from a specific campaign
$hopper_ready_count=0;
$stmtA = "SELECT count(*) from vicidial_hopper where campaign_id='$campaign_id[$i]' and status='READY';";
$stmtA = "SELECT count(*) from $vicidial_hopper where campaign_id='$campaign_id[$i]' and status='READY';";
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
{
@@ -429,7 +801,7 @@ foreach(@campaign_id)
$rec_countA++;
}
}
$event_string = "|$campaign_id[$i]|$hopper_level[$i]|$hopper_ready_count|$local_call_time[$i]|$GMT_allowed|";
$event_string = "|$campaign_id[$i]|$hopper_level[$i]|$hopper_ready_count|$local_call_time[$i]||";
&event_logger;
##### IF hopper level is below set minimum, then try to add more leads #####
@@ -481,7 +853,8 @@ foreach(@campaign_id)
if ($DBX) {print " |$lead_filter_id[$i]|\n";}
}
$stmtA = "SELECT count(*) FROM vicidial_list where called_since_last_reset='N' and status IN('$dial_status_a[$i]','$dial_status_b[$i]','$dial_status_c[$i]','$dial_status_d[$i]','$dial_status_e[$i]') and list_id IN($camp_lists) and gmt_offset_now IN($GMT_allowed) $lead_filter_sql[$i];";
$stmtA = "SELECT count(*) FROM vicidial_list where called_since_last_reset='N' and status IN('$dial_status_a[$i]','$dial_status_b[$i]','$dial_status_c[$i]','$dial_status_d[$i]','$dial_status_e[$i]') and list_id IN($camp_lists) and ($all_gmtSQL) $lead_filter_sql[$i];";
if ($DBX) {print " |$stmtA|\n";}
$dbhA->query("$stmtA");
$campaign_leads_to_call=0;
if ($dbhA->has_selected_record)
@@ -494,9 +867,9 @@ foreach(@campaign_id)
if ($DBX) {print " |$stmtA|\n";}
}
}
if ( ($lead_order[$i] eq "DOWN COUNT 2nd NEW") or ($lead_order[$i] eq "DOWN COUNT 3rd NEW") or ($lead_order[$i] eq "DOWN COUNT 4th NEW") )
if ($lead_order[$i] =~ /DOWN COUNT 2nd NEW|DOWN COUNT 3rd NEW|DOWN COUNT 4th NEW/)
{
$stmtA = "SELECT count(*) FROM vicidial_list where called_since_last_reset='N' and status IN('NEW') and list_id IN($camp_lists) and gmt_offset_now IN($GMT_allowed) $lead_filter_sql[$i];";
$stmtA = "SELECT count(*) FROM vicidial_list where called_since_last_reset='N' and status IN('NEW') and list_id IN($camp_lists) and ($all_gmtSQL) $lead_filter_sql[$i];";
$dbhA->query("$stmtA");
$NEW_campaign_leads_to_call=0;
if ($dbhA->has_selected_record)
@@ -512,7 +885,7 @@ foreach(@campaign_id)
}
##### IF no NEW leads to be called, error out of this campaign #####
if ( ( ($lead_order[$i] eq "DOWN COUNT 2nd NEW") or ($lead_order[$i] eq "DOWN COUNT 3rd NEW") or ($lead_order[$i] eq "DOWN COUNT 4th NEW") ) && ($NEW_campaign_leads_to_call > 0) ) {$GOOD=1;}
if ( ($lead_order[$i] =~ /DOWN COUNT 2nd NEW|DOWN COUNT 3rd NEW|DOWN COUNT 4th NEW/) && ($NEW_campaign_leads_to_call > 0) ) {$GOOD=1;}
else
{
if ($DB) {print " ERROR CANNOT ADD ANY NEW LEADS TO HOPPER\n";}
@@ -522,12 +895,22 @@ foreach(@campaign_id)
if ($campaign_leads_to_call < 1)
{
if ($DB) {print " ERROR CANNOT ADD ANY LEADS TO HOPPER\n";}
if ($VCSdialable_leads > 0)
{
$stmtA = "UPDATE vicidial_campaign_stats SET dialable_leads='0' where campaign_id='$campaign_id[$i]';";
$dbhA->query("$stmtA");
}
}
else
{
if ($VCSdialable_leads != $campaign_leads_to_call)
{
$stmtA = "UPDATE vicidial_campaign_stats SET dialable_leads='$campaign_leads_to_call' where campaign_id='$campaign_id[$i]';";
$dbhA->query("$stmtA");
}
if ($DB) {print " Getting Leads to add to hopper\n";}
### grab leads already in hopper so we don't duplicate
$stmtA = "SELECT lead_id FROM vicidial_hopper where campaign_id='$campaign_id[$i]';";
$stmtA = "SELECT lead_id FROM $vicidial_hopper where campaign_id='$campaign_id[$i]';";
if ($DBX) {print " |$stmtA|\n";}
$dbhA->query("$stmtA");
$rec_countLISTS=0;
@@ -566,7 +949,7 @@ foreach(@campaign_id)
$order_stmt = 'order by called_count, lead_id asc';
if ($DB) {print " looking for $NEW_level NEW leads mixed in with $OTHER_level other leads\n";}
$stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state FROM vicidial_list where called_since_last_reset='N' and status IN('NEW') and list_id IN($camp_lists) and lead_id NOT IN($lead_id_lists) and gmt_offset_now IN($GMT_allowed) $lead_filter_sql[$i] $order_stmt limit $NEW_level;";
$stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state FROM vicidial_list where called_since_last_reset='N' and status IN('NEW') and list_id IN($camp_lists) and lead_id NOT IN($lead_id_lists) and ($all_gmtSQL) $lead_filter_sql[$i] $order_stmt limit $NEW_level;";
if ($DBX) {print " |$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
@@ -582,6 +965,7 @@ foreach(@campaign_id)
$NEW_lists_to_hopper[$NEW_rec_countLEADS] = "$record->[1]";
$NEW_gmt_to_hopper[$NEW_rec_countLEADS] = "$record->[2]";
$NEW_phone_to_hopper[$NEW_rec_countLEADS] = "$record->[3]";
$NEW_state_to_hopper[$NEW_rec_countLEADS] = "$record->[4]";
if ($DB_show_offset) {print "LEAD_ADD: $record->[2] $record->[3] $record->[4]\n";}
$NEW_rec_countLEADS++;
}
@@ -592,7 +976,7 @@ foreach(@campaign_id)
if ($DB) {print " lead call order: $order_stmt\n";}
$stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state FROM vicidial_list where called_since_last_reset='N' and status IN('$dial_status_a[$i]','$dial_status_b[$i]','$dial_status_c[$i]','$dial_status_d[$i]','$dial_status_e[$i]') and list_id IN($camp_lists) and lead_id NOT IN($lead_id_lists) and gmt_offset_now IN($GMT_allowed) $lead_filter_sql[$i] $order_stmt limit $OTHER_level;";
$stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state FROM vicidial_list where called_since_last_reset='N' and status IN('$dial_status_a[$i]','$dial_status_b[$i]','$dial_status_c[$i]','$dial_status_d[$i]','$dial_status_e[$i]') and list_id IN($camp_lists) and lead_id NOT IN($lead_id_lists) and ($all_gmtSQL) $lead_filter_sql[$i] $order_stmt limit $OTHER_level;";
if ($DBX) {print " |$stmtA|\n";}
$dbhA->query("$stmtA");
if ($dbhA->has_selected_record)
@@ -615,6 +999,7 @@ foreach(@campaign_id)
$leads_to_hopper[$rec_countLEADS] = "$NEW_leads_to_hopper[$NEW_in]";
$lists_to_hopper[$rec_countLEADS] = "$NEW_lists_to_hopper[$NEW_in]";
$gmt_to_hopper[$rec_countLEADS] = "$NEW_gmt_to_hopper[$NEW_in]";
$state_to_hopper[$rec_countLEADS] = "$NEW_state_to_hopper[$NEW_in]";
if ($DB_show_offset) {print "LEAD_ADD: $NEW_leads_to_hopper[$NEW_in] $NEW_phone_to_hopper[$NEW_in]\n";}
$rec_countLEADS++;
$NEW_in++;
@@ -624,6 +1009,7 @@ foreach(@campaign_id)
$leads_to_hopper[$rec_countLEADS] = "$record->[0]";
$lists_to_hopper[$rec_countLEADS] = "$record->[1]";
$gmt_to_hopper[$rec_countLEADS] = "$record->[2]";
$state_to_hopper[$rec_countLEADS] = "$record->[4]";
if ($DB_show_offset) {print "LEAD_ADD: $record->[2] $record->[3] $record->[4]\n";}
$rec_countLEADS++;
}
@@ -638,7 +1024,7 @@ foreach(@campaign_id)
{
if ($leads_to_hopper[$h] != '0')
{
$stmtA = "INSERT INTO vicidial_hopper (lead_id,campaign_id,status,user,list_id,gmt_offset_now) values('$leads_to_hopper[$h]','$campaign_id[$i]','READY','','$lists_to_hopper[$h]','$gmt_to_hopper[$h]');";
$stmtA = "INSERT INTO $vicidial_hopper (lead_id,campaign_id,status,user,list_id,gmt_offset_now,state) values('$leads_to_hopper[$h]','$campaign_id[$i]','READY','','$lists_to_hopper[$h]','$gmt_to_hopper[$h]','$state_to_hopper[$h]');";
$dbhA->query("$stmtA");
}
$h++;