Added Dialer Inventory Report, requires a process to be added to the crontab after-hours to gather the statistics

git-svn-id: svn://192.168.202.10@1769 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2012-01-03 03:50:33 +00:00
parent c585869a65
commit 668bc616cf
6 changed files with 2080 additions and 7 deletions
+4
View File
@@ -790,6 +790,10 @@ OTHER CHANGES:
allow for periodic beep in agent session required by some organizations
to make customers aware of a recorded line.
181. Added Dialer Inventory Report, requires a process to be added to the
crontab after-hours to gather the statistics (this example is 7:01am):
1 7 * * * /usr/share/astguiclient/AST_dialer_inventory_snapshot.pl -q --override-24hours
@@ -0,0 +1,766 @@
#!/usr/bin/perl
#
# AST_dialer_inventory_snapshot.pl
#
# Copyright (C) 2011 Joe Johnson <freewermadmin@gmail.com> LICENSE: AGPLv2
# Matt Florell <vicidial@gmail.com>
#
# NOTES:
# - run this script from the crontab in off-hours to generate snapshot reporting
# data for the AST_dialer_inventory_report.php script, here is a recommended
# crontab entry:
# 34 0,7 * * * /usr/share/astguiclient/AST_dialer_inventory_snapshot.pl
#
#
# CHANGES
# 111013-0054 - First build
# 111106-1317 - Added help screen and debug output, reformatting
# 111110-0652 - Added single campaign/list options and call time override option
# 111230-1140 - Debugging additions and more minor changes
#
use DBI;
use POSIX;
#use Tie::IxHash;
$secX = time();
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
if ($hour < 10) {$hour = "0$hour";}
if ($min < 10) {$min = "0$min";}
if ($sec < 10) {$sec = "0$sec";}
if ($mon < 10) {$mon = "0$mon";}
if ($mday < 10) {$mday = "0$mday";}
$snapshot_time="$year-$mon-$mday $hour:$min:$sec";
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
if ( ($line =~ /^PATHDONEmonitor/) && ($CLIDONEmonitor < 1) )
{$PATHDONEmonitor = $line; $PATHDONEmonitor =~ s/.*=//gi;}
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
if ( ($line =~ /^VARFTP_host/) && ($CLIFTP_host < 1) )
{$VARFTP_host = $line; $VARFTP_host =~ s/.*=//gi;}
if ( ($line =~ /^VARFTP_user/) && ($CLIFTP_user < 1) )
{$VARFTP_user = $line; $VARFTP_user =~ s/.*=//gi;}
if ( ($line =~ /^VARFTP_pass/) && ($CLIFTP_pass < 1) )
{$VARFTP_pass = $line; $VARFTP_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARFTP_port/) && ($CLIFTP_port < 1) )
{$VARFTP_port = $line; $VARFTP_port =~ s/.*=//gi;}
if ( ($line =~ /^VARFTP_dir/) && ($CLIFTP_dir < 1) )
{$VARFTP_dir = $line; $VARFTP_dir =~ s/.*=//gi;}
if ( ($line =~ /^VARHTTP_path/) && ($CLIHTTP_path < 1) )
{$VARHTTP_path = $line; $VARHTTP_path =~ s/.*=//gi;}
$i++;
}
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";
print " [--campaign=XXX] = run for only one campaign\n";
print " [--list=XXX] = run for only one list\n";
print " [--override-24hours] = force no local call time check\n";
print " [--debug] = debug\n";
print " [--debugX] = super debug\n";
print " [--help] = this screen\n";
print "\n";
exit;
}
else
{
if ($args =~ /--debug/i)
{
$DB=1;
print "\n----- DEBUG -----\n\n";
}
if ($args =~ /--debugX/i)
{
$DBX=1;
print "\n----- SUPER DEBUG -----\n\n";
}
if ($args =~ /--campaign=/i)
{
# print "\n|$ARGS|\n\n";
@data_in = split(/--campaign=/,$args);
$CLIcampaign = $data_in[1];
$CLIcampaign =~ s/ .*$//gi;
$campaign_SQL=" and campaign_id='$CLIcampaign' ";
if ($DB) {print "\n----- SINGLE CAMPAIGN: $CLIcampaign -----\n\n";}
}
if ($args =~ /--list=/i)
{
# print "\n|$ARGS|\n\n";
@data_in = split(/--list=/,$args);
$CLIlist = $data_in[1];
$CLIlist =~ s/ .*$//gi;
$list_SQL=" and (list_id='$CLIlist') ";
$campaign_SQL=" and campaign_id=(SELECT campaign_id from vicidial_lists where list_id='$CLIlist') ";
if ($DB) {print "\n----- SINGLE LIST: $CLIlist -----\n\n";}
}
if ($args =~ /--override-24hours/i)
{
$override_24hours="yes";
if ($DB) {print "\n----- OVERRIDE 24 HOURS -----\n\n";}
}
}
}
if ($DB > 0) {print "\nAST_dialer_inventory_snapshot.pl - backend statistical gathering process\n";}
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
$dbhB = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
$dbhC = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
$dbhD = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
$dbh = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
$single_status=1;
$time_settings[0]="SERVER";
$time_settings[1]="LOCAL";
$gmt_stmt="SELECT default_local_gmt from system_settings";
$gmt_rslt=$dbhA->prepare($gmt_stmt);
$gmt_rslt->execute();
@gmt_row=$gmt_rslt->fetchrow_array;
$local_offset=$gmt_row[0];
$gmt_stmt="SELECT distinct gmt_offset_now, gmt_offset_now-($local_offset) from vicidial_list";
$gmt_rslt=$dbhA->prepare($gmt_stmt);
$gmt_rslt->execute();
# tie %gmt_ary, "Tie::IxHash";
while (@gmt_row=$gmt_rslt->fetchrow_array)
{
$gmt_row[1]=~s/25$/15/gi;
$gmt_row[1]=~s/75$/45/gi;
$gmt_row[1]=~s/\.5$/30/gi;
$gmt_row[1]=~s/\./:/gi;
$gmt_array{"$gmt_row[0]"}=$gmt_row[1];
}
if ($DB > 0) {print "GMT OFFSET: $local_offset\nLIST TIMEZONES: $i\n";}
# Get shift information
# tie %shift_ary, "Tie::IxHash";
$shift_stmt="SELECT shift_id, shift_name, str_to_date(shift_start_time, '%H%i') as shift_start_time, addtime(str_to_date(shift_start_time, '%H%i'), shift_length) as shift_end_time, if(addtime(str_to_date(shift_start_time, '%H%i'), shift_length)>'23:59:59', '1', '0') as day_offset, shift_weekdays from vicidial_shifts where report_option='Y' order by shift_start_time asc";
$shift_rslt=$dbhA->prepare($shift_stmt);
$shift_rslt->execute();
while(@shift_row=$shift_rslt->fetchrow_array)
{
$shift_ary{$shift_row[0]}[0]=$shift_row[1];
$shift_ary{$shift_row[0]}[1]=$shift_row[2];
$shift_ary{$shift_row[0]}[2]=$shift_row[3];
$shift_ary{$shift_row[0]}[3]=$shift_row[4];
$shift_ary{$shift_row[0]}[4]=$shift_row[5];
}
if ($DB > 0) {print "SHIFT COUNT: $i\n";}
$campaign_stmt="SELECT campaign_id from vicidial_campaigns where campaign_id in (SELECT distinct campaign_id from vicidial_lists) $campaign_SQL order by campaign_id;";
$campaign_rslt=$dbhA->prepare($campaign_stmt);
$campaign_rslt->execute();
while (@group=$campaign_rslt->fetchrow_array)
{
$stmt="SELECT call_count_limit, call_count_target, dial_statuses, local_call_time, drop_lockout_time from vicidial_campaigns where campaign_id='$group[0]'";
if ($DBX > 0) {print " |$stmt|\n";}
$rslt=$dbhB->prepare($stmt);
$rslt->execute();
@campaign_row=$rslt->fetchrow_array;
$call_count_limit=$campaign_row[0];
$call_count_target=$campaign_row[1];
$active_dial_statuses=$campaign_row[2];
$local_call_time=$campaign_row[3];
if ($override_24hours) {$local_call_time="24hours";}
$drop_lockout_time=$campaign_row[4];
$stmt="SELECT distinct status from vicidial_statuses where completed='N' UNION SELECT distinct status from vicidial_campaign_statuses where completed='N' and campaign_id='$group[0]'";
if ($DBX > 0) {print " |$stmt|\n";}
$rslt=$dbhB->prepare($stmt);
$rslt->execute();
$inactive_dial_statuses=" ";
$dial_statuses=" ";
$inventory_statuses=" ";
$inventory_ptnstr="|";
while (@row=$rslt->fetchrow_array)
{
$dial_statuses.="$row[0] ";
$inventory_statuses.="'$row[0]',";
$inventory_ptnstr.="$row[0]|";
if ($active_dial_statuses !~ /\s$row[0]\s/i) {$inactive_dial_statuses.="$row[0] ";}
}
$inventory_statuses=substr($inventory_statuses, 0, -1);
if ($DBX > 0) {print " CAMPAIGN DIAL STATUSES: |$active_dial_statuses|\n";}
if ($DBX > 0) {print " DIAL STATUSES: |$dial_statuses|\n";}
if ($DBX > 0) {print " INVENTORY STATUSES RESULTS: |$inventory_statuses|\n";}
if ($DBX > 0) {print " INACTIVE STATUSES RESULTS: |$inactive_dial_statuses|\n";}
$filter_stmt="SELECT lead_filter_sql from vicidial_campaigns v, vicidial_lead_filters vlf where v.campaign_id='$group[0]' and v.lead_filter_id=vlf.lead_filter_id limit 1";
if ($DBX > 0) {print " |$filter_stmt|\n";}
$filter_rslt=$dbhB->prepare($filter_stmt);
$filter_rslt->execute();
@filter_row=$filter_rslt->fetchrow_array;
$filter_row[0] =~ s/\\//gi;
if (length($filter_row[0])>0) {$filter_SQL=" and $filter_row[0]";} else {$filter_SQL="";}
if ($DB > 0) {print "CAMPAIGN: $group[0] LIMIT: $call_count_limit TARGET: $call_count_target STATUSES: $i\n";}
$lists_stmt="SELECT list_id, list_name, list_description, if(list_lastcalldate is null, '*** Not called *** ', list_lastcalldate) as list_lastcalldate from vicidial_lists where (campaign_id='$group[0]') $list_SQL order by list_id asc";
if ($DBX > 0) {print " |$lists_stmt|\n";}
$lists_rslt=$dbhB->prepare($lists_stmt);
$lists_rslt->execute();
while (@lists_row=$lists_rslt->fetchrow_array)
{
$list_id=$lists_row[0];
$list_name=$lists_row[1];
$list_description=$lists_row[2];
$last_calldate=$lists_row[3];
$list_start_inv=0;
GetListCount($list_id, $inventory_ptnstr);
if ($list_start_inv>0) {$average_calls=sprintf("%.1f", $total_calls/$list_start_inv);} else {$average_calls="0.0";}
$Xdialable_count_nofilter = dialable_leads($local_call_time,$dial_statuses,$list_id,$drop_lockout_time,$call_count_limit,$single_status);
if (length($inactive_dial_statuses)>1)
{
$Xdialable_inactive_count = dialable_leads($local_call_time,$inactive_dial_statuses,$list_id,$drop_lockout_time,$call_count_limit,$single_status,$filter_SQL);
}
else
{
$Xdialable_inactive_count = 0;
}
$oneoff_SQL=$filter_SQL." and (called_count < $call_count_limit-1) ";
$oneoff_count = dialable_leads($local_call_time,$dial_statuses,$list_id,$drop_lockout_time,$call_count_limit,$single_status,$oneoff_SQL);
$full_dialable_SQL="";
$Xdialable_count = dialable_leads($local_call_time,$dial_statuses,$list_id,$drop_lockout_time,$call_count_limit,$single_status,$filter_SQL);
$dialable_total = ($dialable_total + $Xdialable_count);
if ($DB > 0) {print "FULL DIALABLE SQL: |$dial_statuses|\n|$full_dialable_SQL|";}
if ($list_start_inv>0) {$penetration=sprintf("%.2f", (100*($list_start_inv-$Xdialable_count)/$list_start_inv));} else {$penetration="0.00";}
for ($q=0; $q<scalar(@time_settings); $q++)
{
%shift_ary2=%shift_ary;
$shift_data="";
$time_setting=$time_settings[$q];
foreach $val (keys %shift_ary2)
{
$total_shift_count=0;
$gmt_stmt="SELECT distinct gmt_offset_now from vicidial_list where list_id='$list_id'";
if ($DBX > 0) {print " |$gmt_stmt|\n";}
$gmt_rslt=$dbhC->prepare($gmt_stmt);
$gmt_rslt->execute();
while (@gmt_row=$gmt_rslt->fetchrow_array)
{
if ($time_setting=="LOCAL")
{
$offset_hours=$gmt_array{"$gmt_row[0]"};
}
else
{
$offset_hours=0;
}
if (length($shift_ary2{$val}[4])>0)
{
if ($shift_ary2{$val}[3]==0)
{
$shift_days_SQL=" and time(addtime(call_date, '$offset_hours'))>='$shift_ary2{$val}[1]' and time(addtime(call_date, '$offset_hours'))<='$shift_ary2{$val}[2]' ";
$day_str="";
for ($j=0; $j<length($shift_ary2{$val}[4]); $j++)
{
$day=substr($shift_ary2{$val}[4], $j, 1);
$day++;
$day_str.="$day,";
}
$day_str=substr($day_str, 0, -1);
$shift_days_SQL.="and dayofweek(call_date) in ($day_str)";
}
else
{
$shift_days_SQL=" and (";
for ($j=0; $j<length($shift_ary2{$val}[4]); $j++)
{
$day=substr($shift_ary2{$val}[4], $j, 1);
$day++;
$next_day_hours=(substr("0".substr($shift_ary2{$val}[2], 0, 2)%24, -2).substr($shift_ary2{$val}[2], 2));
$next_day=($day%7)+1;
$shift_days_SQL.=" ((time(addtime(call_date, '$offset_hours'))>='$shift_ary2{$val}[1]' and dayofweek(call_date)='$day') or (time(addtime(call_date, '$offset_hours'))<='$next_day_hours' and dayofweek(call_date)='$next_day')) or ";
# call_date, time(call_date), addtime(call_date, '-1:00:00'), time(addtime(call_date, '-1:30')), time(call_date)>=addtime('09:00', '00:04:00')
}
$shift_days_SQL=substr($shift_days_SQL, 0, -3).")";
}
}
else
{
$shift_days_SQL="";
}
$shift_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target'";
if ($DBX > 0) {print " |$shift_stmt|\n";}
$shift_rslt=$dbhD->prepare($shift_stmt);
$shift_rslt->execute();
@shift_row=$shift_rslt->fetchrow_array;
$total_shift_count+=$shift_row[0];
}
$shift_count=$Xdialable_count-$total_shift_count;
$shift_data.="$val,$shift_count|";
}
$shift_data=substr($shift_data,0,-1);
$ins_stmt="insert into dialable_inventory_snapshots(snapshot_time, list_id, list_name, campaign_id, list_lastcalldate, list_start_inv, dialable_count, dialable_count_nofilter, dialable_count_oneoff, dialable_count_inactive, average_call_count, penetration, shift_data, time_setting) values('$snapshot_time', '$list_id', '$list_name', '$group[0]', '$last_calldate', '$list_start_inv', '$Xdialable_count', '$Xdialable_count_nofilter', '$oneoff_count', '$Xdialable_inactive_count', '$average_calls', '$penetration', '$shift_data', '$time_setting')";
if ($DBX > 0) {print " |$ins_stmt|\n";}
$ins_rslt=$dbh->prepare($ins_stmt);
$ins_rslt->execute();
#print "$ins_stmt\n";
}
if ($DB > 0) {print " LIST: $list_id - $list_name START: $list_start_inv DIALABLE: $dialable_total ONEOFF: $oneoff_count\n";}
}
}
$secY = time();
$process_time = ($secY - $secX);
if ($DB > 0) {print "\nDONE, process time: $process_time seconds\n";}
##### subroutines #####
sub GetListCount
{
$list_id=$_[0];
$inventory_ptnstr=$_[1];
$ct_stmt="SELECT status, called_count, count(*) From vicidial_list where list_id='$list_id' group by status, called_count order by status, called_count";
if ($DBX > 0) {print " |$ct_stmt|\n";}
$ct_rslt=$dbh->prepare($ct_stmt);
$ct_rslt->execute();
$new_count=0; $total_calls=0;
while (@ct_row=$ct_rslt->fetchrow_array)
{
$list_start_inv+=$ct_row[2];
$total_calls+=($ct_row[1]*$ct_row[2]);
if ($inventory_ptnstr=~/\|$ct_row[0]\|/ && $ct_row[1]=="0") {$new_count+=$ct_row[2];}
}
}
sub dialable_leads
{
$local_call_time=$_[0];
$working_dial_statuses=$_[1];
$camp_lists=$_[2];
$drop_lockout_time=$_[3];
$call_count_limit=$_[4];
$single_status=$_[5];
$fSQL=$_[6];
if (defined($camp_lists))
{
if (length($camp_lists)>1)
{
if (length($working_dial_statuses)>2)
{
$g=0;
$p='13';
$GMT_gmt[0] = '';
$GMT_hour[0] = '';
$GMT_day[0] = '';
while ($p > -13)
{
$pzone=3600 * $p;
($sec,$min,$hour,$mday,$mon,$year,$pday,$yday,$isdst)=(gmtime()+$pzone);
$pmin=substr("0$min", -2);
$phour=($hour*100);
#$pmin=(gmdate("i", time() + $pzone));
#$phour=( (gmdate("G", time() + $pzone)) * 100);
#$pday=gmdate("w", time() + $pzone);
$tz = sprintf("%.2f", $p);
$GMT_gmt[$g] = "$tz";
$GMT_day[$g] = "$pday";
$GMT_hour[$g] = ($phour + $pmin);
$p = ($p - 0.25);
$g++;
}
$stmt="SELECT call_time_id,call_time_name,call_time_comments,ct_default_start,ct_default_stop,ct_sunday_start,ct_sunday_stop,ct_monday_start,ct_monday_stop,ct_tuesday_start,ct_tuesday_stop,ct_wednesday_start,ct_wednesday_stop,ct_thursday_start,ct_thursday_stop,ct_friday_start,ct_friday_stop,ct_saturday_start,ct_saturday_stop,ct_state_call_times FROM vicidial_call_times where call_time_id='$local_call_time';";
if ($DBX > 0) {print " |$stmt|\n";}
$rslt=$dbh->prepare($stmt);
$rslt->execute();
@rowx=$rslt->fetchrow_array;
$Gct_default_start = $rowx[3];
$Gct_default_stop = $rowx[4];
$Gct_sunday_start = $rowx[5];
$Gct_sunday_stop = $rowx[6];
$Gct_monday_start = $rowx[7];
$Gct_monday_stop = $rowx[8];
$Gct_tuesday_start = $rowx[9];
$Gct_tuesday_stop = $rowx[10];
$Gct_wednesday_start = $rowx[11];
$Gct_wednesday_stop = $rowx[12];
$Gct_thursday_start = $rowx[13];
$Gct_thursday_stop = $rowx[14];
$Gct_friday_start = $rowx[15];
$Gct_friday_stop = $rowx[16];
$Gct_saturday_start = $rowx[17];
$Gct_saturday_stop = $rowx[18];
$Gct_state_call_times = $rowx[19];
$ct_states = '';
$ct_state_gmt_SQL = '';
$ct_srs=0;
$b=0;
if (length($Gct_state_call_times)>2)
{
@state_rules = split(/\|/,$Gct_state_call_times);
$ct_srs = ((scalar(@state_rules)) - 2);
}
while($ct_srs >= $b)
{
if (length($state_rules[$b])>1)
{
$stmt="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 > 0) {print " |$stmt|\n";}
$rslt=$dbh->prepare($stmt);
$rslt->execute();
@row=$rslt->fetchrow_array;
$Gstate_call_time_id = $row[0];
$Gstate_call_time_state = $row[1];
$Gsct_default_start = $row[4];
$Gsct_default_stop = $row[5];
$Gsct_sunday_start = $row[6];
$Gsct_sunday_stop = $row[7];
$Gsct_monday_start = $row[8];
$Gsct_monday_stop = $row[9];
$Gsct_tuesday_start = $row[10];
$Gsct_tuesday_stop = $row[11];
$Gsct_wednesday_start = $row[12];
$Gsct_wednesday_stop = $row[13];
$Gsct_thursday_start = $row[14];
$Gsct_thursday_stop = $row[15];
$Gsct_friday_start = $row[16];
$Gsct_friday_stop = $row[17];
$Gsct_saturday_start = $row[18];
$Gsct_saturday_stop = $row[19];
$ct_states .="'$Gstate_call_time_state',";
$r=0;
$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
{
if ( ($GMT_hour[$r]>=$Gsct_sunday_start) and ($GMT_hour[$r]<$Gsct_sunday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gsct_monday_start) and ($GMT_hour[$r]<$Gsct_monday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gsct_tuesday_start) and ($GMT_hour[$r]<$Gsct_tuesday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gsct_wednesday_start) and ($GMT_hour[$r]<$Gsct_wednesday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gsct_thursday_start) and ($GMT_hour[$r]<$Gsct_thursday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gsct_friday_start) and ($GMT_hour[$r]<$Gsct_friday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gsct_saturday_start) and ($GMT_hour[$r]<$Gsct_saturday_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
}
}
$r++;
}
$state_gmt = "$state_gmt'99'";
$ct_state_gmt_SQL .= "or (state='$Gstate_call_time_state' and gmt_offset_now IN($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='';
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
{
if ( ($GMT_hour[$r]>=$Gct_sunday_start) and ($GMT_hour[$r]<$Gct_sunday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gct_monday_start) and ($GMT_hour[$r]<$Gct_monday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gct_tuesday_start) and ($GMT_hour[$r]<$Gct_tuesday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gct_wednesday_start) and ($GMT_hour[$r]<$Gct_wednesday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gct_thursday_start) and ($GMT_hour[$r]<$Gct_thursday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gct_friday_start) and ($GMT_hour[$r]<$Gct_friday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gct_saturday_start) and ($GMT_hour[$r]<$Gct_saturday_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
}
}
$r++;
}
$default_gmt = "$default_gmt'99'";
$all_gmtSQL = "(gmt_offset_now IN($default_gmt) $ct_statesSQL) $ct_state_gmt_SQL";
$working_dial_statuses=~s/\s\-$//gi;
@Dstatuses = split(/\s/, $working_dial_statuses);
$Ds_to_print = (scalar(@Dstatuses) - 0);
$Dsql = '';
$o=0;
while ($Ds_to_print > $o)
{
$o++;
$Dsql .= "'$Dstatuses[$o]',";
}
$Dsql=~s/\,$//gi;
if (length($Dsql) < 2) {$Dsql = "''";}
$DLTsql='';
if ($drop_lockout_time > 0)
{
$DLseconds = ($drop_lockout_time * 3600);
$DLseconds = floor($DLseconds);
# $DLseconds = intval("$DLseconds");
$DLTsql = "and ( ( (status IN('DROP','XDROP')) and (last_local_call_time < CONCAT(DATE_ADD(NOW(), INTERVAL -$DLseconds SECOND),' ',CURTIME()) ) ) or (status NOT IN('DROP','XDROP')) )";
}
$CCLsql='';
if ($call_count_limit > 0)
{
$CCLsql = "and (called_count < $call_count_limit)";
}
$stmt="SELECT count(*) FROM vicidial_list where status IN($Dsql) and list_id IN($camp_lists) and ($all_gmtSQL) $CCLsql $DLTsql $fSQL";
$full_dialable_SQL="status IN($Dsql) and list_id IN($camp_lists) and ($all_gmtSQL) $CCLsql $DLTsql $fSQL";
if ($DBX > 0) {print "|$stmt|\n";}
$rslt=$dbh->prepare($stmt);
$rslt->execute();
$rslt_rows = $rslt->rows;
if ($rslt_rows)
{
@rowx=$rslt->fetchrow_array;
$active_leads = "$rowx[0]";
}
else {$active_leads = '0';}
if ($single_status > 0)
{return $active_leads;}
else
{$HTML_header.="This campaign has $active_leads leads to be dialed in those lists\n";}
}
else
{
$HTML_header.="no dial statuses selected for this campaign\n";
}
}
else
{
$HTML_header.="no active lists selected for this campaign\n";
}
}
else
{
$HTML_header.="no active lists selected for this campaign\n";
}
##### END calculate what gmt_offset_now values are within the allowed local_call_time setting ###
}
@@ -0,0 +1,833 @@
<?php
# AST_dialer_inventory_report.php
#
# Copyright (C) 2011 Joe Johnson <freewermadmin@gmail.com> LICENSE: AGPLv2
# Matt Florell <vicidial@gmail.com>
#
# NOTES:
# - For snapshots, the AST_dialer_inventory_snapshot.pl script should be put in
# the crontab and run on a nightly basis after-hours
#
#
# CHANGES
# 111013-0054 - First build
# 111106-1327 - Reformatting, other minor changes
# 111230-1145 - Debugging additions and more minor changes
#
error_reporting(0);
require("dbconnect.php");
require("functions.php");
$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER'];
$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW'];
$PHP_SELF=$_SERVER['PHP_SELF'];
if (isset($_GET["group"])) {$group=$_GET["group"];}
elseif (isset($_POST["group"])) {$group=$_POST["group"];}
if (isset($_GET["report_type"])) {$report_type=$_GET["report_type"];}
elseif (isset($_POST["report_type"])) {$report_type=$_POST["report_type"];}
if (isset($_GET["selected_list"])) {$selected_list=$_GET["selected_list"];}
elseif (isset($_POST["selected_list"])) {$selected_list=$_POST["selected_list"];}
if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];}
elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];}
if (isset($_GET["time_setting"])) {$time_setting=$_GET["time_setting"];}
elseif (isset($_POST["time_setting"])) {$time_setting=$_POST["time_setting"];}
if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];}
elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];}
if (isset($_GET["report_source"])) {$report_source=$_GET["report_source"];}
elseif (isset($_POST["report_source"])) {$report_source=$_POST["report_source"];}
if (isset($_GET["DB"])) {$DB=$_GET["DB"];}
elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];}
if (isset($_GET["DBX"])) {$DBX=$_GET["DBX"];}
elseif (isset($_POST["DBX"])) {$DBX=$_POST["DBX"];}
if (isset($_GET["snapshot_time"])) {$snapshot_time=$_GET["snapshot_time"];}
elseif (isset($_POST["snapshot_time"])) {$snapshot_time=$_POST["snapshot_time"];}
if (isset($_GET["override_24hours"])) {$override_24hours=$_GET["override_24hours"];}
elseif (isset($_POST["override_24hours"])) {$override_24hours=$_POST["override_24hours"];}
$MT[0]='';
$NOW_DATE = date("Y-m-d");
$NOW_TIME = date("Y-m-d H:i:s");
$time_start = microtime(true);
$STARTtime = date("U");
if (!isset($group)) {$group = '';}
if (!isset($query_date)) {$query_date = $NOW_DATE;}
if (!isset($end_date)) {$end_date = $NOW_DATE;}
$report_name = 'Dialer Inventory Report';
$db_source = 'M';
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db FROM system_settings;";
$rslt=mysql_query($stmt, $link);
if ($DB) {$HTML_header.="$stmt\n";}
$qm_conf_ct = mysql_num_rows($rslt);
if ($qm_conf_ct > 0)
{
$row=mysql_fetch_row($rslt);
$non_latin = $row[0];
$outbound_autodial_active = $row[1];
$slave_db_server = $row[2];
$reports_use_slave_db = $row[3];
}
##### END SETTINGS LOOKUP #####
###########################################
if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) )
{
mysql_close($link);
$use_slave_server=1;
$db_source = 'S';
require("dbconnect.php");
#$HTML_header.="<!-- Using slave server $slave_db_server $db_source -->\n";
}
$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level > 6 and view_reports='1' and active='Y';";
if ($DB) {$HTML_header.="|$stmt|\n";}
if ($non_latin > 0) { $rslt=mysql_query("SET NAMES 'UTF8'");}
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$auth=$row[0];
$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level='7' and view_reports='1' and active='Y';";
if ($DB) {$HTML_header.="|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$reports_only_user=$row[0];
if( (strlen($PHP_AUTH_USER)<2) or (strlen($PHP_AUTH_PW)<2) or (!$auth))
{
Header("WWW-Authenticate: Basic realm=\"VICI-PROJECTS\"");
Header("HTTP/1.0 401 Unauthorized");
echo "Invalid Username/Password: |$PHP_AUTH_USER|$PHP_AUTH_PW|\n";
exit;
}
$stmt="SELECT user_group from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level > 6 and view_reports='1' and active='Y';";
if ($DB) {$HTML_header.="|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$LOGuser_group = $row[0];
$stmt="SELECT allowed_campaigns,allowed_reports from vicidial_user_groups where user_group='$LOGuser_group';";
if ($DB) {$HTML_header.="|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$LOGallowed_campaigns = $row[0];
$LOGallowed_reports = $row[1];
if ( (!preg_match("/$report_name/",$LOGallowed_reports)) and (!preg_match("/ALL REPORTS/",$LOGallowed_reports)) )
{
Header("WWW-Authenticate: Basic realm=\"VICI-PROJECTS\"");
Header("HTTP/1.0 401 Unauthorized");
echo "You are not allowed to view this report: |$PHP_AUTH_USER|$report_name|\n";
exit;
}
$inventory_allow_realtime = 0;
if (file_exists('options.php'))
{
require('options.php');
}
$LOGallowed_campaignsSQL='';
$whereLOGallowed_campaignsSQL='';
if ( (!eregi("-ALL",$LOGallowed_campaigns)) )
{
$rawLOGallowed_campaignsSQL = preg_replace("/ -/",'',$LOGallowed_campaigns);
$rawLOGallowed_campaignsSQL = preg_replace("/ /","','",$rawLOGallowed_campaignsSQL);
$LOGallowed_campaignsSQL = "and campaign_id IN('$rawLOGallowed_campaignsSQL')";
$whereLOGallowed_campaignsSQL = "where campaign_id IN('$rawLOGallowed_campaignsSQL')";
}
$regexLOGallowed_campaigns = " $LOGallowed_campaigns ";
$i=0;
$group_string='|';
$group_ct = count($group);
while($i < $group_ct)
{
$group_string .= "$group[$i]|";
$i++;
}
$stmt="SELECT campaign_id from vicidial_campaigns where campaign_id in (SELECT distinct campaign_id from vicidial_lists) $LOGallowed_campaignsSQL order by campaign_id;";
$rslt=mysql_query($stmt, $link);
if ($DB) { echo "$stmt\n";}
$campaigns_to_print = mysql_num_rows($rslt);
$i=0;
while ($i < $campaigns_to_print)
{
$row=mysql_fetch_row($rslt);
$groups[$i] =$row[0];
if (ereg("-ALL",$group_string) )
{$group[$i] = $groups[$i];}
$i++;
}
$i=0;
$group_string='|';
$group_ct = count($group);
while($i < $group_ct)
{
if ( (preg_match("/ $group[$i] /",$regexLOGallowed_campaigns)) or (preg_match("/-ALL/",$LOGallowed_campaigns)) )
{
$group_string .= "$group[$i]|";
$group_SQL .= "'$group[$i]',";
$groupQS .= "&group[]=$group[$i]";
}
$i++;
}
if ( (ereg("--ALL--",$group_string) ) or ($group_ct < 1) )
{$group_SQL = "";}
else
{
$group_SQL = eregi_replace(",$",'',$group_SQL);
$group_SQL = "and campaign_id IN($group_SQL)";
}
$stmt="SELECT list_id, list_name from vicidial_lists $whereLOGallowed_campaignsSQL order by list_id, list_name;";
$rslt=mysql_query($stmt, $link);
if ($DB) {$HTML_header.="$stmt\n";}
$lists_to_print = mysql_num_rows($rslt);
$i=0;
while ($i < $lists_to_print)
{
$row=mysql_fetch_row($rslt);
$lists[$i] = $row[0];
$list_names[$i] = $row[1];
$i++;
}
$campaign_span_txt="Campaigns:<BR>";
$campaign_span_txt.="<SELECT SIZE=5 NAME=group[] multiple>";
if (eregi("--ALL--",$group_string))
{$campaign_span_txt.="<option value=\"--ALL--\" selected>-- ALL CAMPAIGNS --</option>";}
else
{$campaign_span_txt.="<option value=\"--ALL--\">-- ALL CAMPAIGNS --</option>";}
$o=0;
while ($campaigns_to_print > $o)
{
if (eregi("$groups[$o]\|",$group_string)) {$campaign_span_txt.="<option selected value=\"$groups[$o]\">$groups[$o]</option>";}
else {$campaign_span_txt.="<option value=\"$groups[$o]\">$groups[$o]</option>";}
$o++;
}
$campaign_span_txt.="</SELECT>";
$list_span_txt="Lists:<BR>";
$list_span_txt.="<SELECT NAME='selected_list'>";
$o=0;
if ($selected_list)
{
$list_span_txt.="<option value=\"$selected_list\" selected>$selected_list</option>";
}
while ($lists_to_print>$o)
{
$list_span_txt.="<option value=\"$lists[$o]\">$lists[$o] - $list_names[$o]</option>";
$o++;
}
$list_span_txt.="</SELECT>";
$snapshot_span_txt="Snapshot time:<BR>";
$snapshot_stmt="SELECT distinct snapshot_time from dialable_inventory_snapshots order by snapshot_time desc limit 100;";
if ($DBX > 0) {$HTML_header.= "|$snapshot_stmt|\n";}
$snapshot_rslt=mysql_query($snapshot_stmt, $link);
$snapshot_span_txt.="<SELECT NAME='snapshot_time'>\n";
if ($snapshot_time) {$snapshot_span_txt.="\t<option value=\"$snapshot_time\" selected>$snapshot_time</option>\n";}
while ($ss_row=mysql_fetch_row($snapshot_rslt))
{
$snapshot_span_txt.="\t<option value=\"$ss_row[0]\">$ss_row[0]</option>\n";
}
$snapshot_span_txt.="</SELECT>\n";
$HTML_header.="<HTML>\n";
$HTML_header.="<HEAD>\n";
$HTML_header.="<STYLE type='text/css'>\n";
$HTML_header.="<!--\n";
$HTML_header.=" .green {color: white; background-color: green}\n";
$HTML_header.=" .red {color: white; background-color: red}\n";
$HTML_header.=" .blue {color: white; background-color: blue}\n";
$HTML_header.=" .purple {color: white; background-color: purple}\n";
$HTML_header.="-->\n";
$HTML_header.=" </STYLE>\n";
if ($report_type=='LIST') {$onload="onload=\"ToggleSpan('list_span', 'campaign_span')\"";}
$HTML_header.="<script language='Javascript'>\n";
$HTML_header.="function ToggleSpan(show_span, hide_span) {\n";
$HTML_header.="\n";
$HTML_header.=" if (show_span) {document.getElementById(show_span).style.display = 'block';}\n";
$HTML_header.=" if (hide_span) {document.getElementById(hide_span).style.display = 'none';}\n";
$HTML_header.="}\n";
$HTML_header.="</script>\n";
$HTML_header.="\n";
$HTML_header.="<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>\n";
$HTML_header.="<TITLE>$report_name</TITLE></HEAD><BODY $onload BGCOLOR=WHITE marginheight=0 marginwidth=0 leftmargin=0 topmargin=0>\n";
$HTML_header.="<PRE>\n";
$rpt_header="";
####### STAT GENERATION #######
require("count_functions.inc");
function GetListCount($list_id, $inventory_ptnstr)
{
global $list_start_inv;
global $new_count;
global $link;
global $total_calls;
$ct_stmt="SELECT status, called_count, count(*) From vicidial_list where list_id='$list_id' group by status, called_count order by status, called_count;";
if ($DBX > 0) {$HTML_header.= "|$ct_stmt|\n";}
$ct_rslt=mysql_query($ct_stmt, $link);
$new_count=0; $total_calls=0;
while ($ct_row=mysql_fetch_row($ct_rslt))
{
$list_start_inv+=$ct_row[2];
$total_calls+=($ct_row[1]*$ct_row[2]);
if (preg_match('/|$ct_row[0]|/', $inventory_ptnstr) && $ct_row[1]=="0") {$new_count+=$ct_row[2];}
}
}
if ($SUBMIT)
{
if ($snapshot_time && $report_source=="SNAPSHOT")
{
$rpt_header="SNAPSHOT from $snapshot_time\n";
$stmt="SELECT distinct shift_data from dialable_inventory_snapshots where snapshot_time='$snapshot_time' and time_setting='$time_setting' $time_clause order by campaign_id, list_id;";
if ($DBX > 0) {$HTML_header.= "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
$shift_SQL_str="";
while ($shift_row=mysql_fetch_array($rslt))
{
$shift_data1=explode("|", $shift_row["shift_data"]);
for ($i=0; $i<count($shift_data1); $i++)
{
$shift_data2=explode(",", $shift_data1);
$shift_SQL_str.="'$shift_data2[0]',";
}
}
$shift_SQL_str=substr($shift_SQL_str, 0, -1);
$shift_stmt="SELECT shift_id from vicidial_shifts where report_option='Y' order by shift_start_time asc;";
if ($DBX > 0) {$HTML_header.= "|$shift_stmt|\n";}
$shift_rslt=mysql_query($shift_stmt, $link);
$c=0;
while($shift_row=mysql_fetch_array($shift_rslt))
{
$rpt_header_SHIFTS.=" ".sprintf("%8s", substr($shift_row["shift_id"],0,8))." |";
$CSV_header_SHIFTS.="\"$shift_row[shift_id]\",";
$rpt_header_SHIFTS_lower.=" |";
$rpt_header_BORDER.="----------+";
$shift_ary[$c]=$shift_row["shift_id"];
if ($DB > 0) {echo "<BR>-$c-$shift_ary[$c]-$shift_row[shift_id]-\n";}
$c++;
}
if ($report_type=="CAMPAIGNS") {$time_clause=$group_SQL;}
if ($report_type=="LIST") {$time_clause="and list_id='$selected_list'";}
$stmt="SELECT snapshot_id,snapshot_time,list_id,list_name,campaign_id,list_lastcalldate,list_start_inv,dialable_count,dialable_count_nofilter,dialable_count_oneoff,dialable_count_inactive,average_call_count,penetration,shift_data,time_setting from dialable_inventory_snapshots where snapshot_time='$snapshot_time' and time_setting='$time_setting' $time_clause order by campaign_id, list_id;";
if ($DBX > 0) {$HTML_header.= "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
while ($row=mysql_fetch_array($rslt))
{
$rpt_body.="| ".sprintf("%9s", $row["list_id"])." | ".sprintf("%-30s", $row["list_name"])." | ".sprintf("%8s", $row["campaign_id"])." | ".$row["list_lastcalldate"]." | ".sprintf("%9s", $row["list_start_inv"])." | ".sprintf("%8s", $row["dialable_count"])." | ".sprintf("%8s", $row["dialable_count_nofilter"])." | ".sprintf("%8s", $row["dialable_count_oneoff"])." | ".sprintf("%8s", $row["dialable_count_inactive"])." | ".sprintf("%8s", $row["average_call_count"])." | ".sprintf("%6s", $row["penetration"])."% |";
$CSV_body.="\"$row[list_id]\",\"$row[list_name]\",\"$row[last_calldate]\",\"$row[campaign_id]\",\"$row[list_start_inv]\",\"$row[dialable_count]\",\"$row[dialable_count_nofilter]\",\"$row[dialable_count_oneoff]\",\"$row[dialable_count_inactive]\",\"$row[average_call_count]\",\"$row[penetration] %\"";
$shift_data_a=explode("|", $row["shift_data"]);
$b=0;
while ($b < count($shift_ary))
{
$a=0;
while ($a < count($shift_data_a))
{
$shift_data_b=explode(",", $shift_data_a[$a]);
$line_match=0;
if ($shift_ary[$b] == "$shift_data_b[0]")
{
$rpt_body.=" ".sprintf("%8s", $shift_data_b[1])." |";
$CSV_body.=",\"$shift_data_b[1]\"";
$line_match++;
}
if ($DB > 0) {echo "<BR>-$a-$b-$shift_ary[$b]-$shift_data_b[0]($shift_data_b[1])-$line_match-\n";}
$a++;
}
$b++;
}
$rpt_body.="\n";
$CSV_body.="\n";
}
}
else
{
$single_status=1;
## If time setting is set to 'Local', compile a list of time zone offsets and make an array of those offsets with the amount of time that needs to be added or subtracted
if ($time_setting=="LOCAL")
{
$gmt_stmt="SELECT default_local_gmt from system_settings;";
$gmt_rslt=mysql_query($gmt_stmt, $link);
$gmt_row=mysql_fetch_row($gmt_rslt);
$local_offset=$gmt_row[0];
if ($report_type=="CAMPAIGNS") {$time_clause="where list_id in (SELECT list_id from vicidial_lists where ".substr($group_SQL,4).")";}
if ($report_type=="LIST") {$time_clause="where list_id='$selected_list'";}
$gmt_stmt="SELECT distinct gmt_offset_now, gmt_offset_now-($local_offset) from vicidial_list $time_clause ;";
if ($DB) {$HTML_header.=$gmt_stmt."<BR>\n";}
$gmt_rslt=mysql_query($gmt_stmt, $link);
while ($gmt_row=mysql_fetch_row($gmt_rslt))
{
$gmt_row[1]=preg_replace('/25$/', '15', $gmt_row[1]);
$gmt_row[1]=preg_replace('/75$/', '45', $gmt_row[1]);
$gmt_row[1]=preg_replace('/\.5$/', '.30', $gmt_row[1]);
$gmt_row[1]=preg_replace('/\./', ':', $gmt_row[1]);
$gri = $gmt_row[0];
$gmt_array[$gri]=$gmt_row[1];
}
}
# Get shift information
$shift_stmt="SELECT shift_id, shift_name, str_to_date(shift_start_time, '%H%i') as shift_start_time, addtime(str_to_date(shift_start_time, '%H%i'), shift_length) as shift_end_time, if(addtime(str_to_date(shift_start_time, '%H%i'), shift_length)>'23:59:59', '1', '0') as day_offset, shift_weekdays from vicidial_shifts where report_option='Y' order by shift_start_time asc;";
if ($DB) {$HTML_header.="$shift_stmt;\n";}
$shift_rslt=mysql_query($shift_stmt, $link);
while($shift_row=mysql_fetch_array($shift_rslt))
{
$rpt_header_SHIFTS.=" ".sprintf("%8s", substr($shift_row["shift_id"],0,8))." |";
$rpt_header_SHIFTS_lower.=" |";
$CSV_header_SHIFTS.="\"$shift_row[shift_id]\",";
$rpt_header_BORDER.="----------+";
$shift_ary[$shift_row["shift_id"]][0]=$shift_row["shift_name"];
$shift_ary[$shift_row["shift_id"]][1]=$shift_row["shift_start_time"];
$shift_ary[$shift_row["shift_id"]][2]=$shift_row["shift_end_time"];
$shift_ary[$shift_row["shift_id"]][3]=$shift_row["day_offset"];
$shift_ary[$shift_row["shift_id"]][4]=$shift_row["shift_weekdays"];
}
$rpt_body="";
if ($group_ct>0 && $report_type=="CAMPAIGNS")
{
for ($i=0; $i<$group_ct; $i++)
{
$campaign_stmt="SELECT call_count_limit, call_count_target, dial_statuses, local_call_time, drop_lockout_time from vicidial_campaigns where campaign_id='$group[$i]' $LOGallowed_campaignsSQL;";
if ($DB) {$HTML_header.="$campaign_stmt;\n";}
$campaign_rslt=mysql_query($campaign_stmt, $link);
$campaign_row=mysql_fetch_row($campaign_rslt);
$call_count_limit=$campaign_row[0];
$call_count_target=$campaign_row[1];
$active_dial_statuses=$campaign_row[2];
$local_call_time=$campaign_row[3]; if ($override_24hours) {$local_call_time="24hours";}
$drop_lockout_time=$campaign_row[4];
$stmt="SELECT distinct status from vicidial_statuses where completed='N' UNION SELECT distinct status from vicidial_campaign_statuses where completed='N' and campaign_id='$group[$i]' $LOGallowed_campaignsSQL";
if ($DB) {$HTML_header.="$stmt\n";}
$rslt=mysql_query($stmt, $link);
$dial_statuses=" ";
$inventory_statuses=" ";
$inventory_ptnstr="|";
$inactive_dial_statuses=" ";
while ($row=mysql_fetch_row($rslt))
{
$dial_statuses.="$row[0] ";
$inventory_statuses.="'$row[0]',";
$inventory_ptnstr.="$row[0]|";
if (!preg_match("/ $row[0] /", "$active_dial_statuses")) {$inactive_dial_statuses.="$row[0] ";}
}
$inventory_statuses=substr($inventory_statuses, 0, -1);
if ($DB) {$HTML_header.= " CAMPAIGN DIAL STATUSES: |$active_dial_statuses|\n";}
if ($DB) {$HTML_header.= " INVENTORY STATUSES RESULTS: |$inventory_statuses|\n";}
if ($DB) {$HTML_header.= " INACTIVE STATUSES RESULTS: |$inactive_dial_statuses|\n";}
$filter_stmt="SELECT lead_filter_sql from vicidial_campaigns v, vicidial_lead_filters vlf where v.campaign_id='$group[$i]' and v.lead_filter_id=vlf.lead_filter_id limit 1;";
if ($DB) {$HTML_header.="$filter_stmt;\n";}
$filter_rslt=mysql_query($filter_stmt, $link);
$filter_row=mysql_fetch_row($filter_rslt);
if (strlen($filter_row[0])>0) {$filter_SQL=" and $filter_row[0]";} else {$filter_SQL="";}
$filter_SQL = preg_replace("/\\\/",'',$filter_SQL);
$lists_stmt="SELECT list_id, list_name, list_description, if(list_lastcalldate is null, '*** Not called *** ', list_lastcalldate) as list_lastcalldate from vicidial_lists where campaign_id='$group[$i]' $LOGallowed_campaignsSQL order by list_id asc;";
if ($DB) {$HTML_header.="$lists_stmt;\n";}
$lists_rslt=mysql_query($lists_stmt, $link);
while ($lists_row=mysql_fetch_array($lists_rslt))
{
$list_id=$lists_row["list_id"];
$list_name=$lists_row["list_name"];
$list_description=$lists_row["list_description"];
$last_calldate=$lists_row["list_lastcalldate"];
$list_start_inv=0;
GetListCount($list_id, $inventory_ptnstr);
if ($list_start_inv>0) {$average_calls=sprintf("%.1f", $total_calls/$list_start_inv);} else {$average_calls="0.0";}
$Xdialable_count_nofilter = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$list_id,$drop_lockout_time,$call_count_limit,$single_status,"");
if (strlen($inactive_dial_statuses)>1)
{
$Xdialable_inactive_count = dialable_leads($DB,$link,$local_call_time,"$inactive_dial_statuses",$list_id,$drop_lockout_time,$call_count_limit,$single_status,"$filter_SQL");
}
else
{
$Xdialable_inactive_count = 0;
}
$oneoff_SQL=$filter_SQL." and (called_count < $call_count_limit-1) ";
$oneoff_count = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$list_id,$drop_lockout_time,$call_count_limit,$single_status,"$oneoff_SQL");
$full_dialable_SQL="";
$Xdialable_count = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$list_id,$drop_lockout_time,$call_count_limit,$single_status,"$filter_SQL");
if ($list_start_inv>0) {$penetration=sprintf("%.2f", (100*($list_start_inv-$Xdialable_count)/$list_start_inv));} else {$penetration="0.00";}
$rpt_body.="| ".sprintf("%9s", $list_id)." | ".sprintf("%-30s", $list_name)." | ".sprintf("%8s", $group[$i])." | ".$last_calldate." | ".sprintf("%9s", $list_start_inv)." | ".sprintf("%8s", $Xdialable_count)." | ".sprintf("%8s", $Xdialable_count_nofilter)." | ".sprintf("%8s", $oneoff_count)." | ".sprintf("%8s", $Xdialable_inactive_count)." | ".sprintf("%8s", $average_calls)." | ".sprintf("%6s", $penetration)."% |";
$CSV_body.="\"$list_id\",\"$list_name\",\"$last_calldate\",\"$group[$i]\",\"$list_start_inv\",\"$Xdialable_count\",\"$Xdialable_count_nofilter\",\"$oneoff_count\",\"$Xdialable_inactive_count\",\"$average_calls\",\"$penetration %\"";
# $stat_stmt="SELECT call_date, dayofweek(call_date) from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where list_id='$list_id' and called_count<='$called_count_limit' and status in ($inventory_statuses) $filter_SQL";
# SELECT lead_id, count(*) as count from vicidial_log where extract(HOUR_MINUTE FROM call_date)>='900' and extract(HOUR_MINUTE FROM call_date)<='1700' and dayofweek(call_date) in (2,3,4,5,6) and lead_id in (SELECT lead_id from vicidial_list where list_id=41073) group by lead_id order by lead_id;
$shift_ary2=$shift_ary;
while (list($key, $val)=each($shift_ary2))
{
$total_shift_count=0;
$gmt_stmt="SELECT distinct gmt_offset_now from vicidial_list where list_id='$list_id';";
if ($DB) {$HTML_header.="<B>$gmt_stmt</B>\n";}
$gmt_rslt=mysql_query($gmt_stmt, $link);
while ($gmt_row=mysql_fetch_row($gmt_rslt))
{
if ($time_setting=="LOCAL")
{
$gri = $gmt_row[0];
$offset_hours=$gmt_array[$gri];
}
else
{
$offset_hours=0;
}
if (strlen($val[4])>0)
{
if ($val[3]==0)
{
$shift_days_SQL=" and time(addtime(call_date, '$offset_hours'))>='$val[1]' and time(addtime(call_date, '$offset_hours'))<='$val[2]' ";
$day_str="";
for ($j=0; $j<strlen($val[4]); $j++)
{
$day=substr($val[4], $j, 1);
$day++;
$day_str.="$day,";
}
$day_str=substr($day_str, 0, -1);
$shift_days_SQL.="and dayofweek(call_date) in ($day_str)";
}
else
{
$shift_days_SQL=" and (";
for ($j=0; $j<strlen($val[4]); $j++)
{
$day=substr($val[4], $j, 1);
$day++;
$next_day_hours=(substr("0".substr($val[2], 0, 2)%24, -2).substr($val[2], 2));
$next_day=($day%7)+1;
$shift_days_SQL.=" ((time(addtime(call_date, '$offset_hours'))>='$val[1]' and dayofweek(call_date)='$day') or (time(addtime(call_date, '$offset_hours'))<='$next_day_hours' and dayofweek(call_date)='$next_day')) or ";
# call_date, time(call_date), addtime(call_date, '-1:00:00'), time(addtime(call_date, '-1:30')), time(call_date)>=addtime('09:00', '00:04:00')
}
$shift_days_SQL=substr($shift_days_SQL, 0, -3).")";
}
}
else
{
$shift_days_SQL="";
}
$shift_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target';";
$shift_rslt=mysql_query($shift_stmt, $link);
$shift_row=mysql_fetch_row($shift_rslt);
if ($DB) {$HTML_header.="<B>$shift_stmt<BR>$shift_row[0]</B>\n";}
$total_shift_count+=$shift_row[0];
}
$shift_count=$Xdialable_count-$total_shift_count;
$rpt_body.=" ".sprintf("%8s", $shift_count)." |";
$CSV_body.=",\"$shift_count\"";
}
$rpt_body.="\n";
$CSV_body.="\n";
if (!$file_download) {echo $HTML_header; $HTML_header=""; flush();}
}
}
}
else if ($selected_list && $report_type=="LIST")
{
$campaign_stmt="SELECT call_count_limit, call_count_target, dial_statuses, local_call_time, drop_lockout_time, v.campaign_id from vicidial_campaigns v, vicidial_lists vl where vl.list_id='$selected_list' and vl.campaign_id=v.campaign_id;";
if ($DB) {$HTML_header.="$campaign_stmt;\n";}
$campaign_rslt=mysql_query($campaign_stmt, $link);
$campaign_row=mysql_fetch_row($campaign_rslt);
$call_count_limit=$campaign_row[0];
$call_count_target=$campaign_row[1];
$active_dial_statuses=$campaign_row[2];
$local_call_time=$campaign_row[3]; if ($override_24hours) {$local_call_time="24hours";}
$drop_lockout_time=$campaign_row[4];
$campaign_id=$campaign_row[5];
$stmt="SELECT distinct status from vicidial_statuses where completed='N' UNION SELECT distinct status from vicidial_campaign_statuses where completed='N' and campaign_id=(SELECT campaign_id from vicidial_lists where list_id='$selected_list' $LOGallowed_campaignsSQL);";
if ($DB) {$HTML_header.="$stmt\n";}
$rslt=mysql_query($stmt, $link);
$inactive_dial_statuses=" ";
$dial_statuses=" ";
$inventory_statuses="";
$inventory_ptnstr="|";
while ($row=mysql_fetch_row($rslt))
{
$dial_statuses.="$row[0] ";
$inventory_statuses.="'$row[0]',";
$inventory_ptnstr.="$row[0]|";
if (!preg_match("/ $row[0] /", "$active_dial_statuses")) {$inactive_dial_statuses.="$row[0] ";}
}
$inventory_statuses=substr($inventory_statuses, 0, -1);
if ($DB) {$HTML_header.= " CAMPAIGN DIAL STATUSES: |$active_dial_statuses|\n";}
if ($DB) {$HTML_header.= " DIAL STATUSES: |$dial_statuses|\n";}
if ($DB) {$HTML_header.= " INVENTORY STATUSES RESULTS: |$inventory_statuses|\n";}
if ($DB) {$HTML_header.= " INACTIVE STATUSES RESULTS: |$inactive_dial_statuses|\n";}
if ($DB) {$HTML_header.="<B>$campaign_stmt; - $dial_statuses</B>\n";}
$filter_stmt="SELECT lead_filter_sql from vicidial_campaigns v, vicidial_lead_filters vlf where v.campaign_id='$campaign_id' and v.lead_filter_id=vlf.lead_filter_id limit 1;";
if ($DB) {$HTML_header.="$filter_stmt;\n";}
$filter_rslt=mysql_query($filter_stmt, $link);
$filter_row=mysql_fetch_row($filter_rslt);
if (strlen($filter_row[0])>0) {$filter_SQL=" and $filter_row[0]";} else {$filter_SQL="";}
$filter_SQL = preg_replace("/\\\/",'',$filter_SQL);
$lists_stmt="SELECT list_id, list_name, list_description, if(list_lastcalldate is null, '*** Not called *** ', list_lastcalldate) as list_lastcalldate, campaign_id from vicidial_lists where list_id='$selected_list' $LOGallowed_campaignsSQL order by list_id asc;";
if ($DB) {$HTML_header.="$lists_stmt;\n";}
$lists_rslt=mysql_query($lists_stmt, $link);
while ($lists_row=mysql_fetch_array($lists_rslt))
{
$list_id=$lists_row["list_id"];
$list_name=$lists_row["list_name"];
$list_description=$lists_row["list_description"];
$last_calldate=$lists_row["list_lastcalldate"];
$campaign_id=$lists_row["campaign_id"];
$list_call_inv=0;
GetListCount($list_id, $inventory_ptnstr);
if ($list_start_inv>0) {$average_calls=sprintf("%.1f", $total_calls/$list_start_inv);} else {$average_calls="0.0";}
$Xdialable_count_nofilter = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$selected_list,$drop_lockout_time,$call_count_limit,$single_status,"");
if (strlen($inactive_dial_statuses)>1)
{
$Xdialable_inactive_count = dialable_leads($DB,$link,$local_call_time,"$inactive_dial_statuses",$selected_list,$drop_lockout_time,$call_count_limit,$single_status,"$filter_SQL");
}
else
{
$Xdialable_inactive_count = 0;
}
$oneoff_SQL=$filter_SQL." and (called_count < $call_count_limit-1) ";
$oneoff_count = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$selected_list,$drop_lockout_time,$call_count_limit,$single_status,"$oneoff_SQL");
$full_dialable_SQL="";
$Xdialable_count = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$selected_list,$drop_lockout_time,$call_count_limit,$single_status,"$filter_SQL");
if ($DB > 0) {echo "FULL DIALABLE SQL: |$full_dialable_SQL|";}
}
if ($list_start_inv>0) {$penetration=sprintf("%.2f", (100*($list_start_inv-$Xdialable_count)/$list_start_inv));} else {$penetration="0.00";}
$rpt_body.="| ".sprintf("%9s", $list_id)." | ".sprintf("%-30s", $list_name)." | ".sprintf("%8s", $campaign_id)." | ".$last_calldate." | ".sprintf("%9s", $list_start_inv)." | ".sprintf("%8s", $Xdialable_count)." | ".sprintf("%8s", $Xdialable_count_nofilter)." | ".sprintf("%8s", $oneoff_count)." | ".sprintf("%8s", $Xdialable_inactive_count)." | ".sprintf("%8s", $average_calls)." | ".sprintf("%6s", $penetration)."% |";
$CSV_body.="\"$list_id\",\"$list_name\",\"$last_calldate\",\"$campaign_id\",\"$list_start_inv\",\"$Xdialable_count\",\"$Xdialable_count_nofilter\",\"$oneoff_count\",\"$Xdialable_inactive_count\",\"$average_calls\",\"$penetration %\"";
$shift_ary2=$shift_ary;
while (list($key, $val)=each($shift_ary2))
{
$total_shift_count=0;
$total_nofilter_shift_count=0;
$total_oneoff_shift_count=0;
$total_undialable_shift_count=0;
$total_nofilter_undialable_shift_count=0;
$gmt_stmt="SELECT distinct gmt_offset_now from vicidial_list where list_id='$list_id';";
if ($DB) {$HTML_header.="$gmt_stmt\n";}
$gmt_rslt=mysql_query($gmt_stmt, $link);
while ($gmt_row=mysql_fetch_row($gmt_rslt))
{
if ($time_setting=="LOCAL")
{
$gri = $gmt_row[0];
$offset_hours=$gmt_array[$gri];
}
else
{
$offset_hours=0;
}
if (strlen($val[4])>0)
{
if ($val[3]==0)
{
$shift_days_SQL=" and time(addtime(call_date, '$offset_hours'))>='$val[1]' and time(addtime(call_date, '$offset_hours'))<='$val[2]' ";
$day_str="";
for ($i=0; $i<strlen($val[4]); $i++)
{
$day=substr($val[4], $i, 1);
$day++;
$day_str.="$day,";
}
$day_str=substr($day_str, 0, -1);
$shift_days_SQL.="and dayofweek(call_date) in ($day_str)";
}
else
{
$shift_days_SQL=" and (";
for ($i=0; $i<strlen($val[4]); $i++)
{
$day=substr($val[4], $i, 1);
$day++;
$next_day_hours=(substr("0".substr($val[2], 0, 2)%24, -2).substr($val[2], 2));
$next_day=($day%7)+1;
$shift_days_SQL.=" ((time(addtime(call_date, '$offset_hours'))>='$val[1]' and dayofweek(call_date)='$day') or (time(addtime(call_date, '$offset_hours'))<='$next_day_hours' and dayofweek(call_date)='$next_day')) or ";
# call_date, time(call_date), addtime(call_date, '-1:00:00'), time(addtime(call_date, '-1:30')), time(call_date)>=addtime('09:00', '00:04:00')
}
$shift_days_SQL=substr($shift_days_SQL, 0, -3).")";
}
}
else
{
$shift_days_SQL="";
}
# $dialable_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target'";
# $dialable_nofilter_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]') $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target'";
# $undialable_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target'";
# $undialable_nofilter_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]') $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target'";
# $oneoff_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='($call_count_target-1)'";
$shift_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target';";
$shift_rslt=mysql_query($shift_stmt, $link);
$shift_row=mysql_fetch_row($shift_rslt);
if ($DB) {$HTML_header.="<B>$shift_stmt;<BR>$shift_row[0]</B>\n";}
$total_shift_count+=$shift_row[0];
}
$shift_count=$Xdialable_count-$total_shift_count;
$rpt_body.=" ".sprintf("%8s", $shift_count)." |";
$CSV_body.=",\"$shift_count\"";
}
$rpt_body.="\n";
$CSV_body.="\n";
if (!$file_download) {echo $HTML_header; $HTML_header=""; flush();}
}
}
$rpt_header.="Date: ".date("m/d/Y")." -- Time: ".date("H:i a")."\n\n";
$rpt_header.="+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+$rpt_header_BORDER\n";
$rpt_header.="| Call list | List description | Campaign | Last call date | Start Inv | Call Inv | Call Inv | Call Inv | Call Inv | Dial Avg | Pen. % |$rpt_header_SHIFTS\n";
$rpt_header.="| | | | | | Total | No filtr | One-off | Inactive | | |$rpt_header_SHIFTS_lower\n";
$rpt_header.="+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+$rpt_header_BORDER\n";
$CSV_header="\"$report_name\"\n";
$CSV_header.="\"Date: ".date("m/d/Y")."\",\"\",\"Time: ".date("H:i a")."\"\n\n";
$CSV_header.="\"Call list\",\"List description\",\"Campaign\",\"Last call date\",\"Start Inv\",\"Call Inv Total\",\"Call Inv - No filter\",\"Call Inv - One-offs\",\"Call Inv - Inactive dialable statuses\",\"Dial Avg\",\"Pen. %\",".substr($CSV_header_SHIFTS,0,-1)."\n";
$rpt_footer="+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+$rpt_header_BORDER\n";
}
$HTML_header.="</PRE>\n";
###############################
$HTML_text="<TABLE CELLPADDING=4 CELLSPACING=0><TR><TD>\n";
$HTML_text.="\n";
$HTML_text.="<FORM ACTION='$PHP_SELF' METHOD=GET name=vicidial_report id=vicidial_report>\n";
$HTML_text.="<INPUT TYPE=hidden NAME=DB VALUE='$DB'>\n";
$HTML_text.="<TABLE CELLSPACING=3><TR height='200'><TD VALIGN=TOP>\n";
$HTML_text.=" <table width='*' align='center'>\n";
$HTML_text.=" <tr><td>Report type:</td></tr>\n";
if ($report_type=='LIST') {$cmp_checked=""; $list_checked="checked";} else {$cmp_checked="checked"; $list_checked="";}
$HTML_text.=" <tr><td><input type='radio' name='report_type' value='CAMPAIGNS' onClick=\"ToggleSpan('campaign_span', 'list_span')\" $cmp_checked>Campaigns</td></tr>\n";
$HTML_text.=" <tr><td><input type='radio' name='report_type' value='LIST' onClick=\"ToggleSpan('list_span', 'campaign_span')\" $list_checked>List</td></tr>\n";
$HTML_text.=" </table>\n";
$HTML_text.="</TD>\n";
$HTML_text.="<td width='30'>&nbsp;</td>\n";
$HTML_text.="<TD VALIGN=TOP width=250>\n";
$HTML_text.="<span id='campaign_span' style='display:block;'>$campaign_span_txt</span>\n";
$HTML_text.="<span id='list_span' style='display:none;'>$list_span_txt</span>\n";
$HTML_text.="</TD>\n";
$HTML_text.="<TD VALIGN=TOP>\n";
$HTML_text.=" <table width='*' align='center'>\n";
$HTML_text.=" <tr><td>Time setting:</td></tr>\n";
if ($time_setting=='LOCAL') {$svr_checked=""; $local_checked="checked";} else {$svr_checked="checked"; $local_checked="";}
if ($override_24hours) {$override_checked="checked";}
$HTML_text.=" <tr><td><input type='radio' name='time_setting' value='SERVER' $svr_checked>Server</td></tr>\n";
$HTML_text.=" <tr><td><input type='radio' name='time_setting' value='LOCAL' $local_checked>Local</td></tr>\n";
$HTML_text.=" <tr><td><input type='checkbox' name='override_24hours' value='OVERRIDE' $override_checked>Ignore local campaign call time<BR>(default to 24 hours)</td></tr>\n";
$HTML_text.=" </table>\n";
$HTML_text.="</TD>\n";
$HTML_text.="<TD VALIGN=TOP width='150'>\n";
$HTML_text.=" <table width='*' align='center'>\n";
$HTML_text.=" <tr><td>Report source:</td></tr>\n";
if ($report_source=='REALTIME') {$ss_checked=""; $rt_checked="checked";} else {$ss_checked="checked"; $rt_checked="";}
$HTML_text.=" <tr><td width='150' align='left'><input type='radio' name='report_source' value='SNAPSHOT' onClick=\"ToggleSpan('snapshot_span', '')\" $ss_checked>Snapshot</td></tr>\n";
if ($inventory_allow_realtime > 0)
{
$HTML_text.=" <tr><td align='left'><input type='radio' name='report_source' value='REALTIME' onClick=\"ToggleSpan('', 'snapshot_span')\" $rt_checked>Real-time</td></tr>\n";
}
else
{
$HTML_text.=" <tr><td align='left'> &nbsp; </td></tr>\n";
}
$HTML_text.=" <tr><td align='left'><span id='snapshot_span' style='display:block;'>$snapshot_span_txt</span>\n";
$HTML_text.=" </table>\n";
$HTML_text.="</TD>\n";
$HTML_text.="<TD VALIGN='top' align='center'>\n";
$HTML_text.="<font color='BLACK' face='ARIAL,HELVETICA' size='2'> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href='$PHP_SELF?DB=$DB$groupQS&selected_list=$selected_list&report_type=$report_type&time_setting=$time_setting&report_source=$report_source&snapshot_time=$snapshot_time&file_download=1&SUBMIT=$SUBMIT'>DOWNLOAD</a> | <a href='./admin.php?ADD=999999'>REPORTS</a> </font><BR><BR>\n";
$HTML_text.="<input name='SUBMIT' value='SUBMIT' type='submit'>\n";
$HTML_text.="</TD>\n";
$HTML_text.="</TR>\n";
$HTML_text.="</TABLE>\n";
$HTML_text.="<PRE><FONT SIZE=2>\n\n";
$HTML_text.="$rpt_header";
$HTML_text.="$rpt_body";
$HTML_text.="$rpt_footer";
$time_end = microtime(true);
$ENDtime = date("U");
$time = $ENDtime - $STARTtime;
$HTML_text.="Executed in $time seconds\n";
$HTML_text.="</FONT></PRE>\n";
$HTML_text.="</BODY>\n";
$HTML_text.="</HTML>\n";
if ($file_download>0)
{
$FILE_TIME = date("Ymd-His");
$CSVfilename = "AST_DIALERinventory_$US$FILE_TIME.csv";
$CSV_text=$CSV_header.$CSV_body;
$CSV_text=preg_replace('/^\s+/', '', $CSV_text);
$CSV_text=preg_replace('/\s+,/', ',', $CSV_text);
$CSV_text=preg_replace('/,\s+/', ',', $CSV_text);
// We'll be outputting a TXT file
header('Content-type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"$CSVfilename\"");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
ob_clean();
flush();
echo "$CSV_text";
exit;
}
else
{
$short_header=1;
echo $HTML_header;
require("admin_header.php");
echo $HTML_text;
}
?>
+17 -7
View File
@@ -105,9 +105,9 @@ $PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW'];
$PHP_SELF=$_SERVER['PHP_SELF'];
$QUERY_STRING = getenv("QUERY_STRING");
$Vreports = 'NONE, Real-Time Main Report, Real-Time Campaign Summary , Inbound Report, Inbound Service Level Report, Inbound Summary Hourly Report, Inbound Daily Report, Inbound DID Report, Inbound IVR Report, Outbound Calling Report, Outbound Summary Interval Report, Outbound IVR Report, Fronter - Closer Report, Lists Campaign Statuses Report, Campaign Status List Report, Export Calls Report, Export Leads Report , Agent Time Detail, Agent Status Detail, Agent Performance Detail, Team Performance Detail, Single Agent Daily , User Timeclock Report, User Group Timeclock Status Report, User Timeclock Detail Report , Server Performance Report, Administration Change Log, List Update Stats, User Stats, User Time Sheet, Download List';
$Vreports = 'NONE, Real-Time Main Report, Real-Time Campaign Summary , Inbound Report, Inbound Service Level Report, Inbound Summary Hourly Report, Inbound Daily Report, Inbound DID Report, Inbound IVR Report, Outbound Calling Report, Outbound Summary Interval Report, Outbound IVR Report, Fronter - Closer Report, Lists Campaign Statuses Report, Campaign Status List Report, Export Calls Report, Export Leads Report , Agent Time Detail, Agent Status Detail, Agent Performance Detail, Team Performance Detail, Single Agent Daily , User Timeclock Report, User Group Timeclock Status Report, User Timeclock Detail Report , Server Performance Report, Administration Change Log, List Update Stats, User Stats, User Time Sheet, Download List, Dialer Inventory Report';
$UGreports = 'ALL REPORTS, NONE, Real-Time Main Report, Real-Time Campaign Summary , Inbound Report, Inbound Service Level Report, Inbound Summary Hourly Report, Inbound Daily Report, Inbound DID Report, Inbound IVR Report, Outbound Calling Report, Outbound Summary Interval Report, Outbound IVR Report, Fronter - Closer Report, Lists Campaign Statuses Report, Campaign Status List Report, Export Calls Report , Export Leads Report , Agent Time Detail, Agent Status Detail, Agent Performance Detail, Team Performance Detail, Single Agent Daily , User Timeclock Report, User Group Timeclock Status Report, User Timeclock Detail Report , Server Performance Report, Administration Change Log, List Update Stats, User Stats, User Time Sheet, Download List, Custom Reports Links, CallCard Search';
$UGreports = 'ALL REPORTS, NONE, Real-Time Main Report, Real-Time Campaign Summary , Inbound Report, Inbound Service Level Report, Inbound Summary Hourly Report, Inbound Daily Report, Inbound DID Report, Inbound IVR Report, Outbound Calling Report, Outbound Summary Interval Report, Outbound IVR Report, Fronter - Closer Report, Lists Campaign Statuses Report, Campaign Status List Report, Export Calls Report , Export Leads Report , Agent Time Detail, Agent Status Detail, Agent Performance Detail, Team Performance Detail, Single Agent Daily , User Timeclock Report, User Group Timeclock Status Report, User Timeclock Detail Report , Server Performance Report, Administration Change Log, List Update Stats, User Stats, User Time Sheet, Download List, Dialer Inventory Report, Custom Reports Links, CallCard Search';
$Vtables = 'NONE,log_noanswer,did_agent_log,contact_information';
@@ -3022,12 +3022,13 @@ else
# 111201-0939 - Added graded-random next-agent-call option
# 111223-0043 - Added max stats displays for in-groups and , fixed several ereg issues
# 111227-1938 - Added Timer Action for Dx_DIAL_QUIET options
# 120102-2125 - Added Dialer Inventory Report
#
# make sure you have added a user to the vicidial_users MySQL table with at least user_level 8 to access this page the first time
$admin_version = '2.4-352a';
$build = '111227-1938';
$admin_version = '2.4-353a';
$build = '120102-2125';
$STARTtime = date("U");
$SQLdate = date("Y-m-d H:i:s");
@@ -32141,13 +32142,19 @@ if ($ADD==999999)
$stmt="SELECT queuemetrics_url,vtiger_url from system_settings;";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$queuemetrics_url_LU = $row[0];
$vtiger_url_LU = $row[1];
$queuemetrics_url_LU = $row[0];
$vtiger_url_LU = $row[1];
$stmt="SELECT count(*) from vicidial_list_update_log;";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$list_update_count = $row[0];
$list_update_count = $row[0];
$stmt="SELECT count(*) from dialable_inventory_snapshots;";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$inventory_report_count = $row[0];
?>
<HTML>
@@ -32208,6 +32215,9 @@ if ($ADD==999999)
if ( (preg_match("/Campaign Status List Report/",$LOGallowed_reports)) or (preg_match("/ALL REPORTS/",$LOGallowed_reports)) )
{echo "<LI><a href=\"AST_campaign_status_list_report.php\"><FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>Campaign Status List Report</a></FONT>\n";}
# echo "<LI><a href=\"vicidial_sales_viewer.php\"><FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>AGENT SPREADSHEET PERFORMANCE</a></FONT>\n";
if ( ( (preg_match("/Dialer Inventory Report/",$LOGallowed_reports)) or (preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) and ($inventory_report_count > 0) )
{echo "<LI><a href=\"AST_dialer_inventory_report.php\"><FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>Dialer Inventory Report</a></FONT>\n";}
if ($LOGexport_reports >= 1)
{
if ( (preg_match("/Export Calls Report/",$LOGallowed_reports)) or (preg_match("/ALL REPORTS/",$LOGallowed_reports)) )
@@ -0,0 +1,456 @@
<?php
##### CALCULATE COMPLETE LEADS #####
function complete_leads($DB,$link,$dial_statuses,$camp_lists,$call_count_limit,$single_status,$campaign_id)
{
if (isset($camp_lists))
{
if (strlen($camp_lists)>1)
{
if (strlen($dial_statuses)>2)
{
$dial_statuses = preg_replace("/ -$/","",$dial_statuses);
$Dstatuses = explode(" ", $dial_statuses);
$Ds_to_print = (count($Dstatuses) - 0);
$Dsql = '';
$o=0;
while ($Ds_to_print > $o)
{
$o++;
$Dsql .= "'$Dstatuses[$o]',";
}
$Dsql = preg_replace("/,$/","",$Dsql);
if (strlen($Dsql) < 2) {$Dsql = "''";}
$CCLsql = "(called_count < 0) or";
if ($call_count_limit > 0)
{$CCLsql = "(called_count >= $call_count_limit) or";}
$complete_statuses='';
$stmt="SELECT status from vicidial_statuses where completed='Y';";
$rslt=mysql_query($stmt, $link);
$statuses_to_print = mysql_num_rows($rslt);
$q=0;
while ($statuses_to_print > $q)
{
$rowx=mysql_fetch_row($rslt);
$complete_statuses.="'$rowx[0]',";
$q++;
}
$stmt="SELECT status from vicidial_campaign_statuses where completed='Y';";
$rslt=mysql_query($stmt, $link);
$statuses_to_print = mysql_num_rows($rslt);
$q=0;
while ($statuses_to_print > $q)
{
$rowx=mysql_fetch_row($rslt);
$complete_statuses.="'$rowx[0]',";
$q++;
}
$complete_statuses = preg_replace("/,$/","",$complete_statuses);
if (strlen($complete_statuses) < 2) {$complete_statuses = "''";}
$CSsql = "status IN($complete_statuses)";
$stmt="SELECT count(*) FROM vicidial_list where ( (status IN($Dsql)) and (list_id IN($camp_lists)) and ( $CCLsql ($CSsql) ) );";
#$DB=1;
if ($DB) {$HTML_header.="$stmt\n";}
$rslt=mysql_query($stmt, $link);
$rslt_rows = mysql_num_rows($rslt);
if ($rslt_rows)
{
$rowx=mysql_fetch_row($rslt);
$complete_leads = $rowx[0];
}
else {$complete_leads = '0';}
if ($DB > 0) {$HTML_header.="|$DB|\n";}
if ($single_status > 0)
{return $complete_leads;}
else
{$HTML_header.="There are $complete_leads completed leads in those lists\n";}
}
else
{
$HTML_header.="no dial statuses selected for this campaign\n";
}
}
else
{
$HTML_header.="no active lists selected for this campaign\n";
}
}
else
{
$HTML_header.="no active lists selected for this campaign\n";
}
}
##### CALCULATE DIALABLE LEADS #####
function dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL)
{
global $full_dialable_SQL;
##### BEGIN calculate what gmt_offset_now values are within the allowed local_call_time setting ###
if (isset($camp_lists))
{
if (strlen($camp_lists)>1)
{
if (strlen($dial_statuses)>2)
{
$g=0;
$p='13';
$GMT_gmt[0] = '';
$GMT_hour[0] = '';
$GMT_day[0] = '';
while ($p > -13)
{
$pzone=3600 * $p;
$pmin=(gmdate("i", time() + $pzone));
$phour=( (gmdate("G", time() + $pzone)) * 100);
$pday=gmdate("w", time() + $pzone);
$tz = sprintf("%.2f", $p);
$GMT_gmt[$g] = "$tz";
$GMT_day[$g] = "$pday";
$GMT_hour[$g] = ($phour + $pmin);
$p = ($p - 0.25);
$g++;
}
$stmt="SELECT call_time_id,call_time_name,call_time_comments,ct_default_start,ct_default_stop,ct_sunday_start,ct_sunday_stop,ct_monday_start,ct_monday_stop,ct_tuesday_start,ct_tuesday_stop,ct_wednesday_start,ct_wednesday_stop,ct_thursday_start,ct_thursday_stop,ct_friday_start,ct_friday_stop,ct_saturday_start,ct_saturday_stop,ct_state_call_times FROM vicidial_call_times where call_time_id='$local_call_time';";
if ($DB) {$HTML_header.="$stmt\n";}
$rslt=mysql_query($stmt, $link);
$rowx=mysql_fetch_row($rslt);
$Gct_default_start = $rowx[3];
$Gct_default_stop = $rowx[4];
$Gct_sunday_start = $rowx[5];
$Gct_sunday_stop = $rowx[6];
$Gct_monday_start = $rowx[7];
$Gct_monday_stop = $rowx[8];
$Gct_tuesday_start = $rowx[9];
$Gct_tuesday_stop = $rowx[10];
$Gct_wednesday_start = $rowx[11];
$Gct_wednesday_stop = $rowx[12];
$Gct_thursday_start = $rowx[13];
$Gct_thursday_stop = $rowx[14];
$Gct_friday_start = $rowx[15];
$Gct_friday_stop = $rowx[16];
$Gct_saturday_start = $rowx[17];
$Gct_saturday_stop = $rowx[18];
$Gct_state_call_times = $rowx[19];
$ct_states = '';
$ct_state_gmt_SQL = '';
$ct_srs=0;
$b=0;
if (strlen($Gct_state_call_times)>2)
{
$state_rules = explode('|',$Gct_state_call_times);
$ct_srs = ((count($state_rules)) - 2);
}
while($ct_srs >= $b)
{
if (strlen($state_rules[$b])>1)
{
$stmt="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]';";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$Gstate_call_time_id = $row[0];
$Gstate_call_time_state = $row[1];
$Gsct_default_start = $row[4];
$Gsct_default_stop = $row[5];
$Gsct_sunday_start = $row[6];
$Gsct_sunday_stop = $row[7];
$Gsct_monday_start = $row[8];
$Gsct_monday_stop = $row[9];
$Gsct_tuesday_start = $row[10];
$Gsct_tuesday_stop = $row[11];
$Gsct_wednesday_start = $row[12];
$Gsct_wednesday_stop = $row[13];
$Gsct_thursday_start = $row[14];
$Gsct_thursday_stop = $row[15];
$Gsct_friday_start = $row[16];
$Gsct_friday_stop = $row[17];
$Gsct_saturday_start = $row[18];
$Gsct_saturday_stop = $row[19];
$ct_states .="'$Gstate_call_time_state',";
$r=0;
$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
{
if ( ($GMT_hour[$r]>=$Gsct_sunday_start) and ($GMT_hour[$r]<$Gsct_sunday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gsct_monday_start) and ($GMT_hour[$r]<$Gsct_monday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gsct_tuesday_start) and ($GMT_hour[$r]<$Gsct_tuesday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gsct_wednesday_start) and ($GMT_hour[$r]<$Gsct_wednesday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gsct_thursday_start) and ($GMT_hour[$r]<$Gsct_thursday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gsct_friday_start) and ($GMT_hour[$r]<$Gsct_friday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gsct_saturday_start) and ($GMT_hour[$r]<$Gsct_saturday_stop) )
{$state_gmt.="'$GMT_gmt[$r]',";}
}
}
$r++;
}
$state_gmt = "$state_gmt'99'";
$ct_state_gmt_SQL .= "or (state='$Gstate_call_time_state' and gmt_offset_now IN($state_gmt)) ";
}
$b++;
}
if (strlen($ct_states)>2)
{
$ct_states = eregi_replace(",$",'',$ct_states);
$ct_statesSQL = "and state NOT IN($ct_states)";
}
else
{
$ct_statesSQL = "";
}
$r=0;
$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
{
if ( ($GMT_hour[$r]>=$Gct_sunday_start) and ($GMT_hour[$r]<$Gct_sunday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gct_monday_start) and ($GMT_hour[$r]<$Gct_monday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gct_tuesday_start) and ($GMT_hour[$r]<$Gct_tuesday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gct_wednesday_start) and ($GMT_hour[$r]<$Gct_wednesday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gct_thursday_start) and ($GMT_hour[$r]<$Gct_thursday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gct_friday_start) and ($GMT_hour[$r]<$Gct_friday_stop) )
{$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
{
if ( ($GMT_hour[$r]>=$Gct_saturday_start) and ($GMT_hour[$r]<$Gct_saturday_stop) )
{$default_gmt.="'$GMT_gmt[$r]',";}
}
}
$r++;
}
$default_gmt = "$default_gmt'99'";
$all_gmtSQL = "(gmt_offset_now IN($default_gmt) $ct_statesSQL) $ct_state_gmt_SQL";
$dial_statuses = preg_replace("/ -$/","",$dial_statuses);
$Dstatuses = explode(" ", $dial_statuses);
$Ds_to_print = (count($Dstatuses) - 0);
$Dsql = '';
$o=0;
while ($Ds_to_print > $o)
{
$o++;
$Dsql .= "'$Dstatuses[$o]',";
}
$Dsql = preg_replace("/,$/","",$Dsql);
if (strlen($Dsql) < 2) {$Dsql = "''";}
$DLTsql='';
if ($drop_lockout_time > 0)
{
$DLseconds = ($drop_lockout_time * 3600);
$DLseconds = floor($DLseconds);
$DLseconds = intval("$DLseconds");
$DLTsql = "and ( ( (status IN('DROP','XDROP')) and (last_local_call_time < CONCAT(DATE_ADD(NOW(), INTERVAL -$DLseconds SECOND),' ',CURTIME()) ) ) or (status NOT IN('DROP','XDROP')) )";
}
$CCLsql='';
if ($call_count_limit > 0)
{
$CCLsql = "and (called_count < $call_count_limit)";
}
$stmt="SELECT count(*) FROM vicidial_list where status IN($Dsql) and list_id IN($camp_lists) and ($all_gmtSQL) $CCLsql $DLTsql $fSQL";
$full_dialable_SQL="status IN($Dsql) and list_id IN($camp_lists) and ($all_gmtSQL) $CCLsql $DLTsql $fSQL";
#$DB=1;
if ($DB) {$HTML_header.="$stmt\n";}
$rslt=mysql_query($stmt, $link);
$rslt_rows = mysql_num_rows($rslt);
if ($rslt_rows)
{
$rowx=mysql_fetch_row($rslt);
$active_leads = "$rowx[0]";
}
else {$active_leads = '0';}
if ($DB > 0) {$HTML_header.="|$DB|\n";}
if ($single_status > 0)
{return $active_leads;}
else
{$HTML_header.="This campaign has $active_leads leads to be dialed in those lists\n";}
}
else
{
$HTML_header.="no dial statuses selected for this campaign\n";
}
}
else
{
$HTML_header.="no active lists selected for this campaign\n";
}
}
else
{
$HTML_header.="no active lists selected for this campaign\n";
}
##### END calculate what gmt_offset_now values are within the allowed local_call_time setting ###
}
?>
@@ -9,6 +9,7 @@
# 101216-1043 - First Build
# 110307-1039 - Added upper-case/lower-case user setting
# 110708-1730 - Added precision time setting
# 120102-2112 - Added inventory_allow_realtime option
#
# used by the realtime_report.php script
@@ -55,5 +56,8 @@ $user_case = 0; # 1=upper-case, 2-lower-case, 0-no-case-change
# force time precision for reports
$TIME_agenttimedetail = 'H'; # H=hour, M=minute, S=second, HF=force hour
# used by inventory report
$inventory_allow_realtime = 0; # allow real-time report generation for inventory report
?>