diff --git a/docs/NON-AGENT_API.txt b/docs/NON-AGENT_API.txt index dd43b7dc..c388b75a 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: 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 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 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 - +call_status_stats - report on number of calls made by campaign and ingroup, with hourly and status breakdowns New scripts: /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 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 +180109-1313 - Added call_status_stats function 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 diff --git a/www/vicidial/admin.php b/www/vicidial/admin.php index abafd737..bde7428b 100644 --- a/www/vicidial/admin.php +++ b/www/vicidial/admin.php @@ -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'; -$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 ### @@ -4236,12 +4236,13 @@ else # 171224-1220 - Added List default_xfer_group override # 171229-2309 - Added housecleaning code # 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 -$admin_version = '2.14-648a'; -$build = '180108-2011'; +$admin_version = '2.14-649a'; +$build = '180109-1316'; $STARTtime = date("U"); $SQLdate = date("Y-m-d H:i:s"); diff --git a/www/vicidial/lead_report_export.php b/www/vicidial/lead_report_export.php index a56cb1d4..97bb4c52 100644 --- a/www/vicidial/lead_report_export.php +++ b/www/vicidial/lead_report_export.php @@ -5,7 +5,7 @@ # 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 # -# Copyright (C) 2017 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2018 Matt Florell LICENSE: AGPLv2 # # CHANGES # @@ -29,6 +29,7 @@ # 170409-1542 - Added IP List validation code # 170531-2230 - Added DID filtering option # 170615-2245 - Refined DID filtering to calculate call length w/internal transfers +# 180109-2005 - Added vendor lead code filtering option # $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"];} if (isset($_GET["status"])) {$status=$_GET["status"];} elseif (isset($_POST["status"])) {$status=$_POST["status"];} -if (isset($_GET["did_filter"])) {$did_filter=$_GET["did_filter"];} - elseif (isset($_POST["did_filter"])) {$did_filter=$_POST["did_filter"];} -if (isset($_GET["dids"])) {$dids=$_GET["dids"];} +if (isset($_GET["did_filter"])) {$did_filter=$_GET["did_filter"];} + elseif (isset($_POST["did_filter"])) {$did_filter=$_POST["did_filter"];} +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"];} +if (isset($_GET["vlcs"])) {$vlcs=$_GET["vlcs"];} + elseif (isset($_POST["vlcs"])) {$vlcs=$_POST["vlcs"];} if (isset($_GET["DB"])) {$DB=$_GET["DB"];} elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} 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"];} 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"];} -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"];} +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';} @@ -376,6 +383,7 @@ if ($run_export > 0) $list_ct = count($list_id); $status_ct = count($status); $did_ct = count($dids); + $vlc_ct = count($vlcs); $campaign_string='|'; $group_string='|'; $user_group_string='|'; @@ -446,6 +454,27 @@ if ($run_export > 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; while($i < $user_group_ct) { @@ -518,6 +547,8 @@ if ($run_export > 0) echo "
\n"; echo "$did_ct|$did_string|$did_SQL\n"; echo "
\n"; + echo "$vlc_ct|$vlc_string|$vlc_SQL\n"; + echo "
\n"; echo "$user_group_ct|$user_group_string|$user_group_SQL\n"; echo "
\n"; echo "$list_ct|$list_string|$list_SQL\n"; @@ -531,7 +562,7 @@ if ($run_export > 0) $k=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); if ($DB) {echo "$stmt\n";} $outbound_to_print = mysqli_num_rows($rslt); @@ -639,15 +670,15 @@ if ($run_export > 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) { - $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 { - $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); if ($DB) {echo "$stmtA\n";} @@ -1139,6 +1170,7 @@ if ($run_export > 0) } else { + echo "$stmtA\n"; echo _QXZ("There are no calls during this time period for these parameter")."\n"; exit; } @@ -1249,6 +1281,28 @@ else } 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;"; $rslt=mysql_to_mysqli($stmt, $link); @@ -1258,12 +1312,42 @@ else $LISTlists[$i]='---ALL---'; $i++; $lists_to_print++; + $allowed_lists=array(); while ($i < $lists_to_print) { $row=mysqli_fetch_row($rslt); $LISTlists[$i] =$row[0]; + array_push($allowed_lists, $row[0]); $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;"; $rslt=mysql_to_mysqli($stmt, $link); @@ -1330,6 +1414,7 @@ else echo "
\n"; echo ""; echo ""; + echo ""; echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; echo ""._QXZ("Date Range").":
\n"; @@ -1408,6 +1493,16 @@ else echo "

\n"; + if ($VLC_enabled == 'Y') + { + echo ""._QXZ("Use VLC filter").":
\n"; + echo "\n"; + + echo "

\n"; + } + echo ""._QXZ("Export Fields").":
\n"; echo "\n"; @@ -1477,7 +1572,8 @@ else $o++; } echo "\n"; - echo "
\n"; + echo "\n"; echo ""._QXZ("User Groups").":
\n"; echo "
\n"; + echo ""._QXZ("Vendor lead codes").":
\n"; + echo "
  \n"; echo "
\n"; diff --git a/www/vicidial/non_agent_api.php b/www/vicidial/non_agent_api.php index 0eb2bfaa..caae863c 100644 --- a/www/vicidial/non_agent_api.php +++ b/www/vicidial/non_agent_api.php @@ -1,7 +1,7 @@ LICENSE: AGPLv2 +# Copyright (C) 2018 Matt Florell LICENSE: AGPLv2 # # This script is designed as an API(Application Programming Interface) to allow # 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 # 171129-0751 - Fixed issue with duplicate custom fields # 171229-1602 - Added lead_status_search function +# 180109-1313 - Added call_status_stats function # -$version = '2.14-103'; -$build = '171229-1602'; +$version = '2.14-104'; +$build = '180109-1313'; $api_url_log = 0; $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"];} if (isset($_GET["status"])) {$status=$_GET["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"];} elseif (isset($_POST["user_field"])) {$user_field=$_POST["user_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"];} if (isset($_GET["date"])) {$date=$_GET["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"];} elseif (isset($_POST["header"])) {$header=$_POST["header"];} 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"];} if (isset($_GET["campaigns"])) {$campaigns=$_GET["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"];} elseif (isset($_POST["campaign_name"])) {$campaign_name=$_POST["campaign_name"];} 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; $i0) {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; $i0) {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_reason = "NO FUNCTION SPECIFIED";