Added call_status_stats API function

Added vendor lead code filtering option to Lead Export Report

git-svn-id: svn://192.168.202.10@2882 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2018-01-10 01:27:59 +00:00
parent 925373276d
commit b57c04721f
4 changed files with 403 additions and 18 deletions
+42 -2
View File
@@ -1,4 +1,4 @@
NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2017-12-29 NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2018-01-09
This document describes the functions of an API(Application Programming This document describes the functions of an API(Application Programming
Interface) for all functions NOT directly relating to the VICIDIAL Agent screen. Interface) for all functions NOT directly relating to the VICIDIAL Agent screen.
@@ -44,7 +44,7 @@ update_campaign - updates campaign settings in the system
phone_number_log - exports list of calls placed to one of more phone numbers phone_number_log - exports list of calls placed to one of more phone numbers
ccc_lead_info - outputs lead data for cross-cluster-communication call ccc_lead_info - outputs lead data for cross-cluster-communication call
lead_status_search - displays all field values of all leads that match the status and call date in request lead_status_search - displays all field values of all leads that match the status and call date in request
call_status_stats - report on number of calls made by campaign and ingroup, with hourly and status breakdowns
New scripts: New scripts:
/vicidial/non_agent_api.php - the script that is accessed to execute commands /vicidial/non_agent_api.php - the script that is accessed to execute commands
@@ -131,6 +131,7 @@ Changes:
170609-1107 - Added ccc_lead_info function 170609-1107 - Added ccc_lead_info function
170615-0006 - Added DIAL status for manual dial agent calls that have not been answered, to 4 functions 170615-0006 - Added DIAL status for manual dial agent calls that have not been answered, to 4 functions
171229-1602 - Added lead_status_search function 171229-1602 - Added lead_status_search function
180109-1313 - Added call_status_stats function
API Functions use the 'function' variable API Functions use the 'function' variable
@@ -1488,6 +1489,45 @@ NOTE: real_time_sub_status field can consist of: DEAD, DISPO, 3-WAY, PARK, RING,
--------------------------------------------------------------------------------
call_status_stats - report on number of calls made by campaign and ingroup, with hourly and status breakdowns
NOTE: api user for this function must have user_level set to 8 or higher and "view reports" enabled
REQUIRED FIELDS-
campaigns - Campaigns to return stats on. Use "---ALL---" or "ALLCAMPAIGNS" for all campaigns, or use single dash delimiters if
requesting more than one specific campaign
OPTIONAL FIELDS-
query_date - Date to report on, leave blank to default to today's date. Must be in YYYY-MM-DD format
ingroups - List of ingroups to report on. Leave blank for all ingroups belonging to the campaigns specified in the "campaigns" variable.
Use dash delimiters if requesting more than one ingroup.
statuses - List of specific statuses to report on. Leave blank for all, or use dash delimiters if requesting more than one status.
Example URL strings for API calls:
http://server/vicidial/non_agent_api.php?user=6666&pass=1234&function=call_status_stats&campaigns=---ALL---&query_date=2017-11-24 (returns all campaigns and ingroups for 11/24/17)
http://server/vicidial/non_agent_api.php?user=6666&pass=1234&function=call_status_stats&campaigns=TESTCAMP-TESTCAMP2&query_date=2017-11-24&statuses=NP-TD&ingroups=AGENTDIRECT
(returns stat counts for TESTCAMP and TESTCAMP2 campaigns, and AGENTDIRECT ingroup, for 11/24/27 for calls dispositioned as NP and TD)
Example responses:
ERROR: call_status_stats INVALID OR MISSING CAMPAIGNS
ERROR: auth USER DOES NOT HAVE PERMISSION TO USE THIS FUNCTION
ERROR: call_status_stats USER DOES NOT HAVE PERMISSION TO VIEW STATS
A SUCCESS response will not show "SUCCESS", but instead will just print the results in the following format:
campaign_id/ingroup|total calls|human answered calls|hourly breakdown(HH-count,HH-count,etc...)|status breakdown(status-count,status-count,etc...)
Hourly and status breakdowns are delimited by comma, and each hour/status count is delimited by dash, as seen below:
TESTCAMP|26|26|00-0,01-1,02-1,03-0,04-0,05-0,06-0,07-0,08-0,09-0,10-0,11-3,12-4,13-2,14-4,15-1,16-0,17-2,18-0,19-0,20-0,21-6,22-1,23-1|NP-4,TD-22|
AGENTDIRECT|2|2|00-0,01-0,02-0,03-0,04-0,05-0,06-0,07-0,08-0,09-0,10-0,11-1,12-1,13-0,14-0,15-0,16-0,17-0,18-0,19-0,20-0,21-0,22-0,23-0|TD-2|
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
update_campaign - updates campaign information in the vicidial_campaigns table update_campaign - updates campaign information in the vicidial_campaigns table
+4 -3
View File
@@ -126,7 +126,7 @@ $UGreports = 'ALL REPORTS, NONE, Real-Time Main Report, Real-Time Campaign Summa
$Vtables = 'NONE,log_noanswer,did_agent_log,contact_information'; $Vtables = 'NONE,log_noanswer,did_agent_log,contact_information';
$APIfunctions = 'ALL_FUNCTIONS add_group_alias add_lead add_list add_phone add_phone_alias add_user agent_ingroup_info agent_stats_export agent_status audio_playback blind_monitor call_agent callid_info change_ingroups check_phone_number did_log_export external_add_lead external_dial external_hangup external_pause external_status in_group_status logout moh_list park_call pause_code preview_dial_action ra_call_control recording recording_lookup send_dtmf server_refresh set_timer_action sounds_list st_get_agent_active_lead st_login_log transfer_conference update_fields update_lead update_list update_log_entry update_phone update_phone_alias update_user user_group_status vm_list webphone_url webserver logged_in_agents update_campaigns lead_field_info phone_number_log switch_lead ccc_lead_info'; $APIfunctions = 'ALL_FUNCTIONS add_group_alias add_lead add_list add_phone add_phone_alias add_user agent_ingroup_info agent_stats_export agent_status audio_playback blind_monitor call_agent callid_info change_ingroups check_phone_number did_log_export external_add_lead external_dial external_hangup external_pause external_status in_group_status logout moh_list park_call pause_code preview_dial_action ra_call_control recording recording_lookup send_dtmf server_refresh set_timer_action sounds_list st_get_agent_active_lead st_login_log transfer_conference update_fields update_lead update_list update_log_entry update_phone update_phone_alias update_user user_group_status vm_list webphone_url webserver logged_in_agents update_campaigns lead_field_info phone_number_log switch_lead ccc_lead_info lead_status_search call_status_stats';
### BEGIN housecleaning of old static report files, if not done before ### ### BEGIN housecleaning of old static report files, if not done before ###
@@ -4236,12 +4236,13 @@ else
# 171224-1220 - Added List default_xfer_group override # 171224-1220 - Added List default_xfer_group override
# 171229-2309 - Added housecleaning code # 171229-2309 - Added housecleaning code
# 180108-2011 - Added next_dial_my_callbacks campaign option, updated for 2018 # 180108-2011 - Added next_dial_my_callbacks campaign option, updated for 2018
# 180109-1316 - Added call_status_stats API function
# #
# make sure you have added a user to the vicidial_users MySQL table with at least user_level 9 to access this page the first time # make sure you have added a user to the vicidial_users MySQL table with at least user_level 9 to access this page the first time
$admin_version = '2.14-648a'; $admin_version = '2.14-649a';
$build = '180108-2011'; $build = '180109-1316';
$STARTtime = date("U"); $STARTtime = date("U");
$SQLdate = date("Y-m-d H:i:s"); $SQLdate = date("Y-m-d H:i:s");
+121 -10
View File
@@ -5,7 +5,7 @@
# vicidial_log and/or vicidial_closer_log information by status, list_id and # vicidial_log and/or vicidial_closer_log information by status, list_id and
# date range. downloads to a flat text file that is tab delimited # date range. downloads to a flat text file that is tab delimited
# #
# Copyright (C) 2017 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2 # Copyright (C) 2018 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# #
# CHANGES # CHANGES
# #
@@ -29,6 +29,7 @@
# 170409-1542 - Added IP List validation code # 170409-1542 - Added IP List validation code
# 170531-2230 - Added DID filtering option # 170531-2230 - Added DID filtering option
# 170615-2245 - Refined DID filtering to calculate call length w/internal transfers # 170615-2245 - Refined DID filtering to calculate call length w/internal transfers
# 180109-2005 - Added vendor lead code filtering option
# #
$startMS = microtime(); $startMS = microtime();
@@ -55,10 +56,14 @@ if (isset($_GET["list_id"])) {$list_id=$_GET["list_id"];}
elseif (isset($_POST["list_id"])) {$list_id=$_POST["list_id"];} elseif (isset($_POST["list_id"])) {$list_id=$_POST["list_id"];}
if (isset($_GET["status"])) {$status=$_GET["status"];} if (isset($_GET["status"])) {$status=$_GET["status"];}
elseif (isset($_POST["status"])) {$status=$_POST["status"];} elseif (isset($_POST["status"])) {$status=$_POST["status"];}
if (isset($_GET["did_filter"])) {$did_filter=$_GET["did_filter"];} if (isset($_GET["did_filter"])) {$did_filter=$_GET["did_filter"];}
elseif (isset($_POST["did_filter"])) {$did_filter=$_POST["did_filter"];} elseif (isset($_POST["did_filter"])) {$did_filter=$_POST["did_filter"];}
if (isset($_GET["dids"])) {$dids=$_GET["dids"];} if (isset($_GET["vlc_filter"])) {$vlc_filter=$_GET["vlc_filter"];}
elseif (isset($_POST["vlc_filter"])) {$vlc_filter=$_POST["vlc_filter"];}
if (isset($_GET["dids"])) {$dids=$_GET["dids"];}
elseif (isset($_POST["dids"])) {$dids=$_POST["dids"];} elseif (isset($_POST["dids"])) {$dids=$_POST["dids"];}
if (isset($_GET["vlcs"])) {$vlcs=$_GET["vlcs"];}
elseif (isset($_POST["vlcs"])) {$vlcs=$_POST["vlcs"];}
if (isset($_GET["DB"])) {$DB=$_GET["DB"];} if (isset($_GET["DB"])) {$DB=$_GET["DB"];}
elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];}
if (isset($_GET["run_export"])) {$run_export=$_GET["run_export"];} if (isset($_GET["run_export"])) {$run_export=$_GET["run_export"];}
@@ -79,8 +84,10 @@ if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];}
elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];}
if (isset($_GET["search_archived_data"])) {$search_archived_data=$_GET["search_archived_data"];} if (isset($_GET["search_archived_data"])) {$search_archived_data=$_GET["search_archived_data"];}
elseif (isset($_POST["search_archived_data"])) {$search_archived_data=$_POST["search_archived_data"];} elseif (isset($_POST["search_archived_data"])) {$search_archived_data=$_POST["search_archived_data"];}
if (isset($_GET["vicidial_list_archive_only"])) {$vicidial_list_archive_only=$_GET["vicidial_list_archive_only"];} if (isset($_GET["vicidial_list_archive_only"])) {$vicidial_list_archive_only=$_GET["vicidial_list_archive_only"];}
elseif (isset($_POST["vicidial_list_archive_only"])) {$vicidial_list_archive_only=$_POST["vicidial_list_archive_only"];} elseif (isset($_POST["vicidial_list_archive_only"])) {$vicidial_list_archive_only=$_POST["vicidial_list_archive_only"];}
if (isset($_GET["VLC_enabled"])) {$VLC_enabled=$_GET["VLC_enabled"];}
elseif (isset($_POST["VLC_enabled"])) {$VLC_enabled=$_POST["VLC_enabled"];}
if (strlen($shift)<2) {$shift='ALL';} if (strlen($shift)<2) {$shift='ALL';}
@@ -376,6 +383,7 @@ if ($run_export > 0)
$list_ct = count($list_id); $list_ct = count($list_id);
$status_ct = count($status); $status_ct = count($status);
$did_ct = count($dids); $did_ct = count($dids);
$vlc_ct = count($vlcs);
$campaign_string='|'; $campaign_string='|';
$group_string='|'; $group_string='|';
$user_group_string='|'; $user_group_string='|';
@@ -446,6 +454,27 @@ if ($run_export > 0)
} }
if ($did_filter=="NO") {$did_SQL=""; $RUNdid=0;} if ($did_filter=="NO") {$did_SQL=""; $RUNdid=0;}
$i=0;
while($i < $vlc_ct)
{
$vlc_string .= "$vlcs[$i]|";
$vlc_SQL .= "'$vlcs[$i]',";
$i++;
}
if ( (preg_match('/\-\-NONE\-\-/',$vlc_string) ) or ($vlc_ct < 1) )
{
$vlc_SQL = "''";
$vlc_SQL = "vendor_lead_code IN('')"; # JCJ
$RUNvlc=0;
}
else
{
$vlc_SQL = preg_replace('/,$/i', '',$vlc_SQL);
$vlc_SQL = "and vendor_lead_code IN($vlc_SQL)"; # JCJ
$RUNvlc++;
}
if ($vlc_filter=="NO") {$vlc_SQL=""; $RUNvlc=0;}
$i=0; $i=0;
while($i < $user_group_ct) while($i < $user_group_ct)
{ {
@@ -518,6 +547,8 @@ if ($run_export > 0)
echo "<BR>\n"; echo "<BR>\n";
echo "$did_ct|$did_string|$did_SQL\n"; echo "$did_ct|$did_string|$did_SQL\n";
echo "<BR>\n"; echo "<BR>\n";
echo "$vlc_ct|$vlc_string|$vlc_SQL\n";
echo "<BR>\n";
echo "$user_group_ct|$user_group_string|$user_group_SQL\n"; echo "$user_group_ct|$user_group_string|$user_group_SQL\n";
echo "<BR>\n"; echo "<BR>\n";
echo "$list_ct|$list_string|$list_SQL\n"; echo "$list_ct|$list_string|$list_SQL\n";
@@ -531,7 +562,7 @@ if ($run_export > 0)
$k=0; $k=0;
if ($RUNcampaign > 0) if ($RUNcampaign > 0)
{ {
$stmt = "SELECT vl.call_date,vl.phone_number,vi.status,vl.user,vu.full_name,vl.campaign_id,vi.vendor_lead_code,vi.source_id,vi.list_id,vi.gmt_offset_now,vi.phone_code,vi.phone_number,vi.title,vi.first_name,vi.middle_initial,vi.last_name,vi.address1,vi.address2,vi.address3,vi.city,vi.state,vi.province,vi.postal_code,vi.country_code,vi.gender,vi.date_of_birth,vi.alt_phone,vi.email,vi.security_phrase,vi.comments,vl.length_in_sec,vl.user_group,vl.alt_dial,vi.rank,vi.owner,vi.lead_id,vl.uniqueid,vi.entry_list_id,UNIX_TIMESTAMP(vl.call_date)$export_fields_SQL from vicidial_users vu,".$vicidial_log_table." vl,".$vicidial_list_table." vi where ".$date_field." >= '$query_date 00:00:00' and ".$date_field." <= '$end_date 23:59:59' and vu.user=vl.user and vi.lead_id=vl.lead_id $list_SQL $campaign_SQL $user_group_SQL $status_SQL order by ".$date_field." desc limit 500000;"; $stmt = "SELECT vl.call_date,vl.phone_number,vi.status,vl.user,vu.full_name,vl.campaign_id,vi.vendor_lead_code,vi.source_id,vi.list_id,vi.gmt_offset_now,vi.phone_code,vi.phone_number,vi.title,vi.first_name,vi.middle_initial,vi.last_name,vi.address1,vi.address2,vi.address3,vi.city,vi.state,vi.province,vi.postal_code,vi.country_code,vi.gender,vi.date_of_birth,vi.alt_phone,vi.email,vi.security_phrase,vi.comments,vl.length_in_sec,vl.user_group,vl.alt_dial,vi.rank,vi.owner,vi.lead_id,vl.uniqueid,vi.entry_list_id,UNIX_TIMESTAMP(vl.call_date)$export_fields_SQL from vicidial_users vu,".$vicidial_log_table." vl,".$vicidial_list_table." vi where ".$date_field." >= '$query_date 00:00:00' and ".$date_field." <= '$end_date 23:59:59' and vu.user=vl.user and vi.lead_id=vl.lead_id $list_SQL $campaign_SQL $user_group_SQL $status_SQL $vlc_SQL order by ".$date_field." desc limit 500000;";
$rslt=mysql_to_mysqli($stmt, $link); $rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";} if ($DB) {echo "$stmt\n";}
$outbound_to_print = mysqli_num_rows($rslt); $outbound_to_print = mysqli_num_rows($rslt);
@@ -639,15 +670,15 @@ if ($run_export > 0)
if ($RUNdid > 0 && $RUNgroup > 0) if ($RUNdid > 0 && $RUNgroup > 0)
{ {
$stmtA = "SELECT vl.call_date,vl.phone_number,vi.status,vl.user,vu.full_name,vl.campaign_id,vi.vendor_lead_code,vi.source_id,vi.list_id,vi.gmt_offset_now,vi.phone_code,vi.phone_number,vi.title,vi.first_name,vi.middle_initial,vi.last_name,vi.address1,vi.address2,vi.address3,vi.city,vi.state,vi.province,vi.postal_code,vi.country_code,vi.gender,vi.date_of_birth,vi.alt_phone,vi.email,vi.security_phrase,vi.comments,vl.length_in_sec,vl.user_group,vl.queue_seconds,vi.rank,vi.owner,vi.lead_id,vl.closecallid,vi.entry_list_id,vl.uniqueid,UNIX_TIMESTAMP(vl.call_date)$export_fields_SQL from vicidial_users vu,".$vicidial_closer_log_table." vl,".$vicidial_list_table." vi, ".$vicidial_did_log_table." vdl where ".$date_field." >= '$query_date 00:00:00' and ".$date_field." <= '$end_date 23:59:59' and vu.user=vl.user and vi.lead_id=vl.lead_id and vl.uniqueid=vdl.uniqueid $list_SQL $group_SQL $user_group_SQL $did_SQL $status_SQL order by ".$date_field." desc limit 500000;"; $stmtA = "SELECT vl.call_date,vl.phone_number,vi.status,vl.user,vu.full_name,vl.campaign_id,vi.vendor_lead_code,vi.source_id,vi.list_id,vi.gmt_offset_now,vi.phone_code,vi.phone_number,vi.title,vi.first_name,vi.middle_initial,vi.last_name,vi.address1,vi.address2,vi.address3,vi.city,vi.state,vi.province,vi.postal_code,vi.country_code,vi.gender,vi.date_of_birth,vi.alt_phone,vi.email,vi.security_phrase,vi.comments,vl.length_in_sec,vl.user_group,vl.queue_seconds,vi.rank,vi.owner,vi.lead_id,vl.closecallid,vi.entry_list_id,vl.uniqueid,UNIX_TIMESTAMP(vl.call_date)$export_fields_SQL from vicidial_users vu,".$vicidial_closer_log_table." vl,".$vicidial_list_table." vi, ".$vicidial_did_log_table." vdl where ".$date_field." >= '$query_date 00:00:00' and ".$date_field." <= '$end_date 23:59:59' and vu.user=vl.user and vi.lead_id=vl.lead_id and vl.uniqueid=vdl.uniqueid $list_SQL $group_SQL $user_group_SQL $did_SQL $status_SQL $vlc_SQL order by ".$date_field." desc limit 500000;";
} }
else if ($RUNdid > 0) else if ($RUNdid > 0)
{ {
$stmtA = "SELECT vl.call_date,vl.phone_number,vi.status,vl.user,vu.full_name,vl.campaign_id,vi.vendor_lead_code,vi.source_id,vi.list_id,vi.gmt_offset_now,vi.phone_code,vi.phone_number,vi.title,vi.first_name,vi.middle_initial,vi.last_name,vi.address1,vi.address2,vi.address3,vi.city,vi.state,vi.province,vi.postal_code,vi.country_code,vi.gender,vi.date_of_birth,vi.alt_phone,vi.email,vi.security_phrase,vi.comments,vl.length_in_sec,vl.user_group,vl.queue_seconds,vi.rank,vi.owner,vi.lead_id,vl.closecallid,vi.entry_list_id,vl.uniqueid,UNIX_TIMESTAMP(vl.call_date)$export_fields_SQL from vicidial_users vu,".$vicidial_closer_log_table." vl,".$vicidial_list_table." vi, ".$vicidial_did_log_table." vdl where ".$date_field." >= '$query_date 00:00:00' and ".$date_field." <= '$end_date 23:59:59' and vu.user=vl.user and vi.lead_id=vl.lead_id and vl.uniqueid=vdl.uniqueid $list_SQL $user_group_SQL $status_SQL $did_SQL order by ".$date_field." desc limit 500000;"; $stmtA = "SELECT vl.call_date,vl.phone_number,vi.status,vl.user,vu.full_name,vl.campaign_id,vi.vendor_lead_code,vi.source_id,vi.list_id,vi.gmt_offset_now,vi.phone_code,vi.phone_number,vi.title,vi.first_name,vi.middle_initial,vi.last_name,vi.address1,vi.address2,vi.address3,vi.city,vi.state,vi.province,vi.postal_code,vi.country_code,vi.gender,vi.date_of_birth,vi.alt_phone,vi.email,vi.security_phrase,vi.comments,vl.length_in_sec,vl.user_group,vl.queue_seconds,vi.rank,vi.owner,vi.lead_id,vl.closecallid,vi.entry_list_id,vl.uniqueid,UNIX_TIMESTAMP(vl.call_date)$export_fields_SQL from vicidial_users vu,".$vicidial_closer_log_table." vl,".$vicidial_list_table." vi, ".$vicidial_did_log_table." vdl where ".$date_field." >= '$query_date 00:00:00' and ".$date_field." <= '$end_date 23:59:59' and vu.user=vl.user and vi.lead_id=vl.lead_id and vl.uniqueid=vdl.uniqueid $list_SQL $user_group_SQL $status_SQL $vlc_SQL $did_SQL order by ".$date_field." desc limit 500000;";
} }
else else
{ {
$stmtA = "SELECT vl.call_date,vl.phone_number,vi.status,vl.user,vu.full_name,vl.campaign_id,vi.vendor_lead_code,vi.source_id,vi.list_id,vi.gmt_offset_now,vi.phone_code,vi.phone_number,vi.title,vi.first_name,vi.middle_initial,vi.last_name,vi.address1,vi.address2,vi.address3,vi.city,vi.state,vi.province,vi.postal_code,vi.country_code,vi.gender,vi.date_of_birth,vi.alt_phone,vi.email,vi.security_phrase,vi.comments,vl.length_in_sec,vl.user_group,vl.queue_seconds,vi.rank,vi.owner,vi.lead_id,vl.closecallid,vi.entry_list_id,vl.uniqueid,UNIX_TIMESTAMP(vl.call_date)$export_fields_SQL from vicidial_users vu,".$vicidial_closer_log_table." vl,".$vicidial_list_table." vi where ".$date_field." >= '$query_date 00:00:00' and ".$date_field." <= '$end_date 23:59:59' and vu.user=vl.user and vi.lead_id=vl.lead_id $list_SQL $group_SQL $user_group_SQL $status_SQL order by ".$date_field." desc limit 500000;"; $stmtA = "SELECT vl.call_date,vl.phone_number,vi.status,vl.user,vu.full_name,vl.campaign_id,vi.vendor_lead_code,vi.source_id,vi.list_id,vi.gmt_offset_now,vi.phone_code,vi.phone_number,vi.title,vi.first_name,vi.middle_initial,vi.last_name,vi.address1,vi.address2,vi.address3,vi.city,vi.state,vi.province,vi.postal_code,vi.country_code,vi.gender,vi.date_of_birth,vi.alt_phone,vi.email,vi.security_phrase,vi.comments,vl.length_in_sec,vl.user_group,vl.queue_seconds,vi.rank,vi.owner,vi.lead_id,vl.closecallid,vi.entry_list_id,vl.uniqueid,UNIX_TIMESTAMP(vl.call_date)$export_fields_SQL from vicidial_users vu,".$vicidial_closer_log_table." vl,".$vicidial_list_table." vi where ".$date_field." >= '$query_date 00:00:00' and ".$date_field." <= '$end_date 23:59:59' and vu.user=vl.user and vi.lead_id=vl.lead_id $list_SQL $group_SQL $user_group_SQL $status_SQL $vlc_SQL order by ".$date_field." desc limit 500000;";
} }
$rslt=mysql_to_mysqli($stmtA, $link); $rslt=mysql_to_mysqli($stmtA, $link);
if ($DB) {echo "$stmtA\n";} if ($DB) {echo "$stmtA\n";}
@@ -1139,6 +1170,7 @@ if ($run_export > 0)
} }
else else
{ {
echo "$stmtA\n";
echo _QXZ("There are no calls during this time period for these parameter")."\n"; echo _QXZ("There are no calls during this time period for these parameter")."\n";
exit; exit;
} }
@@ -1249,6 +1281,28 @@ else
} }
if (strlen($did_SQL)<3) {$did_SQL="''";} if (strlen($did_SQL)<3) {$did_SQL="''";}
$i=0;
$vlc_string='|';
$vlc_ct = count($vlcs);
while($i < $vlc_ct)
{
if ( (strlen($vlcs[$i]) > 0) and (preg_match("/\|$vlcs[$i]\|/",$vlc_string)) )
{
$vlc_string .= "$vlcs[$i]|";
$vlc_SQL .= "'$vlcs[$i]',";
$vlcQS .= "&vlcs[]=$vlcs[$i]";
}
$i++;
}
if ( (preg_match('/\s\-\-NONE\-\-\s/',$vlc_string) ) or ($vlc_ct < 1) )
{
$vlc_SQL = "''";
}
else
{
$vlc_SQL = preg_replace('/,$/i', '',$vlc_SQL);
}
if (strlen($vlc_SQL)<3) {$vlc_SQL="''";}
$stmt="select list_id from vicidial_lists $whereLOGallowed_campaignsSQL order by list_id;"; $stmt="select list_id from vicidial_lists $whereLOGallowed_campaignsSQL order by list_id;";
$rslt=mysql_to_mysqli($stmt, $link); $rslt=mysql_to_mysqli($stmt, $link);
@@ -1258,12 +1312,42 @@ else
$LISTlists[$i]='---ALL---'; $LISTlists[$i]='---ALL---';
$i++; $i++;
$lists_to_print++; $lists_to_print++;
$allowed_lists=array();
while ($i < $lists_to_print) while ($i < $lists_to_print)
{ {
$row=mysqli_fetch_row($rslt); $row=mysqli_fetch_row($rslt);
$LISTlists[$i] =$row[0]; $LISTlists[$i] =$row[0];
array_push($allowed_lists, $row[0]);
$i++; $i++;
} }
if (count($allowed_lists)>0)
{
$whereLOGallowed_listsSQL="where list_id in ('".implode("','", $allowed_lists)."')";
$LOGallowed_listsSQL="and list_id in ('".implode("','", $allowed_lists)."')";
}
else
{
$whereLOGallowed_listsSQL='';
$LOGallowed_listsSQL='';
}
if ($VLC_enabled == 'Y')
{
$stmt="select distinct vendor_lead_code from vicidial_list $whereLOGallowed_listsSQL order by vendor_lead_code;";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$vlcs_to_print = mysqli_num_rows($rslt);
$i=0;
$LISTvlcs[$i]='---NONE---';
$i++;
$vlcs_to_print++;
while ($i < $vlcs_to_print)
{
$row=mysqli_fetch_row($rslt);
$LISTvlcs[$i] =$row[0];
$i++;
}
}
$stmt="select status from vicidial_statuses order by status;"; $stmt="select status from vicidial_statuses order by status;";
$rslt=mysql_to_mysqli($stmt, $link); $rslt=mysql_to_mysqli($stmt, $link);
@@ -1330,6 +1414,7 @@ else
echo "<FORM ACTION=\"$PHP_SELF\" METHOD=GET name=vicidial_report id=vicidial_report>\n"; echo "<FORM ACTION=\"$PHP_SELF\" METHOD=GET name=vicidial_report id=vicidial_report>\n";
echo "<INPUT TYPE=HIDDEN NAME=DB VALUE=\"$DB\">"; echo "<INPUT TYPE=HIDDEN NAME=DB VALUE=\"$DB\">";
echo "<INPUT TYPE=HIDDEN NAME=run_export VALUE=\"1\">"; echo "<INPUT TYPE=HIDDEN NAME=run_export VALUE=\"1\">";
echo "<INPUT TYPE=HIDDEN NAME=VLC_enabled VALUE=\"$VLC_enabled\">";
echo "<TABLE BORDER=0 CELLSPACING=8><TR><TD ALIGN=LEFT VALIGN=TOP ROWSPAN=3>\n"; echo "<TABLE BORDER=0 CELLSPACING=8><TR><TD ALIGN=LEFT VALIGN=TOP ROWSPAN=3>\n";
echo "<font class=\"select_bold\"><B>"._QXZ("Date Range").":</B></font><BR><CENTER>\n"; echo "<font class=\"select_bold\"><B>"._QXZ("Date Range").":</B></font><BR><CENTER>\n";
@@ -1408,6 +1493,16 @@ else
echo "<BR><BR>\n"; echo "<BR><BR>\n";
if ($VLC_enabled == 'Y')
{
echo "<B>"._QXZ("Use VLC filter").":</B><BR>\n";
echo "<select size=1 name=vlc_filter onChange=\"if (this.value=='YES') {document.getElementById('vlc_span').style.display='block';} else {document.getElementById('vlc_span').style.display='none';}\">";
if ($vlc_filter) {echo "<option value='$vlc_filter' selected>$vlc_filter</option>";}
echo "<option value='NO'>"._QXZ("NO")."</option><option value='YES'>"._QXZ("YES")."</option></select>\n";
echo "<BR><BR>\n";
}
echo "<B>"._QXZ("Export Fields").":</B><BR>\n"; echo "<B>"._QXZ("Export Fields").":</B><BR>\n";
echo "<select size=1 name=export_fields><option value='STANDARD' selected>"._QXZ("STANDARD")."</option><option value='EXTENDED'>"._QXZ("EXTENDED")."</option></select>\n"; echo "<select size=1 name=export_fields><option value='STANDARD' selected>"._QXZ("STANDARD")."</option><option value='EXTENDED'>"._QXZ("EXTENDED")."</option></select>\n";
@@ -1477,7 +1572,8 @@ else
$o++; $o++;
} }
echo "</SELECT>\n"; echo "</SELECT>\n";
echo "</TD><TD ALIGN=LEFT VALIGN=TOP ROWSPAN=3>\n"; echo "</TD>\n";
echo "<TD ALIGN=LEFT VALIGN=TOP ROWSPAN=3>\n";
echo "<font class=\"select_bold\"><B>"._QXZ("User Groups").":</B></font><BR><CENTER>\n"; echo "<font class=\"select_bold\"><B>"._QXZ("User Groups").":</B></font><BR><CENTER>\n";
echo "<SELECT SIZE=20 NAME=user_group[] multiple>\n"; echo "<SELECT SIZE=20 NAME=user_group[] multiple>\n";
$o=0; $o=0;
@@ -1505,6 +1601,21 @@ else
} }
echo "</SELECT></SPAN></TD>\n"; echo "</SELECT></SPAN></TD>\n";
echo "<TD ALIGN=LEFT VALIGN=TOP ROWSPAN=3><SPAN ID='vlc_span' style='display:".($vlc_filter=="YES" ? "block" : "none").";'>\n";
echo "<font class=\"select_bold\"><B>"._QXZ("Vendor lead codes").":</B></font><BR><CENTER>\n";
echo "<SELECT SIZE=20 NAME=vlcs[] multiple>\n";
$o=0;
while ($vlcs_to_print > $o)
{
if (preg_match("/\|$LISTvlcs[$o]\|/",$vlc_string))
{echo "<option selected value=\"$LISTvlcs[$o]\">$LISTvlcs[$o]</option>\n";}
else
{echo "<option value=\"$LISTvlcs[$o]\">$LISTvlcs[$o]</option>\n";}
$o++;
}
echo "</SELECT></SPAN></TD>\n";
echo "</TR><TR></TD><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> &nbsp; \n"; echo "</TR><TR></TD><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> &nbsp; \n";
echo "</TD></TR><TR></TD><TD ALIGN=CENTER VALIGN=TOP COLSPAN=5>\n"; echo "</TD></TR><TR></TD><TD ALIGN=CENTER VALIGN=TOP COLSPAN=5>\n";
+236 -3
View File
@@ -1,7 +1,7 @@
<?php <?php
# non_agent_api.php # non_agent_api.php
# #
# Copyright (C) 2017 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2 # Copyright (C) 2018 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# #
# This script is designed as an API(Application Programming Interface) to allow # This script is designed as an API(Application Programming Interface) to allow
# other programs to interact with all non-agent-screen VICIDIAL functions # other programs to interact with all non-agent-screen VICIDIAL functions
@@ -127,10 +127,11 @@
# 171114-1015 - Added ability for update_lead function insert_if_not_found leads to be inserted into the hopper # 171114-1015 - Added ability for update_lead function insert_if_not_found leads to be inserted into the hopper
# 171129-0751 - Fixed issue with duplicate custom fields # 171129-0751 - Fixed issue with duplicate custom fields
# 171229-1602 - Added lead_status_search function # 171229-1602 - Added lead_status_search function
# 180109-1313 - Added call_status_stats function
# #
$version = '2.14-103'; $version = '2.14-104';
$build = '171229-1602'; $build = '180109-1313';
$api_url_log = 0; $api_url_log = 0;
$startMS = microtime(); $startMS = microtime();
@@ -243,6 +244,8 @@ if (isset($_GET["search_location"])) {$search_location=$_GET["search_location"
elseif (isset($_POST["search_location"])) {$search_location=$_POST["search_location"];} elseif (isset($_POST["search_location"])) {$search_location=$_POST["search_location"];}
if (isset($_GET["status"])) {$status=$_GET["status"];} if (isset($_GET["status"])) {$status=$_GET["status"];}
elseif (isset($_POST["status"])) {$status=$_POST["status"];} elseif (isset($_POST["status"])) {$status=$_POST["status"];}
if (isset($_GET["statuses"])) {$statuses=$_GET["statuses"];}
elseif (isset($_POST["statuses"])) {$statuses=$_POST["statuses"];}
if (isset($_GET["user_field"])) {$user_field=$_GET["user_field"];} if (isset($_GET["user_field"])) {$user_field=$_GET["user_field"];}
elseif (isset($_POST["user_field"])) {$user_field=$_POST["user_field"];} elseif (isset($_POST["user_field"])) {$user_field=$_POST["user_field"];}
if (isset($_GET["list_id_field"])) {$list_id_field=$_GET["list_id_field"];} if (isset($_GET["list_id_field"])) {$list_id_field=$_GET["list_id_field"];}
@@ -257,6 +260,14 @@ if (isset($_GET["called_count"])) {$called_count=$_GET["called_count"];}
elseif (isset($_POST["called_count"])) {$called_count=$_POST["called_count"];} elseif (isset($_POST["called_count"])) {$called_count=$_POST["called_count"];}
if (isset($_GET["date"])) {$date=$_GET["date"];} if (isset($_GET["date"])) {$date=$_GET["date"];}
elseif (isset($_POST["date"])) {$date=$_POST["date"];} elseif (isset($_POST["date"])) {$date=$_POST["date"];}
if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];}
elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];}
if (isset($_GET["query_time"])) {$query_time=$_GET["query_time"];}
elseif (isset($_POST["query_time"])) {$query_time=$_POST["query_time"];}
if (isset($_GET["end_date"])) {$end_date=$_GET["end_date"];}
elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];}
if (isset($_GET["end_time"])) {$end_time=$_GET["end_time"];}
elseif (isset($_POST["end_time"])) {$end_time=$_POST["end_time"];}
if (isset($_GET["header"])) {$header=$_GET["header"];} if (isset($_GET["header"])) {$header=$_GET["header"];}
elseif (isset($_POST["header"])) {$header=$_POST["header"];} elseif (isset($_POST["header"])) {$header=$_POST["header"];}
if (isset($_GET["agent_pass"])) {$agent_pass=$_GET["agent_pass"];} if (isset($_GET["agent_pass"])) {$agent_pass=$_GET["agent_pass"];}
@@ -405,6 +416,8 @@ if (isset($_GET["show_sub_status"])) {$show_sub_status=$_GET["show_sub_status"
elseif (isset($_POST["show_sub_status"])) {$show_sub_status=$_POST["show_sub_status"];} elseif (isset($_POST["show_sub_status"])) {$show_sub_status=$_POST["show_sub_status"];}
if (isset($_GET["campaigns"])) {$campaigns=$_GET["campaigns"];} if (isset($_GET["campaigns"])) {$campaigns=$_GET["campaigns"];}
elseif (isset($_POST["campaigns"])) {$campaigns=$_POST["campaigns"];} elseif (isset($_POST["campaigns"])) {$campaigns=$_POST["campaigns"];}
if (isset($_GET["ingroups"])) {$ingroups=$_GET["ingroups"];}
elseif (isset($_POST["ingroups"])) {$ingroups=$_POST["ingroups"];}
if (isset($_GET["campaign_name"])) {$campaign_name=$_GET["campaign_name"];} if (isset($_GET["campaign_name"])) {$campaign_name=$_GET["campaign_name"];}
elseif (isset($_POST["campaign_name"])) {$campaign_name=$_POST["campaign_name"];} elseif (isset($_POST["campaign_name"])) {$campaign_name=$_POST["campaign_name"];}
if (isset($_GET["auto_dial_level"])) {$auto_dial_level=$_GET["auto_dial_level"];} if (isset($_GET["auto_dial_level"])) {$auto_dial_level=$_GET["auto_dial_level"];}
@@ -9756,6 +9769,226 @@ if ($function == 'logged_in_agents')
################################################################################
### call_status_stats - campaign and ingroup call stats by hour and status
################################################################################
if ($function == 'call_status_stats')
{
# header("Content-Type: text/plain");
if(strlen($campaigns)<2)
{
$result = 'ERROR';
$result_reason = "call_status_stats INVALID OR MISSING CAMPAIGNS";
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 view_reports='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 = "call_status_stats USER DOES NOT HAVE PERMISSION TO VIEW STATS";
echo "$result: $result_reason: |$user|$allowed_user|\n";
$data = "$allowed_user";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{
if (!$query_date) {$query_date=date("Y-m-d");}
if (!$query_time) {$query_time="00:00:00";}
if (!$end_date) {$end_date=$query_date;}
if (!$end_time) {$end_time="23:59:59";}
$outbound_array=array();
$inbound_array=array();
$temp_hour_array=array();
$temp_stat_array=array();
/*
$total_calls_array=array();
$total_hr_array=array();
$total_stat_array=array();
*/
$campaign_array=explode("-", $campaigns);
$campaign_SQL=" and campaign_id in ('".implode("', '", $campaign_array)."') ";
if (in_array("ALLCAMPAIGNS", $campaign_array) || preg_match('/\-\-\-ALL\-\-\-/', $campaigns))
{
$campaign_SQL="";
$campaign_stmt="select campaign_id from vicidial_campaigns order by campaign_id";
if ($DB>0) {echo $campaign_stmt."\n";}
$campaign_rslt=mysql_to_mysqli($campaign_stmt, $link);
while ($row=mysqli_fetch_row($campaign_rslt))
{
$outbound_array{"$row[0]"}[0]=0;
$outbound_array{"$row[0]"}[1]=0;
}
}
else
{
for ($i=0; $i<count($campaign_array); $i++)
{
$outbound_array{"$campaign_array[$i]"}[0]=0;
$outbound_array{"$campaign_array[$i]"}[1]=0;
}
}
ksort($outbound_array);
$ha_stmt="select distinct status from vicidial_statuses where human_answered='Y' UNION select distinct status from vicidial_campaign_statuses where human_answered='Y' $campaign_SQL";
if ($DB>0) {echo $ha_stmt."\n";}
$ha_rslt=mysql_to_mysqli($ha_stmt, $link);
$human_ans_array=array();
while ($ha_row=mysqli_fetch_row($ha_rslt))
{
array_push($human_ans_array, $ha_row[0]);
}
if (strlen($statuses)>0)
{
$status_array=explode("-", $statuses);
$status_SQL=" and status in ('".implode("', '", $status_array)."') ";
}
else
{
$status_SQL="";
}
if (strlen($ingroups)==0)
{
$ingroup_array=array();
$ingroup_stmt="select closer_campaigns from vicidial_campaigns where closer_campaigns is not null and closer_campaigns!='' $campaign_SQL";
if ($DB>0) {echo $ingroup_stmt."\n";}
$ingroup_rslt=mysql_to_mysqli($ingroup_stmt, $link);
while($ingroup_row=mysqli_fetch_row($ingroup_rslt))
{
$ingroup_row[0]=preg_replace('/ -$/', "", trim($ingroup_row[0]));
$ing_ary=explode(" ", $ingroup_row[0]);
$ingroup_array=array_merge($ingroup_array, $ing_ary);
}
$ingroup_array=array_unique($ingroup_array);
$ingroup_array=array_values($ingroup_array);
}
else
{
$ingroup_array=explode("-", $ingroups);
}
$ingroup_SQL=" and campaign_id in ('".implode("', '", $ingroup_array)."') ";
for ($i=0; $i<count($ingroup_array); $i++)
{
$inbound_array{"$ingroup_array[$i]"}[0]=0;
$inbound_array{"$ingroup_array[$i]"}[1]=0;
}
ksort($inbound_array);
$outb_stmt="select campaign_id, status, substr(call_date, 12, 2) as hour, count(*) from vicidial_log where call_date>='$query_date $query_time' and call_date<='$end_date $end_time' $campaign_SQL $status_SQL group by campaign_id, status, hour order by campaign_id, status, hour";
if ($DB>0) {echo $outb_stmt."\n";}
$outb_rslt=mysql_to_mysqli($outb_stmt, $link);
for ($i=0; $i<24; $i++)
{
$hrkey=substr("0$i", -2);
$total_hr_array{"$hrkey"}=0;
}
while($outb_row=mysqli_fetch_row($outb_rslt))
{
$outbound_array{"$outb_row[0]"}[0]+=$outb_row[3];
if (in_array($outb_row[1], $human_ans_array))
{
$outbound_array{"$outb_row[0]"}[1]+=$outb_row[3];
}
$temp_stat_array{"$outb_row[0]"}{"$outb_row[1]"}+=$outb_row[3];
$temp_hour_array{"$outb_row[0]"}{"$outb_row[2]"}+=$outb_row[3];
}
$inb_stmt="select campaign_id, status, substr(call_date, 12, 2) as hour, count(*) from vicidial_closer_log where call_date>='$query_date $query_time' and call_date<='$end_date $end_time' $ingroup_SQL $status_SQL group by campaign_id, status, hour order by campaign_id, status, hour";
if ($DB>0) {echo $inb_stmt."\n";}
$inb_rslt=mysql_to_mysqli($inb_stmt, $link);
while($inb_row=mysqli_fetch_row($inb_rslt))
{
$inbound_array{"$inb_row[0]"}[0]+=$inb_row[3];
if (in_array($inb_row[1], $human_ans_array))
{
$inbound_array{"$inb_row[0]"}[1]+=$inb_row[3];
}
$temp_stat_array{"$inb_row[0]"}{"$inb_row[1]"}+=$inb_row[3];
$temp_hour_array{"$inb_row[0]"}{"$inb_row[2]"}+=$inb_row[3];
}
}
while(list($key, $val)=each($outbound_array)) {
$hour_str="";
$status_str="";
for ($i=0; $i<24; $i++)
{
$hrkey=substr("0$i", -2);
$hrs=$temp_hour_array{"$key"}{"$hrkey"}+=0;
$hour_str.="$hrkey-$hrs,";
}
$hour_str=substr($hour_str, 0, -1);
$temp_ary_ct = count($temp_stat_array{"$key"});
if ($temp_ary_ct > 0)
{
ksort($temp_stat_array{"$key"});
while(list($statkey, $statval)=each($temp_stat_array{"$key"}))
{
$status_str.=$statkey."-".$temp_stat_array{"$key"}{"$statkey"}.",";
}
}
$status_str=substr($status_str, 0, -1);
echo $key."|".$outbound_array{$key}[0]."|".$outbound_array{$key}[1]."|".$hour_str."|".$status_str."|\n";
}
while(list($key, $val)=each($inbound_array)) {
$hour_str="";
$status_str="";
for ($i=0; $i<24; $i++)
{
$hrkey=substr("0$i", -2);
$hrs=$temp_hour_array{"$key"}{"$hrkey"}+=0;
$hour_str.="$hrkey-$hrs,";
}
$hour_str=substr($hour_str, 0, -1);
$temp_ary_ct = count($temp_stat_array{"$key"});
if ($temp_ary_ct > 0)
{
ksort($temp_stat_array{"$key"});
while(list($statkey, $statval)=each($temp_stat_array{"$key"}))
{
$status_str.=$statkey."-".$temp_stat_array{"$key"}{"$statkey"}.",";
}
}
$status_str=substr($status_str, 0, -1);
echo $key."|".$inbound_array{$key}[0]."|".$inbound_array{$key}[1]."|".$hour_str."|".$status_str."|\n";
}
}
exit;
}
################################################################################
### END call_status_stats
################################################################################
$result = 'ERROR'; $result = 'ERROR';
$result_reason = "NO FUNCTION SPECIFIED"; $result_reason = "NO FUNCTION SPECIFIED";