From c8cd121e9ad0166a9fe294eca2e1ccb19ae0d3f1 Mon Sep 17 00:00:00 2001 From: mattf Date: Fri, 6 Jul 2012 21:01:55 +0000 Subject: [PATCH] Added option to allow for SQL qualifying of a lead before playing a Call Menu git-svn-id: svn://192.168.202.10@1838 3d104415-ff17-0410-8863-d5cf3c621b8a --- UPGRADE | 5 + agi/agi-VDAD_inbound_calltime_check.agi | 83 ++++++++++++-- bin/ADMIN_keepalive_ALL.pl | 19 +++- extras/MySQL_AST_CREATE_tables.sql | 8 +- extras/upgrade_2.6.sql | 6 + .../TO_BE_TRANSLATED_2.6.txt | 4 + www/vicidial/admin.php | 105 +++++++++++++++--- 7 files changed, 198 insertions(+), 32 deletions(-) diff --git a/UPGRADE b/UPGRADE index cdad4714..3df82014 100644 --- a/UPGRADE +++ b/UPGRADE @@ -71,6 +71,11 @@ OTHER CHANGES: 6. Added Japanese agent web interface translation +7. Added ability to qualify callers before they go through a Call Menu by using + a SQL fragment(like in Filters) that you define in a Call Menu. Must be + enabled in System Settings. Calls must be passed from an outbound + campaign or an in-group. + diff --git a/agi/agi-VDAD_inbound_calltime_check.agi b/agi/agi-VDAD_inbound_calltime_check.agi index 2f475ff3..b8e5fcc3 100644 --- a/agi/agi-VDAD_inbound_calltime_check.agi +++ b/agi/agi-VDAD_inbound_calltime_check.agi @@ -20,10 +20,15 @@ # ; 5. call route after hours override # ; 6. call route value after hours override # ; 7. call route context after hours override +# ; 8. vicidial_list query qualification (YES/NO, default is NO) +# ; * only works with lead_id-populated calleridname phone calls. +# ; This option allows you to specify a SQL fragment used to do a count(*) +# ; against the vicidial_list table for the lead and other field values +# ; This feature will look for the qualify_sql in the cacll menu record # ; # ;inbound calls check calltime: #exten => 1234,1,Answer ; Answer the line -#exten => 1234,2,AGI(agi-VDAD_inbound_calltime_check.agi,INBOUND-----YES-----START-----24hours-----EXTENSION-----101-----default) +#exten => 1234,2,AGI(agi-VDAD_inbound_calltime_check.agi,INBOUND-----YES-----START-----24hours-----EXTENSION-----101-----default-----NO) #exten => 1234,3,Hangup # # Copyright (C) 2012 Matt Florell LICENSE: AGPLv2 @@ -40,6 +45,7 @@ # 110525-1347 - Added compatibility for outbound IVR logging # 111229-1716 - Changed call time overflow to look at previous day stop time # 120517-1257 - Added CALLMENU timeout option +# 120706-1659 - Added Qualify SQL option # $script = 'agi-VDAD_inbound_calltime_check.agi'; @@ -145,7 +151,7 @@ $sthA->finish(); ############################################# ##### 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;"; +$stmtA = "SELECT enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_log_id,queuemetrics_eq_prepend,call_menu_qualify_enabled FROM system_settings;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -153,12 +159,13 @@ 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_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]; + $call_menu_qualify_enabled = $aryA[7]; } $sthA->finish(); ##### END QUEUEMETRICS LOGGING LOOKUP ##### @@ -188,6 +195,7 @@ if (length($ARGV[0])>1) $route_override = $ARGV_vars[4]; $route_value_override = $ARGV_vars[5]; $route_context_override = $ARGV_vars[6]; + $query_qualification = $ARGV_vars[7]; } $|=1; @@ -215,6 +223,7 @@ while() $outboundIVR=0; $ingroupIVR=0; +$lead_id=''; 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/) { $callerid = $calleridname; @@ -538,6 +547,64 @@ if ( ( ($hm < $ct_default_start) || ($hm > $ct_default_stop) ) && ($hm >= $ct_st + +##### BEGIN QUALIFY SQL CHECK ##### +if ( ($call_menu_qualify_enabled > 0) && ($query_qualification =~ /YES/) && ( ($outboundIVR > 0) || ($ingroupIVR > 0) ) ) + { + $qualify_count=0; + $stmtA = "SELECT qualify_sql FROM vicidial_call_menu where menu_id='$context';"; + $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; + $qualify_sql = $aryA[0]; + } + $sthA->finish(); + + if (length($qualify_sql) > 5) + { + $lead_id = substr($calleridname, 10, 10); + $lead_id = ($lead_id + 0); + + $stmtA = "SELECT count(*) FROM vicidial_list where lead_id='$lead_id' and $qualify_sql;"; + $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; + $qualify_count = $aryA[0]; + } + $sthA->finish(); + + if ($AGILOG) {$agi_string = "Exiting the TimeCheck App Qualify SQL |$qualify_count|$lead_id|$context|$calleridname|$stmtA|"; &agi_output;} + + if ($qualify_count < 1) + { + $AGI->stream_file('sip-silence'); # stop music-on-hold process + $AGI->stream_file('sip-silence'); # stop music-on-hold process + + # sleep for one tenth of a second + usleep(1*100*1000); + + if ($AGILOG) {$agi_string = " TimeCheck App Qualify SQL FAIL, transferring call to D |$qualify_count|$lead_id|$context|$calleridname|"; &agi_output;} + + print "SET CONTEXT $context\n"; + checkresult($result); + print "SET EXTENSION D\n"; + checkresult($result); + print "SET PRIORITY 1\n"; + checkresult($result); + + exit; + } + } + } +##### END QUALIFY SQL CHECK ##### + + ### insert an IVR record to the vicidial_auto_calls table if ($outboundIVR > 0) { diff --git a/bin/ADMIN_keepalive_ALL.pl b/bin/ADMIN_keepalive_ALL.pl index 2f72e367..fc730123 100644 --- a/bin/ADMIN_keepalive_ALL.pl +++ b/bin/ADMIN_keepalive_ALL.pl @@ -72,6 +72,7 @@ # 120209-1525 - Separated all vicidial-auto dialplan contexts into their own contexts to allow for more control of dialing access through phones # 120213-1405 - Added vicidial_daily_ra_stats rolling # 120512-2332 - Added loopback dialaround for ringing of calls +# 120706-1325 - Added Call Menu qualify SQL option # $DB=0; # Debug flag @@ -1132,7 +1133,7 @@ if ($timeclock_end_of_day_NOW > 0) ################################################################################ ##### Get the settings from system_settings ##### -$stmtA = "SELECT sounds_central_control_active,active_voicemail_server,custom_dialplan_entry,default_codecs,generate_cross_server_exten,voicemail_timezones,default_voicemail_timezone FROM system_settings;"; +$stmtA = "SELECT sounds_central_control_active,active_voicemail_server,custom_dialplan_entry,default_codecs,generate_cross_server_exten,voicemail_timezones,default_voicemail_timezone,call_menu_qualify_enabled FROM system_settings;"; # print "$stmtA\n"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -1146,7 +1147,8 @@ if ($sthArows > 0) $SSdefault_codecs = $aryA[3]; $SSgenerate_cross_server_exten = $aryA[4]; $SSvoicemail_timezones = $aryA[5]; - $SSdefault_voicemail_timezone = $aryA[6]; + $SSdefault_voicemail_timezone = $aryA[6]; + $SScall_menu_qualify_enabled = $aryA[7]; } $sthA->finish(); if ($DBXXX > 0) {print "SYSTEM SETTINGS: $sounds_central_control_active|$active_voicemail_server|$SScustom_dialplan_entry|$SSdefault_codecs\n";} @@ -1958,7 +1960,7 @@ if ( ($active_asterisk_server =~ /Y/) && ($generate_vicidial_conf =~ /Y/) && ($r ##### BEGIN Generate the Call Menu entries ##### - $stmtA = "SELECT menu_id,menu_name,menu_prompt,menu_timeout,menu_timeout_prompt,menu_invalid_prompt,menu_repeat,menu_time_check,call_time_id,track_in_vdac,custom_dialplan_entry,tracking_group,dtmf_log,dtmf_field FROM vicidial_call_menu order by menu_id;"; + $stmtA = "SELECT menu_id,menu_name,menu_prompt,menu_timeout,menu_timeout_prompt,menu_invalid_prompt,menu_repeat,menu_time_check,call_time_id,track_in_vdac,custom_dialplan_entry,tracking_group,dtmf_log,dtmf_field,qualify_sql FROM vicidial_call_menu order by menu_id;"; # print "$stmtA\n"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -1981,11 +1983,16 @@ if ( ($active_asterisk_server =~ /Y/) && ($generate_vicidial_conf =~ /Y/) && ($r $tracking_group[$i] = $aryA[11]; $dtmf_log[$i] = $aryA[12]; $dtmf_field[$i] = $aryA[13]; + $qualify_sql[$i] = $aryA[14]; if ($track_in_vdac[$i] > 0) - {$track_in_vdac[$i] = 'YES'} + {$track_in_vdac[$i] = 'YES';} else - {$track_in_vdac[$i] = 'NO'} + {$track_in_vdac[$i] = 'NO';} + if ( (length($qualify_sql[$i]) > 5) && ($SScall_menu_qualify_enabled > 0) ) + {$qualify_sql_active[$i] = 'YES';} + else + {$qualify_sql_active[$i] = 'NO';} $i++; } $sthA->finish(); @@ -2304,7 +2311,7 @@ if ( ($active_asterisk_server =~ /Y/) && ($generate_vicidial_conf =~ /Y/) && ($r $call_menu_ext .= "; $menu_name[$i]\n"; $call_menu_ext .= "[$menu_id[$i]]\n"; $call_menu_ext .= "exten => s,1,Answer\n"; - $call_menu_ext .= "exten => s,n,AGI(agi-VDAD_inbound_calltime_check.agi,$tracking_group[$i]-----$track_in_vdac[$i]-----$menu_id[$i]-----$time_check_scheme-----$time_check_route-----$time_check_route_value-----$time_check_route_context)\n"; + $call_menu_ext .= "exten => s,n,AGI(agi-VDAD_inbound_calltime_check.agi,$tracking_group[$i]-----$track_in_vdac[$i]-----$menu_id[$i]-----$time_check_scheme-----$time_check_route-----$time_check_route_value-----$time_check_route_context-----$qualify_sql_active[$i])\n"; $call_menu_ext .= "exten => s,n,Set(INVCOUNT=0) \n"; $call_menu_ext .= "$menu_prompt_ext"; if ($menu_timeout[$i] > 0) diff --git a/extras/MySQL_AST_CREATE_tables.sql b/extras/MySQL_AST_CREATE_tables.sql index 74deaf20..1b7e6a90 100644 --- a/extras/MySQL_AST_CREATE_tables.sql +++ b/extras/MySQL_AST_CREATE_tables.sql @@ -1481,7 +1481,8 @@ pllb_grouping_limit SMALLINT(5) default '100', did_ra_extensions_enabled ENUM('0','1') default '0', expanded_list_stats ENUM('0','1') default '1', contacts_enabled ENUM('0','1') default '0', -svn_version VARCHAR(100) default '' +svn_version VARCHAR(100) default '', +call_menu_qualify_enabled ENUM('0','1') default '0' ); CREATE TABLE vicidial_campaigns_list_mix ( @@ -1924,7 +1925,8 @@ custom_dialplan_entry TEXT, tracking_group VARCHAR(20) default 'CALLMENU', dtmf_log ENUM('0','1') default '0', dtmf_field VARCHAR(50) default 'NONE', -user_group VARCHAR(20) default '---ALL---' +user_group VARCHAR(20) default '---ALL---', +qualify_sql TEXT ); CREATE TABLE vicidial_call_menu_options ( @@ -2813,7 +2815,7 @@ CREATE TABLE vicidial_log_noanswer_archive LIKE vicidial_log_noanswer; CREATE TABLE vicidial_did_agent_log_archive LIKE vicidial_did_agent_log; CREATE UNIQUE INDEX vdala on vicidial_did_agent_log_archive (uniqueid,call_date,did_route); -UPDATE system_settings SET db_schema_version='1321',db_schema_update_date=NOW(); +UPDATE system_settings SET db_schema_version='1322',db_schema_update_date=NOW(); GRANT RELOAD ON *.* TO cron@'%'; GRANT RELOAD ON *.* TO cron@localhost; diff --git a/extras/upgrade_2.6.sql b/extras/upgrade_2.6.sql index 07f8bd38..4823a56c 100644 --- a/extras/upgrade_2.6.sql +++ b/extras/upgrade_2.6.sql @@ -14,3 +14,9 @@ UPDATE system_settings SET db_schema_version='1320',db_schema_update_date=NOW() ALTER TABLE vicidial_campaigns ADD safe_harbor_audio_field VARCHAR(30) default 'DISABLED'; UPDATE system_settings SET db_schema_version='1321',db_schema_update_date=NOW() where db_schema_version < 1321; + +ALTER TABLE system_settings ADD call_menu_qualify_enabled ENUM('0','1') default '0'; + +ALTER TABLE vicidial_call_menu ADD qualify_sql TEXT; + +UPDATE system_settings SET db_schema_version='1322',db_schema_update_date=NOW() where db_schema_version < 1322; diff --git a/translations/raw_translation_files/TO_BE_TRANSLATED_2.6.txt b/translations/raw_translation_files/TO_BE_TRANSLATED_2.6.txt index d76d7613..e059a957 100644 --- a/translations/raw_translation_files/TO_BE_TRANSLATED_2.6.txt +++ b/translations/raw_translation_files/TO_BE_TRANSLATED_2.6.txt @@ -9,6 +9,10 @@ You can also use LTMG or XFTAMM as statuses to trigger an automatic transfer to Send to Answering Machine Message|| Safe Harbor Audio Field|| This optional setting allows you to define a field in the list that the system will use as the audio filename for each lead in place of the Safe Harbor Audio file. If this is set to DISABLED the Safe Harbor Audio file will always be used. The system will do no validation to make sure that the audio file exists other than to make sure the value of the field is at least one character, so if you want a lead to use the default Safe harbor Audio then you just set the field value in the lead to empty. You can use the pipe character to link multiple audio files together in the field value for each lead. Default is DISABLED. Here is the list of fields that can be used for this setting|| +Call Menu Qualify Enabled|| +This setting enables the option in Call Menus to put a SQL qualification on the people that hear that call menu. For more information on how that feature works, view the help for Call Menus. Default is 0 for disabled|| +Qualify SQL|| +This field allows you to input SQL - Structured Query Language - database fragments, like with Filters, to determine whether this call menu should play for the caller or not. This feature only works if the call has the callerIDname set prior to being sent to this call menu, either as an outbound survey transfer, or through the use of a drop call menu for an In-Group call. If there is a match, the call will proceed as normal. If there is no match, the call will go to the D option or the invalid option if no D option is set. You cannot use single-quotes in this field, only double-quotes if they are needed. Default is empty for disabled|| ############################################################ CLIENT diff --git a/www/vicidial/admin.php b/www/vicidial/admin.php index a9124934..e57e0f52 100644 --- a/www/vicidial/admin.php +++ b/www/vicidial/admin.php @@ -1736,6 +1736,14 @@ if (isset($_GET["dial_ingroup_cid"])) {$dial_ingroup_cid=$_GET["dial_ingroup_c elseif (isset($_POST["dial_ingroup_cid"])) {$dial_ingroup_cid=$_POST["dial_ingroup_cid"];} if (isset($_GET["safe_harbor_audio_field"])) {$safe_harbor_audio_field=$_GET["safe_harbor_audio_field"];} elseif (isset($_POST["safe_harbor_audio_field"])) {$safe_harbor_audio_field=$_POST["safe_harbor_audio_field"];} +if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} + elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} +if (isset($_GET["end_date"])) {$end_date=$_GET["end_date"];} + elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];} +if (isset($_GET["call_menu_qualify_enabled"])) {$call_menu_qualify_enabled=$_GET["call_menu_qualify_enabled"];} + elseif (isset($_POST["call_menu_qualify_enabled"])) {$call_menu_qualify_enabled=$_POST["call_menu_qualify_enabled"];} +if (isset($_GET["qualify_sql"])) {$qualify_sql=$_GET["qualify_sql"];} + elseif (isset($_POST["qualify_sql"])) {$qualify_sql=$_POST["qualify_sql"];} if (isset($script_id)) {$script_id= strtoupper($script_id);} @@ -1749,7 +1757,7 @@ if (strlen($dial_status) > 0) ############################################# ##### START SYSTEM_SETTINGS LOOKUP ##### -$stmt = "SELECT use_non_latin,enable_queuemetrics_logging,enable_vtiger_integration,qc_features_active,outbound_autodial_active,sounds_central_control_active,enable_second_webform,user_territories_active,custom_fields_enabled,admin_web_directory,webphone_url,first_login_trigger,hosted_settings,default_phone_registration_password,default_phone_login_password,default_server_password,test_campaign_calls,active_voicemail_server,voicemail_timezones,default_voicemail_timezone,default_local_gmt,campaign_cid_areacodes_enabled,pllb_grouping_limit,did_ra_extensions_enabled,expanded_list_stats,contacts_enabled,alt_log_server_ip,alt_log_dbname,alt_log_login,alt_log_pass,tables_use_alt_log_db FROM system_settings;"; +$stmt = "SELECT use_non_latin,enable_queuemetrics_logging,enable_vtiger_integration,qc_features_active,outbound_autodial_active,sounds_central_control_active,enable_second_webform,user_territories_active,custom_fields_enabled,admin_web_directory,webphone_url,first_login_trigger,hosted_settings,default_phone_registration_password,default_phone_login_password,default_server_password,test_campaign_calls,active_voicemail_server,voicemail_timezones,default_voicemail_timezone,default_local_gmt,campaign_cid_areacodes_enabled,pllb_grouping_limit,did_ra_extensions_enabled,expanded_list_stats,contacts_enabled,alt_log_server_ip,alt_log_dbname,alt_log_login,alt_log_pass,tables_use_alt_log_db,call_menu_qualify_enabled FROM system_settings;"; $rslt=mysql_query($stmt, $link); if ($DB) {echo "$stmt\n";} $qm_conf_ct = mysql_num_rows($rslt); @@ -1787,6 +1795,7 @@ if ($qm_conf_ct > 0) $SSalt_log_login = $row[28]; $SSalt_log_pass = $row[29]; $SStables_use_alt_log_db = $row[30]; + $SScall_menu_qualify_enabled = $row[31]; } ##### END SETTINGS LOOKUP ##### ########################################### @@ -2023,6 +2032,7 @@ if ($non_latin < 1) $max_calls_count = ereg_replace("[^0-9]","",$max_calls_count); $report_rank = ereg_replace("[^0-9]","",$report_rank); $dial_ingroup_cid = ereg_replace("[^0-9]","",$dial_ingroup_cid); + $call_menu_qualify_enabled = ereg_replace("[^0-9]","",$call_menu_qualify_enabled); $drop_call_seconds = ereg_replace("[^-0-9]","",$drop_call_seconds); @@ -2646,6 +2656,10 @@ if ($non_latin < 1) $modify_url = ereg_replace(";","",$modify_url); $modify_url = ereg_replace("\r","",$modify_url); $modify_url = ereg_replace("\"","",$modify_url); + $qualify_sql = ereg_replace("\\\\","",$qualify_sql); + $qualify_sql = ereg_replace(";","",$qualify_sql); + $qualify_sql = ereg_replace("\r","",$qualify_sql); + $qualify_sql = ereg_replace("'",'"',$qualify_sql); ### VARIABLES TO BE mysql_real_escape_string ### # $web_form_address # $queuemetrics_url @@ -3063,12 +3077,13 @@ else # 120518-1456 - Added XFTAMM/LTMG special hotkeys for send to answering machine message # 120526-0827 - Added User Group User Login Report # 120529-2112 - Added safe_harbor_audio_field campaign option +# 120706-1255 - Added Max stats date range and call menu qualify_sql options # # make sure you have added a user to the vicidial_users MySQL table with at least user_level 8 to access this page the first time -$admin_version = '2.6-370a'; -$build = '120529-2112'; +$admin_version = '2.6-371a'; +$build = '120706-1255'; $STARTtime = date("U"); $SQLdate = date("Y-m-d H:i:s"); @@ -3353,6 +3368,8 @@ echo "