From e3539915ce68ef89db057707e64c35377df7eb63 Mon Sep 17 00:00:00 2001 From: mattf Date: Fri, 14 Feb 2014 21:52:59 +0000 Subject: [PATCH] Fixed minor admin bugs Added Non-Agent API functions: server_refresh, check_phone_number git-svn-id: svn://192.168.202.10@2072 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/UPGRADE | 2 + agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl | 18 +- agc_2-X/trunk/docs/NON-AGENT_API.txt | 83 ++++- .../trunk/extras/MySQL_AST_CREATE_tables.sql | 5 +- agc_2-X/trunk/extras/upgrade_2.8.sql | 4 + .../trunk/www/vicidial/AST_timeonVDADall.php | 35 +- agc_2-X/trunk/www/vicidial/admin.php | 15 +- .../vicidial/admin_listloader_fourth_gen.php | 33 +- agc_2-X/trunk/www/vicidial/non_agent_api.php | 350 +++++++++++++++++- 9 files changed, 503 insertions(+), 42 deletions(-) diff --git a/agc_2-X/trunk/UPGRADE b/agc_2-X/trunk/UPGRADE index 14211670..a490f223 100644 --- a/agc_2-X/trunk/UPGRADE +++ b/agc_2-X/trunk/UPGRADE @@ -186,6 +186,8 @@ OTHER CHANGES: 32. Added Non-Agent API function update_user to allow updating of the major user fields +33. Added Non-Agent API functions for check_phone_number and server_refresh + diff --git a/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl b/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl index 477b0bf9..d3b12ec7 100644 --- a/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl +++ b/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl @@ -92,9 +92,10 @@ # 140112-1910 - Fixed issue with MoH in Astrisk 1.8 # 140126-1153 - Added VMAIL_NO_INST option dialplan generation # 140126-2252 - Added voicemail_instructions option for phones +# 140214-1519 - Added reload_timestamp value to conf files # -$build = '140126-2252'; +$build = '140214-1519'; $DB=0; # Debug flag $MT[0]=''; $MT[1]=''; @@ -1280,7 +1281,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,call_menu_qualify_enabled,allow_voicemail_greeting 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,allow_voicemail_greeting,reload_timestamp FROM system_settings;"; # print "$stmtA\n"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -1297,6 +1298,7 @@ if ($sthArows > 0) $SSdefault_voicemail_timezone = $aryA[6]; $SScall_menu_qualify_enabled = $aryA[7]; $SSallow_voicemail_greeting = $aryA[8]; + $SSreload_timestamp = $aryA[9]; } $sthA->finish(); if ($DBXXX > 0) {print "SYSTEM SETTINGS: $sounds_central_control_active|$active_voicemail_server|$SScustom_dialplan_entry|$SSdefault_codecs\n";} @@ -3014,32 +3016,32 @@ if ( ($active_asterisk_server =~ /Y/) && ($generate_vicidial_conf =~ /Y/) && ($r if (length($SScustom_dialplan_entry)>5) {print ext "include => vicidial-auto-system-setting-custom\n";} print ext "\n"; - print ext "\n; END OF FILE\n"; + print ext "\n; END OF FILE Last Forced System Reload: $SSreload_timestamp\n"; print iax "; WARNING- THIS FILE IS AUTO-GENERATED BY VICIDIAL, ANY EDITS YOU MAKE WILL BE LOST\n"; print iax "$iax\n"; print iax "$Liax\n"; print iax "$Piax\n"; - print iax "\n; END OF FILE\n"; + print iax "\n; END OF FILE Last Forced System Reload: $SSreload_timestamp\n"; print sip "; WARNING- THIS FILE IS AUTO-GENERATED BY VICIDIAL, ANY EDITS YOU MAKE WILL BE LOST\n"; print sip "$sip\n"; print sip "$Lsip\n"; print sip "$Psip\n"; - print sip "\n; END OF FILE\n"; + print sip "\n; END OF FILE Last Forced System Reload: $SSreload_timestamp\n"; # print vm "; WARNING- THIS FILE IS AUTO-GENERATED BY VICIDIAL, ANY EDITS YOU MAKE WILL BE LOST\n"; print vm "$vm_header_content\n"; print vm "$vm\n"; - print vm "\n; END OF FILE\n"; + print vm "\n; END OF FILE Last Forced System Reload: $SSreload_timestamp\n"; print moh "; WARNING- THIS FILE IS AUTO-GENERATED BY VICIDIAL, ANY EDITS YOU MAKE WILL BE LOST\n"; print moh "$moh\n"; - print moh "\n; END OF FILE\n"; + print moh "\n; END OF FILE Last Forced System Reload: $SSreload_timestamp\n"; print mm "; WARNING- THIS FILE IS AUTO-GENERATED BY VICIDIAL, ANY EDITS YOU MAKE WILL BE LOST\n"; print mm "$mm\n"; - print mm "\n; END OF FILE\n"; + print mm "\n; END OF FILE Last Forced System Reload: $SSreload_timestamp\n"; close(ext); close(iax); diff --git a/agc_2-X/trunk/docs/NON-AGENT_API.txt b/agc_2-X/trunk/docs/NON-AGENT_API.txt index bf000728..be4e980e 100644 --- a/agc_2-X/trunk/docs/NON-AGENT_API.txt +++ b/agc_2-X/trunk/docs/NON-AGENT_API.txt @@ -1,4 +1,4 @@ -NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2014-02-06 +NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2014-02-14 This document describes the functions of an API(Application Programming Interface) for all functions NOT directly relating to the VICIDIAL Agent screen. @@ -36,6 +36,8 @@ user_group_status - real-time status of one or more user groups in_group_status - real-time status of one or more in groups agent_status - real-time status of one user callid_info - information about a call based upon the caller_code or call ID +server_refresh - forces a conf file refresh on all telco servers in the cluster +check_phone_number - allows you to check if a phone number is valid and dialable New scripts: @@ -88,6 +90,8 @@ Changes: 130617-2232 - Added real-time sub-statuses to output of agent_status function 140124-1057 - Added callid_info function 140206-1205 - Added update_user function +140211-1056 - Added server_refresh function +140214-1540 - Added check_phone_number function API Functions use the 'function' variable @@ -1051,6 +1055,26 @@ SUCCESS: update_phone_alias PHONE ALIAS HAS BEEN DELETED - 6666|x100| +-------------------------------------------------------------------------------- +server_refresh - forces a conf file refresh on all telco servers in the cluster + +NOTE: api user for this function must have user_level set to 8 or higher and "ast admin access" enabled + +REQUIRED FIELDS- +stage - "REFRESH" + +Example URL string for API calls: +http://server/vicidial/non_agent_api.php?source=test&function=server_refresh&user=6666&pass=1234&stage=REFRESH + +Example responses: +ERROR: server_refresh USER DOES NOT HAVE PERMISSION TO REFRESH SERVERS - 6666|0 +ERROR: server_refresh YOU MUST USE ALL REQUIRED FIELDS - 6666| +SUCCESS: server_refresh SERVER REFRESH HAS BEEN TRIGGERED - 6666|1 + + + + + -------------------------------------------------------------------------------- add_list - adds a list to the system @@ -1157,3 +1181,60 @@ NOTICE: update_list LEADS IN LIST HAVE BEEN DELETED - 6666|1101|324 ERROR: NO FUNCTION SPECIFIED + + + + +-------------------------------------------------------------------------------- +check_phone_number - allows you to check if a phone number is valid and dialable + +NOTE: api user for this function must have user_level set to 8 or higher + +REQUIRED FIELDS- +phone_number - must be all numbers, 6-16 digits +phone_code - must be all numbers, 1-4 digits, defaults to 1 if not set +local_call_time - must be a valid call time ID in the system + +OPTIONAL FIELDS- +postal_code - must be 5 digits. Only works for USA zipcodes, needed for POSTAL tz_method +state - must be 2 letters. Only needed if state call time rules enabled +owner - must be 2-5 letters. Only needed if using TZCODE tz_method + +SETTINGS FIELDS- +dnc_check - Y, N or AREACODE, default is N +campaign_dnc_check - Y, N or AREACODE, default is N +campaign_id - 2-8 Character campaign ID, required if using campaign_dnc_check +usacan_prefix_check - Y or N, default is N. Check for a valid 4th digit for USA and Canada phone numbers (cannot be 0 or 1) +usacan_areacode_check - Y or N, default is N. Check for a valid areacode for USA and Canada phone numbers +nanpa_ac_prefix_check - Y or N, default is N. Check for a valid NANPA areacode and prefix, if optional NANPA data is on the system +tz_method - , POSTAL, TZCODE, NANPA or AREACODE, default is which will use the country code and AREACODE for time zone lookups + AREACODE relies on the phone number's areacode + POSTAL relies on the postal_code field + TZCODE relies on the owner field being populated with a proper time zone code + NANPA relies on the optional NANPA areacode prefix data being loaded on your system + (NOTE: you can do more than one method at once, i.e.: "POSTALTZCODE") + + +Example URL strings for API calls: +http://server/vicidial/non_agent_api.php?source=test&user=6666&pass=1234&function=check_phone_number&phone_number=7275551111&call_time=9am-9pm + +http://server/vicidial/non_agent_api.php?DB=0&source=test&function=check_phone_number&user=6666&pass=1234&owner=GST&postal_code=81009&phone_number=3125551212&local_call_time=9am-9pm&tz_method=AREACODEPOSTALNANPATZCODE + + +Example responses: + +ERROR: check_phone_number USER DOES NOT HAVE PERMISSION TO CHECK PHONE NUMBERS - |6666|0| +ERROR: check_phone_number THIS IS NOT A VALID CALL TIME - |6666|badct| +ERROR: check_phone_number NANPA options disabled, NANPA prefix data not loaded - 0|6666 +ERROR: check_phone_number INVALID PHONE NUMBER LENGTH - 72755|6666 +ERROR: check_phone_number INVALID PHONE NUMBER PREFIX - 72755|6666 +ERROR: check_phone_number INVALID PHONE NUMBER AREACODE - 72755|6666 +ERROR: check_phone_number INVALID PHONE NUMBER NANPA AREACODE PREFIX - 7275551212|6666 +ERROR: check_phone_number PHONE NUMBER IN DNC - 7275551112|6666 + +A success response will show the results for each tz_method used(with 0 or 1 for dialable and the gmt-offset) followed by a hash"#" and then the phone information after: +AREACODE: 1|-6#PHONE: 3125551212|1|||| +AREACODE: 1|-6#POSTAL: 1|-7.0#TZCODE: 0|10#NANPA: 1|-6#PHONE: 3125551212|1|81009||GST| + + +ERROR: NO FUNCTION SPECIFIED diff --git a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql index 6896e9cb..e24a2622 100644 --- a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql +++ b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql @@ -1544,7 +1544,8 @@ pass_key VARCHAR(100) default '', pass_cost TINYINT(2) UNSIGNED default '2', disable_auto_dial ENUM('0','1') default '0', queuemetrics_record_hold ENUM('0','1') default '0', -country_code_list_stats ENUM('0','1') default '0' +country_code_list_stats ENUM('0','1') default '0', +reload_timestamp DATETIME ) ENGINE=MyISAM; CREATE TABLE vicidial_campaigns_list_mix ( @@ -3253,4 +3254,4 @@ UPDATE vicidial_configuration set value='1766' where name='qc_database_version'; UPDATE system_settings set vdc_agent_api_active='1'; -UPDATE system_settings SET db_schema_version='1368',db_schema_update_date=NOW(); +UPDATE system_settings SET db_schema_version='1369',db_schema_update_date=NOW(),reload_timestamp=NOW(); diff --git a/agc_2-X/trunk/extras/upgrade_2.8.sql b/agc_2-X/trunk/extras/upgrade_2.8.sql index 3154094f..a724e5c6 100644 --- a/agc_2-X/trunk/extras/upgrade_2.8.sql +++ b/agc_2-X/trunk/extras/upgrade_2.8.sql @@ -204,3 +204,7 @@ UPDATE system_settings SET db_schema_version='1367',db_schema_update_date=NOW() CREATE UNIQUE INDEX vlca_user_campaign_id on vicidial_campaign_agents (user, campaign_id); UPDATE system_settings SET db_schema_version='1368',db_schema_update_date=NOW() where db_schema_version < 1368; + +ALTER TABLE system_settings ADD reload_timestamp DATETIME; + +UPDATE system_settings SET db_schema_version='1369',db_schema_update_date=NOW(),reload_timestamp=NOW() where db_schema_version < 1369; diff --git a/agc_2-X/trunk/www/vicidial/AST_timeonVDADall.php b/agc_2-X/trunk/www/vicidial/AST_timeonVDADall.php index 272d229b..72fb85e7 100644 --- a/agc_2-X/trunk/www/vicidial/AST_timeonVDADall.php +++ b/agc_2-X/trunk/www/vicidial/AST_timeonVDADall.php @@ -84,10 +84,11 @@ # 130620-2303 - Added filtering of input to prevent SQL injection attacks and new user auth # 130901-2008 - Changed to mysqli PHP functions # 131120-1543 - Fixed small display bug when customer phone view is enabled +# 140213-1705 - Fixed division by zero bug # -$version = '2.8-73'; -$build = '131120-1543'; +$version = '2.8-74'; +$build = '140213-1705'; header ("Content-type: text/html; charset=utf-8"); @@ -1458,16 +1459,34 @@ if ($CARRIERstats > 0) if (strlen($FTminute_count[$print_ctp])<1) {$FTminute_count[$print_ctp]=0;} if (strlen($FIVEminute_count[$print_ctp])<1) {$FIVEminute_count[$print_ctp]=0;} if (strlen($ONEminute_count[$print_ctp])<1) {$ONEminute_count[$print_ctp]=0;} + + if ( ($TFhour_count[$print_ctp] < 1) or ($TFhour_total < 1) ) {$TFhour_pct=0;} + else {$TFhour_pct = (100*($TFhour_count[$print_ctp]/$TFhour_total));} + + if ( ($SIXhour_count[$print_ctp] < 1) or ($SIXhour_total < 1) ) {$SIXhour_pct=0;} + else {$SIXhour_pct = (100*($SIXhour_count[$print_ctp]/$SIXhour_total));} + + if ( ($ONEhour_count[$print_ctp] < 1) or ($ONEhour_total < 1) ) {$ONEhour_pct=0;} + else {$ONEhour_pct = (100*($ONEhour_count[$print_ctp]/$ONEhour_total));} + + if ( ($FTminute_count[$print_ctp] < 1) or ($FTminute_total < 1) ) {$TFminute_pct=0;} + else {$TFminute_pct = (100*($FTminute_count[$print_ctp]/$FTminute_total));} + + if ( ($FIVEminute_count[$print_ctp] < 1) or ($FIVEminute_total < 1) ) {$FIVEminute_pct=0;} + else {$FIVEminute_pct = (100*($FIVEminute_count[$print_ctp]/$FIVEminute_total));} + + if ( ($ONEminute_count[$print_ctp] < 1) or ($ONEminute_total < 1) ) {$ONEminute_pct=0;} + else {$ONEminute_pct = (100*($ONEminute_count[$print_ctp]/$ONEminute_total));} $CARRIERstatsHTML .= ""; $CARRIERstatsHTML .= " "; $CARRIERstatsHTML .= "    $TFhour_status[$print_ctp] "; - $CARRIERstatsHTML .= " $TFhour_count[$print_ctp]  ".sprintf("%01.1f", (100*($TFhour_count[$print_ctp]/$TFhour_total)))."%"; - $CARRIERstatsHTML .= " $SIXhour_count[$print_ctp]  ".sprintf("%01.1f", (100*($SIXhour_count[$print_ctp]/$SIXhour_total)))."%"; - $CARRIERstatsHTML .= " $ONEhour_count[$print_ctp]  ".sprintf("%01.1f", (100*($ONEhour_count[$print_ctp]/$ONEhour_total)))."%"; - $CARRIERstatsHTML .= " $FTminute_count[$print_ctp]  ".sprintf("%01.1f", (100*($FTminute_count[$print_ctp]/$FTminute_total)))."%"; - $CARRIERstatsHTML .= " $FIVEminute_count[$print_ctp]  ".sprintf("%01.1f", (100*($FIVEminute_count[$print_ctp]/$FIVEminute_total)))."%"; - $CARRIERstatsHTML .= " $ONEminute_count[$print_ctp]  ".sprintf("%01.1f", (100*($ONEminute_count[$print_ctp]/$ONEminute_total)))."%"; + $CARRIERstatsHTML .= " $TFhour_count[$print_ctp]  ".sprintf("%01.1f", $TFhour_pct)."%"; + $CARRIERstatsHTML .= " $SIXhour_count[$print_ctp]  ".sprintf("%01.1f", $SIXhour_pct)."%"; + $CARRIERstatsHTML .= " $ONEhour_count[$print_ctp]  ".sprintf("%01.1f", $ONEhour_pct)."%"; + $CARRIERstatsHTML .= " $FTminute_count[$print_ctp]  ".sprintf("%01.1f", $TFminute_pct)."%"; + $CARRIERstatsHTML .= " $FIVEminute_count[$print_ctp]  ".sprintf("%01.1f", $FIVEminute_pct)."%"; + $CARRIERstatsHTML .= " $ONEminute_count[$print_ctp]  ".sprintf("%01.1f", $ONEminute_pct)."%"; $CARRIERstatsHTML .= ""; $print_ctp++; } diff --git a/agc_2-X/trunk/www/vicidial/admin.php b/agc_2-X/trunk/www/vicidial/admin.php index bb1b67b6..b38a9cee 100644 --- a/agc_2-X/trunk/www/vicidial/admin.php +++ b/agc_2-X/trunk/www/vicidial/admin.php @@ -3273,12 +3273,13 @@ else # 140126-0939 - Added VMAIL_NO_INST options # 140126-2253 - Added voicemail_instructions option for phones # 140206-1357 - Filter dashes from new or copied campaigns and in-groups +# 140214-1643 - Added system settings dialplan reload timestamp # # 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.8-425a'; -$build = '140206-1357'; +$admin_version = '2.8-426a'; +$build = '140214-1643'; $STARTtime = date("U"); $SQLdate = date("Y-m-d H:i:s"); @@ -14342,6 +14343,9 @@ if ($ADD==411111111111111) if ($reload_dialplan_on_servers > 0) { + $stmtB="UPDATE system_settings set reload_timestamp=NOW();"; + $rslt=mysql_to_mysqli($stmtB, $link); + $stmtB="UPDATE servers set rebuild_conf_files='Y' where active='Y' and active_asterisk_server='Y' and generate_vicidial_conf='Y';"; $rslt=mysql_to_mysqli($stmtB, $link); } @@ -23561,7 +23565,7 @@ if ($ADD==3811) echo "In-Group Email Date: $group_calldate$NWB#inbound_groups-group_emaildate$NWE\n"; echo "\n"; - horizontal_bar_chart($group_id,'8','in-group',$link,'total_calls','call count',1); + horizontal_bar_chart($group_id,'8','in-group',$link,'total_calls','call count',1,'',''); echo "\n"; echo "Admin User Group: \n"; - echo "Reload Dialplan On Servers: $NWB#settings-reload_dialplan_on_servers$NWE\n"; + echo "Reload Dialplan On Servers: $NWB#settings-reload_dialplan_on_servers$NWE     Last: $reload_timestamp\n"; } else { diff --git a/agc_2-X/trunk/www/vicidial/admin_listloader_fourth_gen.php b/agc_2-X/trunk/www/vicidial/admin_listloader_fourth_gen.php index 39b83a5a..48ab53e9 100644 --- a/agc_2-X/trunk/www/vicidial/admin_listloader_fourth_gen.php +++ b/agc_2-X/trunk/www/vicidial/admin_listloader_fourth_gen.php @@ -2,7 +2,7 @@ # admin_listloader_fourth_gen.php - version 2.8 # (based upon - new_listloader_superL.php script) # -# Copyright (C) 2013 Matt Florell,Joe Johnson LICENSE: AGPLv2 +# Copyright (C) 2014 Matt Florell,Joe Johnson LICENSE: AGPLv2 # # ViciDial web-based lead loader from formatted file # @@ -53,10 +53,11 @@ # 130719-1914 - Added SQL to filter by template statuses, if template has specific statuses to dedupe against # 130802-0619 - Added status deduping option without template # 130824-2322 - Changed to mysqli PHP functions +# 140214-1022 - Fixed status dedupe bug # -$version = '2.8-51'; -$build = '130824-2322'; +$version = '2.8-52'; +$build = '140214-1022'; require("dbconnect_mysqli.php"); require("functions.php"); @@ -319,6 +320,18 @@ else $LOCAL_GMT_OFF = $SERVER_GMT; $LOCAL_GMT_OFF_STD = $SERVER_GMT; +$dedupe_status_select=''; +$stmt="SELECT status, status_name from vicidial_statuses order by status;"; +$rslt=mysql_to_mysqli($stmt, $link); +$stat_num_rows = mysqli_num_rows($rslt); +$snr_count=0; +while ($stat_num_rows > $snr_count) + { + $row=mysqli_fetch_row($rslt); + $dedupe_status_select .= "\t\t\t\n"; + $snr_count++; + } + #if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOCAL GMT OFFSET NOW: $LOCAL_GMT_OFF\n";} @@ -573,19 +586,7 @@ if ( (!$OK_to_process) or ( ($leadfile) and ($file_layout!="standard" && $file_l diff --git a/agc_2-X/trunk/www/vicidial/non_agent_api.php b/agc_2-X/trunk/www/vicidial/non_agent_api.php index 58949f80..8137948f 100644 --- a/agc_2-X/trunk/www/vicidial/non_agent_api.php +++ b/agc_2-X/trunk/www/vicidial/non_agent_api.php @@ -84,10 +84,12 @@ # 140107-2143 - Added webserver and url logging # 140124-1057 - Added callid_info function # 140206-1205 - Added update_user function +# 140211-1056 - Added server_refresh function +# 140214-1540 - Added check_phone_number function # -$version = '2.8-60'; -$build = '140206-1205'; +$version = '2.8-62'; +$build = '140214-1540'; $api_url_log = 0; $startMS = microtime(); @@ -348,6 +350,8 @@ if (isset($_GET["campaign_rank"])) {$campaign_rank=$_GET["campaign_rank"];} elseif (isset($_POST["campaign_rank"])) {$campaign_rank=$_POST["campaign_rank"];} if (isset($_GET["campaign_grade"])) {$campaign_grade=$_GET["campaign_grade"];} elseif (isset($_POST["campaign_grade"])) {$campaign_grade=$_POST["campaign_grade"];} +if (isset($_GET["local_call_time"])) {$local_call_time=$_GET["local_call_time"];} + elseif (isset($_POST["local_call_time"])) {$local_call_time=$_POST["local_call_time"];} header ("Content-type: text/html; charset=utf-8"); @@ -507,6 +511,7 @@ if ($non_latin < 1) $delete_user = preg_replace('/[^A-Z]/','',$delete_user); $campaign_rank = preg_replace('/[^-_0-9]/','',$campaign_rank); $campaign_grade = preg_replace('/[^0-9]/','',$campaign_grade); + $local_call_time = preg_replace('/[^-_0-9a-zA-Z]/','',$local_call_time); } else { @@ -3255,6 +3260,80 @@ if ($function == 'update_phone_alias') +################################################################################ +### server_refresh - forces a conf file refresh on all telco servers in the cluster +################################################################################ +if ($function == 'server_refresh') + { + if(strlen($source)<2) + { + $result = 'ERROR'; + $result_reason = "Invalid Source"; + echo "$result: $result_reason - $source\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + echo "ERROR: Invalid Source: |$source|\n"; + exit; + } + else + { + $stmt="SELECT count(*) from vicidial_users where user='$user' and vdc_agent_api_access='1' and ast_admin_access='1' and user_level >= 8 and active='Y';"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $allowed_user=$row[0]; + if ($allowed_user < 1) + { + $result = 'ERROR'; + $result_reason = "server_refresh USER DOES NOT HAVE PERMISSION TO REFRESH SERVERS"; + $data = "$allowed_user"; + echo "$result: $result_reason: |$user|$data\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + else + { + if (!preg_match("/REFRESH/",$stage)) + { + $result = 'ERROR'; + $result_reason = "server_refresh YOU MUST USE ALL REQUIRED FIELDS"; + $data = "$alias_id|$alias_name|$phone_logins"; + echo "$result: $result_reason: |$user|$data\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + else + { + $stmt="UPDATE system_settings set reload_timestamp=NOW();"; + $rslt=mysql_to_mysqli($stmt, $link); + + $stmt="UPDATE servers SET rebuild_conf_files='Y';"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {echo "|$stmt|\n";} + $affected_rows = mysqli_affected_rows($link); + + ### LOG INSERTION Admin Log Table ### + $SQL_log = "$stmt|"; + $SQL_log = preg_replace('/;/', '', $SQL_log); + $SQL_log = addslashes($SQL_log); + $stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$user', ip_address='$ip', event_section='SERVERS', event_type='OTHER', record_id='refresh', event_code='ADMIN API SERVERS REFRESH', event_sql=\"$SQL_log\", event_notes='servers: $affected_rows';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + + $result = 'SUCCESS'; + $result_reason = "server_refresh SERVER REFRESH HAS BEEN TRIGGERED"; + $data = "$affected_rows"; + echo "$result: $result_reason - $user|$data\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + } + } + exit; + } +################################################################################ +### END server_refresh +################################################################################ + + + ################################################################################ ### update_list - updates list information in the vicidial_lists table and other functions ################################################################################ @@ -6879,6 +6958,273 @@ if ($function == 'update_lead') + + +################################################################################ +### check_phone_number - allows you to check if a phone number is valid and dialable +################################################################################ +if ($function == 'check_phone_number') + { + if(strlen($source)<2) + { + $result = 'ERROR'; + $result_reason = "Invalid Source"; + echo "$result: $result_reason - $source\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + echo "ERROR: Invalid Source: |$source|\n"; + exit; + } + else + { + $stmt="SELECT count(*) from vicidial_users where user='$user' and vdc_agent_api_access='1' and user_level > 7 and active='Y';"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $allowed_check=$row[0]; + + if ($allowed_check < 1) + { + $result = 'ERROR'; + $result_reason = "check_phone_number USER DOES NOT HAVE PERMISSION TO CHECK PHONE NUMBERS"; + echo "$result: $result_reason: |$user|$modify_leads|\n"; + $data = "$modify_leads"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + else + { + $stmt="SELECT count(*) from vicidial_call_times where call_time_id='$local_call_time';"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $valid_call_time=$row[0]; + + if ($valid_call_time < 1) + { + $result = 'ERROR'; + $result_reason = "check_phone_number THIS IS NOT A VALID CALL TIME"; + echo "$result: $result_reason: |$user|$local_call_time|\n"; + $data = "$valid_call_time"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + else + { + if (strlen($phone_code)<1) {$phone_code='1';} + if (strlen($tz_method)<1) {$tz_method='AREACODE';} + if ( ($nanpa_ac_prefix_check == 'Y') or (preg_match("/NANPA/i",$tz_method)) ) + { + $stmt="SELECT count(*) from vicidial_nanpa_prefix_codes;"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $vicidial_nanpa_prefix_codes_count = $row[0]; + if ($vicidial_nanpa_prefix_codes_count < 10) + { + $nanpa_ac_prefix_check='N'; + $tz_method = preg_replace("/NANPA/",'',$tz_method); + + $result = 'ERROR'; + $result_reason = "check_phone_number NANPA options disabled, NANPA prefix data not loaded"; + echo "$result: $result_reason - $vicidial_nanpa_prefix_codes_count|$user\n"; + $data = "$inserted_alt_phones|$lead_id"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + + exit; + } + } + + $valid_number=1; + if ( (strlen($phone_number)<6) || (strlen($phone_number)>16) ) + { + $valid_number=0; + $result_reason = "check_phone_number INVALID PHONE NUMBER LENGTH"; + } + if ( ($usacan_prefix_check=='Y') and ($valid_number > 0) ) + { + $USprefix = substr($phone_number, 3, 1); + if ($DB>0) {echo "DEBUG: check_phone_number prefix check - $USprefix|$phone_number\n";} + if ($USprefix < 2) + { + $valid_number=0; + $result_reason = "check_phone_number INVALID PHONE NUMBER PREFIX"; + } + } + if ( ($usacan_areacode_check=='Y') and ($valid_number > 0) ) + { + $phone_areacode = substr($phone_number, 0, 3); + $stmt = "select count(*) from vicidial_phone_codes where areacode='$phone_areacode' and country_code='1';"; + if ($DB>0) {echo "DEBUG: check_phone_number areacode check query - $stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $valid_number=$row[0]; + if ($valid_number < 1) + { + $result_reason = "check_phone_number INVALID PHONE NUMBER AREACODE"; + } + } + if ( ($nanpa_ac_prefix_check=='Y') and ($valid_number > 0) ) + { + $phone_areacode = substr($phone_number, 0, 3); + $phone_prefix = substr($phone_number, 3, 3); + $stmt = "SELECT count(*) from vicidial_nanpa_prefix_codes where areacode='$phone_areacode' and prefix='$phone_prefix';"; + if ($DB>0) {echo "DEBUG: check_phone_number areacode check query - $stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $valid_number=$row[0]; + if ($valid_number < 1) + { + $result_reason = "check_phone_number INVALID PHONE NUMBER NANPA AREACODE PREFIX"; + } + } + if ($valid_number < 1) + { + $result = 'ERROR'; + echo "$result: $result_reason - $phone_number|$user\n"; + $data = "$phone_number"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + else + { + ### START checking for DNC if defined ### + if ( ($dnc_check == 'Y') or ($dnc_check == 'AREACODE') ) + { + if ($DB>0) {echo "DEBUG: Checking for system DNC\n";} + if ($dnc_check == 'AREACODE') + { + $phone_areacode = substr($phone_number, 0, 3); + $phone_areacode .= "XXXXXXX"; + $stmt="SELECT count(*) from vicidial_dnc where phone_number IN('$phone_number','$phone_areacode');"; + } + else + {$stmt="SELECT count(*) from vicidial_dnc where phone_number='$phone_number';";} + if ($DB>0) {echo "DEBUG: check_phone_number query - $stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $dnc_found=$row[0]; + + if ($dnc_found > 0) + { + $result = 'ERROR'; + $result_reason = "check_phone_number PHONE NUMBER IN DNC"; + echo "$result: $result_reason - $phone_number|$user\n"; + $data = "$phone_number"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + } + if ( ($campaign_dnc_check == 'Y') or ($campaign_dnc_check == 'AREACODE') ) + { + if ($DB>0) {echo "DEBUG: Checking for campaign DNC\n";} + + $stmt="SELECT use_other_campaign_dnc from vicidial_campaigns where campaign_id='$campaign_id';"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $use_other_campaign_dnc = $row[0]; + $temp_campaign_id = $campaign_id; + if (strlen($use_other_campaign_dnc) > 0) {$temp_campaign_id = $use_other_campaign_dnc;} + + if ($campaign_dnc_check == 'AREACODE') + { + $phone_areacode = substr($phone_number, 0, 3); + $phone_areacode .= "XXXXXXX"; + $stmt="SELECT count(*) from vicidial_campaign_dnc where phone_number IN('$phone_number','$phone_areacode') and campaign_id='$temp_campaign_id';"; + } + else + {$stmt="SELECT count(*) from vicidial_campaign_dnc where phone_number='$phone_number' and campaign_id='$temp_campaign_id';";} + if ($DB>0) {echo "DEBUG: check_phone_number query - $stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $dnc_found=$row[0]; + + if ($dnc_found > 0) + { + $result = 'ERROR'; + $result_reason = "check_phone_number PHONE NUMBER IN CAMPAIGN DNC"; + echo "$result: $result_reason - $phone_number|$campaign_id|$user\n"; + $data = "$phone_number|$campaign_id"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + } + ### END checking for DNC if defined ### + + $tz_run=0; + $result_reason=''; + $gmt_offset=''; $dialable='0'; + if (preg_match("/AREACODE/i",$tz_method)) + { + $tz_run++; + ### get current gmt_offset of the phone_number + $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,'',$postal_code,$owner,$USprefix); + + ### call function to determine if lead is dialable + $dialable = dialable_gmt($DB,$link,$local_call_time,$gmt_offset,$state); + + $result_reason .= "AREACODE: $dialable|$gmt_offset#"; + } + $gmt_offset=''; $dialable='0'; + if (preg_match("/POSTAL/i",$tz_method)) + { + $tz_run++; + + if ( (strlen($postal_code)>4) and (strlen($postal_code)< 6) ) + { + ### get current gmt_offset of the phone_number + $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,'POSTAL',$postal_code,$owner,$USprefix); + + ### call function to determine if lead is dialable + $dialable = dialable_gmt($DB,$link,$local_call_time,$gmt_offset,$state); + } + + $result_reason .= "POSTAL: $dialable|$gmt_offset#"; + } + $gmt_offset=''; $dialable='0'; + if (preg_match("/TZCODE/i",$tz_method)) + { + $tz_run++; + + if ( (strlen($owner)>0) and (strlen($owner)< 7) ) + { + ### get current gmt_offset of the phone_number + $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,'TZCODE',$postal_code,$owner,$USprefix); + + ### call function to determine if lead is dialable + $dialable = dialable_gmt($DB,$link,$local_call_time,$gmt_offset,$state); + } + + $result_reason .= "TZCODE: $dialable|$gmt_offset#"; + } + $gmt_offset=''; $dialable='0'; + if (preg_match("/NANPA/i",$tz_method)) + { + $tz_run++; + ### get current gmt_offset of the phone_number + $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,'NANPA',$postal_code,$owner,$USprefix); + + ### call function to determine if lead is dialable + $dialable = dialable_gmt($DB,$link,$local_call_time,$gmt_offset,$state); + + $result_reason .= "NANPA: $dialable|$gmt_offset#"; + } + + $result = 'NOTICE'; + $result_reason .= "PHONE: $phone_number|$phone_code|$postal_code|$state|$owner|"; + echo "$result_reason\n"; + $data = ""; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + } + } + exit; + } + } +################################################################################ +### END check_phone_number +################################################################################ + + + + + $result = 'ERROR'; $result_reason = "NO FUNCTION SPECIFIED"; echo "$result: $result_reason\n";