From 668bc616cf9a08d7c68f54e809757619ebde235f Mon Sep 17 00:00:00 2001 From: mattf Date: Tue, 3 Jan 2012 03:50:33 +0000 Subject: [PATCH] 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 --- agc_2-X/trunk/UPGRADE | 4 + .../bin/AST_dialer_inventory_snapshot.pl | 766 ++++++++++++++++ .../vicidial/AST_dialer_inventory_report.php | 833 ++++++++++++++++++ agc_2-X/trunk/www/vicidial/admin.php | 24 +- .../trunk/www/vicidial/count_functions.inc | 456 ++++++++++ .../trunk/www/vicidial/options-example.php | 4 + 6 files changed, 2080 insertions(+), 7 deletions(-) create mode 100644 agc_2-X/trunk/bin/AST_dialer_inventory_snapshot.pl create mode 100644 agc_2-X/trunk/www/vicidial/AST_dialer_inventory_report.php create mode 100644 agc_2-X/trunk/www/vicidial/count_functions.inc diff --git a/agc_2-X/trunk/UPGRADE b/agc_2-X/trunk/UPGRADE index 95cc581d..25caf8c0 100644 --- a/agc_2-X/trunk/UPGRADE +++ b/agc_2-X/trunk/UPGRADE @@ -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 + diff --git a/agc_2-X/trunk/bin/AST_dialer_inventory_snapshot.pl b/agc_2-X/trunk/bin/AST_dialer_inventory_snapshot.pl new file mode 100644 index 00000000..aa33bbdd --- /dev/null +++ b/agc_2-X/trunk/bin/AST_dialer_inventory_snapshot.pl @@ -0,0 +1,766 @@ +#!/usr/bin/perl +# +# AST_dialer_inventory_snapshot.pl +# +# Copyright (C) 2011 Joe Johnson LICENSE: AGPLv2 +# Matt Florell +# +# 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 = ; +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 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=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 ### + } diff --git a/agc_2-X/trunk/www/vicidial/AST_dialer_inventory_report.php b/agc_2-X/trunk/www/vicidial/AST_dialer_inventory_report.php new file mode 100644 index 00000000..c169b346 --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/AST_dialer_inventory_report.php @@ -0,0 +1,833 @@ + LICENSE: AGPLv2 +# Matt Florell +# +# 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.="\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:
"; +$campaign_span_txt.=""; + +$list_span_txt="Lists:
"; +$list_span_txt.=""; + +$snapshot_span_txt="Snapshot time:
"; +$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.="\n"; + + +$HTML_header.="\n"; +$HTML_header.="\n"; +$HTML_header.="\n"; + +if ($report_type=='LIST') {$onload="onload=\"ToggleSpan('list_span', 'campaign_span')\"";} + +$HTML_header.="\n"; +$HTML_header.="\n"; +$HTML_header.="\n"; +$HTML_header.="$report_name\n"; +$HTML_header.="
\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 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 "
-$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 "
-$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."
\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.="$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 ($j=0; $j=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.="$shift_stmt
$shift_row[0]
\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.="$campaign_stmt; - $dial_statuses\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=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.="$shift_stmt;
$shift_row[0]
\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.="
\n"; +############################### + +$HTML_text="
\n"; +$HTML_text.="\n"; +$HTML_text.="
\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="
\n"; +$HTML_text.=" \n"; +$HTML_text.=" \n"; +if ($report_type=='LIST') {$cmp_checked=""; $list_checked="checked";} else {$cmp_checked="checked"; $list_checked="";} +$HTML_text.=" \n"; +$HTML_text.=" \n"; +$HTML_text.="
Report type:
Campaigns
List
\n"; +$HTML_text.="
 \n"; +$HTML_text.="$campaign_span_txt\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.=" \n"; +$HTML_text.=" \n"; +if ($time_setting=='LOCAL') {$svr_checked=""; $local_checked="checked";} else {$svr_checked="checked"; $local_checked="";} +if ($override_24hours) {$override_checked="checked";} +$HTML_text.=" \n"; +$HTML_text.=" \n"; +$HTML_text.=" \n"; +$HTML_text.="
Time setting:
Server
Local
Ignore local campaign call time
(default to 24 hours)
\n"; +$HTML_text.="
\n"; +$HTML_text.=" \n"; +$HTML_text.=" \n"; +if ($report_source=='REALTIME') {$ss_checked=""; $rt_checked="checked";} else {$ss_checked="checked"; $rt_checked="";} +$HTML_text.=" \n"; + +if ($inventory_allow_realtime > 0) + { + $HTML_text.=" \n"; + } +else + { + $HTML_text.=" \n"; + } + +$HTML_text.="
Report source:
Snapshot
Real-time
 
$snapshot_span_txt\n"; +$HTML_text.="
\n"; +$HTML_text.="
\n"; +$HTML_text.="           DOWNLOAD | REPORTS

\n"; +$HTML_text.="\n"; +$HTML_text.="
\n"; +$HTML_text.="
\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.="
\n"; +$HTML_text.="\n"; +$HTML_text.="\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; + } + +?> + + diff --git a/agc_2-X/trunk/www/vicidial/admin.php b/agc_2-X/trunk/www/vicidial/admin.php index d5e84222..3d0fe865 100644 --- a/agc_2-X/trunk/www/vicidial/admin.php +++ b/agc_2-X/trunk/www/vicidial/admin.php @@ -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]; + ?> @@ -32208,6 +32215,9 @@ if ($ADD==999999) if ( (preg_match("/Campaign Status List Report/",$LOGallowed_reports)) or (preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) {echo "
  • Campaign Status List Report\n";} # echo "
  • AGENT SPREADSHEET PERFORMANCE\n"; + if ( ( (preg_match("/Dialer Inventory Report/",$LOGallowed_reports)) or (preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) and ($inventory_report_count > 0) ) + {echo "
  • Dialer Inventory Report\n";} + if ($LOGexport_reports >= 1) { if ( (preg_match("/Export Calls Report/",$LOGallowed_reports)) or (preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) diff --git a/agc_2-X/trunk/www/vicidial/count_functions.inc b/agc_2-X/trunk/www/vicidial/count_functions.inc new file mode 100644 index 00000000..4c4a0855 --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/count_functions.inc @@ -0,0 +1,456 @@ +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 ### +} +?> diff --git a/agc_2-X/trunk/www/vicidial/options-example.php b/agc_2-X/trunk/www/vicidial/options-example.php index 465679ff..f19eb411 100644 --- a/agc_2-X/trunk/www/vicidial/options-example.php +++ b/agc_2-X/trunk/www/vicidial/options-example.php @@ -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 + ?>