From 65f86c94905ef54495cf54bc667ffeae3960f469 Mon Sep 17 00:00:00 2001 From: mattf Date: Sun, 24 Feb 2008 08:48:40 +0000 Subject: [PATCH] Fixed bugs in FastAGIlog script added new report scripts updated documentation changed active agent display time in timeonVDADall from 30 minutes to 360 minutes Changed all uniqueid fields in database to VARCHAR(20) git-svn-id: svn://192.168.202.10@782 3d104415-ff17-0410-8863-d5cf3c621b8a --- agi/agi-VDAD_ALL_outbound.agi | 1058 ++++++++++++++++++++++++++++ bin/AST_SWAMPauto_dial.pl | 265 +++++++ bin/AST_agent_daily_SPH.pl | 733 +++++++++++++++++++ bin/AST_agent_daily_SPHfront.pl | 662 +++++++++++++++++ bin/FastAGI_log.pl | 70 +- docs/BASE_INSTALL.txt | 1 + docs/REQUIRED_APPS_INSTALL.txt | 16 +- docs/SCRATCH_INSTALL.txt | 16 +- extras/MySQL_AST_CREATE_tables.sql | 20 +- extras/upgrade_2.0.5.sql | 21 +- www/agc/vdc_db_query.php | 10 +- www/vicidial/AST_timeonVDADall.php | 2 +- 12 files changed, 2817 insertions(+), 57 deletions(-) create mode 100644 agi/agi-VDAD_ALL_outbound.agi create mode 100644 bin/AST_SWAMPauto_dial.pl create mode 100644 bin/AST_agent_daily_SPH.pl create mode 100644 bin/AST_agent_daily_SPHfront.pl diff --git a/agi/agi-VDAD_ALL_outbound.agi b/agi/agi-VDAD_ALL_outbound.agi new file mode 100644 index 00000000..8b672ff7 --- /dev/null +++ b/agi/agi-VDAD_ALL_outbound.agi @@ -0,0 +1,1058 @@ +#!/usr/bin/perl +# +# agi-VDAD_ALL_outbound.agi version 2.0.5 *DBI-version* +# +# runs when an outbound call is answered. This script will +# send the calls out to the agents that are logged in. +# ## THIS SCRIPT CONSOLIDATES EIGHT SEPARATE VDAD outbound transfer SCRIPTS ## +# +# +# You need to put lines similar to those below in your extensions.conf file: +# ; Below are the parameters needed for the script to be run properly +# ; 1. the method of call handling for the script: +# ; - NORMAL - Standard outbound routing to agent +# ; - TEST - For performance testing only +# ; - BROADCAST - For no-agent broadcast dialing +# ; - SURVEY - For survery question then on to agent +# ; - REMINDER - Reminder campaign +# ; - REMINDX - Reminder with transfer to agent +# ; 2. the method of searching for an available agent: +# ; - LB - Load Balance total system +# ; - LO - Load Balance Overflow only (priority to home server) +# ; - SO - Home server only +# +# ;outbound VICIDIAL calls: +#exten => 8368,1,Answer ; Answer the line +#exten => 8368,2,AGI(agi-VDAD_ALL_outbound.agi,NORMAL-----LB) +#exten => 8368,3,AGI(agi-VDAD_ALL_outbound.agi,NORMAL-----LB) +#exten => 8368,4,AGI(agi-VDAD_ALL_outbound.agi,NORMAL-----LB) +#exten => 8368,5,Hangup +# +# Copyright (C) 2008 Matt Florell LICENSE: GPLv2 +# +# changes: +# 80218-2027 - First Build +# + +$script = 'agi-VDAD_ALL_outbound.agi'; +$AGILOG = '0'; + +$DROP_TIME = 9; ### default number of seconds to wait until you drop a waiting call +$at='@'; + + +($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); +$year = ($year + 1900); +$mon++; +if ($mon < 10) {$mon = "0$mon";} +if ($mday < 10) {$mday = "0$mday";} +if ($hour < 10) {$Fhour = "0$hour";} +if ($min < 10) {$min = "0$min";} +if ($sec < 10) {$sec = "0$sec";} + +$now_date_epoch = time(); +$now_date = "$year-$mon-$mday $hour:$min:$sec"; +$CLInow_date = "$year-$mon-$mday\\ $hour:$min:$sec"; +$start_time=$now_date; + $CIDdate = "$mon$mday$hour$min$sec"; + $tsSQLdate = "$year$mon$mday$hour$min$sec"; + $SQLdate = "$year-$mon-$mday $hour:$min:$sec"; + $SQLdateBEGIN = $SQLdate; + +$BDtarget = ($now_date_epoch - 5); +($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) = localtime($BDtarget); +$Byear = ($Byear + 1900); +$Bmon++; +if ($Bmon < 10) {$Bmon = "0$Bmon";} +if ($Bmday < 10) {$Bmday = "0$Bmday";} +if ($Bhour < 10) {$Bhour = "0$Bhour";} +if ($Bmin < 10) {$Bmin = "0$Bmin";} +if ($Bsec < 10) {$Bsec = "0$Bsec";} + $BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec"; + + + +# 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 =~ /^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;} + $i++; + } + +if (!$VARDB_port) {$VARDB_port='3306';} +if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";} +if (!$PRSLOGfile) {$PRSLOGfile = "$PATHlogs/prsout.$year-$mon-$mday";} +if (!$PRSTESTfile) {$PRSTESTfile = "$PATHlogs/prstest.$year-$mon-$mday";} + +use DBI; +use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second +use Asterisk::AGI; +$AGI = new Asterisk::AGI; + +$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") + or die "Couldn't connect to database: " . DBI->errstr; + +### Grab Server values from the database +$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks,agi_output FROM servers where server_ip = '$VARserver_ip';"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; + $rec_count=0; +while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $DBvoicemail_dump_exten = "$aryA[0]"; + $DBext_context = "$aryA[1]"; + $DBanswer_transfer_agent = "$aryA[2]"; + $DBSERVER_GMT = "$aryA[3]"; + $DBasterisk_version = "$aryA[4]"; + $DBmax_vicidial_trunks = "$aryA[5]"; + $DBagi_output = "$aryA[6]"; + if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;} + if ($DBext_context) {$ext_context = $DBext_context;} + if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;} + if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;} + if ($DBasterisk_version) {$AST_ver = $DBasterisk_version;} + if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;} + if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';} + if ($DBagi_output =~ /FILE/) {$AGILOG = '2';} + if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';} + $rec_count++; + } +$sthA->finish(); + +### begin parsing run-time options ### +if (length($ARGV[0])>1) +{ + if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;} + $i=0; + while ($#ARGV >= $i) + { + $args = "$args $ARGV[$i]"; + if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;} + $i++; + } + + ### list of command-line array arguments: + @ARGV_vars = split(/-----/, $ARGV[0]); + + $call_handle_method = $ARGV_vars[0]; + $agent_search_method = $ARGV_vars[1]; + +} + +if ($call_handle_method !~ /NORMAL|TEST|BROADCAST|SURVEY|REMIND/) {$call_handle_method='NORMAL';} +if ($agent_search_method !~ /LB|LO|SO/) {$agent_search_method='LB';} + +if ($call_handle_method =~ /BROADCAST|SURVEY/) {$vdlog_status='PU';} +else {$vdlog_status='QUEUE';} + +$|=1; +while() +{ + chomp; + last unless length($_); + if ($AGILOG) + { + if (/^agi_(\w+)\:\s+(.*)$/) + { + $AGI{$1} = $2; + } + } + + if (/^agi_uniqueid\:\s+(.*)$/) {$unique_id = $1; $uniqueid = $unique_id;} + if (/^agi_priority\:\s+(.*)$/) {$priority = $1;} + if (/^agi_channel\:\s+(.*)$/) {$channel = $1;} + if (/^agi_extension\:\s+(.*)$/) {$extension = $1;} + if (/^agi_type\:\s+(.*)$/) {$type = $1;} + if (/^agi_callerid\:\s+(.*)$/) {$callerid = $1;} + if (/^agi_calleridname\:\s+(.*)$/) {$calleridname = $1;} +} + +if ( (length($callerid)>20) && ($callerid =~ /\"\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S/) ) + { + $callerid =~ s/^\"//gi; + $callerid =~ s/\".*$//gi; + ### set the callerid to the ACQS value(calleridname) + print "SET CALLERID $callerid\n"; + checkresult($result); + if ($AGILOG) {$agi_string = "callerID changed: $callerid"; &agi_output;} + } +if ( ( +(length($calleridname)>5) && ( (!$callerid) or ($callerid =~ /unknown|private|00000000/i) or ($callerid =~ /5551212/) ) +) or ( (length($calleridname)>17) && ($calleridname =~ /\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/) ) ) + { + $callerid = $calleridname; + ### set the callerid to the ACQS value(calleridname) + print "SET CALLERID $callerid\n"; + checkresult($result); + if ($AGILOG) {$agi_string = "callerID changed: $callerid"; &agi_output;} + } + + +if ($AGILOG) {$agi_string = "AGI Environment Dump:"; &agi_output;} + +foreach $i (sort keys %AGI) +{ + if ($AGILOG) {$agi_string = " -- $i = $AGI{$i}"; &agi_output;} +} + +if ($AGILOG) {$agi_string = "AGI Variables: |$unique_id|$channel|$extension|$type|$callerid|$calleridname|$priority|"; &agi_output;} + +$VDADcampaign=''; +$VDADphone=''; +$VDADphone_code=''; + +$callerid =~ s/\"//gi; +$CIDlead_id = $callerid; +$CIDlead_id = substr($CIDlead_id, 11, 9); +$CIDlead_id = ($CIDlead_id + 0); + +if ($AGILOG) {$agi_string = "+++++ VDAD START : |$CIDlead_id|$now_date|$AST_ver|$priority|"; &agi_output;} + +if ( ($channel =~ /Local/i) && ($AST_ver !~ /^1\.0\.8|^1\.0\.9/) ) +{ +if ($AGILOG) {$agi_string = "+++++ VDAD START LOCAL CHANNEL: EXITING- $priority"; &agi_output;} +if ($priority > 2) {sleep(1);} +exit; +} + +$stmtA = "SELECT count(*) FROM vicidial_live_agents where callerid='$callerid';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; + $rec_count=0; +while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $Pseudo_duplicate_count = "$aryA[0]"; + $rec_count++; + } +$sthA->finish(); + +if ($Pseudo_duplicate_count > 0) +{ +if ($AGILOG) {$agi_string = "+++++ VDAD START PSEUDO DUPLICATE: EXITING- $priority"; &agi_output;} +exit; +} + +$stmtA = "SELECT count(*) FROM vicidial_auto_calls where callerid='$callerid' and status IN('LIVE','XFER');"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; + $rec_count=0; +while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $dialplan_duplicate_count = "$aryA[0]"; + $rec_count++; + } +$sthA->finish(); + +if ($dialplan_duplicate_count > 0) +{ +if ($AGILOG) {$agi_string = "+++++ VDAD START DIALPLAN DUPLICATE: EXITING- $priority"; &agi_output;} +exit; +} + + +### Grab call parameters from vicidial_auto_calls table +$stmtA = "UPDATE vicidial_auto_calls set uniqueid='$unique_id', channel='$channel',status='LIVE',stage='LIVE-0' where callerid='$callerid' order by call_time desc limit 1;"; +$affected_rows = $dbhA->do($stmtA); +if ($AGILOG) {$agi_string = "-- VDAD : |$affected_rows|update of vac table: $callerid\n|$stmtA|"; &agi_output;} +if ($affected_rows > 0) + { + # flag the lead as being Answered or Picked up + $stmtA = "UPDATE vicidial_list set status='PU' where lead_id='$CIDlead_id';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDAD vicidial_list PU update: |$affected_rows|$uniqueid|"; &agi_output;} + + $stmtA = "SELECT campaign_id,phone_number,phone_code,lead_id,call_time FROM vicidial_auto_calls where callerid='$callerid' order by call_time desc limit 1;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $VDADcampaign = "$aryA[0]"; + $VDADphone = "$aryA[1]"; + $VDADphone_code = "$aryA[2]"; + $VDADlead_id = "$aryA[3]"; + $VDADcall_time = "$aryA[4]"; + $rec_count++; + } + $sthA->finish(); + + ### Grab campaign values from the database + $stmtA = "SELECT drop_call_seconds,safe_harbor_message,safe_harbor_exten,concurrent_transfers,next_agent_call FROM vicidial_campaigns where campaign_id = '$VDADcampaign';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $DBdrop_call_seconds = "$aryA[0]"; + $DBsafe_harbor_message = "$aryA[1]"; + $DBsafe_harbor_exten = "$aryA[2]"; + $DBconcurrent_transfers = "$aryA[3]"; + if ($DBdrop_call_seconds) {$DROP_TIME = $DBdrop_call_seconds;} + if ($DBsafe_harbor_message) {$safe_harbor_message = $DBsafe_harbor_message;} + if ($DBsafe_harbor_exten) {$safe_harbor_exten = $DBsafe_harbor_exten;} + $CAMP_callorder = "$aryA[4]"; + $rec_count++; + } + $sthA->finish(); + + $stmtA = "INSERT INTO vicidial_log (uniqueid,lead_id,campaign_id,call_date,start_epoch,status,phone_code,phone_number,user,processed) values('$uniqueid','$CIDlead_id','$VDADcampaign','$SQLdate','$now_date_epoch','$vdlog_status','$VDADphone_code','$VDADphone','VDAD','N')"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rows = $dbhA->do($stmtA); + + if ($AGILOG) {$agi_string = "-- VDAD : |$VDADlead_id|$CIDlead_id|insert to vicidial_log: $uniqueid"; &agi_output;} + + ############################################# + ##### START QUEUEMETRICS LOGGING LOOKUP ##### + $stmtA = "SELECT enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_log_id,queuemetrics_eq_prepend FROM system_settings;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $enable_queuemetrics_logging = "$aryA[0]"; + $queuemetrics_server_ip = "$aryA[1]"; + $queuemetrics_dbname = "$aryA[2]"; + $queuemetrics_login= "$aryA[3]"; + $queuemetrics_pass = "$aryA[4]"; + $queuemetrics_log_id = "$aryA[5]"; + $queuemetrics_eq_prepend = "$aryA[6]"; + $rec_count++; + } + $sthA->finish(); + ##### END QUEUEMETRICS LOGGING LOOKUP ##### + ########################################### + if ($enable_queuemetrics_logging > 0) + { + $stmtA = "SELECT phone_number FROM vicidial_auto_calls where lead_id='$CIDlead_id';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $phone_number = "$aryA[0]"; + $data2 = "$phone_number"; + $rec_count++; + } + $sthA->finish(); + + if ( (length($queuemetrics_eq_prepend) > 0) && ($queuemetrics_eq_prepend !~ /NONE/) ) + { + $stmtA = "SELECT $queuemetrics_eq_prepend FROM vicidial_list where lead_id='$CIDlead_id';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + $DASH='-'; + @aryA = $sthA->fetchrow_array; + $QMprepend = "$aryA[0]"; + $rec_count++; + $data2 = "$QMprepend$DASH$phone_number"; + } + $sthA->finish(); + } + + $dbhB = DBI->connect("DBI:mysql:$queuemetrics_dbname:$queuemetrics_server_ip:3306", "$queuemetrics_login", "$queuemetrics_pass") + or die "Couldn't connect to database: " . DBI->errstr; + + if ($DBX) {print "CONNECTED TO DATABASE: $queuemetrics_server_ip|$queuemetrics_dbname\n";} + + $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$secX',call_id='$callerid',queue='$VDADcampaign',agent='NONE',verb='ENTERQUEUE',data2='$data2',serverid='$queuemetrics_log_id';"; + $Baffected_rows = $dbhB->do($stmtB); + + $dbhB->disconnect(); + } + } + + +##### PLAY SURVEY/REMINDER MESSAGE ##### +#if ($call_handle_method =~ /SURVEY|REMIND/) +# { +# $AGI->stream_file("$welcome_message_filename"); +# } + + +$drop_timer=0; +$drop_seconds=0; +$hold_message_counter=25; +$hold_tone_counter=0; + +while ($drop_timer <= $DROP_TIME) +{ +$channel_status = $AGI->channel_status("$channel"); +if ($channel_status < 1) + { + if ($AGILOG) {$agi_string = "CHANNEL $channel DOWN $channel_status $DROP_TIME|$drop_timer CHECKING AGAIN"; &agi_output;} + ### sleep for 99 hundredths of a second + usleep(1*990*1000); + + $channel_status_DC = $AGI->channel_status("$channel"); + + if ($channel_status_DC < 1) + { + if ($AGILOG) {$agi_string = "CHANNEL $channel DOWN $channel_status $DROP_TIME|$drop_timer"; &agi_output;} + if ($drop_timer < $DROP_TIME) {$drop_seconds = $drop_timer;} + $drop_timer = ($drop_timer + $DROP_TIME); + } + } + + $rec_countCUSTDATA=0; + $rec_countWAIT=0; + $cbc=0; + $aco_sub=0; + $agent_call_order='order by last_call_finish'; + if ($CAMP_callorder =~ /overall_user_level/i) {$agent_call_order = 'order by user_level desc,last_call_finish';} + if ($CAMP_callorder =~ /oldest_call_start/i) {$agent_call_order = 'order by last_call_time';} + if ($CAMP_callorder =~ /oldest_call_finish/i) {$agent_call_order = 'order by last_call_finish';} + if ($CAMP_callorder =~ /random/i) {$agent_call_order = 'order by random_id';} + if ($CAMP_callorder =~ /campaign_rank/i) {$agent_call_order = 'order by campaign_weight desc,last_call_finish';} + if ($CAMP_callorder =~ /fewest_calls/i) {$aco_sub=1; $agent_call_order = 'order by calls_today';} + + +##### Attempt to send call to an agent on this server only ##### +if ($agent_search_method =~ /^SO|^LO/) +{ + $rec_countWAIT=0; + $stmtA = "SELECT count(*) FROM vicidial_auto_calls where status = 'LIVE' and server_ip='$VARserver_ip' and campaign_id = '$VDADcampaign' and call_time < \"$VDADcall_time\" and lead_id != '$VDADlead_id';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $rec_countWAIT = "$aryA[0]"; + $rec_count++; + } + $sthA->finish(); + if ($DBconcurrent_transfers =~ /AUTO/) + { + $active_agents=1; + $stmtA = "SELECT count(*) FROM vicidial_live_agents where server_ip='$VARserver_ip' and campaign_id = '$VDADcampaign' and last_update_time > '$BDtsSQLdate';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $active_agents = "$aryA[0]"; + $rec_count++; + } + + $concurrent_transfers = ($active_agents / 10); + $concurrent_transfers = sprintf("%.0f", $concurrent_transfers); + $concurrent_transfers++; + if ($AGILOG) {$agi_string = "|CONCURRENT TRANSFERS AUTO SETTING: $concurrent_transfers ($active_agents)|"; &agi_output;} + } + else {$concurrent_transfers = $DBconcurrent_transfers;} + $sthA->finish(); + if ($rec_countWAIT < $concurrent_transfers) + { + $stmtA = "UPDATE vicidial_live_agents set status='QUEUE',lead_id='$CIDlead_id',uniqueid='$unique_id', channel='$channel', call_server_ip='$VARserver_ip', callerid='$callerid' where status = 'READY' and server_ip='$VARserver_ip' and campaign_id='$VDADcampaign' and last_update_time > '$BDtsSQLdate' $agent_call_order limit 1;"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDAD get agent: |$affected_rows|update of vla table: $VDADcampaign|$VARserver_ip\n|$stmtA|"; &agi_output;} + if ($affected_rows > 0) + { + $r=0; + $VDADuser=''; + while ( (length($VDADuser)<1) && ($r<3) ) + { + $stmtA = "SELECT conf_exten,user,extension FROM vicidial_live_agents where status IN('QUEUE','INCALL') and server_ip='$VARserver_ip' and campaign_id='$VDADcampaign' and callerid='$callerid' and channel='$channel' order by last_call_time limit 1;"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $VDADconf_exten = "$aryA[0]"; + $VDADuser = "$aryA[1]"; + $VDADextension = "$aryA[2]"; + $rec_count++; + } + $sthA->finish(); + $r++; + if ($r > 1) + { + if ($AGILOG) {$agi_string = "EEEEEEEEEE vla UPDATE DELAY!!! |$callerid|$r|"; &agi_output;} + + ### sleep for 23 hundredths of a second + usleep(1*230*1000); + $drop_timer = ($drop_timer + 0.25); + } + if ($r > 2) + { + $stmtA = "SELECT conf_exten,user,extension FROM vicidial_live_agents where callerid='$callerid' order by last_call_time limit 1;"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $VDADconf_exten = "$aryA[0]"; + $VDADuser = "$aryA[1]"; + $VDADextension = "$aryA[2]"; + $rec_count++; + } + $sthA->finish(); + + if ($AGILOG) {$agi_string = "FFFFFFFFFF vla OR SELECT |$callerid|$VDADuser|"; &agi_output;} + } + } + + $stmtA = "UPDATE vicidial_auto_calls set status='XFER', stage='XFER-$drop_timer' where callerid='$callerid';"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDAD XFER : |$affected_rows|update of vac table: $callerid\n|$stmtA|"; &agi_output;} + + $dbhA->disconnect(); + + if ($enable_queuemetrics_logging > 0) + { + $dbhB = DBI->connect("DBI:mysql:$queuemetrics_dbname:$queuemetrics_server_ip:3306", "$queuemetrics_login", "$queuemetrics_pass") + or die "Couldn't connect to database: " . DBI->errstr; + + if ($DBX) {print "CONNECTED TO DATABASE: $queuemetrics_server_ip|$queuemetrics_dbname\n";} + + $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$secX',call_id='$callerid',queue='$VDADcampaign',agent='Agent/$VDADuser',verb='CONNECT',data1='$drop_timer',serverid='$queuemetrics_log_id';"; + $Baffected_rows = $dbhB->do($stmtB); + + $dbhB->disconnect(); + } + + if ($AGILOG) {$agi_string = "exiting the VDAD app, transferring call to $VDADconf_exten"; &agi_output;} + print "SET CONTEXT $ext_context\n"; + checkresult($result); + print "SET EXTENSION $VDADconf_exten\n"; + checkresult($result); + print "SET PRIORITY 1\n"; + checkresult($result); + + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + $year = ($year + 1900); + $mon++; + if ($mon < 10) {$mon = "0$mon";} + if ($mday < 10) {$mday = "0$mday";} + if ($hour < 10) {$Fhour = "0$hour";} + if ($min < 10) {$min = "0$min";} + if ($sec < 10) {$sec = "0$sec";} + + $now_date_epoch = time(); + $now_date = "$year-$mon-$mday $hour:$min:$sec"; + if ($AGILOG) {$agi_string = "XXXXXXXXXX VDAD transferred: start|stop $start_time|$now_date"; &agi_output;} + + exit; + } + else + { + if ($AGILOG) {$agi_string = "NNNNNNNNNN No agent record found!!!"; &agi_output;} + } + } + else + { + if ($AGILOG) {$agi_string = "WWWWWWWW VDAD XFER WAIT: |$rec_countWAIT|$VDADcampaign|$channel|$callerid|$uniqueid|"; &agi_output;} + } +} + +if ($agent_search_method =~ /^LO|^LB/) +{ +################################################################################################### +##### Attempt to send call to an agent on any server ##### + $cbc=0; + $rec_countWAITrem=0; +$stmtA = "SELECT count(*) FROM vicidial_auto_calls where status = 'LIVE' and campaign_id = '$VDADcampaign' and call_time < \"$VDADcall_time\" and lead_id != '$VDADlead_id';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; + $rec_count=0; +while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $rec_countWAITrem = "$aryA[0]"; + $rec_count++; + } +$sthA->finish(); +if ($DBconcurrent_transfers =~ /AUTO/) + { + $active_agents=1; + $stmtA = "SELECT count(*) FROM vicidial_live_agents where campaign_id = '$VDADcampaign' and last_update_time > '$BDtsSQLdate';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $active_agents = "$aryA[0]"; + $rec_count++; + } + + $concurrent_transfers = ($active_agents / 10); + $concurrent_transfers = sprintf("%.0f", $concurrent_transfers); + $concurrent_transfers++; + if ($AGILOG) {$agi_string = "|CONCURRENT TRANSFERS AUTO SETTING: $concurrent_transfers ($active_agents)|"; &agi_output;} + } +else {$concurrent_transfers = $DBconcurrent_transfers;} +$sthA->finish(); +if ($rec_countWAITrem < $concurrent_transfers) + { + $stmtA = "UPDATE vicidial_live_agents set status='QUEUE',lead_id='$CIDlead_id',uniqueid='$unique_id', channel='$channel', call_server_ip='$VARserver_ip', callerid='$callerid' where status = 'READY' and campaign_id='$VDADcampaign' and last_update_time > '$BDtsSQLdate' $agent_call_order limit 1;"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDAD get agent: |$affected_rows|update of vla table: $VDADcampaign|$VARserver_ip\n|$stmtA|"; &agi_output;} + if ($affected_rows > 0) + { + $r=0; + $VDADuser=''; + while ( (length($VDADuser)<1) && ($r<3) ) + { + $stmtA = "SELECT conf_exten,user,extension,server_ip FROM vicidial_live_agents where status IN('QUEUE','INCALL') and campaign_id='$VDADcampaign' and callerid='$callerid' and channel='$channel' order by last_call_time limit 1;"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $VDADconf_exten = "$aryA[0]"; + $VDADuser = "$aryA[1]"; + $VDADextension = "$aryA[2]"; + $VDADserver_ip = "$aryA[3]"; + $rec_count++; + } + $sthA->finish(); + $r++; + if ($r > 1) + { + if ($AGILOG) {$agi_string = "EEEEEEEEEE vla UPDATE DELAY!!! |$callerid|$r|"; &agi_output;} + + ### sleep for 23 hundredths of a second + usleep(1*230*1000); + $drop_timer = ($drop_timer + 0.25); + } + if ($r > 2) + { + $stmtA = "SELECT conf_exten,user,extension,server_ip FROM vicidial_live_agents where callerid='$callerid' order by last_call_time limit 1;"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $VDADconf_exten = "$aryA[0]"; + $VDADuser = "$aryA[1]"; + $VDADextension = "$aryA[2]"; + $VDADserver_ip = "$aryA[3]"; + $rec_count++; + } + $sthA->finish(); + + if ($AGILOG) {$agi_string = "FFFFFFFFFF vla OR SELECT |$callerid|$VDADuser|"; &agi_output;} + } + } + + $stmtA = "UPDATE vicidial_auto_calls set status='XFER', stage='XFER-$drop_timer' where callerid='$callerid';"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDAD XFER REMOTE: |$affected_rows|update of vac table: $callerid\n|$stmtA|"; &agi_output;} + + $dbhA->disconnect(); + + if ($enable_queuemetrics_logging > 0) + { + $dbhB = DBI->connect("DBI:mysql:$queuemetrics_dbname:$queuemetrics_server_ip:3306", "$queuemetrics_login", "$queuemetrics_pass") + or die "Couldn't connect to database: " . DBI->errstr; + + if ($DBX) {print "CONNECTED TO DATABASE: $queuemetrics_server_ip|$queuemetrics_dbname\n";} + + $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$secX',call_id='$callerid',queue='$VDADcampaign',agent='Agent/$VDADuser',verb='CONNECT',data1='$drop_timer',serverid='$queuemetrics_log_id';"; + $Baffected_rows = $dbhB->do($stmtB); + + $dbhB->disconnect(); + } + + ### format the remote server dialstring to get the call to the overflow agent meetme room + $S='*'; + if( $VDADserver_ip =~ m/(\S+)\.(\S+)\.(\S+)\.(\S+)/ ) + { + $a = leading_zero($1); + $b = leading_zero($2); + $c = leading_zero($3); + $d = leading_zero($4); + $VDADremDIALstr = "$a$S$b$S$c$S$d$S"; + } + $VDADremDIALstr .= "$VDADconf_exten"; + + if ($AGILOG) {$agi_string = "exiting the VDAD app, transferring call to $VDADremDIALstr"; &agi_output;} + print "SET CONTEXT $ext_context\n"; + checkresult($result); + print "SET EXTENSION $VDADremDIALstr\n"; + checkresult($result); + print "SET PRIORITY 1\n"; + checkresult($result); + + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + $year = ($year + 1900); + $mon++; + if ($mon < 10) {$mon = "0$mon";} + if ($mday < 10) {$mday = "0$mday";} + if ($hour < 10) {$Fhour = "0$hour";} + if ($min < 10) {$min = "0$min";} + if ($sec < 10) {$sec = "0$sec";} + + $now_date_epoch = time(); + $now_date = "$year-$mon-$mday $hour:$min:$sec"; + if ($AGILOG) {$agi_string = "XXXXXXXXXX VDAD transferred: start|stop $start_time|$now_date"; &agi_output;} + + exit; + } + else + { + if ($AGILOG) {$agi_string = "NNNNNNNNNN No agent record found!!!"; &agi_output;} + } + } +else + { + if ($AGILOG) {$agi_string = "WWWWWWWW VDAD XFER BALANCE WAIT: |$rec_countWAIT|$VDADcampaign|$channel|$callerid|$uniqueid|"; &agi_output;} + } + +} + +if ($drop_timer < 3) + { + ### sleep for 23 hundredths of a second + usleep(1*230*1000); + $drop_timer = ($drop_timer + 0.25); + } +else + { + ### sleep for 99 hundredths of a second + usleep(1*990*1000); + + $drop_timer++; + } + +$stmtA = "UPDATE vicidial_auto_calls set stage='LIVE-$drop_timer' where callerid='$callerid';"; +$affected_rows = $dbhA->do($stmtA); +if ($affected_rows < 1) + { + $stmtA = "INSERT INTO vicidial_auto_calls (server_ip,campaign_id,status,lead_id,uniqueid,callerid,channel,phone_code,phone_number,call_time,call_type,stage) values('$VARserver_ip','$channel_group','CLOSER','$insert_lead_id','$uniqueid','$callerid','$channel','$phone_code','$phone_number','$SQLdate','IN','CLOSER-$drop_timer')"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "$affected_rows|VDAC-reinsert|$stmtA|"; &agi_output;} + } +#if ($AGILOG) {$agi_string = "-- VDAD : |$affected_rows|update of vac table: $callerid\n|$stmtA|"; &agi_output;} + +} + + + + + + + + + + + + + +if ($drop_timer > $DROP_TIME) +{ +($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); +$year = ($year + 1900); +$mon++; +if ($mon < 10) {$mon = "0$mon";} +if ($mday < 10) {$mday = "0$mday";} +if ($hour < 10) {$Fhour = "0$hour";} +if ($min < 10) {$min = "0$min";} +if ($sec < 10) {$sec = "0$sec";} + +$now_date_epoch = time(); +$now_date = "$year-$mon-$mday $hour:$min:$sec"; + $CIDdate = "$mon$mday$hour$min$sec"; + $tsSQLdate = "$year$mon$mday$hour$min$sec"; + $SQLdate = "$year-$mon-$mday $hour:$min:$sec"; + $VDADvoicemail_ext = ''; + +if ($enable_queuemetrics_logging > 0) + { + $dbhB = DBI->connect("DBI:mysql:$queuemetrics_dbname:$queuemetrics_server_ip:3306", "$queuemetrics_login", "$queuemetrics_pass") + or die "Couldn't connect to database: " . DBI->errstr; + + if ($DBX) {print "CONNECTED TO DATABASE: $queuemetrics_server_ip|$queuemetrics_dbname\n";} + + $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$secX',call_id='$callerid',queue='$VDADcampaign',agent='NONE',verb='EXITWITHTIMEOUT',data1='1',serverid='$queuemetrics_log_id';"; + $Baffected_rows = $dbhB->do($stmtB); + + $dbhB->disconnect(); + } + +if ($drop_seconds < 1) + { + $drop_seconds = $DROP_TIME; + + if ($safe_harbor_message =~ /Y/) + { + $DROPexten = "$safe_harbor_exten"; + } + else + { + $stmtA = "SELECT voicemail_ext FROM vicidial_campaigns where campaign_id = '$VDADcampaign' limit 1;"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $VDADvoicemail_ext = "$aryA[0]"; + $VDADvoicemail_ext =~ s/\D//gi; + if (length($VDADvoicemail_ext)>0) + {$DROPexten = "$voicemail_dump_exten$VDADvoicemail_ext";} + $rec_count++; + } + $sthA->finish(); + } + } + + + ### use STDOUT to send call to proper DROP location + $VHqueryCID = "VH$CIDdate$VDADconf_exten"; + + if (length($DROPexten)>0) + { ### if DROP extension is defined then send the dropped call there instead of hangup + + $AGI->stream_file('ding'); # stop music-on-hold process + + sleep(1); + + if ($AGILOG) {$agi_string = "exiting the VDAD app, transferring call to $DROPexten"; &agi_output;} + print "SET CONTEXT $ext_context\n"; + checkresult($result); + print "SET EXTENSION $DROPexten\n"; + checkresult($result); + print "SET PRIORITY 1\n"; + checkresult($result); + } + else + { + ### insert a NEW record to the vicidial_manager table to be processed + $stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$VARserver_ip','','Hangup','$VHqueryCID','Channel: $channel','','','','','','','','','')"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDCL call_hungup timout: |$VHqueryCID|$VDADconf_exten|$channel|insert to vicidial_manager"; &agi_output;} + } + + $stmtA = "DELETE FROM vicidial_auto_calls where callerid='$callerid' order by call_time desc limit 1;"; + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDAD vac record deleted: |$affected_rows|$VDADcampaign|"; &agi_output;} + + $Euniqueid=$uniqueid; + $Euniqueid =~ s/\.*//gi; + $stmtA = "UPDATE vicidial_log FORCE INDEX(lead_id) set status='DROP',end_epoch='$now_date_epoch',length_in_sec='$drop_seconds' where lead_id = '$CIDlead_id' and uniqueid LIKE \"$Euniqueid%\";"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDAD vicidial_log update: |$affected_rows|$uniqueid"; &agi_output;} + + $stmtA = "UPDATE vicidial_list set status='DROP' where lead_id = '$CIDlead_id';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDAD vicidial_list update: |$affected_rows|$CIDlead_id"; &agi_output;} +} + + + + $dbhA->disconnect(); + +exit; + +sub enter_pin_number +{ + +$digits_to_collect =~ s/DIGITID//gi; + +# please enter the pin number followed by the pound key +# please enter your X digit pin number + +$digit=''; +undef $digit; +$interrupt_digit=''; +undef $interrupt_digit; + +$interrupt_digit = $AGI->stream_file('four_digit_id','123456789'); + + if ($AGILOG) {$agi_string = "interrupt_digit |$interrupt_digit|"; &agi_output;} + +$digits_being_entered=1; +$totalDTMF=''; +if ($interrupt_digit > 1) + { + if ($interrupt_digit == 48) {$interrupt_digit=0;} + if ($interrupt_digit == 49) {$interrupt_digit=1;} + if ($interrupt_digit == 50) {$interrupt_digit=2;} + if ($interrupt_digit == 51) {$interrupt_digit=3;} + if ($interrupt_digit == 52) {$interrupt_digit=4;} + if ($interrupt_digit == 53) {$interrupt_digit=5;} + if ($interrupt_digit == 54) {$interrupt_digit=6;} + if ($interrupt_digit == 55) {$interrupt_digit=7;} + if ($interrupt_digit == 56) {$interrupt_digit=8;} + if ($interrupt_digit == 57) {$interrupt_digit=9;} + + $totalDTMF=$interrupt_digit; + } + +$digit_loop_counter=0; + +while ( ($digit_loop_counter < $digits_to_collect) ) + { + $digit = chr($AGI->wait_for_digit('10000')); # wait 10 seconds for input or until the pound key is pressed + if ($digit =~ /\d/) + { + $totalDTMF = "$totalDTMF$digit"; + if ($AGILOG) {$agi_string = "digit |$digit| TotalDTMF |$totalDTMF|"; &agi_output;} +# $AGI->say_digits("$digit"); + undef $digit; + } + else + { + $digit_loop_counter=$digits_to_collect; + } + + $digit_loop_counter++; + } + +$totalDTMF =~ s/\D//gi; +$pin = $totalDTMF; +if ($totalDTMF) {if ($AGILOG) {$agi_string = "digit |$digit| TotalDTMF |$totalDTMF|"; &agi_output;}} +} + + + + +sub checkresult { + my ($res) = @_; + my $retval; + $tests++; + chomp $res; + if ($res =~ /^200/) { + $res =~ /result=(-?\d+)/; + if (!length($1)) { + # print STDERR "FAIL ($res)\n"; + $fail++; + } else { + # print STDERR "PASS ($1)\n"; + $pass++; + } + } else { + # print STDERR "FAIL (unexpected result '$res')\n"; + $fail++; + } +} + + +sub leading_zero($) +{ + $_ = $_[0]; + s/^(\d)$/0$1/; + s/^(\d\d)$/0$1/; + return $_; +} # End of the leading_zero() routine. + + + +### you're call is very important to us, please stay on the line and you will be transferred to the next available agent + + +sub agi_output +{ +if ($AGILOG >=2) + { + ### open the log file for writing ### + open(Lout, ">>$AGILOGfile") + || die "Can't open $AGILOGfile: $!\n"; + print Lout "$now_date|$script|$agi_string\n"; + close(Lout); + } + ### send to STDERR writing ### +if ( ($AGILOG == '1') || ($AGILOG == '3') ) + {print STDERR "$now_date|$script|$agi_string\n";} +$agi_string=''; +} + + +sub trigger_transfer_process +{ +# $DS='--'; +# $BEGIN='BEGIN'; +# +# $CLI = "/usr/bin/date >> $PRSTESTfile &"; +# $CLI = "/root/phone.pl $insert_lead_id$DS$insert_close_id$DS$CLInow_date$DS$VDADuser$DS$phone_number$DS$DS$BEGIN$DS >> $PRSTESTfile &"; +# +# `$CLI`; +# +# if ($AGILOG >=2) +# { +# ### open the log file for writing ### +# open(Pout, ">>$PRSLOGfile") +# || die "Can't open $AGILOGfile: $!\n"; +# print Pout "$now_date|$VDADconf_exten|$VDADuser|$VDADextension|$insert_lead_id|$phone_number|$insert_close_id|$channel_group|$drop_timer|$CLI|\n"; +# close(Pout); +# } +} diff --git a/bin/AST_SWAMPauto_dial.pl b/bin/AST_SWAMPauto_dial.pl new file mode 100644 index 00000000..28bd26e1 --- /dev/null +++ b/bin/AST_SWAMPauto_dial.pl @@ -0,0 +1,265 @@ +#!/usr/bin/perl +# +# AST_SWAMPauto_dial.pl version 0.2 +# +# DESCRIPTION: +# uses MySQL to place auto_dial calls on the VICIDIAL dialer system +# +# SUMMARY: +# This program was designed to test inbound phone system with a set number of +# calls being launched one per second for a set time period using incrementing +# CallerID numbers +# +# # The Gettysburg address is about 100 seconds, this is a free recording +# cd /var/lib/asterisk/sounds/ +# wget http://www.eflo.net/files/gettysburgaddress.wav +# +# exten => 834562311,1,Answer +# exten => 834562311,2,Playback(gettysburgaddress) +# exten => 834562311,3,Hangup +# +# Copyright (C) 2008 Matt Florell LICENSE: GPLv2 +# +# changes: +# 50708-1533 - First version +# 80217-0226 - Changed to DBI and added more options +# + + +# constants + $CIDlist[0] = '9989998888'; +$dialstring_800_prefix = '91'; +$dialstring_number = '6102350343'; # number being dialed (inbound queue) + $server_ips[0] = '192.168.75.21'; + $server_ips[1] = '192.168.75.23'; +# $server_ips[2] = '192.168.75.22'; +# $server_ips[3] = '192.168.1.240'; +# $server_ips[0] = '192.168.1.106'; +# $server_ips[1] = '192.168.1.249'; +# $server_ips[2] = '192.168.1.239'; +# $server_ips[3] = '192.168.1.240'; +# $server_ips[0] = '10.10.11.11'; +# $server_ips[1] = '10.10.11.21'; +# $server_ips[2] = '10.10.11.22'; +# $server_ips[3] = '10.10.11.23'; +# $server_ips[4] = '10.10.11.24'; +# $server_ips[5] = '10.10.11.25'; +# $server_ips[6] = '10.10.11.13'; +# $server_ips[7] = '10.10.11.14'; +# $server_ips[8] = '10.10.11.15'; +# $server_ips[9] = '10.10.11.16'; +# $server_ips[10] = '10.10.11.18'; +# $server_ips[11] = '10.10.11.19'; +$exten='834562311'; # where the test audio file is located +$context='default'; +$US='_'; +$loop_delay = '1'; +$it='0'; +$total_loops='3600'; # 3600 seconds = 1 hour +#$total_loops='100'; # 3600 seconds = 1 hour +$dialstring = "$dialstring_800_prefix$dialstring_number"; +$MT[0]=''; + + +### begin parsing run-time options ### +if (length($ARGV[0])>1) +{ + $i=0; + while ($#ARGV >= $i) + { + $args = "$args $ARGV[$i]"; + $i++; + } + + if ($args =~ /--help/i) + { + print "allowed run time options:\n [-t] = test\n [-debug] = verbose debug messages\n [--delay=XXX] = delay of XXX seconds per loop, default 2.5 seconds\n\n"; + } + else + { + if ($args =~ /--delay=/i) + { + @data_in = split(/--delay=/,$args); + $loop_delay = $data_in[1]; + print " LOOP DELAY OVERRIDE!!!!! = $loop_delay seconds\n\n"; + $loop_delay = ($loop_delay * 1000); + } + else + { + $loop_delay = '1000'; + } + if ($args =~ /-debug/i) + { + $DB=1; # Debug flag, set to 0 for no debug messages, On an active system this will generate hundreds of lines of output per minute + } + if ($args =~ /-t/i) + { + $TEST=1; + $T=1; + } + } +} +else +{ +print "no command line options set\n"; + $DB=1; + $loop_delay = '1000'; +# $loop_delay = '500'; +} +### end parsing run-time options ### + + +# 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 =~ /^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;} + $i++; + } + +&get_time_now; + +# Customized Variables +$server_ip = $VARserver_ip; # Asterisk server IP + +$SWAMPLOGfile = "$PATHlogs/SWAMP_LOG_$file_date$txt"; + + + $event_string='PROGRAM STARTED||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||'; + &event_logger; # writes to the log and if debug flag is set prints to STDOUT + +use lib './lib', '../lib'; +use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second + + +if (!$VARDB_port) {$VARDB_port='3306';} + +use DBI; + +$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") + or die "Couldn't connect to database: " . DBI->errstr; + + +$event_string='LOGGED INTO MYSQL SERVER ON 1 CONNECTION|'; +&event_logger; + +$total=0; +$list_it=0; +$server_it=0; +$list_inc=0; +while($it < $total_loops) + { + &get_time_now; # update time/date variables + + $CIDtemp = ($CIDlist[$list_it] + $list_inc); + $SERVERtemp = $server_ips[$server_it]; + + $k=0; + while ($k < 1) + { + $stmtA = "INSERT INTO vicidial_manager values('','','$SQLdate','NEW','N','$SERVERtemp','','Originate','TESTCIDX$CIDdate$US$it','Channel: Local/$dialstring@$context','Context; $context','Exten: $exten','Priority: 1','Callerid: \"Inbound Test Call\" <$CIDtemp>','','','','','');"; + $affected_rows = $dbhA->do($stmtA); + # print "|$stmtA|\n"; + $k++; + $total++; + + $event_string="CALL: $total TO: $dialstring CID: $CIDtemp it: $it list_it: $list_it list_inc: $list_inc server: $SERVERtemp"; + print "$event_string\n"; + &event_logger; + + } + ### sleep before beginning the loop again + usleep(1*$loop_delay*1000); + + $it++; + $list_it++; + if ($list_it > $#CIDlist) {$list_it=0; $list_inc++;} + $server_it++; + if ($server_it > $#server_ips) {$server_it=0;} + } + +exit; + + + + + + + + + + + + + +sub get_time_now #get the current date and time and epoch for logging call lengths and datetimes +{ + $secX = time(); +$secX = time(); + +($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); +$year = ($year + 1900); +$mon++; +if ($mon < 10) {$mon = "0$mon";} +if ($mday < 10) {$mday = "0$mday";} +if ($hour < 10) {$Fhour = "0$hour";} +if ($min < 10) {$min = "0$min";} +if ($sec < 10) {$sec = "0$sec";} + +$now_date_epoch = time(); +$now_date = "$year-$mon-$mday $hour:$min:$sec"; +$file_date = "$year-$mon-$mday_$hour$min$sec"; + $CIDdate = "$mon$mday$hour$min$sec"; + $tsSQLdate = "$year$mon$mday$hour$min$sec"; + $SQLdate = "$year-$mon-$mday $hour:$min:$sec"; + +} + + + + + +sub event_logger +{ + +#if ($DB) {print "$now_date|$event_string|\n";} + ### open the log file for writing ### + open(Lout, ">>$SWAMPLOGfile") + || die "Can't open $SWAMPLOGfile: $!\n"; + + print Lout "$now_date|$event_string|\n"; + + close(Lout); + +$event_string=''; +} diff --git a/bin/AST_agent_daily_SPH.pl b/bin/AST_agent_daily_SPH.pl new file mode 100644 index 00000000..b310b83a --- /dev/null +++ b/bin/AST_agent_daily_SPH.pl @@ -0,0 +1,733 @@ +#!/usr/bin/perl + +# AST_agent_daily_SPH.pl +# +# This script is designed to gather stats for all agent activity over the course +# of a week and print it in an ASCI text file to be placed +# on a web server for viewing. +# +# This script assumes a work day to be from 2AM to 2AM +# +# Place in the crontab and run every night at 02:00AM for the previous day's stats +# 0 2 * * * /home/cron/AST_agent_daily_SPH.pl +# +# CHANGES +# 80114-1221 - First version +# 80116-0941 - only print agents with week and month hours of 0 to PIPE file +# 80216-2255 - Add Year-to-date on Sunday mornings only +# + +$txt = '.txt'; +$US = '_'; +$MT[0] = ''; + +$SQLrestrict = "and campaign_id IN('QRA','QRB','QRC','QRD')"; + +### begin parsing run-time options ### +if (length($ARGV[0])>1) +{ + $i=0; + while ($#ARGV >= $i) + { + $args = "$args $ARGV[$i]"; + $i++; + } + + if ($args =~ /--help/i) + { + print "allowed run time options:\n [-q] = quiet\n [-t] = test\n\n"; + exit; + } + else + { + if ($args =~ /--debug/i) + { + $DB=1; + print "\n-----DEBUG MODE-----\n\n"; + } + if ($args =~ /-q/i) + { + $q=1; $Q=1; + } + if ($args =~ /-t/i) + { + $T=1; $TEST=1; + print "\n-----TESTING-----\n\n"; + } + } +} +else +{ +print "no command line options set\n"; +} +### end parsing run-time options ### + + +$secX = time(); + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + $year = ($year + 1900); + $mon++; + if ($mon < 10) {$mon = "0$mon";} + if ($mday < 10) {$mday = "0$mday";} + if ($hour < 10) {$hour = "0$hour";} + if ($min < 10) {$min = "0$min";} + if ($sec < 10) {$sec = "0$sec";} + $filedate = "$year$mon$mday-$hour$min$sec"; + $ABIfiledate = "$mon-$mday-$year$us$hour$min$sec"; + $shipdate = "$year-$mon-$mday"; + $datestamp = "$year/$mon/$mday $hour:$min"; + +use Time::Local; + +$YTDrun=0; + +### find epoch of 2AM today +$TWOAMsec = ( ($secX - ($sec + ($min * 60) + ($hour * 3600) ) ) + 7200); +### find epoch of 2AM yesterday +$TWOAMsecY = ($TWOAMsec - 86400); + +($Tsec,$Tmin,$Thour,$Tmday,$Tmon,$Tyear,$Twday,$Tyday,$Tisdst) = localtime($TWOAMsecY); +$Tyear = ($Tyear + 1900); +$Tmon++; +if ($Tmon < 10) {$Tmon = "0$Tmon";} +if ($Tmday < 10) {$Tmday = "0$Tmday";} +if ($Thour < 10) {$Thour = "0$Thour";} +if ($Tmin < 10) {$Tmin = "0$Tmin";} +if ($Tsec < 10) {$Tsec = "0$Tsec";} + $begindate = "$Tyear-$Tmon-$Tmday $Thour:$Tmin:$Tsec"; +if ($Twday == '6') {$YTDrun=1; print "RUNNING YTD\n";} + +### find epoch of 2AM the first day of the month +$BMONTHsec = ($TWOAMsecY - (86400 * ($Tmday - 1) ) ); +### find epoch of 2AM the first day of next month +if ($Tmon>11) {$Tmon=0; $Tyear++;} +$EMONTHsec = timelocal($Tsec,$Tmin,$Thour,1,$Tmon,$Tyear); + + if ($Twday==0) {$day='Sunday '; $SETprevday = 6;} + if ($Twday==1) {$day='Monday '; $SETprevday = 0;} + if ($Twday==2) {$day='Tuesday '; $SETprevday = 1;} + if ($Twday==3) {$day='Wednesday'; $SETprevday = 2;} + if ($Twday==4) {$day='Thursday '; $SETprevday = 3;} + if ($Twday==5) {$day='Friday '; $SETprevday = 4;} + if ($Twday==6) {$day='Saturday '; $SETprevday = 5;} + +($TMsec,$TMmin,$TMhour,$TMmday,$TMmon,$TMyear,$TMwday,$TMyday,$TMisdst) = localtime($BMONTHsec); +$TMyear = ($TMyear + 1900); +$TMmon++; +if ($TMmon < 10) {$TMmon = "0$TMmon";} +if ($TMmday < 10) {$TMmday = "0$TMmday";} +if ($TMhour < 10) {$TMhour = "0$TMhour";} +if ($TMmin < 10) {$TMmin = "0$TMmin";} +if ($TMsec < 10) {$TMsec = "0$TMsec";} + $beginmonth = "$TMyear-$TMmon-$TMmday $TMhour:$TMmin:$TMsec"; + +($TMsec,$TMmin,$TMhour,$TMmday,$TMmon,$TMyear,$TMwday,$TMyday,$TMisdst) = localtime($EMONTHsec); +$TMyear = ($TMyear + 1900); +$TMmon++; +if ($TMmon < 10) {$TMmon = "0$TMmon";} +if ($TMmday < 10) {$TMmday = "0$TMmday";} +if ($TMhour < 10) {$TMhour = "0$TMhour";} +if ($TMmin < 10) {$TMmin = "0$TMmin";} +if ($TMsec < 10) {$TMsec = "0$TMsec";} + $endmonth = "$TMyear-$TMmon-$TMmday $TMhour:$TMmin:$TMsec"; + +#print "|$ABIfiledate|$begindate|$beginmonth|$endmonth|\n"; +#exit; + +print "\n\n\n\n\n\n\n\n\n\n\n\n-- AST_agent_daily_SPH.pl --\n\n"; +print "This program is designed to print sales-per-hour(SPH) to a file for agents' activity for the current week. \n\n"; + + +# 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 =~ /^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;} + $i++; + } + +# Customized Variables +$server_ip = $VARserver_ip; # Asterisk server IP + +$outfile = "AGENT_SPH_$Tyear-$Tmon-$Tmday$txt"; +$Doutfile = "AGENT_SPH_PIPE_$Tyear-$Tmon-$Tmday$txt"; + +### open the X out file for writing ### +open(out, ">$PATHweb/vicidial/agent_reports/$outfile") + || die "Can't open $outfile: $!\n"; +open(Dout, ">$PATHweb/vicidial/agent_reports/$Doutfile") + || die "Can't open $Doutfile: $!\n"; + +if (!$VARDB_port) {$VARDB_port='3306';} + + +use DBI; + +$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; + +#$vicidial_agent_log = 'vicidial_agent_log_archive'; +$vicidial_agent_log = 'vicidial_agent_log'; + +########################################################################### +########### PAST WEEK STAT GATHERING LOOP ################################# +########################################################################### +if ($YTDrun>0) + { + $YEARheadPIPE = 'MONTH HOURS|MONTH SPH|'; + $YEARheadFIXED = ' HRS SPH '; + $YEARhHEAD = ' YEAR'; + } +print Dout "DATE|AGENT|USER|MON HOURS|MON SPH|TUE HOURS|TUE SPH|WED HOURS|WED SPH|THU HOURS|THU SPH|FRI HOURS|FRI SPH|SAT HOURS|SAT SPH|SUN HOURS|SUN SPH|WEEK HOURS|WEEK SPH|MONTH HOURS|MONTH SPH$YEARheadPIPE|GROUP|\n"; +$outline = "REPORT: SPH $Tyear-$Tmon-$Tmday\n\n"; +$outline.= " MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY WEEK MONTH$YEARhHEAD\n"; +$outline.= "AGENT USER HRS SPH HRS SPH HRS SPH HRS SPH HRS SPH HRS SPH HRS SPH HRS SPH HRS SPH $YEARheadFIXED GROUP \n"; +print "$outline"; +print out "$outline"; + +### FIND ALL ACTIVE USERS IN THE SYSTEM IN('1090','1102','1245')='1090' +$stmtA = "select full_name,user,user_group from vicidial_users order by user_group,full_name limit 1000;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; +$rec_count=0; +while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + + $Dname[$rec_count] = $aryA[0]; + $Duser[$rec_count] = $aryA[1]; + $Dgroup[$rec_count] = $aryA[2]; + $name[$rec_count] = sprintf("%-20s", $aryA[0]); while(length($name[$rec_count])>20) {chop($name[$rec_count]);} + $user[$rec_count] = sprintf("%-8s", $aryA[1]); + $group[$rec_count] = sprintf("%-8s", $aryA[2]); + + $rec_count++; + } +$sthA->finish(); + + +$Gsph[0]=' 0'; $Gsph[1]=' 0'; $Gsph[2]=' 0'; $Gsph[3]=' 0'; $Gsph[4]=' 0'; $Gsph[5]=' 0'; $Gsph[6]=' 0'; +$Gsales[0]=0; $Gsales[1]=0; $Gsales[2]=0; $Gsales[3]=0; $Gsales[4]=0; $Gsales[5]=0; $Gsales[6]=0; +$Ghours[0]=' 0.0'; $Ghours[1]=' 0.0'; $Ghours[2]=' 0.0'; $Ghours[3]=' 0.0'; $Ghours[4]=' 0.0'; $Ghours[5]=' 0.0'; $Ghours[6]=' 0.0'; +$GDsph[0]=0; $GDsph[1]=0; $GDsph[2]=0; $GDsph[3]=0; $GDsph[4]=0; $GDsph[5]=0; $GDsph[6]=0; +$GDsales[0]=0; $GDsales[1]=0; $GDsales[2]=0; $GDsales[3]=0; $GDsales[4]=0; $GDsales[5]=0; $GDsales[6]=0; +$GDhours[0]=0; $GDhours[1]=0; $GDhours[2]=0; $GDhours[3]=0; $GDhours[4]=0; $GDhours[5]=0; $GDhours[6]=0; +$GWEEKsph=0; $GWEEKhours=0; $GWEEKsales=0; +$GMONTHsph=0; $GMONTHhours=0; $GMONTHsales=0; +$GYEARsph=0; $GYEARhours=0; $GYEARsales=0; + +$TOTsph[0]=' 0'; $TOTsph[1]=' 0'; $TOTsph[2]=' 0'; $TOTsph[3]=' 0'; $TOTsph[4]=' 0'; $TOTsph[5]=' 0'; $TOTsph[6]=' 0'; +$TOTsales[0]=0; $TOTsales[1]=0; $TOTsales[2]=0; $TOTsales[3]=0; $TOTsales[4]=0; $TOTsales[5]=0; $TOTsales[6]=0; +$TOThours[0]=' 0.0'; $TOThours[1]=' 0.0'; $TOThours[2]=' 0.0'; $TOThours[3]=' 0.0'; $TOThours[4]=' 0.0'; $TOThours[5]=' 0.0'; $TOThours[6]=' 0.0'; +$TOTDsph[0]=0; $TOTDsph[1]=0; $TOTDsph[2]=0; $TOTDsph[3]=0; $TOTDsph[4]=0; $TOTDsph[5]=0; $TOTDsph[6]=0; +$TOTDsales[0]=0; $TOTDsales[1]=0; $TOTDsales[2]=0; $TOTDsales[3]=0; $TOTDsales[4]=0; $TOTDsales[5]=0; $TOTDsales[6]=0; +$TOTDhours[0]=0; $TOTDhours[1]=0; $TOTDhours[2]=0; $TOTDhours[3]=0; $TOTDhours[4]=0; $TOTDhours[5]=0; $TOTDhours[6]=0; +$TOTWEEKsph=0; $TOTWEEKhours=0; $TOTWEEKsales=0; +$TOTMONTHsph=0; $TOTMONTHhours=0; $TOTMONTHsales=0; +$TOTYEARsph=0; $TOTYEARhours=0; $TOTYEARsales=0; + + +### GO THROUGH EACH USER ACCOUNT AND FIND OUT THE HOURS AND SPH +$i=0; +foreach (@Duser) + { + $j=0; + $sph[0]=' 0'; $sph[1]=' 0'; $sph[2]=' 0'; $sph[3]=' 0'; $sph[4]=' 0'; $sph[5]=' 0'; $sph[6]=' 0'; + $sales[0]=0; $sales[1]=0; $sales[2]=0; $sales[3]=0; $sales[4]=0; $sales[5]=0; $sales[6]=0; + $hours[0]=' 0.0'; $hours[1]=' 0.0'; $hours[2]=' 0.0'; $hours[3]=' 0.0'; $hours[4]=' 0.0'; $hours[5]=' 0.0'; $hours[6]=' 0.0'; + $Dsph[0]=0; $Dsph[1]=0; $Dsph[2]=0; $Dsph[3]=0; $Dsph[4]=0; $Dsph[5]=0; $Dsph[6]=0; + $Dsales[0]=0; $Dsales[1]=0; $Dsales[2]=0; $Dsales[3]=0; $Dsales[4]=0; $Dsales[5]=0; $Dsales[6]=0; + $Dhours[0]=0; $Dhours[1]=0; $Dhours[2]=0; $Dhours[3]=0; $Dhours[4]=0; $Dhours[5]=0; $Dhours[6]=0; + $WEEKsph=0; $WEEKhours=0; $WEEKsales=0; + $MONTHsph=0; $MONTHhours=0; $MONTHsales=0; + $YEARsph=0; $YEARhours=0; $YEARsales=0; + + $UDtarget[0] = ($TWOAMsec - (86400 * 0) ); # X-0 days in the past + $UDtarget[1] = ($TWOAMsec - (86400 * 1) ); # X-1 days in the past + $UDtarget[2] = ($TWOAMsec - (86400 * 2) ); # X-2 days in the past + $UDtarget[3] = ($TWOAMsec - (86400 * 3) ); # X-3 days in the past + $UDtarget[4] = ($TWOAMsec - (86400 * 4) ); # X-4 days in the past + $UDtarget[5] = ($TWOAMsec - (86400 * 5) ); # X-5 days in the past + $UDtarget[6] = ($TWOAMsec - (86400 * 6) ); # X-6 days in the past + $UDtarget[7] = ($TWOAMsec - (86400 * 7) ); # X-7 days in the past + + $prevday = $SETprevday; + + ### GO THROUGH EACH DAY THIS WEEK UP TO TODAY + while ($prevday >= 0) + { + ($Tsec,$Tmin,$Thour,$Tmday,$Tmon,$Tyear,$Twday,$Tyday,$Tisdst) = localtime($UDtarget[$j]); + $Tyear = ($Tyear + 1900); + $Tmon++; + if ($Tmon < 10) {$Tmon = "0$Tmon";} + if ($Tmday < 10) {$Tmday = "0$Tmday";} + if ($Thour < 10) {$Thour = "0$Thour";} + if ($Tmin < 10) {$Tmin = "0$Tmin";} + if ($Tsec < 10) {$Tsec = "0$Tsec";} + $enddate = "$Tyear-$Tmon-$Tmday $Thour:$Tmin:$Tsec"; + + $k = ($j + 1); + ($Tsec,$Tmin,$Thour,$Tmday,$Tmon,$Tyear,$Twday,$Tyday,$Tisdst) = localtime($UDtarget[$k]); + $Tyear = ($Tyear + 1900); + $Tmon++; + if ($Tmon < 10) {$Tmon = "0$Tmon";} + if ($Tmday < 10) {$Tmday = "0$Tmday";} + if ($Thour < 10) {$Thour = "0$Thour";} + if ($Tmin < 10) {$Tmin = "0$Tmin";} + if ($Tsec < 10) {$Tsec = "0$Tsec";} + $begindate = "$Tyear-$Tmon-$Tmday $Thour:$Tmin:$Tsec"; + + $Dsales[$prevday]=0; + $Dhours[$prevday]=0; + + $stmtA = "select sum(talk_sec+pause_sec+wait_sec+dispo_sec) from vicidial_agent_log where event_time <= '$enddate' and event_time >= '$begindate' and pause_sec<48800 and wait_sec<48800 and talk_sec<48800 and dispo_sec<48800 and user='$Duser[$i]' $SQLrestrict limit 1;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $Dhours[$prevday] = ($aryA[0]/3600); + } + + $stmtA = "select count(*) from vicidial_xfer_log vx,vicidial_closer_log vc where vx.call_date <= '$enddate' and vx.call_date >= '$begindate' and vc.status IN('A1','A2','A3','A4','SALE','UPSELL') and vx.user='$Duser[$i]' and vx.xfercallid=vc.xfercallid;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $Dsales[$prevday] = $aryA[0]; + } + + $Dhours[$prevday] = sprintf("%.2f", $Dhours[$prevday]); + $hours[$prevday] = sprintf("%5s", $Dhours[$prevday]); + $sales[$prevday] = sprintf("%5s", $Dsales[$prevday]); + if ( ($Dsales[$prevday] > 0) && ($Dhours[$prevday] > 0) ) + {$Dsph[$prevday] = ($Dsales[$prevday]/$Dhours[$prevday]);} + else + {$Dsph[$prevday] = 0;} + $Dsph[$prevday] = sprintf("%.1f", $Dsph[$prevday]); + $sph[$prevday] = sprintf("%4s", $Dsph[$prevday]); + + $GDsales[$prevday] = ($GDsales[$prevday] + $Dsales[$prevday]); + $TOTDsales[$prevday] = ($TOTDsales[$prevday] + $Dsales[$prevday]); + $GDhours[$prevday] = ($GDhours[$prevday] + $Dhours[$prevday]); + $TOTDhours[$prevday] = ($TOTDhours[$prevday] + $Dhours[$prevday]); + + $WEEKhours = ($WEEKhours + $Dhours[$prevday]); + $WEEKsales = ($WEEKsales + $Dsales[$prevday]); + + if ($DB) {print STDERR "$hours[$prevday] $sales[$prevday] $sph[$prevday] $prevday $begindate\n";} + $prevday = ($prevday - 1); + $j++; + } + + $stmtA = "select sum(talk_sec+pause_sec+wait_sec+dispo_sec) from vicidial_agent_log where event_time <= '$endmonth' and event_time >= '$beginmonth' and pause_sec<48800 and wait_sec<48800 and talk_sec<48800 and dispo_sec<48800 and user='$Duser[$i]' $SQLrestrict limit 1;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $MONTHhours = ($aryA[0]/3600); + } + + $stmtA = "select count(*) from vicidial_xfer_log vx,vicidial_closer_log vc where vx.call_date <= '$endmonth' and vx.call_date >= '$beginmonth' and vc.status IN('A1','A2','A3','A4','SALE','UPSELL') and vx.user='$Duser[$i]' and vx.xfercallid=vc.xfercallid;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $MONTHsales = $aryA[0]; + } + + if ($YTDrun>0) + { + $Ybegin='-01-01 01:00:00'; + $stmtA = "select sum(talk_sec+pause_sec+wait_sec+dispo_sec) from vicidial_agent_log where event_time <= '$endmonth' and event_time >= '$TMyear$Ybegin' and pause_sec<48800 and wait_sec<48800 and talk_sec<48800 and dispo_sec<48800 and user='$Duser[$i]' $SQLrestrict limit 1;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $YEARhours = ($aryA[0]/3600); + } + + $stmtA = "select count(*) from vicidial_xfer_log vx,vicidial_closer_log vc where vx.call_date <= '$endmonth' and vx.call_date >= '$TMyear$Ybegin' and vc.status IN('A1','A2','A3','A4','SALE','UPSELL') and vx.user='$Duser[$i]' and vx.xfercallid=vc.xfercallid;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $YEARsales = $aryA[0]; + } + + if ( ($YEARsales > 0) && ($YEARhours > 0) ) + {$YEARsph = ($YEARsales/$YEARhours);} + else + {$YEARsph = 0;} + + $GYEARsales = ($GYEARsales + $YEARsales); + $TOTYEARsales = ($TOTYEARsales + $YEARsales); + $GYEARhours = ($GYEARhours + $YEARhours); + $TOTYEARhours = ($TOTYEARhours + $YEARhours); + + $YEARhours = sprintf("%.0f", $YEARhours); + $YEARhours = sprintf("%5s", $YEARhours); + $YEARsph = sprintf("%.1f", $YEARsph); + $YEARsph = sprintf("%4s", $YEARsph); + + $YEARpipe="$YEARhours|$YEARsph|"; + $YEARfixed="$YEARhours $YEARsph "; + } + + if ( ($WEEKsales > 0) && ($WEEKhours > 0) ) + {$WEEKsph = ($WEEKsales/$WEEKhours);} + else + {$WEEKsph = 0;} + + if ( ($MONTHsales > 0) && ($MONTHhours > 0) ) + {$MONTHsph = ($MONTHsales/$MONTHhours);} + else + {$MONTHsph = 0;} + + $GMONTHsales = ($GMONTHsales + $MONTHsales); + $TOTMONTHsales = ($TOTMONTHsales + $MONTHsales); + $GMONTHhours = ($GMONTHhours + $MONTHhours); + $TOTMONTHhours = ($TOTMONTHhours + $MONTHhours); + + print Dout "$shipdate|$Dname[$i]|$Duser[$i]||$Dhours[0]|$Dsph[0]|$Dhours[1]|$Dsph[1]|$Dhours[2]|$Dsph[2]|$Dhours[3]|$Dsph[3]|$Dhours[4]|$Dsph[4]|$Dhours[5]|$Dsph[5]|$Dhours[6]|$Dsph[6]|$WEEKhours|$WEEKsph|$MONTHhours|$MONTHsph|$YEARpipe$Dgroup[$i]\n"; + + ### only print to ASCII fixed-length file if week-to-date and month-to-date hours > 0 + if ( ($WEEKhours > 0) || ($MONTHhours > 0) ) + { + $WEEKhours = sprintf("%.0f", $WEEKhours); + $WEEKhours = sprintf("%5s", $WEEKhours); + $WEEKsph = sprintf("%.1f", $WEEKsph); + $WEEKsph = sprintf("%4s", $WEEKsph); + + $MONTHhours = sprintf("%.0f", $MONTHhours); + $MONTHhours = sprintf("%5s", $MONTHhours); + $MONTHsph = sprintf("%.1f", $MONTHsph); + $MONTHsph = sprintf("%4s", $MONTHsph); + + $outline = "$name[$i] $user[$i] $hours[0] $sph[0] $hours[1] $sph[1] $hours[2] $sph[2] $hours[3] $sph[3] $hours[4] $sph[4] $hours[5] $sph[5] $hours[6] $sph[6] $WEEKhours $WEEKsph $MONTHhours $MONTHsph $YEARfixed$group[$i]\n"; + print "$outline"; + print out "$outline"; + } + else + { + print "SKIPPED: $name[$i] $user[$i] $WEEKhours $MONTHhours\n"; + } + + $Dprevgroup = $Dgroup[$i]; + $prevgroup = $group[$i]; + $i++; + + ### BEGIN GROUP SUMMARY STATS + if ($Dgroup[$i] !~ /^$Dprevgroup$/) + { + $prevday = $SETprevday; + + ### GO THROUGH EACH DAY THIS WEEK UP TO TODAY + while ($prevday >= 0) + { + $GDhours[$prevday] = sprintf("%.2f", $GDhours[$prevday]); + $Ghours[$prevday] = sprintf("%5s", $GDhours[$prevday]); while(length($Ghours[$prevday])>5) {chop($Ghours[$prevday]);} + $Gsales[$prevday] = sprintf("%5s", $GDsales[$prevday]); + if ( ($GDsales[$prevday] > 0) && ($GDhours[$prevday] > 0) ) + {$GDsph[$prevday] = ($GDsales[$prevday]/$GDhours[$prevday]);} + else + {$GDsph[$prevday] = 0;} + $GDsph[$prevday] = sprintf("%.1f", $GDsph[$prevday]); + $Gsph[$prevday] = sprintf("%4s", $GDsph[$prevday]); + + $GWEEKhours = ($GWEEKhours + $GDhours[$prevday]); + $GWEEKsales = ($GWEEKsales + $GDsales[$prevday]); + + $prevday = ($prevday - 1); + } + + if ( ($GWEEKsales > 0) && ($GWEEKhours > 0) ) + {$GWEEKsph = ($GWEEKsales/$GWEEKhours);} + else + {$GWEEKsph = 0;} + + if ( ($GMONTHsales > 0) && ($GMONTHhours > 0) ) + {$GMONTHsph = ($GMONTHsales/$GMONTHhours);} + else + {$GMONTHsph = 0;} + + if ($YTDrun>0) + { + if ( ($GYEARsales > 0) && ($GYEARhours > 0) ) + {$GYEARsph = ($GYEARsales/$GYEARhours);} + else + {$GYEARsph = 0;} + + $GYEARhours = sprintf("%.0f", $GYEARhours); + $GYEARhours = sprintf("%5s", $GYEARhours); while(length($GYEARhours)>5) {chop($GYEARhours);} + $GYEARsph = sprintf("%.1f", $GYEARsph); + $GYEARsph = sprintf("%4s", $GYEARsph); + + $YEARgpipe="$GYEARhours|$GYEARsph|"; + $YEARgfixed=" $GYEARhours $GYEARsph"; + } + + print Dout "$shipdate|TOTAL $Dprevgroup|||$GDhours[0]|$GDsph[0]|$GDhours[1]|$GDsph[1]|$GDhours[2]|$GDsph[2]|$GDhours[3]|$GDsph[3]|$GDhours[4]|$GDsph[4]|$GDhours[5]|$GDsph[5]|$GDhours[6]|$GDsph[6]|$GWEEKhours|$GWEEKsph|$GMONTHhours|$GMONTHsph|$YEARgpipe\n"; + + $GWEEKhours = sprintf("%.0f", $GWEEKhours); + $GWEEKhours = sprintf("%5s", $GWEEKhours); while(length($GWEEKhours)>5) {chop($GWEEKhours);} + $GWEEKsph = sprintf("%.1f", $GWEEKsph); + $GWEEKsph = sprintf("%4s", $GWEEKsph); + + $GMONTHhours = sprintf("%.0f", $GMONTHhours); + $GMONTHhours = sprintf("%5s", $GMONTHhours); while(length($GMONTHhours)>5) {chop($GMONTHhours);} + $GMONTHsph = sprintf("%.1f", $GMONTHsph); + $GMONTHsph = sprintf("%4s", $GMONTHsph); + + $outline = " GROUP TOTAL $prevgroup $Ghours[0] $Gsph[0] $Ghours[1] $Gsph[1] $Ghours[2] $Gsph[2] $Ghours[3] $Gsph[3] $Ghours[4] $Gsph[4] $Ghours[5] $Gsph[5] $Ghours[6] $Gsph[6] $GWEEKhours $GWEEKsph $GMONTHhours $GMONTHsph$YEARgfixed\n\n"; + print "$outline"; + print out "$outline"; + + $Gsph[0]=' 0'; $Gsph[1]=' 0'; $Gsph[2]=' 0'; $Gsph[3]=' 0'; $Gsph[4]=' 0'; $Gsph[5]=' 0'; $Gsph[6]=' 0'; + $Gsales[0]=0; $Gsales[1]=0; $Gsales[2]=0; $Gsales[3]=0; $Gsales[4]=0; $Gsales[5]=0; $Gsales[6]=0; + $Ghours[0]=' 0.0'; $Ghours[1]=' 0.0'; $Ghours[2]=' 0.0'; $Ghours[3]=' 0.0'; $Ghours[4]=' 0.0'; $Ghours[5]=' 0.0'; $Ghours[6]=' 0.0'; + $GDsph[0]=0; $GDsph[1]=0; $GDsph[2]=0; $GDsph[3]=0; $GDsph[4]=0; $GDsph[5]=0; $GDsph[6]=0; + $GDsales[0]=0; $GDsales[1]=0; $GDsales[2]=0; $GDsales[3]=0; $GDsales[4]=0; $GDsales[5]=0; $GDsales[6]=0; + $GDhours[0]=0; $GDhours[1]=0; $GDhours[2]=0; $GDhours[3]=0; $GDhours[4]=0; $GDhours[5]=0; $GDhours[6]=0; + $GWEEKsph=0; $GWEEKhours=0; $GWEEKsales=0; + $GMONTHsph=0; $GMONTHhours=0; $GMONTHsales=0; + $GYEARsph=0; $GYEARhours=0; $GYEARsales=0; + } + } + ### END AGENT STATS + + +### BEGIN TOTAL STATS + + +$prevday = $SETprevday; + +### GO THROUGH EACH DAY THIS WEEK UP TO TODAY +while ($prevday >= 0) + { + $TOTDhours[$prevday] = sprintf("%.0f", $TOTDhours[$prevday]); + $TOThours[$prevday] = sprintf("%5s", $TOTDhours[$prevday]); while(length($TOThours[$prevday])>5) {chop($TOThours[$prevday]);} + $TOTsales[$prevday] = sprintf("%5s", $TOTDsales[$prevday]); + if ( ($TOTDsales[$prevday] > 0) && ($TOTDhours[$prevday] > 0) ) + {$TOTDsph[$prevday] = ($TOTDsales[$prevday]/$TOTDhours[$prevday]);} + else + {$TOTDsph[$prevday] = 0;} + $TOTDsph[$prevday] = sprintf("%.1f", $TOTDsph[$prevday]); + $TOTsph[$prevday] = sprintf("%4s", $TOTDsph[$prevday]); + + $TOTWEEKhours = ($TOTWEEKhours + $TOTDhours[$prevday]); + $TOTWEEKsales = ($TOTWEEKsales + $TOTDsales[$prevday]); + + $prevday = ($prevday - 1); + } + +if ( ($TOTWEEKsales > 0) && ($TOTWEEKhours > 0) ) + {$TOTWEEKsph = ($TOTWEEKsales/$TOTWEEKhours);} +else + {$TOTWEEKsph = 0;} + +if ( ($TOTMONTHsales > 0) && ($TOTMONTHhours > 0) ) + {$TOTMONTHsph = ($TOTMONTHsales/$TOTMONTHhours);} +else + {$TOTMONTHsph = 0;} + + if ($YTDrun>0) + { + if ( ($TOTMONTHsales > 0) && ($TOTMONTHhours > 0) ) + {$TOTMONTHsph = ($TOTMONTHsales/$TOTMONTHhours);} + else + {$TOTMONTHsph = 0;} + + $TOTYEARhours = sprintf("%.0f", $TOTYEARhours); + $TOTYEARhours = sprintf("%5s", $TOTYEARhours); while(length($TOTYEARhours)>5) {chop($TOTYEARhours);} + $TOTYEARsph = sprintf("%.1f", $TOTYEARsph); + $TOTYEARsph = sprintf("%4s", $TOTYEARsph); + + $YEARtpipe="$TOTYEARhours|$TOTYEARsph|"; + $YEARtfixed=" $TOTYEARhours $TOTYEARsph"; + } + +print Dout "$shipdate|TOTAL|||$TOTDhours[0]|$TOTDsph[0]|$TOTDhours[1]|$TOTDsph[1]|$TOTDhours[2]|$TOTDsph[2]|$TOTDhours[3]|$TOTDsph[3]|$TOTDhours[4]|$TOTDsph[4]|$TOTDhours[5]|$TOTDsph[5]|$TOTDhours[6]|$TOTDsph[6]|$TOTWEEKhours|$TOTWEEKsph|$TOTMONTHhours|$TOTMONTHsph|$YEARtpipe\n"; + + $TOTWEEKhours = sprintf("%.0f", $TOTWEEKhours); + $TOTWEEKhours = sprintf("%5s", $TOTWEEKhours); while(length($TOTWEEKhours)>5) {chop($TOTWEEKhours);} + $TOTWEEKsph = sprintf("%.1f", $TOTWEEKsph); + $TOTWEEKsph = sprintf("%4s", $TOTWEEKsph); + + $TOTMONTHhours = sprintf("%.0f", $TOTMONTHhours); + $TOTMONTHhours = sprintf("%5s", $TOTMONTHhours); while(length($TOTMONTHhours)>5) {chop($TOTMONTHhours);} + $TOTMONTHsph = sprintf("%.1f", $TOTMONTHsph); + $TOTMONTHsph = sprintf("%4s", $TOTMONTHsph); + +$outline = " TOTAL $TOThours[0] $TOTsph[0] $TOThours[1] $TOTsph[1] $TOThours[2] $TOTsph[2] $TOThours[3] $TOTsph[3] $TOThours[4] $TOTsph[4] $TOThours[5] $TOTsph[5] $TOThours[6] $TOTsph[6] $TOTWEEKhours $TOTWEEKsph $TOTMONTHhours $TOTMONTHsph$YEARtfixed\n"; +print "$outline"; +print out "$outline"; + + +exit; + + + + + + + ### TOTAL ACTIVE TIME + $active = ($aryA[3] + $aryA[4] + $aryA[5] + $aryA[6]); + $TIME_S = $active; + $TIME_H = int($TIME_S / 3600); + $TIME_S = ($TIME_S - ($TIME_H * 3600)); + $TIME_M = int($TIME_S / 60); + $TIME_S = ($TIME_S - ($TIME_M * 60)); + if ($TIME_S < 10) {$TIME_S = "0$TIME_S";} + if ($TIME_M < 10) {$TIME_M = "0$TIME_M";} + $TIME_HMS = "$TIME_H:$TIME_M:$TIME_S"; + $Dactive = $TIME_HMS; + $active = sprintf("%9s", $TIME_HMS); + + ### TOTAL TALK TIME + $TIME_S = $aryA[3]; + $TIME_H = int($TIME_S / 3600); + $TIME_S = ($TIME_S - ($TIME_H * 3600)); + $TIME_M = int($TIME_S / 60); + $TIME_S = ($TIME_S - ($TIME_M * 60)); + if ($TIME_S < 10) {$TIME_S = "0$TIME_S";} + if ($TIME_M < 10) {$TIME_M = "0$TIME_M";} + $TIME_HMS = "$TIME_H:$TIME_M:$TIME_S"; + $Dtalk = $TIME_HMS; + $talk = sprintf("%9s", $TIME_HMS); + + ### TOTAL PAUSE TIME + $TIME_S = $aryA[4]; + $TIME_H = int($TIME_S / 3600); + $TIME_S = ($TIME_S - ($TIME_H * 3600)); + $TIME_M = int($TIME_S / 60); + $TIME_S = ($TIME_S - ($TIME_M * 60)); + if ($TIME_S < 10) {$TIME_S = "0$TIME_S";} + if ($TIME_M < 10) {$TIME_M = "0$TIME_M";} + $TIME_HMS = "$TIME_H:$TIME_M:$TIME_S"; + $Dpause = $TIME_HMS; + $pause = sprintf("%9s", $TIME_HMS); + + ### TOTAL WAIT TIME + $TIME_S = $aryA[5]; + $TIME_H = int($TIME_S / 3600); + $TIME_S = ($TIME_S - ($TIME_H * 3600)); + $TIME_M = int($TIME_S / 60); + $TIME_S = ($TIME_S - ($TIME_M * 60)); + if ($TIME_S < 10) {$TIME_S = "0$TIME_S";} + if ($TIME_M < 10) {$TIME_M = "0$TIME_M";} + $TIME_HMS = "$TIME_H:$TIME_M:$TIME_S"; + $Dwait = $TIME_HMS; + $wait = sprintf("%9s", $TIME_HMS); + + ### TOTAL DISPO TIME + $TIME_S = $aryA[6]; + $TIME_H = int($TIME_S / 3600); + $TIME_S = ($TIME_S - ($TIME_H * 3600)); + $TIME_M = int($TIME_S / 60); + $TIME_S = ($TIME_S - ($TIME_M * 60)); + if ($TIME_S < 10) {$TIME_S = "0$TIME_S";} + if ($TIME_M < 10) {$TIME_M = "0$TIME_M";} + $TIME_HMS = "$TIME_H:$TIME_M:$TIME_S"; + $Ddispo = $TIME_HMS; + $dispo = sprintf("%9s", $TIME_HMS); + + $stmtB = "select event_time,UNIX_TIMESTAMP(event_time) from $vicidial_agent_log where event_time <= '$shipdate 23:59:59' and event_time >= '$begindate 00:00:00' and user='$aryA[2]' order by event_time limit 1;"; + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtA ", $dbhB->errstr; + @aryB = $sthB->fetchrow_array; + $Dfirst_time = $aryB[0]; + $first_time = sprintf("%21s", $aryB[0]); + $Dfirst_log = $aryB[1]; + $first_log = $aryB[1]; + + $stmtB = "select event_time,UNIX_TIMESTAMP(event_time) from $vicidial_agent_log where event_time <= '$shipdate 23:59:59' and event_time >= '$begindate 00:00:00' and user='$aryA[2]' order by event_time desc limit 1;"; + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtA ", $dbhB->errstr; + @aryB = $sthB->fetchrow_array; + $Dlast_time = $aryB[0]; + $last_time = sprintf("%21s", $aryB[0]); + $Dlast_log = $aryB[1]; + $last_log = $aryB[1]; + + $TIME_S = ($last_log - $first_log); + $TIME_H = int($TIME_S / 3600); + $TIME_S = ($TIME_S - ($TIME_H * 3600)); + $TIME_M = int($TIME_S / 60); + $TIME_S = ($TIME_S - ($TIME_M * 60)); + if ($TIME_S < 10) {$TIME_S = "0$TIME_S";} + if ($TIME_M < 10) {$TIME_M = "0$TIME_M";} + $TIME_HMS = "$TIME_H:$TIME_M:$TIME_S"; + $TIME_HMS = "N/A"; + $Dlogin_time = $TIME_HMS; + $login_time = sprintf("%9s", $TIME_HMS); + + + + print Dout "$shipdate|$Dname|$Duser|$Dcalls|$Dtalk|$Dpause|$Dwait|$Ddispo|$Dactive|$Dlogin_time|$Dfirst_time|$Dlast_time\n"; + print out "$name$user$calls$talk$pause$wait$dispo$active$login_time$first_time$last_time\n"; + print "$name$user$calls$talk$pause$wait$dispo$active$login_time$first_time$last_time\n"; + + + +close(Dout); +close(out); + +### calculate time to run script ### +$secY = time(); +$secZ = ($secY - $secX); +$secZm = ($secZ /60); + +print "script execution time in seconds: $secZ minutes: $secZm\n"; + +exit; + + + + + diff --git a/bin/AST_agent_daily_SPHfront.pl b/bin/AST_agent_daily_SPHfront.pl new file mode 100644 index 00000000..cc77c38a --- /dev/null +++ b/bin/AST_agent_daily_SPHfront.pl @@ -0,0 +1,662 @@ +#!/usr/bin/perl + +# AST_agent_daily_SPH.pl +# +# This script is designed to gather stats for all agent activity over the course +# of a week and print it in an ASCI text file to be placed +# on a web server for viewing. +# +# This script assumes a work day to be from 2AM to 2AM +# +# Place in the crontab and run every night at 02:00AM for the previous day's stats +# 0 2 * * * /home/cron/AST_agent_daily_SPH.pl +# +# CHANGES +# 80114-1221 - First version +# 80116-0941 - only print agents with week and month hours of 0 to PIPE file +# + +$txt = '.txt'; +$US = '_'; +$MT[0] = ''; + +### begin parsing run-time options ### +if (length($ARGV[0])>1) +{ + $i=0; + while ($#ARGV >= $i) + { + $args = "$args $ARGV[$i]"; + $i++; + } + + if ($args =~ /--help/i) + { + print "allowed run time options:\n [-q] = quiet\n [-t] = test\n\n"; + exit; + } + else + { + if ($args =~ /--debug/i) + { + $DB=1; + print "\n-----DEBUG MODE-----\n\n"; + } + if ($args =~ /-q/i) + { + $q=1; $Q=1; + } + if ($args =~ /-t/i) + { + $T=1; $TEST=1; + print "\n-----TESTING-----\n\n"; + } + } +} +else +{ +print "no command line options set\n"; +} +### end parsing run-time options ### + + +$secX = time(); + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + $year = ($year + 1900); + $mon++; + if ($mon < 10) {$mon = "0$mon";} + if ($mday < 10) {$mday = "0$mday";} + if ($hour < 10) {$hour = "0$hour";} + if ($min < 10) {$min = "0$min";} + if ($sec < 10) {$sec = "0$sec";} + $filedate = "$year$mon$mday-$hour$min$sec"; + $ABIfiledate = "$mon-$mday-$year$us$hour$min$sec"; + $shipdate = "$year-$mon-$mday"; + $datestamp = "$year/$mon/$mday $hour:$min"; + +use Time::Local; + +### find epoch of 2AM today +$TWOAMsec = ( ($secX - ($sec + ($min * 60) + ($hour * 3600) ) ) + 7200); +### find epoch of 2AM yesterday +$TWOAMsecY = ($TWOAMsec - 86400); + +($Tsec,$Tmin,$Thour,$Tmday,$Tmon,$Tyear,$Twday,$Tyday,$Tisdst) = localtime($TWOAMsecY); +$Tyear = ($Tyear + 1900); +$Tmon++; +if ($Tmon < 10) {$Tmon = "0$Tmon";} +if ($Tmday < 10) {$Tmday = "0$Tmday";} +if ($Thour < 10) {$Thour = "0$Thour";} +if ($Tmin < 10) {$Tmin = "0$Tmin";} +if ($Tsec < 10) {$Tsec = "0$Tsec";} + $begindate = "$Tyear-$Tmon-$Tmday $Thour:$Tmin:$Tsec"; + +### find epoch of 2AM the first day of the month +$BMONTHsec = ($TWOAMsecY - (86400 * ($Tmday - 1) ) ); +### find epoch of 2AM the first day of next month +if ($Tmon>11) {$Tmon=0; $Tyear++;} +$EMONTHsec = timelocal($Tsec,$Tmin,$Thour,1,$Tmon,$Tyear); + + if ($Twday==0) {$day='Sunday '; $SETprevday = 6;} + if ($Twday==1) {$day='Monday '; $SETprevday = 0;} + if ($Twday==2) {$day='Tuesday '; $SETprevday = 1;} + if ($Twday==3) {$day='Wednesday'; $SETprevday = 2;} + if ($Twday==4) {$day='Thursday '; $SETprevday = 3;} + if ($Twday==5) {$day='Friday '; $SETprevday = 4;} + if ($Twday==6) {$day='Saturday '; $SETprevday = 5;} + +($TMsec,$TMmin,$TMhour,$TMmday,$TMmon,$TMyear,$TMwday,$TMyday,$TMisdst) = localtime($BMONTHsec); +$TMyear = ($TMyear + 1900); +$TMmon++; +if ($TMmon < 10) {$TMmon = "0$TMmon";} +if ($TMmday < 10) {$TMmday = "0$TMmday";} +if ($TMhour < 10) {$TMhour = "0$TMhour";} +if ($TMmin < 10) {$TMmin = "0$TMmin";} +if ($TMsec < 10) {$TMsec = "0$TMsec";} + $beginmonth = "$TMyear-$TMmon-$TMmday $TMhour:$TMmin:$TMsec"; + +($TMsec,$TMmin,$TMhour,$TMmday,$TMmon,$TMyear,$TMwday,$TMyday,$TMisdst) = localtime($EMONTHsec); +$TMyear = ($TMyear + 1900); +$TMmon++; +if ($TMmon < 10) {$TMmon = "0$TMmon";} +if ($TMmday < 10) {$TMmday = "0$TMmday";} +if ($TMhour < 10) {$TMhour = "0$TMhour";} +if ($TMmin < 10) {$TMmin = "0$TMmin";} +if ($TMsec < 10) {$TMsec = "0$TMsec";} + $endmonth = "$TMyear-$TMmon-$TMmday $TMhour:$TMmin:$TMsec"; + +#print "|$ABIfiledate|$begindate|$beginmonth|$endmonth|\n"; +#exit; + +print "\n\n\n\n\n\n\n\n\n\n\n\n-- AST_agent_daily_SPH.pl --\n\n"; +print "This program is designed to print sales-per-hour(SPH) to a file for agents' activity for the current week. \n\n"; + + +# 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 =~ /^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;} + $i++; + } + +# Customized Variables +$server_ip = $VARserver_ip; # Asterisk server IP + +$outfile = "AGENT_SPH_$Tyear-$Tmon-$Tmday$txt"; +$Doutfile = "AGENT_SPH_PIPE_$Tyear-$Tmon-$Tmday$txt"; + +### open the X out file for writing ### +open(out, ">$PATHweb/vicidial/agent_reports/$outfile") + || die "Can't open $outfile: $!\n"; +open(Dout, ">$PATHweb/vicidial/agent_reports/$Doutfile") + || die "Can't open $Doutfile: $!\n"; + +if (!$VARDB_port) {$VARDB_port='3306';} + + +use DBI; + +$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; + +#$vicidial_agent_log = 'vicidial_agent_log_archive'; +$vicidial_agent_log = 'vicidial_agent_log'; + +########################################################################### +########### PAST WEEK STAT GATHERING LOOP ################################# +########################################################################### +print Dout "DATE|AGENT|USER|MON HOURS|MON SPH|TUE HOURS|TUE SPH|WED HOURS|WED SPH|THU HOURS|THU SPH|FRI HOURS|FRI SPH|SAT HOURS|SAT SPH|SUN HOURS|SUN SPH|WEEK HOURS|WEEK SPH|MONTH HOURS|MONTH SPH|GROUP|\n"; +$outline = "REPORT: SPH $Tyear-$Tmon-$Tmday\n\n"; +$outline.= " MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY WEEK MONTH\n"; +$outline.= "AGENT USER HRS SPH HRS SPH HRS SPH HRS SPH HRS SPH HRS SPH HRS SPH HRS SPH HRS SPH GROUP \n"; +print "$outline"; +print out "$outline"; + +### FIND ALL ACTIVE USERS IN THE SYSTEM IN('1090','1102','1245')='1090' +$stmtA = "select full_name,user,user_group from vicidial_users order by user_group,full_name limit 1000;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; +$rec_count=0; +while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + + $Dname[$rec_count] = $aryA[0]; + $Duser[$rec_count] = $aryA[1]; + $Dgroup[$rec_count] = $aryA[2]; + $name[$rec_count] = sprintf("%-20s", $aryA[0]); while(length($name[$rec_count])>20) {chop($name[$rec_count]);} + $user[$rec_count] = sprintf("%-8s", $aryA[1]); + $group[$rec_count] = sprintf("%-8s", $aryA[2]); + + $rec_count++; + } +$sthA->finish(); + + +$Gsph[0]=' 0'; $Gsph[1]=' 0'; $Gsph[2]=' 0'; $Gsph[3]=' 0'; $Gsph[4]=' 0'; $Gsph[5]=' 0'; $Gsph[6]=' 0'; +$Gsales[0]=0; $Gsales[1]=0; $Gsales[2]=0; $Gsales[3]=0; $Gsales[4]=0; $Gsales[5]=0; $Gsales[6]=0; +$Ghours[0]=' 0.0'; $Ghours[1]=' 0.0'; $Ghours[2]=' 0.0'; $Ghours[3]=' 0.0'; $Ghours[4]=' 0.0'; $Ghours[5]=' 0.0'; $Ghours[6]=' 0.0'; +$GDsph[0]=0; $GDsph[1]=0; $GDsph[2]=0; $GDsph[3]=0; $GDsph[4]=0; $GDsph[5]=0; $GDsph[6]=0; +$GDsales[0]=0; $GDsales[1]=0; $GDsales[2]=0; $GDsales[3]=0; $GDsales[4]=0; $GDsales[5]=0; $GDsales[6]=0; +$GDhours[0]=0; $GDhours[1]=0; $GDhours[2]=0; $GDhours[3]=0; $GDhours[4]=0; $GDhours[5]=0; $GDhours[6]=0; +$GWEEKsph=0; $GWEEKhours=0; $GWEEKsales=0; +$GMONTHsph=0; $GMONTHhours=0; $GMONTHsales=0; + +$TOTsph[0]=' 0'; $TOTsph[1]=' 0'; $TOTsph[2]=' 0'; $TOTsph[3]=' 0'; $TOTsph[4]=' 0'; $TOTsph[5]=' 0'; $TOTsph[6]=' 0'; +$TOTsales[0]=0; $TOTsales[1]=0; $TOTsales[2]=0; $TOTsales[3]=0; $TOTsales[4]=0; $TOTsales[5]=0; $TOTsales[6]=0; +$TOThours[0]=' 0.0'; $TOThours[1]=' 0.0'; $TOThours[2]=' 0.0'; $TOThours[3]=' 0.0'; $TOThours[4]=' 0.0'; $TOThours[5]=' 0.0'; $TOThours[6]=' 0.0'; +$TOTDsph[0]=0; $TOTDsph[1]=0; $TOTDsph[2]=0; $TOTDsph[3]=0; $TOTDsph[4]=0; $TOTDsph[5]=0; $TOTDsph[6]=0; +$TOTDsales[0]=0; $TOTDsales[1]=0; $TOTDsales[2]=0; $TOTDsales[3]=0; $TOTDsales[4]=0; $TOTDsales[5]=0; $TOTDsales[6]=0; +$TOTDhours[0]=0; $TOTDhours[1]=0; $TOTDhours[2]=0; $TOTDhours[3]=0; $TOTDhours[4]=0; $TOTDhours[5]=0; $TOTDhours[6]=0; +$TOTWEEKsph=0; $TOTWEEKhours=0; $TOTWEEKsales=0; +$TOTMONTHsph=0; $TOTMONTHhours=0; $TOTMONTHsales=0; + + +### GO THROUGH EACH USER ACCOUNT AND FIND OUT THE HOURS AND SPH +$i=0; +foreach (@Duser) + { + $j=0; + $sph[0]=' 0'; $sph[1]=' 0'; $sph[2]=' 0'; $sph[3]=' 0'; $sph[4]=' 0'; $sph[5]=' 0'; $sph[6]=' 0'; + $sales[0]=0; $sales[1]=0; $sales[2]=0; $sales[3]=0; $sales[4]=0; $sales[5]=0; $sales[6]=0; + $hours[0]=' 0.0'; $hours[1]=' 0.0'; $hours[2]=' 0.0'; $hours[3]=' 0.0'; $hours[4]=' 0.0'; $hours[5]=' 0.0'; $hours[6]=' 0.0'; + $Dsph[0]=0; $Dsph[1]=0; $Dsph[2]=0; $Dsph[3]=0; $Dsph[4]=0; $Dsph[5]=0; $Dsph[6]=0; + $Dsales[0]=0; $Dsales[1]=0; $Dsales[2]=0; $Dsales[3]=0; $Dsales[4]=0; $Dsales[5]=0; $Dsales[6]=0; + $Dhours[0]=0; $Dhours[1]=0; $Dhours[2]=0; $Dhours[3]=0; $Dhours[4]=0; $Dhours[5]=0; $Dhours[6]=0; + $WEEKsph=0; $WEEKhours=0; $WEEKsales=0; + $MONTHsph=0; $MONTHhours=0; $MONTHsales=0; + + $UDtarget[0] = ($TWOAMsec - (86400 * 0) ); # X-0 days in the past + $UDtarget[1] = ($TWOAMsec - (86400 * 1) ); # X-1 days in the past + $UDtarget[2] = ($TWOAMsec - (86400 * 2) ); # X-2 days in the past + $UDtarget[3] = ($TWOAMsec - (86400 * 3) ); # X-3 days in the past + $UDtarget[4] = ($TWOAMsec - (86400 * 4) ); # X-4 days in the past + $UDtarget[5] = ($TWOAMsec - (86400 * 5) ); # X-5 days in the past + $UDtarget[6] = ($TWOAMsec - (86400 * 6) ); # X-6 days in the past + $UDtarget[7] = ($TWOAMsec - (86400 * 7) ); # X-7 days in the past + + $prevday = $SETprevday; + + ### GO THROUGH EACH DAY THIS WEEK UP TO TODAY + while ($prevday >= 0) + { + ($Tsec,$Tmin,$Thour,$Tmday,$Tmon,$Tyear,$Twday,$Tyday,$Tisdst) = localtime($UDtarget[$j]); + $Tyear = ($Tyear + 1900); + $Tmon++; + if ($Tmon < 10) {$Tmon = "0$Tmon";} + if ($Tmday < 10) {$Tmday = "0$Tmday";} + if ($Thour < 10) {$Thour = "0$Thour";} + if ($Tmin < 10) {$Tmin = "0$Tmin";} + if ($Tsec < 10) {$Tsec = "0$Tsec";} + $enddate = "$Tyear-$Tmon-$Tmday $Thour:$Tmin:$Tsec"; + + $k = ($j + 1); + ($Tsec,$Tmin,$Thour,$Tmday,$Tmon,$Tyear,$Twday,$Tyday,$Tisdst) = localtime($UDtarget[$k]); + $Tyear = ($Tyear + 1900); + $Tmon++; + if ($Tmon < 10) {$Tmon = "0$Tmon";} + if ($Tmday < 10) {$Tmday = "0$Tmday";} + if ($Thour < 10) {$Thour = "0$Thour";} + if ($Tmin < 10) {$Tmin = "0$Tmin";} + if ($Tsec < 10) {$Tsec = "0$Tsec";} + $begindate = "$Tyear-$Tmon-$Tmday $Thour:$Tmin:$Tsec"; + + $Dsales[$prevday]=0; + $Dhours[$prevday]=0; + + $stmtA = "select sum(talk_sec+pause_sec+wait_sec+dispo_sec) from vicidial_agent_log where event_time <= '$enddate' and event_time >= '$begindate' and pause_sec<48800 and wait_sec<48800 and talk_sec<48800 and dispo_sec<48800 and user='$Duser[$i]' limit 1;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $Dhours[$prevday] = ($aryA[0]/3600); + } + + $stmtA = "select count(*) from vicidial_log where call_date <= '$enddate' and call_date >= '$begindate' and status IN('A1','A2','A3','A4','SALE','UPSELL') and user='$Duser[$i]';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $Dsales[$prevday] = $aryA[0]; + } + + $Dhours[$prevday] = sprintf("%.2f", $Dhours[$prevday]); + $hours[$prevday] = sprintf("%5s", $Dhours[$prevday]); + $sales[$prevday] = sprintf("%5s", $Dsales[$prevday]); + if ( ($Dsales[$prevday] > 0) && ($Dhours[$prevday] > 0) ) + {$Dsph[$prevday] = ($Dsales[$prevday]/$Dhours[$prevday]);} + else + {$Dsph[$prevday] = 0;} + $Dsph[$prevday] = sprintf("%.1f", $Dsph[$prevday]); + $sph[$prevday] = sprintf("%4s", $Dsph[$prevday]); + + $GDsales[$prevday] = ($GDsales[$prevday] + $Dsales[$prevday]); + $TOTDsales[$prevday] = ($TOTDsales[$prevday] + $Dsales[$prevday]); + $GDhours[$prevday] = ($GDhours[$prevday] + $Dhours[$prevday]); + $TOTDhours[$prevday] = ($TOTDhours[$prevday] + $Dhours[$prevday]); + + $WEEKhours = ($WEEKhours + $Dhours[$prevday]); + $WEEKsales = ($WEEKsales + $Dsales[$prevday]); + + if ($DB) {print STDERR "$hours[$prevday] $sales[$prevday] $sph[$prevday] $prevday $begindate\n";} + $prevday = ($prevday - 1); + $j++; + } + + $stmtA = "select sum(talk_sec+pause_sec+wait_sec+dispo_sec) from vicidial_agent_log where event_time <= '$endmonth' and event_time >= '$beginmonth' and pause_sec<48800 and wait_sec<48800 and talk_sec<48800 and dispo_sec<48800 and user='$Duser[$i]' limit 1;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $MONTHhours = ($aryA[0]/3600); + } + + $stmtA = "select count(*) from vicidial_log where call_date <= '$endmonth' and call_date >= '$beginmonth' and status IN('A1','A2','A3','A4','SALE','UPSELL') and user='$Duser[$i]';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $MONTHsales = $aryA[0]; + } + + if ( ($WEEKsales > 0) && ($WEEKhours > 0) ) + {$WEEKsph = ($WEEKsales/$WEEKhours);} + else + {$WEEKsph = 0;} + + if ( ($MONTHsales > 0) && ($MONTHhours > 0) ) + {$MONTHsph = ($MONTHsales/$MONTHhours);} + else + {$MONTHsph = 0;} + + $GMONTHsales = ($GMONTHsales + $MONTHsales); + $TOTMONTHsales = ($TOTMONTHsales + $MONTHsales); + $GMONTHhours = ($GMONTHhours + $MONTHhours); + $TOTMONTHhours = ($TOTMONTHhours + $MONTHhours); + + print Dout "$shipdate|$Dname[$i]|$Duser[$i]||$Dhours[0]|$Dsph[0]|$Dhours[1]|$Dsph[1]|$Dhours[2]|$Dsph[2]|$Dhours[3]|$Dsph[3]|$Dhours[4]|$Dsph[4]|$Dhours[5]|$Dsph[5]|$Dhours[6]|$Dsph[6]|$WEEKhours|$WEEKsph|$MONTHhours|$MONTHsph|$Dgroup[$i]\n"; + + ### only print to ASCII fixed-length file if week-to-date and month-to-date hours > 0 + if ( ($WEEKhours > 0) || ($MONTHhours > 0) ) + { + $WEEKhours = sprintf("%.0f", $WEEKhours); + $WEEKhours = sprintf("%5s", $WEEKhours); + $WEEKsph = sprintf("%.1f", $WEEKsph); + $WEEKsph = sprintf("%4s", $WEEKsph); + + $MONTHhours = sprintf("%.0f", $MONTHhours); + $MONTHhours = sprintf("%5s", $MONTHhours); + $MONTHsph = sprintf("%.1f", $MONTHsph); + $MONTHsph = sprintf("%4s", $MONTHsph); + + $outline = "$name[$i] $user[$i] $hours[0] $sph[0] $hours[1] $sph[1] $hours[2] $sph[2] $hours[3] $sph[3] $hours[4] $sph[4] $hours[5] $sph[5] $hours[6] $sph[6] $WEEKhours $WEEKsph $MONTHhours $MONTHsph $group[$i]\n"; + print "$outline"; + print out "$outline"; + } + else + { + print "SKIPPED: $name[$i] $user[$i] $WEEKhours $MONTHhours\n"; + } + + $Dprevgroup = $Dgroup[$i]; + $prevgroup = $group[$i]; + $i++; + + ### BEGIN GROUP SUMMARY STATS + if ($Dgroup[$i] !~ /^$Dprevgroup$/) + { + $prevday = $SETprevday; + + ### GO THROUGH EACH DAY THIS WEEK UP TO TODAY + while ($prevday >= 0) + { + $GDhours[$prevday] = sprintf("%.2f", $GDhours[$prevday]); + $Ghours[$prevday] = sprintf("%5s", $GDhours[$prevday]); while(length($Ghours[$prevday])>5) {chop($Ghours[$prevday]);} + $Gsales[$prevday] = sprintf("%5s", $GDsales[$prevday]); + if ( ($GDsales[$prevday] > 0) && ($GDhours[$prevday] > 0) ) + {$GDsph[$prevday] = ($GDsales[$prevday]/$GDhours[$prevday]);} + else + {$GDsph[$prevday] = 0;} + $GDsph[$prevday] = sprintf("%.1f", $GDsph[$prevday]); + $Gsph[$prevday] = sprintf("%4s", $GDsph[$prevday]); + + $GWEEKhours = ($GWEEKhours + $GDhours[$prevday]); + $GWEEKsales = ($GWEEKsales + $GDsales[$prevday]); + + $prevday = ($prevday - 1); + } + + if ( ($GWEEKsales > 0) && ($GWEEKhours > 0) ) + {$GWEEKsph = ($GWEEKsales/$GWEEKhours);} + else + {$GWEEKsph = 0;} + + if ( ($GMONTHsales > 0) && ($GMONTHhours > 0) ) + {$GMONTHsph = ($GMONTHsales/$GMONTHhours);} + else + {$GMONTHsph = 0;} + + print Dout "$shipdate|TOTAL $Dprevgroup|||$GDhours[0]|$GDsph[0]|$GDhours[1]|$GDsph[1]|$GDhours[2]|$GDsph[2]|$GDhours[3]|$GDsph[3]|$GDhours[4]|$GDsph[4]|$GDhours[5]|$GDsph[5]|$GDhours[6]|$GDsph[6]|$GWEEKhours|$GWEEKsph|$GMONTHhours|$GMONTHsph|\n"; + + $GWEEKhours = sprintf("%.0f", $GWEEKhours); + $GWEEKhours = sprintf("%5s", $GWEEKhours); while(length($GWEEKhours)>5) {chop($GWEEKhours);} + $GWEEKsph = sprintf("%.1f", $GWEEKsph); + $GWEEKsph = sprintf("%4s", $GWEEKsph); + + $GMONTHhours = sprintf("%.0f", $GMONTHhours); + $GMONTHhours = sprintf("%5s", $GMONTHhours); while(length($GMONTHhours)>5) {chop($GMONTHhours);} + $GMONTHsph = sprintf("%.1f", $GMONTHsph); + $GMONTHsph = sprintf("%4s", $GMONTHsph); + + $outline = " GROUP TOTAL $prevgroup $Ghours[0] $Gsph[0] $Ghours[1] $Gsph[1] $Ghours[2] $Gsph[2] $Ghours[3] $Gsph[3] $Ghours[4] $Gsph[4] $Ghours[5] $Gsph[5] $Ghours[6] $Gsph[6] $GWEEKhours $GWEEKsph $GMONTHhours $GMONTHsph\n\n"; + print "$outline"; + print out "$outline"; + + $Gsph[0]=' 0'; $Gsph[1]=' 0'; $Gsph[2]=' 0'; $Gsph[3]=' 0'; $Gsph[4]=' 0'; $Gsph[5]=' 0'; $Gsph[6]=' 0'; + $Gsales[0]=0; $Gsales[1]=0; $Gsales[2]=0; $Gsales[3]=0; $Gsales[4]=0; $Gsales[5]=0; $Gsales[6]=0; + $Ghours[0]=' 0.0'; $Ghours[1]=' 0.0'; $Ghours[2]=' 0.0'; $Ghours[3]=' 0.0'; $Ghours[4]=' 0.0'; $Ghours[5]=' 0.0'; $Ghours[6]=' 0.0'; + $GDsph[0]=0; $GDsph[1]=0; $GDsph[2]=0; $GDsph[3]=0; $GDsph[4]=0; $GDsph[5]=0; $GDsph[6]=0; + $GDsales[0]=0; $GDsales[1]=0; $GDsales[2]=0; $GDsales[3]=0; $GDsales[4]=0; $GDsales[5]=0; $GDsales[6]=0; + $GDhours[0]=0; $GDhours[1]=0; $GDhours[2]=0; $GDhours[3]=0; $GDhours[4]=0; $GDhours[5]=0; $GDhours[6]=0; + $GWEEKsph=0; $GWEEKhours=0; $GWEEKsales=0; + $GMONTHsph=0; $GMONTHhours=0; $GMONTHsales=0; + } + } + ### END AGENT STATS + + +### BEGIN TOTAL STATS + + +$prevday = $SETprevday; + +### GO THROUGH EACH DAY THIS WEEK UP TO TODAY +while ($prevday >= 0) + { + $TOTDhours[$prevday] = sprintf("%.0f", $TOTDhours[$prevday]); + $TOThours[$prevday] = sprintf("%5s", $TOTDhours[$prevday]); while(length($TOThours[$prevday])>5) {chop($TOThours[$prevday]);} + $TOTsales[$prevday] = sprintf("%5s", $TOTDsales[$prevday]); + if ( ($TOTDsales[$prevday] > 0) && ($TOTDhours[$prevday] > 0) ) + {$TOTDsph[$prevday] = ($TOTDsales[$prevday]/$TOTDhours[$prevday]);} + else + {$TOTDsph[$prevday] = 0;} + $TOTDsph[$prevday] = sprintf("%.1f", $TOTDsph[$prevday]); + $TOTsph[$prevday] = sprintf("%4s", $TOTDsph[$prevday]); + + $TOTWEEKhours = ($TOTWEEKhours + $TOTDhours[$prevday]); + $TOTWEEKsales = ($TOTWEEKsales + $TOTDsales[$prevday]); + + $prevday = ($prevday - 1); + } + +if ( ($TOTWEEKsales > 0) && ($TOTWEEKhours > 0) ) + {$TOTWEEKsph = ($TOTWEEKsales/$TOTWEEKhours);} +else + {$TOTWEEKsph = 0;} + +if ( ($TOTMONTHsales > 0) && ($TOTMONTHhours > 0) ) + {$TOTMONTHsph = ($TOTMONTHsales/$TOTMONTHhours);} +else + {$TOTMONTHsph = 0;} + + +print Dout "$shipdate|TOTAL|||$TOTDhours[0]|$TOTDsph[0]|$TOTDhours[1]|$TOTDsph[1]|$TOTDhours[2]|$TOTDsph[2]|$TOTDhours[3]|$TOTDsph[3]|$TOTDhours[4]|$TOTDsph[4]|$TOTDhours[5]|$TOTDsph[5]|$TOTDhours[6]|$TOTDsph[6]|$TOTWEEKhours|$TOTWEEKsph|$TOTMONTHhours|$TOTMONTHsph|\n"; + + $TOTWEEKhours = sprintf("%.0f", $TOTWEEKhours); + $TOTWEEKhours = sprintf("%5s", $TOTWEEKhours); while(length($TOTWEEKhours)>5) {chop($TOTWEEKhours);} + $TOTWEEKsph = sprintf("%.1f", $TOTWEEKsph); + $TOTWEEKsph = sprintf("%4s", $TOTWEEKsph); + + $TOTMONTHhours = sprintf("%.0f", $TOTMONTHhours); + $TOTMONTHhours = sprintf("%5s", $TOTMONTHhours); while(length($TOTMONTHhours)>5) {chop($TOTMONTHhours);} + $TOTMONTHsph = sprintf("%.1f", $TOTMONTHsph); + $TOTMONTHsph = sprintf("%4s", $TOTMONTHsph); + +$outline = " TOTAL $TOThours[0] $TOTsph[0] $TOThours[1] $TOTsph[1] $TOThours[2] $TOTsph[2] $TOThours[3] $TOTsph[3] $TOThours[4] $TOTsph[4] $TOThours[5] $TOTsph[5] $TOThours[6] $TOTsph[6] $TOTWEEKhours $TOTWEEKsph $TOTMONTHhours $TOTMONTHsph\n"; +print "$outline"; +print out "$outline"; + + +exit; + + + + + + + + + + + + + + + + + + + + + + + + + ### TOTAL ACTIVE TIME + $active = ($aryA[3] + $aryA[4] + $aryA[5] + $aryA[6]); + $TIME_S = $active; + $TIME_H = int($TIME_S / 3600); + $TIME_S = ($TIME_S - ($TIME_H * 3600)); + $TIME_M = int($TIME_S / 60); + $TIME_S = ($TIME_S - ($TIME_M * 60)); + if ($TIME_S < 10) {$TIME_S = "0$TIME_S";} + if ($TIME_M < 10) {$TIME_M = "0$TIME_M";} + $TIME_HMS = "$TIME_H:$TIME_M:$TIME_S"; + $Dactive = $TIME_HMS; + $active = sprintf("%9s", $TIME_HMS); + + ### TOTAL TALK TIME + $TIME_S = $aryA[3]; + $TIME_H = int($TIME_S / 3600); + $TIME_S = ($TIME_S - ($TIME_H * 3600)); + $TIME_M = int($TIME_S / 60); + $TIME_S = ($TIME_S - ($TIME_M * 60)); + if ($TIME_S < 10) {$TIME_S = "0$TIME_S";} + if ($TIME_M < 10) {$TIME_M = "0$TIME_M";} + $TIME_HMS = "$TIME_H:$TIME_M:$TIME_S"; + $Dtalk = $TIME_HMS; + $talk = sprintf("%9s", $TIME_HMS); + + ### TOTAL PAUSE TIME + $TIME_S = $aryA[4]; + $TIME_H = int($TIME_S / 3600); + $TIME_S = ($TIME_S - ($TIME_H * 3600)); + $TIME_M = int($TIME_S / 60); + $TIME_S = ($TIME_S - ($TIME_M * 60)); + if ($TIME_S < 10) {$TIME_S = "0$TIME_S";} + if ($TIME_M < 10) {$TIME_M = "0$TIME_M";} + $TIME_HMS = "$TIME_H:$TIME_M:$TIME_S"; + $Dpause = $TIME_HMS; + $pause = sprintf("%9s", $TIME_HMS); + + ### TOTAL WAIT TIME + $TIME_S = $aryA[5]; + $TIME_H = int($TIME_S / 3600); + $TIME_S = ($TIME_S - ($TIME_H * 3600)); + $TIME_M = int($TIME_S / 60); + $TIME_S = ($TIME_S - ($TIME_M * 60)); + if ($TIME_S < 10) {$TIME_S = "0$TIME_S";} + if ($TIME_M < 10) {$TIME_M = "0$TIME_M";} + $TIME_HMS = "$TIME_H:$TIME_M:$TIME_S"; + $Dwait = $TIME_HMS; + $wait = sprintf("%9s", $TIME_HMS); + + ### TOTAL DISPO TIME + $TIME_S = $aryA[6]; + $TIME_H = int($TIME_S / 3600); + $TIME_S = ($TIME_S - ($TIME_H * 3600)); + $TIME_M = int($TIME_S / 60); + $TIME_S = ($TIME_S - ($TIME_M * 60)); + if ($TIME_S < 10) {$TIME_S = "0$TIME_S";} + if ($TIME_M < 10) {$TIME_M = "0$TIME_M";} + $TIME_HMS = "$TIME_H:$TIME_M:$TIME_S"; + $Ddispo = $TIME_HMS; + $dispo = sprintf("%9s", $TIME_HMS); + + $stmtB = "select event_time,UNIX_TIMESTAMP(event_time) from $vicidial_agent_log where event_time <= '$shipdate 23:59:59' and event_time >= '$begindate 00:00:00' and user='$aryA[2]' order by event_time limit 1;"; + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtA ", $dbhB->errstr; + @aryB = $sthB->fetchrow_array; + $Dfirst_time = $aryB[0]; + $first_time = sprintf("%21s", $aryB[0]); + $Dfirst_log = $aryB[1]; + $first_log = $aryB[1]; + + $stmtB = "select event_time,UNIX_TIMESTAMP(event_time) from $vicidial_agent_log where event_time <= '$shipdate 23:59:59' and event_time >= '$begindate 00:00:00' and user='$aryA[2]' order by event_time desc limit 1;"; + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtA ", $dbhB->errstr; + @aryB = $sthB->fetchrow_array; + $Dlast_time = $aryB[0]; + $last_time = sprintf("%21s", $aryB[0]); + $Dlast_log = $aryB[1]; + $last_log = $aryB[1]; + + $TIME_S = ($last_log - $first_log); + $TIME_H = int($TIME_S / 3600); + $TIME_S = ($TIME_S - ($TIME_H * 3600)); + $TIME_M = int($TIME_S / 60); + $TIME_S = ($TIME_S - ($TIME_M * 60)); + if ($TIME_S < 10) {$TIME_S = "0$TIME_S";} + if ($TIME_M < 10) {$TIME_M = "0$TIME_M";} + $TIME_HMS = "$TIME_H:$TIME_M:$TIME_S"; + $TIME_HMS = "N/A"; + $Dlogin_time = $TIME_HMS; + $login_time = sprintf("%9s", $TIME_HMS); + + + + print Dout "$shipdate|$Dname|$Duser|$Dcalls|$Dtalk|$Dpause|$Dwait|$Ddispo|$Dactive|$Dlogin_time|$Dfirst_time|$Dlast_time\n"; + print out "$name$user$calls$talk$pause$wait$dispo$active$login_time$first_time$last_time\n"; + print "$name$user$calls$talk$pause$wait$dispo$active$login_time$first_time$last_time\n"; + + + +close(Dout); +close(out); + +### calculate time to run script ### +$secY = time(); +$secZ = ($secY - $secX); +$secZm = ($secZ /60); + +print "script execution time in seconds: $secZ minutes: $secZm\n"; + +exit; + + + + + diff --git a/bin/FastAGI_log.pl b/bin/FastAGI_log.pl index 779d2856..52567e70 100644 --- a/bin/FastAGI_log.pl +++ b/bin/FastAGI_log.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# FastAGI_log.pl version 2.0.3 *DBI-version* +# FastAGI_log.pl version 2.0.5 *DBI-version* # # Experimental Deamon using perl Net::Server that runs as FastAGI to reduce load # replaces the following AGI scripts: @@ -25,7 +25,7 @@ # exten => h,1,DeadAGI(agi://127.0.0.1:4577/call_log--HVcauses--PRI-----NODEBUG-----${HANGUPCAUSE}-----${DIALSTATUS}-----${DIALEDTIME}-----${ANSWEREDTIME}) # # -# Copyright (C) 2007 Matt Florell LICENSE: GPLv2 +# Copyright (C) 2008 Matt Florell LICENSE: GPLv2 # # CHANGELOG: # 61010-1007 - First test build @@ -33,6 +33,7 @@ # 70215-1258 - Added queue_log entry when deleting vac record # 70808-1425 - Moved VD_hangup section to the call_log end stage to improve efficiency # 71030-2039 - Added priority to hopper insertions +# 80224-0040 - Fixed bugs in vicidial_log updates # @@ -127,7 +128,7 @@ if ($SERVERLOG =~ /Y/) print "SERVER LOGGING ON: LEVEL-$log_level FILE-$childLOGfile\n"; } -package TEST_VDfastAGI; +package VDfastAGI; use Net::Server; use Asterisk::AGI; @@ -140,7 +141,7 @@ use Net::Server::PreFork; # any personality will do sub process_request { $process = 'begin'; - $script = 'TEST_VDfastAGI'; + $script = 'VDfastAGI'; ########## Get current time, parse configs, get logging preferences ########## ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year = ($year + 1900); @@ -441,6 +442,20 @@ sub process_request { else { if ($AGILOG) {$agi_string = "|CALL HUNG UP|"; &agi_output;} + if ($request =~ /--HVcauses--/i) + { + $HVcauses=1; + @ARGV_vars = split(/-----/, $request); + $PRI = $ARGV_vars[0]; + $PRI =~ s/.*--HVcauses--//gi; + $DEBUG = $ARGV_vars[1]; + $hangup_cause = $ARGV_vars[2]; + $dialstatus = $ARGV_vars[3]; + $dial_time = $ARGV_vars[4]; + $ring_time = $ARGV_vars[5]; + $agi_string = "URL HVcauses: |$PRI|$DEBUG|$hangup_cause|$dialstatus|$dial_time|$ring_time|"; + &agi_output; + } ### get uniqueid and start_epoch from the call_log table $stmtA = "SELECT uniqueid,start_epoch FROM call_log where uniqueid='$unique_id';"; @@ -551,20 +566,24 @@ sub process_request { if ($dialstatus =~ /BUSY/) {$VDL_status = 'B'; $VDAC_status = 'BUSY';} if ($dialstatus =~ /CHANUNAVAIL/) {$VDL_status = 'DC'; $VDAC_status = 'DISCONNECT';} - $stmtA = "UPDATE vicidial_auto_calls set status='$VDAC_status' where callerid = '$callerid';"; - if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} - $affected_rows = $dbhA->do($stmtA); - if ($AGILOG) {$agi_string = "-- VDAC update: |$affected_rows|$CIDlead_id"; &agi_output;} - $stmtA = "UPDATE vicidial_list set status='$VDL_status' where lead_id = '$CIDlead_id';"; if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} - $affected_rows = $dbhA->do($stmtA); - if ($AGILOG) {$agi_string = "-- VDAD vicidial_list update: |$affected_rows|$CIDlead_id"; &agi_output;} + $VDADaffected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDAD vicidial_list update: |$VDADaffected_rows|$CIDlead_id"; &agi_output;} - $stmtA = "UPDATE vicidial_log set status='$VDL_status' where uniqueid = '$uniqueid';"; + $stmtA = "UPDATE vicidial_auto_calls set status='$VDAC_status' where callerid = '$callerid';"; if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} - $affected_rows = $dbhA->do($stmtA); - if ($AGILOG) {$agi_string = "-- VDAD vicidial_log update: |$affected_rows|$uniqueid|"; &agi_output;} + $VDACaffected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDAC update: |$VDACaffected_rows|$CIDlead_id"; &agi_output;} + + $Euniqueid=$uniqueid; + $Euniqueid =~ s/\.\d+$//gi; + $stmtA = "UPDATE vicidial_log FORCE INDEX(lead_id) set status='$VDL_status' where lead_id = '$CIDlead_id' and uniqueid LIKE \"$Euniqueid%\";"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $VDLaffected_rows = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VDAD vicidial_log update: |$VDLaffected_rows|$uniqueid|$VDACuniqueid|"; &agi_output;} + + sleep(1); $dbhA->disconnect(); } @@ -581,7 +600,7 @@ sub process_request { ########## FIND AND DELETE vicidial_auto_calls ########## $VD_alt_dial = 'NONE'; - $stmtA = "SELECT lead_id,callerid,campaign_id,alt_dial,stage,UNIX_TIMESTAMP(call_time) FROM vicidial_auto_calls where uniqueid = '$uniqueid' limit 1;"; + $stmtA = "SELECT lead_id,callerid,campaign_id,alt_dial,stage,UNIX_TIMESTAMP(call_time),uniqueid FROM vicidial_auto_calls where uniqueid = '$uniqueid' or callerid = '$callerid' limit 1;"; if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -596,6 +615,7 @@ sub process_request { $VD_alt_dial = "$aryA[3]"; $VD_stage = "$aryA[4]"; $VD_start_epoch = "$aryA[5]"; + $VD_uniqueid = "$aryA[6]"; $rec_countCUSTDATA++; } $sthA->finish(); @@ -606,9 +626,9 @@ sub process_request { } else { - $stmtA = "DELETE FROM vicidial_auto_calls where uniqueid='$uniqueid' order by call_time desc limit 1;"; + $stmtA = "DELETE FROM vicidial_auto_calls where uniqueid='$uniqueid' or callerid = '$callerid' order by call_time desc limit 1;"; $affected_rows = $dbhA->do($stmtA); - if ($AGILOG) {$agi_string = "-- VDAC record deleted: |$affected_rows| |$VD_lead_id|$uniqueid|$VD_callerid|$VARserver_ip"; &agi_output;} + if ($AGILOG) {$agi_string = "-- VDAC record deleted: |$affected_rows| |$VD_lead_id|$uniqueid|$VD_uniqueid|$VD_callerid|$VARserver_ip"; &agi_output;} ############################################# ##### START QUEUEMETRICS LOGGING LOOKUP ##### @@ -673,14 +693,16 @@ sub process_request { ########## FIND AND UPDATE vicidial_log ########## - $stmtA = "SELECT start_epoch,status FROM vicidial_log where uniqueid='$uniqueid' and lead_id='$VD_lead_id' limit 1;"; + $Euniqueid=$uniqueid; + $Euniqueid =~ s/\.\d+$//gi; + $stmtA = "SELECT start_epoch,status FROM vicidial_log FORCE INDEX(lead_id) where lead_id = '$VD_lead_id' and uniqueid LIKE \"$Euniqueid%\" limit 1;"; if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; $epc_countCUSTDATA=0; $VD_closecallid=''; - while ($sthArows > $rec_countCUSTDATA) + while ($sthArows > $epc_countCUSTDATA) { @aryA = $sthA->fetchrow_array; $VD_start_epoch = "$aryA[0]"; @@ -691,7 +713,7 @@ sub process_request { if (!$epc_countCUSTDATA) { - if ($AGILOG) {$agi_string = "no VDL record found: $uniqueid $calleridname $VD_lead_id $uniqueid"; &agi_output;} + if ($AGILOG) {$agi_string = "no VDL record found: $uniqueid $calleridname $VD_lead_id $uniqueid $VD_uniqueid"; &agi_output;} $secX = time(); $Rtarget = ($secX - 21600); # look for VDCL entry within last 6 hours @@ -724,7 +746,7 @@ sub process_request { } if (!$epc_countCUSTDATA) { - if ($AGILOG) {$agi_string = "no VDL or VDCL record found: $uniqueid $calleridname $VD_lead_id $uniqueid"; &agi_output;} + if ($AGILOG) {$agi_string = "no VDL or VDCL record found: $uniqueid $calleridname $VD_lead_id $uniqueid $VD_uniqueid"; &agi_output;} } else { @@ -742,7 +764,7 @@ sub process_request { if ($AGILOG) {$agi_string = "-- VDAD vicidial_list update: |$affected_rows|$VD_lead_id"; &agi_output;} } - $stmtA = "UPDATE vicidial_log set $SQL_status end_epoch='$now_date_epoch',length_in_sec='$VD_seconds' where uniqueid = '$uniqueid';"; + $stmtA = "UPDATE vicidial_log FORCE INDEX(lead_id) set $SQL_status end_epoch='$now_date_epoch',length_in_sec='$VD_seconds' where lead_id = '$VD_lead_id' and uniqueid LIKE \"$Euniqueid%\";"; if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} $affected_rows = $dbhA->do($stmtA); if ($AGILOG) {$agi_string = "-- VDAD vicidial_log update: |$affected_rows|$uniqueid|$VD_status|"; &agi_output;} @@ -753,7 +775,7 @@ sub process_request { ########## UPDATE vicidial_closer_log ########## if (length($VD_closecallid) < 1) { - if ($AGILOG) {$agi_string = "no VDCL record found: $uniqueid $calleridname $VD_lead_id $uniqueid"; &agi_output;} + if ($AGILOG) {$agi_string = "no VDCL record found: $uniqueid $calleridname $VD_lead_id $uniqueid $VD_uniqueid"; &agi_output;} } else { @@ -878,7 +900,7 @@ sub process_request { } -TEST_VDfastAGI->run( +VDfastAGI->run( port=>4577, user=>'root', group=>'root', diff --git a/docs/BASE_INSTALL.txt b/docs/BASE_INSTALL.txt index 5612057e..5e9319b2 100644 --- a/docs/BASE_INSTALL.txt +++ b/docs/BASE_INSTALL.txt @@ -474,6 +474,7 @@ insert into vicidial_statuses values('DROP','Agent Not Available','N','Y','UNDEF insert into vicidial_statuses values('NA','No Answer AutoDial','N','N','UNDEFINED'); insert into vicidial_statuses values('CALLBK','Call Back','Y','Y','UNDEFINED'); +insert into vicidial_statuses values('CBHOLD','Call Back Hold','N','Y','UNDEFINED'); insert into vicidial_statuses values('A','Answering Machine','Y','N','UNDEFINED'); insert into vicidial_statuses values('AA','Answering Machine Auto','N','N','UNDEFINED'); insert into vicidial_statuses values('AM','Answering Machine Sent to Mesg','N','N','UNDEFINED'); diff --git a/docs/REQUIRED_APPS_INSTALL.txt b/docs/REQUIRED_APPS_INSTALL.txt index 5d973118..f6d1716a 100644 --- a/docs/REQUIRED_APPS_INSTALL.txt +++ b/docs/REQUIRED_APPS_INSTALL.txt @@ -181,9 +181,9 @@ cd /usr/local wget http://mirror.candidhosting.com/pub/apache/httpd/httpd-2.0.61.tar.gz gunzip httpd-2.0.61.tar.gz tar xvf httpd-2.0.61.tar -wget http://us2.php.net/distributions/php-4.4.7.tar.gz -gunzip php-4.4.7.tar.gz -tar xvf php-4.4.7.tar +wget http://us2.php.net/distributions/php-4.4.8.tar.gz +gunzip php-4.4.8.tar.gz +tar xvf php-4.4.8.tar cd httpd-2.0.61 ./configure --prefix=/usr/local/apache2 --enable-ssl --enable-setenvif --enable-so --with-apxs2 --enable-dav --enable-maintainer-mode make @@ -197,7 +197,7 @@ openssl req -new -x509 -days 1200 -keyout /usr/local/apache2/conf/ssl.key/server openssl rsa -in /usr/local/apache2/conf/ssl.key/server.key.cpy -out /usr/local/apache2/conf/ssl.key/server.key -cd ../php-4.4.7 +cd ../php-4.4.8 ./configure --with-mysql=/usr/local/mysql --enable-inline-optimization --enable-memory-limit --enable-track-vars --enable-libgcc --with-xml --enable-versioning --enable-sysvsem --with-openssl --disable-debug --with-apxs2=/usr/local/apache2/bin/apxs --with-zlib make make install @@ -425,11 +425,11 @@ rm -f /usr/lib/asterisk/modules/pbx_functions.so mkdir /usr/src/asterisk-1.4 cd /usr/src/asterisk-1.4 -wget http://ftp.digium.com/pub/asterisk/releases/asterisk-1.4.17.tar.gz +wget http://ftp.digium.com/pub/asterisk/releases/asterisk-1.4.18.tar.gz wget http://ftp.digium.com/pub/zaptel/releases/zaptel-1.4.8.tar.gz wget http://ftp.digium.com/pub/libpri/releases/libpri-1.4.3.tar.gz -gunzip asterisk-1.4.17.tar.gz -tar xvf asterisk-1.4.17.tar +gunzip asterisk-1.4.18.tar.gz +tar xvf asterisk-1.4.18.tar gunzip zaptel-1.4.8.tar.gz tar xvf zaptel-1.4.8.tar gunzip libpri-1.4.3.tar.gz @@ -442,7 +442,7 @@ cd ../libpri-1.4.3 make clean make make install -cd ../asterisk-1.4.17 +cd ../asterisk-1.4.18 wget http://www.eflo.net/files/enter.h wget http://www.eflo.net/files/leave.h mv -f enter.h apps/enter.h diff --git a/docs/SCRATCH_INSTALL.txt b/docs/SCRATCH_INSTALL.txt index 3bbe4f34..58f2a622 100644 --- a/docs/SCRATCH_INSTALL.txt +++ b/docs/SCRATCH_INSTALL.txt @@ -66,7 +66,7 @@ PHASE 1: INSTALLING AN OPERATING SYSTEM This installation will be using Slackware 11 for the linux distribution, -Slackware 10.X will also work with these instructions. There are several easier +Slackware 12.X will also work with these instructions. There are several easier linux distributions and there are others that are more popular, but Slackware is a nice non-commercial distro that has been around for a long time and proven itself to be a very uncluttered and stable platform for development. @@ -684,15 +684,15 @@ installation on another machine) - wget http://mirror.candidhosting.com/pub/apache/httpd/httpd-2.0.61.tar.gz - gunzip httpd-2.0.61.tar.gz - tar xvf httpd-2.0.61.tar - - wget http://us2.php.net/distributions/php-4.4.7.tar.gz + - wget http://us2.php.net/distributions/php-4.4.8.tar.gz NOTE: PHP 5.1.1 has also been tested with this release - - gunzip php-4.4.7.tar.gz - - tar xvf php-4.4.7.tar + - gunzip php-4.4.8.tar.gz + - tar xvf php-4.4.8.tar - cd httpd-2.0.61 - ./configure --enable-so --with-apxs2 - make - make install - - cd ../php-4.4.7 + - cd ../php-4.4.8 - ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql - make - make install @@ -2972,6 +2972,7 @@ insert into vicidial_statuses values('DROP','Agent Not Available','N','Y','UNDEF insert into vicidial_statuses values('NA','No Answer AutoDial','N','N','UNDEFINED'); insert into vicidial_statuses values('CALLBK','Call Back','Y','Y','UNDEFINED'); +insert into vicidial_statuses values('CBHOLD','Call Back Hold','N','Y','UNDEFINED'); insert into vicidial_statuses values('A','Answering Machine','Y','N','UNDEFINED'); insert into vicidial_statuses values('AA','Answering Machine Auto','N','N','UNDEFINED'); insert into vicidial_statuses values('AM','Answering Machine Sent to Mesg','N','N','UNDEFINED'); @@ -3100,10 +3101,7 @@ The browser requirements for this are: - Microsoft Internet Explorer 6.0 This version is fully functional and has been tested in our production -call center with no problems. On RedHat 9.0 Linux workstations we have noticed -a decrease in system load running the web-client as compared to the Perl/Tk -client. Also, the memory usage stayed at about 22MB for a full shift of -activity, so no memory leaks with Firefox. +call center with no problems. To log into this app you will need a login setup in the vicidial_users table with a user_level of 1 or greater as well as an entry for the phone you are diff --git a/extras/MySQL_AST_CREATE_tables.sql b/extras/MySQL_AST_CREATE_tables.sql index b7d1b6f6..57a9f2eb 100644 --- a/extras/MySQL_AST_CREATE_tables.sql +++ b/extras/MySQL_AST_CREATE_tables.sql @@ -147,7 +147,7 @@ index(user) ); CREATE TABLE live_inbound ( -uniqueid DOUBLE(18,7) NOT NULL, +uniqueid VARCHAR(20) NOT NULL, channel VARCHAR(100) NOT NULL, server_ip VARCHAR(15) NOT NULL, caller_id VARCHAR(30), @@ -177,7 +177,7 @@ last_update DATETIME ); CREATE TABLE call_log ( -uniqueid DOUBLE(18,7) PRIMARY KEY NOT NULL, +uniqueid VARCHAR(20) PRIMARY KEY NOT NULL, channel VARCHAR(100), channel_group VARCHAR(30), type VARCHAR(10), @@ -197,7 +197,7 @@ index (channel) ); CREATE TABLE park_log ( -uniqueid DOUBLE(18,7) PRIMARY KEY NOT NULL, +uniqueid VARCHAR(20) PRIMARY KEY NOT NULL, status VARCHAR(10), channel VARCHAR(100), channel_group VARCHAR(30), @@ -214,7 +214,7 @@ index (parked_time) CREATE TABLE vicidial_manager ( man_id INT(9) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL, -uniqueid DOUBLE(18,7), +uniqueid VARCHAR(20), entry_date DATETIME, status ENUM('NEW','QUEUE','SENT','UPDATED','DEAD'), response ENUM('Y','N'), @@ -300,7 +300,7 @@ extension VARCHAR(100), status ENUM('READY','QUEUE','INCALL','PAUSED','CLOSER') default 'PAUSED', lead_id INT(9) UNSIGNED NOT NULL, campaign_id VARCHAR(8), -uniqueid DOUBLE(18,7), +uniqueid VARCHAR(20), callerid VARCHAR(20), channel VARCHAR(100), random_id INT(8) UNSIGNED, @@ -325,7 +325,7 @@ server_ip VARCHAR(15) NOT NULL, campaign_id VARCHAR(20), status ENUM('SENT','RINGING','LIVE','XFER','PAUSED','CLOSER','BUSY','DISCONNECT') default 'PAUSED', lead_id INT(9) UNSIGNED NOT NULL, -uniqueid DOUBLE(18,7), +uniqueid VARCHAR(20), callerid VARCHAR(20), channel VARCHAR(100), phone_code VARCHAR(10), @@ -342,7 +342,7 @@ index (last_update_time) ); CREATE TABLE vicidial_log ( -uniqueid DOUBLE(18,7) PRIMARY KEY NOT NULL, +uniqueid VARCHAR(20) PRIMARY KEY NOT NULL, lead_id INT(9) UNSIGNED NOT NULL, list_id BIGINT(14) UNSIGNED, campaign_id VARCHAR(8), @@ -653,7 +653,7 @@ closer_campaigns TEXT ); CREATE TABLE live_inbound_log ( -uniqueid DOUBLE(18,7) NOT NULL, +uniqueid VARCHAR(20) NOT NULL, channel VARCHAR(100) NOT NULL, server_ip VARCHAR(15) NOT NULL, caller_id VARCHAR(30), @@ -924,7 +924,8 @@ queuemetrics_eq_prepend VARCHAR(255) default 'NONE', vicidial_agent_disable ENUM('NOT_ACTIVE','LIVE_AGENT','EXTERNAL','ALL') default 'NOT_ACTIVE', allow_sipsak_messages ENUM('0','1') default '0', admin_home_url VARCHAR(255) default '../vicidial/welcome.php', -enable_agc_xfer_log ENUM('0','1') default '0' +enable_agc_xfer_log ENUM('0','1') default '0', +db_schema_version INT(8) UNSIGNED default '0' ); CREATE TABLE vicidial_campaigns_list_mix ( @@ -1071,3 +1072,4 @@ INSERT INTO vicidial_state_call_times SET state_call_time_id='utah',state_call_t INSERT INTO vicidial_state_call_times SET state_call_time_id='washington',state_call_time_state='WA',state_call_time_name='Washington 8am',sct_default_start='800',sct_default_stop='2100'; INSERT INTO vicidial_state_call_times SET state_call_time_id='wyoming',state_call_time_state='WY',state_call_time_name='Wyoming 8am-8pm',sct_default_start='800',sct_default_stop='2000'; +UPDATE system_settings SET db_schema_version='1075'; diff --git a/extras/upgrade_2.0.5.sql b/extras/upgrade_2.0.5.sql index 8ac9ba15..a0f8904c 100644 --- a/extras/upgrade_2.0.5.sql +++ b/extras/upgrade_2.0.5.sql @@ -40,11 +40,24 @@ ALTER TABLE vicidial_users ADD qc_commit ENUM('1','0') default '0'; ALTER TABLE vicidial_user_groups ADD qc_allowed_campaigns TEXT; ALTER TABLE vicidial_user_groups ADD qc_allowed_inbound_groups TEXT; - - - - ALTER TABLE system_settings ADD db_schema_version INT(8) UNSIGNED default '0'; UPDATE system_settings SET db_schema_version='1074', version='2.0.5b0.5'; +ALTER TABLE live_inbound MODIFY uniqueid VARCHAR(20) NOT NULL; +ALTER TABLE live_inbound_log MODIFY uniqueid VARCHAR(20) NOT NULL; +ALTER TABLE live_inbound_log MODIFY uniqueid VARCHAR(20) NOT NULL; +ALTER TABLE vicidial_manager MODIFY uniqueid VARCHAR(20) NOT NULL; +ALTER TABLE vicidial_live_agents MODIFY uniqueid VARCHAR(20) NOT NULL; +ALTER TABLE vicidial_auto_calls MODIFY uniqueid VARCHAR(20) NOT NULL; +ALTER TABLE call_log DROP PRIMARY KEY; +ALTER TABLE call_log DROP INDEX uniqueid; +ALTER TABLE call_log MODIFY uniqueid VARCHAR(20) PRIMARY KEY UNIQUE NOT NULL; +ALTER TABLE park_log DROP PRIMARY KEY; +ALTER TABLE park_log DROP INDEX uniqueid; +ALTER TABLE park_log MODIFY uniqueid VARCHAR(20) PRIMARY KEY UNIQUE NOT NULL; +ALTER TABLE vicidial_log DROP PRIMARY KEY; +ALTER TABLE vicidial_log DROP INDEX uniqueid; +ALTER TABLE vicidial_log MODIFY uniqueid VARCHAR(20) PRIMARY KEY UNIQUE NOT NULL; + +UPDATE system_settings SET db_schema_version='1075'; diff --git a/www/agc/vdc_db_query.php b/www/agc/vdc_db_query.php index 5c165c44..a8263907 100644 --- a/www/agc/vdc_db_query.php +++ b/www/agc/vdc_db_query.php @@ -676,10 +676,16 @@ if ($ACTION == 'manDiaLnextCaLL') if ( ($WeBRooTWritablE > 0) and ($enable_agc_xfer_log > 0) ) { + # generate callerID for unique identifier in xfer_log file + $PADlead_id = sprintf("%09s", $lead_id); + while (strlen($PADlead_id) > 9) {$PADlead_id = substr("$PADlead_id", 0, -1);} + # Create unique calleridname to track the call: MmmddhhmmssLLLLLLLLL + $MqueryCID = "M$CIDdate$PADlead_id"; + # DATETIME|campaign|lead_id|phone_number|user|type # 2007-08-22 11:11:11|TESTCAMP|65432|3125551212|1234|M $fp = fopen ("./xfer_log.txt", "a"); - fwrite ($fp, "$NOW_TIME|$campaign|$lead_id|$phone_number|$user|M\n"); + fwrite ($fp, "$NOW_TIME|$campaign|$lead_id|$phone_number|$user|M|$MqueryCID|\n"); fclose($fp); } @@ -1882,7 +1888,7 @@ if ($ACTION == 'VDADcheckINCOMING') # DATETIME|campaign|lead_id|phone_number|user|type # 2007-08-22 11:11:11|TESTCAMP|65432|3125551212|1234|A $fp = fopen ("./xfer_log.txt", "a"); - fwrite ($fp, "$NOW_TIME|$campaign|$lead_id|$phone_number|$user|$Ctype\n"); + fwrite ($fp, "$NOW_TIME|$campaign|$lead_id|$phone_number|$user|$Ctype|$callerid|$uniqueid\n"); fclose($fp); } diff --git a/www/vicidial/AST_timeonVDADall.php b/www/vicidial/AST_timeonVDADall.php index 044daf92..a6afbf6b 100644 --- a/www/vicidial/AST_timeonVDADall.php +++ b/www/vicidial/AST_timeonVDADall.php @@ -842,7 +842,7 @@ $talking_to_print = mysql_num_rows($rslt); } if (eregi("PAUSED",$row[3])) { - if ($call_time_M_int >= 30) + if ($call_time_M_int >= 360) {$i++; continue;} else {