From d7c5af08d4529cb9e4ac726e9acb04a577b1391c Mon Sep 17 00:00:00 2001 From: mattf Date: Sat, 2 Mar 2024 13:18:05 +0000 Subject: [PATCH] Added 'delete_dnc_phone' Non-Agent API function. git-svn-id: svn://192.168.202.10@3812 3d104415-ff17-0410-8863-d5cf3c621b8a --- UPGRADE | 2 + docs/NON-AGENT_API.txt | 27 +++++++- www/vicidial/non_agent_api.php | 111 ++++++++++++++++++++++++++++++++- 3 files changed, 136 insertions(+), 4 deletions(-) diff --git a/UPGRADE b/UPGRADE index 8e436c65..80a036bc 100644 --- a/UPGRADE +++ b/UPGRADE @@ -853,6 +853,8 @@ OTHER CHANGES: 242. Added Per-User Per-In-Group daily call limits. +243. Added 'delete_dnc_phone' Non-Agent API function. + diff --git a/docs/NON-AGENT_API.txt b/docs/NON-AGENT_API.txt index 5d1bae74..89e79478 100644 --- a/docs/NON-AGENT_API.txt +++ b/docs/NON-AGENT_API.txt @@ -1,4 +1,4 @@ -NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2024-01-20 +NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2024-03-02 This document describes the functions of an API(Application Programming Interface) for all functions NOT directly relating to the VICIDIAL Agent screen. @@ -216,6 +216,8 @@ Changes: 240101-0920 - Added DUPPHONEALT... options for duplicate_check within add_lead function 240105-1009 - Added delete_fpg_phone function 240120-0840 - Added list_order,list_order_randomize,list_order_secondary optional fields to update_campaign function +240217-0907 - Added more missing vicidial_users fields from copy function +240302-0804 - Added delete_dnc_phone function API Functions use the 'function' variable @@ -1605,6 +1607,29 @@ SUCCESS: add_dnc_phone DNC NUMBER HAS BEEN ADDED - 6666|7275551212|TESTCAMP +-------------------------------------------------------------------------------- +delete_dnc_phone - removes phone number from a DNC list in the system + +NOTE: api user for this function must have user_level set to 8 or higher and "modify lists" enabled and "Delete From DNC Lists" enabled + +REQUIRED FIELDS- +phone_number - 6-20 characters +campaign_id - 2-30 characters, should be a valid campaign ID or "SYSTEM_INTERNAL" for the internal DNC list + +Example URL strings for API calls: +http://server/vicidial/non_agent_api.php?source=test&function=delete_dnc_phone&user=6666&pass=1234&phone_number=7275551212&campaign_id=TESTCAMP +http://server/vicidial/non_agent_api.php?source=test&function=delete_dnc_phone&user=6666&pass=1234&phone_number=7275551212&campaign_id=SYSTEM_INTERNAL + +Example responses: +ERROR: delete_dnc_phone USER DOES NOT HAVE PERMISSION TO DELETE DNC NUMBERS - 6666|0 +ERROR: delete_dnc_phone YOU MUST USE ALL REQUIRED FIELDS - 6666|||1000 +ERROR: delete_dnc_phone DNC NUMBER DOES NOT EXIST - 6666|7275551212 +SUCCESS: delete_dnc_phone DNC NUMBER HAS BEEN DELETED - 6666|7275551212|TESTCAMP + + + + + -------------------------------------------------------------------------------- add_fpg_phone - adds phone number to a Filter Phone Group in the system diff --git a/www/vicidial/non_agent_api.php b/www/vicidial/non_agent_api.php index 6bb4b870..7736e747 100644 --- a/www/vicidial/non_agent_api.php +++ b/www/vicidial/non_agent_api.php @@ -209,10 +209,11 @@ # 240105-1009 - Added delete_fpg_phone function # 240120-0840 - Added list_order,list_order_randomize,list_order_secondary optional fields to update_campaign function # 240217-0907 - Added more missing vicidial_users fields from copy function +# 240302-0804 - Added delete_dnc_phone function # -$version = '2.14-186'; -$build = '240217-0907'; +$version = '2.14-187'; +$build = '240302-0804'; $php_script='non_agent_api.php'; $api_url_log = 0; $camp_lead_order_random=1; @@ -4806,7 +4807,7 @@ if ($function == 'add_dnc_phone') $affected_rowsB = mysqli_affected_rows($link); ### LOG INSERTION Admin Log Table ### - $SQL_log = "$stmt|"; + $SQL_log = "$stmtA|$stmtB|"; $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='LISTS', event_type='ADD', record_id='$phone_number', event_code='ADMIN API ADD DNC NUMBER', event_sql=\"$SQL_log\", event_notes='$phone_number|$campaign_id|$affected_rowsA|$affected_rowsB';"; @@ -4829,6 +4830,110 @@ if ($function == 'add_dnc_phone') ################################################################################ +################################################################################ +### delete_dnc_phone - removes a phone number from a DNC list in the system +################################################################################ +if ($function == 'delete_dnc_phone') + { + 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 + { + if ( (!preg_match("/ $function /",$api_allowed_functions)) and (!preg_match("/ALL_FUNCTIONS/",$api_allowed_functions)) ) + { + $result = 'ERROR'; + $result_reason = "auth USER DOES NOT HAVE PERMISSION TO USE THIS FUNCTION"; + echo "$result: $result_reason: |$user|$function|\n"; + $data = "$allowed_user"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + $stmt="SELECT count(*) from vicidial_users where user='$user' and modify_lists='1' and delete_from_dnc='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 = "delete_dnc_phone USER DOES NOT HAVE PERMISSION TO DELETE DNC NUMBERS"; + $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 ( (strlen($phone_number) < 6) or (strlen($campaign_id) < 1) ) + { + $result = 'ERROR'; + $result_reason = "delete_dnc_phone YOU MUST USE ALL REQUIRED FIELDS"; + $data = "$phone_number|$campaign_id"; + 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="SELECT count(*) from vicidial_campaign_dnc where phone_number='$phone_number' and campaign_id='$campaign_id';"; + if ($campaign_id == 'SYSTEM_INTERNAL') + {$stmt="SELECT count(*) from vicidial_dnc where phone_number='$phone_number';";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $dnc_exists=$row[0]; + if ($dnc_exists < 1) + { + $result = 'ERROR'; + $result_reason = "delete_dnc_phone DNC NUMBER DOES NOT EXIST"; + $data = "$phone_number|$campaign_id"; + 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 + { + $stmtA="DELETE FROM vicidial_campaign_dnc WHERE phone_number='$phone_number' and campaign_id='$campaign_id';"; + if ($campaign_id == 'SYSTEM_INTERNAL') + {$stmtA="DELETE FROM vicidial_dnc where phone_number='$phone_number';";} + $rslt=mysql_to_mysqli($stmtA, $link); + $affected_rowsA = mysqli_affected_rows($link); + + $stmtB="INSERT INTO vicidial_dnc_log SET phone_number='$phone_number', campaign_id='$campaign_id', action='delete', action_date=NOW(), user='$user';"; + if ($campaign_id == 'SYSTEM_INTERNAL') + {$stmtB="INSERT INTO vicidial_dnc_log SET phone_number='$phone_number', campaign_id='-SYSINT-', action='delete', action_date=NOW(), user='$user';";} + $rslt=mysql_to_mysqli($stmtB, $link); + $affected_rowsB = mysqli_affected_rows($link); + + ### LOG INSERTION Admin Log Table ### + $SQL_log = "$stmtA|$stmtB|"; + $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='LISTS', event_type='DELETE', record_id='$phone_number', event_code='ADMIN API DELETE DNC NUMBER', event_sql=\"$SQL_log\", event_notes='$phone_number|$campaign_id|$affected_rowsA|$affected_rowsB';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + + $result = 'SUCCESS'; + $result_reason = "delete_dnc_phone DNC NUMBER HAS BEEN DELETED"; + $data = "$phone_number|$campaign_id"; + 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 delete_dnc_phone +################################################################################ + + ################################################################################ ### add_fpg_phone - adds a phone number to a Filter Phone Group in the system ################################################################################