Added batch_update_lead function to the Non-Agent API
git-svn-id: svn://192.168.202.10@3522 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
@@ -684,6 +684,8 @@ OTHER CHANGES:
|
||||
|
||||
190. Added Asterisk 16 "PJSIP" compatibility
|
||||
|
||||
191. Added 'batch_update_lead' Non-Agent API function
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2021-08-12
|
||||
NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2021-09-17
|
||||
|
||||
This document describes the functions of an API(Application Programming
|
||||
Interface) for all functions NOT directly relating to the VICIDIAL Agent screen.
|
||||
@@ -20,6 +20,7 @@ vm_list - outputs a list of voicemail boxes in the system
|
||||
blind_monitor - calls user-defined phone and places them in session as blind monitor
|
||||
add_lead - adds a new lead to the vicidial_list table with several fields and options
|
||||
update_lead - updates lead information in vicidial_list and associated custom table
|
||||
batch_update_lead - updates multiple leads in vicidial_list with single set of field values (limited field options)
|
||||
agent_ingroup_info - shows in-group and outbound auto-dial info for logged-in agent
|
||||
recording_lookup - looks up recordings based upon user and date or lead_id
|
||||
did_log_export - exports all calls inbound to a DID for one day
|
||||
@@ -192,6 +193,7 @@ Changes:
|
||||
210625-1421 - Added BARGESWAP option to blind_monitor function
|
||||
210701-2050 - Added ingroup_rank/ingroup_grade options to the update_user function
|
||||
210812-2640 - Added update of live agent records for ingroup_rank/ingroup_grade in the update_user function
|
||||
210917-1615 - Added batch_update_lead function
|
||||
|
||||
|
||||
API Functions use the 'function' variable
|
||||
@@ -1224,6 +1226,66 @@ ERROR: update_lead NOT AN ALLOWED LIST ID - 7275551212|98762
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
batch_update_lead - updates multiple leads in vicidial_list with single set of field values (limited field options)
|
||||
|
||||
NOTE: api user for this function must have modify_leads set to 1 and user_level must be set to 8 or higher
|
||||
NOTE: This function will first find which leads exist and then update them all at once. As such, there will not be admin log entries associated with each individual lead modified
|
||||
|
||||
REQUIRED FIELDS-
|
||||
lead_ids - must be all numbers and commas, 1-9 digit numbers separate by a comma
|
||||
source - description of what originated the API call (maximum 20 characters)
|
||||
|
||||
SETTINGS FIELDS-
|
||||
list_exists_check - Y or N, default is N. If the list_id_field is not a defined list in the system, it will ERROR and not update the leads.
|
||||
reset_lead - Y or N, Setting this to Y will reset the called-since-last-reset flag of the lead, default is N.
|
||||
records - maximum number of records to update (defaults to '100'[most recently created leads])
|
||||
|
||||
EDITABLE FIELDS-
|
||||
user_field - 1-20 characters, this updates the 'user' field in the vicidial_list table
|
||||
list_id_field - 3-12 digits, this updates the 'list_id' field in the vicidial_list table
|
||||
status - 1-6 characters, not punctuation or spaces
|
||||
vendor_lead_code - 1-20 characters
|
||||
source_id - 1-50 characters
|
||||
gmt_offset_now - overridden by auto-lookup of phone_code and area_code portion of phone number if applicable
|
||||
title - 1-4 characters
|
||||
first_name - 1-30 characters
|
||||
middle_initial - 1 character
|
||||
last_name - 1-30 characters
|
||||
address1 - 1-100 characters
|
||||
address2 - 1-100 characters
|
||||
address3 - 1-100 characters
|
||||
city - 1-50 characters
|
||||
state - 2 characters
|
||||
province - 1-50 characters
|
||||
postal_code - 1-10 characters
|
||||
country_code - 3 characters
|
||||
gender - U, M, F (Undefined, Male, Female) - defaults to 'U'
|
||||
date_of_birth - YYYY-MM-DD
|
||||
alt_phone - 1-12 characters
|
||||
email - 1-70 characters
|
||||
security_phrase - 1-100 characters
|
||||
comments - 1-255 characters
|
||||
rank - 1-5 digits
|
||||
owner - 1-20 characters (user ID, Territory or user group)
|
||||
called_count - digits only, the number of attempts dialing the lead
|
||||
phone_code - digits only, can be 1-4 digits
|
||||
|
||||
Example URL strings for API calls:
|
||||
http://server/vicidial/non_agent_api.php?source=test&user=6666&pass=1234&function=batch_update_lead&lead_ids=2345,2346&list_id_field=138
|
||||
|
||||
Example responses:
|
||||
SUCCESS: batch_update_lead LEADS HAVE BEEN UPDATED - 6666|2|2345,2346
|
||||
ERROR: batch_update_lead USER DOES NOT HAVE PERMISSION TO UPDATE LEADS IN THE SYSTEM - 6666|0|
|
||||
ERROR: batch_update_lead NO LEADS DEFINED - 6666|
|
||||
ERROR: batch_update_lead NOT AN ALLOWED LIST ID - 6666|138
|
||||
ERROR: batch_update_lead NOT A DEFINED LIST ID, LIST EXISTS CHECK ENABLED - 6666|138
|
||||
ERROR: batch_update_lead NO LEADS FOUND - 6666|0|2345,2346
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
add_user - adds a user to the system
|
||||
|
||||
|
||||
@@ -183,10 +183,11 @@
|
||||
# 210701-2050 - Added ingroup_rank/ingroup_grade options to the update_user function
|
||||
# 210812-2640 - Added update of live agent records for ingroup_rank/ingroup_grade in the update_user function
|
||||
# 210823-0918 - Fix for security issue
|
||||
# 210917-1615 - Added batch_update_lead function
|
||||
#
|
||||
|
||||
$version = '2.14-160';
|
||||
$build = '210823-0918';
|
||||
$version = '2.14-161';
|
||||
$build = '210917-1615';
|
||||
$php_script='non_agent_api.php';
|
||||
$api_url_log = 0;
|
||||
|
||||
@@ -660,6 +661,9 @@ if (isset($_GET["ingrp_rg_only"])) {$ingrp_rg_only=$_GET["ingrp_rg_only"];}
|
||||
elseif (isset($_POST["ingrp_rg_only"])) {$ingrp_rg_only=$_POST["ingrp_rg_only"];}
|
||||
if (isset($_GET["group_id"])) {$group_id=$_GET["group_id"];}
|
||||
elseif (isset($_POST["group_id"])) {$group_id=$_POST["group_id"];}
|
||||
if (isset($_GET["lead_ids"])) {$lead_ids=$_GET["lead_ids"];}
|
||||
elseif (isset($_POST["lead_ids"])) {$lead_ids=$_POST["lead_ids"];}
|
||||
|
||||
|
||||
if (file_exists('options.php'))
|
||||
{require('options.php');}
|
||||
@@ -940,6 +944,7 @@ else
|
||||
$list_id = preg_replace('/[^-_0-9a-zA-Z]/','',$list_id);
|
||||
$list_id_field = preg_replace('/[^0-9]/','',$list_id_field);
|
||||
$lead_id = preg_replace('/[^0-9]/','',$lead_id);
|
||||
$lead_ids = preg_replace('/[^\,0-9]/','',$lead_ids);
|
||||
$list_exists_check = preg_replace('/[^0-9a-zA-Z]/','',$list_exists_check);
|
||||
$use_internal_webserver = preg_replace('/[^0-9a-zA-Z]/','',$use_internal_webserver);
|
||||
$field_rerank = preg_replace('/[^_0-9a-zA-Z]/','',$field_rerank);
|
||||
@@ -1121,7 +1126,7 @@ $LOGuser_group = $row[2];
|
||||
$VUselected_language = $row[3];
|
||||
$VUdelete_inbound_dids = $row[4];
|
||||
|
||||
if ( ($api_list_restrict > 0) and ( ($function == 'add_lead') or ($function == 'update_lead') or ($function == 'update_list') or ($function == 'list_info') or ($function == 'list_custom_fields') ) )
|
||||
if ( ($api_list_restrict > 0) and ( ($function == 'add_lead') or ($function == 'update_lead') or ($function == 'batch_update_lead') or ($function == 'update_list') or ($function == 'list_info') or ($function == 'list_custom_fields') ) )
|
||||
{
|
||||
$stmt="SELECT allowed_campaigns from vicidial_user_groups where user_group='$LOGuser_group';";
|
||||
if ($DB>0) {echo "|$stmt|\n";}
|
||||
@@ -14245,6 +14250,194 @@ if ($function == 'update_lead')
|
||||
|
||||
|
||||
|
||||
################################################################################
|
||||
### batch_update_lead - updates multiple leads in vicidial_list with single set of field values (limited field options)
|
||||
################################################################################
|
||||
if ($function == 'batch_update_lead')
|
||||
{
|
||||
$list_id_field = preg_replace('/[^0-9]/','',$list_id_field);
|
||||
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 vdc_agent_api_access='1' and modify_leads IN('1','2','3','4') and user_level > 7 and active='Y';";
|
||||
$rslt=mysql_to_mysqli($stmt, $link);
|
||||
$row=mysqli_fetch_row($rslt);
|
||||
$modify_leads=$row[0];
|
||||
|
||||
if ($modify_leads < 1)
|
||||
{
|
||||
$result = 'ERROR';
|
||||
$result_reason = "batch_update_lead USER DOES NOT HAVE PERMISSION TO UPDATE LEADS IN THE SYSTEM";
|
||||
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
|
||||
{
|
||||
$lead_ids_SQL='';
|
||||
$find_lead_id=0;
|
||||
if (strlen($records)<1)
|
||||
{$records='1000';}
|
||||
|
||||
if (strlen($lead_ids)>0)
|
||||
{
|
||||
$find_lead_id=1;
|
||||
$lead_ids_SQL = "lead_id IN($lead_ids)";
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = 'ERROR';
|
||||
$result_reason = "batch_update_lead NO LEADS DEFINED";
|
||||
$data = "$lead_ids";
|
||||
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;
|
||||
}
|
||||
|
||||
if ( ($api_list_restrict > 0) and ($list_id_field >= 99) )
|
||||
{
|
||||
if (!preg_match("/ $list_id_field /",$allowed_lists))
|
||||
{
|
||||
$result = 'ERROR';
|
||||
$result_reason = "batch_update_lead NOT AN ALLOWED LIST ID";
|
||||
$data = "$list_id_field";
|
||||
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;
|
||||
}
|
||||
}
|
||||
if ( (preg_match("/Y/i",$list_exists_check)) and (strlen($list_id_field) > 0) )
|
||||
{
|
||||
$stmt="SELECT count(*) from vicidial_lists where list_id='$list_id_field';";
|
||||
$rslt=mysql_to_mysqli($stmt, $link);
|
||||
$row=mysqli_fetch_row($rslt);
|
||||
if ($DB>0) {echo "DEBUG: batch_update_lead list_exists_check query - $row[0]|$stmt\n";}
|
||||
$list_exists_count = $row[0];
|
||||
if ($list_exists_count < 1)
|
||||
{
|
||||
$result = 'ERROR';
|
||||
$result_reason = "batch_update_lead NOT A DEFINED LIST ID, LIST EXISTS CHECK ENABLED";
|
||||
$data = "$list_id_field";
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
$search_found=0;
|
||||
$found_lead_ids='';
|
||||
if (strlen($lead_ids) > 0) # search for the lead_id
|
||||
{
|
||||
if (strlen($allowed_listsSQL) > 3)
|
||||
{$allowed_listsSQL = "and list_id IN($allowed_listsSQL)";}
|
||||
$stmt="SELECT lead_id from vicidial_list where $lead_ids_SQL $allowed_listsSQL order by lead_id desc limit $records;";
|
||||
if ($DB>0) {echo "DEBUG: Checking for lead_ids - $lead_ids |$stmt|\n";}
|
||||
$rslt=mysql_to_mysqli($stmt, $link);
|
||||
$pc_recs = mysqli_num_rows($rslt);
|
||||
$n=0;
|
||||
while ($pc_recs > $n)
|
||||
{
|
||||
$row=mysqli_fetch_row($rslt);
|
||||
if ($n > 0)
|
||||
{$found_lead_ids .= ",";}
|
||||
$found_lead_ids .= "$row[0]";
|
||||
$n++;
|
||||
$search_found++;
|
||||
}
|
||||
}
|
||||
### END searching ###
|
||||
|
||||
if ( ($search_found > 0) and (strlen($found_lead_ids) > 0) )
|
||||
{
|
||||
$VL_update_SQL='';
|
||||
##### BEGIN update lead information in the system #####
|
||||
if (strlen($user_field)>0) {$VL_update_SQL .= "user=\"$user_field\",";}
|
||||
if (strlen($list_id_field)>0) {$VL_update_SQL .= "list_id=\"$list_id_field\",";}
|
||||
if (strlen($status)>0) {$VL_update_SQL .= "status=\"$status\",";}
|
||||
if (strlen($vendor_lead_code)>0) {$VL_update_SQL .= "vendor_lead_code=\"$vendor_lead_code\",";}
|
||||
if (strlen($source_id)>0) {$VL_update_SQL .= "source_id=\"$source_id\",";}
|
||||
if (strlen($gmt_offset_now)>0) {$VL_update_SQL .= "gmt_offset_now=\"$gmt_offset_now\",";}
|
||||
if (strlen($title)>0) {$VL_update_SQL .= "title=\"$title\",";}
|
||||
if (strlen($first_name)>0) {$VL_update_SQL .= "first_name=\"$first_name\",";}
|
||||
if (strlen($middle_initial)>0) {$VL_update_SQL .= "middle_initial=\"$middle_initial\",";}
|
||||
if (strlen($last_name)>0) {$VL_update_SQL .= "last_name=\"$last_name\",";}
|
||||
if (strlen($address1)>0) {$VL_update_SQL .= "address1=\"$address1\",";}
|
||||
if (strlen($address2)>0) {$VL_update_SQL .= "address2=\"$address2\",";}
|
||||
if (strlen($address3)>0) {$VL_update_SQL .= "address3=\"$address3\",";}
|
||||
if (strlen($city)>0) {$VL_update_SQL .= "city=\"$city\",";}
|
||||
if (strlen($state)>0) {$VL_update_SQL .= "state=\"$state\",";}
|
||||
if (strlen($province)>0) {$VL_update_SQL .= "province=\"$province\",";}
|
||||
if (strlen($postal_code)>0) {$VL_update_SQL .= "postal_code=\"$postal_code\",";}
|
||||
if (strlen($country_code)>0) {$VL_update_SQL .= "country_code=\"$country_code\",";}
|
||||
if (strlen($gender)>0) {$VL_update_SQL .= "gender=\"$gender\",";}
|
||||
if (strlen($date_of_birth)>0) {$VL_update_SQL .= "date_of_birth=\"$date_of_birth\",";}
|
||||
if (strlen($alt_phone)>0) {$VL_update_SQL .= "alt_phone=\"$alt_phone\",";}
|
||||
if (strlen($email)>0) {$VL_update_SQL .= "email=\"$email\",";}
|
||||
if (strlen($security_phrase)>0) {$VL_update_SQL .= "security_phrase=\"$security_phrase\",";}
|
||||
if (strlen($comments)>0) {$VL_update_SQL .= "comments=\"$comments\",";}
|
||||
if (strlen($rank)>0) {$VL_update_SQL .= "rank=\"$rank\",";}
|
||||
if (strlen($owner)>0) {$VL_update_SQL .= "owner=\"$owner\",";}
|
||||
if (strlen($called_count)>0) {$VL_update_SQL .= "called_count=\"$called_count\",";}
|
||||
if (strlen($phone_code)>0) {$VL_update_SQL .= "phone_code=\"$phone_code\",";}
|
||||
if ( (strlen($reset_lead) > 0 && $reset_lead == 'Y') ) {$VL_update_SQL .= "called_since_last_reset='N',";}
|
||||
$VL_update_SQL = preg_replace("/,$/","",$VL_update_SQL);
|
||||
$VL_update_SQL = preg_replace("/\"--BLANK--\"/",'""',$VL_update_SQL);
|
||||
$VL_update_SQL = preg_replace("/\n/","!N",$VL_update_SQL);
|
||||
|
||||
$VLaffected_rows=0;
|
||||
|
||||
if (strlen($VL_update_SQL)>6)
|
||||
{
|
||||
$stmt = "UPDATE vicidial_list SET $VL_update_SQL where lead_id IN($found_lead_ids);";
|
||||
$result_reason = "batch_update_lead LEADS HAVE BEEN UPDATED";
|
||||
|
||||
if ($DB>0) {echo "DEBUG: batch_update_lead query - $stmt\n";}
|
||||
$rslt=mysql_to_mysqli($stmt, $link);
|
||||
$VLaffected_rows = mysqli_affected_rows($link);
|
||||
|
||||
$result = 'SUCCESS';
|
||||
$data = "$VLaffected_rows|$search_found|$found_lead_ids";
|
||||
echo "$result: $result_reason - $user|$data\n";
|
||||
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
|
||||
}
|
||||
##### END update lead information in the system #####
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = 'ERROR';
|
||||
$result_reason = "batch_update_lead NO MATCHES FOUND IN THE SYSTEM";
|
||||
$data = "$lead_ids";
|
||||
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 batch_update_lead
|
||||
################################################################################
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
################################################################################
|
||||
|
||||
Reference in New Issue
Block a user