From 89e8d576662932f4f11a5b7926f3607bfb18ff67 Mon Sep 17 00:00:00 2001 From: mattf Date: Thu, 13 Sep 2012 00:45:56 +0000 Subject: [PATCH] Added user_group_status and in_group_status functions to the non-agent-api Added new cm_status_dial.agi script git-svn-id: svn://192.168.202.10@1857 3d104415-ff17-0410-8863-d5cf3c621b8a --- UPGRADE | 2 + agi/cm_status_dial.agi | 341 +++++++++++++++++++++++++ docs/NON-AGENT_API.txt | 69 ++++- www/vicidial/non_agent_api.php | 446 ++++++++++++++++++++++++++++++++- 4 files changed, 853 insertions(+), 5 deletions(-) create mode 100644 agi/cm_status_dial.agi diff --git a/UPGRADE b/UPGRADE index fd051755..e1303107 100644 --- a/UPGRADE +++ b/UPGRADE @@ -91,6 +91,8 @@ OTHER CHANGES: 14. Added outbound call logging in vicidial_dial_log table +15. Added user_group_status and in_group_status functions to the non-agent API. + diff --git a/agi/cm_status_dial.agi b/agi/cm_status_dial.agi new file mode 100644 index 00000000..58225fd7 --- /dev/null +++ b/agi/cm_status_dial.agi @@ -0,0 +1,341 @@ +#!/usr/bin/perl +# +# cm_status_dial.agi version 2.4 +# +# Used as a Call Menu AGI option route to alter status of a lead before dialing. +# The lead is only updated if the call is tagged with a lead_id before this script. +# +# You need to put lines similar to those below in your extensions.conf file: +# ; Below are the parameters needed for the script to be run properly +# ; 1. the status to change the lead to +# ; 2. the phone number or extension to dial +# ; 3. the context to dial in +# ; +# ;inbound calls check calltime: +#cm_status_dial.agi,XFER-----917275551212-----default +# +# Copyright (C) 2012 Matt Florell LICENSE: AGPLv2 +# +# changes: +# 120909-2301 - First Build +# + +$script = 'cm_status_dial.agi'; + +($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); +$year = ($year + 1900); +$mon++; +if ($mon < 10) {$mon = "0$mon";} +if ($mday < 10) {$mday = "0$mday";} +if ($hour < 10) {$hour = "0$hour";} +if ($min < 10) {$min = "0$min";} +if ($sec < 10) {$sec = "0$sec";} + +$now_date_epoch = time(); +$now_date = "$year-$mon-$mday $hour:$min:$sec"; + +# default path to astguiclient configuration file: +$PATHconf = '/etc/astguiclient.conf'; + +open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; +@conf = ; +close(conf); +$i=0; +foreach(@conf) + { + $line = $conf[$i]; + $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; + if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) ) + {$PATHhome = $line; $PATHhome =~ s/.*=//gi;} + if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) ) + {$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;} + if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) ) + {$PATHagi = $line; $PATHagi =~ s/.*=//gi;} + if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) ) + {$PATHweb = $line; $PATHweb =~ s/.*=//gi;} + if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) ) + {$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;} + if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) ) + {$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;} + if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) ) + {$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) ) + {$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) + {$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) ) + {$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) ) + {$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) ) + {$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;} + $i++; + } + +if (!$VARDB_port) {$VARDB_port='3306';} +if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";} + +use DBI; +use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second +use Asterisk::AGI; +$AGI = new Asterisk::AGI; + +$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") + or die "Couldn't connect to database: " . DBI->errstr; + +### Grab Server values from the database +$stmtA = "SELECT agi_output FROM servers where server_ip = '$VARserver_ip';"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; +if ($sthArows > 0) + { + $AGILOG = '0'; + @aryA = $sthA->fetchrow_array; + $DBagi_output = "$aryA[0]"; + if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';} + if ($DBagi_output =~ /FILE/) {$AGILOG = '2';} + if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';} + } +$sthA->finish(); + +############################################# +##### START QUEUEMETRICS LOGGING LOOKUP ##### +#$stmtA = "SELECT enable_queuemetrics_logging,queuemetrics_server_ip,queuemetrics_dbname,queuemetrics_login,queuemetrics_pass,queuemetrics_log_id,queuemetrics_eq_prepend FROM system_settings;"; +#$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +#$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +#$sthArows=$sthA->rows; +#if ($sthArows > 0) +# { +# @aryA = $sthA->fetchrow_array; +# $enable_queuemetrics_logging = $aryA[0]; +# $queuemetrics_server_ip = $aryA[1]; +# $queuemetrics_dbname = $aryA[2]; +# $queuemetrics_login= $aryA[3]; +# $queuemetrics_pass = $aryA[4]; +# $queuemetrics_log_id = $aryA[5]; +# $queuemetrics_eq_prepend = $aryA[6]; +# } +#$sthA->finish(); +##### END QUEUEMETRICS LOGGING LOOKUP ##### +########################################### + + +### begin parsing run-time options ### +if (length($ARGV[0])>1) + { + if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;} + $i=0; + while ($#ARGV >= $i) + { + $args = "$args $ARGV[$i]"; + if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;} + $i++; + } + + ### list of command-line array arguments: + @ARGV_vars = split(/-----/, $ARGV[0]); + + $new_status = $ARGV_vars[0]; + $dial_extension = $ARGV_vars[1]; + $dial_context = $ARGV_vars[2]; + } + +$|=1; +while() + { + chomp; + last unless length($_); + if ($AGILOG) + { + if (/^agi_(\w+)\:\s+(.*)$/) + { + $AGI{$1} = $2; + } + } + + if (/^agi_context\:\s+(.*)$/) {$context = $1;} + if (/^agi_priority\:\s+(.*)$/) {$priority = $1;} + if (/^agi_uniqueid\:\s+(.*)$/) {$unique_id = $1; $uniqueid = $unique_id;} + if (/^agi_channel\:\s+(.*)$/) {$channel = $1;} + if (/^agi_extension\:\s+(.*)$/) {$extension = $1;} + if (/^agi_type\:\s+(.*)$/) {$type = $1;} + if (/^agi_callerid\:\s+(.*)$/) {$callerid = $1;} + if (/^agi_calleridname\:\s+(.*)$/) {$calleridname = $1;} + } + +$outboundIVR=0; +$fieldUPDATE=0; +if ($calleridname =~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/) + { + $phone_number = $callerid; + $callerid = $calleridname; + $outboundIVR=1; + + $stmtA = "SELECT campaign_id,lead_id FROM vicidial_auto_calls where callerid='$callerid';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $campaign_id = $aryA[0]; + $lead_id = $aryA[1]; + } + $sthA->finish(); + } +elsif ($calleridname =~ /^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/) + { + $lead_id = substr($calleridname, 10, 10); + $lead_id = ($lead_id + 0); + $phone_number = $callerid; + $callerid = $calleridname; + $fieldUPDATE=1; + } +else + { + if ( ($callerid =~ /\".*\"/) && ( (!$calleridname) or ($calleridname =~ /unknown/) ) ) + { + $calleridname = $callerid; + $calleridname =~ s/\<\d\d\d\d\d\d\d\d\d\d\>//gi; + $calleridname =~ s/\"|\" //gi; + } + + $callerid =~ s/\D|\'//gi; + $calleridname =~ s/unknown|\'//gi; + if ( (!$callerid) or ($callerid =~ /unknown/) ) + {$callerid = $calleridname;} + + + if (length($callerid)>0) {$phone_number = $callerid;} + else {$phone_number = '';} + if (length($calleridname)>0) {$VLcomments = $calleridname;} + else {$VLcomments = '';} + } + +if (length($callerid)<8) {$callerid = $parked_by;} +if (length($pin)>0) {$callerid = $pin;} + + +foreach $i (sort keys %AGI) + { + if ($AGILOG) {$agi_string = " -- $i = $AGI{$i}"; &agi_output;} + } + +if ($AGILOG) {$agi_string = "AGI Variables: |$unique_id|$channel|$extension|$type|$callerid|"; &agi_output;} + + +if (length($pin) < 1) {$pin=$inbound_number;} + +$fronter = $pin; + +if ($AGILOG) {$agi_string = "+++++ STATUS DIAL LOG STARTED : |$channel_group|$callerid-$pin|$now_date"; &agi_output;} + +$VDADphone=''; +$VDADphone_code=''; + +if ($channel =~ /Local/i) + { + if ($AGILOG) {$agi_string = "+++++ STATUS DIAL START LOCAL CHANNEL: EXITING- $priority"; &agi_output;} + exit; + } + +### insert an IVR record to the vicidial_auto_calls table +if ($outboundIVR > 0) + { + $stmtA = "UPDATE vicidial_list SET status='$new_status' where lead_id='$lead_id';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsL = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VL update: |$affected_rowsL|$new_status|$dtmf|$lead_id|$context|"; &agi_output;} + } +else + { + if ($fieldUPDATE > 0) + { + $stmtA = "UPDATE vicidial_list SET status='$new_status' where lead_id='$lead_id';"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rowsL = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "-- VL update: |$affected_rowsL|$new_status|$dtmf|$lead_id|$context|"; &agi_output;} + } + } + +### QueueMetrics logging if enabled +#if ($enable_queuemetrics_logging > 0) +# { +# $dbhB = DBI->connect("DBI:mysql:$queuemetrics_dbname:$queuemetrics_server_ip:3306", "$queuemetrics_login", "$queuemetrics_pass") +# or die "Couldn't connect to database: " . DBI->errstr; +# +# if ($DBX) {print "CONNECTED TO QueueMetrics DATABASE: $queuemetrics_server_ip|$queuemetrics_dbname\n";} +# +# if ($outboundIVR > 0) +# {$uniqueid = $caller_id;} +# +# $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$now_date_epoch',call_id='$uniqueid',queue='NONE',agent='NONE',verb='INFO',data1='IVR',data2='$context',serverid='$queuemetrics_log_id';"; +# if ($AGILOG) {$agi_string = "|$stmtB|"; &agi_output;} +# $Baffected_rows = $dbhB->do($stmtB); +# $dbhB->disconnect(); +# } + + +$sthA->finish(); +$dbhA->disconnect(); + + +if ($AGILOG) {$agi_string = " Status Dial, transferring call |$dial_extension|$dial_context|$lead_id|$calleridname|"; &agi_output;} + +print "SET CONTEXT $dial_context\n"; + checkresult($result); +print "SET EXTENSION $dial_extension\n"; + checkresult($result); +print "SET PRIORITY 1\n"; + checkresult($result); + + +exit; + + + + + +sub agi_output + { + if ($AGILOG >=2) + { + ### open the log file for writing ### + open(Lout, ">>$AGILOGfile") + || die "Can't open $AGILOGfile: $!\n"; + print Lout "$now_date|$script|$agi_string\n"; + close(Lout); + } + ### send to STDERR writing ### + if ( ($AGILOG == '1') || ($AGILOG == '3') ) + {print STDERR "$now_date|$script|$agi_string\n";} + $agi_string=''; + } + +sub checkresult + { + my ($res) = @_; + my $retval; + $tests++; + chomp $res; + if ($res =~ /^200/) + { + $res =~ /result=(-?\d+)/; + if (!length($1)) + { + # print STDERR "FAIL ($res)\n"; + $fail++; + } + else + { + # print STDERR "PASS ($1)\n"; + $pass++; + } + } + else + { + # print STDERR "FAIL (unexpected result '$res')\n"; + $fail++; + } + } diff --git a/docs/NON-AGENT_API.txt b/docs/NON-AGENT_API.txt index ffa2905a..b0dbac4d 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: 2012-08-10 +NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2012-09-12 This document describes the functions of an API(Application Programming Interface) for all functions NOT directly relating to the VICIDIAL Agent screen. @@ -31,7 +31,8 @@ update_phone_alias - updates or deletes an existing phone alias record in the sy add_list - adds a list to the system update_list - updates list settings in the system, reset leads in list, delete list add_group_alias - adds group alias to the system - +user_group_status - real-time status of one or more user groups +in_group_status - real-time status of one or more in groups New scripts: @@ -73,7 +74,7 @@ Changes: 120213-1613 - Added optional logging of all non-admin.php requests, enabled in options.php 120326-1307 - Added agent_stats_export function 120810-0859 - Added add_group_alias function, altered agent_stats_export function - +120912-2042 - Added user_group_status and in_group_status functions @@ -328,6 +329,68 @@ user|full_name|user_group|calls|login_time|total_talk_time|avg_talk_time|avg_wai + +-------------------------------------------------------------------------------- +user_group_status - real-time status of one or more user groups + +NOTE: api user for this function must have user_level set to 7 or higher and "view reports" enabled + +REQUIRED FIELDS- +source - description of what originated the API call (maximum 20 characters) +user_groups - pipe-delimited list of user groups to get status information for "ADMIN|AGENTS" + +SETTINGS FIELDS- +stage - the format of the exported data: csv, tab, pipe(default) +header - include a header(YES) or not(NO). This is optional, default is not to include a header + +NOTES- +There is a hard limit of 10000000 records analyzed + +Example URL strings for API calls: +http://server/vicidial/non_agent_api.php?source=test&user=6666&pass=1234&function=user_group_status&user_groups=ADMIN|AGENT&header=YES + +Example responses: +ERROR: user_group_status USER DOES NOT HAVE PERMISSION TO GET USER GROUP INFO - 6666|0 +ERROR: user_group_status INVALID SEARCH PARAMETERS - 6666|| + +A SUCCESS response will not show "SUCCESS", but instead will just print the results in the following format: +usergroups|calls_waiting|agents_logged_in|agents_in_calls|agents_waiting|agents_paused|agents_in_dead_calls|agents_in_dispo +ADMIN AGENT|0|1|0|1|0|0|0 + + + + + +-------------------------------------------------------------------------------- +in_group_status - real-time status of one or more in groups + +NOTE: api user for this function must have user_level set to 7 or higher and "view reports" enabled + +REQUIRED FIELDS- +source - description of what originated the API call (maximum 20 characters) +in_groups - pipe-delimited list of inbound groups to get status information for "SALESLINE|SUPPORT" + +SETTINGS FIELDS- +stage - the format of the exported data: csv, tab, pipe(default) +header - include a header(YES) or not(NO). This is optional, default is not to include a header + +NOTES- +There is a hard limit of 10000000 records analyzed + +Example URL strings for API calls: +http://server/vicidial/non_agent_api.php?source=test&user=6666&pass=1234&stage=csv&function=in_group_status&user_groups=SALESLINE|SUPPORT&header=YES + +Example responses: +ERROR: in_group_status USER DOES NOT HAVE PERMISSION TO GET IN-GROUP INFO - 6666|0 +ERROR: in_group_status INVALID SEARCH PARAMETERS - 6666|| + +A SUCCESS response will not show "SUCCESS", but instead will just print the results in the following format: +ingroups,total_calls,calls_waiting,agents_logged_in,agents_in_calls,agents_waiting,agents_paused,agents_in_dispo +SALESLINE SUPPORT,31,0,75,54,0,20,1 + + + + -------------------------------------------------------------------------------- add_lead - adds a new lead to the vicidial_list table with several fields and options diff --git a/www/vicidial/non_agent_api.php b/www/vicidial/non_agent_api.php index b325c249..4135b6f9 100644 --- a/www/vicidial/non_agent_api.php +++ b/www/vicidial/non_agent_api.php @@ -67,10 +67,11 @@ # 120326-1317 - Added agent_stats_export function # 120810-0859 - Added add_group_alias function, altered agent_stats_export function # 120831-1529 - Added vicidial_dial_log outbound call logging +# 120912-2042 - Added user_group_status and in_group_status functions # -$version = '2.6-45'; -$build = '120831-1529'; +$version = '2.6-46'; +$build = '120912-2042'; $api_url_log = 0; $startMS = microtime(); @@ -308,6 +309,10 @@ if (isset($_GET["caller_id_number"])) {$caller_id_number=$_GET["caller_id_numb elseif (isset($_POST["caller_id_number"])) {$caller_id_number=$_POST["caller_id_number"];} if (isset($_GET["caller_id_name"])) {$caller_id_name=$_GET["caller_id_name"];} elseif (isset($_POST["caller_id_name"])) {$caller_id_name=$_POST["caller_id_name"];} +if (isset($_GET["user_groups"])) {$user_groups=$_GET["user_groups"];} + elseif (isset($_POST["user_groups"])) {$user_groups=$_POST["user_groups"];} +if (isset($_GET["in_groups"])) {$in_groups=$_GET["in_groups"];} + elseif (isset($_POST["in_groups"])) {$in_groups=$_POST["in_groups"];} header ("Content-type: text/html; charset=utf-8"); @@ -3760,6 +3765,443 @@ if ($function == 'agent_stats_export') +################################################################################ +### user_group_status - exports user group real-time stats +################################################################################ +if ($function == 'user_group_status') + { + if(strlen($source)<2) + { + $result = 'ERROR'; + $result_reason = "Invalid Source"; + echo "$result: $result_reason - $source\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + echo "ERROR: Invalid Source: |$source|\n"; + exit; + } + else + { + $stmt="SELECT count(*) from vicidial_users where user='$user' and pass='$pass' and vdc_agent_api_access='1' and view_reports='1' and user_level > 6 and active='Y';"; + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $allowed_user=$row[0]; + if ($allowed_user < 1) + { + $result = 'ERROR'; + $result_reason = "user_group_status USER DOES NOT HAVE PERMISSION TO GET USER GROUP INFO"; + 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 + { + $search_SQL=''; + $search_ready=0; + + require_once("functions.php"); + + if ( (strlen($user_groups)>0) and (strlen($user_groups)<10000) ) + { + $user_groupsOUTPUT = preg_replace("/\|/",' ',$user_groups); + $user_groupsSQL = preg_replace("/\|/","','",$user_groups); + $search_SQL .= "and user_group IN('$user_groupsSQL')"; + $search_ready++; + } + if ($search_ready < 1) + { + $result = 'ERROR'; + $result_reason = "user_group_status INVALID SEARCH PARAMETERS"; + $data = "$user|$user_groups"; + echo "$result: $result_reason: $data\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + else + { + $stmt="SELECT user_group from vicidial_users where user='$user' and pass='$pass' and user_level > 6 and view_reports='1' and active='Y';"; + if ($DB) {$MAIN.="|$stmt|\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $LOGuser_group = $row[0]; + + $stmt="SELECT allowed_campaigns,admin_viewable_groups from vicidial_user_groups where user_group='$LOGuser_group';"; + if ($DB) {$MAIN.="|$stmt|\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $LOGallowed_campaigns = $row[0]; + $LOGadmin_viewable_groups = $row[1]; + + $LOGadmin_viewable_groupsSQL=''; + $whereLOGadmin_viewable_groupsSQL=''; + if ( (!eregi("--ALL--",$LOGadmin_viewable_groups)) and (strlen($LOGadmin_viewable_groups) > 3) ) + { + $rawLOGadmin_viewable_groupsSQL = preg_replace("/ -/",'',$LOGadmin_viewable_groups); + $rawLOGadmin_viewable_groupsSQL = preg_replace("/ /","','",$rawLOGadmin_viewable_groupsSQL); + $LOGadmin_viewable_groupsSQL = "and user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')"; + $whereLOGadmin_viewable_groupsSQL = "where user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')"; + } + $LOGallowed_campaignsSQL=''; + $whereLOGallowed_campaignsSQL=''; + $whereLOGallowed_callsSQL=''; + if ( (!eregi("-ALL",$LOGallowed_campaigns)) ) + { + $rawLOGallowed_campaignsSQL = preg_replace("/ -/",'',$LOGallowed_campaigns); + $rawLOGallowed_campaignsSQL = preg_replace("/ /","','",$rawLOGallowed_campaignsSQL); + $LOGallowed_campaignsSQL = "and campaign_id IN('$rawLOGallowed_campaignsSQL')"; + $whereLOGallowed_campaignsSQL = "where campaign_id IN('$rawLOGallowed_campaignsSQL')"; + + $stmt="select group_id from vicidial_inbound_groups $whereLOGadmin_viewable_groupsSQL order by group_id;"; + $rslt=mysql_query($stmt, $link); + $groups_to_print = mysql_num_rows($rslt); + $i=0; + $rawLOGallowed_ingroupsSQL=''; + while ($i < $groups_to_print) + { + $row=mysql_fetch_row($rslt); + $rawLOGallowed_ingroupsSQL .= "row[0]','"; + $i++; + } + $whereLOGallowed_callsSQL = "where campaign_id IN('$rawLOGallowed_campaignsSQL','$rawLOGallowed_ingroupsSQL')"; + } + + $k=0; + $output=''; + $DLset=0; + if ($stage == 'csv') + {$DL = ','; $DLset++;} + if ($stage == 'tab') + {$DL = "\t"; $DLset++;} + if ($stage == 'pipe') + {$DL = '|'; $DLset++;} + if ($DLset < 1) + {$DL='|'; $stage='pipe';} + if (strlen($time_format) < 1) + {$time_format = 'HF';} + if ($header == 'YES') + {$output .= 'usergroups' . $DL . 'calls_waiting' . $DL . 'agents_logged_in' . $DL . 'agents_in_calls' . $DL . 'agents_waiting' . $DL . 'agents_paused' . $DL . 'agents_in_dead_calls' . $DL . 'agents_in_dispo' . "\n";} + + $total_agents=0; + $total_agents_in_calls=0; + $total_agents_waiting=0; + $total_agents_paused=0; + $total_agents_dead=0; + $total_agents_dispo=0; + $total_calls=0; + $total_calls_waiting=0; + $call_camps[0]=''; + $call_types[0]=''; + + $callerids=''; + $pausecode=''; + $stmt="select callerid,status,campaign_id,call_type from vicidial_auto_calls $whereLOGallowed_callsSQL;"; + $rslt=mysql_query($stmt, $link); + if ($DB) {echo "$stmt\n";} + $calls_to_list = mysql_num_rows($rslt); + if ($calls_to_list > 0) + { + $i=0; + while ($i < $calls_to_list) + { + $row=mysql_fetch_row($rslt); + $callerids .= "$row[0]|"; + if (eregi("LIVE",$row[1])) + {$total_calls_waiting++;} + $call_camps[$i] = $row[2]; + $call_types[$i] = $row[3]; + $i++; + } + } + + $stmt="select vicidial_live_agents.user,vicidial_live_agents.status,vicidial_live_agents.campaign_id,vicidial_users.user_group,vicidial_live_agents.comments,vicidial_live_agents.callerid,lead_id from vicidial_live_agents,vicidial_users where vicidial_live_agents.user=vicidial_users.user $search_SQL $LOGadmin_viewable_groupsSQL limit 10000000;"; + $rslt=mysql_query($stmt, $link); + $rec_recs = mysql_num_rows($rslt); + if ($DB>0) {echo "DEBUG: user_group_status query - $rec_recs|$stmt\n";} + if ($rec_recs > 0) + { + while ($rec_recs > $k) + { + # user,status,campaign_id,user_group,comments,callerid,lead_id + $row=mysql_fetch_row($rslt); + + if (eregi("READY|PAUSED",$row[1])) + { + if ($row[6] > 0) + {$row[1] = 'DISPO';} + } + + if (eregi("INCALL",$row[1])) + { + $stmtP="select count(*) from parked_channels where channel_group='$row[5]';"; + $rsltP=mysql_query($stmtP,$link); + $rowP=mysql_fetch_row($rsltP); + $parked_channel = $rowP[0]; + + if ($parked_channel > 0) + {$row[1] = 'PARK';} + else + { + if (!ereg("$row[5]\|",$callerids)) + {$row[1] = 'DEAD';} + } + } + + if ($row[1]=='DEAD') + {$total_agents_dead++;} + if ($row[1]=='DISPO') + {$total_agents_dispo++;} + if ($row[1]=='PAUSED') + {$total_agents_paused++;} + if ( (eregi("INCALL",$row[1])) or (eregi("QUEUE",$row[1])) or (eregi("PARK",$row[1]))) + {$total_agents_in_calls++;} + if ( (eregi("READY",$row[1])) or (eregi("CLOSER",$row[1])) ) + {$total_agents_waiting++;} + + $total_agents++; + $k++; + } + } + $output .= "$user_groupsOUTPUT$DL$total_calls_waiting$DL$total_agents$DL$total_agents_in_calls$DL$total_agents_waiting$DL$total_agents_paused$DL$total_agents_dead$DL$total_agents_dispo\n"; + + echo "$output"; + + $result = 'SUCCESS'; + $data = "$user|$user_groups|$stage"; + $result_reason = "user_group_status AGENTS FOUND: $k"; + + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + } + } + exit; + } +################################################################################ +### END user_group_status +################################################################################ + + + + + +################################################################################ +### in_group_status - exports in-group real-time stats +################################################################################ +if ($function == 'in_group_status') + { + if(strlen($source)<2) + { + $result = 'ERROR'; + $result_reason = "Invalid Source"; + echo "$result: $result_reason - $source\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + echo "ERROR: Invalid Source: |$source|\n"; + exit; + } + else + { + $stmt="SELECT count(*) from vicidial_users where user='$user' and pass='$pass' and vdc_agent_api_access='1' and view_reports='1' and user_level > 6 and active='Y';"; + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $allowed_user=$row[0]; + if ($allowed_user < 1) + { + $result = 'ERROR'; + $result_reason = "in_group_status USER DOES NOT HAVE PERMISSION TO GET IN-GROUP INFO"; + 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 + { + $search_SQL=''; + $search_ready=0; + + require_once("functions.php"); + + if ( (strlen($in_groups)>0) and (strlen($in_groups)<10000) ) + { + $in_groupsOUTPUT = preg_replace("/\|/",' ',$in_groups); + $in_groupsSQL = preg_replace("/\|/","','",$in_groups); + $search_SQL .= "where campaign_id IN('$in_groupsSQL')"; + $agent_search_SQL .= "where group_id IN('$in_groupsSQL')"; + $search_ready++; + } + if ($search_ready < 1) + { + $result = 'ERROR'; + $result_reason = "in_group_status INVALID SEARCH PARAMETERS"; + $data = "$user|$in_groups"; + echo "$result: $result_reason: $data\n"; + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + exit; + } + else + { + $stmt="SELECT user_group from vicidial_users where user='$user' and pass='$pass' and user_level > 6 and view_reports='1' and active='Y';"; + if ($DB) {$MAIN.="|$stmt|\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $LOGuser_group = $row[0]; + + $stmt="SELECT allowed_campaigns,admin_viewable_groups from vicidial_user_groups where user_group='$LOGuser_group';"; + if ($DB) {$MAIN.="|$stmt|\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $LOGallowed_campaigns = $row[0]; + $LOGadmin_viewable_groups = $row[1]; + + $LOGadmin_viewable_groupsSQL=''; + $whereLOGadmin_viewable_groupsSQL=''; + if ( (!eregi("--ALL--",$LOGadmin_viewable_groups)) and (strlen($LOGadmin_viewable_groups) > 3) ) + { + $rawLOGadmin_viewable_groupsSQL = preg_replace("/ -/",'',$LOGadmin_viewable_groups); + $rawLOGadmin_viewable_groupsSQL = preg_replace("/ /","','",$rawLOGadmin_viewable_groupsSQL); + $LOGadmin_viewable_groupsSQL = "and user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')"; + $whereLOGadmin_viewable_groupsSQL = "where user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')"; + } + $LOGallowed_campaignsSQL=''; + $whereLOGallowed_campaignsSQL=''; + $LOGallowed_callsSQL=''; + if ( (!eregi("-ALL",$LOGallowed_campaigns)) ) + { + $rawLOGallowed_campaignsSQL = preg_replace("/ -/",'',$LOGallowed_campaigns); + $rawLOGallowed_campaignsSQL = preg_replace("/ /","','",$rawLOGallowed_campaignsSQL); + $LOGallowed_campaignsSQL = "and campaign_id IN('$rawLOGallowed_campaignsSQL')"; + $whereLOGallowed_campaignsSQL = "where campaign_id IN('$rawLOGallowed_campaignsSQL')"; + + $stmt="select group_id from vicidial_inbound_groups $whereLOGadmin_viewable_groupsSQL order by group_id;"; + $rslt=mysql_query($stmt, $link); + $groups_to_print = mysql_num_rows($rslt); + $i=0; + $rawLOGallowed_ingroupsSQL=''; + while ($i < $groups_to_print) + { + $row=mysql_fetch_row($rslt); + $rawLOGallowed_ingroupsSQL .= "row[0]','"; + $i++; + } + $LOGallowed_callsSQL = "and campaign_id IN('$rawLOGallowed_campaignsSQL','$rawLOGallowed_ingroupsSQL')"; + } + + + $k=0; + $output=''; + $DLset=0; + if ($stage == 'csv') + {$DL = ','; $DLset++;} + if ($stage == 'tab') + {$DL = "\t"; $DLset++;} + if ($stage == 'pipe') + {$DL = '|'; $DLset++;} + if ($DLset < 1) + {$DL='|'; $stage='pipe';} + if (strlen($time_format) < 1) + {$time_format = 'HF';} + if ($header == 'YES') + {$output .= 'ingroups' . $DL . 'total_calls' . $DL . 'calls_waiting' . $DL . 'agents_logged_in' . $DL . 'agents_in_calls' . $DL . 'agents_waiting' . $DL . 'agents_paused' . $DL . 'agents_in_dispo' . "\n";} + + $total_agents=0; + $total_agents_in_calls=0; + $total_agents_waiting=0; + $total_agents_paused=0; + $total_agents_dead=0; + $total_agents_dispo=0; + $total_calls=0; + $total_calls_waiting=0; + $call_camps[0]=''; + $call_types[0]=''; + + $callerids=''; + $pausecode=''; + $stmt="select callerid,status,campaign_id,call_type from vicidial_auto_calls $search_SQL $LOGallowed_callsSQL;"; + $rslt=mysql_query($stmt, $link); + if ($DB) {echo "$stmt\n";} + $calls_to_list = mysql_num_rows($rslt); + if ($calls_to_list > 0) + { + $i=0; + while ($i < $calls_to_list) + { + $row=mysql_fetch_row($rslt); + $callerids .= "$row[0]|"; + if (eregi("LIVE",$row[1])) + {$total_calls_waiting++;} + $call_camps[$i] = $row[2]; + $call_types[$i] = $row[3]; + $total_calls++; + $i++; + } + } + + $users=''; + $stmt="SELECT distinct user from vicidial_live_inbound_agents where group_id IN('$in_groupsSQL');"; + $rslt=mysql_query($stmt, $link); + if ($DB) {echo "$stmt\n";} + $IG_users = mysql_num_rows($rslt); + if ($IG_users > 0) + { + $i=0; + while ($i < $IG_users) + { + $row=mysql_fetch_row($rslt); + $users .= "$row[0]','"; + $i++; + } + } + + $k=0; + $stmt="select vicidial_live_agents.user,vicidial_live_agents.status,vicidial_live_agents.campaign_id,vicidial_users.user_group,vicidial_live_agents.comments,vicidial_live_agents.callerid,lead_id from vicidial_live_agents,vicidial_users where vicidial_live_agents.user=vicidial_users.user and vicidial_live_agents.user IN('$users') $LOGadmin_viewable_groupsSQL limit 10000000;"; + $rslt=mysql_query($stmt, $link); + $rec_recs = mysql_num_rows($rslt); + if ($DB>0) {echo "DEBUG: in_group_status query - $rec_recs|$stmt\n";} + if ($rec_recs > 0) + { + while ($rec_recs > $k) + { + # user,status,campaign_id,user_group,comments,callerid,lead_id + $row=mysql_fetch_row($rslt); + + if (eregi("READY|PAUSED",$row[1])) + { + if ($row[6] > 0) + {$row[1] = 'DISPO';} + } + if ($row[1]=='DISPO') + {$total_agents_dispo++;} + if ($row[1]=='PAUSED') + {$total_agents_paused++;} + if ( (eregi("INCALL",$row[1])) or (eregi("QUEUE",$row[1])) or (eregi("PARK",$row[1]))) + {$total_agents_in_calls++;} + if ( (eregi("READY",$row[1])) or (eregi("CLOSER",$row[1])) ) + {$total_agents_waiting++;} + + $total_agents++; + $k++; + } + } + $output .= "$in_groupsOUTPUT$DL$total_calls$DL$total_calls_waiting$DL$total_agents$DL$total_agents_in_calls$DL$total_agents_waiting$DL$total_agents_paused$DL$total_agents_dispo\n"; + + echo "$output"; + + $result = 'SUCCESS'; + $data = "$user|$in_groups|$stage"; + $result_reason = "in_group_status CALLS FOUND: $k"; + + api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); + } + } + } + exit; + } +################################################################################ +### END in_group_status +################################################################################ + + + + + ################################################################################ ### add_lead - inserts a lead into the vicidial_list table ################################################################################