From c076f0fe99f8f1854ef1416fd6052c266ab4ad20 Mon Sep 17 00:00:00 2001 From: mattf Date: Sat, 18 Nov 2023 12:42:31 +0000 Subject: [PATCH] Added code for 3-way-press-agent functions in agent screen, more to follow. git-svn-id: svn://192.168.202.10@3777 3d104415-ff17-0410-8863-d5cf3c621b8a --- agi/agi-3way_press_agent.agi | 633 +++++++++++++++++++++++++++++ agi/agi-3way_press_outside.agi | 627 ++++++++++++++++++++++++++++ bin/ADMIN_archive_log_tables.pl | 53 +++ bin/AST_conf_update.pl | 39 +- bin/AST_conf_update_3way.pl | 22 +- extras/MySQL_AST_CREATE_tables.sql | 43 +- extras/upgrade_2.14.sql | 43 ++ www/vicidial/admin_modify_lead.php | 61 +++ 8 files changed, 1518 insertions(+), 3 deletions(-) create mode 100644 agi/agi-3way_press_agent.agi create mode 100644 agi/agi-3way_press_outside.agi diff --git a/agi/agi-3way_press_agent.agi b/agi/agi-3way_press_agent.agi new file mode 100644 index 00000000..96f0e4fd --- /dev/null +++ b/agi/agi-3way_press_agent.agi @@ -0,0 +1,633 @@ +#!/usr/bin/perl +# +# agi-3way_press_agent.agi version 2.14 +# +# Runs when a 3way call using a dial override is placed through a special +# extension from the agent screen to an outside-agent where that outside-agent +# will have to press-1 to accept the phone call. +# An example of the special extension: "49907917275551212" where: +# - 49907 is the special extension +# - 9 is the dial prefix +# - 1 is the phone code +# - 7275551212 is the outside-agent number to be dialed +# +# THIS IS THE FIRST REQUIRED AGI SCRIPT OF 2 FOR THIS FEATURE +# +# You need to put lines similar to those below in your extensions.conf file: +# +#; VICIdial agent initation of outside-agent transfer: +#exten => _49907.,1,Answer +#exten => _49907.,n,NoOp(${CALLERID(name)}) +#exten => _49907.,n,Playback(sip-silence) +#exten => _49907.,n,AGI(agi-3way_press_agent.agi) +#exten => _49907.,n,Hangup +# +# +# Copyright (C) 2023 Matt Florell LICENSE: AGPLv2 +# +# changes: +# 231113-2016 - First Build +# + +$script = 'agi-3way_press_agent.agi'; + +$at='@'; +$S='*'; +$mel=1; # Mysql Error Log enabled = 1 +$mysql_log_count=272; +$one_mysql_log=0; +$MT[0]=''; + + +$now_date_epoch = 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";} +$CIDdate = "$mon$mday$hour$min$sec"; +$tsSQLdate = "$year$mon$mday$hour$min$sec"; +$SQLdate = "$year-$mon-$mday $hour:$min:$sec"; +$SQLdateBEGIN = $SQLdate; + while (length($CIDdate) > 9) {$CIDdate =~ s/^.//gi;} # 0902235959 changed to 902235959 + +# 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 (!$TPALOGfile) {$TPALOGfile = "$PATHlogs/tpaout.$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 agi_output,local_gmt 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; + $dbhP=$dbhA; $mysql_count='02001'; $MEL_aff_rows=$sthArows; &mysql_error_logging; +$rec_count=0; +while ($sthArows > $rec_count) + { + $AGILOG = '0'; + @aryA = $sthA->fetchrow_array; + $DBagi_output = $aryA[0]; + $local_gmt = $aryA[1]; + if ($isdst) {$local_gmt++;} + if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';} + if ($DBagi_output =~ /FILE/) {$AGILOG = '2';} + if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';} + $rec_count++; + } +$sthA->finish(); + +############################################# +##### START SYSTEM SETTINGS LOOKUP ##### +$stmtA = "SELECT enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_log_id,queuemetrics_eq_prepend,queuemetrics_pe_phone_append,did_agent_log,alt_log_server_ip,alt_log_dbname,alt_log_login,alt_log_pass,tables_use_alt_log_db,did_ra_extensions_enabled,queuemetrics_socket,queuemetrics_socket_url,enable_did_entry_list_id,enable_drop_lists,inbound_answer_config,agent_search_method,abandon_check_queue,inbound_credits FROM system_settings;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; + $dbhP=$dbhA; $mysql_count='02026'; $MEL_aff_rows=$sthArows; &mysql_error_logging; +if ($sthArows > 0) + { + @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]; + $queuemetrics_pe_phone_append = $aryA[7]; + $did_agent_log = $aryA[8]; + $alt_log_server_ip = $aryA[9]; + $alt_log_dbname = $aryA[10]; + $alt_log_login = $aryA[11]; + $alt_log_pass = $aryA[12]; + $tables_use_alt_log_db = $aryA[13]; + $did_ra_extensions_enabled = $aryA[14]; + $queuemetrics_socket = $aryA[15]; + $queuemetrics_socket_url = $aryA[16]; + $enable_did_entry_list_id = $aryA[17]; + $enable_drop_lists = $aryA[18]; + $inbound_answer_config = $aryA[19]; + $SSagent_search_method = $aryA[20]; + $SSabandon_check_queue = $aryA[21]; + $SSinbound_credits = $aryA[22]; + } +$sthA->finish(); +##### END SYSTEM SETTINGS LOOKUP ##### +########################################### + +### 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]); + + $stage = $ARGV_vars[0]; + } + +$|=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_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 (/^agi_context\:\s+(.*)$/) {$context = $1;} + } +$callerid =~ s/\'|\\\\|\\\|\\|\\;|\\\;|\;|;//gi; +$calleridname =~ s/\'|\\\\|\\\|\\|\\;|\\\;|\;|;//gi; +$extension =~ s/\'|\"|\\\\|\\\|\\|\\;|\\\;|\;|;//gi; +$original_cid = $callerid; + +if ($calleridname =~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^M\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/) + { + $lead_id = substr($calleridname, 10, 10); + $lead_id = ($lead_id + 0); + } +if ($calleridname =~ /^DC\d\d\d\d\d\dW\d\d\d\d\d\d\d\d\d\dW/) + { + $lead_id = substr($calleridname, 9, 10); + $lead_id = ($lead_id + 0); + } + +if ($calleridname =~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^M\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/) + {$callerid = $calleridname;} + +if ( ($callerid =~ /\".*\"/) && ( (!$calleridname) or ($calleridname =~ /unknown/) ) ) + { + $calleridname = $callerid; + $calleridname =~ s/\<\d\d\d\d\d\d\d\d\d\d\>//gi; + $calleridname =~ s/\"|\" //gi; + } + +if ($callerid !~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/) + { + $callerid =~ s/\D|\'//gi; + $calleridname =~ s/unknown|\'//gi; + if ( (!$callerid) or ($callerid =~ /unknown/) ) + {$callerid = $calleridname;} + } + +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|$stage|"; &agi_output;} + +$CALLvendor_lead_code = $AGI->get_variable('vendor_lead_code'); +$CALLlead_id = $AGI->get_variable('lead_id'); + +if ($AGILOG) {$agi_string = "CALL Variables: |Lead ID: $lead_id($CALLlead_id) VLC: $CALLvendor_lead_code $callerid|"; &agi_output;} + + +if ($AGILOG) {$agi_string = "+++++ 3WAY PRESS AGENT STARTED: |$channel_group|$callerid|$now_date"; &agi_output;} + +$VDADphone=''; +$VDADphone_code=''; +$VCcallerid = $channel_group; +$VD_campaign_id = $channel_group; +if (length($VCcallerid)<2) + {$VCcallerid = 'ViciDial Inbound';} + +$phone_number = substr($extension, -10); +$dialstring = $extension; +$dialstring =~ s/^49907//gi; + +if ($AGILOG) {$agi_string = "+++++ 3WAY PRESS AGENT VARIABLES: |phone: $phone_number|dialstring: $dialstring|CID: $original_cid|"; &agi_output;} + + +### Grab Server values from the database +$cbc=0; +$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks,voicemail_dump_exten_no_inst,routing_prefix 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; + $dbhP=$dbhA; $mysql_count='02004'; $MEL_aff_rows=$sthArows; &mysql_error_logging; +while ($sthArows > $cbc) + { + @aryA = $sthA->fetchrow_array; + $DBvoicemail_dump_exten = $aryA[0]; + $DBext_context = $aryA[1]; + $DBanswer_transfer_agent = $aryA[2]; + $DBSERVER_GMT = $aryA[3]; + $asterisk_version = $aryA[4]; + $DBmax_vicidial_trunks = $aryA[5]; + $voicemail_dump_exten_no_inst = $aryA[6]; + $routing_prefix = $aryA[7]; + 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 ($asterisk_version) {$AST_ver = $asterisk_version;} + if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;} + + $LOCAL_GMT_OFF = $SERVER_GMT; + $LOCAL_GMT_OFF_STD = $SERVER_GMT; + + if ($isdst) {$LOCAL_GMT_OFF++;} + if ($DB) {print "SEED TIME $now_date_epoch : $year-$mon-$mday $hour:$min:$sec LOCAL GMT OFFSET NOW: $LOCAL_GMT_OFF\n";} + + $cbc++; + } +$sthA->finish(); + + + +$AGI->stream_file('sip-silence'); +$AGI->stream_file('sip-silence'); + + +### Grab call details based on vicidial_manager record +$CALLserver_ip=''; +$CALLsession_id=''; +$CALLuser=''; +$stmtA = "SELECT server_ip,cmd_line_d FROM vicidial_manager where callerid='$calleridname' order by entry_date desc limit 1;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; + $dbhP=$dbhA; $mysql_count='02009'; $MEL_aff_rows=$sthArows; &mysql_error_logging; +if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $CALLserver_ip = $aryA[0]; + $CALLsession_id = $aryA[1]; + $CALLsession_id =~ s/Exten:| //gi; + } +$sthA->finish(); + +$stmtA = "SELECT user FROM vicidial_live_agents where lead_id='$lead_id' and server_ip='$CALLserver_ip' order by live_agent_id desc limit 1;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; + $dbhP=$dbhA; $mysql_count='02009'; $MEL_aff_rows=$sthArows; &mysql_error_logging; +if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $CALLuser = $aryA[0]; + } +$sthA->finish(); + +if ( (length($CALLuser) < 1) || (length($CALLserver_ip) < 5) || (length($CALLsession_id) < 1) ) + { + if ($AGILOG) {$agi_string = "3-WAY AGENT ERROR: no user/server/session found, exiting... |$CALLuser|$CALLserver_ip|$CALLsession_id|$calleridname|"; &agi_output;} + exit; + } + +if ($AGILOG) {$agi_string = "3-WAY DEBUG: user/server/session found: |$CALLuser|$CALLserver_ip|$CALLsession_id|$calleridname|"; &agi_output;} + + +$PADlead_id = sprintf("%010s", $lead_id); while (length($PADlead_id) > 10) {chop($PADlead_id);} +$VIDqueryCID = "T$CIDdate$PADlead_id"; +$newcallerid = "\"$VIDqueryCID <$original_cid>\""; +$CALLcontext = '@default'; + + +### Insert the call to vicidial_3way_press_live +$stmtA="INSERT INTO vicidial_3way_press_live SET call_date=NOW(),caller_code='$calleridname',call_3way_id='$VIDqueryCID',lead_id='$lead_id',phone_number='$phone_number',dialstring='$dialstring',outbound_cid='$original_cid',user='$CALLuser',session_id='$CALLsession_id',server_ip='$CALLserver_ip',session_id_3way='',status='NEW';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} +$affected_rowsA = $dbhA->do($stmtA); +if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live INSERT: |$affected_rowsA|$stmtA|"; &agi_output;} + +### Log the call to vicidial_3way_press_log +$stmtA="INSERT INTO vicidial_3way_press_log SET call_date=NOW(),caller_code='$calleridname',call_3way_id='$VIDqueryCID',lead_id='$lead_id',phone_number='$phone_number',dialstring='$dialstring',outbound_cid='$original_cid',user='$CALLuser',session_id='$CALLsession_id',server_ip='$CALLserver_ip',session_id_3way='',result='Started: $SQLdate';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} +$affected_rowsB = $dbhA->do($stmtA); +if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log LOG INSERT: |$affected_rowsB|$stmtA|"; &agi_output;} + +### Insert the outside-agent call into vicidial_manager +$stmtA="INSERT INTO vicidial_manager values('','',NOW(),'NEW','N','$CALLserver_ip','','Originate','$VIDqueryCID','Channel: Local/$dialstring$CALLcontext','Context: xfer_press_dialplan','Exten: s','Priority: 1','Callerid: $newcallerid','Variable: __lead_id=$lead_id','','','','');"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} +$affected_rowsG = $dbhA->do($stmtA); +if ($AGILOG) {$agi_string = "-- vicidial_manager INSERT: |$affected_rowsG|$stmtA|"; &agi_output;} + + +# loop every second until vicidial_3way_press_live record changes to status='ACCEPTED', then grab an unused session, update record and go into it +$CALLstatus=''; +$wait_loop=0; +while ($wait_loop < 100) + { + usleep(1*990*1000); + if ($wait_loop =~ /0$|5$/) + { + $AGI->stream_file('hold_tone'); + } + + $stmtA = "SELECT status FROM vicidial_3way_press_live where call_3way_id='$VIDqueryCID' order by call_date desc limit 1;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $dbhP=$dbhA; $mysql_count='02XXX'; $MEL_aff_rows=$sthArows; &mysql_error_logging; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $CALLstatus = $aryA[0]; + } + $sthA->finish(); + + if ($CALLstatus =~ /ACCEPTED/) + { + #grab open session + $free_session_count=0; + $stmtA="SELECT count(*) FROM vicidial_conferences where server_ip='$CALLserver_ip' and ((extension='') or (extension is null)) and conf_exten != '$CALLsession_id';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $dbhP=$dbhA; $mysql_count='02XXX'; $MEL_aff_rows=$sthArows; &mysql_error_logging; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $free_session_count = $aryA[0]; + } + $sthA->finish(); + + if ($free_session_count < 1) + { + if ($AGILOG) {$agi_string = "-- ERROR: no sessions available! |$CALLserver_ip|$stmtA|"; &agi_output;} + } + else + { + ### Update vicidial_conferences to grab available session + $stmtA="UPDATE vicidial_conferences set extension='Local/8300$CALLuser$tsSQLdate', leave_3way='0' where server_ip='$CALLserver_ip' and ((extension='') or (extension is null)) and conf_exten != '$CALLsession_id' limit 1;"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsC = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_conferences UPDATE: |$affected_rowsC|$stmtA|"; &agi_output;} + + # Grab the session_id that was reserved + $CALLconf_exten=''; + $stmtA="SELECT conf_exten from vicidial_conferences where server_ip='$CALLserver_ip' and extension='Local/8300$CALLuser$tsSQLdate' and conf_exten != '$CALLsession_id';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $dbhP=$dbhA; $mysql_count='02XXX'; $MEL_aff_rows=$sthArows; &mysql_error_logging; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $CALLconf_exten = $aryA[0]; + } + $sthA->finish(); + + if (length($CALLconf_exten) < 1) + { + if ($AGILOG) {$agi_string = "-- ERROR: no valid session available! |$CALLserver_ip|$stmtA|"; &agi_output;} + } + else + { + ### Update the call in vicidial_3way_press_live + $stmtA="UPDATE vicidial_3way_press_live SET status='RESERVED',session_id_3way='$CALLconf_exten' where call_3way_id='$VIDqueryCID';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsA = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live reserved UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;} + + ### Update the call in vicidial_3way_press_log + $stmtA="UPDATE vicidial_3way_press_log SET session_id_3way='$CALLconf_exten', result=CONCAT(result,'|Reserved: ',NOW()) where call_3way_id='$VIDqueryCID';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsA = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log reserved UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;} + + ### Update vicidial_conferences to leave_3way + # $stmtA="UPDATE vicidial_conferences set leave_3way='1', leave_3way_datetime=NOW(), extension='3WAY_$CALLuser' where server_ip='$CALLserver_ip' and conf_exten='$CALLconf_exten';"; + # if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + # $affected_rowsD = $dbhA->do($stmtA); + # if ($AGILOG) {$agi_string = "-- vicidial_conferences UPDATE: |$affected_rowsD|$stmtA|"; &agi_output;} + + if ($AGILOG) {$agi_string = "3-WAY AGENT TRANSFER: |$CALLuser|$CALLserver_ip|$CALLconf_exten|$calleridname|$VIDqueryCID|"; &agi_output;} + print "SET CONTEXT $ext_context\n"; + $result = ; + checkresult($result); + print "SET EXTENSION 7$CALLconf_exten\n"; + $result = ; + checkresult($result); + print "SET PRIORITY 1\n"; + $result = ; + checkresult($result); + + $wait_loop=1000; + exit; + } + } + } + + + if ($CALLstatus =~ /DECLINED/) + { + ### Delete the call in vicidial_3way_press_live + $stmtA="DELETE from vicidial_3way_press_live where call_3way_id='$VIDqueryCID';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsE = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live declined DELETE: |$affected_rowsE|$stmtA|"; &agi_output;} + + if ($AGILOG) {$agi_string = "3-WAY AGENT TRANSFER DECLINED: |$CALLuser|$CALLserver_ip|$CALLconf_exten|$calleridname|$VIDqueryCID|"; &agi_output;} + $AGI->stream_file('buzz'); + usleep(1*490*1000); + + exit; + } + + $wait_loop++; + } + + + + + +# send call to special extension with lead_id defined and handle_method set to CLOSER +exit; + + +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. + + +sub agi_output + { + ($Lsec,$Lmin,$Lhour,$Lmday,$Lmon,$Lyear,$Lwday,$Lyday,$Lisdst) = localtime(time); + if ($Lhour < 10) {$Lhour = "0$Lhour";} + if ($Lmin < 10) {$Lmin = "0$Lmin";} + if ($Lsec < 10) {$Lsec = "0$Lsec";} + $LOGtime = "$Lhour:$Lmin:$Lsec"; + + if ($AGILOG >=2) + { + ### open the log file for writing ### + open(Lout, ">>$AGILOGfile") + || die "Can't open $AGILOGfile: $!\n"; + print Lout "$now_date|$LOGtime|$script|$agi_string\n"; + close(Lout); + } + ### send to STDERR writing ### + if ( ($AGILOG == '1') || ($AGILOG == '3') ) + {print STDERR "$now_date|$LOGtime|$script|$agi_string\n";} + $agi_string=''; + } + + +sub mysql_error_logging + { + ($Lsec,$Lmin,$Lhour,$Lmday,$Lmon,$Lyear,$Lwday,$Lyday,$Lisdst) = localtime(time); + if ($Lhour < 10) {$Lhour = "0$Lhour";} + if ($Lmin < 10) {$Lmin = "0$Lmin";} + if ($Lsec < 10) {$Lsec = "0$Lsec";} + $LOGtime = "$Lhour:$Lmin:$Lsec"; + + $errno=''; + $error=''; + if ( ($mel > 0) || ($one_mysql_log > 0) ) + { + $errno = $dbhP->err(); + if ( ($errno > 0) || ($mel > 1) || ($one_mysql_log > 0) ) + { + $error = $dbhP->errstr(); + ### open the log file for writing ### + open(Eout, ">>$ERRLOGfile") + || die "Can't open $ERRLOGfile: $!\n"; + print Eout "$now_date|$LOGtime|$script|$mysql_count|$MEL_aff_rows|$errno|$error|$stmtA|$callerid|$insert_lead_id|\n"; + close(Eout); + } + } + $one_mysql_log=0; + } + +# subroutine to parse the asterisk version +# and return a hash with the various part +sub parse_asterisk_version + { + # grab the arguments + my $ast_ver_str = $_[0]; + + # get everything after the - and put it in $ast_ver_postfix + my @hyphen_parts = split( /-/ , $ast_ver_str ); + + my $ast_ver_postfix = $hyphen_parts[1]; + + # now split everything before the - up by the . + my @dot_parts = split( /\./ , $hyphen_parts[0] ); + + my %ast_ver_hash; + + if ( $dot_parts[0] <= 1 ) + { + %ast_ver_hash = ( + "major" => $dot_parts[0], + "minor" => $dot_parts[1], + "build" => $dot_parts[2], + "revision" => $dot_parts[3], + "postfix" => $ast_ver_postfix + ); + } + + # digium dropped the 1 from asterisk 10 but we still need it + if ( $dot_parts[0] > 1 ) + { + %ast_ver_hash = ( + "major" => 1, + "minor" => $dot_parts[0], + "build" => $dot_parts[1], + "revision" => $dot_parts[2], + "postfix" => $ast_ver_postfix + ); + } + + return ( %ast_ver_hash ); + } diff --git a/agi/agi-3way_press_outside.agi b/agi/agi-3way_press_outside.agi new file mode 100644 index 00000000..01ba7047 --- /dev/null +++ b/agi/agi-3way_press_outside.agi @@ -0,0 +1,627 @@ +#!/usr/bin/perl +# +# agi-3way_press_outside.agi version 2.14 +# +# Runs when a 3way call using a dial override is placed through a special +# extension from the agent screen to an outside-agent where that outside-agent +# will have to press-1 to accept the phone call. +# An example of the special extension: "49907917275551212" where: +# - 49907 is the special extension +# - 9 is the dial prefix +# - 1 is the phone code +# - 7275551212 is the outside-agent number to be dialed +# +# THIS IS THE SECOND REQUIRED AGI SCRIPT OF 2 FOR THIS FEATURE +# +# 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 stage of the outside-agent phone call: +# ; answered - outside-agent has answered the phone call +# ; declined - outside-agent has not pressed-1 in time and the call is to hung up +# ; accepted - outside-agent has pressed-1 and is to be sent to the agent +# +#; VICIdial outside-agent transfer after initiated by agent: +#[xfer_press_dialplan] +#exten => s,1,Answer +#exten => s,n,NoOp(${call_3way_id}) +#exten => s,n,NoOp(${CALLERID(name)}) +#exten => s,n,AGI(agi-3way_press_outside.agi,answered) +#exten => s,n,Playback(sip-silence) +#exten => s,n,Wait(1) +#exten => s,n,Background(outside-sales) +#exten => s,n,Background(press-1) +#exten => s,n,Background(now) +#exten => s,n,Wait(10) +#exten => s,n,AGI(agi-3way_press_outside.agi,declined) +#exten => s,n,Hangup +# +#exten => 1,1,NoOp(${call_3way_id}) +#exten => 1,n,NoOp(${CALLERID(name)}) +#exten => 1,n,AGI(agi-3way_press_outside.agi,accepted) +#exten => 1,n,Hangup() +# +#exten => t,1,Playback(buzz) +#exten => t,n,Hangup() +# +#exten => i,1,Playback(buzz) +#exten => i,n,Hangup() +# +# +# Copyright (C) 2023 Matt Florell LICENSE: AGPLv2 +# +# changes: +# 231113-2041 - First Build +# + +$script = 'agi-3way_press_outside.agi'; + +$at='@'; +$S='*'; +$mel=1; # Mysql Error Log enabled = 1 +$mysql_log_count=272; +$one_mysql_log=0; +$MT[0]=''; + + +$now_date_epoch = 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";} +$CIDdate = "$mon$mday$hour$min$sec"; +$tsSQLdate = "$year$mon$mday$hour$min$sec"; +$SQLdate = "$year-$mon-$mday $hour:$min:$sec"; +$SQLdateBEGIN = $SQLdate; + while (length($CIDdate) > 9) {$CIDdate =~ s/^.//gi;} # 0902235959 changed to 902235959 + +# 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 (!$TPALOGfile) {$TPALOGfile = "$PATHlogs/tpaout.$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 agi_output,local_gmt 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; + $dbhP=$dbhA; $mysql_count='02001'; $MEL_aff_rows=$sthArows; &mysql_error_logging; +$rec_count=0; +while ($sthArows > $rec_count) + { + $AGILOG = '0'; + @aryA = $sthA->fetchrow_array; + $DBagi_output = $aryA[0]; + $local_gmt = $aryA[1]; + if ($isdst) {$local_gmt++;} + if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';} + if ($DBagi_output =~ /FILE/) {$AGILOG = '2';} + if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';} + $rec_count++; + } +$sthA->finish(); + +############################################# +##### START SYSTEM SETTINGS LOOKUP ##### +$stmtA = "SELECT enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_log_id,queuemetrics_eq_prepend,queuemetrics_pe_phone_append,did_agent_log,alt_log_server_ip,alt_log_dbname,alt_log_login,alt_log_pass,tables_use_alt_log_db,did_ra_extensions_enabled,queuemetrics_socket,queuemetrics_socket_url,enable_did_entry_list_id,enable_drop_lists,inbound_answer_config,agent_search_method,abandon_check_queue,inbound_credits FROM system_settings;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; + $dbhP=$dbhA; $mysql_count='02026'; $MEL_aff_rows=$sthArows; &mysql_error_logging; +if ($sthArows > 0) + { + @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]; + $queuemetrics_pe_phone_append = $aryA[7]; + $did_agent_log = $aryA[8]; + $alt_log_server_ip = $aryA[9]; + $alt_log_dbname = $aryA[10]; + $alt_log_login = $aryA[11]; + $alt_log_pass = $aryA[12]; + $tables_use_alt_log_db = $aryA[13]; + $did_ra_extensions_enabled = $aryA[14]; + $queuemetrics_socket = $aryA[15]; + $queuemetrics_socket_url = $aryA[16]; + $enable_did_entry_list_id = $aryA[17]; + $enable_drop_lists = $aryA[18]; + $inbound_answer_config = $aryA[19]; + $SSagent_search_method = $aryA[20]; + $SSabandon_check_queue = $aryA[21]; + $SSinbound_credits = $aryA[22]; + } +$sthA->finish(); +##### END SYSTEM SETTINGS LOOKUP ##### +########################################### + +### 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]); + + $stage = $ARGV_vars[0]; + } + +$|=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_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 (/^agi_context\:\s+(.*)$/) {$context = $1;} + } +$callerid =~ s/\'|\\\\|\\\|\\|\\;|\\\;|\;|;//gi; +$calleridname =~ s/\'|\\\\|\\\|\\|\\;|\\\;|\;|;//gi; +$extension =~ s/\'|\"|\\\\|\\\|\\|\\;|\\\;|\;|;//gi; + + +if ($calleridname =~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^M\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^T\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/) + { + $lead_id = substr($calleridname, 10, 10); + $lead_id = ($lead_id + 0); + } +if ($calleridname =~ /^DC\d\d\d\d\d\dW\d\d\d\d\d\d\d\d\d\dW/) + { + $lead_id = substr($calleridname, 9, 10); + $lead_id = ($lead_id + 0); + } + +if ($calleridname =~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^T\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/) + {$callerid = $calleridname;} + +if ( ($callerid =~ /\".*\"/) && ( (!$calleridname) or ($calleridname =~ /unknown/) ) ) + { + $calleridname = $callerid; + $calleridname =~ s/\<\d\d\d\d\d\d\d\d\d\d\>//gi; + $calleridname =~ s/\"|\" //gi; + } + +if ($callerid !~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^M\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^T\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/) + { + $callerid =~ s/\D|\'//gi; + $calleridname =~ s/unknown|\'//gi; + if ( (!$callerid) or ($callerid =~ /unknown/) ) + {$callerid = $calleridname;} + } + +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|$stage|"; &agi_output;} + + +$CALLvendor_lead_code = $AGI->get_variable('vendor_lead_code'); +$CALLlead_id = $AGI->get_variable('lead_id'); + +if ($AGILOG) {$agi_string = "CALL Variables: |Lead ID: $lead_id($CALLlead_id) VLC: $CALLvendor_lead_code $callerid|"; &agi_output;} + + +if ($AGILOG) {$agi_string = "+++++ 3WAY PRESS OUTSIDE-AGENT STARTED : |$channel_group|$callerid|$now_date"; &agi_output;} + +$VDADphone=''; +$VDADphone_code=''; +$VCcallerid = $channel_group; +$VD_campaign_id = $channel_group; +if (length($VCcallerid)<2) + {$VCcallerid = 'ViciDial Inbound';} + + +### Grab Server values from the database +$cbc=0; +$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks,voicemail_dump_exten_no_inst,routing_prefix 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; + $dbhP=$dbhA; $mysql_count='02004'; $MEL_aff_rows=$sthArows; &mysql_error_logging; +while ($sthArows > $cbc) + { + @aryA = $sthA->fetchrow_array; + $DBvoicemail_dump_exten = $aryA[0]; + $DBext_context = $aryA[1]; + $DBanswer_transfer_agent = $aryA[2]; + $DBSERVER_GMT = $aryA[3]; + $asterisk_version = $aryA[4]; + $DBmax_vicidial_trunks = $aryA[5]; + $voicemail_dump_exten_no_inst = $aryA[6]; + $routing_prefix = $aryA[7]; + 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 ($asterisk_version) {$AST_ver = $asterisk_version;} + if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;} + + $LOCAL_GMT_OFF = $SERVER_GMT; + $LOCAL_GMT_OFF_STD = $SERVER_GMT; + + if ($isdst) {$LOCAL_GMT_OFF++;} + if ($DB) {print "SEED TIME $now_date_epoch : $year-$mon-$mday $hour:$min:$sec LOCAL GMT OFFSET NOW: $LOCAL_GMT_OFF\n";} + + $cbc++; + } +$sthA->finish(); + + +$AGI->stream_file('sip-silence'); +$AGI->stream_file('sip-silence'); + +### Grab call details based on vicidial_3way_press_live record +$CALLserver_ip=''; +$CALLsession_id=''; +$CALLuser=''; +$CALLlead_id=''; +$CALLsession_id_3way=''; +$stmtA = "SELECT server_ip,session_id,user,lead_id,session_id_3way FROM vicidial_3way_press_live where call_3way_id='$calleridname' order by call_date desc limit 1;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; + $dbhP=$dbhA; $mysql_count='02009'; $MEL_aff_rows=$sthArows; &mysql_error_logging; +if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $CALLserver_ip = $aryA[0]; + $CALLsession_id = $aryA[1]; + $CALLuser = $aryA[2]; + $CALLlead_id = $aryA[3]; + $CALLsession_id_3way = $aryA[4]; + } +$sthA->finish(); + +$stmtA = "SELECT user FROM vicidial_live_agents where lead_id='$lead_id' and server_ip='$CALLserver_ip' order by live_agent_id desc limit 1;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; + $dbhP=$dbhA; $mysql_count='02009'; $MEL_aff_rows=$sthArows; &mysql_error_logging; +if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $CALLuser = $aryA[0]; + } +$sthA->finish(); + +if ( (length($CALLuser) < 1) || (length($CALLserver_ip) < 5) || (length($CALLsession_id) < 1) ) + { + if ($AGILOG) {$agi_string = "3-WAY AGENT ERROR: no user/server/session found, exiting... |$CALLuser|$CALLserver_ip|$CALLsession_id|$calleridname|"; &agi_output;} + print "SET CONTEXT $context\n"; + $result = ; + checkresult($result); + print "SET EXTENSION i\n"; + $result = ; + checkresult($result); + print "SET PRIORITY 1\n"; + $result = ; + checkresult($result); + exit; + } + +if ($AGILOG) {$agi_string = "3-WAY DEBUG: user/server/session found: |$CALLuser|$CALLserver_ip|$CALLsession_id|$calleridname|"; &agi_output;} + +if ($stage =~ /answered/i) + { + ### Update the call in vicidial_3way_press_live + $stmtA="UPDATE vicidial_3way_press_live SET status='ANSWERED' where call_3way_id='$calleridname';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsA = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live answered UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;} + + ### Update the call in vicidial_3way_press_log + $stmtA="UPDATE vicidial_3way_press_log SET result=CONCAT(result,'|Answered: $SQLdate') where call_3way_id='$calleridname';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsA = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log answered UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;} + } + +if ($stage =~ /accepted/i) + { + ### Update the call in vicidial_3way_press_live + $stmtA="UPDATE vicidial_3way_press_live SET status='ACCEPTED' where call_3way_id='$calleridname';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsA = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live accepted UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;} + + ### Update the call in vicidial_3way_press_log + $stmtA="UPDATE vicidial_3way_press_log SET result=CONCAT(result,'|Accepted: $SQLdate') where call_3way_id='$calleridname';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsA = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log accepted UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;} + + + # loop until session_id_3way is populated + $CALLstatus=''; + $CALLconf_exten=''; + $wait_loop=0; + while ($wait_loop < 100) + { + usleep(1*990*1000); + if ($wait_loop =~ /0$|5$/) + { + $AGI->stream_file('hold_tone'); + } + + $stmtA = "SELECT status,session_id_3way FROM vicidial_3way_press_live where call_3way_id='$calleridname' order by call_date desc limit 1;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $dbhP=$dbhA; $mysql_count='02XXX'; $MEL_aff_rows=$sthArows; &mysql_error_logging; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $CALLstatus = $aryA[0]; + $CALLconf_exten = $aryA[1]; + } + $sthA->finish(); + + if ( ($CALLstatus =~ /RESERVED/) && (length($CALLconf_exten) > 0) ) + { + ### Update the call in vicidial_3way_press_live + $stmtA="UPDATE vicidial_3way_press_live SET status='TRANSFER' where call_3way_id='$calleridname';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsA = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live transfer UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;} + + ### Update the call in vicidial_3way_press_log + $stmtA="UPDATE vicidial_3way_press_log SET result=CONCAT(result,'|Transfer: ',NOW()) where call_3way_id='$calleridname';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsA = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log transfer UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;} + + ### Update vicidial_conferences to leave_3way=1 + $stmtA="UPDATE vicidial_conferences set leave_3way='1', leave_3way_datetime=NOW(), extension='3WAY_$CALLuser' where server_ip='$CALLserver_ip' and conf_exten='$CALLconf_exten';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsD = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_conferences UPDATE: |$affected_rowsD|$stmtA|"; &agi_output;} + + ### Delete the call in vicidial_3way_press_live + $stmtA="DELETE from vicidial_3way_press_live where call_3way_id='$calleridname';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsE = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live transfer DELETE: |$affected_rowsE|$stmtA|"; &agi_output;} + + if ($AGILOG) {$agi_string = "3-WAY AGENT TRANSFER: |$CALLuser|$CALLserver_ip|$CALLconf_exten|$calleridname|"; &agi_output;} + print "SET CONTEXT $ext_context\n"; + $result = ; + checkresult($result); + print "SET EXTENSION 7$CALLconf_exten\n"; + $result = ; + checkresult($result); + print "SET PRIORITY 1\n"; + $result = ; + checkresult($result); + + $wait_loop=1000; + exit; + } + + $wait_loop++; + } + + } + + +if ($stage =~ /declined/i) + { + ### Update the call in vicidial_3way_press_live + $stmtA="UPDATE vicidial_3way_press_live SET status='DECLINED' where call_3way_id='$calleridname';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsA = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_3way_press_live declined UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;} + + ### Update the call in vicidial_3way_press_log + $stmtA="UPDATE vicidial_3way_press_log SET result=CONCAT(result,'|Declined: $SQLdate') where call_3way_id='$calleridname';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsA = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- vicidial_3way_press_log declined UPDATE: |$affected_rowsA|$stmtA|"; &agi_output;} + } + + + + +exit; + + +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. + + +sub agi_output + { + ($Lsec,$Lmin,$Lhour,$Lmday,$Lmon,$Lyear,$Lwday,$Lyday,$Lisdst) = localtime(time); + if ($Lhour < 10) {$Lhour = "0$Lhour";} + if ($Lmin < 10) {$Lmin = "0$Lmin";} + if ($Lsec < 10) {$Lsec = "0$Lsec";} + $LOGtime = "$Lhour:$Lmin:$Lsec"; + + if ($AGILOG >=2) + { + ### open the log file for writing ### + open(Lout, ">>$AGILOGfile") + || die "Can't open $AGILOGfile: $!\n"; + print Lout "$now_date|$LOGtime|$script|$agi_string\n"; + close(Lout); + } + ### send to STDERR writing ### + if ( ($AGILOG == '1') || ($AGILOG == '3') ) + {print STDERR "$now_date|$LOGtime|$script|$agi_string\n";} + $agi_string=''; + } + + +sub mysql_error_logging + { + ($Lsec,$Lmin,$Lhour,$Lmday,$Lmon,$Lyear,$Lwday,$Lyday,$Lisdst) = localtime(time); + if ($Lhour < 10) {$Lhour = "0$Lhour";} + if ($Lmin < 10) {$Lmin = "0$Lmin";} + if ($Lsec < 10) {$Lsec = "0$Lsec";} + $LOGtime = "$Lhour:$Lmin:$Lsec"; + + $errno=''; + $error=''; + if ( ($mel > 0) || ($one_mysql_log > 0) ) + { + $errno = $dbhP->err(); + if ( ($errno > 0) || ($mel > 1) || ($one_mysql_log > 0) ) + { + $error = $dbhP->errstr(); + ### open the log file for writing ### + open(Eout, ">>$ERRLOGfile") + || die "Can't open $ERRLOGfile: $!\n"; + print Eout "$now_date|$LOGtime|$script|$mysql_count|$MEL_aff_rows|$errno|$error|$stmtA|$callerid|$insert_lead_id|\n"; + close(Eout); + } + } + $one_mysql_log=0; + } + +# subroutine to parse the asterisk version +# and return a hash with the various part +sub parse_asterisk_version + { + # grab the arguments + my $ast_ver_str = $_[0]; + + # get everything after the - and put it in $ast_ver_postfix + my @hyphen_parts = split( /-/ , $ast_ver_str ); + + my $ast_ver_postfix = $hyphen_parts[1]; + + # now split everything before the - up by the . + my @dot_parts = split( /\./ , $hyphen_parts[0] ); + + my %ast_ver_hash; + + if ( $dot_parts[0] <= 1 ) + { + %ast_ver_hash = ( + "major" => $dot_parts[0], + "minor" => $dot_parts[1], + "build" => $dot_parts[2], + "revision" => $dot_parts[3], + "postfix" => $ast_ver_postfix + ); + } + + # digium dropped the 1 from asterisk 10 but we still need it + if ( $dot_parts[0] > 1 ) + { + %ast_ver_hash = ( + "major" => 1, + "minor" => $dot_parts[0], + "build" => $dot_parts[1], + "revision" => $dot_parts[2], + "postfix" => $ast_ver_postfix + ); + } + + return ( %ast_ver_hash ); + } diff --git a/bin/ADMIN_archive_log_tables.pl b/bin/ADMIN_archive_log_tables.pl index 4353267f..08b6ad5a 100644 --- a/bin/ADMIN_archive_log_tables.pl +++ b/bin/ADMIN_archive_log_tables.pl @@ -69,6 +69,7 @@ # 230421-0057 - Added vicidial_agent_latency_summary_log archiving # 230507-0804 - Added vicidial_latency_gaps archiving # 231028-0810 - Added --url-log-only and --url-log-days=x options for purging of vicidial_url_log table only +# 231117-1914 - Added vicidial_3way_press_log archiving # $CALC_TEST=0; @@ -3444,6 +3445,58 @@ if (!$T) } + ##### vicidial_3way_press_log + $stmtA = "SELECT count(*) from vicidial_3way_press_log;"; + $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; + $vicidial_3way_press_log_count = $aryA[0]; + } + $sthA->finish(); + + $stmtA = "SELECT count(*) from vicidial_3way_press_log_archive;"; + $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; + $vicidial_3way_press_log_archive_count = $aryA[0]; + } + $sthA->finish(); + + if (!$Q) {print "\nProcessing vicidial_3way_press_log table... ($vicidial_3way_press_log_count|$vicidial_3way_press_log_archive_count)\n";} + $stmtA = "INSERT IGNORE INTO vicidial_3way_press_log_archive SELECT * from vicidial_3way_press_log;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows inserted into vicidial_3way_press_log_archive table \n";} + + $rv = $sthA->err(); + if (!$rv) + { + if ($wipe_all > 0) + {$stmtA = "DELETE FROM vicidial_3way_press_log;";} + else + {$stmtA = "DELETE FROM vicidial_3way_press_log WHERE call_date < '$del_time';";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows deleted from vicidial_3way_press_log table \n";} + + $stmtA = "optimize table vicidial_3way_press_log;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + + $stmtA = "optimize table vicidial_3way_press_log_archive;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + } + ##### vicidial_call_notes $stmtA = "SELECT count(*) from vicidial_call_notes;"; diff --git a/bin/AST_conf_update.pl b/bin/AST_conf_update.pl index 8cbfff2f..cc350ff4 100644 --- a/bin/AST_conf_update.pl +++ b/bin/AST_conf_update.pl @@ -4,7 +4,7 @@ # # This script checks if there are channels in reserved conferences # -# Copyright (C) 2020 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2023 Matt Florell LICENSE: AGPLv2 # # 50810-1532 - Added database server variable definitions lookup # 50823-1456 - Added commandline arguments for debug at runtime @@ -21,6 +21,7 @@ # 170916-0947 - Added support for AMI version 2+ # 180420-2302 - Fix for high-volume systems, added varibles to hangup queryCID # 200413-1356 - Fix for \n\n at the end of PING commands causing errors in AMI +# 231117-2254 - Added AMI version 5 compatibility # # constants @@ -350,6 +351,24 @@ if ($no_vc_3way_check < 1) if ($DB) {print "\n\n|$PTextensions[$i]|$PT_conf_extens[$i]|$COMMAND|\n";} @list_channels = $t->cmd(String => "$COMMAND", Prompt => '/--END COMMAND--\n\n/'); } + elsif ($ami_version =~ /^5\./i) + { + # get the current time + ( $now_sec, $now_micro_sec ) = gettimeofday(); + + # figure out how many micro seconds since epoch + $now_micro_epoch = $now_sec * 1000000; + $now_micro_epoch = $now_micro_epoch + $now_micro_sec; + + $begin_micro_epoch = $now_micro_epoch; + + # create a new action id + $action_id = "$now_sec.$now_micro_sec"; + + $COMMAND = "Action: Command\nActionID:$action_id\nCommand: Meetme list $PT_conf_extens[$i]"; + if ($DB) {print "\n\n|$PTextensions[$i]|$PT_conf_extens[$i]|$COMMAND|\n";} + @list_channels = $t->cmd(String => "$COMMAND", Prompt => '/\n\n/'); + } $j=0; $conf_empty[$i]=0; @@ -541,6 +560,24 @@ if ( !( ( @PTextensions == 1 ) && ( $PTextensions[0] eq '') ) ) if ($DB) {print "|$PTextensions[$i]|$PT_conf_extens[$i]|$COMMAND|\n";} @list_channels = $t->cmd(String => "$COMMAND", Prompt => '/--END COMMAND--/'); } + elsif ($ami_version =~ /^5\./i) + { + # get the current time + ( $now_sec, $now_micro_sec ) = gettimeofday(); + + # figure out how many micro seconds since epoch + $now_micro_epoch = $now_sec * 1000000; + $now_micro_epoch = $now_micro_epoch + $now_micro_sec; + + $begin_micro_epoch = $now_micro_epoch; + + # create a new action id + $action_id = "$now_sec.$now_micro_sec"; + + $COMMAND = "Action: Command\nActionID: $action_id\nCommand: Meetme list $PT_conf_extens[$i]"; + if ($DB) {print "|$PTextensions[$i]|$PT_conf_extens[$i]|$COMMAND|\n";} + @list_channels = $t->cmd(String => "$COMMAND", Prompt => '/\n\n/'); + } $j=0; $conf_empty[$i]=0; diff --git a/bin/AST_conf_update_3way.pl b/bin/AST_conf_update_3way.pl index 9057ab3b..31987daf 100644 --- a/bin/AST_conf_update_3way.pl +++ b/bin/AST_conf_update_3way.pl @@ -11,7 +11,7 @@ # script's crontab entry that does some of these functions: # AST_conf_update.pl --no-vc-3way-check # -# Copyright (C) 2020 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2023 Matt Florell LICENSE: AGPLv2 # # 100811-2119 - First build, based upon AST_conf_update.pl script # 100928-1506 - Changed from hard-coded 60 minute limit to servers.vicidial_recording_limit @@ -21,6 +21,7 @@ # 170921-1814 - Added support for AMI2 # 180420-2301 - Fix for high-volume systems, added varibles to hangup queryCID # 200413-1356 - Fix for \n\n at the end of PING commands causing errors in AMI +# 231117-2255 - Added AMI version 5 compatibility # # constants @@ -349,6 +350,25 @@ while ($loops > $loop_counter) &event_logger; @list_channels = $t->cmd(String => "$COMMAND", Prompt => '/--END COMMAND--\n\n/'); } + elsif ($ami_version =~ /^5\./i) + { + # get the current time + ( $now_sec, $now_micro_sec ) = gettimeofday(); + + # figure out how many micro seconds since epoch + $now_micro_epoch = $now_sec * 1000000; + $now_micro_epoch = $now_micro_epoch + $now_micro_sec; + + $begin_micro_epoch = $now_micro_epoch; + + # create a new action id + $action_id = "$now_sec.$now_micro_sec"; + + $COMMAND = "Action: Command\nActionID:$action_id\nCommand: Meetme list $PT_conf_extens[$i]"; + $event_string = "|$PT_conf_extens[$i]|$COMMAND|"; + &event_logger; + @list_channels = $t->cmd(String => "$COMMAND", Prompt => '/\n\n/'); + } $j=0; diff --git a/extras/MySQL_AST_CREATE_tables.sql b/extras/MySQL_AST_CREATE_tables.sql index 6bb7576e..cba7eff8 100644 --- a/extras/MySQL_AST_CREATE_tables.sql +++ b/extras/MySQL_AST_CREATE_tables.sql @@ -5049,6 +5049,44 @@ index(check_date), unique index vlgi (user,gap_date) ) ENGINE=MyISAM; +CREATE TABLE vicidial_3way_press_live ( +call_date DATETIME(6), +caller_code VARCHAR(30) NOT NULL, +call_3way_id VARCHAR(30) NOT NULL, +lead_id INT(9) UNSIGNED, +phone_number VARCHAR(18), +dialstring VARCHAR(28), +outbound_cid VARCHAR(20), +user VARCHAR(20), +session_id VARCHAR(20), +server_ip VARCHAR(15), +session_id_3way VARCHAR(20) default '', +status VARCHAR(40), +index(call_date), +index(caller_code), +index(call_3way_id), +index(lead_id) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_3way_press_log ( +call_date DATETIME(6), +caller_code VARCHAR(30) NOT NULL, +call_3way_id VARCHAR(30) NOT NULL, +lead_id INT(9) UNSIGNED, +phone_number VARCHAR(18), +dialstring VARCHAR(28), +outbound_cid VARCHAR(20), +user VARCHAR(20), +session_id VARCHAR(20), +server_ip VARCHAR(15), +session_id_3way VARCHAR(20) default '', +result TEXT, +index(call_date), +index(caller_code), +index(call_3way_id), +index(lead_id) +) ENGINE=MyISAM; + ALTER TABLE vicidial_email_list MODIFY message text character set utf8; @@ -5345,6 +5383,9 @@ CREATE UNIQUE INDEX vdalsla on vicidial_agent_latency_summary_log_archive (user, CREATE TABLE vicidial_latency_gaps_archive LIKE vicidial_latency_gaps; CREATE UNIQUE INDEX vdlga on vicidial_latency_gaps_archive (user,gap_date); +CREATE TABLE vicidial_3way_press_log_archive LIKE vicidial_3way_press_log; +CREATE UNIQUE INDEX vdpla on vicidial_3way_press_log_archive (call_date,caller_code,user); + CREATE TABLE vicidial_daily_rt_monitoring_log LIKE vicidial_rt_monitor_log; GRANT RELOAD ON *.* TO cron@'%'; @@ -5445,4 +5486,4 @@ INSERT INTO `wallboard_reports` VALUES ('AGENTS_AND_QUEUES','Agents and Queues', UPDATE system_settings set vdc_agent_api_active='1'; -UPDATE system_settings SET db_schema_version='1699',db_schema_update_date=NOW(),reload_timestamp=NOW(); +UPDATE system_settings SET db_schema_version='1700',db_schema_update_date=NOW(),reload_timestamp=NOW(); diff --git a/extras/upgrade_2.14.sql b/extras/upgrade_2.14.sql index 12ea645d..914b667a 100644 --- a/extras/upgrade_2.14.sql +++ b/extras/upgrade_2.14.sql @@ -2441,3 +2441,46 @@ ALTER TABLE vicidial_campaigns ADD hopper_hold_inserts ENUM('ENABLED','DISABLED' ALTER TABLE vicidial_hopper MODIFY status ENUM('READY','QUEUE','INCALL','DONE','HOLD','DNC','RHOLD','RQUEUE') default 'READY'; UPDATE system_settings SET db_schema_version='1699',db_schema_update_date=NOW() where db_schema_version < 1699; + +CREATE TABLE vicidial_3way_press_live ( +call_date DATETIME(6), +caller_code VARCHAR(30) NOT NULL, +call_3way_id VARCHAR(30) NOT NULL, +lead_id INT(9) UNSIGNED, +phone_number VARCHAR(18), +dialstring VARCHAR(28), +outbound_cid VARCHAR(20), +user VARCHAR(20), +session_id VARCHAR(20), +server_ip VARCHAR(15), +session_id_3way VARCHAR(20) default '', +status VARCHAR(40), +index(call_date), +index(caller_code), +index(call_3way_id), +index(lead_id) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_3way_press_log ( +call_date DATETIME(6), +caller_code VARCHAR(30) NOT NULL, +call_3way_id VARCHAR(30) NOT NULL, +lead_id INT(9) UNSIGNED, +phone_number VARCHAR(18), +dialstring VARCHAR(28), +outbound_cid VARCHAR(20), +user VARCHAR(20), +session_id VARCHAR(20), +server_ip VARCHAR(15), +session_id_3way VARCHAR(20) default '', +result TEXT, +index(call_date), +index(caller_code), +index(call_3way_id), +index(lead_id) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_3way_press_log_archive LIKE vicidial_3way_press_log; +CREATE UNIQUE INDEX vdpla on vicidial_3way_press_log_archive (call_date,caller_code,user); + +UPDATE system_settings SET db_schema_version='1700',db_schema_update_date=NOW() where db_schema_version < 1700; diff --git a/www/vicidial/admin_modify_lead.php b/www/vicidial/admin_modify_lead.php index b7d9004b..70d9281e 100644 --- a/www/vicidial/admin_modify_lead.php +++ b/www/vicidial/admin_modify_lead.php @@ -115,6 +115,7 @@ # 230205-2135 - Small fix for ignore_group_on_search issue # 230307-1326 - Small fix for closer calls DID display, Issue #1447 # 230309-1444 - Added Inbound Call Menu Log display as part of IVR Log section +# 231117-1920 - Added vicidial_3way_press_log display # require("dbconnect_mysqli.php"); @@ -3380,6 +3381,66 @@ else } + if ($CIDdisplay=="Yes") + { + echo ""._QXZ("3-WAY PRESS LOGS FOR THIS LEAD").":\n"; + echo "\n"; + echo "\n"; + + $stmt="SELECT phone_number,call_date,user,result from vicidial_3way_press_log where lead_id='" . mysqli_real_escape_string($link, $lead_id) . "' order by call_date desc limit 500;"; + $rslt=mysql_to_mysqli($stmt, $link); + $logs_to_print = mysqli_num_rows($rslt); + if ($DB) {echo "$logs_to_print|$stmt|\n";} + + $u=0; + while ($logs_to_print > $u) + { + $row=mysqli_fetch_row($rslt); + if (preg_match("/1$|3$|5$|7$|9$/i", $u)) + {$bgcolor="bgcolor=\"#$SSstd_row2_background\"";} + else + {$bgcolor="bgcolor=\"#$SSstd_row1_background\"";} + + $u++; + echo ""; + echo ""; + echo ""; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + + if ($archive_log=="Yes") + { + $stmt="SELECT phone_number,call_date,user,result from vicidial_3way_press_log_archive where lead_id='" . mysqli_real_escape_string($link, $lead_id) . "' order by call_date desc limit 500;"; + $rslt=mysql_to_mysqli($stmt, $link); + $logs_to_print = mysqli_num_rows($rslt); + if ($DB) {echo "$logs_to_print|$stmt|\n";} + + $u=0; + while ($logs_to_print > $u) + { + $row=mysqli_fetch_row($rslt); + if (preg_match("/1$|3$|5$|7$|9$/i", $u)) + {$bgcolor="bgcolor=\"#$SSstd_row2_background\"";} + else + {$bgcolor="bgcolor=\"#$SSstd_row1_background\"";} + + $u++; + echo ""; + echo ""; + echo ""; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + } + echo "
# "._QXZ("PHONE").""._QXZ("DATE/TIME")." "._QXZ("USER")." "._QXZ("RESULT")."
$u $row[0] $row[1] $row[2] $row[3]  
$u $row[0] $row[1] $row[2] $row[3]  


\n"; + } + + ##### BEGIN switch lead log entries ##### $stmt="SELECT * from vicidial_agent_function_log where lead_id='" . mysqli_real_escape_string($link, $lead_id) . "' and function='switch_lead' order by event_time desc limit 500;"; $rslt=mysql_to_mysqli($stmt, $link);